HHH-18139 completely remove org.hibernate.id.factory.*
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
51acbd04dc
commit
e7196be0f2
|
@ -64,7 +64,6 @@ import org.hibernate.dialect.TimeZoneSupport;
|
|||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
|
@ -577,7 +576,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
implements MetadataBuildingOptions, JpaOrmXmlPersistenceUnitDefaultAware {
|
||||
private final StandardServiceRegistry serviceRegistry;
|
||||
private final MappingDefaultsImpl mappingDefaults;
|
||||
private final IdentifierGeneratorFactory identifierGeneratorFactory;
|
||||
private final TimeZoneStorageType defaultTimezoneStorage;
|
||||
private final WrapperArrayHandling wrapperArrayHandling;
|
||||
|
||||
|
@ -607,7 +605,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
|
||||
public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
this.identifierGeneratorFactory = serviceRegistry.getService( IdentifierGeneratorFactory.class );
|
||||
|
||||
final StrategySelector strategySelector = serviceRegistry.requireService( StrategySelector.class );
|
||||
final ConfigurationService configService = serviceRegistry.requireService( ConfigurationService.class );
|
||||
|
@ -773,11 +770,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
return mappingDefaults;
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return identifierGeneratorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZoneStorageStrategy getDefaultTimeZoneStorage() {
|
||||
return toTimeZoneStorageStrategy( getTimeZoneSupport() );
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.hibernate.id.UUIDHexGenerator;
|
|||
import org.hibernate.id.enhanced.LegacyNamingStrategy;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
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.mapping.Column;
|
||||
import org.hibernate.mapping.GeneratorCreator;
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.dialect.TimeZoneSupport;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.type.WrapperArrayHandling;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
import org.hibernate.usertype.CompositeUserType;
|
||||
|
@ -53,11 +52,6 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
|
|||
return delegate.getMappingDefaults();
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return delegate.getIdentifierGeneratorFactory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZoneStorageStrategy getDefaultTimeZoneStorage() {
|
||||
return delegate.getDefaultTimeZoneStorage();
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.hibernate.boot.internal.ClassmateContext;
|
|||
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
|
||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver;
|
||||
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
|
||||
|
@ -75,11 +74,6 @@ public interface BootstrapContext {
|
|||
*/
|
||||
MetadataBuildingOptions getMetadataBuildingOptions();
|
||||
|
||||
@Deprecated(since="7.0", forRemoval = true)
|
||||
default IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return getMetadataBuildingOptions().getIdentifierGeneratorFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the bootstrap was initiated from JPA bootstrapping.
|
||||
*
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.hibernate.collection.internal.StandardCollectionSemanticsResolver;
|
|||
import org.hibernate.collection.spi.CollectionSemanticsResolver;
|
||||
import org.hibernate.dialect.TimeZoneSupport;
|
||||
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.metamodel.internal.ManagedTypeRepresentationResolverStandard;
|
||||
import org.hibernate.metamodel.spi.ManagedTypeRepresentationResolver;
|
||||
import org.hibernate.type.WrapperArrayHandling;
|
||||
|
@ -46,16 +45,6 @@ public interface MetadataBuildingOptions {
|
|||
*/
|
||||
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
|
||||
* property and the {@linkplain #getTimeZoneSupport() time zone support} of
|
||||
|
@ -80,6 +69,10 @@ public interface MetadataBuildingOptions {
|
|||
*/
|
||||
WrapperArrayHandling getWrapperArrayHandling();
|
||||
|
||||
/**
|
||||
* @deprecated no longer called
|
||||
*/
|
||||
@Deprecated(since="7.0", forRemoval = true)
|
||||
default ManagedTypeRepresentationResolver getManagedTypeRepresentationResolver() {
|
||||
// for now always return the standard one
|
||||
return ManagedTypeRepresentationResolverStandard.INSTANCE;
|
||||
|
|
|
@ -221,14 +221,4 @@ public interface AvailableSettings
|
|||
@Deprecated(since = "6.2", forRemoval = true)
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
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";
|
||||
}
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
* 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;
|
||||
package org.hibernate.generator;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.generator.GeneratorCreationContext;
|
||||
import org.hibernate.mapping.RootClass;
|
||||
|
||||
@Incubating
|
|
@ -8,7 +8,6 @@ package org.hibernate.id;
|
|||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.internal.util.BytesHelper;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +21,7 @@ import org.hibernate.internal.util.BytesHelper;
|
|||
* @deprecated since {@link UUIDHexGenerator} is deprecated
|
||||
*/
|
||||
@Deprecated(since = "6")
|
||||
public abstract class AbstractUUIDGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
public abstract class AbstractUUIDGenerator implements IdentifierGenerator {
|
||||
|
||||
private static final int IP;
|
||||
static {
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Properties;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
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.
|
||||
*/
|
||||
public class Assigned implements IdentifierGenerator, StandardGenerator {
|
||||
public class Assigned implements IdentifierGenerator {
|
||||
private String entityName;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.hibernate.boot.model.relational.Database;
|
|||
import org.hibernate.boot.model.relational.ExportableProducer;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.property.access.spi.Setter;
|
||||
import org.hibernate.type.CompositeType;
|
||||
|
||||
|
@ -52,7 +51,7 @@ import org.hibernate.type.CompositeType;
|
|||
*/
|
||||
@Internal
|
||||
public class CompositeNestedGeneratedValueGenerator
|
||||
implements IdentifierGenerator, StandardGenerator, IdentifierGeneratorAggregator, Serializable {
|
||||
implements IdentifierGenerator, IdentifierGeneratorAggregator, Serializable {
|
||||
/**
|
||||
* Contract for declaring how to locate the context for sub-value injection.
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,6 @@ import java.util.Properties;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
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(since = "6", forRemoval = true)
|
||||
public class ForeignGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
public class ForeignGenerator implements IdentifierGenerator {
|
||||
private static final CoreMessageLogger LOG = messageLogger( ForeignGenerator.class );
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.sql.SQLException;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
|
@ -26,7 +25,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
* @deprecated use {@link org.hibernate.id.uuid.UuidGenerator}
|
||||
*/
|
||||
@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 boolean WARNED;
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
|
|||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.generator.OnExecutionGenerator;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.id.insert.BasicSelectingDelegate;
|
||||
import org.hibernate.id.insert.GetGeneratedKeysDelegate;
|
||||
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.
|
||||
*/
|
||||
public class IdentityGenerator
|
||||
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator {
|
||||
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator {
|
||||
|
||||
@Override
|
||||
public boolean referenceColumnsInSql(Dialect dialect) {
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.dialect.Dialect;
|
|||
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
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.
|
||||
*/
|
||||
public class IncrementGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
public class IncrementGenerator implements IdentifierGenerator {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IncrementGenerator.class );
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,12 +9,11 @@ package org.hibernate.id;
|
|||
import org.hibernate.boot.model.relational.ExportableProducer;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.id.enhanced.StandardOptimizerDescriptor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
|
||||
/**
|
||||
* 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,
|
||||
*/
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.util.Properties;
|
|||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.generator.OnExecutionGenerator;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
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.
|
||||
*/
|
||||
public class SelectGenerator
|
||||
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator {
|
||||
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator {
|
||||
|
||||
/**
|
||||
* The property specifying the unique key name.
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.id.uuid.StandardRandomStrategy;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
@ -41,7 +40,7 @@ import org.hibernate.type.descriptor.java.UUIDJavaType;
|
|||
* {@link org.hibernate.annotations.UuidGenerator} instead
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
public class UUIDGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
public class UUIDGenerator implements IdentifierGenerator {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( UUIDGenerator.class );
|
||||
|
||||
public static final String UUID_GEN_STRATEGY = "uuid_gen_strategy";
|
||||
|
|
|
@ -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 );
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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" );
|
||||
}
|
||||
}
|
|
@ -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" );
|
||||
}
|
||||
}
|
|
@ -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" );
|
||||
}
|
||||
}
|
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
|
@ -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" );
|
||||
}
|
||||
}
|
|
@ -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" );
|
||||
}
|
||||
}
|
|
@ -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;
|
|
@ -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;
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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;
|
|
@ -19,7 +19,7 @@ import org.hibernate.generator.BeforeExecutionGenerator;
|
|||
import org.hibernate.generator.EventType;
|
||||
import org.hibernate.generator.EventTypeSets;
|
||||
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.ValueTransformer;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
package org.hibernate.mapping;
|
||||
|
||||
import org.hibernate.Internal;
|
||||
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext;
|
||||
import org.hibernate.generator.CustomIdGeneratorCreationContext;
|
||||
import org.hibernate.generator.Generator;
|
||||
|
||||
@Internal
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.mapping;
|
|||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.generator.Generator;
|
||||
|
||||
/**
|
||||
|
@ -39,28 +38,7 @@ public interface KeyValue extends Value {
|
|||
* of {@link IdentifierGenerator}.
|
||||
*/
|
||||
@Deprecated(since="6.2", forRemoval = true)
|
||||
default IdentifierGenerator createIdentifierGenerator(
|
||||
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) {
|
||||
default IdentifierGenerator createIdentifierGenerator(Dialect dialect, RootClass rootClass) {
|
||||
final Generator generator = createGenerator( dialect, rootClass );
|
||||
return generator instanceof IdentifierGenerator ? (IdentifierGenerator) generator : null;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.hibernate.dialect.Dialect;
|
|||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.generator.Generator;
|
||||
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.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
|
|
|
@ -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.JtaPlatformResolverInitiator;
|
||||
import org.hibernate.event.internal.EntityCopyObserverFactoryInitiator;
|
||||
import org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactoryInitiator;
|
||||
import org.hibernate.loader.ast.internal.BatchLoaderFactoryInitiator;
|
||||
import org.hibernate.persister.internal.PersisterClassResolverInitiator;
|
||||
import org.hibernate.persister.internal.PersisterFactoryInitiator;
|
||||
|
@ -67,9 +66,6 @@ public final class StandardServiceInitiators {
|
|||
// SessionFactoryBuilderService
|
||||
serviceInitiators.add( DefaultSessionFactoryBuilderInitiator.INSTANCE );
|
||||
|
||||
// IdentifierGeneratorFactory
|
||||
serviceInitiators.add( StandardIdentifierGeneratorFactoryInitiator.INSTANCE );
|
||||
|
||||
// BytecodeProvider
|
||||
serviceInitiators.add( BytecodeProviderInitiator.INSTANCE );
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.hibernate.boot.model.relational.Database;
|
|||
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.factory.spi.CustomIdGeneratorCreationContext;
|
||||
import org.hibernate.generator.CustomIdGeneratorCreationContext;
|
||||
|
||||
/**
|
||||
* An example custom generator.
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
|
@ -50,15 +49,10 @@ public class CustomNamingStrategyTests {
|
|||
@Test
|
||||
public void testIt(DomainModelScope domainModelScope, ServiceRegistryScope serviceRegistryScope) {
|
||||
domainModelScope.withHierarchy( TheEntity.class, (entityDescriptor) -> {
|
||||
final IdentifierGeneratorFactory identifierGeneratorFactory = domainModelScope.getDomainModel()
|
||||
.getMetadataBuildingOptions()
|
||||
.getIdentifierGeneratorFactory();
|
||||
|
||||
final JdbcServices jdbcServices = serviceRegistryScope.getRegistry().getService( JdbcServices.class );
|
||||
final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) entityDescriptor.getIdentifier().createIdentifierGenerator(
|
||||
identifierGeneratorFactory,
|
||||
jdbcEnvironment.getDialect(),
|
||||
entityDescriptor
|
||||
);
|
||||
|
|
|
@ -159,7 +159,7 @@ public class SequenceNamingStrategyTest {
|
|||
}
|
||||
|
||||
private IdentifierGenerator extractGenerator(PersistentClass entityBinding) {
|
||||
return entityBinding.getIdentifier().createIdentifierGenerator( null, null, null );
|
||||
return entityBinding.getIdentifier().createIdentifierGenerator(null, null );
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity")
|
||||
|
|
|
@ -140,7 +140,7 @@ public class TableNamingStrategyTest {
|
|||
}
|
||||
|
||||
private IdentifierGenerator extractGenerator(PersistentClass entityBinding) {
|
||||
return entityBinding.getIdentifier().createIdentifierGenerator( null, null, null );
|
||||
return entityBinding.getIdentifier().createIdentifierGenerator(null, null );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,10 +56,7 @@ public class GeneratedValueTest {
|
|||
PersistentClass entityBinding = metadata.getEntityBinding( TheEntity.class.getName() );
|
||||
assertEquals( UUID.class, entityBinding.getIdentifier().getType().getReturnedClass() );
|
||||
IdentifierGenerator generator = entityBinding.getIdentifier().createIdentifierGenerator(
|
||||
metadata.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
metadata.getDatabase().getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityBinding
|
||||
);
|
||||
assertTyping( UUIDGenerator.class, generator );
|
||||
|
|
|
@ -6,34 +6,6 @@
|
|||
*/
|
||||
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.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
|
@ -43,6 +15,29 @@ import jakarta.persistence.JoinColumn;
|
|||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
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.is;
|
||||
|
@ -62,15 +57,10 @@ public class AutoGenerationTypeTests {
|
|||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator entityIdGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
|
@ -91,15 +81,10 @@ public class AutoGenerationTypeTests {
|
|||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator idGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
|
@ -119,8 +104,6 @@ public class AutoGenerationTypeTests {
|
|||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
|
||||
|
||||
final PersistentClass entity1Binding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -130,10 +113,7 @@ public class AutoGenerationTypeTests {
|
|||
final IdentifierBag idBagMapping = (IdentifierBag) theTwos.getValue();
|
||||
final KeyValue collectionIdMapping = idBagMapping.getIdentifier();
|
||||
final SequenceStyleGenerator collectionIdGenerator = (SequenceStyleGenerator) collectionIdMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
null
|
||||
);
|
||||
|
||||
|
@ -151,15 +131,10 @@ public class AutoGenerationTypeTests {
|
|||
.addAnnotatedClass( Entity4.class )
|
||||
.buildMetadata();
|
||||
|
||||
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity4.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
|
@ -174,15 +149,10 @@ public class AutoGenerationTypeTests {
|
|||
.addAnnotatedClass( Entity3.class )
|
||||
.buildMetadata();
|
||||
|
||||
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity3.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.hibernate.id.Configurable;
|
|||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.PostInsertIdentityPersister;
|
||||
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.service.ServiceRegistry;
|
||||
import org.hibernate.type.Type;
|
||||
|
|
|
@ -18,8 +18,6 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
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.resource.beans.container.spi.BeanContainer;
|
||||
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.orm.junit.BaseUnitTest;
|
||||
import org.hibernate.testing.orm.junit.FailureExpected;
|
||||
import org.hibernate.testing.util.ServiceRegistryUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -50,6 +49,7 @@ import static org.mockito.Mockito.times;
|
|||
* @author Yanming Zhou
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14688")
|
||||
@FailureExpected(reason = "functionality has been removed for now")
|
||||
@BaseUnitTest
|
||||
public class UserDefinedGeneratorsTests {
|
||||
|
||||
|
@ -74,26 +74,18 @@ public class UserDefinedGeneratorsTests {
|
|||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final IdentifierGeneratorFactory generatorFactory = new StandardIdentifierGeneratorFactory( ssr );
|
||||
|
||||
final PersistentClass entityBinding1 = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final PersistentClass entityBinding2 = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final IdentifierGenerator generator1 = entityBinding1.getRootClass()
|
||||
.getIdentifier()
|
||||
.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding1.getRootClass()
|
||||
);
|
||||
final IdentifierGenerator generator2 = entityBinding2.getRootClass()
|
||||
.getIdentifier()
|
||||
.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding2.getRootClass()
|
||||
);
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.hibernate.boot.model.relational.Sequence;
|
|||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
|
@ -58,10 +57,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -86,10 +82,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -117,10 +110,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitSequenceGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -150,10 +140,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
final PersistentClass entityMapping = bootModel.getEntityBinding(
|
||||
ExplicitSequenceGeneratorImplicitNameEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
Database database = bootModel.getDatabase();
|
||||
|
@ -196,10 +183,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitTableGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -222,10 +206,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorImplicitNameEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -248,10 +229,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitTableGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -276,10 +254,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
@ -296,10 +271,7 @@ public class GeneratedValueTests extends BaseUnitTestCase {
|
|||
.buildMetadata();
|
||||
final PersistentClass entityMapping = bootModel.getEntityBinding( ImplicitIncrementGeneratorEntity.class.getName() );
|
||||
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
|
||||
bootModel.getMetadataBuildingOptions().getIdentifierGeneratorFactory(),
|
||||
ssr.getService( JdbcEnvironment.class ).getDialect(),
|
||||
null,
|
||||
null,
|
||||
(RootClass) entityMapping
|
||||
);
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( bootModel.getDatabase().getJdbcEnvironment() ) );
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,8 +44,6 @@ import org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl;
|
|||
import org.hibernate.engine.query.spi.NativeQueryInterpreter;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
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.jpa.internal.MutableJpaComplianceImpl;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
|
@ -774,11 +772,6 @@ public abstract class MockSessionFactory
|
|||
throw new UnsupportedOperationException("operation not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierGeneratorFactory getIdentifierGeneratorFactory() {
|
||||
return new StandardIdentifierGeneratorFactory(serviceRegistry, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappingDefaults getMappingDefaults() {
|
||||
return new MockMappingDefaults();
|
||||
|
|
Loading…
Reference in New Issue