minor jdoc refresh and deprecations to org.hibernate.id
This commit is contained in:
parent
d4cc873ad0
commit
663c6c2c71
|
@ -39,7 +39,7 @@ public @interface UuidGenerator {
|
|||
RANDOM,
|
||||
/**
|
||||
* Applies a time-based generation strategy consistent with IETF RFC 4122.
|
||||
* Uses IP address rather than mac address.
|
||||
* Uses IP address rather than MAC address.
|
||||
*
|
||||
* @implNote Can be a bottleneck due to the need to synchronize in order
|
||||
* to increment an internal count as part of the algorithm.
|
||||
|
|
|
@ -30,7 +30,7 @@ import jakarta.persistence.TableGenerator;
|
|||
public class IdGeneratorInterpreterImpl implements IdGeneratorStrategyInterpreter {
|
||||
private static final CoreMessageLogger log = CoreLogging.messageLogger( IdGeneratorInterpreterImpl.class );
|
||||
|
||||
private IdGeneratorStrategyInterpreter fallbackInterpreter = FallbackInterpreter.INSTANCE;
|
||||
private final IdGeneratorStrategyInterpreter fallbackInterpreter = FallbackInterpreter.INSTANCE;
|
||||
private ArrayList<IdGeneratorStrategyInterpreter> delegates;
|
||||
|
||||
@Override
|
||||
|
@ -88,16 +88,13 @@ public class IdGeneratorInterpreterImpl implements IdGeneratorStrategyInterprete
|
|||
@Override
|
||||
public String determineGeneratorName(GenerationType generationType, GeneratorNameDeterminationContext context) {
|
||||
switch ( generationType ) {
|
||||
case IDENTITY: {
|
||||
case IDENTITY:
|
||||
return "identity";
|
||||
}
|
||||
case SEQUENCE: {
|
||||
case SEQUENCE:
|
||||
return SequenceStyleGenerator.class.getName();
|
||||
}
|
||||
case TABLE: {
|
||||
case TABLE:
|
||||
return org.hibernate.id.enhanced.TableGenerator.class.getName();
|
||||
}
|
||||
case AUTO: {
|
||||
case AUTO:
|
||||
if ( "increment".equalsIgnoreCase( context.getGeneratedValueGeneratorName() ) ) {
|
||||
return IncrementGenerator.class.getName();
|
||||
}
|
||||
|
@ -108,14 +105,12 @@ public class IdGeneratorInterpreterImpl implements IdGeneratorStrategyInterprete
|
|||
}
|
||||
|
||||
return SequenceStyleGenerator.class.getName();
|
||||
}
|
||||
default: {
|
||||
default:
|
||||
// UNKNOWN
|
||||
if ( "UUID".equals( generationType.name() ) ) {
|
||||
return UUIDGenerator.class.getName();
|
||||
}
|
||||
throw new UnsupportedOperationException( "Unsupported generation type:" + generationType );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,10 @@ import org.hibernate.internal.util.BytesHelper;
|
|||
*
|
||||
* @see UUIDHexGenerator
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated since {@link UUIDHexGenerator} is deprecated
|
||||
*/
|
||||
@Deprecated(since = "6")
|
||||
public abstract class AbstractUUIDGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
|
||||
private static final int IP;
|
||||
|
|
|
@ -16,12 +16,12 @@ import org.hibernate.service.ServiceRegistry;
|
|||
import org.hibernate.type.Type;
|
||||
|
||||
/**
|
||||
* <b>assigned</b>
|
||||
* <p>
|
||||
* An {@code IdentifierGenerator} that returns the current identifier assigned
|
||||
* An {@link IdentifierGenerator} that returns the current identifier assigned
|
||||
* to an instance.
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @implNote This also implements the {@code assigned} generation type in {@code hbm.xml} mappings.
|
||||
*/
|
||||
public class Assigned implements IdentifierGenerator, StandardGenerator {
|
||||
private String entityName;
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Internal;
|
||||
import org.hibernate.boot.model.relational.Database;
|
||||
import org.hibernate.boot.model.relational.ExportableProducer;
|
||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||
|
@ -47,6 +48,7 @@ import org.hibernate.id.factory.spi.StandardGenerator;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Internal
|
||||
public class CompositeNestedGeneratedValueGenerator
|
||||
implements IdentifierGenerator, StandardGenerator, IdentifierGeneratorAggregator, Serializable {
|
||||
/**
|
||||
|
|
|
@ -24,18 +24,26 @@ import static org.hibernate.internal.CoreLogging.messageLogger;
|
|||
import static org.hibernate.spi.NavigablePath.IDENTIFIER_MAPPER_PROPERTY;
|
||||
|
||||
/**
|
||||
* <b>foreign</b>
|
||||
* The legacy id generator named {@code foreign}.
|
||||
* <p>
|
||||
* An {@code Identifier} generator that uses the value of the id property of an
|
||||
* associated object
|
||||
* associated object.
|
||||
* <p>
|
||||
* One mapping parameter is required: property.
|
||||
* One mapping parameter is required: {@value PROPERTY}.
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated This remains around as an implementation detail of {@code hbm.xml} mappings.
|
||||
*/
|
||||
@Deprecated(since = "6")
|
||||
public class ForeignGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
private static final CoreMessageLogger LOG = messageLogger( ForeignGenerator.class );
|
||||
|
||||
/**
|
||||
* The parameter which specifies the property holding a reference to the associated object.
|
||||
*/
|
||||
public static final String PROPERTY = "property";
|
||||
|
||||
private String entityName;
|
||||
private String propertyName;
|
||||
|
||||
|
@ -70,7 +78,7 @@ public class ForeignGenerator implements IdentifierGenerator, StandardGenerator
|
|||
|
||||
@Override
|
||||
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
propertyName = parameters.getProperty( "property" );
|
||||
propertyName = parameters.getProperty( PROPERTY );
|
||||
entityName = parameters.getProperty( ENTITY_NAME );
|
||||
if ( propertyName==null ) {
|
||||
throw new MappingException( "param named \"property\" is required for foreign id generation strategy" );
|
||||
|
|
|
@ -17,7 +17,9 @@ import org.hibernate.internal.CoreLogging;
|
|||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
||||
/**
|
||||
* Generates {@code string} values using the SQL Server NEWID() function.
|
||||
* The legacy id generator named {@code guid}.
|
||||
* <p>
|
||||
* Generates {@code string} values using the SQL Server {@code NEWID()} function.
|
||||
*
|
||||
* @author Joseph Fifield
|
||||
*
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.id;
|
|||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Thrown by {@code IdentifierGenerator} implementation class when
|
||||
* Thrown by an {@link IdentifierGenerator} implementation class when
|
||||
* ID generation fails.
|
||||
*
|
||||
* @see IdentifierGenerator
|
||||
|
|
|
@ -53,7 +53,7 @@ import static org.hibernate.generator.EventTypeSets.INSERT_ONLY;
|
|||
* <p>
|
||||
* Instances of {@code IdentifierGenerator} are usually created and configured
|
||||
* by the {@link org.hibernate.id.factory.IdentifierGeneratorFactory} service.
|
||||
* It is not usually correct to use an {@code IdentifierGenerator} with the
|
||||
* It's not usually correct to use an {@code IdentifierGenerator} with the
|
||||
* {@link org.hibernate.annotations.IdGeneratorType} meta-annotation.
|
||||
*
|
||||
* @author Gavin King
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.hibernate.boot.model.relational.ExportableProducer;
|
|||
* Identifies {@linkplain IdentifierGenerator generators} which potentially aggregate other
|
||||
* {@link PersistentIdentifierGenerator} generators.
|
||||
* <p>
|
||||
* Initially this is limited to {@link CompositeNestedGeneratedValueGenerator}
|
||||
* Initially this is limited to {@link CompositeNestedGeneratedValueGenerator}.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
|
|
@ -14,11 +14,11 @@ import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
|
|||
import org.hibernate.id.insert.InsertReturningDelegate;
|
||||
|
||||
/**
|
||||
* An {@link OnExecutionGenerator} that handles {@code IDENTITY}/"autoincrement" columns
|
||||
* on those databases which support them.
|
||||
* An {@link OnExecutionGenerator} that handles {@code IDENTITY}/"autoincrement"
|
||||
* columns on those databases which support them.
|
||||
* <p>
|
||||
* Delegates to the {@link org.hibernate.dialect.identity.IdentityColumnSupport} provided
|
||||
* by the {@linkplain Dialect#getIdentityColumnSupport() dialect}.
|
||||
* Delegates to the {@link org.hibernate.dialect.identity.IdentityColumnSupport}
|
||||
* provided by the {@linkplain Dialect#getIdentityColumnSupport() dialect}.
|
||||
* <p>
|
||||
* The actual work involved in retrieving the primary key value is the job of a
|
||||
* {@link org.hibernate.id.insert.InsertGeneratedIdentifierDelegate}, either:
|
||||
|
@ -28,10 +28,13 @@ import org.hibernate.id.insert.InsertReturningDelegate;
|
|||
* <li>a {@link org.hibernate.id.insert.BasicSelectingDelegate}.
|
||||
* </ul>
|
||||
*
|
||||
* @see jakarta.persistence.GenerationType#IDENTITY
|
||||
* @see org.hibernate.dialect.identity.IdentityColumnSupport
|
||||
* @see org.hibernate.id.insert.InsertGeneratedIdentifierDelegate
|
||||
*
|
||||
* @author Christoph Sturm
|
||||
*
|
||||
* @implNote This also implements the {@code identity} generation type in {@code hbm.xml} mappings.
|
||||
*/
|
||||
public class IdentityGenerator
|
||||
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator {
|
||||
|
@ -48,7 +51,7 @@ public class IdentityGenerator
|
|||
|
||||
@Override
|
||||
public InsertGeneratedIdentifierDelegate getGeneratedIdentifierDelegate(PostInsertIdentityPersister persister) {
|
||||
Dialect dialect = persister.getFactory().getJdbcServices().getDialect();
|
||||
final Dialect dialect = persister.getFactory().getJdbcServices().getDialect();
|
||||
if ( persister.getFactory().getSessionFactoryOptions().isGetGeneratedKeysEnabled() ) {
|
||||
return dialect.getIdentityColumnSupport().buildGetGeneratedKeysDelegate( persister, dialect );
|
||||
}
|
||||
|
|
|
@ -24,27 +24,43 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
|||
import org.hibernate.id.factory.spi.StandardGenerator;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHolder;
|
||||
import static org.hibernate.id.PersistentIdentifierGenerator.CATALOG;
|
||||
import static org.hibernate.id.PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER;
|
||||
import static org.hibernate.id.PersistentIdentifierGenerator.PK;
|
||||
import static org.hibernate.id.PersistentIdentifierGenerator.SCHEMA;
|
||||
import static org.hibernate.internal.util.StringHelper.split;
|
||||
|
||||
/**
|
||||
* <b>increment</b>
|
||||
* An {@link IdentifierGenerator} that returns a {@code long}, constructed by counting
|
||||
* from the maximum primary key value obtained by querying the table or tables at startup.
|
||||
* <p>
|
||||
* An {@code IdentifierGenerator} that returns a {@code long}, constructed by
|
||||
* counting from the maximum primary key value at startup. Not safe for use in a
|
||||
* cluster!
|
||||
* This id generator is not safe unless a single VM has exclusive access to the database.
|
||||
* <p>
|
||||
* Mapping parameters supported, but not usually needed: tables, column.
|
||||
* (The tables parameter specified a comma-separated list of table names.)
|
||||
* Mapping parameters supported, but not usually needed: {@value #TABLES}, {@value #COLUMN}.
|
||||
* (The {@value #TABLES} parameter specifies a comma-separated list of table names.)
|
||||
*
|
||||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
* @author Brett Meyer
|
||||
*
|
||||
* @implNote This also implements the {@code increment} generation type in {@code hbm.xml} mappings.
|
||||
*/
|
||||
public class IncrementGenerator implements IdentifierGenerator, StandardGenerator {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( IncrementGenerator.class );
|
||||
|
||||
/**
|
||||
* A parameter identifying the column holding the id.
|
||||
*/
|
||||
public static final String COLUMN = "column";
|
||||
/**
|
||||
* A parameter specifying a list of tables over which the generated id should be unique.
|
||||
*/
|
||||
public static final String TABLES = "tables";
|
||||
|
||||
private Class<?> returnClass;
|
||||
private String column;
|
||||
private List<QualifiedTableName> physicalTableNames;
|
||||
|
@ -74,29 +90,29 @@ public class IncrementGenerator implements IdentifierGenerator, StandardGenerato
|
|||
|
||||
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
|
||||
final ObjectNameNormalizer normalizer =
|
||||
(ObjectNameNormalizer) parameters.get( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER );
|
||||
(ObjectNameNormalizer) parameters.get( IDENTIFIER_NORMALIZER );
|
||||
|
||||
column = parameters.getProperty( "column" );
|
||||
column = parameters.getProperty( COLUMN );
|
||||
if ( column == null ) {
|
||||
column = parameters.getProperty( PersistentIdentifierGenerator.PK );
|
||||
column = parameters.getProperty( PK );
|
||||
}
|
||||
column = normalizer.normalizeIdentifierQuoting( column ).render( jdbcEnvironment.getDialect() );
|
||||
|
||||
IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
|
||||
|
||||
final String schema = normalizer.toDatabaseIdentifierText(
|
||||
parameters.getProperty( PersistentIdentifierGenerator.SCHEMA )
|
||||
parameters.getProperty( SCHEMA )
|
||||
);
|
||||
final String catalog = normalizer.toDatabaseIdentifierText(
|
||||
parameters.getProperty( PersistentIdentifierGenerator.CATALOG )
|
||||
parameters.getProperty( CATALOG )
|
||||
);
|
||||
|
||||
String tableList = parameters.getProperty( "tables" );
|
||||
String tableList = parameters.getProperty( TABLES );
|
||||
if ( tableList == null ) {
|
||||
tableList = parameters.getProperty( PersistentIdentifierGenerator.TABLES );
|
||||
}
|
||||
physicalTableNames = new ArrayList<>();
|
||||
for ( String tableName : StringHelper.split( ", ", tableList ) ) {
|
||||
for ( String tableName : split( ", ", tableList ) ) {
|
||||
physicalTableNames.add( new QualifiedTableName( identifierHelper.toIdentifier( catalog ),
|
||||
identifierHelper.toIdentifier( schema ), identifierHelper.toIdentifier( tableName ) ) );
|
||||
}
|
||||
|
@ -128,7 +144,7 @@ public class IncrementGenerator implements IdentifierGenerator, StandardGenerato
|
|||
}
|
||||
|
||||
private void initializePreviousValueHolder(SharedSessionContractImplementor session) {
|
||||
previousValueHolder = IdentifierGeneratorHelper.getIntegralDataTypeHolder( returnClass );
|
||||
previousValueHolder = getIntegralDataTypeHolder( returnClass );
|
||||
|
||||
if ( LOG.isDebugEnabled() ) {
|
||||
LOG.debugf( "Fetching initial value: %s", sql );
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Defines a common api for dealing with data of integral data type.
|
||||
* Defines a common API for dealing with data of integral data type.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -39,7 +39,7 @@ public interface IntegralDataTypeHolder extends Serializable {
|
|||
IntegralDataTypeHolder initialize(ResultSet resultSet, long defaultValue) throws SQLException;
|
||||
|
||||
/**
|
||||
* Bind this holders internal value to the given result set.
|
||||
* Bind this holder's internal value to the given result set.
|
||||
*
|
||||
* @param preparedStatement The JDBC prepared statement
|
||||
* @param position The position at which to bind
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.sql.ResultSet;
|
|||
*
|
||||
* @deprecated this interface is unnecessary and no longer used
|
||||
*/
|
||||
@Deprecated(since = "6.2")
|
||||
@Deprecated(since = "6.2", forRemoval = true)
|
||||
public interface ResultSetIdentifierConsumer {
|
||||
/**
|
||||
* Given a result set, consume/extract the necessary values and construct an
|
||||
|
|
|
@ -23,7 +23,7 @@ import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPrope
|
|||
* key of the entity, either:
|
||||
* <ul>
|
||||
* <li>the mapped {@linkplain org.hibernate.annotations.NaturalId} of the entity, or
|
||||
* <li>a property specified using the parameter named {@code "key"}.
|
||||
* <li>a property specified using the parameter named {@value #KEY}.
|
||||
* </ul>
|
||||
* <p>
|
||||
* The second approach is provided for backward compatibility with older versions of
|
||||
|
@ -74,14 +74,22 @@ import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPrope
|
|||
* @see org.hibernate.id.insert.UniqueKeySelectingDelegate
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @implNote This also implements the {@code select} generation type in {@code hbm.xml} mappings.
|
||||
*/
|
||||
public class SelectGenerator
|
||||
implements PostInsertIdentifierGenerator, BulkInsertionCapableIdentifierGenerator, StandardGenerator {
|
||||
|
||||
/**
|
||||
* The property specifying the unique key name.
|
||||
*/
|
||||
public static final String KEY = "key";
|
||||
|
||||
private String uniqueKeyPropertyName;
|
||||
|
||||
@Override
|
||||
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) {
|
||||
uniqueKeyPropertyName = parameters.getProperty( "key" );
|
||||
uniqueKeyPropertyName = parameters.getProperty( KEY );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,25 +12,34 @@ import org.hibernate.MappingException;
|
|||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
||||
|
||||
/**
|
||||
* <b>uuid</b>
|
||||
* The legacy id generator named {@code uuid} / {@code uuid.hex}.
|
||||
* <p>
|
||||
* A {@code UUIDGenerator} that returns a string of length 32,
|
||||
* A {@link UUIDGenerator} that returns a string of length 32,
|
||||
* This string will consist of only hex digits. Optionally,
|
||||
* the string may be generated with separators between each
|
||||
* component of the UUID.
|
||||
* <p>
|
||||
* Mapping parameters supported: separator.
|
||||
* Mapping parameter supported: {@value #SEPARATOR}.
|
||||
*
|
||||
* @author Gavin King
|
||||
*
|
||||
* @deprecated This remains around as an implementation detail of {@code hbm.xml} mappings.
|
||||
*/
|
||||
@Deprecated(since = "6")
|
||||
public class UUIDHexGenerator extends AbstractUUIDGenerator {
|
||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( UUIDHexGenerator.class );
|
||||
|
||||
/**
|
||||
* The configuration parameter specifying the separator to use.
|
||||
*/
|
||||
public static final String SEPARATOR = "separator";
|
||||
|
||||
private static boolean WARNED;
|
||||
|
||||
private String sep = "";
|
||||
|
@ -45,7 +54,7 @@ public class UUIDHexGenerator extends AbstractUUIDGenerator {
|
|||
|
||||
@Override
|
||||
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException {
|
||||
sep = ConfigurationHelper.getString( "separator", parameters, "" );
|
||||
sep = getString( SEPARATOR, parameters, "" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,12 +9,12 @@ package org.hibernate.id.enhanced;
|
|||
import org.hibernate.HibernateException;
|
||||
|
||||
/**
|
||||
* Common support for optimizer implementations.
|
||||
* Common support for {@link Optimizer} implementations.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractOptimizer implements Optimizer {
|
||||
protected final Class returnClass;
|
||||
protected final Class<?> returnClass;
|
||||
protected final int incrementSize;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ public abstract class AbstractOptimizer implements Optimizer {
|
|||
* @param returnClass The expected id class.
|
||||
* @param incrementSize The increment size
|
||||
*/
|
||||
AbstractOptimizer(Class returnClass, int incrementSize) {
|
||||
AbstractOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
if ( returnClass == null ) {
|
||||
throw new HibernateException( "return class is required" );
|
||||
}
|
||||
|
@ -37,8 +37,7 @@ public abstract class AbstractOptimizer implements Optimizer {
|
|||
*
|
||||
* @return Value for property 'returnClass'.
|
||||
*/
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
public final Class getReturnClass() {
|
||||
public final Class<?> getReturnClass() {
|
||||
return returnClass;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,26 +20,29 @@ import org.jboss.logging.Logger;
|
|||
* optimization.
|
||||
* <p>
|
||||
* A 'hilo' algorithm is simply a means for a single value stored in the
|
||||
* database to represent a "bucket" of possible, contiguous values. The
|
||||
* database to represent a "bucket" of possible, contiguous values. The
|
||||
* database value identifies which particular bucket we are on.
|
||||
* <p>
|
||||
* This database value must be paired with another value that defines the
|
||||
* size of the bucket; the number of possible values available.
|
||||
* The {@link #getIncrementSize() incrementSize} serves this purpose. The
|
||||
* The {@link #getIncrementSize() incrementSize} serves this purpose. The
|
||||
* naming here is meant more for consistency in that this value serves the
|
||||
* same purpose as the increment supplied to the {@link PooledOptimizer}.
|
||||
* <p>
|
||||
* The general algorithms used to determine the bucket are:<ol>
|
||||
* The general algorithms used to determine the bucket is:
|
||||
* <ol>
|
||||
* <li>{@code upperLimit = (databaseValue * incrementSize) + 1}</li>
|
||||
* <li>{@code lowerLimit = upperLimit - incrementSize}</li>
|
||||
* </ol>
|
||||
* As an example, consider a case with incrementSize of 20. Initially the
|
||||
* <p>
|
||||
* As an example, consider a case with incrementSize of 20. Initially, the
|
||||
* database holds 1:<ol>
|
||||
* <li>{@code upperLimit = (1 * 20) + 1 = 21}</li>
|
||||
* <li>{@code lowerLimit = 21 - 20 = 1}</li>
|
||||
* </ol>
|
||||
* <p>
|
||||
* From there we increment the value from lowerLimit until we reach the
|
||||
* upperLimit, at which point we would define a new bucket. The database
|
||||
* upperLimit, at which point we would define a new bucket. The database
|
||||
* now contains 2, though incrementSize remains unchanged:<ol>
|
||||
* <li>{@code upperLimit = (2 * 20) + 1 = 41}</li>
|
||||
* <li>{@code lowerLimit = 41 - 20 = 21}</li>
|
||||
|
@ -61,12 +64,12 @@ public class HiLoOptimizer extends AbstractOptimizer {
|
|||
|
||||
|
||||
/**
|
||||
* Constructs a HiLoOptimizer
|
||||
* Constructs a {@code HiLoOptimizer}
|
||||
*
|
||||
* @param returnClass The Java type of the values to be generated
|
||||
* @param incrementSize The increment size.
|
||||
*/
|
||||
public HiLoOptimizer(Class returnClass, int incrementSize) {
|
||||
public HiLoOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
super( returnClass, incrementSize );
|
||||
if ( incrementSize < 1 ) {
|
||||
throw new HibernateException( "increment size cannot be less than 1" );
|
||||
|
|
|
@ -20,8 +20,9 @@ public interface InitialValueAwareOptimizer {
|
|||
* <p>
|
||||
* {@code -1} is used to indicate that the user did not specify.
|
||||
*
|
||||
* @param initialValue The initial value specified by the user, or {@code -1} to indicate that the
|
||||
* user did not specify.
|
||||
* @param initialValue The initial value specified by the user,
|
||||
* or {@code -1} to indicate that the user
|
||||
* did not specify an initial value.
|
||||
*/
|
||||
void injectInitialValue(long initialValue);
|
||||
}
|
||||
|
|
|
@ -36,12 +36,12 @@ public class LegacyHiLoAlgorithmOptimizer extends AbstractOptimizer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a LegacyHiLoAlgorithmOptimizer
|
||||
* Constructs a {@code LegacyHiLoAlgorithmOptimizer}
|
||||
*
|
||||
* @param returnClass The Java type of the values to be generated
|
||||
* @param incrementSize The increment size.
|
||||
*/
|
||||
public LegacyHiLoAlgorithmOptimizer(Class returnClass, int incrementSize) {
|
||||
public LegacyHiLoAlgorithmOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
super( returnClass, incrementSize );
|
||||
if ( incrementSize < 1 ) {
|
||||
throw new HibernateException( "increment size cannot be less than 1" );
|
||||
|
@ -124,7 +124,6 @@ public class LegacyHiLoAlgorithmOptimizer extends AbstractOptimizer {
|
|||
*
|
||||
* @return Value for property 'lastValue'.
|
||||
*/
|
||||
@SuppressWarnings( {"UnusedDeclaration"})
|
||||
public synchronized IntegralDataTypeHolder getLastValue() {
|
||||
return noTenantGenerationState().value;
|
||||
}
|
||||
|
|
|
@ -15,43 +15,45 @@ import org.hibernate.boot.model.relational.QualifiedName;
|
|||
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
||||
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import static org.hibernate.boot.model.naming.Identifier.isQuoted;
|
||||
import static org.hibernate.boot.model.naming.Identifier.unQuote;
|
||||
import static org.hibernate.id.IdentifierGenerator.GENERATOR_NAME;
|
||||
import static org.hibernate.id.OptimizableGenerator.IMPLICIT_NAME_BASE;
|
||||
import static org.hibernate.id.PersistentIdentifierGenerator.TABLE;
|
||||
import static org.hibernate.id.enhanced.SequenceStyleGenerator.CONFIG_SEQUENCE_PER_ENTITY_SUFFIX;
|
||||
import static org.hibernate.id.enhanced.TableGenerator.DEF_TABLE;
|
||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
||||
|
||||
/**
|
||||
* Naming strategy which implements the behavior of older versions of
|
||||
* Hibernate, for the most part.
|
||||
*
|
||||
* <p>
|
||||
* For sequences (including forced-table sequences):<ol>
|
||||
* <li>
|
||||
* If {@value SequenceStyleGenerator#CONFIG_SEQUENCE_PER_ENTITY_SUFFIX} is specified,
|
||||
* a name composed of the "base" name with the specified suffix. The base name
|
||||
* depends on the usage of the generator, but is generally the root entity-name if
|
||||
* applied to an entity identifier or the table we are generating values for
|
||||
* applied to an entity identifier or the table we are generating values for.
|
||||
* </li>
|
||||
* <li>
|
||||
* If annotations are used and {@link GeneratedValue#generator()} is specified,
|
||||
* its value is used as the sequence name
|
||||
* its value is used as the sequence name.
|
||||
* </li>
|
||||
* <li>
|
||||
* Fall back is to use {@value DEF_SEQUENCE}
|
||||
* Fall back is to use {@value DEF_SEQUENCE}.
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
* For tables:<ol>
|
||||
* <li>
|
||||
* If annotations are used and {@link GeneratedValue#generator()} is specified,
|
||||
* its value is used as the table name
|
||||
* its value is used as the table name.
|
||||
* </li>
|
||||
* <li>
|
||||
* Fall back is to use {@value TableGenerator#DEF_TABLE}
|
||||
* Fall back is to use {@value TableGenerator#DEF_TABLE}.
|
||||
* </li>
|
||||
* </ol>
|
||||
*/
|
||||
|
@ -69,35 +71,31 @@ public class LegacyNamingStrategy implements ImplicitDatabaseObjectNamingStrateg
|
|||
return QualifiedNameParser.INSTANCE.parse( sequenceName );
|
||||
}
|
||||
|
||||
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
|
||||
return new QualifiedSequenceName(
|
||||
catalogName,
|
||||
schemaName,
|
||||
jdbcEnvironment.getIdentifierHelper().toIdentifier( sequenceName )
|
||||
serviceRegistry.getService( JdbcEnvironment.class )
|
||||
.getIdentifierHelper()
|
||||
.toIdentifier( sequenceName )
|
||||
);
|
||||
}
|
||||
|
||||
private String implicitSequenceName(Map<?, ?> configValues) {
|
||||
final String explicitSuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, configValues );
|
||||
final String explicitSuffix = getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, configValues );
|
||||
|
||||
if ( StringHelper.isNotEmpty( explicitSuffix ) ) {
|
||||
if ( isNotEmpty( explicitSuffix ) ) {
|
||||
// an "implicit name suffix" was specified
|
||||
final String rootTableName = ConfigurationHelper.getString( PersistentIdentifierGenerator.TABLE, configValues );
|
||||
final String base = ConfigurationHelper.getString( IMPLICIT_NAME_BASE, configValues, rootTableName );
|
||||
if ( StringHelper.isNotEmpty( base ) ) {
|
||||
if ( Identifier.isQuoted( base ) ) {
|
||||
return "`" + Identifier.unQuote( base ) + explicitSuffix + "`";
|
||||
}
|
||||
return base + explicitSuffix;
|
||||
final String rootTableName = getString( TABLE, configValues );
|
||||
final String base = getString( IMPLICIT_NAME_BASE, configValues, rootTableName );
|
||||
if ( isNotEmpty( base ) ) {
|
||||
return isQuoted( base )
|
||||
? "`" + unQuote( base ) + explicitSuffix + "`"
|
||||
: base + explicitSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
final String annotationGeneratorName = ConfigurationHelper.getString( IdentifierGenerator.GENERATOR_NAME, configValues );
|
||||
if ( StringHelper.isNotEmpty( annotationGeneratorName ) ) {
|
||||
return annotationGeneratorName;
|
||||
}
|
||||
|
||||
return DEF_SEQUENCE;
|
||||
final String annotationGeneratorName = getString( GENERATOR_NAME, configValues );
|
||||
return isNotEmpty( annotationGeneratorName ) ? annotationGeneratorName : DEF_SEQUENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,11 +119,7 @@ public class LegacyNamingStrategy implements ImplicitDatabaseObjectNamingStrateg
|
|||
}
|
||||
|
||||
private String implicitTableName(Map<?, ?> configValues) {
|
||||
final String annotationName = ConfigurationHelper.getString( IdentifierGenerator.GENERATOR_NAME, configValues );
|
||||
if ( StringHelper.isNotEmpty( annotationName ) ) {
|
||||
return annotationName;
|
||||
}
|
||||
|
||||
return DEF_TABLE;
|
||||
final String annotationName = getString( GENERATOR_NAME, configValues );
|
||||
return isNotEmpty( annotationName ) ? annotationName : DEF_TABLE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,10 +11,10 @@ import java.io.Serializable;
|
|||
import org.hibernate.id.IntegralDataTypeHolder;
|
||||
|
||||
/**
|
||||
* An optimizer that performs no optimization. The database is hit for
|
||||
* every request.
|
||||
*
|
||||
* Using this implementation is probably not the most efficient choice.
|
||||
* An optimizer that performs no optimization. A round-trip to
|
||||
* the database is required for each new id.
|
||||
* <p>
|
||||
* This implementation is not the most efficient one.
|
||||
*/
|
||||
public final class NoopOptimizer extends AbstractOptimizer {
|
||||
private IntegralDataTypeHolder lastSourceValue;
|
||||
|
@ -25,7 +25,7 @@ public final class NoopOptimizer extends AbstractOptimizer {
|
|||
* @param returnClass The Java type of the values to be generated
|
||||
* @param incrementSize The increment size.
|
||||
*/
|
||||
public NoopOptimizer(Class returnClass, int incrementSize) {
|
||||
public NoopOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
super( returnClass, incrementSize );
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Variation of {@link PooledOptimizer} which interprets the incoming database value as the lo value, rather than
|
||||
* the hi value.
|
||||
* Variation of {@link PooledOptimizer} which interprets the incoming database
|
||||
* value as the lo value, rather than the hi value.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
|
@ -39,12 +39,12 @@ public class PooledLoOptimizer extends AbstractOptimizer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a PooledLoOptimizer.
|
||||
* Constructs a {@code PooledLoOptimizer}.
|
||||
*
|
||||
* @param returnClass The Java type of the values to be generated
|
||||
* @param incrementSize The increment size.
|
||||
*/
|
||||
public PooledLoOptimizer(Class returnClass, int incrementSize) {
|
||||
public PooledLoOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
super( returnClass, incrementSize );
|
||||
if ( incrementSize < 1 ) {
|
||||
throw new HibernateException( "increment size cannot be less than 1" );
|
||||
|
|
|
@ -17,8 +17,9 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Variation of {@link PooledOptimizer} which interprets the incoming database value as the lo value, rather than
|
||||
* the hi value, as well as using thread local to cache the generation state.
|
||||
* Variation of {@link PooledOptimizer} which interprets the incoming database
|
||||
* value as the lo value, rather than the hi value, as well as using thread local
|
||||
* to cache the generation state.
|
||||
*
|
||||
* @author Stuart Douglas
|
||||
* @author Scott Marlow
|
||||
|
@ -35,12 +36,12 @@ public class PooledLoThreadLocalOptimizer extends AbstractOptimizer {
|
|||
private final ThreadLocal<Map<String, GenerationState>> multiTenantStates = ThreadLocal.withInitial( HashMap::new );
|
||||
|
||||
/**
|
||||
* Constructs a PooledLoThreadLocalOptimizer.
|
||||
* Constructs a {@code PooledLoThreadLocalOptimizer}.
|
||||
*
|
||||
* @param returnClass The Java type of the values to be generated
|
||||
* @param incrementSize The increment size.
|
||||
*/
|
||||
public PooledLoThreadLocalOptimizer(Class returnClass, int incrementSize) {
|
||||
public PooledLoThreadLocalOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
super( returnClass, incrementSize );
|
||||
if ( incrementSize < 1 ) {
|
||||
throw new HibernateException( "increment size cannot be less than 1" );
|
||||
|
|
|
@ -17,15 +17,14 @@ import org.hibernate.internal.CoreMessageLogger;
|
|||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Optimizer which uses a pool of values, storing the next low value of the
|
||||
* range in the database.
|
||||
* Optimizer which uses a pool of values, storing the next low value of the range
|
||||
* in the database.
|
||||
* <p>
|
||||
* Note that this optimizer works essentially the same as the
|
||||
* {@link HiLoOptimizer} except that here the bucket ranges are actually
|
||||
* encoded into the database structures.
|
||||
* This optimizer works essentially the same as the {@link HiLoOptimizer}, except
|
||||
* that here the bucket ranges are actually encoded into the database structures.
|
||||
* <p>
|
||||
* Note if you prefer that the database value be interpreted as the bottom end of our current range,
|
||||
* then use the {@link PooledLoOptimizer} strategy
|
||||
* If you prefer that the database value be interpreted as the bottom end of our
|
||||
* current range, then use the {@link PooledLoOptimizer} strategy.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*
|
||||
|
@ -45,12 +44,12 @@ public class PooledOptimizer extends AbstractOptimizer implements InitialValueAw
|
|||
private long initialValue = -1;
|
||||
|
||||
/**
|
||||
* Constructs a PooledOptimizer
|
||||
* Constructs a {@code PooledOptimizer}
|
||||
*
|
||||
* @param returnClass The Java type of the values to be generated
|
||||
* @param incrementSize The increment size.
|
||||
*/
|
||||
public PooledOptimizer(Class returnClass, int incrementSize) {
|
||||
public PooledOptimizer(Class<?> returnClass, int incrementSize) {
|
||||
super( returnClass, incrementSize );
|
||||
if ( incrementSize < 1 ) {
|
||||
throw new HibernateException( "increment size cannot be less than 1" );
|
||||
|
|
|
@ -48,33 +48,37 @@ import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
|
|||
* <table>
|
||||
* <caption>General configuration parameters</caption>
|
||||
* <tr>
|
||||
* <td><b>NAME</b></td>
|
||||
* <td><b>DEFAULT</b></td>
|
||||
* <td><b>DESCRIPTION</b></td>
|
||||
* <td><b>Parameter name</b></td>
|
||||
* <td><b>Default value</b></td>
|
||||
* <td><b>Interpretation</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #SEQUENCE_PARAM}</td>
|
||||
* <td>N/A</td>
|
||||
* <td>{@value #SEQUENCE_PARAM}</td>
|
||||
* <td></td>
|
||||
* <td>The name of the sequence/table to use to store/retrieve values</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #INITIAL_PARAM}</td>
|
||||
* <td>{@link #DEFAULT_INITIAL_VALUE}</td>
|
||||
* <td>The initial value to be stored for the given segment; the effect in terms of storage varies based on {@link Optimizer} and {@link DatabaseStructure}</td>
|
||||
* <td>{@value #INITIAL_PARAM}</td>
|
||||
* <td>{@value #DEFAULT_INITIAL_VALUE}</td>
|
||||
* <td>The initial value to be stored for the given segment;
|
||||
* the effect in terms of storage varies based on {@link Optimizer}
|
||||
* and {@link DatabaseStructure}</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #INCREMENT_PARAM}</td>
|
||||
* <td>{@link #DEFAULT_INCREMENT_SIZE}</td>
|
||||
* <td>The increment size for the underlying segment; the effect in terms of storage varies based on {@link Optimizer} and {@link DatabaseStructure}</td>
|
||||
* <td>{@value #INCREMENT_PARAM}</td>
|
||||
* <td>{@value #DEFAULT_INCREMENT_SIZE}</td>
|
||||
* <td>The increment size for the underlying segment;
|
||||
* the effect in terms of storage varies based on {@link Optimizer}
|
||||
* and {@link DatabaseStructure}</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #OPT_PARAM}</td>
|
||||
* <td><i>depends on defined increment size</i></td>
|
||||
* <td>{@value #OPT_PARAM}</td>
|
||||
* <td><em>depends on defined increment size</em></td>
|
||||
* <td>Allows explicit definition of which optimization strategy to use</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #FORCE_TBL_PARAM}</td>
|
||||
* <td><b><i>false</i></b></td>
|
||||
* <td>{@value #FORCE_TBL_PARAM}</td>
|
||||
* <td>{@code false}</td>
|
||||
* <td>Allows explicit definition of which optimization strategy to use</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
|
@ -83,19 +87,19 @@ import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
|
|||
* <table>
|
||||
* <caption>Table configuration parameters</caption>
|
||||
* <tr>
|
||||
* <td><b>NAME</b></td>
|
||||
* <td><b>DEFAULT</b></td>
|
||||
* <td><b>DESCRIPTION</b></td>
|
||||
* <td><b>Parameter name</b></td>
|
||||
* <td><b>Default value</b></td>
|
||||
* <td><b>Interpretation</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_COLUMN_PARAM}</td>
|
||||
* <td>{@link #DEF_VALUE_COLUMN}</td>
|
||||
* <td>{@value #VALUE_COLUMN_PARAM}</td>
|
||||
* <td>{@value #DEF_VALUE_COLUMN}</td>
|
||||
* <td>The name of column which holds the sequence value for the given segment</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
* @author Lukasz Antoniak
|
||||
*/
|
||||
public class SequenceStyleGenerator
|
||||
implements PersistentIdentifierGenerator, BulkInsertionCapableIdentifierGenerator {
|
||||
|
@ -134,7 +138,8 @@ public class SequenceStyleGenerator
|
|||
// table-specific parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* Indicates the name of the column holding the identifier values. The default value is {@link #DEF_VALUE_COLUMN}
|
||||
* Indicates the name of the column holding the identifier values.
|
||||
* The default value is {@value #DEF_VALUE_COLUMN}
|
||||
*/
|
||||
public static final String VALUE_COLUMN_PARAM = "value_column";
|
||||
|
||||
|
|
|
@ -18,10 +18,11 @@ import org.hibernate.service.ServiceRegistry;
|
|||
import static org.hibernate.id.enhanced.TableGenerator.DEF_TABLE;
|
||||
|
||||
/**
|
||||
* ImplicitDatabaseObjectNamingStrategy using a single structure for
|
||||
* all implicit names:<ul>
|
||||
* <li>{@value ImplicitDatabaseObjectNamingStrategy#DEF_SEQUENCE} for sequences</li>
|
||||
* <li>{@value TableGenerator#DEF_TABLE} for tables</li>
|
||||
* An {@link ImplicitDatabaseObjectNamingStrategy} using a single structure for all
|
||||
* implicit names:
|
||||
* <ul>
|
||||
* <li>{@value ImplicitDatabaseObjectNamingStrategy#DEF_SEQUENCE} for sequences
|
||||
* <li>{@value TableGenerator#DEF_TABLE} for tables
|
||||
* </ul>
|
||||
*
|
||||
* @author Andrea Boriero
|
||||
|
|
|
@ -16,46 +16,51 @@ import org.hibernate.boot.model.relational.QualifiedName;
|
|||
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
||||
import org.hibernate.boot.model.relational.QualifiedSequenceName;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import static org.hibernate.boot.model.naming.Identifier.isQuoted;
|
||||
import static org.hibernate.boot.model.naming.Identifier.unQuote;
|
||||
import static org.hibernate.id.IdentifierGenerator.GENERATOR_NAME;
|
||||
import static org.hibernate.id.OptimizableGenerator.IMPLICIT_NAME_BASE;
|
||||
import static org.hibernate.id.PersistentIdentifierGenerator.TABLE;
|
||||
import static org.hibernate.id.enhanced.SequenceStyleGenerator.CONFIG_SEQUENCE_PER_ENTITY_SUFFIX;
|
||||
import static org.hibernate.id.enhanced.SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX;
|
||||
import static org.hibernate.id.enhanced.TableGenerator.DEF_TABLE;
|
||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
||||
|
||||
/**
|
||||
* Hibernate's standard implicit naming strategy for identifier sequences and tables.
|
||||
*
|
||||
* For sequences (including forced-table sequences):<ol>
|
||||
* The standard {@linkplain ImplicitDatabaseObjectNamingStrategy implicit naming strategy}
|
||||
* for identifier sequences and tables.
|
||||
* <p>
|
||||
* For sequences (including forced-table sequences):
|
||||
* <ol>
|
||||
* <li>
|
||||
* If {@value SequenceStyleGenerator#CONFIG_SEQUENCE_PER_ENTITY_SUFFIX} is specified,
|
||||
* a name composed of the "base" name with the specified suffix. The base name
|
||||
* depends on the usage of the generator, but is generally the root entity-name if
|
||||
* applied to an entity identifier or the table we are generating values for
|
||||
* a name is composed of the "base" name with the specified suffix. The base name
|
||||
* depends on the usage of the generator, but is usually the root entity name if
|
||||
* applied to an entity identifier or the table we are generating values for, or
|
||||
* </li>
|
||||
* <li>
|
||||
* If annotations are used and {@link GeneratedValue#generator()} is specified,
|
||||
* its value is used as the sequence name
|
||||
* If annotations are used and {@link GeneratedValue#generator} is specified,
|
||||
* its value is used as the sequence name.
|
||||
* </li>
|
||||
* <li>
|
||||
* If the "base" name is known, use that
|
||||
* If the "base" name is known, use that.
|
||||
* </li>
|
||||
* <li>
|
||||
* Throw an exception
|
||||
* Otherwise, throw a {@link MappingException}.
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
* For tables:<ol>
|
||||
*<p>
|
||||
* For tables:
|
||||
* <ol>
|
||||
* <li>
|
||||
* If annotations are used and {@link GeneratedValue#generator()} is specified,
|
||||
* its value is used as the table name
|
||||
* If annotations are used and {@link GeneratedValue#generator} is specified,
|
||||
* its value is used as the table name.
|
||||
* </li>
|
||||
* <li>
|
||||
* Fall back is to use {@value TableGenerator#DEF_TABLE}
|
||||
* Fall back is to use {@value TableGenerator#DEF_TABLE}.
|
||||
* </li>
|
||||
* </ol>
|
||||
*
|
||||
|
@ -70,9 +75,8 @@ public class StandardNamingStrategy implements ImplicitDatabaseObjectNamingStrat
|
|||
Identifier schemaName,
|
||||
Map<?, ?> configValues,
|
||||
ServiceRegistry serviceRegistry) {
|
||||
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
|
||||
|
||||
final String rootTableName = ConfigurationHelper.getString( PersistentIdentifierGenerator.TABLE, configValues );
|
||||
final String rootTableName = getString( TABLE, configValues );
|
||||
final String implicitName = implicitSequenceName( rootTableName, configValues, serviceRegistry );
|
||||
|
||||
if ( implicitName.contains( "." ) ) {
|
||||
|
@ -82,7 +86,9 @@ public class StandardNamingStrategy implements ImplicitDatabaseObjectNamingStrat
|
|||
return new QualifiedSequenceName(
|
||||
catalogName,
|
||||
schemaName,
|
||||
jdbcEnvironment.getIdentifierHelper().toIdentifier( implicitName )
|
||||
serviceRegistry.getService( JdbcEnvironment.class )
|
||||
.getIdentifierHelper()
|
||||
.toIdentifier( implicitName )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -90,32 +96,30 @@ public class StandardNamingStrategy implements ImplicitDatabaseObjectNamingStrat
|
|||
String rootTableName,
|
||||
Map<?, ?> configValues,
|
||||
ServiceRegistry serviceRegistry) {
|
||||
final String explicitSuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, configValues );
|
||||
final String base = ConfigurationHelper.getString( IMPLICIT_NAME_BASE, configValues, rootTableName );
|
||||
final String explicitSuffix = getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, configValues );
|
||||
final String base = getString( IMPLICIT_NAME_BASE, configValues, rootTableName );
|
||||
|
||||
if ( StringHelper.isNotEmpty( explicitSuffix ) ) {
|
||||
if ( isNotEmpty( explicitSuffix ) ) {
|
||||
// an "implicit name suffix" was specified
|
||||
if ( StringHelper.isNotEmpty( base ) ) {
|
||||
if ( Identifier.isQuoted( base ) ) {
|
||||
return "`" + Identifier.unQuote( base ) + explicitSuffix + "`";
|
||||
}
|
||||
return base + explicitSuffix;
|
||||
if ( isNotEmpty( base ) ) {
|
||||
return isQuoted( base )
|
||||
? "`" + unQuote( base ) + explicitSuffix + "`"
|
||||
: base + explicitSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
final String annotationGeneratorName = ConfigurationHelper.getString( IdentifierGenerator.GENERATOR_NAME, configValues );
|
||||
if ( StringHelper.isNotEmpty( annotationGeneratorName ) ) {
|
||||
final String annotationGeneratorName = getString( GENERATOR_NAME, configValues );
|
||||
if ( isNotEmpty( annotationGeneratorName ) ) {
|
||||
return annotationGeneratorName;
|
||||
}
|
||||
|
||||
if ( StringHelper.isNotEmpty( base ) ) {
|
||||
if ( Identifier.isQuoted( base ) ) {
|
||||
return "`" + Identifier.unQuote( base ) + DEF_SEQUENCE_SUFFIX + "`";
|
||||
}
|
||||
return base + DEF_SEQUENCE_SUFFIX;
|
||||
else if ( isNotEmpty( base ) ) {
|
||||
return isQuoted( base )
|
||||
? "`" + unQuote( base ) + DEF_SEQUENCE_SUFFIX + "`"
|
||||
: base + DEF_SEQUENCE_SUFFIX;
|
||||
}
|
||||
else {
|
||||
throw new MappingException( "Unable to determine implicit sequence name; target table - " + rootTableName );
|
||||
}
|
||||
|
||||
throw new MappingException( "Unable to determine implicit sequence name; target table - " + rootTableName );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -130,22 +134,18 @@ public class StandardNamingStrategy implements ImplicitDatabaseObjectNamingStrat
|
|||
return QualifiedNameParser.INSTANCE.parse( tableName );
|
||||
}
|
||||
else {
|
||||
final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class );
|
||||
return new QualifiedNameParser.NameParts(
|
||||
catalogName,
|
||||
schemaName,
|
||||
jdbcEnvironment.getIdentifierHelper().toIdentifier( tableName )
|
||||
serviceRegistry.getService( JdbcEnvironment.class )
|
||||
.getIdentifierHelper().toIdentifier( tableName )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static String implicitTableName(Map<?, ?> configValues) {
|
||||
final String generatorName = ConfigurationHelper.getString( IdentifierGenerator.GENERATOR_NAME, configValues );
|
||||
if ( StringHelper.isNotEmpty( generatorName ) ) {
|
||||
return generatorName;
|
||||
}
|
||||
|
||||
return DEF_TABLE;
|
||||
final String generatorName = getString( GENERATOR_NAME, configValues );
|
||||
return isNotEmpty( generatorName ) ? generatorName : DEF_TABLE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,31 +17,32 @@ import org.jboss.logging.Logger;
|
|||
*/
|
||||
public enum StandardOptimizerDescriptor {
|
||||
/**
|
||||
* Describes the optimizer for no optimization
|
||||
* Describes the optimizer for no optimization.
|
||||
*/
|
||||
NONE( "none", NoopOptimizer.class ),
|
||||
/**
|
||||
* Describes the optimizer for using a custom "hilo" algorithm optimization
|
||||
* Describes the optimizer for using a custom "hilo" algorithm optimization.
|
||||
*/
|
||||
HILO( "hilo", HiLoOptimizer.class ),
|
||||
/**
|
||||
* Describes the optimizer for using a custom "hilo" algorithm optimization, following the legacy
|
||||
* Hibernate hilo algorithm
|
||||
* Describes the optimizer for using a custom "hilo" algorithm optimization, following the
|
||||
* legacy Hibernate hilo algorithm.
|
||||
*/
|
||||
LEGACY_HILO( "legacy-hilo", LegacyHiLoAlgorithmOptimizer.class ),
|
||||
/**
|
||||
* Describes the optimizer for use with tables/sequences that store the chunk information. Here, specifically the
|
||||
* hi value is stored in the database.
|
||||
* Describes the optimizer for use with tables/sequences that store the chunk information.
|
||||
* Here, specifically the hi value is stored in the database.
|
||||
*/
|
||||
POOLED( "pooled", PooledOptimizer.class, true ),
|
||||
/**
|
||||
* Describes the optimizer for use with tables/sequences that store the chunk information. Here, specifically the
|
||||
* lo value is stored in the database.
|
||||
* Describes the optimizer for use with tables/sequences that store the chunk information.
|
||||
* Here, specifically the lo value is stored in the database.
|
||||
*/
|
||||
POOLED_LO( "pooled-lo", PooledLoOptimizer.class, true ),
|
||||
/**
|
||||
* Describes the optimizer for use with tables/sequences that store the chunk information. Here, specifically the
|
||||
* lo value is stored in the database and ThreadLocal used to cache the generation state.
|
||||
* Describes the optimizer for use with tables/sequences that store the chunk information.
|
||||
* Here, specifically the lo value is stored in the database and ThreadLocal used to cache
|
||||
* the generation state.
|
||||
*/
|
||||
POOLED_LOTL( "pooled-lotl", PooledLoThreadLocalOptimizer.class, true );
|
||||
|
||||
|
@ -78,8 +79,9 @@ public enum StandardOptimizerDescriptor {
|
|||
*
|
||||
* @param externalName The external name
|
||||
*
|
||||
* @return The corresponding enum value; if no external name is supplied, {@link #NONE} is returned; if an
|
||||
* unrecognized external name is supplied, {@code null} is returned
|
||||
* @return The corresponding enum value; if no external name is supplied,
|
||||
* {@link #NONE} is returned; if an unrecognized external name is supplied,
|
||||
* {@code null} is returned
|
||||
*/
|
||||
public static StandardOptimizerDescriptor fromExternalName(String externalName) {
|
||||
if ( StringHelper.isEmpty( externalName ) ) {
|
||||
|
|
|
@ -70,58 +70,58 @@ import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
|||
* 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>
|
||||
* Byy 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 instead default to using a row for each entity name.
|
||||
* By default, we use a single row for all generators (the {@value #DEF_SEGMENT_VALUE}
|
||||
* segment). The configuration parameter {@value #CONFIG_PREFER_SEGMENT_PER_ENTITY} can
|
||||
* be used to change that to instead default to using a row for each entity name.
|
||||
* <p>
|
||||
* <table>
|
||||
* <caption>Configuration parameters</caption>
|
||||
* <tr>
|
||||
* <td><b>NAME</b></td>
|
||||
* <td><b>DEFAULT</b></td>
|
||||
* <td><b>DESCRIPTION</b></td>
|
||||
* <td><b>Parameter name</b></td>
|
||||
* <td><b>Default value</b></td>
|
||||
* <td><b>Interpretation</b></td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #TABLE_PARAM}</td>
|
||||
* <td>{@link #DEF_TABLE}</td>
|
||||
* <td>{@value #TABLE_PARAM}</td>
|
||||
* <td>{@value #DEF_TABLE}</td>
|
||||
* <td>The name of the table to use to store/retrieve values</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_COLUMN_PARAM}</td>
|
||||
* <td>{@link #DEF_VALUE_COLUMN}</td>
|
||||
* <td>{@value #VALUE_COLUMN_PARAM}</td>
|
||||
* <td>{@value #DEF_VALUE_COLUMN}</td>
|
||||
* <td>The name of column which holds the sequence value for the given segment</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #SEGMENT_COLUMN_PARAM}</td>
|
||||
* <td>{@link #DEF_SEGMENT_COLUMN}</td>
|
||||
* <td>{@value #SEGMENT_COLUMN_PARAM}</td>
|
||||
* <td>{@value #DEF_SEGMENT_COLUMN}</td>
|
||||
* <td>The name of the column which holds the segment key</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #SEGMENT_VALUE_PARAM}</td>
|
||||
* <td>{@link #DEF_SEGMENT_VALUE}</td>
|
||||
* <td>{@value #SEGMENT_VALUE_PARAM}</td>
|
||||
* <td>{@value #DEF_SEGMENT_VALUE}</td>
|
||||
* <td>The value indicating which segment is used by this generator;
|
||||
* refers to values in the {@link #SEGMENT_COLUMN_PARAM} column</td>
|
||||
* refers to values in the {@value #SEGMENT_COLUMN_PARAM} column</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #SEGMENT_LENGTH_PARAM}</td>
|
||||
* <td>{@link #DEF_SEGMENT_LENGTH}</td>
|
||||
* <td>The data length of the {@link #SEGMENT_COLUMN_PARAM} column;
|
||||
* <td>{@value #SEGMENT_LENGTH_PARAM}</td>
|
||||
* <td>{@value #DEF_SEGMENT_LENGTH}</td>
|
||||
* <td>The data length of the {@value #SEGMENT_COLUMN_PARAM} column;
|
||||
* used for schema creation</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #INITIAL_PARAM}</td>
|
||||
* <td>{@link #DEFAULT_INITIAL_VALUE}</td>
|
||||
* <td>{@value #INITIAL_PARAM}</td>
|
||||
* <td>{@value #DEFAULT_INITIAL_VALUE}</td>
|
||||
* <td>The initial value to be stored for the given segment</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #INCREMENT_PARAM}</td>
|
||||
* <td>{@link #DEFAULT_INCREMENT_SIZE}</td>
|
||||
* <td>{@value #INCREMENT_PARAM}</td>
|
||||
* <td>{@value #DEFAULT_INCREMENT_SIZE}</td>
|
||||
* <td>The increment size for the underlying segment;
|
||||
* see the discussion on {@link Optimizer} for more details.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #OPT_PARAM}</td>
|
||||
* <td><i>depends on defined increment size</i></td>
|
||||
* <td>{@value #OPT_PARAM}</td>
|
||||
* <td><em>depends on defined increment size</em></td>
|
||||
* <td>Allows explicit definition of which optimization strategy to use</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
|
@ -135,62 +135,62 @@ public class TableGenerator implements PersistentIdentifierGenerator {
|
|||
);
|
||||
|
||||
/**
|
||||
* By default (in the absence of a {@link #SEGMENT_VALUE_PARAM} setting) we use a single row for all
|
||||
* By default, in the absence of a {@value #SEGMENT_VALUE_PARAM} setting, we use a single row for all
|
||||
* generators. This setting can be used to change that to instead default to using a row for each entity name.
|
||||
*/
|
||||
public static final String CONFIG_PREFER_SEGMENT_PER_ENTITY = "prefer_entity_table_as_segment_value";
|
||||
|
||||
/**
|
||||
* Configures the name of the table to use. The default value is {@link #DEF_TABLE}
|
||||
* Configures the name of the table to use. The default value is {@value #DEF_TABLE}
|
||||
*/
|
||||
public static final String TABLE_PARAM = "table_name";
|
||||
|
||||
/**
|
||||
* The default {@link #TABLE_PARAM} value
|
||||
* The default {@value #TABLE_PARAM} value
|
||||
*/
|
||||
public static final String DEF_TABLE = "hibernate_sequences";
|
||||
|
||||
/**
|
||||
* The name of column which holds the sequence value. The default value is {@link #DEF_VALUE_COLUMN}
|
||||
* The name of column which holds the sequence value. The default value is {@value #DEF_VALUE_COLUMN}
|
||||
*/
|
||||
public static final String VALUE_COLUMN_PARAM = "value_column_name";
|
||||
|
||||
/**
|
||||
* The default {@link #VALUE_COLUMN_PARAM} value
|
||||
* The default {@value #VALUE_COLUMN_PARAM} value
|
||||
*/
|
||||
public static final String DEF_VALUE_COLUMN = "next_val";
|
||||
|
||||
/**
|
||||
* The name of the column which holds the segment key. The segment defines the different buckets (segments)
|
||||
* of values currently tracked in the table. The default value is {@link #DEF_SEGMENT_COLUMN}
|
||||
* of values currently tracked in the table. The default value is {@value #DEF_SEGMENT_COLUMN}
|
||||
*/
|
||||
public static final String SEGMENT_COLUMN_PARAM = "segment_column_name";
|
||||
|
||||
/**
|
||||
* The default {@link #SEGMENT_COLUMN_PARAM} value
|
||||
* The default {@value #SEGMENT_COLUMN_PARAM} value
|
||||
*/
|
||||
public static final String DEF_SEGMENT_COLUMN = "sequence_name";
|
||||
|
||||
/**
|
||||
* The value indicating which segment is used by this generator, as indicated by the actual value stored in the
|
||||
* column indicated by {@link #SEGMENT_COLUMN_PARAM}. The default value for setting is {@link #DEF_SEGMENT_VALUE},
|
||||
* although {@link #CONFIG_PREFER_SEGMENT_PER_ENTITY} effects the default as well.
|
||||
* column indicated by {@value #SEGMENT_COLUMN_PARAM}. The default value for setting is {@link #DEF_SEGMENT_VALUE},
|
||||
* although {@value #CONFIG_PREFER_SEGMENT_PER_ENTITY} effects the default as well.
|
||||
*/
|
||||
public static final String SEGMENT_VALUE_PARAM = "segment_value";
|
||||
|
||||
/**
|
||||
* The default {@link #SEGMENT_VALUE_PARAM} value, unless {@link #CONFIG_PREFER_SEGMENT_PER_ENTITY} is specified
|
||||
* The default {@value #SEGMENT_VALUE_PARAM} value, unless {@link #CONFIG_PREFER_SEGMENT_PER_ENTITY} is specified
|
||||
*/
|
||||
public static final String DEF_SEGMENT_VALUE = "default";
|
||||
|
||||
/**
|
||||
* Indicates the length of the column defined by {@link #SEGMENT_COLUMN_PARAM}. Used in schema export. The
|
||||
* default value is {@link #DEF_SEGMENT_LENGTH}
|
||||
* default value is {@value #DEF_SEGMENT_LENGTH}
|
||||
*/
|
||||
public static final String SEGMENT_LENGTH_PARAM = "segment_value_length";
|
||||
|
||||
/**
|
||||
* The default {@link #SEGMENT_LENGTH_PARAM} value
|
||||
* The default {@value #SEGMENT_LENGTH_PARAM} value
|
||||
*/
|
||||
public static final int DEF_SEGMENT_LENGTH = 255;
|
||||
|
||||
|
|
|
@ -6,9 +6,21 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* This package contains the built-in id generators, all of which
|
||||
* implement {@link org.hibernate.id.IdentifierGenerator} or
|
||||
* This package and its subpackages, especially {@link org.hibernate.id.enhanced},
|
||||
* contain the built-in id generators, all of which implement either
|
||||
* {@link org.hibernate.id.IdentifierGenerator} or
|
||||
* {@link org.hibernate.id.PostInsertIdentifierGenerator}.
|
||||
* <p>
|
||||
* The most useful id generators in modern Hibernate are:
|
||||
* <ul>
|
||||
* <li>{@link org.hibernate.id.IdentityGenerator} - {@code @GeneratedValue(strategy=IDENTITY)}
|
||||
* <li>{@link org.hibernate.id.enhanced.SequenceStyleGenerator} - {@code @GeneratedValue(strategy=SEQUENCE)}
|
||||
* <li>{@link org.hibernate.id.enhanced.TableGenerator} - {@code @GeneratedValue(strategy=TABLE)}
|
||||
* <li>{@link org.hibernate.id.uuid.UuidGenerator} - {@code @UuidGenerator}
|
||||
* </ul>
|
||||
* <p>
|
||||
* @apiNote The remaining id generators are kept around for backward compatibility
|
||||
* and as an implementation detail of the {@code hbm.xml} mapping format.
|
||||
*
|
||||
* @see org.hibernate.generator
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue