javax.persistence.TableGenerator Java Examples

The following examples show how to use javax.persistence.TableGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static TableGenerator buildTableGeneratorAnnotation(Element element, XMLContext.Default defaults) {
	AnnotationDescriptor ad = new AnnotationDescriptor( TableGenerator.class );
	copyStringAttribute( ad, element, "name", false );
	copyStringAttribute( ad, element, "table", false );
	copyStringAttribute( ad, element, "catalog", false );
	copyStringAttribute( ad, element, "schema", false );
	copyStringAttribute( ad, element, "pk-column-name", false );
	copyStringAttribute( ad, element, "value-column-name", false );
	copyStringAttribute( ad, element, "pk-column-value", false );
	copyIntegerAttribute( ad, element, "initial-value" );
	copyIntegerAttribute( ad, element, "allocation-size" );
	buildUniqueConstraints( ad, element );
	if ( StringHelper.isEmpty( (String) ad.valueOf( "schema" ) )
			&& StringHelper.isNotEmpty( defaults.getSchema() ) ) {
		ad.setValue( "schema", defaults.getSchema() );
	}
	if ( StringHelper.isEmpty( (String) ad.valueOf( "catalog" ) )
			&& StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
		ad.setValue( "catalog", defaults.getCatalog() );
	}
	return AnnotationFactory.create( ad );
}
 
Example #2
Source File: ChangeRecord.java    From juddi with Apache License 2.0 6 votes vote down vote up
@Id
@GeneratedValue(strategy = GenerationType.TABLE,
     generator = "personGen")
@TableGenerator(name = "personGen",
     table = "JPAGEN_GENERATORS",
     pkColumnName = "NAME",
     pkColumnValue = "JPAGEN_PERSON_GEN",
     valueColumnName = "VALUE")
public Long getId() {
        return id;
}
 
Example #3
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Annotation getTableGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) {
	for ( Element element : elementsForProperty ) {
		Element subelement = element != null ? element.element( annotationToXml.get( TableGenerator.class ) ) : null;
		if ( subelement != null ) {
			return buildTableGeneratorAnnotation( subelement, defaults );
		}
	}
	if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( TableGenerator.class );
	}
	else {
		return null;
	}
}
 
Example #4
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private TableGenerator getTableGenerator(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( annotationToXml.get( TableGenerator.class ) ) : null;
	if ( element != null ) {
		return buildTableGeneratorAnnotation( element, defaults );
	}
	else if ( defaults.canUseJavaAnnotations() && isPhysicalAnnotationPresent( TableGenerator.class ) ) {
		TableGenerator tableAnn = getPhysicalAnnotation( TableGenerator.class );
		if ( StringHelper.isNotEmpty( defaults.getSchema() )
				|| StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
			AnnotationDescriptor annotation = new AnnotationDescriptor( TableGenerator.class );
			annotation.setValue( "name", tableAnn.name() );
			annotation.setValue( "table", tableAnn.table() );
			annotation.setValue( "catalog", tableAnn.table() );
			if ( StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) )
					&& StringHelper.isNotEmpty( defaults.getCatalog() ) ) {
				annotation.setValue( "catalog", defaults.getCatalog() );
			}
			annotation.setValue( "schema", tableAnn.table() );
			if ( StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) )
					&& StringHelper.isNotEmpty( defaults.getSchema() ) ) {
				annotation.setValue( "catalog", defaults.getSchema() );
			}
			annotation.setValue( "pkColumnName", tableAnn.pkColumnName() );
			annotation.setValue( "valueColumnName", tableAnn.valueColumnName() );
			annotation.setValue( "pkColumnValue", tableAnn.pkColumnValue() );
			annotation.setValue( "initialValue", tableAnn.initialValue() );
			annotation.setValue( "allocationSize", tableAnn.allocationSize() );
			annotation.setValue( "uniqueConstraints", tableAnn.uniqueConstraints() );
			return AnnotationFactory.create( annotation );
		}
		else {
			return tableAnn;
		}
	}
	else {
		return null;
	}
}
 
