Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ private static SingleStoreTableType getTableType(DialectResolutionInfo info) {
private static boolean getUpdateForEnabled(DialectResolutionInfo info) {
return ConfigurationHelper.getBoolean(
SINGLE_STORE_FOR_UPDATE_LOCK_ENABLED,
info.getConfigurationValues(),
false
info.getConfigurationValues()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.id.uuid.LocalObjectUuidHelper;
import org.hibernate.internal.BaselineSessionEventsListenerBuilder;
import org.hibernate.internal.EmptyInterceptor;
import org.hibernate.internal.util.NullnessHelper;
Expand All @@ -77,7 +76,6 @@
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.hibernate.resource.jdbc.spi.StatementInspector;
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
import org.hibernate.stat.Statistics;
import org.hibernate.type.format.FormatMapper;
import org.hibernate.type.format.jaxb.JaxbXmlFormatMapper;

Expand All @@ -88,6 +86,7 @@
import static org.hibernate.cfg.AvailableSettings.*;
import static org.hibernate.cfg.DialectSpecificSettings.ORACLE_OSON_DISABLED;
import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN;
import static org.hibernate.id.uuid.LocalObjectUuidHelper.generateLocalObjectUuid;
import static org.hibernate.internal.LockOptionsHelper.applyPropertiesToLockOptions;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
import static org.hibernate.internal.util.PropertiesHelper.map;
Expand All @@ -99,6 +98,7 @@
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
import static org.hibernate.jpa.internal.util.CacheModeHelper.interpretCacheMode;
import static org.hibernate.jpa.internal.util.ConfigurationHelper.getFlushMode;
import static org.hibernate.stat.Statistics.DEFAULT_QUERY_STATISTICS_MAX_SIZE;
import static org.hibernate.type.format.jackson.JacksonIntegration.getJsonJacksonFormatMapperOrNull;
import static org.hibernate.type.format.jackson.JacksonIntegration.getOsonJacksonFormatMapperOrNull;
import static org.hibernate.type.format.jackson.JacksonIntegration.getXMLJacksonFormatMapperOrNull;
Expand All @@ -117,7 +117,7 @@
*/
public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {

private final String uuid = LocalObjectUuidHelper.generateLocalObjectUuid();
private final String uuid = generateLocalObjectUuid();
private final StandardServiceRegistry serviceRegistry;

// integration
Expand Down Expand Up @@ -416,7 +416,8 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
strategySelector.resolveDefaultableStrategy( TimestampsCacheFactory.class,
settings.get( QUERY_CACHE_FACTORY ), StandardTimestampsCacheFactory.INSTANCE );
minimalPutsEnabled =
configurationService.getSetting( USE_MINIMAL_PUTS, BOOLEAN, regionFactory.isMinimalPutsEnabledByDefault() );
configurationService.getSetting( USE_MINIMAL_PUTS, BOOLEAN,
regionFactory.isMinimalPutsEnabledByDefault() );
structuredCacheEntriesEnabled =
configurationService.getSetting( USE_STRUCTURED_CACHE, BOOLEAN, false );
directReferenceCacheEntriesEnabled =
Expand Down Expand Up @@ -462,7 +463,7 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
connectionHandlingMode = interpretConnectionHandlingMode( settings, serviceRegistry );

connectionProviderDisablesAutoCommit =
getBoolean( CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, settings, false );
getBoolean( CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT, settings );

commentsEnabled = getBoolean( USE_SQL_COMMENTS, settings );

Expand All @@ -479,10 +480,9 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo

criteriaValueHandlingMode = ValueHandlingMode.interpret( settings.get( CRITERIA_VALUE_HANDLING_MODE ) );
criteriaCopyTreeEnabled = getBoolean( CRITERIA_COPY_TREE, settings, jpaBootstrap );
criteriaPlanCacheEnabled = getBoolean( CRITERIA_PLAN_CACHE_ENABLED, settings, false );
criteriaPlanCacheEnabled = getBoolean( CRITERIA_PLAN_CACHE_ENABLED, settings );

nativeJdbcParametersIgnored =
getBoolean( NATIVE_IGNORE_JDBC_PARAMETERS, settings, false );
nativeJdbcParametersIgnored = getBoolean( NATIVE_IGNORE_JDBC_PARAMETERS, settings );

// added the boolean parameter in case we want to define some form of "all" as discussed
jpaCompliance = context.getJpaCompliance();
Expand All @@ -504,16 +504,14 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
xmlFunctionsEnabled = getBoolean( XML_FUNCTIONS_ENABLED, settings );

queryStatisticsMaxSize =
getInt( QUERY_STATISTICS_MAX_SIZE, settings, Statistics.DEFAULT_QUERY_STATISTICS_MAX_SIZE );
getInt( QUERY_STATISTICS_MAX_SIZE, settings, DEFAULT_QUERY_STATISTICS_MAX_SIZE );

unownedAssociationTransientCheck =
getBoolean( UNOWNED_ASSOCIATION_TRANSIENT_CHECK, settings, isJpaBootstrap() );

passProcedureParameterNames =
getBoolean( QUERY_PASS_PROCEDURE_PARAMETER_NAMES, settings, false );
passProcedureParameterNames = getBoolean( QUERY_PASS_PROCEDURE_PARAMETER_NAMES, settings );

preferJdbcDatetimeTypes =
getBoolean( NATIVE_PREFER_JDBC_DATETIME_TYPES, settings, false );
preferJdbcDatetimeTypes = getBoolean( NATIVE_PREFER_JDBC_DATETIME_TYPES, settings );

defaultSessionProperties = initializeDefaultSessionProperties( configurationService );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static MySQLServerConfiguration fromDialectResolutionInfo(DialectResoluti
bytesPerCharacter = getInt( MYSQL_BYTES_PER_CHARACTER, info.getConfigurationValues(), 4 );
}
if ( noBackslashEscapes == null ) {
noBackslashEscapes = getBoolean( MYSQL_NO_BACKSLASH_ESCAPES, info.getConfigurationValues(), false );
noBackslashEscapes = getBoolean( MYSQL_NO_BACKSLASH_ESCAPES, info.getConfigurationValues() );
}
return new MySQLServerConfiguration( bytesPerCharacter, noBackslashEscapes );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public static OracleServerConfiguration fromDialectResolutionInfo(DialectResolut

// default to the dialect-specific configuration settings
final Map<String, Object> configuration = info.getConfigurationValues();
final boolean defaultExtended = getBoolean( ORACLE_EXTENDED_STRING_SIZE, configuration, false );
final boolean defaultAutonomous = getBoolean( ORACLE_AUTONOMOUS_DATABASE, configuration, false );
final boolean defaultContinuity = getBoolean( ORACLE_APPLICATION_CONTINUITY, configuration, false );
final boolean defaultExtended = getBoolean( ORACLE_EXTENDED_STRING_SIZE, configuration );
final boolean defaultAutonomous = getBoolean( ORACLE_AUTONOMOUS_DATABASE, configuration );
final boolean defaultContinuity = getBoolean( ORACLE_APPLICATION_CONTINUITY, configuration );

boolean extended;
boolean autonomous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
import org.hibernate.type.descriptor.jdbc.TinyIntJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType;
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

Expand Down Expand Up @@ -206,10 +203,10 @@ public long getDefaultLobLength() {
}

private static boolean isAnsiNull(DialectResolutionInfo info) {
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
final var databaseMetaData = info.getDatabaseMetadata();
if ( databaseMetaData != null ) {
try ( var statement = databaseMetaData.getConnection().createStatement() ) {
final ResultSet resultSet = statement.executeQuery( "SELECT @@options" );
final var resultSet = statement.executeQuery( "SELECT @@options" );
if ( resultSet.next() ) {
final byte[] optionBytes = resultSet.getBytes( 1 );
// By trial and error, enabling and disabling ansinull revealed that this bit is the indicator
Expand All @@ -221,14 +218,14 @@ private static boolean isAnsiNull(DialectResolutionInfo info) {
}
}
// default to the dialect-specific configuration setting
return getBoolean( SYBASE_ANSI_NULL, info.getConfigurationValues(), false );
return getBoolean( SYBASE_ANSI_NULL, info.getConfigurationValues() );
}

private int pageSize(DialectResolutionInfo info) {
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
final var databaseMetaData = info.getDatabaseMetadata();
if ( databaseMetaData != null ) {
try ( var statement = databaseMetaData.getConnection().createStatement() ) {
final ResultSet resultSet = statement.executeQuery( "SELECT @@maxpagesize" );
final var resultSet = statement.executeQuery( "SELECT @@maxpagesize" );
if ( resultSet.next() ) {
return resultSet.getInt( 1 );
}
Expand Down Expand Up @@ -296,8 +293,7 @@ public boolean supportsDistinctFromPredicate() {
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );

final JdbcTypeRegistry jdbcTypeRegistry = typeContributions.getTypeConfiguration()
.getJdbcTypeRegistry();
final var jdbcTypeRegistry = typeContributions.getTypeConfiguration().getJdbcTypeRegistry();
jdbcTypeRegistry.addDescriptor( Types.BOOLEAN, TinyIntJdbcType.INSTANCE );
jdbcTypeRegistry.addDescriptor( Types.TIMESTAMP_WITH_TIMEZONE, TimestampJdbcType.INSTANCE );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ else if ( ! generationState.upperLimit.gt( generationState.value ) ) {
private GenerationState noTenantState;
private Map<String,GenerationState> tenantSpecificState;

@Override
public void reset() {
noTenantState = null;
tenantSpecificState = null;
}

private GenerationState locateGenerationState(String tenantId) {
if ( tenantId == null ) {
if ( noTenantState == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public Serializable generate(AccessCallback callback) {
private GenerationState noTenantState;
private Map<String,GenerationState> tenantSpecificState;

@Override
public void reset() {
noTenantState = null;
tenantSpecificState = null;
}

private GenerationState locateGenerationState(String tenantIdentifier) {
if ( tenantIdentifier == null ) {
if ( noTenantState == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public NoopOptimizer(Class<?> returnClass, int incrementSize) {

@Override
public Serializable generate(AccessCallback callback) {
// IMPL NOTE : this method is called concurrently and is
// IMPL NOTE: this method is called concurrently and is
// not synchronized. It is very important to work on the
// local variable: the field lastSourceValue is not
// reliable as it might be mutated by multiple threads.
Expand Down Expand Up @@ -59,4 +59,9 @@ public boolean applyIncrementSizeToSourceValues() {
public Expression createLowValueExpression(Expression databaseValue, SessionFactoryImplementor sessionFactory) {
return databaseValue;
}

@Override
public void reset() {
lastSourceValue = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import java.io.Serializable;

/**
* Performs optimization on an optimizable identifier generator. Typically
* Performs optimization on an optimizable identifier generator. Typically.
* this optimization takes the form of trying to ensure we do not have to
* hit the database on each and every request to get an identifier value.
* <p>
* Optimizers work on constructor injection. They should provide
* a constructor with the following arguments <ol>
* <li>java.lang.Class - The return type for the generated values</li>
* <li>int - The increment size</li>
* Optimizers work on constructor injection. They should provide a
* constructor accepting the following arguments:
* <ol>
* <li>{@code java.lang.Class} - The return type for the generated values</li>
* <li>{@code int} - The increment size</li>
* </ol>
*
* @author Steve Ebersole
Expand All @@ -35,6 +36,13 @@ public interface Optimizer {
*/
Serializable generate(AccessCallback callback);

/**
* Reset the optimizer before restarting the underlying database sequence.
*
* @since 7.2
*/
void reset();

/**
* A common means to access the last value obtained from the underlying
* source. This is intended for testing purposes, since accessing the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public Serializable generate(AccessCallback callback) {
private GenerationState noTenantState;
private Map<String,GenerationState> tenantSpecificState;

@Override
public void reset() {
noTenantState = null;
tenantSpecificState = null;
}

private GenerationState locateGenerationState(String tenantIdentifier) {
if ( tenantIdentifier == null ) {
if ( noTenantState == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ private GenerationState locateGenerationState(String tenantIdentifier) {
}
}

@Override
public void reset() {
singleTenantState.remove();
multiTenantStates.remove();
}

// for Hibernate testsuite use only
private GenerationState noTenantGenerationState() {
final var noTenantState = locateGenerationState( null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public PooledOptimizer(Class<?> returnClass, int incrementSize) {
OPTIMIZER_MESSAGE_LOGGER.creatingPooledOptimizer( incrementSize, returnClass.getName() );
}


@Override
public Serializable generate(AccessCallback callback) {
lock.lock();
Expand Down Expand Up @@ -99,6 +98,12 @@ else if ( generationState.value.gt( generationState.hiValue ) ) {
private GenerationState noTenantState;
private Map<String,GenerationState> tenantSpecificState;

@Override
public void reset() {
noTenantState = null;
tenantSpecificState = null;
}

private GenerationState locateGenerationState(String tenantIdentifier) {
if ( tenantIdentifier == null ) {
if ( noTenantState == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.AssertionFailure;
import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.InitCommand;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.QualifiedName;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
Expand Down Expand Up @@ -178,9 +179,16 @@ public void registerExtraExportables(Table table, Optimizer optimizer) {
final long max = getMaxPrimaryKey( isolator, primaryKeyColumnName, tableName );
final long current = getNextSequenceValue( isolator, sequenceName);
final long startWith = Math.max( max + adjustment, current );
optimizer.reset();
return new InitCommand( sqlContext.getDialect().getSequenceSupport()
.getRestartSequenceString( sequenceName, startWith ) );
} );
table.addResetCommand( sqlContext -> {
optimizer.reset();
final String sequenceName = sqlContext.format( physicalSequenceName );
return new InitCommand( sqlContext.getDialect().getSequenceSupport()
.getRestartSequenceString( sequenceName, initialValue ) );
} );
}

@Override
Expand All @@ -197,18 +205,24 @@ protected QualifiedName getQualifiedName() {
}

protected void buildSequence(Database database) {
final var namespace = database.locateNamespace(
logicalQualifiedSequenceName.getCatalogName(),
logicalQualifiedSequenceName.getSchemaName()
);
final var sequence =
locateOrCreateSequence( database.locateNamespace(
logicalQualifiedSequenceName.getCatalogName(),
logicalQualifiedSequenceName.getSchemaName()
) );
physicalSequenceName = sequence.getName();
}

private Sequence locateOrCreateSequence(Namespace namespace) {
final int sourceIncrementSize = getSourceIncrementSize();
final var objectName = logicalQualifiedSequenceName.getObjectName();
Sequence sequence = namespace.locateSequence( objectName );
if ( sequence != null ) {
sequence.validate( initialValue, sourceIncrementSize );
final var existingSequence = namespace.locateSequence( objectName );
if ( existingSequence != null ) {
existingSequence.validate( initialValue, sourceIncrementSize );
return existingSequence;
}
else {
sequence = namespace.createSequence(
return namespace.createSequence(
objectName,
physicalName -> new Sequence(
contributor,
Expand All @@ -221,6 +235,5 @@ protected void buildSequence(Database database) {
)
);
}
physicalSequenceName = sequence.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ protected OptimizerDescriptor determineOptimizationStrategy(Properties params, i
* selected optimizer. This is the hook to achieve that.
*
* @param optimizationStrategy The optimizer strategy (name)
* @param incrementSize The {@link #determineIncrementSize determined increment size}
* @param incrementSize The {@linkplain #determineIncrementSize determined increment size}
* @return The adjusted increment size.
*/
protected int determineAdjustedIncrementSize(OptimizerDescriptor optimizationStrategy, int incrementSize) {
Expand Down
Loading
Loading