mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
jdbc Connections in try-with-resources (so they close and return to connection pool)
This commit is contained in:
@ -106,16 +106,19 @@ public class TestUtils
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static void primeTestDatabase() throws Exception
|
public static void primeTestDatabase() throws Exception
|
||||||
{
|
{
|
||||||
ConnectionManager connectionManager = new ConnectionManager();
|
ConnectionManager connectionManager = new ConnectionManager();
|
||||||
Connection connection = connectionManager.getConnection(TestUtils.defineDefaultH2Backend());
|
|
||||||
InputStream primeTestDatabaseSqlStream = TestUtils.class.getResourceAsStream("/prime-test-database.sql");
|
try(Connection connection = connectionManager.getConnection(TestUtils.defineDefaultH2Backend()))
|
||||||
assertNotNull(primeTestDatabaseSqlStream);
|
|
||||||
List<String> lines = (List<String>) IOUtils.readLines(primeTestDatabaseSqlStream);
|
|
||||||
lines = lines.stream().filter(line -> !line.startsWith("-- ")).toList();
|
|
||||||
String joinedSQL = String.join("\n", lines);
|
|
||||||
for(String sql : joinedSQL.split(";"))
|
|
||||||
{
|
{
|
||||||
QueryManager.executeUpdate(connection, sql);
|
InputStream primeTestDatabaseSqlStream = TestUtils.class.getResourceAsStream("/prime-test-database.sql");
|
||||||
|
assertNotNull(primeTestDatabaseSqlStream);
|
||||||
|
List<String> lines = (List<String>) IOUtils.readLines(primeTestDatabaseSqlStream);
|
||||||
|
lines = lines.stream().filter(line -> !line.startsWith("-- ")).toList();
|
||||||
|
String joinedSQL = String.join("\n", lines);
|
||||||
|
for(String sql : joinedSQL.split(";"))
|
||||||
|
{
|
||||||
|
QueryManager.executeUpdate(connection, sql);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,8 +131,10 @@ public class TestUtils
|
|||||||
public static void runTestSql(String sql, QueryManager.ResultSetProcessor resultSetProcessor) throws Exception
|
public static void runTestSql(String sql, QueryManager.ResultSetProcessor resultSetProcessor) throws Exception
|
||||||
{
|
{
|
||||||
ConnectionManager connectionManager = new ConnectionManager();
|
ConnectionManager connectionManager = new ConnectionManager();
|
||||||
Connection connection = connectionManager.getConnection(defineDefaultH2Backend());
|
try(Connection connection = connectionManager.getConnection(defineDefaultH2Backend()))
|
||||||
QueryManager.executeStatement(connection, sql, resultSetProcessor);
|
{
|
||||||
|
QueryManager.executeStatement(connection, sql, resultSetProcessor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user