@@ -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 ();
0 commit comments