Skip to content

Commit 4176cb2

Browse files
committed
some misc code cleanups
1 parent a6aeeba commit 4176cb2

File tree

4 files changed

+52
-79
lines changed

4 files changed

+52
-79
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/ConnectionProviderInitiator.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import static org.hibernate.cfg.SchemaToolingSettings.ENABLE_SYNONYMS;
4545
import static org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.isMultiTenancyEnabled;
4646
import static org.hibernate.internal.util.StringHelper.isBlank;
47-
import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
47+
import static org.hibernate.internal.util.StringHelper.nullIfBlank;
4848

4949
/**
5050
* Instantiates and configures an appropriate {@link ConnectionProvider}.
@@ -108,28 +108,26 @@ else if ( explicitSetting instanceof Class<?> providerClass ) {
108108
return instantiateExplicitConnectionProvider( providerClass, beanContainer );
109109
}
110110
else {
111-
final String providerName = nullIfEmpty( explicitSetting.toString() );
111+
final String providerName = nullIfBlank( explicitSetting.toString() );
112112
if ( providerName != null ) {
113-
return instantiateNamedConnectionProvider(providerName, strategySelector, beanContainer);
113+
return instantiateNamedConnectionProvider( providerName, strategySelector, beanContainer );
114114
}
115115
}
116116
}
117117

118118
return instantiateConnectionProvider( configurationValues, strategySelector, beanContainer );
119119
}
120120

121-
private ConnectionProvider instantiateNamedConnectionProvider(String providerName, StrategySelector strategySelector, BeanContainer beanContainer) {
121+
private ConnectionProvider instantiateNamedConnectionProvider(
122+
String providerName, StrategySelector strategySelector, BeanContainer beanContainer) {
122123
LOG.instantiatingExplicitConnectionProvider( providerName );
123124
final Class<?> providerClass =
124125
strategySelector.selectStrategyImplementor( ConnectionProvider.class, providerName );
125126
try {
126127
return instantiateExplicitConnectionProvider( providerClass, beanContainer );
127128
}
128129
catch (Exception e) {
129-
throw new HibernateException(
130-
"Could not instantiate connection provider [" + providerName + "]",
131-
e
132-
);
130+
throw new HibernateException( "Could not instantiate connection provider [" + providerName + "]", e );
133131
}
134132
}
135133

@@ -165,7 +163,7 @@ else if ( configurationValues.containsKey( URL ) ) {
165163
return new DriverManagerConnectionProviderImpl();
166164
}
167165
else {
168-
if (beanContainer != null) {
166+
if ( beanContainer != null ) {
169167
return Helper.getBean(
170168
beanContainer,
171169
ConnectionProvider.class,

hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/GlobalTemporaryTableStrategy.java

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,29 @@ public class GlobalTemporaryTableStrategy {
3030
public static final String SHORT_NAME = "global_temporary";
3131

3232
public static final String CREATE_ID_TABLES = "hibernate.query.mutation_strategy.global_temporary.create_tables";
33-
3433
public static final String DROP_ID_TABLES = "hibernate.query.mutation_strategy.global_temporary.drop_tables";
3534

3635
private final TemporaryTable temporaryTable;
37-
3836
private final SessionFactoryImplementor sessionFactory;
3937

4038
private boolean prepared;
41-
4239
private boolean dropIdTables;
4340

44-
public GlobalTemporaryTableStrategy(
45-
TemporaryTable temporaryTable,
46-
SessionFactoryImplementor sessionFactory) {
41+
public GlobalTemporaryTableStrategy(TemporaryTable temporaryTable, SessionFactoryImplementor sessionFactory) {
4742
this.temporaryTable = temporaryTable;
4843
this.sessionFactory = sessionFactory;
4944

5045
if ( sessionFactory.getJdbcServices().getDialect().getTemporaryTableAfterUseAction() == AfterUseAction.DROP ) {
51-
throw new IllegalArgumentException( "Global-temp ID tables cannot use AfterUseAction.DROP : " + temporaryTable.getTableExpression() );
46+
throw new IllegalArgumentException( "Global-temp ID tables cannot use AfterUseAction.DROP : "
47+
+ temporaryTable.getTableExpression() );
5248
}
5349
}
5450

5551
public EntityMappingType getEntityDescriptor() {
5652
return temporaryTable.getEntityDescriptor();
5753
}
5854

59-
public void prepare(
60-
MappingModelCreationProcess mappingModelCreationProcess,
61-
JdbcConnectionAccess connectionAccess) {
55+
public void prepare(MappingModelCreationProcess mappingModelCreationProcess, JdbcConnectionAccess connectionAccess) {
6256
if ( prepared ) {
6357
return;
6458
}
@@ -69,56 +63,41 @@ public void prepare(
6963
mappingModelCreationProcess.getCreationContext()
7064
.getBootstrapContext().getServiceRegistry()
7165
.requireService( ConfigurationService.class );
72-
boolean createIdTables = configService.getSetting(
73-
CREATE_ID_TABLES,
74-
StandardConverters.BOOLEAN,
75-
true
76-
);
7766

78-
if ( !createIdTables ) {
79-
return;
80-
}
81-
82-
log.debugf( "Creating global-temp ID table : %s", getTemporaryTable().getTableExpression() );
67+
if ( configService.getSetting( CREATE_ID_TABLES, StandardConverters.BOOLEAN, true ) ) {
68+
log.debugf( "Creating global-temp ID table: %s", getTemporaryTable().getTableExpression() );
8369

84-
final TemporaryTableHelper.TemporaryTableCreationWork temporaryTableCreationWork = new TemporaryTableHelper.TemporaryTableCreationWork(
85-
getTemporaryTable(),
86-
sessionFactory
87-
);
88-
Connection connection;
89-
try {
90-
connection = connectionAccess.obtainConnection();
91-
}
92-
catch (UnsupportedOperationException e) {
93-
// assume this comes from org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl
94-
log.debug( "Unable to obtain JDBC connection; assuming ID tables already exist or wont be needed" );
95-
return;
96-
}
97-
catch (SQLException e) {
98-
log.error( "Unable obtain JDBC Connection", e );
99-
return;
100-
}
70+
final TemporaryTableHelper.TemporaryTableCreationWork temporaryTableCreationWork =
71+
new TemporaryTableHelper.TemporaryTableCreationWork( getTemporaryTable(), sessionFactory );
72+
final Connection connection;
73+
try {
74+
connection = connectionAccess.obtainConnection();
75+
}
76+
catch (UnsupportedOperationException e) {
77+
// assume this comes from org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl
78+
log.debug( "Unable to obtain JDBC connection; assuming ID tables already exist or wont be needed" );
79+
return;
80+
}
81+
catch (SQLException e) {
82+
log.error( "Unable obtain JDBC Connection", e );
83+
return;
84+
}
10185

102-
try {
103-
temporaryTableCreationWork.execute( connection );
104-
this.dropIdTables = configService.getSetting(
105-
DROP_ID_TABLES,
106-
StandardConverters.BOOLEAN,
107-
false
108-
);
109-
}
110-
finally {
11186
try {
112-
connectionAccess.releaseConnection( connection );
87+
temporaryTableCreationWork.execute( connection );
88+
dropIdTables = configService.getSetting( DROP_ID_TABLES, StandardConverters.BOOLEAN, false );
11389
}
114-
catch (SQLException ignore) {
90+
finally {
91+
try {
92+
connectionAccess.releaseConnection( connection );
93+
}
94+
catch (SQLException ignore) {
95+
}
11596
}
11697
}
11798
}
11899

119-
public void release(
120-
SessionFactoryImplementor sessionFactory,
121-
JdbcConnectionAccess connectionAccess) {
100+
public void release(SessionFactoryImplementor sessionFactory, JdbcConnectionAccess connectionAccess) {
122101
if ( !dropIdTables ) {
123102
return;
124103
}
@@ -127,10 +106,8 @@ public void release(
127106

128107
log.debugf( "Dropping global-temp ID table : %s", getTemporaryTable().getTableExpression() );
129108

130-
final TemporaryTableHelper.TemporaryTableDropWork temporaryTableDropWork = new TemporaryTableHelper.TemporaryTableDropWork(
131-
getTemporaryTable(),
132-
sessionFactory
133-
);
109+
final TemporaryTableHelper.TemporaryTableDropWork temporaryTableDropWork =
110+
new TemporaryTableHelper.TemporaryTableDropWork( getTemporaryTable(), sessionFactory );
134111
Connection connection;
135112
try {
136113
connection = connectionAccess.obtainConnection();

hibernate-core/src/main/java/org/hibernate/query/sqm/mutation/internal/temptable/LocalTemporaryTableStrategy.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,17 @@ public class LocalTemporaryTableStrategy {
2727

2828
private boolean dropIdTables;
2929

30-
public LocalTemporaryTableStrategy(
31-
TemporaryTable temporaryTable,
32-
SessionFactoryImplementor sessionFactory) {
30+
public LocalTemporaryTableStrategy(TemporaryTable temporaryTable, SessionFactoryImplementor sessionFactory) {
3331
this.temporaryTable = temporaryTable;
3432
this.sessionFactory = sessionFactory;
3533
}
3634

37-
public void prepare(
38-
MappingModelCreationProcess mappingModelCreationProcess,
39-
JdbcConnectionAccess connectionAccess) {
35+
public void prepare(MappingModelCreationProcess mappingModelCreationProcess, JdbcConnectionAccess connectionAccess) {
4036
final ConfigurationService configService =
4137
mappingModelCreationProcess.getCreationContext()
4238
.getBootstrapContext().getServiceRegistry()
4339
.requireService( ConfigurationService.class );
44-
this.dropIdTables = configService.getSetting(
45-
DROP_ID_TABLES,
46-
StandardConverters.BOOLEAN,
47-
false
48-
);
40+
dropIdTables = configService.getSetting( DROP_ID_TABLES, StandardConverters.BOOLEAN, false );
4941
}
5042

5143
public void release(SessionFactoryImplementor sessionFactory, JdbcConnectionAccess connectionAccess) {

hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@ public static BeanLifecycleStrategy getLifecycleStrategy(boolean shouldRegistryM
4949

5050
@Nullable
5151
public static BeanContainer getBeanContainer(ServiceRegistry serviceRegistry) {
52-
return allowExtensionsInCdi( serviceRegistry ) ? serviceRegistry.requireService( ManagedBeanRegistry.class ).getBeanContainer() : null;
52+
return allowExtensionsInCdi( serviceRegistry )
53+
? serviceRegistry.requireService( ManagedBeanRegistry.class ).getBeanContainer()
54+
: null;
5355
}
5456

5557
@SuppressWarnings( "unchecked" )
5658
@Nullable
57-
public static <T> T getBean(@Nullable BeanContainer beanContainer, Class<?> beanType, boolean canUseCachedReferences, boolean useJpaCompliantCreation, @Nullable Supplier<T> fallbackSupplier) {
59+
public static <T> T getBean(
60+
@Nullable BeanContainer beanContainer,
61+
Class<?> beanType,
62+
boolean canUseCachedReferences,
63+
boolean useJpaCompliantCreation,
64+
@Nullable Supplier<T> fallbackSupplier) {
5865
if ( beanContainer == null ) {
5966
return null;
6067
}
@@ -72,10 +79,9 @@ public boolean useJpaCompliantCreation() {
7279
}
7380
},
7481
new BeanInstanceProducer() {
75-
7682
@Override
7783
public <B> B produceBeanInstance(Class<B> beanType) {
78-
return (B) (fallbackSupplier != null ? fallbackSupplier.get() : null);
84+
return fallbackSupplier != null ? (B) fallbackSupplier.get() : null;
7985
}
8086

8187
@Override

0 commit comments

Comments
 (0)