HHH-18139 completely remove org.hibernate.id.factory.*

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-05-20 12:31:19 +02:00 committed by Steve Ebersole
parent 51acbd04dc
commit e7196be0f2
54 changed files with 49 additions and 1083 deletions

View File

@ -64,7 +64,6 @@ import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl; import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.internal.log.DeprecationLogger;
@ -577,7 +576,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware { implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware {
private final StandardServiceRegistry serviceRegistry; private final StandardServiceRegistry serviceRegistry;
private final MappingDefaultsImpl mappingDefaults; private final MappingDefaultsImpl mappingDefaults;
private final IdentifierGeneratorFactory identifierGeneratorFactory;
private final TimeZoneStorageType defaultTimezoneStorage; private final TimeZoneStorageType defaultTimezoneStorage;
private final WrapperArrayHandling wrapperArrayHandling; private final WrapperArrayHandling wrapperArrayHandling;
@ -607,7 +605,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) { public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry; this.serviceRegistry = serviceRegistry;
this.identifierGeneratorFactory = serviceRegistry.getService( IdentifierGeneratorFactory.class );
final StrategySelector strategySelector = serviceRegistry.requireService( StrategySelector.class ); final StrategySelector strategySelector = serviceRegistry.requireService( StrategySelector.class );
final ConfigurationService configService = serviceRegistry.requireService( ConfigurationService.class ); final ConfigurationService configService = serviceRegistry.requireService( ConfigurationService.class );
@ -773,11 +770,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
return mappingDefaults; return mappingDefaults;
} }
@Override @Deprecated
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
return identifierGeneratorFactory;
}
@Override @Override
public TimeZoneStorageStrategy getDefaultTimeZoneStorage() { public TimeZoneStorageStrategy getDefaultTimeZoneStorage() {
return toTimeZoneStorageStrategy( getTimeZoneSupport() ); return toTimeZoneStorageStrategy( getTimeZoneSupport() );

View File

@ -51,7 +51,7 @@ import org.hibernate.id.UUIDHexGenerator;
import org.hibernate.id.enhanced.LegacyNamingStrategy; import org.hibernate.id.enhanced.LegacyNamingStrategy;
import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.enhanced.SingleNamingStrategy; import org.hibernate.id.enhanced.SingleNamingStrategy;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.generator.CustomIdGeneratorCreationContext;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.GeneratorCreator; import org.hibernate.mapping.GeneratorCreator;

View File

@ -17,7 +17,6 @@ import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.dialect.TimeZoneSupport; import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.type.WrapperArrayHandling; import org.hibernate.type.WrapperArrayHandling;
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
@ -53,11 +52,6 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
return delegate.getMappingDefaults(); return delegate.getMappingDefaults();
} }
@Override @Deprecated
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
return delegate.getIdentifierGeneratorFactory();
}
@Override @Override
public TimeZoneStorageStrategy getDefaultTimeZoneStorage() { public TimeZoneStorageStrategy getDefaultTimeZoneStorage() {
return delegate.getDefaultTimeZoneStorage(); return delegate.getDefaultTimeZoneStorage();

View File

@ -19,7 +19,6 @@ import org.hibernate.boot.internal.ClassmateContext;
import org.hibernate.boot.model.convert.spi.ConverterDescriptor; import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject; import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.jpa.spi.MutableJpaCompliance; import org.hibernate.jpa.spi.MutableJpaCompliance;
import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver; import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
@ -75,11 +74,6 @@ public interface BootstrapContext {
*/ */
MetadataBuildingOptions getMetadataBuildingOptions(); MetadataBuildingOptions getMetadataBuildingOptions();
@Deprecated(since="7.0", forRemoval = true)
default IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
return getMetadataBuildingOptions().getIdentifierGeneratorFactory();
}
/** /**
* Whether the bootstrap was initiated from JPA bootstrapping. * Whether the bootstrap was initiated from JPA bootstrapping.
* *

View File

@ -18,7 +18,6 @@ import org.hibernate.collection.internal.StandardCollectionSemanticsResolver;
import org.hibernate.collection.spi.CollectionSemanticsResolver; import org.hibernate.collection.spi.CollectionSemanticsResolver;
import org.hibernate.dialect.TimeZoneSupport; import org.hibernate.dialect.TimeZoneSupport;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.metamodel.internal.ManagedTypeRepresentationResolverStandard; import org.hibernate.metamodel.internal.ManagedTypeRepresentationResolverStandard;
import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver; import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver;
import org.hibernate.type.WrapperArrayHandling; import org.hibernate.type.WrapperArrayHandling;
@ -46,16 +45,6 @@ public interface MetadataBuildingOptions {
*/ */
MappingDefaults getMappingDefaults(); MappingDefaults getMappingDefaults();
/**
* 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();
/** /**
* @return the {@link TimeZoneStorageStrategy} determined by the global configuration * @return the {@link TimeZoneStorageStrategy} determined by the global configuration
* property and the {@linkplain #getTimeZoneSupport() time zone support} of * property and the {@linkplain #getTimeZoneSupport() time zone support} of
@ -80,6 +69,10 @@ public interface MetadataBuildingOptions {
*/ */
WrapperArrayHandling getWrapperArrayHandling(); WrapperArrayHandling getWrapperArrayHandling();
/**
* @deprecated no longer called
*/
@Deprecated(since="7.0", forRemoval = true)
default ManagedTypeRepresentationResolver getManagedTypeRepresentationResolver() { default ManagedTypeRepresentationResolver getManagedTypeRepresentationResolver() {
// for now always return the standard one // for now always return the standard one
return ManagedTypeRepresentationResolverStandard.INSTANCE; return ManagedTypeRepresentationResolverStandard.INSTANCE;

View File

@ -221,14 +221,4 @@ public interface AvailableSettings
@Deprecated(since = "6.2", forRemoval = true) @Deprecated(since = "6.2", forRemoval = true)
@SuppressWarnings("DeprecatedIsStillUsed") @SuppressWarnings("DeprecatedIsStillUsed")
String FLUSH_MODE = "org.hibernate.flushMode"; String FLUSH_MODE = "org.hibernate.flushMode";
/**
* Specifies a class which implements {@link org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider},
* and has a constructor with no parameters.
*
* @deprecated use {@link org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration} instead
*/
@Deprecated(since = "6.0")
@SuppressWarnings("DeprecatedIsStillUsed")
String IDENTIFIER_GENERATOR_STRATEGY_PROVIDER = "hibernate.identifier_generator_strategy_provider";
} }

View File

@ -4,10 +4,9 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later * License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/ */
package org.hibernate.id.factory.spi; package org.hibernate.generator;
import org.hibernate.Incubating; import org.hibernate.Incubating;
import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.mapping.RootClass; import org.hibernate.mapping.RootClass;
@Incubating @Incubating

View File

@ -8,7 +8,6 @@ package org.hibernate.id;
import java.net.InetAddress; import java.net.InetAddress;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.internal.util.BytesHelper; import org.hibernate.internal.util.BytesHelper;
/** /**
@ -22,7 +21,7 @@ import org.hibernate.internal.util.BytesHelper;
* @deprecated since {@link UUIDHexGenerator} is deprecated * @deprecated since {@link UUIDHexGenerator} is deprecated
*/ */
@Deprecated(since = "6") @Deprecated(since = "6")
public abstract class AbstractUUIDGenerator implements IdentifierGenerator, StandardGenerator { public abstract class AbstractUUIDGenerator implements IdentifierGenerator {
private static final int IP; private static final int IP;
static { static {

View File

@ -11,7 +11,6 @@ import java.util.Properties;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -23,7 +22,7 @@ import org.hibernate.type.Type;
* *
* @implNote This also implements the {@code assigned} generation type in {@code hbm.xml} mappings. * @implNote This also implements the {@code assigned} generation type in {@code hbm.xml} mappings.
*/ */
public class Assigned implements IdentifierGenerator, StandardGenerator { public class Assigned implements IdentifierGenerator {
private String entityName; private String entityName;
@Override @Override

View File

@ -16,7 +16,6 @@ import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.ExportableProducer; import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.property.access.spi.Setter; import org.hibernate.property.access.spi.Setter;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
@ -52,7 +51,7 @@ import org.hibernate.type.CompositeType;
*/ */
@Internal @Internal
public class CompositeNestedGeneratedValueGenerator public class CompositeNestedGeneratedValueGenerator
implements IdentifierGenerator, StandardGenerator, IdentifierGeneratorAggregator, Serializable { implements IdentifierGenerator, IdentifierGeneratorAggregator, Serializable {
/** /**
* Contract for declaring how to locate the context for sub-value injection. * Contract for declaring how to locate the context for sub-value injection.
*/ */

View File

@ -11,7 +11,6 @@ import java.util.Properties;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.TransientObjectException; import org.hibernate.TransientObjectException;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
@ -36,7 +35,7 @@ import static org.hibernate.spi.NavigablePath.IDENTIFIER_MAPPER_PROPERTY;
* @deprecated This remains around as an implementation detail of {@code hbm.xml} mappings. * @deprecated This remains around as an implementation detail of {@code hbm.xml} mappings.
*/ */
@Deprecated(since = "6", forRemoval = true) @Deprecated(since = "6", forRemoval = true)
public class ForeignGenerator implements IdentifierGenerator, StandardGenerator { public class ForeignGenerator implements IdentifierGenerator {
private static final CoreMessageLogger LOG = messageLogger( ForeignGenerator.class ); private static final CoreMessageLogger LOG = messageLogger( ForeignGenerator.class );
/** /**

View File

@ -12,7 +12,6 @@ import java.sql.SQLException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
@ -26,7 +25,7 @@ import org.hibernate.internal.CoreMessageLogger;
* @deprecated use {@link org.hibernate.id.uuid.UuidGenerator} * @deprecated use {@link org.hibernate.id.uuid.UuidGenerator}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public class GUIDGenerator implements IdentifierGenerator, StandardGenerator { public class GUIDGenerator implements IdentifierGenerator {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( GUIDGenerator.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( GUIDGenerator.class );
private static boolean WARNED; private static boolean WARNED;

View File

@ -10,7 +10,6 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.generator.OnExecutionGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.id.insert.BasicSelectingDelegate; import org.hibernate.id.insert.BasicSelectingDelegate;
import org.hibernate.id.insert.GetGeneratedKeysDelegate; import org.hibernate.id.insert.GetGeneratedKeysDelegate;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
@ -40,7 +39,7 @@ import static org.hibernate.generator.values.internal.GeneratedValuesHelper.noCu
* @implNote This also implements the {@code identity} generation type in {@code hbm.xml} mappings. * @implNote This also implements the {@code identity} generation type in {@code hbm.xml} mappings.
*/ */
public class IdentityGenerator public class IdentityGenerator
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator { implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator {
@Override @Override
public boolean referenceColumnsInSql(Dialect dialect) { public boolean referenceColumnsInSql(Dialect dialect) {

View File

@ -22,7 +22,6 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
@ -50,7 +49,7 @@ import static org.hibernate.internal.util.StringHelper.split;
* *
* @implNote This also implements the {@code increment} generation type in {@code hbm.xml} mappings. * @implNote This also implements the {@code increment} generation type in {@code hbm.xml} mappings.
*/ */
public class IncrementGenerator implements IdentifierGenerator, StandardGenerator { public class IncrementGenerator implements IdentifierGenerator {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IncrementGenerator.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IncrementGenerator.class );
/** /**

View File

@ -9,12 +9,11 @@ package org.hibernate.id;
import org.hibernate.boot.model.relational.ExportableProducer; import org.hibernate.boot.model.relational.ExportableProducer;
import org.hibernate.id.enhanced.Optimizer; import org.hibernate.id.enhanced.Optimizer;
import org.hibernate.id.enhanced.StandardOptimizerDescriptor; import org.hibernate.id.enhanced.StandardOptimizerDescriptor;
import org.hibernate.id.factory.spi.StandardGenerator;
/** /**
* Commonality between sequence-based and table-based generators * Commonality between sequence-based and table-based generators
*/ */
public interface OptimizableGenerator extends IdentifierGenerator, StandardGenerator, ExportableProducer { public interface OptimizableGenerator extends IdentifierGenerator, ExportableProducer {
/** /**
* If an explicit sequence/table name is not configured, * If an explicit sequence/table name is not configured,
*/ */

View File

@ -10,7 +10,6 @@ import java.util.Properties;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.generator.OnExecutionGenerator; import org.hibernate.generator.OnExecutionGenerator;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -78,7 +77,7 @@ import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPrope
* @implNote This also implements the {@code select} generation type in {@code hbm.xml} mappings. * @implNote This also implements the {@code select} generation type in {@code hbm.xml} mappings.
*/ */
public class SelectGenerator public class SelectGenerator
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator { implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator {
/** /**
* The property specifying the unique key name. * The property specifying the unique key name.

View File

@ -14,7 +14,6 @@ import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.id.uuid.StandardRandomStrategy; import org.hibernate.id.uuid.StandardRandomStrategy;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
@ -41,7 +40,7 @@ import org.hibernate.type.descriptor.java.UUIDJavaType;
* {@link org.hibernate.annotations.UuidGenerator} instead * {@link org.hibernate.annotations.UuidGenerator} instead
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public class UUIDGenerator implements IdentifierGenerator, StandardGenerator { public class UUIDGenerator implements IdentifierGenerator {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( UUIDGenerator.class ); private static final CoreMessageLogger LOG = CoreLogging.messageLogger( UUIDGenerator.class );
public static final String UUID_GEN_STRATEGY = "uuid_gen_strategy"; public static final String UUID_GEN_STRATEGY = "uuid_gen_strategy";

View File

@ -1,23 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory;
import org.hibernate.internal.log.SubSystemLogging;
import org.jboss.logging.Logger;
/**
* Logging related to IdentifierGeneratorFactory
*/
@SubSystemLogging(
name = IdGenFactoryLogging.LOGGER_NAME,
description = "Logging related to creation of IdentifierGenerator instances"
)
public interface IdGenFactoryLogging {
String LOGGER_NAME = SubSystemLogging.BASE + ".idgen.factory";
Logger ID_GEN_FAC_LOGGER = Logger.getLogger( LOGGER_NAME );
}

View File

@ -1,78 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.id.factory;
import java.util.Properties;
import org.hibernate.Incubating;
import org.hibernate.dialect.Dialect;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.generator.Generator;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
/**
* Contract for a factory of {@link IdentifierGenerator} instances. The implementor
* of this service is responsible for providing implementations of the predefined
* built-in id generators, all of which implement {@link IdentifierGenerator}, along
* with any id generator declared using {@link org.hibernate.annotations.GenericGenerator}.
* <p>
* An id generator is identified by either:
* <ul>
* <li>a predefined string-based name (which originated in the old {@code hbm.xml}
* mapping file format),
* <li>the {@link org.hibernate.annotations.GenericGenerator#name name} or the
* the {@link org.hibernate.annotations.GenericGenerator#type type} specified
* by the {@code @GenericGenerator} annotation, or
* <li>a JPA-defined {@link GenerationType}.
* </ul>
* <p>
* A new generator passed a {@link Properties} object containing parameters via the
* method {@link IdentifierGenerator#configure(Type, Properties, ServiceRegistry)}.
* <p>
* This is part of an older mechanism for instantiating and configuring id generators
* which predates the existence of {@link Generator} and the
* {@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.
*/
@Incubating
Generator createIdentifierGenerator(
GenerationType generationType,
String generatedValueGeneratorName,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver);
/**
* Given a strategy, retrieve the appropriate identifier generator instance.
*
* @param strategy The generation strategy.
* @param type The mapping type for the identifier values.
* @param parameters Any parameters properties given in the generator mapping.
*
* @return The appropriate generator instance.
*
* @deprecated use {@link #createIdentifierGenerator(GenerationType, String, String, JavaType, Properties, GeneratorDefinitionResolver)}
*/
@Deprecated(since = "6.0")
Generator createIdentifierGenerator(String strategy, Type type, Properties parameters);
}

View File

@ -1,36 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.internal;
import java.util.Properties;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.GenerationTypeStrategy;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
public class AutoGenerationTypeStrategy implements GenerationTypeStrategy {
/**
* Singleton access
*/
public static final AutoGenerationTypeStrategy INSTANCE = new AutoGenerationTypeStrategy();
@Override
public IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver,
ServiceRegistry serviceRegistry) {
assert generationType == null || generationType == GenerationType.AUTO;
throw new UnsupportedOperationException( "`" + getClass().getName() + "#createIdentifierGenerator not yet implemented" );
}
}

View File

@ -1,35 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.internal;
import java.util.Properties;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.GenerationTypeStrategy;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
public class IdentityGenerationTypeStrategy implements GenerationTypeStrategy {
/**
* Singleton access
*/
public static final IdentityGenerationTypeStrategy INSTANCE = new IdentityGenerationTypeStrategy();
@Override
public IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver,
ServiceRegistry serviceRegistry) {
throw new UnsupportedOperationException( "`" + getClass().getName() + "#createIdentifierGenerator not yet implemented" );
}
}

View File

@ -1,35 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.internal;
import java.util.Properties;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.GenerationTypeStrategy;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
public class SequenceGenerationTypeStrategy implements GenerationTypeStrategy {
/**
* Singleton access
*/
public static final SequenceGenerationTypeStrategy INSTANCE = new SequenceGenerationTypeStrategy();
@Override
public IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver,
ServiceRegistry serviceRegistry) {
throw new UnsupportedOperationException( "`" + getClass().getName() + "#createIdentifierGenerator not yet implemented" );
}
}

View File

@ -1,277 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.id.factory.internal;
import java.io.Serializable;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.hibernate.MappingException;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.generator.Generator;
import org.hibernate.id.Assigned;
import org.hibernate.id.Configurable;
import org.hibernate.id.ForeignGenerator;
import org.hibernate.id.GUIDGenerator;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IdentityGenerator;
import org.hibernate.id.IncrementGenerator;
import org.hibernate.id.SelectGenerator;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.id.UUIDHexGenerator;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.enhanced.TableGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.spi.GenerationTypeStrategy;
import org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.id.factory.spi.StandardGenerator;
import org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider;
import org.hibernate.resource.beans.container.spi.BeanContainer;
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
import org.hibernate.resource.beans.internal.Helper;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
import static org.hibernate.cfg.AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER;
import static org.hibernate.id.factory.IdGenFactoryLogging.ID_GEN_FAC_LOGGER;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
/**
* Basic implementation of {@link org.hibernate.id.factory.IdentifierGeneratorFactory},
* responsible for instantiating the predefined built-in id generators, and generators
* 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 {
private final ConcurrentHashMap<GenerationType, GenerationTypeStrategy> generatorTypeStrategyMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, Class<? extends Generator>> legacyGeneratorClassNameMap = new ConcurrentHashMap<>();
private final ServiceRegistry serviceRegistry;
private final BeanContainer beanContainer;
private Dialect dialect;
/**
* Constructs a new factory
*/
public StandardIdentifierGeneratorFactory(ServiceRegistry serviceRegistry) {
this( serviceRegistry, !Helper.allowExtensionsInCdi( serviceRegistry ) );
}
/**
* Constructs a new factory, explicitly controlling whether to use CDI or not
*/
public StandardIdentifierGeneratorFactory(ServiceRegistry serviceRegistry, boolean ignoreBeanContainer) {
this.serviceRegistry = serviceRegistry;
beanContainer = getBeanContainer( serviceRegistry, ignoreBeanContainer );
registerJpaGenerators();
logOverrides();
registerPredefinedGenerators();
registerUsingLegacyContributor();
}
private static BeanContainer getBeanContainer(ServiceRegistry serviceRegistry, boolean ignoreBeanContainer) {
if (ignoreBeanContainer) {
ID_GEN_FAC_LOGGER.debug( "Ignoring CDI for resolving IdentifierGenerator instances as extended or delayed CDI support was enabled" );
return null;
}
else {
final BeanContainer beanContainer =
serviceRegistry.requireService( ManagedBeanRegistry.class )
.getBeanContainer();
if ( beanContainer == null ) {
ID_GEN_FAC_LOGGER.debug( "Resolving IdentifierGenerator instances will not use CDI as it was not configured" );
}
return beanContainer;
}
}
private void registerJpaGenerators() {
generatorTypeStrategyMap.put( GenerationType.AUTO, AutoGenerationTypeStrategy.INSTANCE );
generatorTypeStrategyMap.put( GenerationType.SEQUENCE, SequenceGenerationTypeStrategy.INSTANCE );
generatorTypeStrategyMap.put( GenerationType.TABLE, TableGenerationTypeStrategy.INSTANCE );
generatorTypeStrategyMap.put( GenerationType.IDENTITY, IdentityGenerationTypeStrategy.INSTANCE );
generatorTypeStrategyMap.put( GenerationType.UUID, UUIDGenerationTypeStrategy.INSTANCE );
}
private void logOverrides() {
serviceRegistry.requireService( ClassLoaderService.class )
.loadJavaServices( GenerationTypeStrategyRegistration.class )
.forEach( (registration) -> registration.registerStrategies(
(generationType, generationTypeStrategy) -> {
final GenerationTypeStrategy previous =
generatorTypeStrategyMap.put( generationType, generationTypeStrategy );
if ( previous != null ) {
ID_GEN_FAC_LOGGER.debugf(
"GenerationTypeStrategyRegistration [%s] overrode previous registration for GenerationType#%s : %s",
registration,
generationType.name(),
previous
);
}
},
serviceRegistry
) );
}
private void registerPredefinedGenerators() {
register( "uuid2", UUIDGenerator.class );
// can be done with UuidGenerator + strategy
register( "guid", GUIDGenerator.class );
register( "uuid", UUIDHexGenerator.class ); // "deprecated" for new use
register( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
register( "assigned", Assigned.class );
register( "identity", IdentityGenerator.class );
register( "select", SelectGenerator.class );
register( "sequence", SequenceStyleGenerator.class );
register( "increment", IncrementGenerator.class );
register( "foreign", ForeignGenerator.class );
register( "enhanced-sequence", SequenceStyleGenerator.class );
register( "enhanced-table", TableGenerator.class );
}
private void registerUsingLegacyContributor() {
final ConfigurationService configService = serviceRegistry.requireService( ConfigurationService.class );
final Object providerSetting = configService.getSettings().get( IDENTIFIER_GENERATOR_STRATEGY_PROVIDER );
if ( providerSetting != null ) {
DEPRECATION_LOGGER.deprecatedSetting2(
IDENTIFIER_GENERATOR_STRATEGY_PROVIDER,
"supply a org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration Java service"
);
final IdentifierGeneratorStrategyProvider idGeneratorStrategyProvider =
serviceRegistry.requireService( StrategySelector.class )
.resolveStrategy( IdentifierGeneratorStrategyProvider.class, providerSetting );
for ( Map.Entry<String,Class<?>> entry : idGeneratorStrategyProvider.getStrategies().entrySet() ) {
@SuppressWarnings({"rawtypes", "unchecked"})
Class<? extends IdentifierGenerator> generatorClass = (Class) entry.getValue();
register( entry.getKey(), generatorClass );
}
}
}
private void register(String strategy, Class<? extends Generator> generatorClass) {
ID_GEN_FAC_LOGGER.debugf( "Registering IdentifierGenerator strategy [%s] -> [%s]", strategy, generatorClass.getName() );
final Class<?> previous = legacyGeneratorClassNameMap.put( strategy, generatorClass );
if ( previous != null && ID_GEN_FAC_LOGGER.isDebugEnabled() ) {
ID_GEN_FAC_LOGGER.debugf( " - overriding [%s]", previous.getName() );
}
}
@Override
public IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatedValueGeneratorName,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver) {
final GenerationTypeStrategy strategy = generatorTypeStrategyMap.get( generationType );
if ( strategy != null ) {
return strategy.createIdentifierGenerator(
generationType,
generatorName,
javaType,
config,
definitionResolver,
serviceRegistry
);
}
throw new UnsupportedOperationException( "No GenerationTypeStrategy specified" );
}
private Dialect getDialect() {
if ( dialect == null ) {
dialect = serviceRegistry.requireService( JdbcEnvironment.class ).getDialect();
}
return dialect;
}
@Override @Deprecated
public Generator createIdentifierGenerator(String strategy, Type type, Properties parameters) {
try {
final Class<? extends Generator> clazz = getIdentifierGeneratorClass( strategy );
final Generator identifierGenerator;
if ( beanContainer == null
|| StandardGenerator.class.isAssignableFrom( clazz )
|| legacyGeneratorClassNameMap.containsKey( strategy ) ) {
identifierGenerator = clazz.newInstance();
}
else {
identifierGenerator =
beanContainer.getBean( clazz, this, FallbackBeanInstanceProducer.INSTANCE )
.getBeanInstance();
}
if ( identifierGenerator instanceof Configurable ) {
( (Configurable) identifierGenerator ).configure( type, parameters, serviceRegistry );
}
return identifierGenerator;
}
catch ( Exception e ) {
final String entityName = parameters.getProperty( IdentifierGenerator.ENTITY_NAME );
throw new MappingException( String.format( "Could not instantiate id generator [entity-name=%s]", entityName ), e );
}
}
@Override
public boolean canUseCachedReferences() {
return false;
}
@Override
public boolean useJpaCompliantCreation() {
return true;
}
private Class<? extends Generator> getIdentifierGeneratorClass(String strategy) {
switch ( strategy ) {
case "hilo":
throw new UnsupportedOperationException( "Support for 'hilo' generator has been removed" );
case "native":
strategy = getDialect().getNativeIdentifierGeneratorStrategy();
//then fall through:
default:
Class<? extends Generator> generatorClass = legacyGeneratorClassNameMap.get( strategy );
return generatorClass != null ? generatorClass : generatorClassForName( strategy );
}
}
private Class<? extends Generator> generatorClassForName(String strategy) {
try {
Class<? extends Generator> clazz =
serviceRegistry.requireService( ClassLoaderService.class )
.classForName( strategy );
if ( !Generator.class.isAssignableFrom( clazz ) ) {
// in principle, this shouldn't happen, since @GenericGenerator
// constrains the type to subtypes of Generator
throw new MappingException( clazz.getName() + " does not implement 'Generator'" );
}
return clazz;
}
catch ( ClassLoadingException e ) {
throw new MappingException( String.format( "Could not interpret id generator strategy [%s]", strategy ) );
}
}
}

View File

@ -1,27 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.id.factory.internal;
import java.util.Map;
import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.service.spi.ServiceRegistryImplementor;
public class StandardIdentifierGeneratorFactoryInitiator implements StandardServiceInitiator<IdentifierGeneratorFactory> {
public static final StandardIdentifierGeneratorFactoryInitiator INSTANCE = new StandardIdentifierGeneratorFactoryInitiator();
@Override
public Class<IdentifierGeneratorFactory> getServiceInitiated() {
return IdentifierGeneratorFactory.class;
}
@Override
public IdentifierGeneratorFactory initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
return new StandardIdentifierGeneratorFactory( registry );
}
}

View File

@ -1,35 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.internal;
import java.util.Properties;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.GenerationTypeStrategy;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
public class TableGenerationTypeStrategy implements GenerationTypeStrategy {
/**
* Singleton access
*/
public static final TableGenerationTypeStrategy INSTANCE = new TableGenerationTypeStrategy();
@Override
public IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver,
ServiceRegistry serviceRegistry) {
throw new UnsupportedOperationException( "`" + getClass().getName() + "#createIdentifierGenerator not yet implemented" );
}
}

View File

@ -1,35 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.internal;
import java.util.Properties;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.GenerationTypeStrategy;
import org.hibernate.id.factory.spi.GeneratorDefinitionResolver;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
import jakarta.persistence.GenerationType;
public class UUIDGenerationTypeStrategy implements GenerationTypeStrategy {
/**
* Singleton access
*/
public static final UUIDGenerationTypeStrategy INSTANCE = new UUIDGenerationTypeStrategy();
@Override
public IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver,
ServiceRegistry serviceRegistry) {
throw new UnsupportedOperationException( "`" + getClass().getName() + "#createIdentifierGenerator not yet implemented" );
}
}

View File

@ -1,11 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
/**
* Implementation of the SPI for id generator factories.
*/
package org.hibernate.id.factory.internal;

View File

@ -1,21 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
/**
* Defines a {@linkplain org.hibernate.service.Service service} for creating
* id generators.
* <p>
* This is an older mechanism for instantiating and configuring id generators
* which predates the existence of {@link org.hibernate.generator.Generator}.
* 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;

View File

@ -1,30 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.spi;
import java.util.Properties;
import jakarta.persistence.GenerationType;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.descriptor.java.JavaType;
/**
* Delegate for defining how to handle the various types of
* {@link GenerationType} possibilities.
*
* @apiNote no GenerationType indicates {@code hbm.xml} mapping
*/
public interface GenerationTypeStrategy {
IdentifierGenerator createIdentifierGenerator(
GenerationType generationType,
String generatorName,
JavaType<?> javaType,
Properties config,
GeneratorDefinitionResolver definitionResolver,
ServiceRegistry serviceRegistry);
}

View File

@ -1,22 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.spi;
import java.util.function.BiConsumer;
import jakarta.persistence.GenerationType;
import org.hibernate.service.JavaServiceLoadable;
import org.hibernate.service.ServiceRegistry;
/**
* A {@link java.util.ServiceLoader} contract for registering implementations
* of {@link GenerationTypeStrategy}.
*/
@JavaServiceLoadable
public interface GenerationTypeStrategyRegistration {
void registerStrategies(BiConsumer<GenerationType, GenerationTypeStrategy> registry, ServiceRegistry serviceRegistry);
}

View File

@ -1,19 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.spi;
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
import jakarta.persistence.GenerationType;
/**
* Access to resolve IdentifierGeneratorDefinition instances
*/
@FunctionalInterface
public interface GeneratorDefinitionResolver {
IdentifierGeneratorDefinition resolveGeneratorDefinition(GenerationType generationType, String generatorName);
}

View File

@ -1,15 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.id.factory.spi;
import org.hibernate.generator.Generator;
/**
* Marker interface for Hibernate-provided implementations of {@link Generator}.
*/
public interface StandardGenerator {
}

View File

@ -1,14 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
/**
* 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;

View File

@ -19,7 +19,7 @@ import org.hibernate.generator.BeforeExecutionGenerator;
import org.hibernate.generator.EventType; import org.hibernate.generator.EventType;
import org.hibernate.generator.EventTypeSets; import org.hibernate.generator.EventTypeSets;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.generator.CustomIdGeneratorCreationContext;
import org.hibernate.type.descriptor.java.UUIDJavaType; import org.hibernate.type.descriptor.java.UUIDJavaType;
import org.hibernate.type.descriptor.java.UUIDJavaType.ValueTransformer; import org.hibernate.type.descriptor.java.UUIDJavaType.ValueTransformer;

View File

@ -1,27 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.jpa.spi;
import org.hibernate.Remove;
import java.util.Map;
/**
* Provides a set of {@link org.hibernate.id.IdentifierGenerator} strategies,
* overriding the default strategies.
*
* @author Emmanuel Bernard
*
* @deprecated supply a {@link org.hibernate.id.factory.spi.GenerationTypeStrategyRegistration} instead
*/
@Deprecated(since = "6.0", forRemoval = true)
public interface IdentifierGeneratorStrategyProvider {
/**
* set of strategy / generator class pairs to register as accepted strategies
*/
Map<String,Class<?>> getStrategies();
}

View File

@ -7,7 +7,7 @@
package org.hibernate.mapping; package org.hibernate.mapping;
import org.hibernate.Internal; import org.hibernate.Internal;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.generator.CustomIdGeneratorCreationContext;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
@Internal @Internal

View File

@ -8,7 +8,6 @@ package org.hibernate.mapping;
import org.hibernate.dialect.Dialect; import org.hibernate.dialect.Dialect;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
/** /**
@ -39,28 +38,7 @@ public interface KeyValue extends Value {
* of {@link IdentifierGenerator}. * of {@link IdentifierGenerator}.
*/ */
@Deprecated(since="6.2", forRemoval = true) @Deprecated(since="6.2", forRemoval = true)
default IdentifierGenerator createIdentifierGenerator( default IdentifierGenerator createIdentifierGenerator(Dialect dialect, RootClass rootClass) {
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
String defaultCatalog,
String defaultSchema,
RootClass rootClass) {
final Generator generator = createGenerator( dialect, rootClass );
return generator instanceof IdentifierGenerator ? (IdentifierGenerator) generator : null;
}
/**
* @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
* of {@link IdentifierGenerator}.
*/
@Deprecated(since="6.2", forRemoval = true)
default IdentifierGenerator createIdentifierGenerator(
IdentifierGeneratorFactory identifierGeneratorFactory,
Dialect dialect,
RootClass rootClass) {
final Generator generator = createGenerator( dialect, rootClass ); final Generator generator = createGenerator( dialect, rootClass );
return generator instanceof IdentifierGenerator ? (IdentifierGenerator) generator : null; return generator instanceof IdentifierGenerator ? (IdentifierGenerator) generator : null;
} }

View File

@ -38,7 +38,7 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.id.Assigned; import org.hibernate.id.Assigned;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.generator.CustomIdGeneratorCreationContext;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;

View File

@ -31,7 +31,6 @@ import org.hibernate.engine.jndi.internal.JndiServiceInitiator;
import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator; import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator; import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformResolverInitiator;
import org.hibernate.event.internal.EntityCopyObserverFactoryInitiator; import org.hibernate.event.internal.EntityCopyObserverFactoryInitiator;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactoryInitiator;
import org.hibernate.loader.ast.internal.BatchLoaderFactoryInitiator; import org.hibernate.loader.ast.internal.BatchLoaderFactoryInitiator;
import org.hibernate.persister.internal.PersisterClassResolverInitiator; import org.hibernate.persister.internal.PersisterClassResolverInitiator;
import org.hibernate.persister.internal.PersisterFactoryInitiator; import org.hibernate.persister.internal.PersisterFactoryInitiator;
@ -67,9 +66,6 @@ public final class StandardServiceInitiators {
// SessionFactoryBuilderService // SessionFactoryBuilderService
serviceInitiators.add( DefaultSessionFactoryBuilderInitiator.INSTANCE ); serviceInitiators.add( DefaultSessionFactoryBuilderInitiator.INSTANCE );
// IdentifierGeneratorFactory
serviceInitiators.add( StandardIdentifierGeneratorFactoryInitiator.INSTANCE );
// BytecodeProvider // BytecodeProvider
serviceInitiators.add( BytecodeProviderInitiator.INSTANCE ); serviceInitiators.add( BytecodeProviderInitiator.INSTANCE );

View File

@ -16,7 +16,7 @@ import org.hibernate.boot.model.relational.Database;
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper; import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.generator.CustomIdGeneratorCreationContext;
/** /**
* An example custom generator. * An example custom generator.

View File

@ -23,7 +23,6 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.id.PersistentIdentifierGenerator; import org.hibernate.id.PersistentIdentifierGenerator;
import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
@ -50,15 +49,10 @@ public class CustomNamingStrategyTests {
@Test @Test
public void testIt(DomainModelScope domainModelScope, ServiceRegistryScope serviceRegistryScope) { public void testIt(DomainModelScope domainModelScope, ServiceRegistryScope serviceRegistryScope) {
domainModelScope.withHierarchy( TheEntity.class, (entityDescriptor) -> { domainModelScope.withHierarchy( TheEntity.class, (entityDescriptor) -> {
final IdentifierGeneratorFactory identifierGeneratorFactory = domainModelScope.getDomainModel()
.getMetadataBuildingOptions()
.getIdentifierGeneratorFactory();
final JdbcServices jdbcServices = serviceRegistryScope.getRegistry().getService( JdbcServices.class ); final JdbcServices jdbcServices = serviceRegistryScope.getRegistry().getService( JdbcServices.class );
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
final SequenceStyleGenerator generator = (SequenceStyleGenerator) entityDescriptor.getIdentifier().createIdentifierGenerator( final SequenceStyleGenerator generator = (SequenceStyleGenerator) entityDescriptor.getIdentifier().createIdentifierGenerator(
identifierGeneratorFactory,
jdbcEnvironment.getDialect(), jdbcEnvironment.getDialect(),
entityDescriptor entityDescriptor
); );

View File

@ -159,7 +159,7 @@ public class SequenceNamingStrategyTest {
} }
private IdentifierGenerator extractGenerator(PersistentClass entityBinding) { private IdentifierGenerator extractGenerator(PersistentClass entityBinding) {
return entityBinding.getIdentifier().createIdentifierGenerator( null, null, null ); return entityBinding.getIdentifier().createIdentifierGenerator(null, null );
} }
@Entity(name = "TestEntity") @Entity(name = "TestEntity")

View File

@ -140,7 +140,7 @@ public class TableNamingStrategyTest {
} }
private IdentifierGenerator extractGenerator(PersistentClass entityBinding) { private IdentifierGenerator extractGenerator(PersistentClass entityBinding) {
return entityBinding.getIdentifier().createIdentifierGenerator( null, null, null ); return entityBinding.getIdentifier().createIdentifierGenerator(null, null );
} }

View File

@ -56,10 +56,7 @@ public class GeneratedValueTest {
PersistentClass entityBinding = metadata.getEntityBinding( TheEntity.class.getName() ); PersistentClass entityBinding = metadata.getEntityBinding( TheEntity.class.getName() );
assertEquals( UUID.class, entityBinding.getIdentifier().getType().getReturnedClass() ); assertEquals( UUID.class, entityBinding.getIdentifier().getType().getReturnedClass() );
IdentifierGenerator generator = entityBinding.getIdentifier().createIdentifierGenerator( IdentifierGenerator generator = entityBinding.getIdentifier().createIdentifierGenerator(
metadata.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
metadata.getDatabase().getDialect(), metadata.getDatabase().getDialect(),
null,
null,
(RootClass) entityBinding (RootClass) entityBinding
); );
assertTyping( UUIDGenerator.class, generator ); assertTyping( UUIDGenerator.class, generator );

View File

@ -6,34 +6,6 @@
*/ */
package org.hibernate.orm.test.idgen.enhanced.auto; package org.hibernate.orm.test.idgen.enhanced.auto;
import java.sql.Types;
import java.util.Collection;
import java.util.UUID;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionIdJdbcTypeCode;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IncrementGenerator;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.id.enhanced.DatabaseStructure;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory;
import org.hibernate.mapping.IdentifierBag;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.testing.orm.junit.FailureExpectedExtension;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@ -43,6 +15,29 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionIdJdbcTypeCode;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IncrementGenerator;
import org.hibernate.id.UUIDGenerator;
import org.hibernate.id.enhanced.DatabaseStructure;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.mapping.IdentifierBag;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.testing.orm.junit.FailureExpectedExtension;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.sql.Types;
import java.util.Collection;
import java.util.UUID;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
@ -62,15 +57,10 @@ public class AutoGenerationTypeTests {
.addAnnotatedClass( Entity2.class ) .addAnnotatedClass( Entity2.class )
.buildMetadata(); .buildMetadata();
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() ); final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() );
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier(); final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
final SequenceStyleGenerator entityIdGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator( final SequenceStyleGenerator entityIdGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
entityBinding.getRootClass() entityBinding.getRootClass()
); );
@ -91,15 +81,10 @@ public class AutoGenerationTypeTests {
.addAnnotatedClass( Entity2.class ) .addAnnotatedClass( Entity2.class )
.buildMetadata(); .buildMetadata();
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
final PersistentClass entityBinding = metadata.getEntityBinding( Entity2.class.getName() ); final PersistentClass entityBinding = metadata.getEntityBinding( Entity2.class.getName() );
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier(); final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
final SequenceStyleGenerator idGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator( final SequenceStyleGenerator idGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
entityBinding.getRootClass() entityBinding.getRootClass()
); );
@ -119,8 +104,6 @@ public class AutoGenerationTypeTests {
.addAnnotatedClass( Entity2.class ) .addAnnotatedClass( Entity2.class )
.buildMetadata(); .buildMetadata();
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
final PersistentClass entity1Binding = metadata.getEntityBinding( Entity1.class.getName() ); final PersistentClass entity1Binding = metadata.getEntityBinding( Entity1.class.getName() );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -130,10 +113,7 @@ public class AutoGenerationTypeTests {
final IdentifierBag idBagMapping = (IdentifierBag) theTwos.getValue(); final IdentifierBag idBagMapping = (IdentifierBag) theTwos.getValue();
final KeyValue collectionIdMapping = idBagMapping.getIdentifier(); final KeyValue collectionIdMapping = idBagMapping.getIdentifier();
final SequenceStyleGenerator collectionIdGenerator = (SequenceStyleGenerator) collectionIdMapping.createIdentifierGenerator( final SequenceStyleGenerator collectionIdGenerator = (SequenceStyleGenerator) collectionIdMapping.createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
null null
); );
@ -151,15 +131,10 @@ public class AutoGenerationTypeTests {
.addAnnotatedClass( Entity4.class ) .addAnnotatedClass( Entity4.class )
.buildMetadata(); .buildMetadata();
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
final PersistentClass entityBinding = metadata.getEntityBinding( Entity4.class.getName() ); final PersistentClass entityBinding = metadata.getEntityBinding( Entity4.class.getName() );
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier(); final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator( final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
entityBinding.getRootClass() entityBinding.getRootClass()
); );
@ -174,15 +149,10 @@ public class AutoGenerationTypeTests {
.addAnnotatedClass( Entity3.class ) .addAnnotatedClass( Entity3.class )
.buildMetadata(); .buildMetadata();
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
final PersistentClass entityBinding = metadata.getEntityBinding( Entity3.class.getName() ); final PersistentClass entityBinding = metadata.getEntityBinding( Entity3.class.getName() );
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier(); final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator( final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
entityBinding.getRootClass() entityBinding.getRootClass()
); );

View File

@ -13,7 +13,7 @@ import org.hibernate.id.Configurable;
import org.hibernate.id.IdentityGenerator; import org.hibernate.id.IdentityGenerator;
import org.hibernate.id.PostInsertIdentityPersister; import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext; import org.hibernate.generator.CustomIdGeneratorCreationContext;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.Type; import org.hibernate.type.Type;

View File

@ -18,8 +18,6 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.resource.beans.container.spi.BeanContainer; import org.hibernate.resource.beans.container.spi.BeanContainer;
import org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions; import org.hibernate.resource.beans.container.spi.BeanContainer.LifecycleOptions;
@ -28,6 +26,7 @@ import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.BaseUnitTest; import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.util.ServiceRegistryUtil; import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -50,6 +49,7 @@ import static org.mockito.Mockito.times;
* @author Yanming Zhou * @author Yanming Zhou
*/ */
@TestForIssue(jiraKey = "HHH-14688") @TestForIssue(jiraKey = "HHH-14688")
@FailureExpected(reason = "functionality has been removed for now")
@BaseUnitTest @BaseUnitTest
public class UserDefinedGeneratorsTests { public class UserDefinedGeneratorsTests {
@ -74,26 +74,18 @@ public class UserDefinedGeneratorsTests {
.addAnnotatedClass( Entity2.class ) .addAnnotatedClass( Entity2.class )
.buildMetadata(); .buildMetadata();
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() ); final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() );
final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() ); final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() );
final IdentifierGenerator generator1 = entityBinding1.getRootClass() final IdentifierGenerator generator1 = entityBinding1.getRootClass()
.getIdentifier() .getIdentifier()
.createIdentifierGenerator( .createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
entityBinding1.getRootClass() entityBinding1.getRootClass()
); );
final IdentifierGenerator generator2 = entityBinding2.getRootClass() final IdentifierGenerator generator2 = entityBinding2.getRootClass()
.getIdentifier() .getIdentifier()
.createIdentifierGenerator( .createIdentifierGenerator(
generatorFactory,
new H2Dialect(), new H2Dialect(),
"",
"",
entityBinding2.getRootClass() entityBinding2.getRootClass()
); );

View File

@ -14,7 +14,6 @@ import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl; import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
@ -58,10 +57,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -86,10 +82,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -117,10 +110,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -150,10 +140,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
final PersistentClass entityMapping = bootModel.getEntityBinding( final PersistentClass entityMapping = bootModel.getEntityBinding(
ExplicitSequenceGeneratorImplicitNameEntity.class.getName() ); ExplicitSequenceGeneratorImplicitNameEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
Database database = bootModel.getDatabase(); Database database = bootModel.getDatabase();
@ -196,10 +183,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitTableGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitTableGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -222,10 +206,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorImplicitNameEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorImplicitNameEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -248,10 +229,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -276,10 +254,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
@ -296,10 +271,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() ); final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator( final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(), ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping (RootClass) entityMapping
); );
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) ); generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );

View File

@ -1,29 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.jpa.ejb3configuration.id;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
/**
* @author Emmanuel Bernard
*/
@Entity
public class Cable {
@Id @GeneratedValue(generator = "fnk")
@GenericGenerator( name = "fnk", strategy = "funky")
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
private Integer id;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
private String name;
}

View File

@ -1,13 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.jpa.ejb3configuration.id;
/**
* @author Emmanuel Bernard
*/
public class FunkyException extends RuntimeException {
}

View File

@ -1,20 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.jpa.ejb3configuration.id;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
/**
* @author Emmanuel Bernard
*/
public class FunkyIdGenerator implements IdentifierGenerator {
public Object generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
throw new FunkyException();
}
}

View File

@ -1,21 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.jpa.ejb3configuration.id;
import java.util.HashMap;
import java.util.Map;
/**
* @author Emmanuel Bernard
*/
public class FunkyIdentifierGeneratorProvider implements org.hibernate.jpa.spi.IdentifierGeneratorStrategyProvider {
public Map<String, Class<?>> getStrategies() {
final HashMap<String, Class<?>> result = new HashMap<String, Class<?>>( 1 );
result.put( "funky", FunkyIdGenerator.class );
return result;
}
}

View File

@ -1,55 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.orm.test.jpa.ejb3configuration.id;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.testing.orm.jpa.PersistenceUnitInfoAdapter;
import org.hibernate.testing.util.ServiceRegistryUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
/**
* @author Emmanuel Bernard
*/
public class IdentifierGeneratorStrategyProviderTest {
@Test
@SuppressWarnings("unchecked")
public void testIdentifierGeneratorStrategyProvider() {
Map settings = ServiceRegistryUtil.createBaseSettings();
settings.put(
AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER,
FunkyIdentifierGeneratorProvider.class.getName()
);
settings.put( org.hibernate.cfg.AvailableSettings.LOADED_CLASSES, Collections.singletonList( Cable.class ) );
final EntityManagerFactory entityManagerFactory = Bootstrap.getEntityManagerFactoryBuilder(
new PersistenceUnitInfoAdapter(),
settings
).build();
final EntityManager entityManager = entityManagerFactory.createEntityManager();
try {
entityManager.persist( new Cable() );
entityManager.flush();
Assertions.fail( "FunkyException should have been thrown when the id is generated" );
}
catch ( FunkyException e ) {
entityManager.close();
entityManagerFactory.close();
}
}
}

View File

@ -44,8 +44,6 @@ import org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl;
import org.hibernate.engine.query.spi.NativeQueryInterpreter; import org.hibernate.engine.query.spi.NativeQueryInterpreter;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.id.factory.IdentifierGeneratorFactory;
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory;
import org.hibernate.internal.FastSessionServices; import org.hibernate.internal.FastSessionServices;
import org.hibernate.jpa.internal.MutableJpaComplianceImpl; import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
import org.hibernate.jpa.spi.JpaCompliance; import org.hibernate.jpa.spi.JpaCompliance;
@ -774,11 +772,6 @@ public abstract class MockSessionFactory
throw new UnsupportedOperationException("operation not supported"); throw new UnsupportedOperationException("operation not supported");
} }
@Override
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
return new StandardIdentifierGeneratorFactory(serviceRegistry, true);
}
@Override @Override
public MappingDefaults getMappingDefaults() { public MappingDefaults getMappingDefaults() {
return new MockMappingDefaults(); return new MockMappingDefaults();