@@ -85,7 +85,12 @@ class LeakingStatementCachingTest {
8585
8686 @ AfterAll
8787 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+ }
8994 }
9095
9196 @ Test
@@ -127,38 +132,40 @@ public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
127132
128133 serviceRegistryBuilder .applySetting ( AvailableSettings .CONNECTION_PROVIDER ,
129134 new DataSourceConnectionProvider () );
130- serviceRegistryBuilder .applySetting ( AvailableSettings .SHOW_SQL , false );
135+ serviceRegistryBuilder .applySetting ( AvailableSettings .SHOW_SQL , true );
136+ serviceRegistryBuilder .applySetting ( AvailableSettings .HBM2DDL_AUTO , "create" );
131137 serviceRegistryBuilder .applySetting ( AvailableSettings .LOG_JDBC_WARNINGS , false );
132138 serviceRegistryBuilder .getSettings ().remove ( AvailableSettings .URL );
133139 }
134140 }
135141
136- private static class SingleConnectionDataSource implements javax .sql .DataSource {
142+ private static class SingleConnectionDataSource implements javax .sql .DataSource {
137143
138144 private final BlockingQueue <Connection > connectionQueue = new ArrayBlockingQueue <>( 1 );
139145
140146 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- }
150147 }
151148
152149 @ Override
153150 public Connection getConnection () {
154151 try {
152+ if ( connectionQueue .isEmpty () ) {
153+ connectionQueue .add ( buildConnectionWrapper () );
154+ }
155155 return connectionQueue .take ();
156156 }
157- catch (InterruptedException e ) {
157+ catch (Exception e ) {
158158 throw new RuntimeException ( e );
159159 }
160160 }
161161
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+
162169 @ Override
163170 public Connection getConnection (String username , String password ) {
164171 throw new UnsupportedOperationException ();
0 commit comments