QueryBinder.bindNamedStoredProcedureQuery( annotation, mappings, isDefault );
}
}
private static IdGenerator buildIdGenerator(java.lang.annotation.Annotation ann, Mappings mappings) {
IdGenerator idGen = new IdGenerator();
if ( mappings.getSchemaName() != null ) {
idGen.addParam( PersistentIdentifierGenerator.SCHEMA, mappings.getSchemaName() );
}
if ( mappings.getCatalogName() != null ) {
idGen.addParam( PersistentIdentifierGenerator.CATALOG, mappings.getCatalogName() );
}
final boolean useNewGeneratorMappings = mappings.useNewGeneratorMappings();
if ( ann == null ) {
idGen = null;
}
else if ( ann instanceof TableGenerator ) {
TableGenerator tabGen = ( TableGenerator ) ann;
idGen.setName( tabGen.name() );
if ( useNewGeneratorMappings ) {
idGen.setIdentifierGeneratorStrategy( org.hibernate.id.enhanced.TableGenerator.class.getName() );
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" );
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.catalog() ) ) {
idGen.addParam( PersistentIdentifierGenerator.CATALOG, tabGen.catalog() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.schema() ) ) {
idGen.addParam( PersistentIdentifierGenerator.SCHEMA, tabGen.schema() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.table() ) ) {
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, tabGen.table() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnName() ) ) {
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, tabGen.pkColumnName()
);
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnValue() ) ) {
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, tabGen.pkColumnValue()
);
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.valueColumnName() ) ) {
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, tabGen.valueColumnName()
);
}
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM,
String.valueOf( tabGen.allocationSize() )
);
// See comment on HHH-4884 wrt initialValue. Basically initialValue is really the stated value + 1
idGen.addParam(
org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM,
String.valueOf( tabGen.initialValue() + 1 )
);
if (tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length > 0) LOG.warn(tabGen.name());
}
else {
idGen.setIdentifierGeneratorStrategy( MultipleHiLoPerTableGenerator.class.getName() );
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.table() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.ID_TABLE, tabGen.table() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.catalog() ) ) {
idGen.addParam( PersistentIdentifierGenerator.CATALOG, tabGen.catalog() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.schema() ) ) {
idGen.addParam( PersistentIdentifierGenerator.SCHEMA, tabGen.schema() );
}
//FIXME implement uniqueconstrains
if (tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length > 0) LOG.ignoringTableGeneratorConstraints(tabGen.name());
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnName() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, tabGen.pkColumnName() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.valueColumnName() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, tabGen.valueColumnName() );
}
if ( !BinderHelper.isEmptyAnnotationValue( tabGen.pkColumnValue() ) ) {
idGen.addParam( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, tabGen.pkColumnValue() );
}
idGen.addParam( TableHiLoGenerator.MAX_LO, String.valueOf( tabGen.allocationSize() - 1 ) );
}
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Add table generator with name: {0}", idGen.getName() );
}
}
else if ( ann instanceof SequenceGenerator ) {
SequenceGenerator seqGen = ( SequenceGenerator ) ann;
idGen.setName( seqGen.name() );
if ( useNewGeneratorMappings ) {
idGen.setIdentifierGeneratorStrategy( SequenceStyleGenerator.class.getName() );
if ( !BinderHelper.isEmptyAnnotationValue( seqGen.catalog() ) ) {
idGen.addParam( PersistentIdentifierGenerator.CATALOG, seqGen.catalog() );
}
if ( !BinderHelper.isEmptyAnnotationValue( seqGen.schema() ) ) {
idGen.addParam( PersistentIdentifierGenerator.SCHEMA, seqGen.schema() );
}
if ( !BinderHelper.isEmptyAnnotationValue( seqGen.sequenceName() ) ) {
idGen.addParam( SequenceStyleGenerator.SEQUENCE_PARAM, seqGen.sequenceName() );
}
idGen.addParam( SequenceStyleGenerator.INCREMENT_PARAM, String.valueOf( seqGen.allocationSize() ) );
idGen.addParam( SequenceStyleGenerator.INITIAL_PARAM, String.valueOf( seqGen.initialValue() ) );
}
else {
idGen.setIdentifierGeneratorStrategy( "seqhilo" );
if ( !BinderHelper.isEmptyAnnotationValue( seqGen.sequenceName() ) ) {
idGen.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, seqGen.sequenceName() );
}
//FIXME: work on initialValue() through SequenceGenerator.PARAMETERS
// steve : or just use o.h.id.enhanced.SequenceStyleGenerator
if ( seqGen.initialValue() != 1 ) {
LOG.unsupportedInitialValue( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS );
}
idGen.addParam( SequenceHiLoGenerator.MAX_LO, String.valueOf( seqGen.allocationSize() - 1 ) );
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Add sequence generator with name: {0}", idGen.getName() );
}
}
}
else if ( ann instanceof GenericGenerator ) {
GenericGenerator genGen = ( GenericGenerator ) ann;
idGen.setName( genGen.name() );
idGen.setIdentifierGeneratorStrategy( genGen.strategy() );
Parameter[] params = genGen.parameters();
for ( Parameter parameter : params ) {
idGen.addParam( parameter.name(), parameter.value() );
}
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Add generic generator with name: {0}", idGen.getName() );
}
}
else {
throw new AssertionFailure( "Unknown Generator annotation: " + ann );
}