75
75
import org .hibernate .id .Configurable ;
76
76
import org .hibernate .integrator .spi .Integrator ;
77
77
import org .hibernate .integrator .spi .IntegratorService ;
78
- import org .hibernate .internal .util .StringHelper ;
79
78
import org .hibernate .jpa .internal .ExceptionMapperLegacyJpaImpl ;
80
79
import org .hibernate .jpa .internal .PersistenceUnitUtilImpl ;
81
80
import org .hibernate .mapping .Collection ;
146
145
import static org .hibernate .engine .config .spi .StandardConverters .STRING ;
147
146
import static org .hibernate .internal .FetchProfileHelper .getFetchProfiles ;
148
147
import static org .hibernate .internal .log .DeprecationLogger .DEPRECATION_LOGGER ;
148
+ import static org .hibernate .internal .util .StringHelper .isNotEmpty ;
149
149
import static org .hibernate .jpa .HibernateHints .HINT_TENANT_ID ;
150
150
import static org .hibernate .proxy .HibernateProxy .extractLazyInitializer ;
151
151
import static org .hibernate .resource .jdbc .spi .PhysicalConnectionHandlingMode .DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT ;
@@ -457,17 +457,16 @@ private static Map<String, Generator> createGenerators(
457
457
for ( PersistentClass model : bootMetamodel .getEntityBindings () ) {
458
458
if ( !model .isInherited () ) {
459
459
final KeyValue id = model .getIdentifier ();
460
- final Generator generator = id . createGenerator ( dialect , ( RootClass ) model , model . getIdentifierProperty () );
461
- if ( generator instanceof Configurable ) {
462
- final Configurable identifierGenerator = ( Configurable ) generator ;
463
- identifierGenerator .initialize ( sqlStringGenerationContext );
460
+ final Generator generator =
461
+ id . createGenerator ( dialect , ( RootClass ) model , model . getIdentifierProperty () );
462
+ if ( generator instanceof Configurable configurable ) {
463
+ configurable .initialize ( sqlStringGenerationContext );
464
464
}
465
465
//TODO: this isn't a great place to do this
466
- if ( generator .allowAssignedIdentifiers () && id instanceof SimpleValue ) {
467
- final SimpleValue simpleValue = (SimpleValue ) id ;
468
- if ( simpleValue .getNullValue () == null ) {
469
- simpleValue .setNullValue ( "undefined" );
470
- }
466
+ if ( generator .allowAssignedIdentifiers ()
467
+ && id instanceof SimpleValue simpleValue
468
+ && simpleValue .getNullValue () == null ) {
469
+ simpleValue .setNullValue ( "undefined" );
471
470
}
472
471
generators .put ( model .getEntityName (), generator );
473
472
}
@@ -559,12 +558,7 @@ private static String getSessionFactoryName(SessionFactoryOptions options, Sessi
559
558
560
559
final ConfigurationService configurationService = serviceRegistry .getService ( ConfigurationService .class );
561
560
assert configurationService != null ;
562
- final String puName = configurationService .getSetting ( PersistenceSettings .PERSISTENCE_UNIT_NAME , STRING );
563
- if ( puName != null ) {
564
- return puName ;
565
- }
566
-
567
- return null ;
561
+ return configurationService .getSetting ( PersistenceSettings .PERSISTENCE_UNIT_NAME , STRING );
568
562
}
569
563
570
564
private String determineJndiName (
@@ -574,19 +568,21 @@ private String determineJndiName(
574
568
final ConfigurationService cfgService = serviceRegistry .getService ( ConfigurationService .class );
575
569
assert cfgService != null ;
576
570
final String explicitJndiName = cfgService .getSetting ( SESSION_FACTORY_JNDI_NAME , STRING );
577
- if ( StringHelper . isNotEmpty ( explicitJndiName ) ) {
571
+ if ( isNotEmpty ( explicitJndiName ) ) {
578
572
return explicitJndiName ;
579
573
}
580
574
581
575
final String puName = cfgService .getSetting ( PERSISTENCE_UNIT_NAME , STRING );
582
576
// do not use name for JNDI if explicitly asked not to or if name comes from JPA persistence-unit name
583
- final boolean nameIsNotJndiName = options .isSessionFactoryNameAlsoJndiName () == Boolean .FALSE || StringHelper .isNotEmpty ( puName );
577
+ final boolean nameIsNotJndiName =
578
+ options .isSessionFactoryNameAlsoJndiName () == Boolean .FALSE
579
+ || isNotEmpty ( puName );
584
580
return !nameIsNotJndiName ? name : null ;
585
581
}
586
582
587
583
private SessionBuilderImpl createDefaultSessionOpenOptionsIfPossible () {
588
- final CurrentTenantIdentifierResolver <Object > currentTenantIdentifierResolver = getCurrentTenantIdentifierResolver ();
589
- if ( currentTenantIdentifierResolver == null ) {
584
+ final CurrentTenantIdentifierResolver <Object > tenantIdResolver = getCurrentTenantIdentifierResolver ();
585
+ if ( tenantIdResolver == null ) {
590
586
return withOptions ();
591
587
}
592
588
else {
@@ -698,8 +694,8 @@ public StatelessSessionBuilder withStatelessOptions() {
698
694
699
695
@ Override
700
696
public StatelessSession openStatelessSession () {
701
- if ( this . defaultStatelessOptions != null ) {
702
- return this . defaultStatelessOptions .openStatelessSession ();
697
+ if ( defaultStatelessOptions != null ) {
698
+ return defaultStatelessOptions .openStatelessSession ();
703
699
}
704
700
else {
705
701
return withStatelessOptions ().openStatelessSession ();
@@ -799,12 +795,10 @@ private <K,V> Session buildEntityManager(final SynchronizationType synchronizati
799
795
if ( map != null ) {
800
796
for ( Map .Entry <K , V > o : map .entrySet () ) {
801
797
final K key = o .getKey ();
802
- if ( key instanceof String ) {
803
- final String sKey = (String ) key ;
804
- if ( HINT_TENANT_ID .equals ( sKey ) ) {
805
- continue ;
798
+ if ( key instanceof String string ) {
799
+ if ( !HINT_TENANT_ID .equals ( string ) ) {
800
+ session .setProperty ( string , o .getValue () );
806
801
}
807
- session .setProperty ( sKey , o .getValue () );
808
802
}
809
803
}
810
804
}
@@ -849,7 +843,7 @@ public NodeBuilder getCriteriaBuilder() {
849
843
return queryEngine .getCriteriaBuilder ();
850
844
}
851
845
852
- @ Override
846
+ @ Override @ Deprecated
853
847
public MetamodelImplementor getMetamodel () {
854
848
validateNotClosed ();
855
849
return (MetamodelImplementor ) runtimeMetamodels .getMappingMetamodel ();
@@ -1033,7 +1027,7 @@ public void addNamedQuery(String name, Query query) {
1033
1027
1034
1028
// then try as a native-SQL or JPQL query
1035
1029
try {
1036
- QueryImplementor <?> hibernateQuery = query .unwrap ( QueryImplementor .class );
1030
+ final QueryImplementor <?> hibernateQuery = query .unwrap ( QueryImplementor .class );
1037
1031
if ( hibernateQuery != null ) {
1038
1032
// create and register the proper NamedQueryDefinition...
1039
1033
if ( hibernateQuery instanceof NativeQueryImplementor ) {
@@ -1119,9 +1113,8 @@ public <E> Map<String, EntityGraph<? extends E>> getNamedEntityGraphs(Class<E> e
1119
1113
return getJpaMetamodel ().getNamedEntityGraphs ( entityType );
1120
1114
}
1121
1115
1122
- @ Override
1116
+ @ Override @ SuppressWarnings ({ "unchecked" , "rawtypes" })
1123
1117
public void runInTransaction (Consumer <EntityManager > work ) {
1124
- //noinspection unchecked,rawtypes
1125
1118
inTransaction ( (Consumer ) work );
1126
1119
}
1127
1120
@@ -1146,11 +1139,11 @@ public StatisticsImplementor getStatistics() {
1146
1139
}
1147
1140
1148
1141
public FilterDefinition getFilterDefinition (String filterName ) throws HibernateException {
1149
- FilterDefinition def = filters .get ( filterName );
1150
- if ( def == null ) {
1142
+ final FilterDefinition filterDefinition = filters .get ( filterName );
1143
+ if ( filterDefinition == null ) {
1151
1144
throw new UnknownFilterException ( filterName );
1152
1145
}
1153
- return def ;
1146
+ return filterDefinition ;
1154
1147
}
1155
1148
1156
1149
@ Override
@@ -1563,7 +1556,7 @@ public StatelessSessionBuilder connection(Connection connection) {
1563
1556
return this ;
1564
1557
}
1565
1558
1566
- @ Override
1559
+ @ Override @ Deprecated
1567
1560
public StatelessSessionBuilder tenantIdentifier (String tenantIdentifier ) {
1568
1561
this .tenantIdentifier = tenantIdentifier ;
1569
1562
return this ;
0 commit comments