miscellaneous code cleanups and refactoring
This commit is contained in:
parent
3521857ef2
commit
072d3e257b
|
@ -68,8 +68,6 @@ import org.hibernate.resource.jdbc.spi.StatementInspector;
|
||||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||||
import org.hibernate.stat.Statistics;
|
import org.hibernate.stat.Statistics;
|
||||||
import org.hibernate.type.format.FormatMapper;
|
import org.hibernate.type.format.FormatMapper;
|
||||||
import org.hibernate.type.format.jackson.JacksonIntegration;
|
|
||||||
import org.hibernate.type.format.jakartajson.JakartaJsonIntegration;
|
|
||||||
import org.hibernate.type.format.jaxb.JaxbXmlFormatMapper;
|
import org.hibernate.type.format.jaxb.JaxbXmlFormatMapper;
|
||||||
|
|
||||||
import jakarta.persistence.criteria.Nulls;
|
import jakarta.persistence.criteria.Nulls;
|
||||||
|
@ -142,6 +140,9 @@ import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
|
||||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getInt;
|
import static org.hibernate.internal.util.config.ConfigurationHelper.getInt;
|
||||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getInteger;
|
import static org.hibernate.internal.util.config.ConfigurationHelper.getInteger;
|
||||||
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
import static org.hibernate.internal.util.config.ConfigurationHelper.getString;
|
||||||
|
import static org.hibernate.type.format.jackson.JacksonIntegration.getJsonJacksonFormatMapperOrNull;
|
||||||
|
import static org.hibernate.type.format.jackson.JacksonIntegration.getXMLJacksonFormatMapperOrNull;
|
||||||
|
import static org.hibernate.type.format.jakartajson.JakartaJsonIntegration.getJakartaJsonBFormatMapperOrNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In-flight state of {@link SessionFactoryOptions} during {@link org.hibernate.boot.SessionFactoryBuilder}
|
* In-flight state of {@link SessionFactoryOptions} during {@link org.hibernate.boot.SessionFactoryBuilder}
|
||||||
|
@ -648,10 +649,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
|
|
||||||
private boolean disallowBatchUpdates(Dialect dialect, ExtractedDatabaseMetaData meta) {
|
private boolean disallowBatchUpdates(Dialect dialect, ExtractedDatabaseMetaData meta) {
|
||||||
final Boolean dialectAnswer = dialect.supportsBatchUpdates();
|
final Boolean dialectAnswer = dialect.supportsBatchUpdates();
|
||||||
if ( dialectAnswer != null ) {
|
return dialectAnswer != null ? !dialectAnswer : !meta.supportsBatchUpdates();
|
||||||
return !dialectAnswer;
|
|
||||||
}
|
|
||||||
return !meta.supportsBatchUpdates();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -759,7 +757,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
if ( isEmpty( producerName ) ) {
|
if ( isEmpty( producerName ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
//noinspection Convert2Lambda
|
//noinspection Convert2Lambda
|
||||||
return strategySelector.resolveDefaultableStrategy(
|
return strategySelector.resolveDefaultableStrategy(
|
||||||
HqlTranslator.class,
|
HqlTranslator.class,
|
||||||
|
@ -773,6 +771,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SqmTranslatorFactory resolveSqmTranslator(
|
private SqmTranslatorFactory resolveSqmTranslator(
|
||||||
String translatorImplFqn,
|
String translatorImplFqn,
|
||||||
|
@ -780,21 +779,20 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
if ( isEmpty( translatorImplFqn ) ) {
|
if ( isEmpty( translatorImplFqn ) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return strategySelector.resolveStrategy(
|
return strategySelector.resolveStrategy(
|
||||||
SqmTranslatorFactory.class,
|
SqmTranslatorFactory.class,
|
||||||
translatorImplFqn
|
translatorImplFqn
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Interceptor determineInterceptor(
|
private static Interceptor determineInterceptor(
|
||||||
Map<String,Object> configurationSettings,
|
Map<String,Object> configurationSettings,
|
||||||
StrategySelector strategySelector) {
|
StrategySelector strategySelector) {
|
||||||
Object setting = configurationSettings.get( INTERCEPTOR );
|
|
||||||
|
|
||||||
return strategySelector.resolveStrategy(
|
return strategySelector.resolveStrategy(
|
||||||
Interceptor.class,
|
Interceptor.class,
|
||||||
setting
|
configurationSettings.get( INTERCEPTOR )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,8 +809,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
return (Supplier<? extends Interceptor>) setting;
|
return (Supplier<? extends Interceptor>) setting;
|
||||||
}
|
}
|
||||||
else if ( setting instanceof Class ) {
|
else if ( setting instanceof Class ) {
|
||||||
Class<? extends Interceptor> clazz = (Class<? extends Interceptor>) setting;
|
return interceptorSupplier( (Class<? extends Interceptor>) setting );
|
||||||
return interceptorSupplier( clazz );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return interceptorSupplier(
|
return interceptorSupplier(
|
||||||
|
@ -839,15 +836,12 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
|
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
|
||||||
Map<String,Object> configurationSettings,
|
Map<String,Object> configurationSettings,
|
||||||
StandardServiceRegistry serviceRegistry) {
|
StandardServiceRegistry serviceRegistry) {
|
||||||
final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret(
|
final PhysicalConnectionHandlingMode specifiedHandlingMode =
|
||||||
configurationSettings.get( CONNECTION_HANDLING )
|
PhysicalConnectionHandlingMode.interpret( configurationSettings.get( CONNECTION_HANDLING ) );
|
||||||
);
|
return specifiedHandlingMode != null
|
||||||
|
? specifiedHandlingMode
|
||||||
if ( specifiedHandlingMode != null ) {
|
: serviceRegistry.requireService( TransactionCoordinatorBuilder.class )
|
||||||
return specifiedHandlingMode;
|
.getDefaultConnectionHandlingMode();
|
||||||
}
|
|
||||||
|
|
||||||
return serviceRegistry.requireService( TransactionCoordinatorBuilder.class ).getDefaultConnectionHandlingMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FormatMapper determineJsonFormatMapper(Object setting, StrategySelector strategySelector) {
|
private static FormatMapper determineJsonFormatMapper(Object setting, StrategySelector strategySelector) {
|
||||||
|
@ -855,13 +849,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
FormatMapper.class,
|
FormatMapper.class,
|
||||||
setting,
|
setting,
|
||||||
(Callable<FormatMapper>) () -> {
|
(Callable<FormatMapper>) () -> {
|
||||||
final FormatMapper jsonJacksonFormatMapper = JacksonIntegration.getJsonJacksonFormatMapperOrNull();
|
final FormatMapper jsonJacksonFormatMapper = getJsonJacksonFormatMapperOrNull();
|
||||||
if (jsonJacksonFormatMapper != null) {
|
return jsonJacksonFormatMapper != null ? jsonJacksonFormatMapper : getJakartaJsonBFormatMapperOrNull();
|
||||||
return jsonJacksonFormatMapper;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return JakartaJsonIntegration.getJakartaJsonBFormatMapperOrNull();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -871,11 +860,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
FormatMapper.class,
|
FormatMapper.class,
|
||||||
setting,
|
setting,
|
||||||
(Callable<FormatMapper>) () -> {
|
(Callable<FormatMapper>) () -> {
|
||||||
final FormatMapper jacksonFormatMapper = JacksonIntegration.getXMLJacksonFormatMapperOrNull();
|
final FormatMapper jacksonFormatMapper = getXMLJacksonFormatMapperOrNull();
|
||||||
if (jacksonFormatMapper != null) {
|
return jacksonFormatMapper != null ? jacksonFormatMapper : new JaxbXmlFormatMapper();
|
||||||
return jacksonFormatMapper;
|
|
||||||
}
|
|
||||||
return new JaxbXmlFormatMapper();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1393,7 +1379,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSessionFactoryObservers(SessionFactoryObserver... observers) {
|
public void addSessionFactoryObservers(SessionFactoryObserver... observers) {
|
||||||
Collections.addAll( this.sessionFactoryObserverList, observers );
|
Collections.addAll( sessionFactoryObserverList, observers );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyInterceptor(Interceptor interceptor) {
|
public void applyInterceptor(Interceptor interceptor) {
|
||||||
|
@ -1401,13 +1387,14 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyStatelessInterceptor(Class<? extends Interceptor> statelessInterceptorClass) {
|
public void applyStatelessInterceptor(Class<? extends Interceptor> statelessInterceptorClass) {
|
||||||
this.applyStatelessInterceptorSupplier(
|
applyStatelessInterceptorSupplier(
|
||||||
() -> {
|
() -> {
|
||||||
try {
|
try {
|
||||||
return statelessInterceptorClass.newInstance();
|
return statelessInterceptorClass.newInstance();
|
||||||
}
|
}
|
||||||
catch (InstantiationException | IllegalAccessException e) {
|
catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new HibernateException( String.format( "Could not supply stateless Interceptor of class %s", statelessInterceptorClass.getName()), e );
|
throw new HibernateException( "Could not supply stateless Interceptor of class '"
|
||||||
|
+ statelessInterceptorClass.getName() + "'", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1563,10 +1550,10 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applySqlFunction(String registrationName, SqmFunctionDescriptor sqlFunction) {
|
public void applySqlFunction(String registrationName, SqmFunctionDescriptor sqlFunction) {
|
||||||
if ( this.sqlFunctions == null ) {
|
if ( sqlFunctions == null ) {
|
||||||
this.sqlFunctions = new HashMap<>();
|
sqlFunctions = new HashMap<>();
|
||||||
}
|
}
|
||||||
this.sqlFunctions.put( registrationName, sqlFunction );
|
sqlFunctions.put( registrationName, sqlFunction );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void allowOutOfTransactionUpdateOperations(boolean allow) {
|
public void allowOutOfTransactionUpdateOperations(boolean allow) {
|
||||||
|
@ -1582,11 +1569,12 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableJpaCompliance mutableJpaCompliance() {
|
private MutableJpaCompliance mutableJpaCompliance() {
|
||||||
if ( !(this.jpaCompliance instanceof MutableJpaCompliance) ) {
|
if ( jpaCompliance instanceof MutableJpaCompliance mutableJpaCompliance ) {
|
||||||
|
return mutableJpaCompliance;
|
||||||
|
}
|
||||||
|
else {
|
||||||
throw new IllegalStateException( "JpaCompliance is no longer mutable" );
|
throw new IllegalStateException( "JpaCompliance is no longer mutable" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return (MutableJpaCompliance) this.jpaCompliance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableJpaTransactionCompliance(boolean enabled) {
|
public void enableJpaTransactionCompliance(boolean enabled) {
|
||||||
|
@ -1627,10 +1615,9 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionFactoryOptions buildOptions() {
|
public SessionFactoryOptions buildOptions() {
|
||||||
if ( this.jpaCompliance instanceof MutableJpaCompliance ) {
|
if ( jpaCompliance instanceof MutableJpaCompliance ) {
|
||||||
this.jpaCompliance = mutableJpaCompliance().immutableCopy();
|
jpaCompliance = mutableJpaCompliance().immutableCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,27 +81,13 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
||||||
|
|
||||||
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );
|
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );
|
||||||
|
|
||||||
final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
|
final IdentifierHelperBuilder identifierHelperBuilder =
|
||||||
identifierHelperBuilder.setGloballyQuoteIdentifiers( globalQuoting( cfgService ) );
|
identifierHelperBuilder( cfgService, nameQualifierSupport );
|
||||||
identifierHelperBuilder.setSkipGlobalQuotingForColumnDefinitions( globalQuotingSkippedForColumnDefinitions(
|
|
||||||
cfgService ) );
|
|
||||||
identifierHelperBuilder.setAutoQuoteKeywords( autoKeywordQuoting( cfgService ) );
|
|
||||||
identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
|
|
||||||
|
|
||||||
IdentifierHelper identifierHelper = null;
|
final ExtractedDatabaseMetaDataImpl.Builder dbMetaDataBuilder =
|
||||||
ExtractedDatabaseMetaDataImpl.Builder dbMetaDataBuilder = new ExtractedDatabaseMetaDataImpl.Builder( this, false, null );
|
new ExtractedDatabaseMetaDataImpl.Builder( this, false, null );
|
||||||
try {
|
|
||||||
identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, null );
|
this.identifierHelper = identifierHelper( dialect, identifierHelperBuilder, dbMetaDataBuilder );;
|
||||||
dbMetaDataBuilder.setSupportsNamedParameters( dialect.supportsNamedParameters( null ) );
|
|
||||||
}
|
|
||||||
catch (SQLException sqle) {
|
|
||||||
// should never ever happen
|
|
||||||
log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
|
|
||||||
}
|
|
||||||
if ( identifierHelper == null ) {
|
|
||||||
identifierHelper = identifierHelperBuilder.build();
|
|
||||||
}
|
|
||||||
this.identifierHelper = identifierHelper;
|
|
||||||
|
|
||||||
this.extractedMetaDataSupport = dbMetaDataBuilder.build();
|
this.extractedMetaDataSupport = dbMetaDataBuilder.build();
|
||||||
|
|
||||||
|
@ -117,12 +103,39 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
||||||
this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
|
this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SqlAstTranslatorFactory resolveSqlAstTranslatorFactory(Dialect dialect) {
|
private IdentifierHelperBuilder identifierHelperBuilder(
|
||||||
if ( dialect.getSqlAstTranslatorFactory() != null ) {
|
ConfigurationService cfgService, NameQualifierSupport nameQualifierSupport) {
|
||||||
return dialect.getSqlAstTranslatorFactory();
|
final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
|
||||||
|
identifierHelperBuilder.setGloballyQuoteIdentifiers( globalQuoting( cfgService ) );
|
||||||
|
identifierHelperBuilder.setSkipGlobalQuotingForColumnDefinitions( globalQuotingSkippedForColumnDefinitions(
|
||||||
|
cfgService ) );
|
||||||
|
identifierHelperBuilder.setAutoQuoteKeywords( autoKeywordQuoting( cfgService ) );
|
||||||
|
identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
|
||||||
|
return identifierHelperBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StandardSqlAstTranslatorFactory();
|
private static IdentifierHelper identifierHelper(
|
||||||
|
Dialect dialect,
|
||||||
|
IdentifierHelperBuilder identifierHelperBuilder,
|
||||||
|
ExtractedDatabaseMetaDataImpl.Builder dbMetaDataBuilder) {
|
||||||
|
try {
|
||||||
|
final IdentifierHelper identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, null );
|
||||||
|
dbMetaDataBuilder.setSupportsNamedParameters( dialect.supportsNamedParameters( null ) );
|
||||||
|
if ( identifierHelper != null ) {
|
||||||
|
return identifierHelper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException sqle) {
|
||||||
|
// should never ever happen
|
||||||
|
log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
|
||||||
|
}
|
||||||
|
return identifierHelperBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SqlAstTranslatorFactory resolveSqlAstTranslatorFactory(Dialect dialect) {
|
||||||
|
return dialect.getSqlAstTranslatorFactory() != null
|
||||||
|
? dialect.getSqlAstTranslatorFactory()
|
||||||
|
: new StandardSqlAstTranslatorFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean logWarnings(ConfigurationService cfgService, Dialect dialect) {
|
private static boolean logWarnings(ConfigurationService cfgService, Dialect dialect) {
|
||||||
|
@ -170,28 +183,12 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
||||||
|
|
||||||
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, false );
|
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, false );
|
||||||
|
|
||||||
NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
|
this.nameQualifierSupport = nameQualifierSupport( databaseMetaData, dialect );
|
||||||
if ( nameQualifierSupport == null ) {
|
|
||||||
nameQualifierSupport = determineNameQualifierSupport( databaseMetaData );
|
|
||||||
}
|
|
||||||
this.nameQualifierSupport = nameQualifierSupport;
|
|
||||||
|
|
||||||
final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
|
this.identifierHelper = identifierHelper( databaseMetaData, dialect );
|
||||||
identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
|
|
||||||
IdentifierHelper identifierHelper = null;
|
|
||||||
try {
|
|
||||||
identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, databaseMetaData );
|
|
||||||
}
|
|
||||||
catch (SQLException sqle) {
|
|
||||||
// should never ever happen
|
|
||||||
log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
|
|
||||||
}
|
|
||||||
if ( identifierHelper == null ) {
|
|
||||||
identifierHelper = identifierHelperBuilder.build();
|
|
||||||
}
|
|
||||||
this.identifierHelper = identifierHelper;
|
|
||||||
|
|
||||||
this.extractedMetaDataSupport = new ExtractedDatabaseMetaDataImpl.Builder( this, true, jdbcConnectionAccess )
|
this.extractedMetaDataSupport =
|
||||||
|
new ExtractedDatabaseMetaDataImpl.Builder( this, true, jdbcConnectionAccess )
|
||||||
.apply( databaseMetaData )
|
.apply( databaseMetaData )
|
||||||
.setSupportsNamedParameters( databaseMetaData.supportsNamedParameters() )
|
.setSupportsNamedParameters( databaseMetaData.supportsNamedParameters() )
|
||||||
.build();
|
.build();
|
||||||
|
@ -207,6 +204,29 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
||||||
this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
|
this.lobCreatorBuilder = LobCreatorBuilderImpl.makeLobCreatorBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IdentifierHelper identifierHelper(DatabaseMetaData databaseMetaData, Dialect dialect) {
|
||||||
|
final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
|
||||||
|
identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
|
||||||
|
try {
|
||||||
|
final IdentifierHelper identifierHelper =
|
||||||
|
dialect.buildIdentifierHelper( identifierHelperBuilder, databaseMetaData );
|
||||||
|
if ( identifierHelper != null ) {
|
||||||
|
return identifierHelper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException sqle) {
|
||||||
|
// should never ever happen
|
||||||
|
log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
|
||||||
|
}
|
||||||
|
return identifierHelperBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private NameQualifierSupport nameQualifierSupport(DatabaseMetaData databaseMetaData, Dialect dialect)
|
||||||
|
throws SQLException {
|
||||||
|
final NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
|
||||||
|
return nameQualifierSupport == null ? determineNameQualifierSupport( databaseMetaData ) : nameQualifierSupport;
|
||||||
|
}
|
||||||
|
|
||||||
private NameQualifierSupport determineNameQualifierSupport(DatabaseMetaData databaseMetaData) throws SQLException {
|
private NameQualifierSupport determineNameQualifierSupport(DatabaseMetaData databaseMetaData) throws SQLException {
|
||||||
final boolean supportsCatalogs = databaseMetaData.supportsCatalogsInTableDefinitions();
|
final boolean supportsCatalogs = databaseMetaData.supportsCatalogsInTableDefinitions();
|
||||||
final boolean supportsSchemas = databaseMetaData.supportsSchemasInTableDefinitions();
|
final boolean supportsSchemas = databaseMetaData.supportsSchemasInTableDefinitions();
|
||||||
|
@ -261,32 +281,16 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
||||||
|
|
||||||
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );
|
this.sqlExceptionHelper = buildSqlExceptionHelper( dialect, logWarnings( cfgService, dialect ) );
|
||||||
|
|
||||||
NameQualifierSupport nameQualifierSupport = dialect.getNameQualifierSupport();
|
NameQualifierSupport nameQualifierSupport = nameQualifierSupport( databaseMetaData,
|
||||||
if ( nameQualifierSupport == null ) {
|
dialect );
|
||||||
nameQualifierSupport = determineNameQualifierSupport( databaseMetaData );
|
|
||||||
}
|
|
||||||
this.nameQualifierSupport = nameQualifierSupport;
|
this.nameQualifierSupport = nameQualifierSupport;
|
||||||
|
|
||||||
final IdentifierHelperBuilder identifierHelperBuilder = IdentifierHelperBuilder.from( this );
|
final IdentifierHelperBuilder identifierHelperBuilder =
|
||||||
identifierHelperBuilder.setGloballyQuoteIdentifiers( globalQuoting( cfgService ) );
|
identifierHelperBuilder( cfgService, nameQualifierSupport );
|
||||||
identifierHelperBuilder.setSkipGlobalQuotingForColumnDefinitions( globalQuotingSkippedForColumnDefinitions(
|
this.identifierHelper = identifierHelper( dialect, databaseMetaData, identifierHelperBuilder );
|
||||||
cfgService ) );
|
|
||||||
identifierHelperBuilder.setAutoQuoteKeywords( autoKeywordQuoting( cfgService ) );
|
|
||||||
identifierHelperBuilder.setNameQualifierSupport( nameQualifierSupport );
|
|
||||||
IdentifierHelper identifierHelper = null;
|
|
||||||
try {
|
|
||||||
identifierHelper = dialect.buildIdentifierHelper( identifierHelperBuilder, databaseMetaData );
|
|
||||||
}
|
|
||||||
catch (SQLException sqle) {
|
|
||||||
// should never ever happen
|
|
||||||
log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
|
|
||||||
}
|
|
||||||
if ( identifierHelper == null ) {
|
|
||||||
identifierHelper = identifierHelperBuilder.build();
|
|
||||||
}
|
|
||||||
this.identifierHelper = identifierHelper;
|
|
||||||
|
|
||||||
this.extractedMetaDataSupport = new ExtractedDatabaseMetaDataImpl.Builder( this, true, jdbcConnectionAccess )
|
this.extractedMetaDataSupport =
|
||||||
|
new ExtractedDatabaseMetaDataImpl.Builder( this, true, jdbcConnectionAccess )
|
||||||
.apply( databaseMetaData )
|
.apply( databaseMetaData )
|
||||||
.setConnectionSchemaName( determineCurrentSchemaName( databaseMetaData, serviceRegistry, dialect ) )
|
.setConnectionSchemaName( determineCurrentSchemaName( databaseMetaData, serviceRegistry, dialect ) )
|
||||||
.setSupportsNamedParameters( dialect.supportsNamedParameters( databaseMetaData ) )
|
.setSupportsNamedParameters( dialect.supportsNamedParameters( databaseMetaData ) )
|
||||||
|
@ -308,21 +312,39 @@ public class JdbcEnvironmentImpl implements JdbcEnvironment {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IdentifierHelper identifierHelper(
|
||||||
|
Dialect dialect, DatabaseMetaData databaseMetaData, IdentifierHelperBuilder identifierHelperBuilder) {
|
||||||
|
try {
|
||||||
|
final IdentifierHelper identifierHelper =
|
||||||
|
dialect.buildIdentifierHelper( identifierHelperBuilder, databaseMetaData );
|
||||||
|
if ( identifierHelper != null ) {
|
||||||
|
return identifierHelper;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException sqle) {
|
||||||
|
// should never ever happen
|
||||||
|
log.debug( "There was a problem accessing DatabaseMetaData in building the JdbcEnvironment", sqle );
|
||||||
|
}
|
||||||
|
return identifierHelperBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
public static final String SCHEMA_NAME_RESOLVER = "hibernate.schema_name_resolver";
|
public static final String SCHEMA_NAME_RESOLVER = "hibernate.schema_name_resolver";
|
||||||
|
|
||||||
private String determineCurrentSchemaName(
|
private String determineCurrentSchemaName(
|
||||||
DatabaseMetaData databaseMetaData,
|
DatabaseMetaData databaseMetaData,
|
||||||
ServiceRegistry serviceRegistry,
|
ServiceRegistry serviceRegistry,
|
||||||
Dialect dialect) {
|
Dialect dialect) {
|
||||||
|
final Object setting =
|
||||||
|
serviceRegistry.requireService( ConfigurationService.class )
|
||||||
|
.getSettings().get( SCHEMA_NAME_RESOLVER );
|
||||||
final SchemaNameResolver schemaNameResolver;
|
final SchemaNameResolver schemaNameResolver;
|
||||||
|
|
||||||
final Object setting = serviceRegistry.requireService( ConfigurationService.class ).getSettings().get(
|
|
||||||
SCHEMA_NAME_RESOLVER );
|
|
||||||
if ( setting == null ) {
|
if ( setting == null ) {
|
||||||
schemaNameResolver = dialect.getSchemaNameResolver();
|
schemaNameResolver = dialect.getSchemaNameResolver();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
schemaNameResolver = serviceRegistry.requireService( StrategySelector.class ).resolveDefaultableStrategy(
|
schemaNameResolver =
|
||||||
|
serviceRegistry.requireService( StrategySelector.class )
|
||||||
|
.resolveDefaultableStrategy(
|
||||||
SchemaNameResolver.class,
|
SchemaNameResolver.class,
|
||||||
setting,
|
setting,
|
||||||
dialect.getSchemaNameResolver()
|
dialect.getSchemaNameResolver()
|
||||||
|
|
|
@ -43,7 +43,6 @@ import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||||
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
import org.hibernate.metamodel.model.domain.SingularPersistentAttribute;
|
||||||
import org.hibernate.metamodel.model.domain.internal.EntitySqmPathSource;
|
import org.hibernate.metamodel.model.domain.internal.EntitySqmPathSource;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.query.BindableType;
|
|
||||||
import org.hibernate.query.IllegalQueryOperationException;
|
import org.hibernate.query.IllegalQueryOperationException;
|
||||||
import org.hibernate.query.IllegalSelectQueryException;
|
import org.hibernate.query.IllegalSelectQueryException;
|
||||||
import org.hibernate.query.Order;
|
import org.hibernate.query.Order;
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
*
|
* Copyright Red Hat Inc. and Hibernate Authors
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
|
||||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
|
||||||
*/
|
*/
|
||||||
package org.hibernate.engine.internal;
|
package org.hibernate.engine.internal;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
|
Loading…
Reference in New Issue