예제 #1
0
  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()));
  }
예제 #2
0
  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));
  }
예제 #3
0
  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;
  }
예제 #4
0
  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);
  }
예제 #5
0
 private void truncate(String table) {
   connectionManager.execute(String.format("truncate table %s cascade", table));
 }
예제 #6
0
 public void recreate(String schema) {
   connectionManager.execute(
       String.format("drop schema %s cascade; create schema %s;", schema, schema));
 }
예제 #7
0
 private void createTable(String kind) {
   connectionManager.execute(String.format(SQL_TABLE_CREATE, kind));
 }