Example #5
Source File: IdGeneratorInterpreterImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void interpretTableGenerator(
		TableGenerator tableGeneratorAnnotation,
		IdentifierGeneratorDefinition.Builder definitionBuilder) {
	fallbackInterpreter.interpretTableGenerator( tableGeneratorAnnotation, definitionBuilder );

	if ( delegates != null ) {
		for ( IdGeneratorStrategyInterpreter delegate : delegates ) {
			delegate.interpretTableGenerator( tableGeneratorAnnotation, definitionBuilder );
		}
	}
}
 
Example #6
Source File: IdGeneratorInterpreterImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String determineGeneratorName(GenerationType generationType, GeneratorNameDeterminationContext context) {
	switch ( generationType ) {
		case IDENTITY: {
			return "identity";
		}
		case SEQUENCE: {
			return org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName();
		}
		case TABLE: {
			return org.hibernate.id.enhanced.TableGenerator.class.getName();
		}
		default: {
			// AUTO

			if ( "increment".equalsIgnoreCase( context.getGeneratedValueGeneratorName() ) ) {
				return IncrementGenerator.class.getName();
			}

			final Class javaType = context.getIdType();
			if ( UUID.class.isAssignableFrom( javaType ) ) {
				return UUIDGenerator.class.getName();
			}

			return org.hibernate.id.enhanced.SequenceStyleGenerator.class.getName();
		}
	}
}
 
Example #7
Source File: SequenceFetcher.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
public <T> T getNextSequence(Class<T> clazz, TableGenerator tg, Object key, boolean isRandom) {
    Future<T> future = _executors.submit(new Fetcher<T>(clazz, tg, key, isRandom));
    try {
        return future.get();
    } catch (Exception e) {
        s_logger.warn("Unable to get sequeunce for " + tg.table() + ":" + tg.pkColumnValue(), e);
        return null;
    }
}
 
Example #8
Source File: SequenceFetcher.java    From cosmic with Apache License 2.0 5 votes vote down vote up
public <T> T getNextSequence(final Class<T> clazz, final TableGenerator tg, final Object key, final boolean isRandom) {
    final Future<T> future = _executors.submit(new Fetcher<>(clazz, tg, key, isRandom));
    try {
        return future.get();
    } catch (final Exception e) {
        s_logger.warn("Unable to get sequeunce for " + tg.table() + ":" + tg.pkColumnValue(), e);
        return null;
    }
}
 
