@@ -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,40 @@ 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
- private static class SingleConnectionDataSource implements javax .sql .DataSource {
142
+ private static class SingleConnectionDataSource implements javax .sql .DataSource {
137
143
138
144
private final BlockingQueue <Connection > connectionQueue = new ArrayBlockingQueue <>( 1 );
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 {
152
+ if ( connectionQueue .isEmpty () ) {
153
+ connectionQueue .add ( buildConnectionWrapper () );
154
+ }
155
155
return connectionQueue .take ();
156
156
}
157
- catch (InterruptedException e ) {
157
+ catch (Exception e ) {
158
158
throw new RuntimeException ( e );
159
159
}
160
160
}
161
161
162
+ private ConnectionWrapper buildConnectionWrapper () throws SQLException {
163
+ DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl ();
164
+ connectionProvider .configure (
165
+ PropertiesHelper .map ( ConnectionProviderBuilder .getConnectionProviderProperties () ) );
166
+ return new ConnectionWrapper ( connectionProvider .getConnection (), this );
167
+ }
168
+
162
169
@ Override
163
170
public Connection getConnection (String username , String password ) {
164
171
throw new UnsupportedOperationException ();
0 commit comments