remove deprecated operations from SessionFactoryBuilder

This commit is contained in:
Gavin King 2022-01-25 08:58:55 +01:00
parent f0fa64bda8
commit 9c37385cb9
5 changed files with 38 additions and 104 deletions

View File

@ -395,25 +395,6 @@ public interface SessionFactoryBuilder {
*/ */
SessionFactoryBuilder applyPreferUserTransactions(boolean preferUserTransactions); SessionFactoryBuilder applyPreferUserTransactions(boolean preferUserTransactions);
/**
* Should we strictly adhere to JPA Query Language (JPQL) syntax, or more broadly support
* all of Hibernate's superset (HQL)?
* <p/>
* Setting this to {@code true} may cause valid HQL to throw an exception because it violates
* the JPQL subset.
*
* @param enabled {@code true} indicates that we should strictly adhere to the JPQL subset; {@code false}
* indicates we should accept the broader HQL syntax.
*
* @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#JPAQL_STRICT_COMPLIANCE
*
* @deprecated Use {@link #enableJpaQueryCompliance} instead
*/
@Deprecated
SessionFactoryBuilder applyStrictJpaQueryLanguageCompliance(boolean enabled);
/** /**
* Should named queries be checked on startup? * Should named queries be checked on startup?
* *
@ -618,26 +599,10 @@ public interface SessionFactoryBuilder {
*/ */
SessionFactoryBuilder applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode); SessionFactoryBuilder applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode);
/**
* Apply a ConnectionReleaseMode.
*
* @param connectionReleaseMode The ConnectionReleaseMode to use.
*
* @return {@code this}, for method chaining
*
* @see org.hibernate.cfg.AvailableSettings#RELEASE_CONNECTIONS
*
* @deprecated Use {@link #applyConnectionHandlingMode} instead
*/
@Deprecated
SessionFactoryBuilder applyConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode);
/** /**
* @see org.hibernate.cfg.AvailableSettings#CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT * @see org.hibernate.cfg.AvailableSettings#CONNECTION_PROVIDER_DISABLES_AUTOCOMMIT
*/ */
default SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) { SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit);
return this;
}
/** /**
* Should Hibernate apply comments to SQL it generates? * Should Hibernate apply comments to SQL it generates?
@ -652,15 +617,14 @@ public interface SessionFactoryBuilder {
/** /**
* Apply a SQLFunction to the underlying {@link org.hibernate.query.sqm.function.SqmFunctionRegistry}. * Apply a SQLFunction to the underlying {@link org.hibernate.query.sqm.function.SqmFunctionRegistry}.
* <p/>
* TODO : Ultimately I would like this to move to {@link MetadataBuilder} in conjunction with allowing mappings to reference SQLFunctions.
* today mappings can only name SQL functions directly, not through the SQLFunctionRegistry indirection
* *
* @param registrationName The name to register it under. * @param registrationName The name to register it under.
* @param functionDescriptor The SQLFunction impl * @param functionDescriptor The SQLFunction impl
* *
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
// Ultimately I would like this to move to {@link MetadataBuilder} in conjunction with allowing mappings to reference SQLFunctions.
// today mappings can only name SQL functions directly, not through the SQLFunctionRegistry indirection
SessionFactoryBuilder applySqlFunction(String registrationName, SqmFunctionDescriptor functionDescriptor); SessionFactoryBuilder applySqlFunction(String registrationName, SqmFunctionDescriptor functionDescriptor);
/** /**

View File

@ -349,12 +349,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return this; return this;
} }
@Override
public SessionFactoryBuilder applyConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
this.optionsBuilder.applyConnectionReleaseMode( connectionReleaseMode );
return this;
}
@Override @Override
public SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) { public SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) {
this.optionsBuilder.applyConnectionProviderDisablesAutoCommit( providerDisablesAutoCommit ); this.optionsBuilder.applyConnectionProviderDisablesAutoCommit( providerDisablesAutoCommit );
@ -391,13 +385,6 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
return this; return this;
} }
@Override
public SessionFactoryBuilder applyStrictJpaQueryLanguageCompliance(boolean enabled) {
this.optionsBuilder.enableStrictJpaQueryLanguageCompliance( enabled );
return this;
}
@Override @Override
public SessionFactoryBuilder enableJpaQueryCompliance(boolean enabled) { public SessionFactoryBuilder enableJpaQueryCompliance(boolean enabled) {
this.optionsBuilder.enableJpaQueryCompliance( enabled ); this.optionsBuilder.enableJpaQueryCompliance( enabled );

View File

@ -17,7 +17,6 @@ import java.util.TimeZone;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.hibernate.ConnectionAcquisitionMode;
import org.hibernate.ConnectionReleaseMode; import org.hibernate.ConnectionReleaseMode;
import org.hibernate.CustomEntityDirtinessStrategy; import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.EmptyInterceptor; import org.hibernate.EmptyInterceptor;
@ -179,12 +178,12 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private Class<? extends Interceptor> statelessInterceptorClass; private Class<? extends Interceptor> statelessInterceptorClass;
private Supplier<? extends Interceptor> statelessInterceptorSupplier; private Supplier<? extends Interceptor> statelessInterceptorSupplier;
private StatementInspector statementInspector; private StatementInspector statementInspector;
private List<SessionFactoryObserver> sessionFactoryObserverList = new ArrayList<>(); private final List<SessionFactoryObserver> sessionFactoryObserverList = new ArrayList<>();
private BaselineSessionEventsListenerBuilder baselineSessionEventsListenerBuilder; // not exposed on builder atm private final BaselineSessionEventsListenerBuilder baselineSessionEventsListenerBuilder; // not exposed on builder atm
// persistence behavior // persistence behavior
private CustomEntityDirtinessStrategy customEntityDirtinessStrategy; private CustomEntityDirtinessStrategy customEntityDirtinessStrategy;
private List<EntityNameResolver> entityNameResolvers = new ArrayList<>(); private final List<EntityNameResolver> entityNameResolvers = new ArrayList<>();
private EntityNotFoundDelegate entityNotFoundDelegate; private EntityNotFoundDelegate entityNotFoundDelegate;
private boolean identifierRollbackEnabled; private boolean identifierRollbackEnabled;
private EntityTuplizerFactory entityTuplizerFactory = new EntityTuplizerFactory(); private EntityTuplizerFactory entityTuplizerFactory = new EntityTuplizerFactory();
@ -269,10 +268,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );
final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class );
final Map configurationSettings = new HashMap(); final Map<Object,Object> configurationSettings = new HashMap<>();
//noinspection unchecked
configurationSettings.putAll( jdbcServices.getJdbcEnvironment().getDialect().getDefaultProperties() ); configurationSettings.putAll( jdbcServices.getJdbcEnvironment().getDialect().getDefaultProperties() );
//noinspection unchecked
configurationSettings.putAll( cfgService.getSettings() ); configurationSettings.putAll( cfgService.getSettings() );
if ( cfgService == null ) { if ( cfgService == null ) {
cfgService = new ConfigurationServiceImpl( configurationSettings ); cfgService = new ConfigurationServiceImpl( configurationSettings );
@ -390,7 +387,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
); );
this.sqmTranslatorFactory = resolveSqmTranslator( this.sqmTranslatorFactory = resolveSqmTranslator(
sqmTranslatorFactoryImplFqn, sqmTranslatorFactoryImplFqn,
serviceRegistry,
strategySelector strategySelector
); );
@ -572,6 +568,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
); );
} }
@SuppressWarnings("unchecked")
private SqmMultiTableMutationStrategy resolveSqmMutationStrategy( private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(
String strategyName, String strategyName,
StandardServiceRegistry serviceRegistry, StandardServiceRegistry serviceRegistry,
@ -620,6 +617,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
); );
} }
@SuppressWarnings("unchecked")
private SqmMultiTableInsertStrategy resolveSqmInsertStrategy( private SqmMultiTableInsertStrategy resolveSqmInsertStrategy(
String strategyName, String strategyName,
StandardServiceRegistry serviceRegistry, StandardServiceRegistry serviceRegistry,
@ -680,7 +678,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
return strategySelector.resolveDefaultableStrategy( return strategySelector.resolveDefaultableStrategy(
HqlTranslator.class, HqlTranslator.class,
producerName, producerName,
new Callable<HqlTranslator>() { new Callable<>() {
@Override @Override
public HqlTranslator call() throws Exception { public HqlTranslator call() throws Exception {
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
@ -692,7 +690,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private SqmTranslatorFactory resolveSqmTranslator( private SqmTranslatorFactory resolveSqmTranslator(
String translatorImplFqn, String translatorImplFqn,
StandardServiceRegistry serviceRegistry,
StrategySelector strategySelector) { StrategySelector strategySelector) {
if ( StringHelper.isEmpty( translatorImplFqn ) ) { if ( StringHelper.isEmpty( translatorImplFqn ) ) {
return null; return null;
@ -704,8 +701,9 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
); );
} }
@SuppressWarnings("deprecation") private static Interceptor determineInterceptor(
private static Interceptor determineInterceptor(Map configurationSettings, StrategySelector strategySelector) { Map<Object,Object> configurationSettings,
StrategySelector strategySelector) {
Object setting = configurationSettings.get( INTERCEPTOR ); Object setting = configurationSettings.get( INTERCEPTOR );
if ( setting == null ) { if ( setting == null ) {
// try the legacy (deprecated) JPA name // try the legacy (deprecated) JPA name
@ -724,9 +722,9 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
); );
} }
@SuppressWarnings({"unchecked" }) @SuppressWarnings("unchecked")
private static Supplier<? extends Interceptor> determineStatelessInterceptor( private static Supplier<? extends Interceptor> determineStatelessInterceptor(
Map configurationSettings, Map<Object,Object> configurationSettings,
StrategySelector strategySelector) { StrategySelector strategySelector) {
Object setting = configurationSettings.get( SESSION_SCOPED_INTERCEPTOR ); Object setting = configurationSettings.get( SESSION_SCOPED_INTERCEPTOR );
@ -763,7 +761,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
} }
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode( private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
Map configurationSettings, Map<Object,Object> configurationSettings,
StandardServiceRegistry serviceRegistry) { StandardServiceRegistry serviceRegistry) {
final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret( final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret(
configurationSettings.get( CONNECTION_HANDLING ) configurationSettings.get( CONNECTION_HANDLING )
@ -930,7 +928,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
@Override @Override
public SessionFactoryObserver[] getSessionFactoryObservers() { public SessionFactoryObserver[] getSessionFactoryObservers() {
return sessionFactoryObserverList.toArray( new SessionFactoryObserver[ sessionFactoryObserverList.size() ] ); return sessionFactoryObserverList.toArray(new SessionFactoryObserver[0]);
} }
@Override @Override
@ -1120,7 +1118,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
@Override @Override
public EntityNameResolver[] getEntityNameResolvers() { public EntityNameResolver[] getEntityNameResolvers() {
return entityNameResolvers.toArray( new EntityNameResolver[ entityNameResolvers.size() ] ); return entityNameResolvers.toArray(new EntityNameResolver[0]);
} }
@Override @Override
@ -1410,21 +1408,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
this.connectionHandlingMode = mode; this.connectionHandlingMode = mode;
} }
public void applyConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
if ( this.connectionHandlingMode == null ) {
this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret(
ConnectionAcquisitionMode.AS_NEEDED,
connectionReleaseMode
);
}
else {
this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret(
this.connectionHandlingMode.getAcquisitionMode(),
connectionReleaseMode
);
}
}
public void applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) { public void applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) {
this.connectionProviderDisablesAutoCommit = providerDisablesAutoCommit; this.connectionProviderDisablesAutoCommit = providerDisablesAutoCommit;
} }
@ -1448,16 +1431,12 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
this.releaseResourcesOnCloseEnabled = enable; this.releaseResourcesOnCloseEnabled = enable;
} }
public void enableStrictJpaQueryLanguageCompliance(boolean enabled) {
enableJpaQueryCompliance( enabled );
}
public void enableJpaQueryCompliance(boolean enabled) { public void enableJpaQueryCompliance(boolean enabled) {
mutableJpaCompliance().setQueryCompliance( enabled ); mutableJpaCompliance().setQueryCompliance( enabled );
} }
private MutableJpaCompliance mutableJpaCompliance() { private MutableJpaCompliance mutableJpaCompliance() {
if ( ! MutableJpaCompliance.class.isInstance( this.jpaCompliance ) ) { if ( !(this.jpaCompliance instanceof MutableJpaCompliance) ) {
throw new IllegalStateException( "JpaCompliance is no longer mutable" ); throw new IllegalStateException( "JpaCompliance is no longer mutable" );
} }
@ -1506,7 +1485,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
} }
public SessionFactoryOptions buildOptions() { public SessionFactoryOptions buildOptions() {
if ( MutableJpaCompliance.class.isInstance( this.jpaCompliance ) ) { if ( this.jpaCompliance instanceof MutableJpaCompliance ) {
this.jpaCompliance = mutableJpaCompliance().immutableCopy(); this.jpaCompliance = mutableJpaCompliance().immutableCopy();
} }

View File

@ -8,7 +8,6 @@ package org.hibernate.boot.spi;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.CustomEntityDirtinessStrategy; import org.hibernate.CustomEntityDirtinessStrategy;
import org.hibernate.EntityNameResolver; import org.hibernate.EntityNameResolver;
import org.hibernate.Interceptor; import org.hibernate.Interceptor;
@ -237,12 +236,6 @@ public abstract class AbstractDelegatingSessionFactoryBuilder<T extends SessionF
return getThis(); return getThis();
} }
@Override
public T applyStrictJpaQueryLanguageCompliance(boolean enabled) {
delegate.applyStrictJpaQueryLanguageCompliance( enabled );
return getThis();
}
@Override @Override
public T applyNamedQueryCheckingOnStartup(boolean enabled) { public T applyNamedQueryCheckingOnStartup(boolean enabled) {
delegate.applyNamedQueryCheckingOnStartup( enabled ); delegate.applyNamedQueryCheckingOnStartup( enabled );
@ -327,13 +320,6 @@ public abstract class AbstractDelegatingSessionFactoryBuilder<T extends SessionF
return getThis(); return getThis();
} }
@SuppressWarnings("deprecation")
@Override
public T applyConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
delegate.applyConnectionReleaseMode( connectionReleaseMode );
return getThis();
}
@Override @Override
public SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) { public SessionFactoryBuilder applyConnectionProviderDisablesAutoCommit(boolean providerDisablesAutoCommit) {
delegate.applyConnectionProviderDisablesAutoCommit( providerDisablesAutoCommit ); delegate.applyConnectionProviderDisablesAutoCommit( providerDisablesAutoCommit );

View File

@ -25,6 +25,8 @@ public interface JpaCompliance {
* Deviations result in an exception if enabled * Deviations result in an exception if enabled
* *
* @return {@code true} indicates to behave in the spec-defined way * @return {@code true} indicates to behave in the spec-defined way
*
* @see org.hibernate.cfg.AvailableSettings#JPA_QUERY_COMPLIANCE
*/ */
boolean isJpaQueryComplianceEnabled(); boolean isJpaQueryComplianceEnabled();
@ -34,6 +36,8 @@ public interface JpaCompliance {
* since it extends the JPA one. * since it extends the JPA one.
* *
* @return {@code true} indicates to behave in the spec-defined way * @return {@code true} indicates to behave in the spec-defined way
*
* @see org.hibernate.cfg.AvailableSettings#JPA_TRANSACTION_COMPLIANCE
*/ */
boolean isJpaTransactionComplianceEnabled(); boolean isJpaTransactionComplianceEnabled();
@ -48,6 +52,8 @@ public interface JpaCompliance {
* *
* @return {@code true} indicates to behave in the spec-defined way, interpreting the * @return {@code true} indicates to behave in the spec-defined way, interpreting the
* mapping as a "list", rather than a "bag" * mapping as a "list", rather than a "bag"
*
* @see org.hibernate.cfg.AvailableSettings#JPA_LIST_COMPLIANCE
*/ */
boolean isJpaListComplianceEnabled(); boolean isJpaListComplianceEnabled();
@ -61,6 +67,8 @@ public interface JpaCompliance {
* exceptions when the spec says it should with regard to close checking * exceptions when the spec says it should with regard to close checking
* *
* @return {@code true} indicates to behave in the spec-defined way * @return {@code true} indicates to behave in the spec-defined way
*
* @see org.hibernate.cfg.AvailableSettings#JPA_CLOSED_COMPLIANCE
*/ */
boolean isJpaClosedComplianceEnabled(); boolean isJpaClosedComplianceEnabled();
@ -76,6 +84,8 @@ public interface JpaCompliance {
* If enabled Hibernate will initialize the entity Proxy even when accessing its identifier. * If enabled Hibernate will initialize the entity Proxy even when accessing its identifier.
* *
* @return {@code true} indicates to behave in the spec-defined way * @return {@code true} indicates to behave in the spec-defined way
*
* @see org.hibernate.cfg.AvailableSettings#JPA_PROXY_COMPLIANCE
*/ */
boolean isJpaProxyComplianceEnabled(); boolean isJpaProxyComplianceEnabled();
@ -88,6 +98,8 @@ public interface JpaCompliance {
* than updated. * than updated.
* *
* @return {@code true} says to act the spec-defined way. * @return {@code true} says to act the spec-defined way.
*
* @see org.hibernate.cfg.AvailableSettings#JPA_CACHING_COMPLIANCE
*/ */
boolean isJpaCacheComplianceEnabled(); boolean isJpaCacheComplianceEnabled();
@ -97,6 +109,8 @@ public interface JpaCompliance {
* defined? * defined?
* *
* @return {@code true} indicates the generator name scope is considered global. * @return {@code true} indicates the generator name scope is considered global.
*
* @see org.hibernate.cfg.AvailableSettings#JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE
*/ */
boolean isGlobalGeneratorScopeEnabled(); boolean isGlobalGeneratorScopeEnabled();
@ -106,6 +120,8 @@ public interface JpaCompliance {
* JPA says the order-items can only be attribute references whereas Hibernate supports a * JPA says the order-items can only be attribute references whereas Hibernate supports a
* wide range of items. With this enabled, Hibernate will throw a compliance error when a * wide range of items. With this enabled, Hibernate will throw a compliance error when a
* non-attribute-reference is used. * non-attribute-reference is used.
*
* @see org.hibernate.cfg.AvailableSettings#JPA_ORDER_BY_MAPPING_COMPLIANCE
*/ */
boolean isJpaOrderByMappingComplianceEnabled(); boolean isJpaOrderByMappingComplianceEnabled();
@ -121,6 +137,8 @@ public interface JpaCompliance {
* <p> * <p>
* This setting controls whether such a coercion should be allowed. * This setting controls whether such a coercion should be allowed.
* *
* @see org.hibernate.cfg.AvailableSettings#JPA_LOAD_BY_ID_COMPLIANCE
*
* @since 6.0 * @since 6.0
*/ */
boolean isLoadByIdComplianceEnabled(); boolean isLoadByIdComplianceEnabled();