Example #9
Source File: GenericDaoBase.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected GenericDaoBase() {
    super();
    Type t = getClass().getGenericSuperclass();
    if (t instanceof ParameterizedType) {
        _entityBeanType = (Class<T>)((ParameterizedType)t).getActualTypeArguments()[0];
    } else if (((Class<?>)t).getGenericSuperclass() instanceof ParameterizedType) {
        _entityBeanType = (Class<T>)((ParameterizedType)((Class<?>)t).getGenericSuperclass()).getActualTypeArguments()[0];
    } else {
        _entityBeanType = (Class<T>)((ParameterizedType)((Class<?>)((Class<?>)t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0];
    }

    s_daoMaps.put(_entityBeanType, this);
    Class<?>[] interphaces = _entityBeanType.getInterfaces();
    if (interphaces != null) {
        for (Class<?> interphace : interphaces) {
            s_daoMaps.put(interphace, this);
        }
    }

    _table = DbUtil.getTableName(_entityBeanType);

    final SqlGenerator generator = new SqlGenerator(_entityBeanType);
    _partialSelectSql = generator.buildSelectSql(false);
    _count = generator.buildCountSql();
    _distinctIdSql= generator.buildDistinctIdSql();
    _partialQueryCacheSelectSql = generator.buildSelectSql(true);
    _embeddedFields = generator.getEmbeddedFields();
    _insertSqls = generator.buildInsertSqls();
    final Pair<StringBuilder, Map<String, Object>> dc = generator.buildDiscriminatorClause();
    _discriminatorClause = dc.first().length() == 0 ? null : dc.first();
    _discriminatorValues = dc.second();

    _idAttributes = generator.getIdAttributes();
    _idField = _idAttributes.get(_table).length > 0 ? _idAttributes.get(_table)[0].field : null;

    _tables = generator.buildTableReferences();

    _allAttributes = generator.getAllAttributes();
    _allColumns = generator.getAllColumns();

    _selectByIdSql = buildSelectByIdSql(createPartialSelectSql(null, true));
    _removeSql = generator.buildRemoveSql();
    _deleteSqls = generator.buildDeleteSqls();
    _removed = generator.getRemovedAttribute();
    _tgs = generator.getTableGenerators();
    _ecAttributes = generator.getElementCollectionAttributes();

    TableGenerator tg = this.getClass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }
    tg = this.getClass().getSuperclass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }

    Callback[] callbacks = new Callback[] {NoOp.INSTANCE, new UpdateBuilder(this)};

    _enhancer = new Enhancer();
    _enhancer.setSuperclass(_entityBeanType);
    _enhancer.setCallbackFilter(s_callbackFilter);
    _enhancer.setCallbacks(callbacks);
    _factory = (Factory)_enhancer.create();

    _searchEnhancer = new Enhancer();
    _searchEnhancer.setSuperclass(_entityBeanType);
    _searchEnhancer.setCallback(new UpdateBuilder(this));

    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Select SQL: " + _partialSelectSql.first().toString());
        s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql"));
        s_logger.trace("Select by Id SQL: " + _selectByIdSql);
        s_logger.trace("Table References: " + _tables);
        s_logger.trace("Insert SQLs:");
        for (final Pair<String, Attribute[]> insertSql : _insertSqls) {
            s_logger.trace(insertSql.first());
        }

        s_logger.trace("Delete SQLs");
        for (final Pair<String, Attribute[]> deletSql : _deleteSqls) {
            s_logger.trace(deletSql.first());
        }

        s_logger.trace("Collection SQLs");
        for (Attribute attr : _ecAttributes) {
            EcInfo info = (EcInfo)attr.attache;
            s_logger.trace(info.insertSql);
            s_logger.trace(info.selectSql);
        }
    }

    setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM);
}
 
Example #10
Source File: AnnotationBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static IdentifierGeneratorDefinition buildIdGenerator(
		java.lang.annotation.Annotation generatorAnn,
		MetadataBuildingContext context) {
	if ( generatorAnn == null ) {
		return null;
	}

	IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder();

	if ( context.getMappingDefaults().getImplicitSchemaName() != null ) {
		definitionBuilder.addParam(
				PersistentIdentifierGenerator.SCHEMA,
				context.getMappingDefaults().getImplicitSchemaName()
		);
	}

	if ( context.getMappingDefaults().getImplicitCatalogName() != null ) {
		definitionBuilder.addParam(
				PersistentIdentifierGenerator.CATALOG,
				context.getMappingDefaults().getImplicitCatalogName()
		);
	}

	if ( generatorAnn instanceof TableGenerator ) {
		context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretTableGenerator(
				(TableGenerator) generatorAnn,
				definitionBuilder
		);
		if ( LOG.isTraceEnabled() ) {
			LOG.tracev( "Add table generator with name: {0}", definitionBuilder.getName() );
		}
	}
	else if ( generatorAnn instanceof SequenceGenerator ) {
		context.getBuildingOptions().getIdGenerationTypeInterpreter().interpretSequenceGenerator(
				(SequenceGenerator) generatorAnn,
				definitionBuilder
		);
		if ( LOG.isTraceEnabled() ) {
			LOG.tracev( "Add sequence generator with name: {0}", definitionBuilder.getName() );
		}
	}
	else if ( generatorAnn instanceof GenericGenerator ) {
		GenericGenerator genGen = ( GenericGenerator ) generatorAnn;
		definitionBuilder.setName( genGen.name() );
		definitionBuilder.setStrategy( genGen.strategy() );
		Parameter[] params = genGen.parameters();
		for ( Parameter parameter : params ) {
			definitionBuilder.addParam( parameter.name(), parameter.value() );
		}
		if ( LOG.isTraceEnabled() ) {
			LOG.tracev( "Add generic generator with name: {0}", definitionBuilder.getName() );
		}
	}
	else {
		throw new AssertionFailure( "Unknown Generator annotation: " + generatorAnn );
	}

	return definitionBuilder.build();
}
 
