/**
* Copyright (C) 2009 - 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 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.batch.BatchMaster;
import com.opengamma.batch.rest.DataBatchMasterResource;
import com.opengamma.batch.rest.RemoteBatchMaster;
import com.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
import com.opengamma.component.factory.ComponentInfoAttributes;
import com.opengamma.engine.ComputationTargetResolver;
import com.opengamma.masterdb.batch.DbBatchMaster;
/**
* Component factory for the database batch master.
*/
@BeanDefinition
public class DbBatchMasterComponentFactory extends AbstractDbMasterComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* The flag determining whether the component should be published by REST (default true).
*/
@PropertyDefinition
private boolean _publishRest = true;
/**
* The scheme used by the {@code UniqueId}.
*/
@PropertyDefinition
private String _uniqueIdScheme;
@PropertyDefinition(validate = "notNull")
private ComputationTargetResolver _computationTargetResolver;
//-------------------------------------------------------------------------
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) {
ComponentInfo info = new ComponentInfo(BatchMaster.class, getClassifier());
// master
DbBatchMaster master = new DbBatchMaster(getDbConnector(), getComputationTargetResolver());
if (getUniqueIdScheme() != null) {
master.setUniqueIdScheme(getUniqueIdScheme());
}
checkSchema(master.getSchemaVersion(), "rsk");
// register
info.addAttribute(ComponentInfoAttributes.LEVEL, 1);
info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteBatchMaster.class);
info.addAttribute(ComponentInfoAttributes.UNIQUE_ID_SCHEME, master.getUniqueIdScheme());
repo.registerComponent(info, master);
// publish
if (isPublishRest()) {
repo.getRestComponents().publish(info, new DataBatchMasterResource(master));
}
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code DbBatchMasterComponentFactory}.
* @return the meta-bean, not null
*/
public static DbBatchMasterComponentFactory.Meta meta() {
return DbBatchMasterComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(DbBatchMasterComponentFactory.Meta.INSTANCE);
}
@Override
public DbBatchMasterComponentFactory.Meta metaBean() {
return DbBatchMasterComponentFactory.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return getClassifier();
case -614707837: // publishRest
return isPublishRest();
case -1737146991: // uniqueIdScheme
return getUniqueIdScheme();
case 1562222174: // computationTargetResolver
return getComputationTargetResolver();
}
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 -614707837: // publishRest
setPublishRest((Boolean) newValue);
return;
case -1737146991: // uniqueIdScheme
setUniqueIdScheme((String) newValue);
return;
case 1562222174: // computationTargetResolver
setComputationTargetResolver((ComputationTargetResolver) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
protected void validate() {
JodaBeanUtils.notNull(_classifier, "classifier");
JodaBeanUtils.notNull(_computationTargetResolver, "computationTargetResolver");
super.validate();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
DbBatchMasterComponentFactory other = (DbBatchMasterComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(isPublishRest(), other.isPublishRest()) &&
JodaBeanUtils.equal(getUniqueIdScheme(), other.getUniqueIdScheme()) &&
JodaBeanUtils.equal(getComputationTargetResolver(), other.getComputationTargetResolver()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash += hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash += hash * 31 + JodaBeanUtils.hashCode(isPublishRest());
hash += hash * 31 + JodaBeanUtils.hashCode(getUniqueIdScheme());
hash += hash * 31 + JodaBeanUtils.hashCode(getComputationTargetResolver());
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 flag determining whether the component should be published by REST (default true).
* @return the value of the property
*/
public boolean isPublishRest() {
return _publishRest;
}
/**
* Sets the flag determining whether the component should be published by REST (default true).
* @param publishRest the new value of the property
*/
public void setPublishRest(boolean publishRest) {
this._publishRest = publishRest;
}
/**
* Gets the the {@code publishRest} property.
* @return the property, not null
*/
public final Property<Boolean> publishRest() {
return metaBean().publishRest().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the scheme used by the {@code UniqueId}.
* @return the value of the property
*/
public String getUniqueIdScheme() {
return _uniqueIdScheme;
}
/**
* Sets the scheme used by the {@code UniqueId}.
* @param uniqueIdScheme the new value of the property
*/
public void setUniqueIdScheme(String uniqueIdScheme) {
this._uniqueIdScheme = uniqueIdScheme;
}
/**
* Gets the the {@code uniqueIdScheme} property.
* @return the property, not null
*/
public final Property<String> uniqueIdScheme() {
return metaBean().uniqueIdScheme().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the computationTargetResolver.
* @return the value of the property, not null
*/
public ComputationTargetResolver getComputationTargetResolver() {
return _computationTargetResolver;
}
/**
* Sets the computationTargetResolver.
* @param computationTargetResolver the new value of the property, not null
*/
public void setComputationTargetResolver(ComputationTargetResolver computationTargetResolver) {
JodaBeanUtils.notNull(computationTargetResolver, "computationTargetResolver");
this._computationTargetResolver = computationTargetResolver;
}
/**
* Gets the the {@code computationTargetResolver} property.
* @return the property, not null
*/
public final Property<ComputationTargetResolver> computationTargetResolver() {
return metaBean().computationTargetResolver().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code DbBatchMasterComponentFactory}.
*/
public static class Meta extends AbstractDbMasterComponentFactory.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", DbBatchMasterComponentFactory.class, String.class);
/**
* The meta-property for the {@code publishRest} property.
*/
private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite(
this, "publishRest", DbBatchMasterComponentFactory.class, Boolean.TYPE);
/**
* The meta-property for the {@code uniqueIdScheme} property.
*/
private final MetaProperty<String> _uniqueIdScheme = DirectMetaProperty.ofReadWrite(
this, "uniqueIdScheme", DbBatchMasterComponentFactory.class, String.class);
/**
* The meta-property for the {@code computationTargetResolver} property.
*/
private final MetaProperty<ComputationTargetResolver> _computationTargetResolver = DirectMetaProperty.ofReadWrite(
this, "computationTargetResolver", DbBatchMasterComponentFactory.class, ComputationTargetResolver.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"publishRest",
"uniqueIdScheme",
"computationTargetResolver");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case -614707837: // publishRest
return _publishRest;
case -1737146991: // uniqueIdScheme
return _uniqueIdScheme;
case 1562222174: // computationTargetResolver
return _computationTargetResolver;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends DbBatchMasterComponentFactory> builder() {
return new DirectBeanBuilder<DbBatchMasterComponentFactory>(new DbBatchMasterComponentFactory());
}
@Override
public Class<? extends DbBatchMasterComponentFactory> beanType() {
return DbBatchMasterComponentFactory.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 publishRest} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> publishRest() {
return _publishRest;
}
/**
* The meta-property for the {@code uniqueIdScheme} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> uniqueIdScheme() {
return _uniqueIdScheme;
}
/**
* The meta-property for the {@code computationTargetResolver} property.
* @return the meta-property, not null
*/
public final MetaProperty<ComputationTargetResolver> computationTargetResolver() {
return _computationTargetResolver;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}