|
41 | 41 | import org.hibernate.StatelessSessionBuilder;
|
42 | 42 | import org.hibernate.UnknownFilterException;
|
43 | 43 | import org.hibernate.binder.internal.TenantIdBinder;
|
44 |
| -import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService; |
45 | 44 | import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
46 | 45 | import org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
|
47 | 46 | import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|
52 | 51 | import org.hibernate.cache.cfg.spi.DomainDataRegionConfig;
|
53 | 52 | import org.hibernate.cache.spi.CacheImplementor;
|
54 | 53 | import org.hibernate.cache.spi.access.AccessType;
|
55 |
| -import org.hibernate.cfg.AvailableSettings; |
56 |
| -import org.hibernate.cfg.PersistenceSettings; |
57 | 54 | import org.hibernate.context.internal.JTASessionContext;
|
58 | 55 | import org.hibernate.context.internal.ManagedSessionContext;
|
59 | 56 | import org.hibernate.context.internal.ThreadLocalSessionContext;
|
60 | 57 | import org.hibernate.context.spi.CurrentSessionContext;
|
61 | 58 | import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
62 | 59 | import org.hibernate.dialect.Dialect;
|
63 |
| -import org.hibernate.engine.config.spi.ConfigurationService; |
64 | 60 | import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
65 | 61 | import org.hibernate.engine.jdbc.spi.JdbcServices;
|
66 | 62 | import org.hibernate.engine.profile.FetchProfile;
|
|
103 | 99 | import org.hibernate.query.sql.spi.NativeQueryImplementor;
|
104 | 100 | import org.hibernate.query.sqm.NodeBuilder;
|
105 | 101 | import org.hibernate.query.sqm.function.SqmFunctionRegistry;
|
106 |
| -import org.hibernate.query.sqm.mutation.internal.temptable.GlobalTemporaryTableStrategy; |
107 |
| -import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableStrategy; |
108 |
| -import org.hibernate.query.sqm.mutation.internal.temptable.PersistentTableStrategy; |
109 | 102 | import org.hibernate.query.sqm.spi.NamedSqmQueryMemento;
|
110 | 103 | import org.hibernate.relational.SchemaManager;
|
111 | 104 | import org.hibernate.relational.internal.SchemaManagerImpl;
|
|
138 | 131 | import static java.util.Collections.emptySet;
|
139 | 132 | import static java.util.Collections.unmodifiableSet;
|
140 | 133 | import static org.hibernate.cfg.AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS;
|
141 |
| -import static org.hibernate.cfg.AvailableSettings.JAKARTA_VALIDATION_FACTORY; |
142 |
| -import static org.hibernate.cfg.AvailableSettings.JPA_VALIDATION_FACTORY; |
143 |
| -import static org.hibernate.cfg.PersistenceSettings.PERSISTENCE_UNIT_NAME; |
144 |
| -import static org.hibernate.cfg.PersistenceSettings.SESSION_FACTORY_JNDI_NAME; |
145 |
| -import static org.hibernate.engine.config.spi.StandardConverters.STRING; |
146 | 134 | import static org.hibernate.internal.FetchProfileHelper.getFetchProfiles;
|
147 |
| -import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; |
148 |
| -import static org.hibernate.internal.util.StringHelper.isNotEmpty; |
| 135 | +import static org.hibernate.internal.SessionFactorySettings.deprecationCheck; |
| 136 | +import static org.hibernate.internal.SessionFactorySettings.determineJndiName; |
| 137 | +import static org.hibernate.internal.SessionFactorySettings.getSessionFactoryName; |
| 138 | +import static org.hibernate.internal.SessionFactorySettings.getSettings; |
| 139 | +import static org.hibernate.internal.SessionFactorySettings.maskOutSensitiveInformation; |
149 | 140 | import static org.hibernate.jpa.HibernateHints.HINT_TENANT_ID;
|
150 | 141 | import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
|
151 | 142 | import static org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT;
|
@@ -262,8 +253,8 @@ public SessionFactoryImpl(
|
262 | 253 | //noinspection unchecked
|
263 | 254 | tenantIdentifierJavaType = jdbcMapping.getJavaTypeDescriptor();
|
264 | 255 | }
|
265 |
| - for (Map.Entry<String, FilterDefinition> filterEntry : filters.entrySet()) { |
266 |
| - if (filterEntry.getValue().isAutoEnabled()) { |
| 256 | + for ( Map.Entry<String, FilterDefinition> filterEntry : filters.entrySet() ) { |
| 257 | + if ( filterEntry.getValue().isAutoEnabled() ) { |
267 | 258 | autoEnabledFilters.add( filterEntry.getValue() );
|
268 | 259 | }
|
269 | 260 | }
|
@@ -295,7 +286,8 @@ public SessionFactoryImpl(
|
295 | 286 | // create runtime metamodels (mapping and JPA)
|
296 | 287 | final RuntimeMetamodelsImpl runtimeMetamodelsImpl = new RuntimeMetamodelsImpl();
|
297 | 288 | runtimeMetamodels = runtimeMetamodelsImpl;
|
298 |
| - final MappingMetamodelImpl mappingMetamodelImpl = new MappingMetamodelImpl( typeConfiguration, serviceRegistry ); |
| 289 | + final MappingMetamodelImpl mappingMetamodelImpl = |
| 290 | + new MappingMetamodelImpl( typeConfiguration, serviceRegistry ); |
299 | 291 | runtimeMetamodelsImpl.setMappingMetamodel( mappingMetamodelImpl );
|
300 | 292 | fastSessionServices = new FastSessionServices( this );
|
301 | 293 | initializeMappingModel( mappingMetamodelImpl, bootstrapContext, bootMetamodel, options );
|
@@ -337,38 +329,16 @@ public SessionFactoryImpl(
|
337 | 329 | LOG.debug( "Instantiated SessionFactory" );
|
338 | 330 | }
|
339 | 331 |
|
340 |
| - private static void deprecationCheck(Map<String, Object> settings) { |
341 |
| - for ( String s:settings.keySet() ) { |
342 |
| - switch (s) { |
343 |
| - case "hibernate.hql.bulk_id_strategy.global_temporary.create_tables": |
344 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.global_temporary.create_tables", GlobalTemporaryTableStrategy.CREATE_ID_TABLES ); |
345 |
| - case "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables": |
346 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.global_temporary.drop_tables", GlobalTemporaryTableStrategy.DROP_ID_TABLES ); |
347 |
| - case "hibernate.hql.bulk_id_strategy.persistent.create_tables": |
348 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.create_tables", PersistentTableStrategy.CREATE_ID_TABLES ); |
349 |
| - case "hibernate.hql.bulk_id_strategy.persistent.drop_tables": |
350 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.drop_tables", PersistentTableStrategy.DROP_ID_TABLES ); |
351 |
| - case "hibernate.hql.bulk_id_strategy.persistent.schema": |
352 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.schema", PersistentTableStrategy.SCHEMA ); |
353 |
| - case "hibernate.hql.bulk_id_strategy.persistent.catalog": |
354 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.persistent.catalog", PersistentTableStrategy.CATALOG ); |
355 |
| - case "hibernate.hql.bulk_id_strategy.local_temporary.drop_tables": |
356 |
| - DEPRECATION_LOGGER.deprecatedSetting( "hibernate.hql.bulk_id_strategy.local_temporary.drop_tables", LocalTemporaryTableStrategy.DROP_ID_TABLES ); |
357 |
| - } |
358 |
| - } |
359 |
| - } |
360 |
| - |
361 | 332 | private void initializeMappingModel(
|
362 | 333 | MappingMetamodelImpl mappingMetamodelImpl,
|
363 | 334 | BootstrapContext bootstrapContext,
|
364 | 335 | MetadataImplementor bootMetamodel,
|
365 | 336 | SessionFactoryOptions options) {
|
366 |
| - final TypeConfiguration typeConfiguration = mappingMetamodelImpl.getTypeConfiguration(); |
367 | 337 | mappingMetamodelImpl.finishInitialization( runtimeModelCreationContext(
|
368 | 338 | bootstrapContext,
|
369 | 339 | bootMetamodel,
|
370 | 340 | mappingMetamodelImpl,
|
371 |
| - typeConfiguration, |
| 341 | + mappingMetamodelImpl.getTypeConfiguration(), |
372 | 342 | options
|
373 | 343 | ) );
|
374 | 344 | }
|
@@ -528,58 +498,6 @@ private void disintegrate(Exception startupException, IntegratorObserver integra
|
528 | 498 | }
|
529 | 499 |
|
530 | 500 |
|
531 |
| - private static Map<String, Object> getSettings(SessionFactoryOptions options, SessionFactoryServiceRegistry serviceRegistry) { |
532 |
| - final Map<String, Object> settings = serviceRegistry.requireService( ConfigurationService.class ).getSettings(); |
533 |
| - final Map<String,Object> result = new HashMap<>( settings ); |
534 |
| - if ( !settings.containsKey( JPA_VALIDATION_FACTORY ) && !settings.containsKey( JAKARTA_VALIDATION_FACTORY ) ) { |
535 |
| - final Object reference = options.getValidatorFactoryReference(); |
536 |
| - if ( reference != null ) { |
537 |
| - result.put( JPA_VALIDATION_FACTORY, reference ); |
538 |
| - result.put( JAKARTA_VALIDATION_FACTORY, reference ); |
539 |
| - } |
540 |
| - } |
541 |
| - return result; |
542 |
| - } |
543 |
| - |
544 |
| - private static String getSessionFactoryName(SessionFactoryOptions options, SessionFactoryServiceRegistry serviceRegistry) { |
545 |
| - final String sessionFactoryName = options.getSessionFactoryName(); |
546 |
| - if ( sessionFactoryName != null ) { |
547 |
| - return sessionFactoryName; |
548 |
| - } |
549 |
| - |
550 |
| - final CfgXmlAccessService cfgXmlAccessService = serviceRegistry.requireService( CfgXmlAccessService.class ); |
551 |
| - if ( cfgXmlAccessService.getAggregatedConfig() != null ) { |
552 |
| - final String nameFromAggregation = cfgXmlAccessService.getAggregatedConfig().getSessionFactoryName(); |
553 |
| - if ( nameFromAggregation != null ) { |
554 |
| - return nameFromAggregation; |
555 |
| - } |
556 |
| - } |
557 |
| - |
558 |
| - |
559 |
| - final ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class ); |
560 |
| - assert configurationService != null; |
561 |
| - return configurationService.getSetting( PersistenceSettings.PERSISTENCE_UNIT_NAME, STRING ); |
562 |
| - } |
563 |
| - |
564 |
| - private String determineJndiName( |
565 |
| - String name, |
566 |
| - SessionFactoryOptions options, |
567 |
| - SessionFactoryServiceRegistry serviceRegistry) { |
568 |
| - final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class ); |
569 |
| - assert cfgService != null; |
570 |
| - final String explicitJndiName = cfgService.getSetting( SESSION_FACTORY_JNDI_NAME, STRING ); |
571 |
| - if ( isNotEmpty( explicitJndiName ) ) { |
572 |
| - return explicitJndiName; |
573 |
| - } |
574 |
| - |
575 |
| - final String puName = cfgService.getSetting( PERSISTENCE_UNIT_NAME, STRING ); |
576 |
| - // do not use name for JNDI if explicitly asked not to or if name comes from JPA persistence-unit name |
577 |
| - final boolean nameIsNotJndiName = |
578 |
| - options.isSessionFactoryNameAlsoJndiName() == Boolean.FALSE |
579 |
| - || isNotEmpty( puName ); |
580 |
| - return !nameIsNotJndiName ? name : null; |
581 |
| - } |
582 |
| - |
583 | 501 | private SessionBuilderImpl createDefaultSessionOpenOptionsIfPossible() {
|
584 | 502 | final CurrentTenantIdentifierResolver<Object> tenantIdResolver = getCurrentTenantIdentifierResolver();
|
585 | 503 | if ( tenantIdResolver == null ) {
|
@@ -888,7 +806,7 @@ public Reference getReference() {
|
888 | 806 | LOG.debug( "Returning a Reference to the SessionFactory" );
|
889 | 807 | return new Reference(
|
890 | 808 | SessionFactoryImpl.class.getName(),
|
891 |
| - new StringRefAddr("uuid", getUuid()), |
| 809 | + new StringRefAddr( "uuid", getUuid() ), |
892 | 810 | SessionFactoryRegistry.ObjectFactoryImpl.class.getName(),
|
893 | 811 | null
|
894 | 812 | );
|
@@ -954,20 +872,16 @@ public void close() throws HibernateException {
|
954 | 872 | runtimeMetamodels.getMappingMetamodel().forEachEntityDescriptor(
|
955 | 873 | entityPersister -> {
|
956 | 874 | if ( entityPersister.getSqmMultiTableMutationStrategy() != null ) {
|
957 |
| - entityPersister.getSqmMultiTableMutationStrategy().release( |
958 |
| - this, |
959 |
| - jdbcConnectionAccess |
960 |
| - ); |
| 875 | + entityPersister.getSqmMultiTableMutationStrategy() |
| 876 | + .release( this, jdbcConnectionAccess ); |
961 | 877 | }
|
962 | 878 | if ( entityPersister.getSqmMultiTableInsertStrategy() != null ) {
|
963 |
| - entityPersister.getSqmMultiTableInsertStrategy().release( |
964 |
| - this, |
965 |
| - jdbcConnectionAccess |
966 |
| - ); |
| 879 | + entityPersister.getSqmMultiTableInsertStrategy() |
| 880 | + .release( this, jdbcConnectionAccess ); |
967 | 881 | }
|
968 | 882 | }
|
969 | 883 | );
|
970 |
| - ( (MappingMetamodelImpl) runtimeMetamodels.getMappingMetamodel() ).close(); |
| 884 | +// ( (MappingMetamodelImpl) runtimeMetamodels.getMappingMetamodel() ).close(); |
971 | 885 | }
|
972 | 886 |
|
973 | 887 | if ( queryEngine != null ) {
|
@@ -1324,18 +1238,18 @@ public SessionBuilderImpl(SessionFactoryImpl sessionFactory) {
|
1324 | 1238 |
|
1325 | 1239 | // set up default builder values...
|
1326 | 1240 | final SessionFactoryOptions sessionFactoryOptions = sessionFactory.getSessionFactoryOptions();
|
1327 |
| - this.statementInspector = sessionFactoryOptions.getStatementInspector(); |
1328 |
| - this.connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode(); |
1329 |
| - this.autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled(); |
1330 |
| - this.defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize(); |
1331 |
| - this.subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled(); |
| 1241 | + statementInspector = sessionFactoryOptions.getStatementInspector(); |
| 1242 | + connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode(); |
| 1243 | + autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled(); |
| 1244 | + defaultBatchFetchSize = sessionFactoryOptions.getDefaultBatchFetchSize(); |
| 1245 | + subselectFetchEnabled = sessionFactoryOptions.isSubselectFetchEnabled(); |
1332 | 1246 |
|
1333 | 1247 | final CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver =
|
1334 | 1248 | sessionFactory.getCurrentTenantIdentifierResolver();
|
1335 | 1249 | if ( currentTenantIdentifierResolver != null ) {
|
1336 | 1250 | tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
|
1337 | 1251 | }
|
1338 |
| - this.jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone(); |
| 1252 | + jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone(); |
1339 | 1253 | }
|
1340 | 1254 |
|
1341 | 1255 |
|
@@ -1772,21 +1686,6 @@ static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException
|
1772 | 1686 | return (SessionFactoryImpl) locateSessionFactoryOnDeserialization( uuid, name );
|
1773 | 1687 | }
|
1774 | 1688 |
|
1775 |
| - private static void maskOutSensitiveInformation(Map<String, Object> props) { |
1776 |
| - maskOutIfSet( props, AvailableSettings.JPA_JDBC_USER ); |
1777 |
| - maskOutIfSet( props, AvailableSettings.JPA_JDBC_PASSWORD ); |
1778 |
| - maskOutIfSet( props, AvailableSettings.JAKARTA_JDBC_USER ); |
1779 |
| - maskOutIfSet( props, AvailableSettings.JAKARTA_JDBC_PASSWORD ); |
1780 |
| - maskOutIfSet( props, AvailableSettings.USER ); |
1781 |
| - maskOutIfSet( props, AvailableSettings.PASS ); |
1782 |
| - } |
1783 |
| - |
1784 |
| - private static void maskOutIfSet(Map<String, Object> props, String setting) { |
1785 |
| - if ( props.containsKey( setting ) ) { |
1786 |
| - props.put( setting, "****" ); |
1787 |
| - } |
1788 |
| - } |
1789 |
| - |
1790 | 1689 | /**
|
1791 | 1690 | * @return the {@link FastSessionServices} for this {@code SessionFactory}.
|
1792 | 1691 | */
|
|
0 commit comments