Example #11
Source File: SqlGenerator.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public Map<String, TableGenerator> getTableGenerators() {
    return _generators;
}
 
Example #12
Source File: SequenceFetcher.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
protected Fetcher(Class<T> clazz, TableGenerator tg, Object key, boolean isRandom) {
    _tg = tg;
    _clazz = clazz;
    _key = key;
    this.isRandom = isRandom;
}
 
Example #13
Source File: SequenceFetcher.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public <T> T getRandomNextSequence(Class<T> clazz, TableGenerator tg) {
    return getNextSequence(clazz, tg, null, true);
}
 
Example #14
Source File: SequenceFetcher.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public <T> T getNextSequence(Class<T> clazz, TableGenerator tg, Object key) {
    return getNextSequence(clazz, tg, key, false);
}
 
Example #15
Source File: SequenceFetcher.java    From cloudstack with Apache License 2.0 4 votes vote down vote up
public <T> T getNextSequence(Class<T> clazz, TableGenerator tg) {
    return getNextSequence(clazz, tg, null, false);
}
 
Example #16
Source File: GenericDaoBase.java    From cosmic with Apache License 2.0 4 votes vote down vote up
protected GenericDaoBase() {
    super();
    final Type t = getClass().getGenericSuperclass();
    if (t instanceof ParameterizedType) {
        _entityBeanType = (Class<T>) ((ParameterizedType) t).getActualTypeArguments()[0];
    } else if (((Class<?>) t).getGenericSuperclass() instanceof ParameterizedType) {
        _entityBeanType = (Class<T>) ((ParameterizedType) ((Class<?>) t).getGenericSuperclass()).getActualTypeArguments()[0];
    } else {
        _entityBeanType = (Class<T>) ((ParameterizedType) ((Class<?>) ((Class<?>) t).getGenericSuperclass()).getGenericSuperclass()).getActualTypeArguments()[0];
    }

    s_daoMaps.put(_entityBeanType.getCanonicalName(), this);
    final Class<?>[] interfaceClasses = _entityBeanType.getInterfaces();
    if (interfaceClasses != null) {
        for (final Class<?> interfaceClass : interfaceClasses) {
            s_daoMaps.put(interfaceClass.getCanonicalName(), this);
        }
    }
    logDetectedDaos();

    _table = DbUtil.getTableName(_entityBeanType);

    final SqlGenerator generator = new SqlGenerator(_entityBeanType);
    _partialSelectSql = generator.buildSelectSql(false);
    _count = generator.buildCountSql();
    _distinctIdSql = generator.buildDistinctIdSql();
    _partialQueryCacheSelectSql = generator.buildSelectSql(true);
    _embeddedFields = generator.getEmbeddedFields();
    _insertSqls = generator.buildInsertSqls();
    final Pair<StringBuilder, Map<String, Object>> dc = generator.buildDiscriminatorClause();
    _discriminatorClause = dc.first().length() == 0 ? null : dc.first();
    _discriminatorValues = dc.second();

    _idAttributes = generator.getIdAttributes();
    _idField = _idAttributes.get(_table).length > 0 ? _idAttributes.get(_table)[0].field : null;

    _tables = generator.buildTableReferences();

    _allAttributes = generator.getAllAttributes();
    _allColumns = generator.getAllColumns();

    _selectByIdSql = buildSelectByIdSql(createPartialSelectSql(null, true));
    _removeSql = generator.buildRemoveSql();
    _deleteSqls = generator.buildDeleteSqls();
    _removed = generator.getRemovedAttribute();
    _tgs = generator.getTableGenerators();
    _ecAttributes = generator.getElementCollectionAttributes();

    TableGenerator tg = this.getClass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }
    tg = this.getClass().getSuperclass().getAnnotation(TableGenerator.class);
    if (tg != null) {
        _tgs.put(tg.name(), tg);
    }

    final Callback[] callbacks = new Callback[]{NoOp.INSTANCE, new UpdateBuilder(this)};

    _enhancer = new Enhancer();
    _enhancer.setSuperclass(_entityBeanType);
    _enhancer.setCallbackFilter(s_callbackFilter);
    _enhancer.setCallbacks(callbacks);
    _factory = (Factory) _enhancer.create();

    _searchEnhancer = new Enhancer();
    _searchEnhancer.setSuperclass(_entityBeanType);
    _searchEnhancer.setCallback(new UpdateBuilder(this));

    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Select SQL: " + _partialSelectSql.first().toString());
        s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql"));
        s_logger.trace("Select by Id SQL: " + _selectByIdSql);
        s_logger.trace("Table References: " + _tables);
        s_logger.trace("Insert SQLs:");
        for (final Pair<String, Attribute[]> insertSql : _insertSqls) {
            s_logger.trace(insertSql.first());
        }

        s_logger.trace("Delete SQLs");
        for (final Pair<String, Attribute[]> deletSql : _deleteSqls) {
            s_logger.trace(deletSql.first());
        }

        s_logger.trace("Collection SQLs");
        for (final Attribute attr : _ecAttributes) {
            final EcInfo info = (EcInfo) attr.attache;
            s_logger.trace(info.insertSql);
            s_logger.trace(info.selectSql);
        }
    }

    setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM);
}
 
Example #17
Source File: SqlGenerator.java    From cosmic with Apache License 2.0 4 votes vote down vote up
public Map<String, TableGenerator> getTableGenerators() {
    return _generators;
}
 
Example #18
Source File: SequenceFetcher.java    From cosmic with Apache License 2.0 4 votes vote down vote up
protected Fetcher(final Class<T> clazz, final TableGenerator tg, final Object key, final boolean isRandom) {
    _tg = tg;
    _clazz = clazz;
    _key = key;
    this.isRandom = isRandom;
}
 
Example #19
Source File: SequenceFetcher.java    From cosmic with Apache License 2.0 4 votes vote down vote up
public <T> T getRandomNextSequence(final Class<T> clazz, final TableGenerator tg) {
    return getNextSequence(clazz, tg, null, true);
}
 
Example #20
Source File: SequenceFetcher.java    From cosmic with Apache License 2.0 4 votes vote down vote up
public <T> T getNextSequence(final Class<T> clazz, final TableGenerator tg, final Object key) {
    return getNextSequence(clazz, tg, key, false);
}
 
Example #21
Source File: SequenceFetcher.java    From cosmic with Apache License 2.0 4 votes vote down vote up
public <T> T getNextSequence(final Class<T> clazz, final TableGenerator tg) {
    return getNextSequence(clazz, tg, null, false);
}
 
Example #22
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "mac_address", nullable = false)
@TableGenerator(name = "mac_address_sq", table = "data_center", pkColumnName = "id", valueColumnName = "mac_address", allocationSize = 1)
public long getMacAddress() {
    return super.getMacAddress();
}
 
Example #23
Source File: IdGeneratorInterpreterImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void interpretTableGenerator(
		TableGenerator tableGeneratorAnnotation,
		IdentifierGeneratorDefinition.Builder definitionBuilder) {
	definitionBuilder.setName( tableGeneratorAnnotation.name() );
	definitionBuilder.setStrategy( org.hibernate.id.enhanced.TableGenerator.class.getName() );
	definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" );

	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.catalog() ) ) {
		definitionBuilder.addParam( PersistentIdentifierGenerator.CATALOG, tableGeneratorAnnotation.catalog() );
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.schema() ) ) {
		definitionBuilder.addParam( PersistentIdentifierGenerator.SCHEMA, tableGeneratorAnnotation.schema() );
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.table() ) ) {
		definitionBuilder.addParam(
				org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM,
				tableGeneratorAnnotation.table()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.pkColumnName() ) ) {
		definitionBuilder.addParam(
				org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM,
				tableGeneratorAnnotation.pkColumnName()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.pkColumnValue() ) ) {
		definitionBuilder.addParam(
				org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM,
				tableGeneratorAnnotation.pkColumnValue()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.valueColumnName() ) ) {
		definitionBuilder.addParam(
				org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM,
				tableGeneratorAnnotation.valueColumnName()
		);
	}
	definitionBuilder.addParam(
			org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM,
			String.valueOf( tableGeneratorAnnotation.allocationSize() )
	);
	// See comment on HHH-4884 wrt initialValue.  Basically initialValue is really the stated value + 1
	definitionBuilder.addParam(
			org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM,
			String.valueOf( tableGeneratorAnnotation.initialValue() + 1 )
	);

	// TODO : implement unique-constraint support
	if ( tableGeneratorAnnotation.uniqueConstraints() != null
			&& tableGeneratorAnnotation.uniqueConstraints().length > 0 ) {
		log.ignoringTableGeneratorConstraints( tableGeneratorAnnotation.name() );
	}
}
 
Example #24
Source File: IdGeneratorInterpreterImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void interpretTableGenerator(
		TableGenerator tableGeneratorAnnotation,
		IdentifierGeneratorDefinition.Builder definitionBuilder) {
	definitionBuilder.setName( tableGeneratorAnnotation.name() );
	definitionBuilder.setStrategy( MultipleHiLoPerTableGenerator.class.getName() );

	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.table() ) ) {
		definitionBuilder.addParam(
				MultipleHiLoPerTableGenerator.ID_TABLE,
				tableGeneratorAnnotation.table()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.catalog() ) ) {
		definitionBuilder.addParam(
				PersistentIdentifierGenerator.CATALOG,
				tableGeneratorAnnotation.catalog()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.schema() ) ) {
		definitionBuilder.addParam(
				PersistentIdentifierGenerator.SCHEMA,
				tableGeneratorAnnotation.schema()
		);
	}

	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.pkColumnName() ) ) {
		definitionBuilder.addParam(
				MultipleHiLoPerTableGenerator.PK_COLUMN_NAME,
				tableGeneratorAnnotation.pkColumnName()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.valueColumnName() ) ) {
		definitionBuilder.addParam(
				MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME,
				tableGeneratorAnnotation.valueColumnName()
		);
	}
	if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.pkColumnValue() ) ) {
		definitionBuilder.addParam(
				MultipleHiLoPerTableGenerator.PK_VALUE_NAME,
				tableGeneratorAnnotation.pkColumnValue()
		);
	}
	definitionBuilder.addParam(
			MultipleHiLoPerTableGenerator.MAX_LO,
			String.valueOf( tableGeneratorAnnotation.allocationSize() - 1 )
	);

	// TODO : implement unique-constraint support
	if ( tableGeneratorAnnotation.uniqueConstraints() != null
			&& tableGeneratorAnnotation.uniqueConstraints().length > 0 ) {
		log.ignoringTableGeneratorConstraints( tableGeneratorAnnotation.name() );
	}
}
 
Example #25
Source File: IdGeneratorStrategyInterpreter.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Extract the IdentifierGeneratorDefinition related to the given TableGenerator annotation
 *
 * @param tableGeneratorAnnotation The annotation
 * @param definitionBuilder The IdentifierGeneratorDefinition builder to which to apply
 * any interpreted/extracted configuration
 */
void interpretTableGenerator(TableGenerator tableGeneratorAnnotation, IdentifierGeneratorDefinition.Builder definitionBuilder);