split out SessionFactorySettings and kill off MappingMetamodelImpl.close()
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
4781c09d0d
commit
eacbd78956
|
@ -41,7 +41,6 @@ import org.hibernate.StatelessSession;
|
||||||
import org.hibernate.StatelessSessionBuilder;
|
import org.hibernate.StatelessSessionBuilder;
|
||||||
import org.hibernate.UnknownFilterException;
|
import org.hibernate.UnknownFilterException;
|
||||||
import org.hibernate.binder.internal.TenantIdBinder;
|
import org.hibernate.binder.internal.TenantIdBinder;
|
||||||
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
|
@ -52,15 +51,12 @@ import org.hibernate.cache.cfg.internal.DomainDataRegionConfigImpl;
|
||||||
import org.hibernate.cache.cfg.spi.DomainDataRegionConfig;
|
import org.hibernate.cache.cfg.spi.DomainDataRegionConfig;
|
||||||
import org.hibernate.cache.spi.CacheImplementor;
|
import org.hibernate.cache.spi.CacheImplementor;
|
||||||
import org.hibernate.cache.spi.access.AccessType;
|
import org.hibernate.cache.spi.access.AccessType;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.cfg.PersistenceSettings;
|
|
||||||
import org.hibernate.context.internal.JTASessionContext;
|
import org.hibernate.context.internal.JTASessionContext;
|
||||||
import org.hibernate.context.internal.ManagedSessionContext;
|
import org.hibernate.context.internal.ManagedSessionContext;
|
||||||
import org.hibernate.context.internal.ThreadLocalSessionContext;
|
import org.hibernate.context.internal.ThreadLocalSessionContext;
|
||||||
import org.hibernate.context.spi.CurrentSessionContext;
|
import org.hibernate.context.spi.CurrentSessionContext;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||||
import org.hibernate.engine.profile.FetchProfile;
|
import org.hibernate.engine.profile.FetchProfile;
|
||||||
|
@ -103,9 +99,6 @@ import org.hibernate.query.spi.QueryImplementor;
|
||||||
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
||||||
import org.hibernate.query.sqm.NodeBuilder;
|
import org.hibernate.query.sqm.NodeBuilder;
|
||||||
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
||||||
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableStrategy;
|
|
||||||
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableStrategy;
|
|
||||||
import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableStrategy;
|
|
||||||
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
|
import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
|
||||||
import org.hibernate.relational.SchemaManager;
|
import org.hibernate.relational.SchemaManager;
|
||||||
import org.hibernate.relational.internal.SchemaManagerImpl;
|
import org.hibernate.relational.internal.SchemaManagerImpl;
|
||||||
|
@ -138,14 +131,12 @@ import static jakarta.persistence.SynchronizationType.SYNCHRONIZED;
|
||||||
import static java.util.Collections.emptySet;
|
import static java.util.Collections.emptySet;
|
||||||
import static java.util.Collections.unmodifiableSet;
|
import static java.util.Collections.unmodifiableSet;
|
||||||
import static org.hibernate.cfg.AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS;
|
import static org.hibernate.cfg.AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS;
|
||||||
import static org.hibernate.cfg.AvailableSettings.JAKARTA_VALIDATION_FACTORY;
|
|
||||||
import static org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY;
|
|
||||||
import static org.hibernate.cfg.PersistenceSettings.PERSISTENCE_UNIT_NAME;
|
|
||||||
import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_JNDI_NAME;
|
|
||||||
import static org.hibernate.engine.config.spi.StandardConverters.STRING;
|
|
||||||
import static org.hibernate.internal.FetchProfileHelper.getFetchProfiles;
|
import static org.hibernate.internal.FetchProfileHelper.getFetchProfiles;
|
||||||
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
|
import static org.hibernate.internal.SessionFactorySettings.deprecationCheck;
|
||||||
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
import static org.hibernate.internal.SessionFactorySettings.determineJndiName;
|
||||||
|
import static org.hibernate.internal.SessionFactorySettings.getSessionFactoryName;
|
||||||
|
import static org.hibernate.internal.SessionFactorySettings.getSettings;
|
||||||
|
import static org.hibernate.internal.SessionFactorySettings.maskOutSensitiveInformation;
|
||||||
import static org.hibernate.jpa.HibernateHints.HINT_TENANT_ID;
|
import static org.hibernate.jpa.HibernateHints.HINT_TENANT_ID;
|
||||||
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
|
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
|
||||||
import static org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
|
import static org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
|
||||||
|
@ -262,8 +253,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
tenantIdentifierJavaType = jdbcMapping.getJavaTypeDescriptor();
|
tenantIdentifierJavaType = jdbcMapping.getJavaTypeDescriptor();
|
||||||
}
|
}
|
||||||
for (Map.Entry<String, FilterDefinition> filterEntry : filters.entrySet()) {
|
for ( Map.Entry<String, FilterDefinition> filterEntry : filters.entrySet() ) {
|
||||||
if (filterEntry.getValue().isAutoEnabled()) {
|
if ( filterEntry.getValue().isAutoEnabled() ) {
|
||||||
autoEnabledFilters.add( filterEntry.getValue() );
|
autoEnabledFilters.add( filterEntry.getValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -295,7 +286,8 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
// create runtime metamodels (mapping and JPA)
|
// create runtime metamodels (mapping and JPA)
|
||||||
final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl();
|
final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl();
|
||||||
runtimeMetamodels = runtimeMetamodelsImpl;
|
runtimeMetamodels = runtimeMetamodelsImpl;
|
||||||
final MappingMetamodelImpl mappingMetamodelImpl = new MappingMetamodelImpl( typeConfiguration, serviceRegistry );
|
final MappingMetamodelImpl mappingMetamodelImpl =
|
||||||
|
new MappingMetamodelImpl( typeConfiguration, serviceRegistry );
|
||||||
runtimeMetamodelsImpl.setMappingMetamodel( mappingMetamodelImpl );
|
runtimeMetamodelsImpl.setMappingMetamodel( mappingMetamodelImpl );
|
||||||
fastSessionServices = new FastSessionServices( this );
|
fastSessionServices = new FastSessionServices( this );
|
||||||
initializeMappingModel( mappingMetamodelImpl, bootstrapContext, bootMetamodel, options );
|
initializeMappingModel( mappingMetamodelImpl, bootstrapContext, bootMetamodel, options );
|
||||||
|
@ -337,38 +329,16 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
LOG.debug( "Instantiated SessionFactory" );
|
LOG.debug( "Instantiated SessionFactory" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void deprecationCheck(Map<String, Object> settings) {
|
|
||||||
for ( String s:settings.keySet() ) {
|
|
||||||
switch (s) {
|
|
||||||
case "hibernate.hql.bulk_id_strategy.global_temporary.create_tables":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.global_temporary.create_tables", GlobalTemporaryTableStrategy.CREATE_ID_TABLES );
|
|
||||||
case "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables", GlobalTemporaryTableStrategy.DROP_ID_TABLES );
|
|
||||||
case "hibernate.hql.bulk_id_strategy.persistent.create_tables":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.create_tables", PersistentTableStrategy.CREATE_ID_TABLES );
|
|
||||||
case "hibernate.hql.bulk_id_strategy.persistent.drop_tables":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.drop_tables", PersistentTableStrategy.DROP_ID_TABLES );
|
|
||||||
case "hibernate.hql.bulk_id_strategy.persistent.schema":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.schema", PersistentTableStrategy.SCHEMA );
|
|
||||||
case "hibernate.hql.bulk_id_strategy.persistent.catalog":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.catalog", PersistentTableStrategy.CATALOG );
|
|
||||||
case "hibernate.hql.bulk_id_strategy.local_temporary.drop_tables":
|
|
||||||
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.local_temporary.drop_tables", LocalTemporaryTableStrategy.DROP_ID_TABLES );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeMappingModel(
|
private void initializeMappingModel(
|
||||||
MappingMetamodelImpl mappingMetamodelImpl,
|
MappingMetamodelImpl mappingMetamodelImpl,
|
||||||
BootstrapContext bootstrapContext,
|
BootstrapContext bootstrapContext,
|
||||||
MetadataImplementor bootMetamodel,
|
MetadataImplementor bootMetamodel,
|
||||||
SessionFactoryOptions options) {
|
SessionFactoryOptions options) {
|
||||||
final TypeConfiguration typeConfiguration = mappingMetamodelImpl.getTypeConfiguration();
|
|
||||||
mappingMetamodelImpl.finishInitialization( runtimeModelCreationContext(
|
mappingMetamodelImpl.finishInitialization( runtimeModelCreationContext(
|
||||||
bootstrapContext,
|
bootstrapContext,
|
||||||
bootMetamodel,
|
bootMetamodel,
|
||||||
mappingMetamodelImpl,
|
mappingMetamodelImpl,
|
||||||
typeConfiguration,
|
mappingMetamodelImpl.getTypeConfiguration(),
|
||||||
options
|
options
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
@ -528,58 +498,6 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Map<String, Object> getSettings(SessionFactoryOptions options, SessionFactoryServiceRegistry serviceRegistry) {
|
|
||||||
final Map<String, Object> settings = serviceRegistry.requireService( ConfigurationService.class ).getSettings();
|
|
||||||
final Map<String,Object> result = new HashMap<>( settings );
|
|
||||||
if ( !settings.containsKey( JPA_VALIDATION_FACTORY ) && !settings.containsKey( JAKARTA_VALIDATION_FACTORY ) ) {
|
|
||||||
final Object reference = options.getValidatorFactoryReference();
|
|
||||||
if ( reference != null ) {
|
|
||||||
result.put( JPA_VALIDATION_FACTORY, reference );
|
|
||||||
result.put( JAKARTA_VALIDATION_FACTORY, reference );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getSessionFactoryName(SessionFactoryOptions options, SessionFactoryServiceRegistry serviceRegistry) {
|
|
||||||
final String sessionFactoryName = options.getSessionFactoryName();
|
|
||||||
if ( sessionFactoryName != null ) {
|
|
||||||
return sessionFactoryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
final CfgXmlAccessService cfgXmlAccessService = serviceRegistry.requireService( CfgXmlAccessService.class );
|
|
||||||
if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
|
|
||||||
final String nameFromAggregation = cfgXmlAccessService.getAggregatedConfig().getSessionFactoryName();
|
|
||||||
if ( nameFromAggregation != null ) {
|
|
||||||
return nameFromAggregation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
|
|
||||||
assert configurationService != null;
|
|
||||||
return configurationService.getSetting( PersistenceSettings.PERSISTENCE_UNIT_NAME, STRING );
|
|
||||||
}
|
|
||||||
|
|
||||||
private String determineJndiName(
|
|
||||||
String name,
|
|
||||||
SessionFactoryOptions options,
|
|
||||||
SessionFactoryServiceRegistry serviceRegistry) {
|
|
||||||
final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );
|
|
||||||
assert cfgService != null;
|
|
||||||
final String explicitJndiName = cfgService.getSetting( SESSION_FACTORY_JNDI_NAME, STRING );
|
|
||||||
if ( isNotEmpty( explicitJndiName ) ) {
|
|
||||||
return explicitJndiName;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String puName = cfgService.getSetting( PERSISTENCE_UNIT_NAME, STRING );
|
|
||||||
// do not use name for JNDI if explicitly asked not to or if name comes from JPA persistence-unit name
|
|
||||||
final boolean nameIsNotJndiName =
|
|
||||||
options.isSessionFactoryNameAlsoJndiName() == Boolean.FALSE
|
|
||||||
|| isNotEmpty( puName );
|
|
||||||
return !nameIsNotJndiName ? name : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SessionBuilderImpl createDefaultSessionOpenOptionsIfPossible() {
|
private SessionBuilderImpl createDefaultSessionOpenOptionsIfPossible() {
|
||||||
final CurrentTenantIdentifierResolver<Object> tenantIdResolver = getCurrentTenantIdentifierResolver();
|
final CurrentTenantIdentifierResolver<Object> tenantIdResolver = getCurrentTenantIdentifierResolver();
|
||||||
if ( tenantIdResolver == null ) {
|
if ( tenantIdResolver == null ) {
|
||||||
|
@ -888,7 +806,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
LOG.debug( "Returning a Reference to the SessionFactory" );
|
LOG.debug( "Returning a Reference to the SessionFactory" );
|
||||||
return new Reference(
|
return new Reference(
|
||||||
SessionFactoryImpl.class.getName(),
|
SessionFactoryImpl.class.getName(),
|
||||||
new StringRefAddr("uuid", getUuid()),
|
new StringRefAddr( "uuid", getUuid() ),
|
||||||
SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
|
SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
@ -954,20 +872,16 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
runtimeMetamodels.getMappingMetamodel().forEachEntityDescriptor(
|
runtimeMetamodels.getMappingMetamodel().forEachEntityDescriptor(
|
||||||
entityPersister -> {
|
entityPersister -> {
|
||||||
if ( entityPersister.getSqmMultiTableMutationStrategy() != null ) {
|
if ( entityPersister.getSqmMultiTableMutationStrategy() != null ) {
|
||||||
entityPersister.getSqmMultiTableMutationStrategy().release(
|
entityPersister.getSqmMultiTableMutationStrategy()
|
||||||
this,
|
.release( this, jdbcConnectionAccess );
|
||||||
jdbcConnectionAccess
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if ( entityPersister.getSqmMultiTableInsertStrategy() != null ) {
|
if ( entityPersister.getSqmMultiTableInsertStrategy() != null ) {
|
||||||
entityPersister.getSqmMultiTableInsertStrategy().release(
|
entityPersister.getSqmMultiTableInsertStrategy()
|
||||||
this,
|
.release( this, jdbcConnectionAccess );
|
||||||
jdbcConnectionAccess
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
( (MappingMetamodelImpl) runtimeMetamodels.getMappingMetamodel() ).close();
|
// ( (MappingMetamodelImpl) runtimeMetamodels.getMappingMetamodel() ).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( queryEngine != null ) {
|
if ( queryEngine != null ) {
|
||||||
|
@ -1324,18 +1238,18 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
|
|
||||||
// set up default builder values...
|
// set up default builder values...
|
||||||
final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
|
final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
|
||||||
this.statementInspector = sessionFactoryOptions.getStatementInspector();
|
statementInspector = sessionFactoryOptions.getStatementInspector();
|
||||||
this.connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode();
|
connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode();
|
||||||
this.autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled();
|
autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled();
|
||||||
this.defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize();
|
defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize();
|
||||||
this.subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled();
|
subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled();
|
||||||
|
|
||||||
final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver =
|
final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver =
|
||||||
sessionFactory.getCurrentTenantIdentifierResolver();
|
sessionFactory.getCurrentTenantIdentifierResolver();
|
||||||
if ( currentTenantIdentifierResolver != null ) {
|
if ( currentTenantIdentifierResolver != null ) {
|
||||||
tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
|
tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
|
||||||
}
|
}
|
||||||
this.jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone();
|
jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1772,21 +1686,6 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
|
||||||
return (SessionFactoryImpl) locateSessionFactoryOnDeserialization( uuid, name );
|
return (SessionFactoryImpl) locateSessionFactoryOnDeserialization( uuid, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void maskOutSensitiveInformation(Map<String, Object> props) {
|
|
||||||
maskOutIfSet( props, AvailableSettings.JPA_JDBC_USER );
|
|
||||||
maskOutIfSet( props, AvailableSettings.JPA_JDBC_PASSWORD );
|
|
||||||
maskOutIfSet( props, AvailableSettings.JAKARTA_JDBC_USER );
|
|
||||||
maskOutIfSet( props, AvailableSettings.JAKARTA_JDBC_PASSWORD );
|
|
||||||
maskOutIfSet( props, AvailableSettings.USER );
|
|
||||||
maskOutIfSet( props, AvailableSettings.PASS );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void maskOutIfSet(Map<String, Object> props, String setting) {
|
|
||||||
if ( props.containsKey( setting ) ) {
|
|
||||||
props.put( setting, "****" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the {@link FastSessionServices} for this {@code SessionFactory}.
|
* @return the {@link FastSessionServices} for this {@code SessionFactory}.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.internal;
|
||||||
|
|
||||||
|
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
||||||
|
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
|
||||||
|
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||||
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableStrategy;
|
||||||
|
import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableStrategy;
|
||||||
|
import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableStrategy;
|
||||||
|
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.hibernate.cfg.PersistenceSettings.PERSISTENCE_UNIT_NAME;
|
||||||
|
import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_JNDI_NAME;
|
||||||
|
import static org.hibernate.cfg.ValidationSettings.JAKARTA_VALIDATION_FACTORY;
|
||||||
|
import static org.hibernate.cfg.ValidationSettings.JPA_VALIDATION_FACTORY;
|
||||||
|
import static org.hibernate.engine.config.spi.StandardConverters.STRING;
|
||||||
|
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
|
||||||
|
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper methods used to set up a {@link SessionFactoryImpl}.
|
||||||
|
*/
|
||||||
|
class SessionFactorySettings {
|
||||||
|
|
||||||
|
static Map<String, Object> getSettings(
|
||||||
|
SessionFactoryOptions options, SessionFactoryServiceRegistry serviceRegistry) {
|
||||||
|
final Map<String, Object> settings =
|
||||||
|
serviceRegistry.requireService( ConfigurationService.class )
|
||||||
|
.getSettings();
|
||||||
|
final Map<String,Object> result = new HashMap<>( settings );
|
||||||
|
if ( !settings.containsKey( JPA_VALIDATION_FACTORY )
|
||||||
|
&& !settings.containsKey( JAKARTA_VALIDATION_FACTORY ) ) {
|
||||||
|
final Object reference = options.getValidatorFactoryReference();
|
||||||
|
if ( reference != null ) {
|
||||||
|
result.put( JPA_VALIDATION_FACTORY, reference );
|
||||||
|
result.put( JAKARTA_VALIDATION_FACTORY, reference );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getSessionFactoryName(
|
||||||
|
SessionFactoryOptions options, SessionFactoryServiceRegistry serviceRegistry) {
|
||||||
|
final String sessionFactoryName = options.getSessionFactoryName();
|
||||||
|
if ( sessionFactoryName != null ) {
|
||||||
|
return sessionFactoryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
final LoadedConfig loadedConfig =
|
||||||
|
serviceRegistry.requireService( CfgXmlAccessService.class )
|
||||||
|
.getAggregatedConfig();
|
||||||
|
if ( loadedConfig != null ) {
|
||||||
|
final String nameFromAggregation = loadedConfig.getSessionFactoryName();
|
||||||
|
if ( nameFromAggregation != null ) {
|
||||||
|
return nameFromAggregation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final ConfigurationService configurationService =
|
||||||
|
serviceRegistry.requireService( ConfigurationService.class );
|
||||||
|
return configurationService.getSetting( PERSISTENCE_UNIT_NAME, STRING );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void maskOutSensitiveInformation(Map<String, Object> props) {
|
||||||
|
maskOutIfSet( props, AvailableSettings.JPA_JDBC_USER );
|
||||||
|
maskOutIfSet( props, AvailableSettings.JPA_JDBC_PASSWORD );
|
||||||
|
maskOutIfSet( props, AvailableSettings.JAKARTA_JDBC_USER );
|
||||||
|
maskOutIfSet( props, AvailableSettings.JAKARTA_JDBC_PASSWORD );
|
||||||
|
maskOutIfSet( props, AvailableSettings.USER );
|
||||||
|
maskOutIfSet( props, AvailableSettings.PASS );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void maskOutIfSet(Map<String, Object> props, String setting) {
|
||||||
|
if ( props.containsKey( setting ) ) {
|
||||||
|
props.put( setting, "****" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static String determineJndiName(
|
||||||
|
String name,
|
||||||
|
SessionFactoryOptions options,
|
||||||
|
SessionFactoryServiceRegistry serviceRegistry) {
|
||||||
|
final ConfigurationService configService =
|
||||||
|
serviceRegistry.requireService( ConfigurationService.class );
|
||||||
|
final String explicitJndiName = configService.getSetting( SESSION_FACTORY_JNDI_NAME, STRING );
|
||||||
|
if ( isNotEmpty( explicitJndiName ) ) {
|
||||||
|
return explicitJndiName;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final String unitName = configService.getSetting( PERSISTENCE_UNIT_NAME, STRING );
|
||||||
|
// do not use name for JNDI if explicitly asked not to or if name comes from JPA persistence-unit name
|
||||||
|
final boolean nameIsNotJndiName =
|
||||||
|
options.isSessionFactoryNameAlsoJndiName() == Boolean.FALSE
|
||||||
|
|| isNotEmpty( unitName );
|
||||||
|
return !nameIsNotJndiName ? name : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void deprecationCheck(Map<String, Object> settings) {
|
||||||
|
for ( String setting:settings.keySet() ) {
|
||||||
|
switch ( setting ) {
|
||||||
|
case "hibernate.hql.bulk_id_strategy.global_temporary.create_tables":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.global_temporary.create_tables", GlobalTemporaryTableStrategy.CREATE_ID_TABLES );
|
||||||
|
case "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables", GlobalTemporaryTableStrategy.DROP_ID_TABLES );
|
||||||
|
case "hibernate.hql.bulk_id_strategy.persistent.create_tables":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.create_tables", PersistentTableStrategy.CREATE_ID_TABLES );
|
||||||
|
case "hibernate.hql.bulk_id_strategy.persistent.drop_tables":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.drop_tables", PersistentTableStrategy.DROP_ID_TABLES );
|
||||||
|
case "hibernate.hql.bulk_id_strategy.persistent.schema":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.schema", PersistentTableStrategy.SCHEMA );
|
||||||
|
case "hibernate.hql.bulk_id_strategy.persistent.catalog":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.catalog", PersistentTableStrategy.CATALOG );
|
||||||
|
case "hibernate.hql.bulk_id_strategy.local_temporary.drop_tables":
|
||||||
|
DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.local_temporary.drop_tables", LocalTemporaryTableStrategy.DROP_ID_TABLES );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -748,11 +748,6 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {
|
|
||||||
// anything to do ?
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] doGetImplementors(Class<?> clazz) throws MappingException {
|
private String[] doGetImplementors(Class<?> clazz) throws MappingException {
|
||||||
final ArrayList<String> results = new ArrayList<>();
|
final ArrayList<String> results = new ArrayList<>();
|
||||||
for ( EntityPersister checkPersister : entityPersisters().values() ) {
|
for ( EntityPersister checkPersister : entityPersisters().values() ) {
|
||||||
|
|
|
@ -132,5 +132,11 @@ public interface MetamodelImplementor extends MappingMetamodel, Metamodel {
|
||||||
*/
|
*/
|
||||||
String[] getAllCollectionRoles();
|
String[] getAllCollectionRoles();
|
||||||
|
|
||||||
void close();
|
/**
|
||||||
|
* @deprecated No longer called
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "7", forRemoval = true)
|
||||||
|
default void close() {
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue