/**
* Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.component.factory.master;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.sql.DataSource;
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.jolbox.bonecp.BoneCPDataSource;
import com.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
import com.opengamma.component.factory.AbstractComponentFactory;
/**
* Component factory for a data source. This has some default values designed for the masters.
*/
@BeanDefinition
public class DataSourceComponentFactory extends AbstractComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* The fully-qualified class name of the database driver.
*/
@PropertyDefinition(validate = "notNull")
private String _driverClass;
/**
* The JDBC connection URL.
*/
@PropertyDefinition(validate = "notNull")
private String _jdbcUrl;
/**
* The database username.
*/
@PropertyDefinition(validate = "notNull")
private String _username;
/**
* The database password.
*/
@PropertyDefinition(validate = "notNull")
private String _password;
/**
* The connection pool name, defaults to the classifier name.
*/
@PropertyDefinition
private String _poolName;
/**
* The number of partitions, defaults to 2.
*/
@PropertyDefinition
private int _partitionCount = 2;
/**
* The number of connections to acquire at once, defaults to 1.
*/
@PropertyDefinition
private int _acquireIncrement = 1;
/**
* The minimum number of connections per partition, defaults to 1.
*/
@PropertyDefinition
private int _minConnectionsPerPartition = 1;
/**
* The maximum number of connections per partition, defaults to 10.
*/
@PropertyDefinition
private int _maxConnectionsPerPartition = 10;
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception {
if (getPoolName() == null) {
setPoolName(getClassifier());
}
initDataSource(repo);
}
protected DataSource initDataSource(ComponentRepository repo) {
BoneCPDataSource dataSource = new BoneCPDataSource();
dataSource.setDriverClass(getDriverClass());
dataSource.setJdbcUrl(getJdbcUrl());
dataSource.setUsername(getUsername());
dataSource.setPassword(getPassword());
dataSource.setPoolName(getPoolName());
dataSource.setPartitionCount(getPartitionCount());
dataSource.setAcquireIncrement(getAcquireIncrement());
dataSource.setMinConnectionsPerPartition(getMinConnectionsPerPartition());
dataSource.setMaxConnectionsPerPartition(getMaxConnectionsPerPartition());
ComponentInfo info = new ComponentInfo(DataSource.class, getClassifier());
repo.registerComponent(info, dataSource);
return dataSource;
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code DataSourceComponentFactory}.
* @return the meta-bean, not null
*/
public static DataSourceComponentFactory.Meta meta() {
return DataSourceComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(DataSourceComponentFactory.Meta.INSTANCE);
}
@Override
public DataSourceComponentFactory.Meta metaBean() {
return DataSourceComponentFactory.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return getClassifier();
case 1227291184: // driverClass
return getDriverClass();
case -1752402828: // jdbcUrl
return getJdbcUrl();
case -265713450: // username
return getUsername();
case 1216985755: // password
return getPassword();
case 634919111: // poolName
return getPoolName();
case -1051422651: // partitionCount
return getPartitionCount();
case -349316295: // acquireIncrement
return getAcquireIncrement();
case 1469514128: // minConnectionsPerPartition
return getMinConnectionsPerPartition();
case 237252158: // maxConnectionsPerPartition
return getMaxConnectionsPerPartition();
}
return super.propertyGet(propertyName, quiet);
}
@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
setClassifier((String) newValue);
return;
case 1227291184: // driverClass
setDriverClass((String) newValue);
return;
case -1752402828: // jdbcUrl
setJdbcUrl((String) newValue);
return;
case -265713450: // username
setUsername((String) newValue);
return;
case 1216985755: // password
setPassword((String) newValue);
return;
case 634919111: // poolName
setPoolName((String) newValue);
return;
case -1051422651: // partitionCount
setPartitionCount((Integer) newValue);
return;
case -349316295: // acquireIncrement
setAcquireIncrement((Integer) newValue);
return;
case 1469514128: // minConnectionsPerPartition
setMinConnectionsPerPartition((Integer) newValue);
return;
case 237252158: // maxConnectionsPerPartition
setMaxConnectionsPerPartition((Integer) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
protected void validate() {
JodaBeanUtils.notNull(_classifier, "classifier");
JodaBeanUtils.notNull(_driverClass, "driverClass");
JodaBeanUtils.notNull(_jdbcUrl, "jdbcUrl");
JodaBeanUtils.notNull(_username, "username");
JodaBeanUtils.notNull(_password, "password");
super.validate();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
DataSourceComponentFactory other = (DataSourceComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(getDriverClass(), other.getDriverClass()) &&
JodaBeanUtils.equal(getJdbcUrl(), other.getJdbcUrl()) &&
JodaBeanUtils.equal(getUsername(), other.getUsername()) &&
JodaBeanUtils.equal(getPassword(), other.getPassword()) &&
JodaBeanUtils.equal(getPoolName(), other.getPoolName()) &&
JodaBeanUtils.equal(getPartitionCount(), other.getPartitionCount()) &&
JodaBeanUtils.equal(getAcquireIncrement(), other.getAcquireIncrement()) &&
JodaBeanUtils.equal(getMinConnectionsPerPartition(), other.getMinConnectionsPerPartition()) &&
JodaBeanUtils.equal(getMaxConnectionsPerPartition(), other.getMaxConnectionsPerPartition()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash += hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash += hash * 31 + JodaBeanUtils.hashCode(getDriverClass());
hash += hash * 31 + JodaBeanUtils.hashCode(getJdbcUrl());
hash += hash * 31 + JodaBeanUtils.hashCode(getUsername());
hash += hash * 31 + JodaBeanUtils.hashCode(getPassword());
hash += hash * 31 + JodaBeanUtils.hashCode(getPoolName());
hash += hash * 31 + JodaBeanUtils.hashCode(getPartitionCount());
hash += hash * 31 + JodaBeanUtils.hashCode(getAcquireIncrement());
hash += hash * 31 + JodaBeanUtils.hashCode(getMinConnectionsPerPartition());
hash += hash * 31 + JodaBeanUtils.hashCode(getMaxConnectionsPerPartition());
return hash ^ super.hashCode();
}
//-----------------------------------------------------------------------
/**
* Gets the classifier that the factory should publish under.
* @return the value of the property, not null
*/
public String getClassifier() {
return _classifier;
}
/**
* Sets the classifier that the factory should publish under.
* @param classifier the new value of the property, not null
*/
public void setClassifier(String classifier) {
JodaBeanUtils.notNull(classifier, "classifier");
this._classifier = classifier;
}
/**
* Gets the the {@code classifier} property.
* @return the property, not null
*/
public final Property<String> classifier() {
return metaBean().classifier().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the fully-qualified class name of the database driver.
* @return the value of the property, not null
*/
public String getDriverClass() {
return _driverClass;
}
/**
* Sets the fully-qualified class name of the database driver.
* @param driverClass the new value of the property, not null
*/
public void setDriverClass(String driverClass) {
JodaBeanUtils.notNull(driverClass, "driverClass");
this._driverClass = driverClass;
}
/**
* Gets the the {@code driverClass} property.
* @return the property, not null
*/
public final Property<String> driverClass() {
return metaBean().driverClass().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the JDBC connection URL.
* @return the value of the property, not null
*/
public String getJdbcUrl() {
return _jdbcUrl;
}
/**
* Sets the JDBC connection URL.
* @param jdbcUrl the new value of the property, not null
*/
public void setJdbcUrl(String jdbcUrl) {
JodaBeanUtils.notNull(jdbcUrl, "jdbcUrl");
this._jdbcUrl = jdbcUrl;
}
/**
* Gets the the {@code jdbcUrl} property.
* @return the property, not null
*/
public final Property<String> jdbcUrl() {
return metaBean().jdbcUrl().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the database username.
* @return the value of the property, not null
*/
public String getUsername() {
return _username;
}
/**
* Sets the database username.
* @param username the new value of the property, not null
*/
public void setUsername(String username) {
JodaBeanUtils.notNull(username, "username");
this._username = username;
}
/**
* Gets the the {@code username} property.
* @return the property, not null
*/
public final Property<String> username() {
return metaBean().username().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the database password.
* @return the value of the property, not null
*/
public String getPassword() {
return _password;
}
/**
* Sets the database password.
* @param password the new value of the property, not null
*/
public void setPassword(String password) {
JodaBeanUtils.notNull(password, "password");
this._password = password;
}
/**
* Gets the the {@code password} property.
* @return the property, not null
*/
public final Property<String> password() {
return metaBean().password().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the connection pool name, defaults to the classifier name.
* @return the value of the property
*/
public String getPoolName() {
return _poolName;
}
/**
* Sets the connection pool name, defaults to the classifier name.
* @param poolName the new value of the property
*/
public void setPoolName(String poolName) {
this._poolName = poolName;
}
/**
* Gets the the {@code poolName} property.
* @return the property, not null
*/
public final Property<String> poolName() {
return metaBean().poolName().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the number of partitions, defaults to 2.
* @return the value of the property
*/
public int getPartitionCount() {
return _partitionCount;
}
/**
* Sets the number of partitions, defaults to 2.
* @param partitionCount the new value of the property
*/
public void setPartitionCount(int partitionCount) {
this._partitionCount = partitionCount;
}
/**
* Gets the the {@code partitionCount} property.
* @return the property, not null
*/
public final Property<Integer> partitionCount() {
return metaBean().partitionCount().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the number of connections to acquire at once, defaults to 1.
* @return the value of the property
*/
public int getAcquireIncrement() {
return _acquireIncrement;
}
/**
* Sets the number of connections to acquire at once, defaults to 1.
* @param acquireIncrement the new value of the property
*/
public void setAcquireIncrement(int acquireIncrement) {
this._acquireIncrement = acquireIncrement;
}
/**
* Gets the the {@code acquireIncrement} property.
* @return the property, not null
*/
public final Property<Integer> acquireIncrement() {
return metaBean().acquireIncrement().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the minimum number of connections per partition, defaults to 1.
* @return the value of the property
*/
public int getMinConnectionsPerPartition() {
return _minConnectionsPerPartition;
}
/**
* Sets the minimum number of connections per partition, defaults to 1.
* @param minConnectionsPerPartition the new value of the property
*/
public void setMinConnectionsPerPartition(int minConnectionsPerPartition) {
this._minConnectionsPerPartition = minConnectionsPerPartition;
}
/**
* Gets the the {@code minConnectionsPerPartition} property.
* @return the property, not null
*/
public final Property<Integer> minConnectionsPerPartition() {
return metaBean().minConnectionsPerPartition().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the maximum number of connections per partition, defaults to 10.
* @return the value of the property
*/
public int getMaxConnectionsPerPartition() {
return _maxConnectionsPerPartition;
}
/**
* Sets the maximum number of connections per partition, defaults to 10.
* @param maxConnectionsPerPartition the new value of the property
*/
public void setMaxConnectionsPerPartition(int maxConnectionsPerPartition) {
this._maxConnectionsPerPartition = maxConnectionsPerPartition;
}
/**
* Gets the the {@code maxConnectionsPerPartition} property.
* @return the property, not null
*/
public final Property<Integer> maxConnectionsPerPartition() {
return metaBean().maxConnectionsPerPartition().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code DataSourceComponentFactory}.
*/
public static class Meta extends AbstractComponentFactory.Meta {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code classifier} property.
*/
private final MetaProperty<String> _classifier = DirectMetaProperty.ofReadWrite(
this, "classifier", DataSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code driverClass} property.
*/
private final MetaProperty<String> _driverClass = DirectMetaProperty.ofReadWrite(
this, "driverClass", DataSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code jdbcUrl} property.
*/
private final MetaProperty<String> _jdbcUrl = DirectMetaProperty.ofReadWrite(
this, "jdbcUrl", DataSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code username} property.
*/
private final MetaProperty<String> _username = DirectMetaProperty.ofReadWrite(
this, "username", DataSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code password} property.
*/
private final MetaProperty<String> _password = DirectMetaProperty.ofReadWrite(
this, "password", DataSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code poolName} property.
*/
private final MetaProperty<String> _poolName = DirectMetaProperty.ofReadWrite(
this, "poolName", DataSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code partitionCount} property.
*/
private final MetaProperty<Integer> _partitionCount = DirectMetaProperty.ofReadWrite(
this, "partitionCount", DataSourceComponentFactory.class, Integer.TYPE);
/**
* The meta-property for the {@code acquireIncrement} property.
*/
private final MetaProperty<Integer> _acquireIncrement = DirectMetaProperty.ofReadWrite(
this, "acquireIncrement", DataSourceComponentFactory.class, Integer.TYPE);
/**
* The meta-property for the {@code minConnectionsPerPartition} property.
*/
private final MetaProperty<Integer> _minConnectionsPerPartition = DirectMetaProperty.ofReadWrite(
this, "minConnectionsPerPartition", DataSourceComponentFactory.class, Integer.TYPE);
/**
* The meta-property for the {@code maxConnectionsPerPartition} property.
*/
private final MetaProperty<Integer> _maxConnectionsPerPartition = DirectMetaProperty.ofReadWrite(
this, "maxConnectionsPerPartition", DataSourceComponentFactory.class, Integer.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"driverClass",
"jdbcUrl",
"username",
"password",
"poolName",
"partitionCount",
"acquireIncrement",
"minConnectionsPerPartition",
"maxConnectionsPerPartition");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case 1227291184: // driverClass
return _driverClass;
case -1752402828: // jdbcUrl
return _jdbcUrl;
case -265713450: // username
return _username;
case 1216985755: // password
return _password;
case 634919111: // poolName
return _poolName;
case -1051422651: // partitionCount
return _partitionCount;
case -349316295: // acquireIncrement
return _acquireIncrement;
case 1469514128: // minConnectionsPerPartition
return _minConnectionsPerPartition;
case 237252158: // maxConnectionsPerPartition
return _maxConnectionsPerPartition;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends DataSourceComponentFactory> builder() {
return new DirectBeanBuilder<DataSourceComponentFactory>(new DataSourceComponentFactory());
}
@Override
public Class<? extends DataSourceComponentFactory> beanType() {
return DataSourceComponentFactory.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code classifier} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> classifier() {
return _classifier;
}
/**
* The meta-property for the {@code driverClass} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> driverClass() {
return _driverClass;
}
/**
* The meta-property for the {@code jdbcUrl} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> jdbcUrl() {
return _jdbcUrl;
}
/**
* The meta-property for the {@code username} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> username() {
return _username;
}
/**
* The meta-property for the {@code password} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> password() {
return _password;
}
/**
* The meta-property for the {@code poolName} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> poolName() {
return _poolName;
}
/**
* The meta-property for the {@code partitionCount} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> partitionCount() {
return _partitionCount;
}
/**
* The meta-property for the {@code acquireIncrement} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> acquireIncrement() {
return _acquireIncrement;
}
/**
* The meta-property for the {@code minConnectionsPerPartition} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> minConnectionsPerPartition() {
return _minConnectionsPerPartition;
}
/**
* The meta-property for the {@code maxConnectionsPerPartition} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> maxConnectionsPerPartition() {
return _maxConnectionsPerPartition;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}