@@ -30,35 +30,29 @@ public class GlobalTemporaryTableStrategy {
30
30
public static final String SHORT_NAME = "global_temporary" ;
31
31
32
32
public static final String CREATE_ID_TABLES = "hibernate.query.mutation_strategy.global_temporary.create_tables" ;
33
-
34
33
public static final String DROP_ID_TABLES = "hibernate.query.mutation_strategy.global_temporary.drop_tables" ;
35
34
36
35
private final TemporaryTable temporaryTable ;
37
-
38
36
private final SessionFactoryImplementor sessionFactory ;
39
37
40
38
private boolean prepared ;
41
-
42
39
private boolean dropIdTables ;
43
40
44
- public GlobalTemporaryTableStrategy (
45
- TemporaryTable temporaryTable ,
46
- SessionFactoryImplementor sessionFactory ) {
41
+ public GlobalTemporaryTableStrategy (TemporaryTable temporaryTable , SessionFactoryImplementor sessionFactory ) {
47
42
this .temporaryTable = temporaryTable ;
48
43
this .sessionFactory = sessionFactory ;
49
44
50
45
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 () );
52
48
}
53
49
}
54
50
55
51
public EntityMappingType getEntityDescriptor () {
56
52
return temporaryTable .getEntityDescriptor ();
57
53
}
58
54
59
- public void prepare (
60
- MappingModelCreationProcess mappingModelCreationProcess ,
61
- JdbcConnectionAccess connectionAccess ) {
55
+ public void prepare (MappingModelCreationProcess mappingModelCreationProcess , JdbcConnectionAccess connectionAccess ) {
62
56
if ( prepared ) {
63
57
return ;
64
58
}
@@ -69,56 +63,41 @@ public void prepare(
69
63
mappingModelCreationProcess .getCreationContext ()
70
64
.getBootstrapContext ().getServiceRegistry ()
71
65
.requireService ( ConfigurationService .class );
72
- boolean createIdTables = configService .getSetting (
73
- CREATE_ID_TABLES ,
74
- StandardConverters .BOOLEAN ,
75
- true
76
- );
77
66
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 () );
83
69
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
+ }
101
85
102
- try {
103
- temporaryTableCreationWork .execute ( connection );
104
- this .dropIdTables = configService .getSetting (
105
- DROP_ID_TABLES ,
106
- StandardConverters .BOOLEAN ,
107
- false
108
- );
109
- }
110
- finally {
111
86
try {
112
- connectionAccess .releaseConnection ( connection );
87
+ temporaryTableCreationWork .execute ( connection );
88
+ dropIdTables = configService .getSetting ( DROP_ID_TABLES , StandardConverters .BOOLEAN , false );
113
89
}
114
- catch (SQLException ignore ) {
90
+ finally {
91
+ try {
92
+ connectionAccess .releaseConnection ( connection );
93
+ }
94
+ catch (SQLException ignore ) {
95
+ }
115
96
}
116
97
}
117
98
}
118
99
119
- public void release (
120
- SessionFactoryImplementor sessionFactory ,
121
- JdbcConnectionAccess connectionAccess ) {
100
+ public void release (SessionFactoryImplementor sessionFactory , JdbcConnectionAccess connectionAccess ) {
122
101
if ( !dropIdTables ) {
123
102
return ;
124
103
}
@@ -127,10 +106,8 @@ public void release(
127
106
128
107
log .debugf ( "Dropping global-temp ID table : %s" , getTemporaryTable ().getTableExpression () );
129
108
130
- final TemporaryTableHelper .TemporaryTableDropWork temporaryTableDropWork = new TemporaryTableHelper .TemporaryTableDropWork (
131
- getTemporaryTable (),
132
- sessionFactory
133
- );
109
+ final TemporaryTableHelper .TemporaryTableDropWork temporaryTableDropWork =
110
+ new TemporaryTableHelper .TemporaryTableDropWork ( getTemporaryTable (), sessionFactory );
134
111
Connection connection ;
135
112
try {
136
113
connection = connectionAccess .obtainConnection ();
0 commit comments