HHH-18139 deprecate IdentifierGeneratorFactory
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
7f3b777cd1
commit
46dd56c715
|
@ -2261,11 +2261,7 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector,
|
|||
// It was done this way in the old code too, so no "regression" here; but
|
||||
// it could be done better
|
||||
try {
|
||||
final Generator generator = identifierValueBinding.createGenerator(
|
||||
bootstrapContext.getIdentifierGeneratorFactory(),
|
||||
dialect,
|
||||
entityBinding
|
||||
);
|
||||
final Generator generator = identifierValueBinding.createGenerator( dialect, entityBinding );
|
||||
|
||||
if ( generator instanceof ExportableProducer ) {
|
||||
( (ExportableProducer) generator ).registerExportables( getDatabase() );
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.boot.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -63,7 +62,6 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.TimeZoneSupport;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
|
@ -71,8 +69,6 @@ import org.hibernate.internal.CoreLogging;
|
|||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.internal.util.NullnessHelper;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.CollectionClassification;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||
|
@ -777,7 +773,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
return mappingDefaults;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override @Deprecated
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return identifierGeneratorFactory;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
|
|||
return delegate.getMappingDefaults();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override @Deprecated
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return delegate.getIdentifierGeneratorFactory();
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ public interface BootstrapContext {
|
|||
*/
|
||||
MetadataBuildingOptions getMetadataBuildingOptions();
|
||||
|
||||
@Deprecated(since="7.0", forRemoval = true)
|
||||
default IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return getMetadataBuildingOptions().getIdentifierGeneratorFactory();
|
||||
}
|
||||
|
|
|
@ -50,7 +50,10 @@ public interface MetadataBuildingOptions {
|
|||
* The service implementing {@link IdentifierGeneratorFactory}.
|
||||
* <p>
|
||||
* @implNote Almost always a {@link org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory}.
|
||||
*
|
||||
* @deprecated Use new {@link org.hibernate.generator.Generator} infrastructure
|
||||
*/
|
||||
@Deprecated(since="7.0", forRemoval = true)
|
||||
IdentifierGeneratorFactory getIdentifierGeneratorFactory();
|
||||
|
||||
/**
|
||||
|
|
|
@ -44,8 +44,11 @@ import jakarta.persistence.GenerationType;
|
|||
* {@link org.hibernate.annotations.IdGeneratorType @IdGeneratorType} meta-annotation.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @deprecated Use new {@link Generator} infrastructure
|
||||
*/
|
||||
@Incubating //this API is currently in flux
|
||||
@Deprecated(since = "7.0")
|
||||
public interface IdentifierGeneratorFactory extends Service {
|
||||
/**
|
||||
* Create an {@link IdentifierGenerator} based on the given details.
|
||||
|
|
|
@ -57,7 +57,10 @@ import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
|
|||
* declared using {@link org.hibernate.annotations.GenericGenerator}.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @deprecated Use new {@link Generator} infrastructure
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public class StandardIdentifierGeneratorFactory
|
||||
implements IdentifierGeneratorFactory, BeanContainer.LifecycleOptions, Serializable {
|
||||
|
||||
|
|
|
@ -14,5 +14,8 @@
|
|||
* It is used when id generators are identified by stringly-typed names.
|
||||
*
|
||||
* @see org.hibernate.id.factory.IdentifierGeneratorFactory
|
||||
*
|
||||
* @deprecated Use new {@link org.hibernate.generator.Generator} infrastructure
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
package org.hibernate.id.factory;
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
package org.hibernate.id.factory.spi;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
import org.hibernate.generator.GeneratorCreationContext;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
|
||||
@Incubating
|
||||
public interface CustomIdGeneratorCreationContext extends GeneratorCreationContext {
|
||||
IdentifierGeneratorFactory getIdentifierGeneratorFactory();
|
||||
RootClass getRootClass();
|
||||
|
||||
// we could add these if it helps integrate old infrastructure
|
||||
|
|
|
@ -7,5 +7,8 @@
|
|||
|
||||
/**
|
||||
* Contains an SPI for id generator factories.
|
||||
*
|
||||
* @deprecated Use new {@link org.hibernate.generator.Generator} infrastructure
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
package org.hibernate.id.factory.spi;
|
||||
|
|
|
@ -73,7 +73,6 @@ import org.hibernate.generator.Generator;
|
|||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.id.Configurable;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.integrator.spi.Integrator;
|
||||
import org.hibernate.integrator.spi.IntegratorService;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
@ -288,7 +287,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
try {
|
||||
integrate( bootMetamodel, bootstrapContext, integratorObserver );
|
||||
|
||||
identifierGenerators = createGenerators( jdbcServices, sqlStringGenerationContext, bootMetamodel, bootstrapContext );
|
||||
identifierGenerators = createGenerators( jdbcServices, sqlStringGenerationContext, bootMetamodel );
|
||||
bootMetamodel.orderColumns( false );
|
||||
bootMetamodel.validate();
|
||||
|
||||
|
@ -463,18 +462,13 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
private static Map<String, Generator> createGenerators(
|
||||
JdbcServices jdbcServices,
|
||||
SqlStringGenerationContext sqlStringGenerationContext,
|
||||
MetadataImplementor bootMetamodel,
|
||||
BootstrapContext bootstrapContext) {
|
||||
MetadataImplementor bootMetamodel) {
|
||||
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
|
||||
final Map<String, Generator> generators = new HashMap<>();
|
||||
bootMetamodel.getEntityBindings().stream()
|
||||
.filter( model -> !model.isInherited() )
|
||||
.forEach( model -> {
|
||||
final Generator generator = model.getIdentifier().createGenerator(
|
||||
bootstrapContext.getIdentifierGeneratorFactory(),
|
||||
jdbcServices.getJdbcEnvironment().getDialect(),
|
||||
(RootClass) model
|
||||
);
|
||||
if ( generator instanceof Configurable ) {
|
||||
for ( PersistentClass model : bootMetamodel.getEntityBindings() ) {
|
||||
if ( !model.isInherited() ) {
|
||||
final Generator generator = model.getIdentifier().createGenerator( dialect, (RootClass) model );
|
||||
if (generator instanceof Configurable) {
|
||||
final Configurable identifierGenerator = (Configurable) generator;
|
||||
identifierGenerator.initialize( sqlStringGenerationContext );
|
||||
}
|
||||
|
@ -482,7 +476,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
( (SimpleValue) model.getIdentifier() ).setNullValue( "undefined" );
|
||||
}
|
||||
generators.put( model.getEntityName(), generator );
|
||||
} );
|
||||
}
|
||||
}
|
||||
return generators;
|
||||
}
|
||||
|
||||
|
@ -775,10 +770,6 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
|||
return sqlStringGenerationContext;
|
||||
}
|
||||
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public DeserializationResolver<?> getDeserializationResolver() {
|
||||
return () -> (SessionFactoryImplementor)
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
|||
import org.hibernate.id.CompositeNestedGeneratedValueGenerator;
|
||||
import org.hibernate.id.Configurable;
|
||||
import org.hibernate.id.IdentifierGenerationException;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
|
@ -669,27 +668,17 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
|
|||
}
|
||||
|
||||
@Override
|
||||
public Generator createGenerator(
|
||||
IdentifierGeneratorFactory identifierGeneratorFactory,
|
||||
Dialect dialect,
|
||||
RootClass rootClass) throws MappingException {
|
||||
public Generator createGenerator(Dialect dialect, RootClass rootClass) throws MappingException {
|
||||
if ( builtIdentifierGenerator == null ) {
|
||||
builtIdentifierGenerator = buildIdentifierGenerator(
|
||||
identifierGeneratorFactory,
|
||||
dialect,
|
||||
rootClass
|
||||
);
|
||||
builtIdentifierGenerator = buildIdentifierGenerator( dialect, rootClass );
|
||||
}
|
||||
return builtIdentifierGenerator;
|
||||
}
|
||||
|
||||
private Generator buildIdentifierGenerator(
|
||||
IdentifierGeneratorFactory identifierGeneratorFactory,
|
||||
Dialect dialect,
|
||||
RootClass rootClass) throws MappingException {
|
||||
private Generator buildIdentifierGenerator( Dialect dialect, RootClass rootClass) throws MappingException {
|
||||
final boolean hasCustomGenerator = ! DEFAULT_ID_GEN_STRATEGY.equals( getIdentifierGeneratorStrategy() );
|
||||
if ( hasCustomGenerator ) {
|
||||
return super.createGenerator( identifierGeneratorFactory, dialect, rootClass );
|
||||
return super.createGenerator( dialect, rootClass );
|
||||
}
|
||||
|
||||
final Class<?> entityClass = rootClass.getMappedClass();
|
||||
|
@ -724,7 +713,7 @@ public class Component extends SimpleValue implements MetaAttributable, Sortable
|
|||
// skip any 'assigned' generators, they would have been handled by
|
||||
// the StandardGenerationContextLocator
|
||||
generator.addGeneratedValuePlan( new ValueGenerationPlan(
|
||||
value.createGenerator( identifierGeneratorFactory, dialect, rootClass ),
|
||||
value.createGenerator( dialect, rootClass ),
|
||||
getType().isMutable() ? injector( property, attributeDeclarer ) : null,
|
||||
i
|
||||
) );
|
||||
|
|
|
@ -29,13 +29,10 @@ public interface KeyValue extends Value {
|
|||
|
||||
boolean isUpdateable();
|
||||
|
||||
Generator createGenerator(
|
||||
IdentifierGeneratorFactory identifierGeneratorFactory,
|
||||
Dialect dialect,
|
||||
RootClass rootClass);
|
||||
Generator createGenerator(Dialect dialect, RootClass rootClass);
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead.
|
||||
* @deprecated Use {@link #createGenerator(Dialect, RootClass)} instead.
|
||||
* No longer used except in legacy tests.
|
||||
*
|
||||
* @return {@code null} if the {@code Generator} returned by {@link #createGenerator} is not an instance
|
||||
|
@ -48,12 +45,12 @@ public interface KeyValue extends Value {
|
|||
String defaultCatalog,
|
||||
String defaultSchema,
|
||||
RootClass rootClass) {
|
||||
final Generator generator = createGenerator( identifierGeneratorFactory, dialect, rootClass );
|
||||
final Generator generator = createGenerator( dialect, rootClass );
|
||||
return generator instanceof IdentifierGenerator ? (IdentifierGenerator) generator : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #createGenerator(IdentifierGeneratorFactory, Dialect, RootClass)} instead.
|
||||
* @deprecated Use {@link #createGenerator(Dialect, RootClass)} instead.
|
||||
* No longer used except in legacy tests.
|
||||
*
|
||||
* @return {@code null} if the {@code Generator} returned by {@link #createGenerator} is not an instance
|
||||
|
@ -64,7 +61,7 @@ public interface KeyValue extends Value {
|
|||
IdentifierGeneratorFactory identifierGeneratorFactory,
|
||||
Dialect dialect,
|
||||
RootClass rootClass) {
|
||||
final Generator generator = createGenerator( identifierGeneratorFactory, dialect, rootClass );
|
||||
final Generator generator = createGenerator( dialect, rootClass );
|
||||
return generator instanceof IdentifierGenerator ? (IdentifierGenerator) generator : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.hibernate.dialect.Dialect;
|
|||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.generator.Generator;
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
@ -391,14 +390,11 @@ public abstract class SimpleValue implements KeyValue {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Generator createGenerator(
|
||||
IdentifierGeneratorFactory identifierGeneratorFactory,
|
||||
Dialect dialect,
|
||||
RootClass rootClass) throws MappingException {
|
||||
public Generator createGenerator(Dialect dialect, RootClass rootClass) throws MappingException {
|
||||
if ( generator == null ) {
|
||||
if ( customIdGeneratorCreator != null ) {
|
||||
generator = customIdGeneratorCreator.createGenerator(
|
||||
new IdGeneratorCreationContext( identifierGeneratorFactory, null, null, rootClass )
|
||||
new IdGeneratorCreationContext( null, null, rootClass )
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
@ -1104,23 +1100,16 @@ public abstract class SimpleValue implements KeyValue {
|
|||
}
|
||||
|
||||
private class IdGeneratorCreationContext implements CustomIdGeneratorCreationContext {
|
||||
private final IdentifierGeneratorFactory identifierGeneratorFactory;
|
||||
private final String defaultCatalog;
|
||||
private final String defaultSchema;
|
||||
private final RootClass rootClass;
|
||||
|
||||
public IdGeneratorCreationContext(IdentifierGeneratorFactory identifierGeneratorFactory, String defaultCatalog, String defaultSchema, RootClass rootClass) {
|
||||
this.identifierGeneratorFactory = identifierGeneratorFactory;
|
||||
public IdGeneratorCreationContext(String defaultCatalog, String defaultSchema, RootClass rootClass) {
|
||||
this.defaultCatalog = defaultCatalog;
|
||||
this.defaultSchema = defaultSchema;
|
||||
this.rootClass = rootClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return identifierGeneratorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Database getDatabase() {
|
||||
return buildingContext.getMetadataCollector().getDatabase();
|
||||
|
|
|
@ -639,11 +639,7 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
|
||||
private BeforeExecutionGenerator createGenerator(RuntimeModelCreationContext context, IdentifierCollection collection) {
|
||||
final Generator generator = collection.getIdentifier().createGenerator(
|
||||
context.getBootstrapContext().getIdentifierGeneratorFactory(),
|
||||
context.getDialect(),
|
||||
null
|
||||
);
|
||||
final Generator generator = collection.getIdentifier().createGenerator( context.getDialect(), null );
|
||||
if ( generator.generatedOnExecution() ) {
|
||||
throw new MappingException("must be an BeforeExecutionGenerator"); //TODO fix message
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ import org.hibernate.generator.EventType;
|
|||
import org.hibernate.generator.Generator;
|
||||
import org.hibernate.generator.OnExecutionGenerator;
|
||||
import org.hibernate.id.Configurable;
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.PostInsertIdentityPersister;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext;
|
||||
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
@ -24,16 +25,20 @@ import java.util.Properties;
|
|||
public class NativeGenerator
|
||||
implements OnExecutionGenerator, BeforeExecutionGenerator, Configurable, ExportableProducer {
|
||||
|
||||
private final IdentifierGeneratorFactory factory;
|
||||
private final String strategy;
|
||||
|
||||
private Generator generator;
|
||||
private final Generator generator;
|
||||
|
||||
public NativeGenerator(NativeId nativeId, Member member, CustomIdGeneratorCreationContext creationContext) {
|
||||
factory = creationContext.getIdentifierGeneratorFactory();
|
||||
strategy = creationContext.getDatabase().getDialect().getNativeIdentifierGeneratorStrategy();
|
||||
if ( "identity".equals(strategy) ) {
|
||||
final String strategy = creationContext.getDatabase().getDialect().getNativeIdentifierGeneratorStrategy();
|
||||
switch (strategy) {
|
||||
case "sequence":
|
||||
generator = new SequenceStyleGenerator();
|
||||
break;
|
||||
case "identity":
|
||||
creationContext.getProperty().getValue().getColumns().get(0).setIdentity(true);
|
||||
generator = new IdentityGenerator();
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,22 +54,9 @@ public class NativeGenerator
|
|||
|
||||
@Override
|
||||
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) {
|
||||
generator = factory.createIdentifierGenerator(strategy, type, parameters);
|
||||
//TODO: should use this instead of the deprecated method, but see HHH-18135
|
||||
// GenerationType generationType;
|
||||
// switch (strategy) {
|
||||
// case "identity":
|
||||
// generationType = GenerationType.IDENTITY;
|
||||
// break;
|
||||
// case "sequence":
|
||||
// generationType = GenerationType.SEQUENCE;
|
||||
// break;
|
||||
// default:
|
||||
// throw new AssertionFailure("unrecognized strategy");
|
||||
// }
|
||||
// generator =
|
||||
// factory.createIdentifierGenerator( generationType, strategy, strategy, type.getJavaTypeDescriptor(),
|
||||
// parameters, (a, b) -> null );
|
||||
if ( generator instanceof Configurable ) {
|
||||
((Configurable) generator).configure( type, parameters, serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue