public void create() { if (databaseExists()) { return; } initConnectionManager.execute( new SqlRunner(SQL_DATABASE_KILL_ACTIVITY) { @Override protected void bind() { bind("database", initDatabase()); } }); initConnectionManager.execute(String.format(SQL_DATABASE_CREATE, currentDatabase())); }
public void drop() { if (!databaseExists()) { return; } final String database = currentDatabase(); initConnectionManager.execute( new SqlRunner(SQL_DATABASE_KILL_ACTIVITY) { @Override protected void bind() { bind("database", database); } }); initConnectionManager.execute(String.format(SQL_DATABASE_DROP, database)); }
public boolean databaseExists() { final String database = currentDatabase(); Boolean exists = initConnectionManager.executeQuery( new SqlRunner(SQL_DATABASE_EXISTS) { @Override protected void bind() { bind("database", database); } @Override protected Boolean collectSingle(ResultSet rs) throws SQLException { return Boolean.TRUE; } }); return exists != null && exists; }
protected List<String> getExistingTables() { String sql = String.format("%s %s", SQL_CATALOG_SELECT, SQL_CATALOG_TABLES); SqlRunner runner = new SqlRunner(sql) { @Override public List<String> collect(ResultSet rs) throws SQLException { List<String> tables = new ArrayList<String>(); while (rs.next()) { tables.add(rs.getString("relname")); } return tables; } }; return connectionManager.executeQuery(runner); }
private void truncate(String table) { connectionManager.execute(String.format("truncate table %s cascade", table)); }
public void recreate(String schema) { connectionManager.execute( String.format("drop schema %s cascade; create schema %s;", schema, schema)); }
private void createTable(String kind) { connectionManager.execute(String.format(SQL_TABLE_CREATE, kind)); }