diff --git a/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java b/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java index dc7e81343e..bbc277d898 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/id/factory/DefaultIdentifierGeneratorFactory.java @@ -97,26 +97,6 @@ public class DefaultIdentifierGeneratorFactory implements IdentifierGeneratorFac } } - public static String generatorType(GenerationType generatorEnum, boolean useNewGeneratorMappings) { - switch ( generatorEnum ) { - case IDENTITY: - return "identity"; - case AUTO: - return useNewGeneratorMappings - ? "enhanced-sequence" - : "native"; - case TABLE: - return useNewGeneratorMappings - ? "enhanced-table" - : MultipleHiLoPerTableGenerator.class.getName(); - case SEQUENCE: - return useNewGeneratorMappings - ? "enhanced-sequence" - : "seqhilo"; - } - throw new AssertionFailure( "Unknown GeneratorType: " + generatorEnum ); - } - @Override public void setDialect(Dialect dialect) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java index 6427e0ead2..654a707fa4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/entity/EntityBinder.java @@ -40,7 +40,6 @@ import org.hibernate.annotations.OptimisticLockType; import org.hibernate.annotations.PolymorphismType; import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.access.AccessType; -import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.binding.Caching; import org.hibernate.metamodel.binding.EntityBinding; @@ -63,6 +62,7 @@ import org.hibernate.metamodel.source.annotations.entity.state.binding.ManyToOne import org.hibernate.metamodel.source.annotations.entity.state.relational.ColumnRelationalStateImpl; import org.hibernate.metamodel.source.annotations.entity.state.relational.ManyToOneRelationalStateImpl; import org.hibernate.metamodel.source.annotations.entity.state.relational.TupleRelationalStateImpl; +import org.hibernate.metamodel.source.annotations.global.IdGeneratorBinder; import org.hibernate.metamodel.source.annotations.util.JandexHelper; import org.hibernate.metamodel.source.internal.MetadataImpl; import org.hibernate.metamodel.source.spi.MetadataImplementor; @@ -374,7 +374,7 @@ public class EntityBinder { String generator = JandexHelper.getValueAsString( generatedValueAnn, "generator" ); IdGenerator idGenerator = null; if ( StringHelper.isNotEmpty( generator ) ) { - idGenerator = ( (MetadataImpl) meta ).getIdGenerator( generator ); + idGenerator = meta.getIdGenerator( generator ); if ( idGenerator == null ) { throw new MappingException( String.format( @@ -392,7 +392,7 @@ public class EntityBinder { "strategy", GenerationType.class ); - String strategy = DefaultIdentifierGeneratorFactory.generatorType( + String strategy = IdGeneratorBinder.generatorType( generationType, meta.getOptions().useNewIdentifierGenerators() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java index 102d932a47..9aab618944 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/global/IdGeneratorBinder.java @@ -32,6 +32,7 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.Index; import org.jboss.logging.Logger; +import org.hibernate.AssertionFailure; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerators; import org.hibernate.cfg.AvailableSettings; @@ -41,7 +42,6 @@ import org.hibernate.id.SequenceHiLoGenerator; import org.hibernate.id.TableHiLoGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.TableGenerator; -import org.hibernate.id.factory.DefaultIdentifierGeneratorFactory; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.binding.IdGenerator; @@ -116,7 +116,7 @@ public class IdGeneratorBinder { Map prms = new HashMap(); addStringParameter( generator, "sequenceName", prms, SequenceStyleGenerator.SEQUENCE_PARAM ); boolean useNewIdentifierGenerators = metadata.getOptions().useNewIdentifierGenerators(); - strategy = DefaultIdentifierGeneratorFactory.generatorType( GenerationType.SEQUENCE, useNewIdentifierGenerators); + strategy = generatorType( GenerationType.SEQUENCE, useNewIdentifierGenerators ); if ( useNewIdentifierGenerators ) { addStringParameter( generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG ); addStringParameter( generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA ); @@ -150,7 +150,7 @@ public class IdGeneratorBinder { addStringParameter( generator, "catalog", prms, PersistentIdentifierGenerator.CATALOG ); addStringParameter( generator, "schema", prms, PersistentIdentifierGenerator.SCHEMA ); boolean useNewIdentifierGenerators = metadata.getOptions().useNewIdentifierGenerators(); - strategy = DefaultIdentifierGeneratorFactory.generatorType( GenerationType.TABLE, useNewIdentifierGenerators); + strategy = generatorType( GenerationType.TABLE, useNewIdentifierGenerators ); if ( useNewIdentifierGenerators ) { prms.put( TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" ); addStringParameter( generator, "table", prms, TableGenerator.TABLE_PARAM ); @@ -185,4 +185,24 @@ public class IdGeneratorBinder { private IdGeneratorBinder() { } + + public static String generatorType(GenerationType generatorEnum, boolean useNewGeneratorMappings) { + switch ( generatorEnum ) { + case IDENTITY: + return "identity"; + case AUTO: + return useNewGeneratorMappings + ? "enhanced-sequence" + : "native"; + case TABLE: + return useNewGeneratorMappings + ? "enhanced-table" + : MultipleHiLoPerTableGenerator.class.getName(); + case SEQUENCE: + return useNewGeneratorMappings + ? "enhanced-sequence" + : "seqhilo"; + } + throw new AssertionFailure( "Unknown GeneratorType: " + generatorEnum ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java index 8d3eca77fe..4f30305d24 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/MetadataImpl.java @@ -128,7 +128,7 @@ public class MetadataImpl implements MetadataImplementor, Serializable { public void addIdGenerator(IdGenerator generator) { idGenerators.put( generator.getName(), generator ); } - + @Override public IdGenerator getIdGenerator(String name) { if ( name == null ) { throw new IllegalArgumentException( "null is not a valid generator name" ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetadataImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetadataImplementor.java index 4c59411827..ef2b06b54e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetadataImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/spi/MetadataImplementor.java @@ -27,6 +27,7 @@ import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.metamodel.Metadata; import org.hibernate.metamodel.binding.EntityBinding; import org.hibernate.metamodel.binding.FetchProfile; +import org.hibernate.metamodel.binding.IdGenerator; import org.hibernate.metamodel.binding.PluralAttributeBinding; import org.hibernate.metamodel.binding.TypeDef; import org.hibernate.metamodel.relational.Database; @@ -62,4 +63,5 @@ public interface MetadataImplementor extends Metadata { public void addFilterDefinition(FilterDefinition filterDefinition); public Iterable getFilterDefinitions(); + public IdGenerator getIdGenerator(String name); }