mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-24 04:05:39 +00:00
HHH-14497 - Drop legacy id-generator settings;
HHH-14718 - Drop deprecated generator implementations
This commit is contained in:
parent
189bc54dbd
commit
915da5228d
@ -275,11 +275,10 @@ Problems might result from Hibernate types which are equivalent, rather than equ
|
||||
One such example is a mismatch between a property defined as an `org.hibernate.type.StandardBasicTypes.DATE` and a property defined as an `org.hibernate.type.StandardBasicTypes.TIMESTAMP`,
|
||||
even though the database may not make a distinction, or may be capable of handling the conversion.
|
||||
|
||||
If id property is not specified in the `properties_list`,
|
||||
Hibernate generates a value automatically.
|
||||
If id property is not specified in the `properties_list`, Hibernate generates a value automatically.
|
||||
Automatic generation is only available if you use ID generators which operate on the database.
|
||||
Otherwise, Hibernate throws an exception during parsing.
|
||||
Available in-database generators are `org.hibernate.id.SequenceGenerator` and its subclasses, and objects which implement `org.hibernate.id.PostInsertIdentifierGenerator`.
|
||||
Otherwise, Hibernate throws an exception during parsing. Available in-database generators implement
|
||||
`org.hibernate.id.PostInsertIdentifierGenerator`.
|
||||
|
||||
For properties mapped as either version or timestamp, the insert statement gives you two options.
|
||||
You can either specify the property in the properties_list, in which case its value is taken from the corresponding select expressions or omit it from the properties_list,
|
||||
|
@ -6,9 +6,6 @@
|
||||
*/
|
||||
package org.hibernate.boot;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanOptions;
|
||||
import org.hibernate.boot.archive.scan.spi.Scanner;
|
||||
@ -27,6 +24,9 @@
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.SharedCacheMode;
|
||||
|
||||
/**
|
||||
* Contract for specifying various overrides to be used in metamodel building.
|
||||
*
|
||||
@ -186,28 +186,6 @@ public interface MetadataBuilder {
|
||||
*/
|
||||
MetadataBuilder applyArchiveDescriptorFactory(ArchiveDescriptorFactory factory);
|
||||
|
||||
/**
|
||||
* Should we enable support for the "new" (since 3.2) identifier generator mappings for
|
||||
* handling:<ul>
|
||||
* <li>{@link jakarta.persistence.GenerationType#SEQUENCE}</li>
|
||||
* <li>{@link jakarta.persistence.GenerationType#IDENTITY}</li>
|
||||
* <li>{@link jakarta.persistence.GenerationType#TABLE}</li>
|
||||
* <li>{@link jakarta.persistence.GenerationType#AUTO}</li>
|
||||
* </ul>
|
||||
* <p/>
|
||||
* Its default is defined by the {@link org.hibernate.cfg.AvailableSettings#USE_NEW_ID_GENERATOR_MAPPINGS}
|
||||
* setting if using property-based configuration.
|
||||
*
|
||||
*
|
||||
* @param enable {@code true} to enable; {@code false} to disable; don't call for
|
||||
* default.
|
||||
*
|
||||
* @return {@code this}, for method chaining
|
||||
*
|
||||
* @see org.hibernate.cfg.AvailableSettings#USE_NEW_ID_GENERATOR_MAPPINGS
|
||||
*/
|
||||
MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enable);
|
||||
|
||||
/**
|
||||
* Should we process or ignore explicitly defined discriminators in the case
|
||||
* of joined-subclasses. The legacy behavior of Hibernate was to ignore the
|
||||
|
@ -8,23 +8,21 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.TableGenerator;
|
||||
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.BinderHelper;
|
||||
import org.hibernate.id.IncrementGenerator;
|
||||
import org.hibernate.id.MultipleHiLoPerTableGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.SequenceHiLoGenerator;
|
||||
import org.hibernate.id.UUIDGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.TableGenerator;
|
||||
|
||||
/**
|
||||
* The root (composition) IdGenerationTypeInterpreter.
|
||||
*
|
||||
@ -75,14 +73,6 @@ public void interpretSequenceGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
public void enableLegacyFallback() {
|
||||
fallbackInterpreter = LegacyFallbackInterpreter.INSTANCE;
|
||||
}
|
||||
|
||||
public void disableLegacyFallback() {
|
||||
fallbackInterpreter = FallbackInterpreter.INSTANCE;
|
||||
}
|
||||
|
||||
public void addInterpreterDelegate(IdGeneratorStrategyInterpreter delegate) {
|
||||
if ( delegates == null ) {
|
||||
delegates = new ArrayList<>();
|
||||
@ -90,118 +80,6 @@ public void addInterpreterDelegate(IdGeneratorStrategyInterpreter delegate) {
|
||||
delegates.add( delegate );
|
||||
}
|
||||
|
||||
private static class LegacyFallbackInterpreter implements IdGeneratorStrategyInterpreter {
|
||||
/**
|
||||
* Singleton access
|
||||
*/
|
||||
public static final LegacyFallbackInterpreter INSTANCE = new LegacyFallbackInterpreter();
|
||||
|
||||
@Override
|
||||
public String determineGeneratorName(GenerationType generationType, GeneratorNameDeterminationContext context) {
|
||||
switch ( generationType ) {
|
||||
case IDENTITY: {
|
||||
return "identity";
|
||||
}
|
||||
case SEQUENCE: {
|
||||
return "seqhilo";
|
||||
}
|
||||
case TABLE: {
|
||||
return MultipleHiLoPerTableGenerator.class.getName();
|
||||
}
|
||||
default: {
|
||||
// AUTO
|
||||
|
||||
if ( "increment".equalsIgnoreCase( context.getGeneratedValueGeneratorName() ) ) {
|
||||
return IncrementGenerator.class.getName();
|
||||
}
|
||||
|
||||
final Class javaType = context.getIdType();
|
||||
if ( UUID.class.isAssignableFrom( javaType ) ) {
|
||||
return UUIDGenerator.class.getName();
|
||||
}
|
||||
|
||||
return "native";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interpretTableGenerator(
|
||||
TableGenerator tableGeneratorAnnotation,
|
||||
IdentifierGeneratorDefinition.Builder definitionBuilder) {
|
||||
definitionBuilder.setName( tableGeneratorAnnotation.name() );
|
||||
definitionBuilder.setStrategy( MultipleHiLoPerTableGenerator.class.getName() );
|
||||
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.table() ) ) {
|
||||
definitionBuilder.addParam(
|
||||
MultipleHiLoPerTableGenerator.ID_TABLE,
|
||||
tableGeneratorAnnotation.table()
|
||||
);
|
||||
}
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.catalog() ) ) {
|
||||
definitionBuilder.addParam(
|
||||
PersistentIdentifierGenerator.CATALOG,
|
||||
tableGeneratorAnnotation.catalog()
|
||||
);
|
||||
}
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.schema() ) ) {
|
||||
definitionBuilder.addParam(
|
||||
PersistentIdentifierGenerator.SCHEMA,
|
||||
tableGeneratorAnnotation.schema()
|
||||
);
|
||||
}
|
||||
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.pkColumnName() ) ) {
|
||||
definitionBuilder.addParam(
|
||||
MultipleHiLoPerTableGenerator.PK_COLUMN_NAME,
|
||||
tableGeneratorAnnotation.pkColumnName()
|
||||
);
|
||||
}
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.valueColumnName() ) ) {
|
||||
definitionBuilder.addParam(
|
||||
MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME,
|
||||
tableGeneratorAnnotation.valueColumnName()
|
||||
);
|
||||
}
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( tableGeneratorAnnotation.pkColumnValue() ) ) {
|
||||
definitionBuilder.addParam(
|
||||
MultipleHiLoPerTableGenerator.PK_VALUE_NAME,
|
||||
tableGeneratorAnnotation.pkColumnValue()
|
||||
);
|
||||
}
|
||||
definitionBuilder.addParam(
|
||||
MultipleHiLoPerTableGenerator.MAX_LO,
|
||||
String.valueOf( tableGeneratorAnnotation.allocationSize() - 1 )
|
||||
);
|
||||
|
||||
// TODO : implement unique-constraint support
|
||||
if ( tableGeneratorAnnotation.uniqueConstraints() != null
|
||||
&& tableGeneratorAnnotation.uniqueConstraints().length > 0 ) {
|
||||
log.ignoringTableGeneratorConstraints( tableGeneratorAnnotation.name() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void interpretSequenceGenerator(
|
||||
SequenceGenerator sequenceGeneratorAnnotation,
|
||||
IdentifierGeneratorDefinition.Builder definitionBuilder) {
|
||||
definitionBuilder.setName( sequenceGeneratorAnnotation.name() );
|
||||
|
||||
definitionBuilder.setStrategy( "seqhilo" );
|
||||
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( sequenceGeneratorAnnotation.sequenceName() ) ) {
|
||||
definitionBuilder.addParam( org.hibernate.id.SequenceGenerator.SEQUENCE, sequenceGeneratorAnnotation.sequenceName() );
|
||||
}
|
||||
//FIXME: work on initialValue() through SequenceGenerator.PARAMETERS
|
||||
// steve : or just use o.h.id.enhanced.SequenceStyleGenerator
|
||||
if ( sequenceGeneratorAnnotation.initialValue() != 1 ) {
|
||||
log.unsupportedInitialValue( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS );
|
||||
}
|
||||
definitionBuilder.addParam( SequenceHiLoGenerator.MAX_LO, String.valueOf( sequenceGeneratorAnnotation.allocationSize() - 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static class FallbackInterpreter implements IdGeneratorStrategyInterpreter {
|
||||
/**
|
||||
* Singleton access
|
||||
|
@ -10,9 +10,6 @@
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.SharedCacheMode;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
@ -79,6 +76,10 @@
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.SharedCacheMode;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@ -379,17 +380,6 @@ public MetadataBuilder applyAttributeConverter(AttributeConverter attributeConve
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enabled) {
|
||||
if ( enabled ) {
|
||||
this.options.idGenerationTypeInterpreter.disableLegacyFallback();
|
||||
}
|
||||
else {
|
||||
this.options.idGenerationTypeInterpreter.enableLegacyFallback();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder applyIdGenerationTypeInterpreter(IdGeneratorStrategyInterpreter interpreter) {
|
||||
this.options.idGenerationTypeInterpreter.addInterpreterDelegate( interpreter );
|
||||
@ -688,18 +678,6 @@ public ImplicitNamingStrategy call() {
|
||||
|
||||
this.sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService );
|
||||
|
||||
final boolean useNewIdentifierGenerators = configService.getSetting(
|
||||
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
if ( useNewIdentifierGenerators ) {
|
||||
this.idGenerationTypeInterpreter.disableLegacyFallback();
|
||||
}
|
||||
else {
|
||||
this.idGenerationTypeInterpreter.enableLegacyFallback();
|
||||
}
|
||||
|
||||
this.useNationalizedCharacterData = configService.getSetting(
|
||||
AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA,
|
||||
StandardConverters.BOOLEAN,
|
||||
|
@ -12,10 +12,6 @@
|
||||
|
||||
/**
|
||||
* Mainly this is used to support legacy sequence exporting.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
* @see org.hibernate.id.SequenceGenerator
|
||||
*/
|
||||
public class NamedAuxiliaryDatabaseObject
|
||||
extends SimpleAuxiliaryDatabaseObject
|
||||
@ -32,16 +28,6 @@ public NamedAuxiliaryDatabaseObject(
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public NamedAuxiliaryDatabaseObject(
|
||||
String name,
|
||||
Namespace namespace,
|
||||
String[] createStrings,
|
||||
String[] dropStrings,
|
||||
Set<String> dialectScopes) {
|
||||
super( namespace, createStrings, dropStrings, dialectScopes );
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportIdentifier() {
|
||||
return new QualifiedNameImpl(
|
||||
|
@ -134,12 +134,6 @@ public MetadataBuilder applyArchiveDescriptorFactory(ArchiveDescriptorFactory fa
|
||||
return getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enable) {
|
||||
delegate.enableNewIdentifierGeneratorSupport( enable );
|
||||
return getThis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataBuilder enableExplicitDiscriminatorsForJoinedSubclassSupport(boolean enabled) {
|
||||
delegate.enableExplicitDiscriminatorsForJoinedSubclassSupport( enabled );
|
||||
|
@ -533,17 +533,6 @@ public interface AvailableSettings {
|
||||
*/
|
||||
String DEFAULT_CACHE_CONCURRENCY_STRATEGY = "hibernate.cache.default_cache_concurrency_strategy";
|
||||
|
||||
/**
|
||||
* Setting which indicates whether or not the new {@link org.hibernate.id.IdentifierGenerator} are used
|
||||
* for AUTO, TABLE and SEQUENCE.
|
||||
* <p/>
|
||||
* Default is {@code true}. Existing applications may want to disable this (set it {@code false}) for
|
||||
* upgrade compatibility.
|
||||
*
|
||||
* @see MetadataBuilder#enableNewIdentifierGeneratorSupport
|
||||
*/
|
||||
String USE_NEW_ID_GENERATOR_MAPPINGS = "hibernate.id.new_generator_mappings";
|
||||
|
||||
/**
|
||||
* @see MetadataBuilder#enableImplicitForcingOfDiscriminatorsInSelect(boolean)
|
||||
*/
|
||||
|
@ -36,7 +36,6 @@
|
||||
import org.hibernate.cfg.annotations.Nullability;
|
||||
import org.hibernate.cfg.annotations.TableBinder;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.MultipleHiLoPerTableGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
@ -552,10 +551,8 @@ public static void makeIdGenerator(
|
||||
//This is quite vague in the spec but a generator could override the generator choice
|
||||
String identifierGeneratorStrategy = gen.getStrategy();
|
||||
//yuk! this is a hack not to override 'AUTO' even if generator is set
|
||||
final boolean avoidOverriding =
|
||||
identifierGeneratorStrategy.equals( "identity" )
|
||||
|| identifierGeneratorStrategy.equals( "seqhilo" )
|
||||
|| identifierGeneratorStrategy.equals( MultipleHiLoPerTableGenerator.class.getName() );
|
||||
final boolean avoidOverriding = identifierGeneratorStrategy.equals( "identity" )
|
||||
|| identifierGeneratorStrategy.equals( "seqhilo" );
|
||||
if ( generatorType == null || !avoidOverriding ) {
|
||||
id.setIdentifierGeneratorStrategy( identifierGeneratorStrategy );
|
||||
}
|
||||
|
@ -6,14 +6,6 @@
|
||||
*/
|
||||
package org.hibernate.dialect;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.Index;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.tool.schema.spi.Exporter;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -23,6 +15,13 @@
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.Index;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.tool.schema.spi.Exporter;
|
||||
|
||||
/**
|
||||
* The exporter for Cloud Spanner CREATE and DROP table statements.
|
||||
*
|
||||
@ -94,13 +93,8 @@ private String[] getTableString(Table table, Iterable<Column> keyColumns, SqlStr
|
||||
context.format( table.getQualifiedTableName() ),
|
||||
colsAndTypes.toString(),
|
||||
primaryKeyColNames
|
||||
) );
|
||||
|
||||
// Hibernate requires the special hibernate_sequence table to be populated with an initial val.
|
||||
if ( table.getName().equals( SequenceStyleGenerator.DEF_SEQUENCE_NAME ) ) {
|
||||
statements.add( "INSERT INTO " + SequenceStyleGenerator.DEF_SEQUENCE_NAME + " ("
|
||||
+ SequenceStyleGenerator.DEF_VALUE_COLUMN + ") VALUES(1)" );
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return statements.toArray( new String[0] );
|
||||
}
|
||||
|
@ -1,398 +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;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.model.naming.Identifier;
|
||||
import org.hibernate.boot.model.relational.Database;
|
||||
import org.hibernate.boot.model.relational.Namespace;
|
||||
import org.hibernate.boot.model.relational.QualifiedName;
|
||||
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
||||
import org.hibernate.engine.jdbc.Size;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.engine.jdbc.internal.FormatStyle;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
|
||||
import org.hibernate.engine.spi.SessionEventListenerManager;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.enhanced.AccessCallback;
|
||||
import org.hibernate.id.enhanced.LegacyHiLoAlgorithmOptimizer;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.jdbc.AbstractReturningWork;
|
||||
import org.hibernate.jdbc.WorkExecutorVisitable;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.mapping.PrimaryKey;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.BasicTypeRegistry;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A hilo <tt>IdentifierGenerator</tt> that returns a <tt>Long</tt>, constructed using
|
||||
* a hi/lo algorithm. The hi value MUST be fetched in a separate transaction
|
||||
* to the <tt>Session</tt> transaction so the generator must be able to obtain
|
||||
* a new connection and commit it. Hence this implementation may not
|
||||
* be used when the user is supplying connections. In this
|
||||
* case a <tt>SequenceHiLoGenerator</tt> would be a better choice (where
|
||||
* supported).<br>
|
||||
* <br>
|
||||
* <p/>
|
||||
* A hilo <tt>IdentifierGenerator</tt> that uses a database
|
||||
* table to store the last generated values. A table can contains
|
||||
* several hi values. They are distinct from each other through a key
|
||||
* <p/>
|
||||
* <p>This implementation is not compliant with a user connection</p>
|
||||
* <p/>
|
||||
* <p/>
|
||||
* <p>Allowed parameters (all of them are optional):</p>
|
||||
* <ul>
|
||||
* <li>table: table name (default <tt>hibernate_sequences</tt>)</li>
|
||||
* <li>primary_key_column: key column name (default <tt>sequence_name</tt>)</li>
|
||||
* <li>value_column: hi value column name(default <tt>sequence_next_hi_value</tt>)</li>
|
||||
* <li>primary_key_value: key value for the current entity (default to the entity's primary table name)</li>
|
||||
* <li>primary_key_length: length of the key column in DB represented as a varchar (default to 255)</li>
|
||||
* <li>max_lo: max low value before increasing hi (default to Short.MAX_VALUE)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @author <a href="mailto:kr@hbt.de">Klaus Richarz</a>.
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.id.enhanced.TableGenerator} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MultipleHiLoPerTableGenerator implements PersistentIdentifierGenerator {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( MultipleHiLoPerTableGenerator.class );
|
||||
|
||||
public static final String ID_TABLE = "table";
|
||||
public static final String PK_COLUMN_NAME = "primary_key_column";
|
||||
public static final String PK_VALUE_NAME = "primary_key_value";
|
||||
public static final String VALUE_COLUMN_NAME = "value_column";
|
||||
public static final String PK_LENGTH_NAME = "primary_key_length";
|
||||
|
||||
private static final int DEFAULT_PK_LENGTH = 255;
|
||||
public static final String DEFAULT_TABLE = "hibernate_sequences";
|
||||
private static final String DEFAULT_PK_COLUMN = "sequence_name";
|
||||
private static final String DEFAULT_VALUE_COLUMN = "sequence_next_hi_value";
|
||||
|
||||
private String contributor;
|
||||
|
||||
private QualifiedName qualifiedTableName;
|
||||
private QualifiedName physicalTableName;
|
||||
private String segmentColumnName;
|
||||
private String segmentName;
|
||||
private String valueColumnName;
|
||||
private String query;
|
||||
private String insert;
|
||||
private String update;
|
||||
|
||||
//hilo params
|
||||
public static final String MAX_LO = "max_lo";
|
||||
|
||||
private int maxLo;
|
||||
private LegacyHiLoAlgorithmOptimizer hiloOptimizer;
|
||||
|
||||
private Class returnClass;
|
||||
private int keySize;
|
||||
|
||||
@Override
|
||||
public Optimizer getOptimizer() {
|
||||
return hiloOptimizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object generate(final SharedSessionContractImplementor session, Object obj) {
|
||||
DeprecationLogger.DEPRECATION_LOGGER.deprecatedTableGenerator( getClass().getName() );
|
||||
|
||||
final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry()
|
||||
.getService( JdbcServices.class )
|
||||
.getSqlStatementLogger();
|
||||
final SessionEventListenerManager statsCollector = session.getEventListenerManager();
|
||||
|
||||
final WorkExecutorVisitable<IntegralDataTypeHolder> work = new AbstractReturningWork<IntegralDataTypeHolder>() {
|
||||
@Override
|
||||
public IntegralDataTypeHolder execute(Connection connection) throws SQLException {
|
||||
IntegralDataTypeHolder value = IdentifierGeneratorHelper.getIntegralDataTypeHolder( returnClass );
|
||||
|
||||
int rows;
|
||||
do {
|
||||
final PreparedStatement queryPreparedStatement = prepareStatement(
|
||||
connection,
|
||||
query,
|
||||
statementLogger,
|
||||
statsCollector
|
||||
);
|
||||
try {
|
||||
final ResultSet rs = executeQuery( queryPreparedStatement, statsCollector );
|
||||
boolean isInitialized = rs.next();
|
||||
if ( !isInitialized ) {
|
||||
value.initialize( 0 );
|
||||
final PreparedStatement insertPreparedStatement = prepareStatement(
|
||||
connection,
|
||||
insert,
|
||||
statementLogger,
|
||||
statsCollector
|
||||
);
|
||||
try {
|
||||
value.bind( insertPreparedStatement, 1 );
|
||||
executeUpdate( insertPreparedStatement, statsCollector );
|
||||
}
|
||||
finally {
|
||||
insertPreparedStatement.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
value.initialize( rs, 0 );
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
LOG.unableToReadOrInitHiValue( sqle );
|
||||
throw sqle;
|
||||
}
|
||||
finally {
|
||||
queryPreparedStatement.close();
|
||||
}
|
||||
|
||||
|
||||
final PreparedStatement updatePreparedStatement = prepareStatement(
|
||||
connection,
|
||||
update,
|
||||
statementLogger,
|
||||
statsCollector
|
||||
);
|
||||
try {
|
||||
value.copy().increment().bind( updatePreparedStatement, 1 );
|
||||
value.bind( updatePreparedStatement, 2 );
|
||||
|
||||
rows = executeUpdate( updatePreparedStatement, statsCollector );
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
LOG.error( LOG.unableToUpdateHiValue( physicalTableName.render() ), sqle );
|
||||
throw sqle;
|
||||
}
|
||||
finally {
|
||||
updatePreparedStatement.close();
|
||||
}
|
||||
} while ( rows == 0 );
|
||||
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
// maxLo < 1 indicates a hilo generator with no hilo :?
|
||||
if ( maxLo < 1 ) {
|
||||
//keep the behavior consistent even for boundary usages
|
||||
IntegralDataTypeHolder value = null;
|
||||
while ( value == null || value.lt( 1 ) ) {
|
||||
value = session.getTransactionCoordinator().createIsolationDelegate().delegateWork( work, true );
|
||||
}
|
||||
return value.makeValue();
|
||||
}
|
||||
|
||||
return hiloOptimizer.generate(
|
||||
new AccessCallback() {
|
||||
public IntegralDataTypeHolder getNextValue() {
|
||||
return session.getTransactionCoordinator().createIsolationDelegate().delegateWork(
|
||||
work,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTenantIdentifier() {
|
||||
return session.getTenantIdentifier();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private PreparedStatement prepareStatement(
|
||||
Connection connection,
|
||||
String sql,
|
||||
SqlStatementLogger statementLogger,
|
||||
SessionEventListenerManager statsCollector) throws SQLException {
|
||||
statementLogger.logStatement( sql, FormatStyle.BASIC.getFormatter() );
|
||||
try {
|
||||
statsCollector.jdbcPrepareStatementStart();
|
||||
return connection.prepareStatement( sql );
|
||||
}
|
||||
finally {
|
||||
statsCollector.jdbcPrepareStatementEnd();
|
||||
}
|
||||
}
|
||||
|
||||
private int executeUpdate(PreparedStatement ps, SessionEventListenerManager statsCollector) throws SQLException {
|
||||
try {
|
||||
statsCollector.jdbcExecuteStatementStart();
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
finally {
|
||||
statsCollector.jdbcExecuteStatementEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ResultSet executeQuery(PreparedStatement ps, SessionEventListenerManager statsCollector)
|
||||
throws SQLException {
|
||||
try {
|
||||
statsCollector.jdbcExecuteStatementStart();
|
||||
return ps.executeQuery();
|
||||
}
|
||||
finally {
|
||||
statsCollector.jdbcExecuteStatementEnd();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"StatementWithEmptyBody", "deprecation"})
|
||||
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
returnClass = type.getReturnedClass();
|
||||
|
||||
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
|
||||
|
||||
qualifiedTableName = determineGeneratorTableName( params, jdbcEnvironment );
|
||||
|
||||
segmentColumnName = determineSegmentColumnName( params, jdbcEnvironment );
|
||||
keySize = ConfigurationHelper.getInt( PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH );
|
||||
segmentName = ConfigurationHelper.getString( PK_VALUE_NAME, params, params.getProperty( TABLE ) );
|
||||
|
||||
valueColumnName = determineValueColumnName( params, jdbcEnvironment );
|
||||
|
||||
//hilo config
|
||||
maxLo = ConfigurationHelper.getInt( MAX_LO, params, Short.MAX_VALUE );
|
||||
|
||||
if ( maxLo >= 1 ) {
|
||||
hiloOptimizer = new LegacyHiLoAlgorithmOptimizer( returnClass, maxLo );
|
||||
}
|
||||
|
||||
contributor = params.getProperty( CONTRIBUTOR_NAME );
|
||||
if ( contributor == null ) {
|
||||
contributor = "orm";
|
||||
}
|
||||
}
|
||||
|
||||
protected QualifiedName determineGeneratorTableName(Properties params, JdbcEnvironment jdbcEnvironment) {
|
||||
final String tableName = ConfigurationHelper.getString( ID_TABLE, params, DEFAULT_TABLE );
|
||||
|
||||
if ( tableName.contains( "." ) ) {
|
||||
return QualifiedNameParser.INSTANCE.parse( tableName );
|
||||
}
|
||||
else {
|
||||
// todo : need to incorporate implicit catalog and schema names
|
||||
final Identifier catalog = jdbcEnvironment.getIdentifierHelper().toIdentifier(
|
||||
ConfigurationHelper.getString( CATALOG, params )
|
||||
);
|
||||
final Identifier schema = jdbcEnvironment.getIdentifierHelper().toIdentifier(
|
||||
ConfigurationHelper.getString( SCHEMA, params )
|
||||
);
|
||||
return new QualifiedNameParser.NameParts(
|
||||
catalog,
|
||||
schema,
|
||||
jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected String determineSegmentColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
|
||||
final String name = ConfigurationHelper.getString( PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN );
|
||||
return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
|
||||
}
|
||||
|
||||
protected String determineValueColumnName(Properties params, JdbcEnvironment jdbcEnvironment) {
|
||||
final String name = ConfigurationHelper.getString( VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN );
|
||||
return jdbcEnvironment.getIdentifierHelper().toIdentifier( name ).render( jdbcEnvironment.getDialect() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerExportables(Database database) {
|
||||
final Namespace namespace = database.locateNamespace(
|
||||
qualifiedTableName.getCatalogName(),
|
||||
qualifiedTableName.getSchemaName()
|
||||
);
|
||||
|
||||
Table table = namespace.locateTable( qualifiedTableName.getObjectName() );
|
||||
if ( table == null ) {
|
||||
table = namespace.createTable(
|
||||
qualifiedTableName.getObjectName(),
|
||||
(identifier) -> new Table( contributor, namespace, identifier, false )
|
||||
);
|
||||
|
||||
// todo : not sure the best solution here. do we add the columns if missing? other?
|
||||
table.setPrimaryKey( new PrimaryKey( table ) );
|
||||
|
||||
final BasicTypeRegistry basicTypeRegistry = database.getTypeConfiguration().getBasicTypeRegistry();
|
||||
final Column pkColumn = new ExportableColumn(
|
||||
database,
|
||||
table,
|
||||
segmentColumnName,
|
||||
basicTypeRegistry.resolve( StandardBasicTypes.STRING ),
|
||||
database.getDialect().getTypeName( Types.VARCHAR, Size.length(keySize) )
|
||||
);
|
||||
pkColumn.setNullable( false );
|
||||
table.addColumn( pkColumn );
|
||||
table.getPrimaryKey().addColumn( pkColumn );
|
||||
|
||||
final Column valueColumn = new ExportableColumn(
|
||||
database,
|
||||
table,
|
||||
valueColumnName,
|
||||
basicTypeRegistry.resolve( StandardBasicTypes.LONG )
|
||||
);
|
||||
table.addColumn( valueColumn );
|
||||
}
|
||||
|
||||
// allow physical naming strategies a chance to kick in
|
||||
physicalTableName = table.getQualifiedTableName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(SqlStringGenerationContext context) {
|
||||
String formattedPhysicalTableName = context.format( physicalTableName );
|
||||
|
||||
query = "select " +
|
||||
valueColumnName +
|
||||
" from " +
|
||||
context.getDialect().appendLockHint( new LockOptions( LockMode.PESSIMISTIC_WRITE ), formattedPhysicalTableName ) +
|
||||
" where " + segmentColumnName + " = '" + segmentName + "'" +
|
||||
context.getDialect().getForUpdateString();
|
||||
|
||||
update = "update " +
|
||||
formattedPhysicalTableName +
|
||||
" set " +
|
||||
valueColumnName +
|
||||
" = ? where " +
|
||||
valueColumnName +
|
||||
" = ? and " +
|
||||
segmentColumnName +
|
||||
" = '" +
|
||||
segmentName
|
||||
+ "'";
|
||||
|
||||
insert = "insert into " + formattedPhysicalTableName +
|
||||
"(" + segmentColumnName + ", " + valueColumnName + ") " +
|
||||
"values('" + segmentName + "', ?)";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,207 +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;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
|
||||
import org.hibernate.boot.model.relational.Database;
|
||||
import org.hibernate.boot.model.relational.Namespace;
|
||||
import org.hibernate.boot.model.relational.QualifiedName;
|
||||
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
||||
import org.hibernate.boot.model.relational.Sequence;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* <b>sequence</b><br>
|
||||
* <br>
|
||||
* Generates <tt>long</tt> values using an oracle-style sequence. A higher
|
||||
* performance algorithm is <tt>SequenceHiLoGenerator</tt>.<br>
|
||||
* <br>
|
||||
* Mapping parameters supported: sequence, parameters.
|
||||
*
|
||||
* @see SequenceHiLoGenerator
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated Use {@link org.hibernate.id.enhanced.SequenceStyleGenerator} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public class SequenceGenerator
|
||||
implements PersistentIdentifierGenerator, BulkInsertionCapableIdentifierGenerator {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger( SequenceGenerator.class.getName() );
|
||||
|
||||
/**
|
||||
* The sequence parameter
|
||||
*/
|
||||
public static final String SEQUENCE = "sequence";
|
||||
|
||||
/**
|
||||
* The parameters parameter, appended to the create sequence DDL.
|
||||
* For example (Oracle): <tt>INCREMENT BY 1 START WITH 1 MAXVALUE 100 NOCACHE</tt>.
|
||||
*
|
||||
* @deprecated No longer supported. To specify initial-value or increment use the
|
||||
* org.hibernate.id.enhanced.SequenceStyleGenerator generator instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String PARAMETERS = "parameters";
|
||||
|
||||
private String contributor;
|
||||
|
||||
private QualifiedName logicalQualifiedSequenceName;
|
||||
private QualifiedName physicalSequenceName;
|
||||
private Type identifierType;
|
||||
private String sql;
|
||||
|
||||
protected Type getIdentifierType() {
|
||||
return identifierType;
|
||||
}
|
||||
|
||||
public QualifiedName getPhysicalSequenceName() {
|
||||
return physicalSequenceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Exposed for tests only.
|
||||
*/
|
||||
@Deprecated
|
||||
public String[] getAllSqlForTests() {
|
||||
return new String[] { sql };
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optimizer getOptimizer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
DeprecationLogger.DEPRECATION_LOGGER.deprecatedSequenceGenerator( getClass().getName() );
|
||||
|
||||
identifierType = type;
|
||||
|
||||
final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get( IDENTIFIER_NORMALIZER );
|
||||
logicalQualifiedSequenceName = QualifiedNameParser.INSTANCE.parse(
|
||||
ConfigurationHelper.getString( SEQUENCE, params, "hibernate_sequence" ),
|
||||
normalizer.normalizeIdentifierQuoting( params.getProperty( CATALOG ) ),
|
||||
normalizer.normalizeIdentifierQuoting( params.getProperty( SCHEMA ) )
|
||||
);
|
||||
|
||||
if ( params.containsKey( PARAMETERS ) ) {
|
||||
LOG.warn(
|
||||
"Use of 'parameters' config setting is no longer supported; " +
|
||||
"to specify initial-value or increment use the " +
|
||||
"org.hibernate.id.enhanced.SequenceStyleGenerator generator instead."
|
||||
);
|
||||
}
|
||||
|
||||
contributor = determineContributor( params );
|
||||
}
|
||||
|
||||
private String determineContributor(Properties params) {
|
||||
final String contributor = params.getProperty( CONTRIBUTOR_NAME );
|
||||
return contributor == null ? "orm" : contributor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object generate(SharedSessionContractImplementor session, Object obj) {
|
||||
return generateHolder( session ).makeValue();
|
||||
}
|
||||
|
||||
protected IntegralDataTypeHolder generateHolder(SharedSessionContractImplementor session) {
|
||||
try {
|
||||
final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator();
|
||||
PreparedStatement st = jdbcCoordinator.getStatementPreparer().prepareStatement( sql );
|
||||
final LogicalConnectionImplementor logicalConnection = jdbcCoordinator.getLogicalConnection();
|
||||
try {
|
||||
ResultSet rs = jdbcCoordinator.getResultSetReturn().extract( st );
|
||||
try {
|
||||
rs.next();
|
||||
IntegralDataTypeHolder result = buildHolder();
|
||||
result.initialize( rs, 1 );
|
||||
LOG.debugf( "Sequence identifier generated: %s", result );
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
logicalConnection.getResourceRegistry().release( rs, st );
|
||||
}
|
||||
}
|
||||
finally {
|
||||
logicalConnection.getResourceRegistry().release( st );
|
||||
jdbcCoordinator.afterStatementExecution();
|
||||
}
|
||||
|
||||
}
|
||||
catch (SQLException sqle) {
|
||||
throw session.getJdbcServices().getSqlExceptionHelper().convert(
|
||||
sqle,
|
||||
"could not get next sequence value",
|
||||
sql
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected IntegralDataTypeHolder buildHolder() {
|
||||
return IdentifierGeneratorHelper.getIntegralDataTypeHolder( identifierType.getReturnedClass() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsBulkInsertionIdentifierGeneration() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String determineBulkInsertionIdentifierGenerationSelectFragment(SqlStringGenerationContext context) {
|
||||
return context.getDialect().getSequenceSupport().getSelectSequenceNextValString( context.format( getPhysicalSequenceName() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerExportables(Database database) {
|
||||
final Namespace namespace = database.locateNamespace(
|
||||
logicalQualifiedSequenceName.getCatalogName(),
|
||||
logicalQualifiedSequenceName.getSchemaName()
|
||||
);
|
||||
Sequence sequence = namespace.locateSequence( logicalQualifiedSequenceName.getObjectName() );
|
||||
if ( sequence != null ) {
|
||||
sequence.validate( 1, 1 );
|
||||
}
|
||||
else {
|
||||
sequence = namespace.createSequence(
|
||||
logicalQualifiedSequenceName.getObjectName(),
|
||||
(physicalName) -> new Sequence(
|
||||
contributor,
|
||||
namespace.getPhysicalName().getCatalog(),
|
||||
namespace.getPhysicalName().getSchema(),
|
||||
physicalName,
|
||||
1,
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
this.physicalSequenceName = sequence.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(SqlStringGenerationContext context) {
|
||||
String formattedPhysicalSequenceName = context.format( physicalSequenceName );
|
||||
this.sql = context.getDialect().getSequenceSupport().getSequenceNextValString( formattedPhysicalSequenceName );
|
||||
}
|
||||
}
|
@ -1,95 +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;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.enhanced.AccessCallback;
|
||||
import org.hibernate.id.enhanced.LegacyHiLoAlgorithmOptimizer;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* <b>seqhilo</b><br>
|
||||
* <br>
|
||||
* An <tt>IdentifierGenerator</tt> that combines a hi/lo algorithm with an underlying
|
||||
* oracle-style sequence that generates hi values. The user may specify a
|
||||
* maximum lo value to determine how often new hi values are fetched.<br>
|
||||
* <br>
|
||||
* Mapping parameters supported: sequence, max_lo, parameters.
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated See deprecation discussion on {@link SequenceGenerator}
|
||||
*/
|
||||
@Deprecated
|
||||
public class SequenceHiLoGenerator extends SequenceGenerator {
|
||||
public static final String MAX_LO = "max_lo";
|
||||
|
||||
private int maxLo;
|
||||
|
||||
private LegacyHiLoAlgorithmOptimizer hiloOptimizer;
|
||||
|
||||
@Override
|
||||
public Optimizer getOptimizer() {
|
||||
return hiloOptimizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
super.configure( type, params, serviceRegistry );
|
||||
|
||||
maxLo = ConfigurationHelper.getInt( MAX_LO, params, 9 );
|
||||
|
||||
if ( maxLo >= 1 ) {
|
||||
hiloOptimizer = new LegacyHiLoAlgorithmOptimizer(
|
||||
getIdentifierType().getReturnedClass(),
|
||||
maxLo
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Object generate(final SharedSessionContractImplementor session, Object obj) {
|
||||
// maxLo < 1 indicates a hilo generator with no hilo :?
|
||||
if ( maxLo < 1 ) {
|
||||
//keep the behavior consistent even for boundary usages
|
||||
IntegralDataTypeHolder value = null;
|
||||
while ( value == null || value.lt( 0 ) ) {
|
||||
value = super.generateHolder( session );
|
||||
}
|
||||
return value.makeValue();
|
||||
}
|
||||
|
||||
return hiloOptimizer.generate(
|
||||
new AccessCallback() {
|
||||
@Override
|
||||
public IntegralDataTypeHolder getNextValue() {
|
||||
return generateHolder( session );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTenantIdentifier() {
|
||||
return session.getTenantIdentifier();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* For testing/assertion purposes
|
||||
*
|
||||
* @return The optimizer
|
||||
*/
|
||||
LegacyHiLoAlgorithmOptimizer getHiloOptimizer() {
|
||||
return hiloOptimizer;
|
||||
}
|
||||
}
|
@ -1,120 +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;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.model.relational.QualifiedName;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.insert.AbstractReturningDelegate;
|
||||
import org.hibernate.id.insert.IdentifierGeneratingInsert;
|
||||
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.sql.Insert;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* A generator which combines sequence generation with immediate retrieval
|
||||
* through JDBC3 {@link java.sql.Connection#prepareStatement(String, String[]) getGeneratedKeys}.
|
||||
* In this respect it works much like ANSI-SQL IDENTITY generation.
|
||||
* <p/>
|
||||
* This generator only known to work with newer Oracle drivers compiled for
|
||||
* JDK 1.4 (JDBC3).
|
||||
* <p/>
|
||||
* Note: Due to a bug in Oracle drivers, sql comments on these insert statements
|
||||
* are completely disabled.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @deprecated See deprecation discussion on {@link SequenceGenerator}
|
||||
*/
|
||||
@Deprecated
|
||||
public class SequenceIdentityGenerator
|
||||
extends SequenceGenerator
|
||||
implements PostInsertIdentifierGenerator {
|
||||
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SequenceIdentityGenerator.class );
|
||||
|
||||
@Override
|
||||
public Object generate(SharedSessionContractImplementor s, Object obj) {
|
||||
return IdentifierGeneratorHelper.POST_INSERT_INDICATOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertGeneratedIdentifierDelegate getInsertGeneratedIdentifierDelegate(
|
||||
PostInsertIdentityPersister persister,
|
||||
Dialect dialect,
|
||||
boolean isGetGeneratedKeysEnabled) throws HibernateException {
|
||||
return new Delegate( persister, getPhysicalSequenceName() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
super.configure( type, params, serviceRegistry );
|
||||
}
|
||||
|
||||
public static class Delegate extends AbstractReturningDelegate {
|
||||
private final QualifiedName physicalSequenceName;
|
||||
private final String[] keyColumns;
|
||||
|
||||
public Delegate(PostInsertIdentityPersister persister, QualifiedName physicalSequenceName) {
|
||||
super( persister );
|
||||
this.physicalSequenceName = physicalSequenceName;
|
||||
this.keyColumns = getPersister().getRootTableKeyColumnNames();
|
||||
if ( keyColumns.length > 1 ) {
|
||||
throw new HibernateException( "sequence-identity generator cannot be used with multi-column keys" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert(SqlStringGenerationContext context) {
|
||||
Dialect dialect = context.getDialect();
|
||||
NoCommentsInsert insert = new NoCommentsInsert( dialect );
|
||||
String sequenceNextValFragment = dialect.getSequenceSupport().getSelectSequenceNextValString( context.format( physicalSequenceName ) );
|
||||
insert.addColumn( getPersister().getRootTableKeyColumnNames()[0], sequenceNextValFragment );
|
||||
return insert;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PreparedStatement prepare(String insertSQL, SharedSessionContractImplementor session) throws SQLException {
|
||||
return session.getJdbcCoordinator().getStatementPreparer().prepareStatement( insertSQL, keyColumns );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object executeAndExtract(PreparedStatement insert, SharedSessionContractImplementor session)
|
||||
throws SQLException {
|
||||
session.getJdbcCoordinator().getResultSetReturn().executeUpdate( insert );
|
||||
return IdentifierGeneratorHelper.getGeneratedIdentity(
|
||||
insert.getGeneratedKeys(),
|
||||
getPersister().getRootTableKeyColumnNames()[0],
|
||||
getPersister().getIdentifierType(),
|
||||
session.getJdbcServices().getJdbcEnvironment().getDialect()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoCommentsInsert extends IdentifierGeneratingInsert {
|
||||
public NoCommentsInsert(Dialect dialect) {
|
||||
super( dialect );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Insert setComment(String comment) {
|
||||
// don't allow comments on these insert statements as comments totally
|
||||
// blow up the Oracle getGeneratedKeys "support" :(
|
||||
LOG.disallowingInsertStatementComment();
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -39,27 +39,21 @@
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class UUIDGenerator implements IdentifierGenerator {
|
||||
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_CLASS = "uuid_gen_strategy_class";
|
||||
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( UUIDGenerator.class );
|
||||
|
||||
private UUIDGenerationStrategy strategy;
|
||||
private UUIDJavaTypeDescriptor.ValueTransformer valueTransformer;
|
||||
|
||||
public static UUIDGenerator buildSessionFactoryUniqueIdentifierGenerator() {
|
||||
final UUIDGenerator generator = new UUIDGenerator();
|
||||
generator.strategy = StandardRandomStrategy.INSTANCE;
|
||||
generator.valueTransformer = UUIDJavaTypeDescriptor.ToStringTransformer.INSTANCE;
|
||||
return generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
// check first for the strategy instance
|
||||
// check first for an explicit strategy instance
|
||||
strategy = (UUIDGenerationStrategy) params.get( UUID_GEN_STRATEGY );
|
||||
|
||||
if ( strategy == null ) {
|
||||
// next check for the strategy class
|
||||
// next check for an explicit strategy class
|
||||
final String strategyClassName = params.getProperty( UUID_GEN_STRATEGY_CLASS );
|
||||
if ( strategyClassName != null ) {
|
||||
try {
|
||||
@ -77,6 +71,7 @@ public void configure(Type type, Properties params, ServiceRegistry serviceRegis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( strategy == null ) {
|
||||
// lastly use the standard random generator
|
||||
strategy = StandardRandomStrategy.INSTANCE;
|
||||
@ -86,6 +81,7 @@ public void configure(Type type, Properties params, ServiceRegistry serviceRegis
|
||||
valueTransformer = UUIDJavaTypeDescriptor.PassThroughTransformer.INSTANCE;
|
||||
}
|
||||
else if ( String.class.isAssignableFrom( type.getReturnedClass() ) ) {
|
||||
// todo (6.0) : allow for org.hibernate.type.descriptor.java.UUIDJavaTypeDescriptor.NoDashesStringTransformer
|
||||
valueTransformer = UUIDJavaTypeDescriptor.ToStringTransformer.INSTANCE;
|
||||
}
|
||||
else if ( byte[].class.isAssignableFrom( type.getReturnedClass() ) ) {
|
||||
|
@ -49,7 +49,7 @@
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #SEQUENCE_PARAM}</td>
|
||||
* <td>{@link #DEF_SEQUENCE_NAME}</td>
|
||||
* <td>N/A</td>
|
||||
* <td>The name of the sequence/table to use to store/retrieve values</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
@ -107,13 +107,7 @@ public class SequenceStyleGenerator
|
||||
* based on the entity / collection-role name
|
||||
*/
|
||||
public static final String SEQUENCE_PARAM = "sequence_name";
|
||||
|
||||
/**
|
||||
* @deprecated As of 6.0 with no replacement - `hibernate_sequence` as a real, implicit exportable name
|
||||
* is no longer supported. No effect
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String DEF_SEQUENCE_NAME = "hibernate_sequence";
|
||||
public static final String ALT_SEQUENCE_PARAM = "sequence";
|
||||
|
||||
/**
|
||||
* Specifies the suffix to use for an implicit sequence name - appended to the entity-name / collection-role
|
||||
@ -295,7 +289,12 @@ protected QualifiedName determineSequenceName(
|
||||
ConfigurationHelper.getString( SCHEMA, params )
|
||||
);
|
||||
|
||||
final String sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params );
|
||||
final String sequenceName = ConfigurationHelper.getString(
|
||||
SEQUENCE_PARAM,
|
||||
params,
|
||||
() -> ConfigurationHelper.getString( ALT_SEQUENCE_PARAM, params )
|
||||
);
|
||||
|
||||
if ( StringHelper.isNotEmpty( sequenceName ) ) {
|
||||
// we have an explicit name, use it
|
||||
if ( sequenceName.contains( "." ) ) {
|
||||
|
@ -65,13 +65,6 @@
|
||||
* performing generation, which would mean that we would have a row in the generator
|
||||
* table for each entity name. Or any configuration really; the setup is very flexible.
|
||||
* <p/>
|
||||
* In this respect it is very similar to the legacy
|
||||
* {@link org.hibernate.id.MultipleHiLoPerTableGenerator} in terms of the
|
||||
* underlying storage structure (namely a single table capable of holding
|
||||
* multiple generator values). The differentiator is, as with
|
||||
* {@link SequenceStyleGenerator} as well, the externalized notion
|
||||
* of an optimizer.
|
||||
* <p/>
|
||||
* <b>NOTE</b> that by default we use a single row for all generators (based
|
||||
* on {@link #DEF_SEGMENT_VALUE}). The configuration parameter
|
||||
* {@link #CONFIG_PREFER_SEGMENT_PER_ENTITY} can be used to change that to
|
||||
|
@ -13,10 +13,8 @@
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.id.Assigned;
|
||||
import org.hibernate.id.ForeignGenerator;
|
||||
@ -25,9 +23,6 @@
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.IncrementGenerator;
|
||||
import org.hibernate.id.SelectGenerator;
|
||||
import org.hibernate.id.SequenceGenerator;
|
||||
import org.hibernate.id.SequenceHiLoGenerator;
|
||||
import org.hibernate.id.SequenceIdentityGenerator;
|
||||
import org.hibernate.id.UUIDGenerator;
|
||||
import org.hibernate.id.UUIDHexGenerator;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
@ -36,6 +31,7 @@
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.resource.beans.container.spi.BeanContainer;
|
||||
import org.hibernate.resource.beans.container.spi.ContainedBean;
|
||||
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
|
||||
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
@ -50,7 +46,7 @@
|
||||
*/
|
||||
@SuppressWarnings( { "deprecation" ,"rawtypes" ,"serial" } )
|
||||
public class DefaultIdentifierGeneratorFactory
|
||||
implements MutableIdentifierGeneratorFactory, Serializable, ServiceRegistryAwareService {
|
||||
implements MutableIdentifierGeneratorFactory, Serializable, ServiceRegistryAwareService, BeanContainer.LifecycleOptions {
|
||||
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( DefaultIdentifierGeneratorFactory.class );
|
||||
|
||||
@ -78,18 +74,18 @@ public DefaultIdentifierGeneratorFactory() {
|
||||
*/
|
||||
public DefaultIdentifierGeneratorFactory(boolean ignoreBeanContainer) {
|
||||
this.ignoreBeanContainer = ignoreBeanContainer;
|
||||
register( "uuid", UUIDHexGenerator.class );
|
||||
register( "uuid2", UUIDGenerator.class );
|
||||
register( "guid", GUIDGenerator.class ); // can be done with UUIDGenerator + strategy
|
||||
register( "uuid", UUIDHexGenerator.class ); // "deprecated" for new use
|
||||
register( "uuid.hex", UUIDHexGenerator.class ); // uuid.hex is deprecated
|
||||
register( "uuid.hex", UUIDHexGenerator.class );
|
||||
// could be done with UUIDGenerator + strategy
|
||||
register( "guid", GUIDGenerator.class );
|
||||
|
||||
register( "assigned", Assigned.class );
|
||||
register( "identity", IdentityGenerator.class );
|
||||
register( "select", SelectGenerator.class );
|
||||
register( "sequence", SequenceStyleGenerator.class );
|
||||
register( "seqhilo", SequenceHiLoGenerator.class );
|
||||
register( "increment", IncrementGenerator.class );
|
||||
register( "foreign", ForeignGenerator.class );
|
||||
register( "sequence-identity", SequenceIdentityGenerator.class );
|
||||
register( "enhanced-sequence", SequenceStyleGenerator.class );
|
||||
register( "enhanced-table", TableGenerator.class );
|
||||
}
|
||||
@ -121,23 +117,12 @@ public IdentifierGenerator createIdentifierGenerator(String strategy, Type type,
|
||||
identifierGenerator = ( IdentifierGenerator ) clazz.newInstance();
|
||||
}
|
||||
else {
|
||||
identifierGenerator = ( IdentifierGenerator ) beanContainer.getBean(
|
||||
final ContainedBean<IdentifierGenerator> generatorBean = beanContainer.getBean(
|
||||
clazz,
|
||||
new BeanContainer.LifecycleOptions() {
|
||||
|
||||
@Override
|
||||
public boolean canUseCachedReferences() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useJpaCompliantCreation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
},
|
||||
this,
|
||||
FallbackBeanInstanceProducer.INSTANCE
|
||||
).getBeanInstance();
|
||||
);
|
||||
identifierGenerator = generatorBean.getBeanInstance();
|
||||
}
|
||||
identifierGenerator.configure( type, config, serviceRegistry );
|
||||
return identifierGenerator;
|
||||
@ -148,6 +133,16 @@ public boolean useJpaCompliantCreation() {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseCachedReferences() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useJpaCompliantCreation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getIdentifierGeneratorClass(String strategy) {
|
||||
if ( "hilo".equals( strategy ) ) {
|
||||
@ -178,15 +173,5 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {
|
||||
this.beanContainer = serviceRegistry.getService( ManagedBeanRegistry.class ).getBeanContainer();
|
||||
//else we just have beanContainer = null;
|
||||
}
|
||||
|
||||
final boolean useNewIdentifierGenerators = configService.getSetting(
|
||||
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
|
||||
if ( ! useNewIdentifierGenerators ) {
|
||||
register( "sequence", SequenceGenerator.class );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,24 @@ public static String getString(String name, Map values) {
|
||||
* @return The value.
|
||||
*/
|
||||
public static String getString(String name, Map values, String defaultValue) {
|
||||
final String value = getString( name, values );
|
||||
return value == null ? defaultValue : value;
|
||||
return getString( name, values, () -> defaultValue );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config value as a {@link String}
|
||||
*
|
||||
* @param name The config setting name.
|
||||
* @param values The map of config values
|
||||
*
|
||||
* @return The value, or null if not found
|
||||
*/
|
||||
public static String getString(String name, Map<?,?> values, Supplier<String> defaultValueSupplier) {
|
||||
final Object value = values.get( name );
|
||||
if ( value != null ) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return defaultValueSupplier.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,8 +53,7 @@ public static JpaStaticMetaModelPopulationSetting determineJpaMetaModelPopulatio
|
||||
private static String determineSetting(Map configurationValues) {
|
||||
final String setting = ConfigurationHelper.getString(
|
||||
AvailableSettings.STATIC_METAMODEL_POPULATION,
|
||||
configurationValues,
|
||||
null
|
||||
configurationValues
|
||||
);
|
||||
if ( setting != null ) {
|
||||
return setting;
|
||||
|
@ -150,7 +150,7 @@ private static boolean isCacheable(Map<String, Object> hints, SessionFactoryImpl
|
||||
|
||||
private static String determineCacheRegion(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
||||
assert sessionFactory.getSessionFactoryOptions().isQueryCacheEnabled();
|
||||
return ConfigurationHelper.getString( QueryHints.HINT_CACHE_REGION, hints, null );
|
||||
return ConfigurationHelper.getString( QueryHints.HINT_CACHE_REGION, hints );
|
||||
}
|
||||
|
||||
private static CacheMode determineCacheMode(Map<String, Object> hints, SessionFactoryImplementor sessionFactory) {
|
||||
|
@ -114,6 +114,33 @@ public UUID parse(Object value) {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoDashesStringTransformer implements ValueTransformer {
|
||||
public static final NoDashesStringTransformer INSTANCE = new NoDashesStringTransformer();
|
||||
|
||||
public String transform(UUID uuid) {
|
||||
final String stringForm = ToStringTransformer.INSTANCE.transform( uuid );
|
||||
return stringForm.substring( 0, 8 )
|
||||
+ stringForm.substring( 9, 13 )
|
||||
+ stringForm.substring( 14, 18 )
|
||||
+ stringForm.substring( 19, 23 )
|
||||
+ stringForm.substring( 24 );
|
||||
}
|
||||
|
||||
public UUID parse(Object value) {
|
||||
final String stringValue = (String) value;
|
||||
final String uuidString = stringValue.substring( 0, 8 )
|
||||
+ "-"
|
||||
+ stringValue.substring( 8, 12 )
|
||||
+ "-"
|
||||
+ stringValue.substring( 12, 16 )
|
||||
+ "-"
|
||||
+ stringValue.substring( 16, 20 )
|
||||
+ "-"
|
||||
+ stringValue.substring( 20 );
|
||||
return UUID.fromString( uuidString );
|
||||
}
|
||||
}
|
||||
|
||||
public static class ToBytesTransformer implements ValueTransformer {
|
||||
public static final ToBytesTransformer INSTANCE = new ToBytesTransformer();
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
@Entity
|
||||
public class Document implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO) // Required to use SequenceIdentityGenerator in test case for HHH-8103.
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Integer revision;
|
||||
|
@ -1,85 +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.annotations.lob;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue( jiraKey = "HHH-8103" )
|
||||
@RequiresDialect( OracleDialect.class )
|
||||
public class LobWithSequenceIdentityGeneratorTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty( Environment.DIALECT, OracleSeqIdGenDialect.class.getName() );
|
||||
configuration.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "false" );
|
||||
configuration.setProperty( Environment.USE_GET_GENERATED_KEYS, "true" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] { Document.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLobInsertUpdateDeleteSelect() {
|
||||
Session session = openSession();
|
||||
|
||||
// Insert
|
||||
session.getTransaction().begin();
|
||||
Document document = new Document( 1, "HHH-8103", "Oracle expects all LOB properties to be last in INSERT and UPDATE statements." );
|
||||
session.persist( document );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session.clear();
|
||||
|
||||
session.getTransaction().begin();
|
||||
Assert.assertEquals( document, session.get( Document.class, document.getId() ) );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session.clear();
|
||||
|
||||
// Update
|
||||
session.getTransaction().begin();
|
||||
document = (Document) session.get( Document.class, document.getId() );
|
||||
document.setFullText( "Correct!" );
|
||||
session.update( document );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session.clear();
|
||||
|
||||
session.getTransaction().begin();
|
||||
Assert.assertEquals( document, session.get( Document.class, document.getId() ) );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session.clear();
|
||||
|
||||
// Delete
|
||||
session.getTransaction().begin();
|
||||
document = (Document) session.get( Document.class, document.getId() );
|
||||
session.delete( document );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session.clear();
|
||||
|
||||
session.getTransaction().begin();
|
||||
Assert.assertNull( session.get( Document.class, document.getId() ) );
|
||||
session.getTransaction().commit();
|
||||
|
||||
session.close();
|
||||
}
|
||||
}
|
@ -288,7 +288,6 @@ private Properties buildProperties() {
|
||||
if ( createSchema() ) {
|
||||
properties.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
properties.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
properties.put( AvailableSettings.DIALECT, getDialect().getClass().getName() );
|
||||
|
||||
return properties;
|
||||
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<!--
|
||||
|
||||
This mapping demonstrates the use of
|
||||
the EJB3 compliant table hilo generator
|
||||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.orm.test.id">
|
||||
|
||||
<class name="Car">
|
||||
|
||||
<id name="id">
|
||||
<generator class="org.hibernate.id.MultipleHiLoPerTableGenerator">
|
||||
<param name="max_lo">0</param>
|
||||
</generator>
|
||||
</id>
|
||||
<property name="color"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
@ -1,34 +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>.
|
||||
*/
|
||||
|
||||
//$Id: Car.java 5686 2005-02-12 07:27:32Z steveebersole $
|
||||
package org.hibernate.orm.test.id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Car {
|
||||
private Long id;
|
||||
private String color;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
}
|
@ -1,81 +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.id;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = {
|
||||
"org/hibernate/orm/test/id/Car.hbm.xml",
|
||||
"org/hibernate/orm/test/id/Plane.hbm.xml",
|
||||
"org/hibernate/orm/test/id/Radio.hbm.xml"
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class MultipleHiLoPerTableGeneratorTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Car" ).executeUpdate();
|
||||
session.createQuery( "delete from Plane" ).executeUpdate();
|
||||
session.createQuery( "delete from Radio" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistinctId(SessionFactoryScope scope) {
|
||||
int testLength = 8;
|
||||
Car[] cars = new Car[testLength];
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Plane[] planes = new Plane[testLength];
|
||||
for ( int i = 0; i < testLength; i++ ) {
|
||||
cars[i] = new Car();
|
||||
cars[i].setColor( "Color" + i );
|
||||
planes[i] = new Plane();
|
||||
planes[i].setNbrOfSeats( i );
|
||||
session.persist( cars[i] );
|
||||
//s.persist(planes[i]);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
for ( int i = 0; i < testLength; i++ ) {
|
||||
assertEquals( i + 1, cars[i].getId().intValue() );
|
||||
//assertEquals(i+1, planes[i].getId().intValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllParams(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
Radio radio = new Radio();
|
||||
radio.setFrequency( "32 MHz" );
|
||||
session.persist( radio );
|
||||
assertEquals( new Integer( 1 ), radio.getId() );
|
||||
radio = new Radio();
|
||||
radio.setFrequency( "32 MHz" );
|
||||
session.persist( radio );
|
||||
assertEquals( new Integer( 2 ), radio.getId() );
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -1,73 +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.id;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = {
|
||||
"org/hibernate/orm/test/id/Car.hbm.xml"
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class MultipleHiLoPerTableGeneratorWithRollbackTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createQuery( "delete from Car" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRollingBack(SessionFactoryScope scope) {
|
||||
int testLength = 3;
|
||||
Long lastId = scope.fromSession(
|
||||
session -> {
|
||||
session.getTransaction().begin();
|
||||
try {
|
||||
Long id = null;
|
||||
for ( int i = 0; i < testLength; i++ ) {
|
||||
Car car = new Car();
|
||||
car.setColor( "color " + i );
|
||||
session.save( car );
|
||||
id = car.getId();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
finally {
|
||||
session.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Car car = new Car();
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
car.setColor( "blue" );
|
||||
session.save( car );
|
||||
session.flush();
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals( lastId.longValue() + 1, car.getId().longValue(), "id generation was rolled back" );
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<!--
|
||||
|
||||
This mapping demonstrates the use of
|
||||
the EJB3 compliant table hilo generator
|
||||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.orm.test.id">
|
||||
|
||||
<class name="Plane">
|
||||
|
||||
<id name="id">
|
||||
<generator class="org.hibernate.id.MultipleHiLoPerTableGenerator">
|
||||
<param name="max_lo">2</param>
|
||||
</generator>
|
||||
</id>
|
||||
<property name="nbrOfSeats"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
@ -1,34 +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>.
|
||||
*/
|
||||
|
||||
//$Id: Plane.java 5686 2005-02-12 07:27:32Z steveebersole $
|
||||
package org.hibernate.orm.test.id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Plane {
|
||||
private Long id;
|
||||
private int nbrOfSeats;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getNbrOfSeats() {
|
||||
return nbrOfSeats;
|
||||
}
|
||||
|
||||
public void setNbrOfSeats(int nbrOfSeats) {
|
||||
this.nbrOfSeats = nbrOfSeats;
|
||||
}
|
||||
}
|
@ -44,7 +44,6 @@
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.cfg.AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
@ -55,7 +54,6 @@
|
||||
annotatedClasses = PooledHiLoSequenceIdentifierTest.SequenceIdentifier.class
|
||||
)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(settings = @Setting(name = USE_NEW_ID_GENERATOR_MAPPINGS, value = "true"))
|
||||
public class PooledHiLoSequenceIdentifierTest {
|
||||
|
||||
@AfterEach
|
||||
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.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>.
|
||||
-->
|
||||
<!DOCTYPE hibernate-mapping PUBLIC
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<!--
|
||||
|
||||
This mapping demonstrates the use of
|
||||
the EJB3 compliant table hilo generator
|
||||
with all the parameters
|
||||
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.orm.test.id">
|
||||
|
||||
<class name="Radio">
|
||||
|
||||
<id name="id">
|
||||
<generator class="org.hibernate.id.MultipleHiLoPerTableGenerator">
|
||||
<param name="table">sequences</param>
|
||||
<param name="value_column">hi_value</param>
|
||||
<param name="primary_key_column">name</param>
|
||||
<param name="primary_key_length">50</param>
|
||||
<param name="max_lo">2</param>
|
||||
<param name="primary_key_value">Radio</param>
|
||||
</generator>
|
||||
</id>
|
||||
<property name="frequency"/>
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
@ -1,34 +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>.
|
||||
*/
|
||||
|
||||
//$Id: Radio.java 5686 2005-02-12 07:27:32Z steveebersole $
|
||||
package org.hibernate.orm.test.id;
|
||||
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
public class Radio {
|
||||
private Integer id;
|
||||
private String frequency;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFrequency() {
|
||||
return frequency;
|
||||
}
|
||||
|
||||
public void setFrequency(String frequency) {
|
||||
this.frequency = frequency;
|
||||
}
|
||||
}
|
@ -27,9 +27,6 @@
|
||||
xmlMappings = "org/hibernate/orm/test/id/Person.hbm.xml"
|
||||
)
|
||||
@SessionFactory(statementInspectorClass = SQLStatementInspector.class)
|
||||
@ServiceRegistry(
|
||||
settings = @Setting(name = Environment.USE_NEW_ID_GENERATOR_MAPPINGS, value = "false")
|
||||
)
|
||||
public class SequenceGeneratorTest {
|
||||
|
||||
|
||||
|
@ -1,133 +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.id;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.Session;
|
||||
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.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.SequenceGenerator;
|
||||
import org.hibernate.id.SequenceHiLoGenerator;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
|
||||
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
|
||||
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsSequences;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
|
||||
* unit test so that we can make sure the value keep being generated in the expected manner
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
@RequiresDialectFeature(feature = SupportsSequences.class)
|
||||
@BaseUnitTest
|
||||
public class SequenceHiLoGeneratorNoIncrementTest {
|
||||
private static final String TEST_SEQUENCE = "test_sequence";
|
||||
|
||||
private StandardServiceRegistry serviceRegistry;
|
||||
private SessionFactoryImplementor sessionFactory;
|
||||
private SequenceGenerator generator;
|
||||
private SequenceValueExtractor sequenceValueExtractor;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.enableAutoClose()
|
||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
|
||||
.build();
|
||||
|
||||
|
||||
MetadataBuildingContext buildingContext = new MetadataBuildingContextTestingImpl( serviceRegistry );
|
||||
// Build the properties used to configure the id generator
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE );
|
||||
properties.setProperty( SequenceHiLoGenerator.MAX_LO, "0" ); // JPA allocationSize of 1
|
||||
|
||||
properties.put(
|
||||
PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
|
||||
buildingContext.getObjectNameNormalizer()
|
||||
);
|
||||
|
||||
generator = new SequenceHiLoGenerator();
|
||||
generator.configure(
|
||||
buildingContext.getBootstrapContext()
|
||||
.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( StandardBasicTypes.LONG ),
|
||||
properties,
|
||||
serviceRegistry
|
||||
);
|
||||
|
||||
final Metadata metadata = new MetadataSources( serviceRegistry ).buildMetadata();
|
||||
generator.registerExportables( metadata.getDatabase() );
|
||||
|
||||
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
|
||||
generator.initialize( sessionFactory.getSqlStringGenerationContext() );
|
||||
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if ( sessionFactory != null ) {
|
||||
sessionFactory.close();
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHiLoAlgorithm() {
|
||||
TransactionUtil.doInHibernate(
|
||||
() -> sessionFactory,
|
||||
session -> {
|
||||
assertEquals( 1L, generateValue( session ) );
|
||||
|
||||
assertEquals( 1L, extractSequenceValue( session ) );
|
||||
|
||||
assertEquals( 2L, generateValue( session ) );
|
||||
assertEquals( 2L, extractSequenceValue( session ) );
|
||||
|
||||
assertEquals( 3L, generateValue( session ) );
|
||||
assertEquals( 3L, extractSequenceValue( session ) );
|
||||
|
||||
assertEquals( 4L, generateValue( session ) );
|
||||
assertEquals( 4L, extractSequenceValue( session ) );
|
||||
|
||||
assertEquals( 5L, generateValue( session ) );
|
||||
assertEquals( 5L, extractSequenceValue( session ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private long extractSequenceValue(Session session) {
|
||||
return sequenceValueExtractor.extractSequenceValue( (SessionImplementor) session );
|
||||
}
|
||||
|
||||
private long generateValue(Session session) {
|
||||
return (Long) generator.generate( (SharedSessionContractImplementor) session, null );
|
||||
}
|
||||
}
|
@ -1,144 +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.id;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.model.relational.Database;
|
||||
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.MetadataBuildingContext;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.SequenceGenerator;
|
||||
import org.hibernate.id.SequenceHiLoGenerator;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
|
||||
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsSequences;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.transaction.TransactionUtil;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this
|
||||
* unit test so that we can make sure the value keep being generated in the expected manner
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@SuppressWarnings({"deprecation"})
|
||||
@RequiresDialectFeature(feature = SupportsSequences.class)
|
||||
@BaseUnitTest
|
||||
public class SequenceHiLoGeneratorTest {
|
||||
private static final String TEST_SEQUENCE = "test_sequence";
|
||||
|
||||
private StandardServiceRegistry serviceRegistry;
|
||||
private SessionFactoryImplementor sessionFactory;
|
||||
private SequenceHiLoGenerator generator;
|
||||
private SequenceValueExtractor sequenceValueExtractor;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.enableAutoClose()
|
||||
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
|
||||
.build();
|
||||
|
||||
MetadataBuildingContext buildingContext = new MetadataBuildingContextTestingImpl( serviceRegistry );
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE );
|
||||
properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" );
|
||||
properties.put(
|
||||
PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
|
||||
buildingContext.getObjectNameNormalizer()
|
||||
);
|
||||
|
||||
generator = new SequenceHiLoGenerator();
|
||||
generator.configure(
|
||||
buildingContext.getBootstrapContext()
|
||||
.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( StandardBasicTypes.LONG ),
|
||||
properties,
|
||||
serviceRegistry
|
||||
);
|
||||
|
||||
Metadata metadata = new MetadataSources( serviceRegistry ).buildMetadata();
|
||||
Database database = metadata.getDatabase();
|
||||
generator.registerExportables( database );
|
||||
|
||||
generator.initialize( SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() ) );
|
||||
|
||||
sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory();
|
||||
sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE );
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if ( sessionFactory != null ) {
|
||||
sessionFactory.close();
|
||||
}
|
||||
if ( serviceRegistry != null ) {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHiLoAlgorithm() {
|
||||
TransactionUtil.doInHibernate(
|
||||
() -> sessionFactory,
|
||||
session -> {
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// historically the hilo generators skipped the initial block of values;
|
||||
// so the first generated id value is maxlo + 1, here be 4
|
||||
assertEquals( 4L, generateValue( session ) );
|
||||
// which should also perform the first read on the sequence which should set it to its "start with" value (1)
|
||||
assertEquals( 1L, extractSequenceValue( session ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 5L, generateValue( session ) );
|
||||
assertEquals( 1L, extractSequenceValue( session ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 6L, generateValue( session ) );
|
||||
assertEquals( 1L, extractSequenceValue( session ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 7L, generateValue( session ) );
|
||||
// unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation
|
||||
// after a clock over
|
||||
assertEquals( 1L, extractSequenceValue( session ) );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
assertEquals( 8L, generateValue( session ) );
|
||||
// this should force an increment in the sequence value
|
||||
assertEquals( 2L, extractSequenceValue( session ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private long extractSequenceValue(Session session) {
|
||||
return sequenceValueExtractor.extractSequenceValue( (SessionImplementor) session );
|
||||
}
|
||||
|
||||
private long generateValue(Session session) {
|
||||
return (Long) generator.generate( (SharedSessionContractImplementor) session, null );
|
||||
}
|
||||
}
|
@ -1,126 +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.id.sequence;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.model.relational.Namespace;
|
||||
import org.hibernate.boot.model.relational.Sequence;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.BaseUnitTest;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@BaseUnitTest
|
||||
public class LegacySequenceExportTest {
|
||||
private StandardServiceRegistry ssr;
|
||||
|
||||
@BeforeEach
|
||||
public void prepare() {
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false" )
|
||||
.build();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-9936")
|
||||
public void testMultipleUsesOfDefaultSequenceName() {
|
||||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
assertEquals( 0, metadata.getDatabase().getAuxiliaryDatabaseObjects().size() );
|
||||
|
||||
int count = 0;
|
||||
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
|
||||
for ( Sequence sequence : namespace.getSequences() ) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals( 1, count );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-9936")
|
||||
public void testMultipleUsesOfExplicitSequenceName() {
|
||||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity3.class )
|
||||
.addAnnotatedClass( Entity4.class )
|
||||
.buildMetadata();
|
||||
metadata.validate();
|
||||
|
||||
assertEquals( 0, metadata.getDatabase().getAuxiliaryDatabaseObjects().size() );
|
||||
|
||||
int count = 0;
|
||||
for ( Namespace namespace : metadata.getDatabase().getNamespaces() ) {
|
||||
for ( Sequence sequence : namespace.getSequences() ) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals( 1, count );
|
||||
}
|
||||
|
||||
@Entity(name = "Entity1")
|
||||
@Table(name = "Entity1")
|
||||
public static class Entity1 {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
public Integer id;
|
||||
}
|
||||
|
||||
@Entity(name = "Entity2")
|
||||
@Table(name = "Entity2")
|
||||
public static class Entity2 {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
public Integer id;
|
||||
}
|
||||
|
||||
@Entity(name = "Entity3")
|
||||
@Table(name = "Entity3")
|
||||
public static class Entity3 {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
@SequenceGenerator(name = "my_sequence")
|
||||
public Integer id;
|
||||
}
|
||||
|
||||
@Entity(name = "Entity4")
|
||||
@Table(name = "Entity4")
|
||||
public static class Entity4 {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
@SequenceGenerator(name = "my_sequence")
|
||||
public Integer id;
|
||||
}
|
||||
}
|
@ -17,13 +17,11 @@
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.DB2Dialect;
|
||||
import org.hibernate.id.MultipleHiLoPerTableGenerator;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@ -72,46 +70,4 @@ public void testNewGeneratorTableCreationOnDb2() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9850" )
|
||||
public void testLegacyGeneratorTableCreationOnDb2() {
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, DB2Dialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
Metadata metadata = new MetadataSources( ssr )
|
||||
.buildMetadata();
|
||||
|
||||
assertEquals( 0, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
||||
|
||||
MultipleHiLoPerTableGenerator generator = new MultipleHiLoPerTableGenerator();
|
||||
|
||||
Properties properties = new Properties();
|
||||
generator.configure(
|
||||
metadata.getDatabase()
|
||||
.getTypeConfiguration()
|
||||
.getBasicTypeRegistry()
|
||||
.resolve( StandardBasicTypes.INTEGER ),
|
||||
new Properties(),
|
||||
ssr
|
||||
);
|
||||
|
||||
generator.registerExportables( metadata.getDatabase() );
|
||||
|
||||
assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
||||
|
||||
Database database = metadata.getDatabase();
|
||||
final Table table = database.getDefaultNamespace().getTables().iterator().next();
|
||||
SqlStringGenerationContext sqlStringGenerationContext =
|
||||
SqlStringGenerationContextImpl.forTests( database.getJdbcEnvironment() );
|
||||
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata,
|
||||
sqlStringGenerationContext
|
||||
);
|
||||
assertThat( createCommands[0], containsString( "sequence_name varchar(255) not null" ) );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +189,6 @@ protected Map buildSettings() {
|
||||
if ( createSchema() ) {
|
||||
settings.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
settings.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
settings.put( AvailableSettings.DIALECT, getDialect().getClass().getName() );
|
||||
return settings;
|
||||
}
|
||||
|
@ -274,7 +274,6 @@ public void testOnLoadCallInInterceptor() {
|
||||
protected Map basicSettings() {
|
||||
return SettingsGenerator.generateSettings(
|
||||
AvailableSettings.HBM2DDL_AUTO, "create-drop",
|
||||
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true",
|
||||
AvailableSettings.DIALECT, DialectContext.getDialect().getClass().getName(),
|
||||
AvailableSettings.LOADED_CLASSES, Arrays.asList( getAnnotatedClasses() )
|
||||
);
|
||||
|
@ -53,12 +53,6 @@ protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {Person.class, Lockable.class, LocalEntity.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected void addConfigOptions(Map options) {
|
||||
options.put( org.hibernate.cfg.AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverallLockMode() {
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
|
@ -39,7 +39,6 @@
|
||||
UnidirectionalOneToManyIndexColumnTest.Child.class
|
||||
},
|
||||
integrationSettings = {
|
||||
@Setting(name = AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, value = "true"),
|
||||
@Setting(name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop"),
|
||||
@Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl")
|
||||
}
|
||||
|
@ -110,7 +110,6 @@ public void assertConnectionIsReleasedIfRollbackFails() {
|
||||
private Map basicSettings() {
|
||||
return SettingsGenerator.generateSettings(
|
||||
Environment.HBM2DDL_AUTO, "create-drop",
|
||||
Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true",
|
||||
Environment.DIALECT, DialectContext.getDialect().getClass().getName(),
|
||||
Environment.CONNECTION_PROVIDER, ProxyConnectionProvider.class.getName()
|
||||
);
|
||||
|
@ -6,26 +6,23 @@
|
||||
*/
|
||||
package org.hibernate.orm.test.nationalized;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Lob;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@ -39,9 +36,6 @@
|
||||
annotatedClasses = NationalizedLobFieldTest.MyEntity.class
|
||||
)
|
||||
@SessionFactory
|
||||
@ServiceRegistry(
|
||||
settings = @Setting(name = AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, value = "false")
|
||||
)
|
||||
public class NationalizedLobFieldTest {
|
||||
|
||||
@BeforeEach
|
||||
|
@ -42,7 +42,6 @@ public class JoinTableWithDefaultSchemaTest extends BaseUnitTestCase {
|
||||
public void testGetTableDataForJoinTableWithDefaultSchema() {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DEFAULT_CATALOG, "hibernate_orm_test" )
|
||||
.applySetting( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false" )
|
||||
.build();
|
||||
try {
|
||||
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||
|
@ -57,7 +57,7 @@ public void testPlaceholderReplacement() {
|
||||
|
||||
String str = ConfigurationHelper.getString( "my.nonexistent.prop", props, "did.not.exist" );
|
||||
assertEquals( "did.not.exist", str );
|
||||
str = ConfigurationHelper.getString( "my.nonexistent.prop", props, null );
|
||||
str = ConfigurationHelper.getString( "my.nonexistent.prop", props );
|
||||
assertNull( str );
|
||||
str = ConfigurationHelper.getString( "my.string.prop", props, "na" );
|
||||
assertEquals( "replacement did not occur", "string", str );
|
||||
|
@ -6,8 +6,6 @@
|
||||
*/
|
||||
package org.hibernate.test.boot.database.qualfiedTableNaming;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -17,21 +15,6 @@
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.TableGenerator;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
@ -58,7 +41,6 @@
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.persister.entity.AbstractEntityPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableStrategy;
|
||||
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableStrategy;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
@ -79,6 +61,24 @@
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import jakarta.persistence.Basic;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.TableGenerator;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(CustomParameterized.class)
|
||||
@TestForIssue(jiraKey = { "HHH-14921", "HHH-14922" })
|
||||
public class DefaultCatalogAndSchemaTest {
|
||||
@ -176,16 +176,12 @@ public void initSessionFactory() {
|
||||
EntityWithExplicitQualifiersWithTableGenerator.class,
|
||||
EntityWithDefaultQualifiersWithSequenceGenerator.class,
|
||||
EntityWithExplicitQualifiersWithSequenceGenerator.class,
|
||||
EntityWithDefaultQualifiersWithSeqHiLoGenerator.class,
|
||||
EntityWithExplicitQualifiersWithSeqHiLoGenerator.class,
|
||||
EntityWithDefaultQualifiersWithIncrementGenerator.class,
|
||||
EntityWithExplicitQualifiersWithIncrementGenerator.class,
|
||||
EntityWithDefaultQualifiersWithSequenceIdentityGenerator.class,
|
||||
EntityWithExplicitQualifiersWithSequenceIdentityGenerator.class,
|
||||
EntityWithDefaultQualifiersWithEnhancedSequenceGenerator.class,
|
||||
EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.class,
|
||||
EntityWithDefaultQualifiersWithLegacySequenceGenerator.class,
|
||||
EntityWithExplicitQualifiersWithLegacySequenceGenerator.class
|
||||
EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.class
|
||||
);
|
||||
|
||||
StandardServiceRegistry serviceRegistry;
|
||||
@ -341,16 +337,12 @@ public void entityPersister() {
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithTableGenerator.class, expectedExplicitQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithDefaultQualifiersWithSequenceGenerator.class, expectedDefaultQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithSequenceGenerator.class, expectedExplicitQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithDefaultQualifiersWithSeqHiLoGenerator.class, expectedDefaultQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithSeqHiLoGenerator.class, expectedExplicitQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithDefaultQualifiersWithIncrementGenerator.class, expectedDefaultQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithIncrementGenerator.class, expectedExplicitQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithDefaultQualifiersWithSequenceIdentityGenerator.class, expectedDefaultQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithSequenceIdentityGenerator.class, expectedExplicitQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithDefaultQualifiersWithEnhancedSequenceGenerator.class, expectedDefaultQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.class, expectedExplicitQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithDefaultQualifiersWithLegacySequenceGenerator.class, expectedDefaultQualifier() );
|
||||
verifyEntityPersisterQualifiers( EntityWithExplicitQualifiersWithLegacySequenceGenerator.class, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
private void verifyEntityPersisterQualifiers(Class<?> entityClass, ExpectedQualifier expectedQualifier) {
|
||||
@ -470,32 +462,6 @@ public void enhancedSequenceGenerator() {
|
||||
EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.NAME, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacySequenceGenerator() {
|
||||
org.hibernate.id.SequenceGenerator generator = idGenerator( org.hibernate.id.SequenceGenerator.class,
|
||||
EntityWithDefaultQualifiersWithLegacySequenceGenerator.class );
|
||||
verifyOnlyQualifier( generator.getAllSqlForTests(), SqlType.RUNTIME,
|
||||
EntityWithDefaultQualifiersWithLegacySequenceGenerator.NAME, expectedDefaultQualifier() );
|
||||
|
||||
generator = idGenerator( org.hibernate.id.SequenceGenerator.class,
|
||||
EntityWithExplicitQualifiersWithLegacySequenceGenerator.class );
|
||||
verifyOnlyQualifier( generator.getAllSqlForTests(), SqlType.RUNTIME,
|
||||
EntityWithExplicitQualifiersWithLegacySequenceGenerator.NAME, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seqHiLoGenerator() {
|
||||
org.hibernate.id.SequenceHiLoGenerator generator = idGenerator( org.hibernate.id.SequenceHiLoGenerator.class,
|
||||
EntityWithDefaultQualifiersWithSeqHiLoGenerator.class );
|
||||
verifyOnlyQualifier( generator.getAllSqlForTests(), SqlType.RUNTIME,
|
||||
EntityWithDefaultQualifiersWithSeqHiLoGenerator.NAME, expectedDefaultQualifier() );
|
||||
|
||||
generator = idGenerator( org.hibernate.id.SequenceHiLoGenerator.class,
|
||||
EntityWithExplicitQualifiersWithSeqHiLoGenerator.class );
|
||||
verifyOnlyQualifier( generator.getAllSqlForTests(), SqlType.RUNTIME,
|
||||
EntityWithExplicitQualifiersWithSeqHiLoGenerator.NAME, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incrementGenerator() {
|
||||
org.hibernate.id.IncrementGenerator generator = idGenerator( org.hibernate.id.IncrementGenerator.class,
|
||||
@ -509,19 +475,6 @@ public void incrementGenerator() {
|
||||
EntityWithExplicitQualifiersWithIncrementGenerator.NAME, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sequenceIdentityGenerator() {
|
||||
org.hibernate.id.SequenceIdentityGenerator generator = idGenerator( org.hibernate.id.SequenceIdentityGenerator.class,
|
||||
EntityWithDefaultQualifiersWithSequenceIdentityGenerator.class );
|
||||
verifyOnlyQualifier( generator.getAllSqlForTests(), SqlType.RUNTIME,
|
||||
EntityWithDefaultQualifiersWithSequenceIdentityGenerator.NAME, expectedDefaultQualifier() );
|
||||
|
||||
generator = idGenerator( org.hibernate.id.SequenceIdentityGenerator.class,
|
||||
EntityWithExplicitQualifiersWithSequenceIdentityGenerator.class );
|
||||
verifyOnlyQualifier( generator.getAllSqlForTests(), SqlType.RUNTIME,
|
||||
EntityWithExplicitQualifiersWithSequenceIdentityGenerator.NAME, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
private <T extends IdentifierGenerator> T idGenerator(Class<T> expectedType, Class<?> entityClass) {
|
||||
AbstractEntityPersister persister = (AbstractEntityPersister)
|
||||
sessionFactory.getMetamodel().entityPersister( entityClass );
|
||||
@ -558,16 +511,12 @@ private void verifyDDLQualifiers(String sql) {
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithTableGenerator.NAME, expectedExplicitQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithSequenceGenerator.NAME, expectedDefaultQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithSequenceGenerator.NAME, expectedExplicitQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithSeqHiLoGenerator.NAME, expectedDefaultQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithSeqHiLoGenerator.NAME, expectedExplicitQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithIncrementGenerator.NAME, expectedDefaultQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithIncrementGenerator.NAME, expectedExplicitQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithSequenceIdentityGenerator.NAME, expectedDefaultQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithSequenceIdentityGenerator.NAME, expectedExplicitQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithEnhancedSequenceGenerator.NAME, expectedDefaultQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithEnhancedSequenceGenerator.NAME, expectedExplicitQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithDefaultQualifiersWithLegacySequenceGenerator.NAME, expectedDefaultQualifier() );
|
||||
verifyOnlyQualifier( sql, SqlType.DDL, EntityWithExplicitQualifiersWithLegacySequenceGenerator.NAME, expectedExplicitQualifier() );
|
||||
}
|
||||
|
||||
private enum SqlType {
|
||||
@ -1079,36 +1028,6 @@ public static class EntityWithExplicitQualifiersWithTableGenerator {
|
||||
private String basic;
|
||||
}
|
||||
|
||||
@Entity(name = EntityWithDefaultQualifiersWithSeqHiLoGenerator.NAME)
|
||||
public static class EntityWithDefaultQualifiersWithSeqHiLoGenerator {
|
||||
public static final String NAME = "EntityWithDefaultQualifiersWithSeqHiLoGenerator";
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = NAME + "_generator")
|
||||
@GenericGenerator(name = NAME + "_generator", strategy = "org.hibernate.id.SequenceHiLoGenerator", parameters = {
|
||||
@Parameter(name = "sequence", value = NAME + "_seq"),
|
||||
@Parameter(name = "max_lo", value = "5")
|
||||
})
|
||||
private Long id;
|
||||
@Basic
|
||||
private String basic;
|
||||
}
|
||||
|
||||
@Entity(name = EntityWithExplicitQualifiersWithSeqHiLoGenerator.NAME)
|
||||
@Table(catalog = EXPLICIT_CATALOG, schema = EXPLICIT_SCHEMA)
|
||||
public static class EntityWithExplicitQualifiersWithSeqHiLoGenerator {
|
||||
public static final String NAME = "EntityWithExplicitQualifiersWithSeqHiLoGenerator";
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = NAME + "_generator")
|
||||
@GenericGenerator(name = NAME + "_generator", strategy = "org.hibernate.id.SequenceHiLoGenerator", parameters = {
|
||||
@Parameter(name = "sequence", value = NAME + "_seq"),
|
||||
@Parameter(name = "max_lo", value = "5"),
|
||||
@Parameter(name = "catalog", value = EXPLICIT_CATALOG),
|
||||
@Parameter(name = "schema", value = EXPLICIT_SCHEMA)
|
||||
})
|
||||
private Long id;
|
||||
@Basic
|
||||
private String basic;
|
||||
}
|
||||
|
||||
@Entity(name = EntityWithDefaultQualifiersWithIncrementGenerator.NAME)
|
||||
public static class EntityWithDefaultQualifiersWithIncrementGenerator {
|
||||
@ -1194,34 +1113,4 @@ public static class EntityWithExplicitQualifiersWithEnhancedSequenceGenerator {
|
||||
private String basic;
|
||||
}
|
||||
|
||||
|
||||
@Entity(name = EntityWithDefaultQualifiersWithLegacySequenceGenerator.NAME)
|
||||
public static class EntityWithDefaultQualifiersWithLegacySequenceGenerator {
|
||||
public static final String NAME = "EntityWithDefaultQualifiersWithLegacySequenceGenerator";
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = NAME + "_generator")
|
||||
@GenericGenerator(name = NAME + "_generator", strategy = "org.hibernate.id.SequenceGenerator", parameters = {
|
||||
@Parameter(name = "sequence", value = NAME + "_seq")
|
||||
})
|
||||
private Long id;
|
||||
@Basic
|
||||
private String basic;
|
||||
}
|
||||
|
||||
@Entity(name = EntityWithExplicitQualifiersWithLegacySequenceGenerator.NAME)
|
||||
@Table(catalog = EXPLICIT_CATALOG, schema = EXPLICIT_SCHEMA)
|
||||
public static class EntityWithExplicitQualifiersWithLegacySequenceGenerator {
|
||||
public static final String NAME = "EntityWithExplicitQualifiersWithLegacySequenceGenerator";
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = NAME + "_generator")
|
||||
@GenericGenerator(name = NAME + "_generator", strategy = "org.hibernate.id.SequenceGenerator", parameters = {
|
||||
@Parameter(name = "sequence", value = NAME + "_seq"),
|
||||
@Parameter(name = "catalog", value = EXPLICIT_CATALOG),
|
||||
@Parameter(name = "schema", value = EXPLICIT_SCHEMA)
|
||||
})
|
||||
private Long id;
|
||||
@Basic
|
||||
private String basic;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,9 +40,7 @@ public class SequenceExportTest extends BaseUnitTestCase {
|
||||
|
||||
@Before
|
||||
public void prepare() {
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" )
|
||||
.build();
|
||||
ssr = new StandardServiceRegistryBuilder().build();
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -48,7 +48,6 @@ public void init() throws URISyntaxException {
|
||||
if ( auditStrategy != null && !"".equals( auditStrategy ) ) {
|
||||
config.setProperty( EnversSettings.AUDIT_STRATEGY, auditStrategy );
|
||||
}
|
||||
config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
config.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
|
||||
// These tests always use H2, so we reset the init_sql config here
|
||||
config.setProperty( "hibernate.connection.init_sql", "" );
|
||||
|
@ -124,7 +124,6 @@ private Map buildSettings() {
|
||||
|
||||
settings.put( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
|
||||
|
||||
settings.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
settings.put( AvailableSettings.DIALECT, getDialect().getClass().getName() );
|
||||
return settings;
|
||||
}
|
||||
|
@ -85,7 +85,6 @@ protected void init(boolean audited, String auditStrategy) throws IOException {
|
||||
}
|
||||
if ( createSchema() ) {
|
||||
configurationProperties.setProperty( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
configurationProperties.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
configurationProperties.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
|
||||
}
|
||||
if ( auditStrategy != null && !"".equals( auditStrategy ) ) {
|
||||
|
@ -180,7 +180,6 @@ private void afterConstructAndConfigureConfiguration(Configuration cfg) {
|
||||
protected Configuration constructConfiguration(BootstrapServiceRegistry bootstrapServiceRegistry) {
|
||||
Configuration configuration = new Configuration( bootstrapServiceRegistry );
|
||||
configuration.setProperty( AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||
configuration.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
if ( createSchema() ) {
|
||||
configuration.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
final String secondSchemaName = createSecondSchema();
|
||||
|
@ -218,7 +218,6 @@ private void initialize(StandardServiceRegistryBuilder ssrb) {
|
||||
final Dialect dialect = BaseCoreFunctionalTestCase.getDialect();
|
||||
|
||||
ssrb.applySetting( AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
|
||||
ssrb.applySetting( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
if ( createSchema() ) {
|
||||
ssrb.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
final String secondSchemaName = createSecondSchema();
|
||||
@ -311,7 +310,6 @@ protected void afterMetadataSourcesApplied(MetadataSources metadataSources) {
|
||||
}
|
||||
|
||||
protected void initialize(MetadataBuilder metadataBuilder) {
|
||||
metadataBuilder.enableNewIdentifierGeneratorSupport( true );
|
||||
metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
|
||||
}
|
||||
|
||||
|
@ -112,8 +112,6 @@ protected Map<Object, Object> buildSettings() {
|
||||
settings.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
|
||||
}
|
||||
|
||||
settings.put( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user