HHH-6261
This commit is contained in:
parent
ec0e823b64
commit
32a320d078
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
|
|
|
@ -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<String, String> prms = new HashMap<String, String>();
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" );
|
||||
|
|
|
@ -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<FilterDefinition> getFilterDefinitions();
|
||||
public IdGenerator getIdGenerator(String name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue