/** * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.masterdb.spring; import java.util.Map; import net.sf.ehcache.CacheManager; import org.joda.beans.Bean; import org.joda.beans.BeanBuilder; import org.joda.beans.BeanDefinition; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.Property; import org.joda.beans.PropertyDefinition; import org.joda.beans.impl.direct.DirectBeanBuilder; import org.joda.beans.impl.direct.DirectMetaProperty; import org.joda.beans.impl.direct.DirectMetaPropertyMap; import com.opengamma.core.change.JmsChangeManager; import com.opengamma.masterdb.security.DbSecurityMaster; import com.opengamma.masterdb.security.EHCachingSecurityMasterDetailProvider; import com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterDetailProvider; /** * Spring factory bean to create the database security master. */ @BeanDefinition public class DbSecurityMasterFactoryBean extends AbstractDbMasterFactoryBean<DbSecurityMaster> { /** * The cache manager for the detail. */ @PropertyDefinition private CacheManager _cacheManager; /** * Creates an instance. */ public DbSecurityMasterFactoryBean() { super(DbSecurityMaster.class); } //------------------------------------------------------------------------- @Override public DbSecurityMaster createObject() { DbSecurityMaster master = new DbSecurityMaster(getDbConnector()); if (getUniqueIdScheme() != null) { master.setUniqueIdScheme(getUniqueIdScheme()); } if (getMaxRetries() != null) { master.setMaxRetries(getMaxRetries()); } if (getJmsConnector() != null) { JmsChangeManager cm = new JmsChangeManager(getJmsConnector().ensureTopicName(getJmsChangeManagerTopic())); master.setChangeManager(cm); cm.start(); } if (getCacheManager() != null) { master.setDetailProvider(new EHCachingSecurityMasterDetailProvider(new HibernateSecurityMasterDetailProvider(), getCacheManager())); } return master; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code DbSecurityMasterFactoryBean}. * @return the meta-bean, not null */ public static DbSecurityMasterFactoryBean.Meta meta() { return DbSecurityMasterFactoryBean.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(DbSecurityMasterFactoryBean.Meta.INSTANCE); } @Override public DbSecurityMasterFactoryBean.Meta metaBean() { return DbSecurityMasterFactoryBean.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the cache manager for the detail. * @return the value of the property */ public CacheManager getCacheManager() { return _cacheManager; } /** * Sets the cache manager for the detail. * @param cacheManager the new value of the property */ public void setCacheManager(CacheManager cacheManager) { this._cacheManager = cacheManager; } /** * Gets the the {@code cacheManager} property. * @return the property, not null */ public final Property<CacheManager> cacheManager() { return metaBean().cacheManager().createProperty(this); } //----------------------------------------------------------------------- @Override public DbSecurityMasterFactoryBean clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { DbSecurityMasterFactoryBean other = (DbSecurityMasterFactoryBean) obj; return JodaBeanUtils.equal(getCacheManager(), other.getCacheManager()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getCacheManager()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("DbSecurityMasterFactoryBean{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } @Override protected void toString(StringBuilder buf) { super.toString(buf); buf.append("cacheManager").append('=').append(JodaBeanUtils.toString(getCacheManager())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code DbSecurityMasterFactoryBean}. */ public static class Meta extends AbstractDbMasterFactoryBean.Meta<DbSecurityMaster> { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code cacheManager} property. */ private final MetaProperty<CacheManager> _cacheManager = DirectMetaProperty.ofReadWrite( this, "cacheManager", DbSecurityMasterFactoryBean.class, CacheManager.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "cacheManager"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -1452875317: // cacheManager return _cacheManager; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends DbSecurityMasterFactoryBean> builder() { return new DirectBeanBuilder<DbSecurityMasterFactoryBean>(new DbSecurityMasterFactoryBean()); } @Override public Class<? extends DbSecurityMasterFactoryBean> beanType() { return DbSecurityMasterFactoryBean.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code cacheManager} property. * @return the meta-property, not null */ public final MetaProperty<CacheManager> cacheManager() { return _cacheManager; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1452875317: // cacheManager return ((DbSecurityMasterFactoryBean) bean).getCacheManager(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -1452875317: // cacheManager ((DbSecurityMasterFactoryBean) bean).setCacheManager((CacheManager) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }