public void cleanupAllTables() throws IOException { for (final String tableName : allTables) { cleanupTable(tableName); } }
protected void executeQuery(final String query) throws SQLException, IOException { executeQuery(query, new ResultSetJob()); }
protected void execute(final String query) throws SQLException, IOException { execute(query, new ResultSetJob()); }
protected void executeQuery(final String query, final ResultSetJob job) throws SQLException, IOException { final Connection connection = getConnection(); Statement statement = null; try { statement = connection.createStatement(); final ResultSet rs = statement.executeQuery(query); job.work(rs); } finally { if (statement != null) { statement.close(); } connection.close(); } }
protected Connection getConnection() throws SQLException, IOException { return getDataSource().getConnection(); }
public void cleanupTable(final String table) throws IOException { logger.debug("Deleting table: " + table); try { executeQuery("truncate table " + table); } catch (SQLException e) { throw new IOException(e); } }
public void executeScript(final String script) throws IOException { final String[] rawStatements = script.replaceAll("\n", " ").replaceAll("\r", "").split(";"); for (final String statement : rawStatements) { if (!WHITESPACE_ONLY.matcher(statement).matches()) { try { // TODO consider batch approach execute(statement); } catch (SQLException e) { throw new IOException(e); } } } }
@Override protected void configure() { if (EmbeddedDB.DBEngine.MYSQL.equals(helper.getDBEngine())) { install(new GlobalLockerModule()); } else { install(new MockGlobalLockerModule()); } } }
@BeforeMethod(groups = {"slow", "mysql"}) public void beforeMethod() throws Exception { try { DBTestingHelper.get().cleanupAllTables(); } catch (Exception ignored) { } }
protected void executeQuery(final String query, final ResultSetJob job) throws SQLException, IOException { final Connection connection = getConnection(); Statement statement = null; try { statement = connection.createStatement(); final ResultSet rs = statement.executeQuery(query); job.work(rs); } finally { if (statement != null) { statement.close(); } connection.close(); } }
protected void executeQuery(final String query) throws SQLException, IOException { executeQuery(query, new ResultSetJob()); }
protected void execute(final String query) throws SQLException, IOException { execute(query, new ResultSetJob()); }
protected Connection getConnection() throws SQLException, IOException { return getDataSource().getConnection(); }
public void cleanupAllTables() throws IOException { for (final String tableName : allTables) { cleanupTable(tableName); } }
public void cleanupTable(final String table) throws IOException { logger.debug("Deleting table: " + table); try { executeQuery("truncate table " + table); } catch (SQLException e) { throw new IOException(e); } }
public void executeScript(final String script) throws IOException { final String[] rawStatements = script.replaceAll("\n", " ").replaceAll("\r", "").split(";"); for (final String statement : rawStatements) { if (!WHITESPACE_ONLY.matcher(statement).matches()) { try { // TODO consider batch approach execute(statement); } catch (SQLException e) { throw new IOException(e); } } } }
@BeforeMethod(groups = {"slow", "mysql"}) public void cleanupTablesBetweenMethods() { try { DBTestingHelper.get().cleanupAllTables(); } catch (Exception ignored) { } }
protected void execute(final String query, final ResultSetJob job) throws SQLException, IOException { final Connection connection = getConnection(); Statement statement = null; try { statement = connection.createStatement(); if (statement.execute(query)) { job.work(statement.getResultSet()); } } finally { if (statement != null) { statement.close(); } connection.close(); } }
public static synchronized IDBI getDBI() throws IOException { return new DBIProvider(get().getDataSource()).get(); }
protected void execute(final String query, final ResultSetJob job) throws SQLException, IOException { final Connection connection = getConnection(); Statement statement = null; try { statement = connection.createStatement(); if (statement.execute(query)) { job.work(statement.getResultSet()); } } finally { if (statement != null) { statement.close(); } connection.close(); } }