@@ -85,7 +85,12 @@ class LeakingStatementCachingTest {
85
85
86
86
@ AfterAll
87
87
public void tearDown (SessionFactoryScope scope ) {
88
- SINGLE_CONNECTION_DATASOURCE .close ();
88
+ try {
89
+ scope .getSessionFactory ().getSchemaManager ().dropMappedObjects ( false );
90
+ }
91
+ finally {
92
+ SINGLE_CONNECTION_DATASOURCE .close ();
93
+ }
89
94
}
90
95
91
96
@ Test
@@ -127,38 +132,48 @@ public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
127
132
128
133
serviceRegistryBuilder .applySetting ( AvailableSettings .CONNECTION_PROVIDER ,
129
134
new DataSourceConnectionProvider () );
130
- serviceRegistryBuilder .applySetting ( AvailableSettings .SHOW_SQL , false );
135
+ serviceRegistryBuilder .applySetting ( AvailableSettings .SHOW_SQL , true );
136
+ serviceRegistryBuilder .applySetting ( AvailableSettings .HBM2DDL_AUTO , "create" );
131
137
serviceRegistryBuilder .applySetting ( AvailableSettings .LOG_JDBC_WARNINGS , false );
132
138
serviceRegistryBuilder .getSettings ().remove ( AvailableSettings .URL );
133
139
}
134
140
}
135
141
136
142
private static class SingleConnectionDataSource implements javax .sql .DataSource {
137
143
138
- private final BlockingQueue <Connection > connectionQueue = new ArrayBlockingQueue <>( 1 ) ;
144
+ private BlockingQueue <Connection > connectionQueue ;
139
145
140
146
public SingleConnectionDataSource () {
141
- DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl ();
142
- connectionProvider .configure (
143
- PropertiesHelper .map ( ConnectionProviderBuilder .getConnectionProviderProperties () ) );
144
- try {
145
- connectionQueue .add ( new ConnectionWrapper ( connectionProvider .getConnection (), this ) );
146
- }
147
- catch (SQLException e ) {
148
- throw new RuntimeException ( e );
149
- }
150
147
}
151
148
152
149
@ Override
153
150
public Connection getConnection () {
154
151
try {
155
- return connectionQueue .take ();
152
+ if ( connectionQueue == null ) {
153
+ connectionQueue = new ArrayBlockingQueue <>( 1 );
154
+ connectionQueue .add ( buildConnectionWrapper () );
155
+ }
156
+ if ( connectionQueue .isEmpty () ) {
157
+ throw new IllegalStateException ( "A problem occurred retrieving the connection" );
158
+ }
159
+ Connection connection = connectionQueue .take ();
160
+ if ( connection == null || connection .isClosed () ) {
161
+ throw new IllegalStateException ( "A problem occurred retrieving the connection" );
162
+ }
163
+ return connection ;
156
164
}
157
- catch (InterruptedException e ) {
165
+ catch (Exception e ) {
158
166
throw new RuntimeException ( e );
159
167
}
160
168
}
161
169
170
+ private ConnectionWrapper buildConnectionWrapper () throws SQLException {
171
+ DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl ();
172
+ connectionProvider .configure (
173
+ PropertiesHelper .map ( ConnectionProviderBuilder .getConnectionProviderProperties () ) );
174
+ return new ConnectionWrapper ( connectionProvider .getConnection (), this );
175
+ }
176
+
162
177
@ Override
163
178
public Connection getConnection (String username , String password ) {
164
179
throw new UnsupportedOperationException ();
0 commit comments