Exemplo n.º 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()));
  }
Exemplo n.º 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));
  }
Exemplo n.º 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;
  }
Exemplo n.º 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);
  }
Exemplo n.º 5
0
 private void truncate(String table) {
   connectionManager.execute(String.format("truncate table %s cascade", table));
 }
Exemplo n.º 6
0
 public void recreate(String schema) {
   connectionManager.execute(
       String.format("drop schema %s cascade; create schema %s;", schema, schema));
 }
Exemplo n.º 7
0
 private void createTable(String kind) {
   connectionManager.execute(String.format(SQL_TABLE_CREATE, kind));
 }