Esempio n. 1
0
  public String getTableSpace(Connection connection) throws SQLException {
    String tableSpace = tableSpaces.get(connection.schema());

    if (tableSpace == null) {
      tableSpace = getTableSpace(connection, "INDEX", "IDX");
      tableSpaces.put(connection.schema(), tableSpace);
    }

    return tableSpace;
  }
Esempio n. 2
0
  public static String getTableSpace(Connection connection, String dataFile1, String dataFile2)
      throws SQLException {
    String sql = null;
    String result = "";

    switch (connection.vendor()) {
      case Oracle:
        {
          sql =
              "SELECT TO_NCHAR(q.tablespace_name) AS TBS FROM user_ts_quotas q inner join user_tablespaces t on (q.tablespace_name=t.tablespace_name) WHERE (upper(q.tablespace_name) like '%"
                  + dataFile1
                  + "'  ESCAPE '/' or  upper(q.tablespace_name) like '%"
                  + dataFile2
                  + "' ESCAPE '/') AND q.max_bytes<>0";
          break;
        }
      case SqlServer:
        {
          sql =
              "select Convert(nvarchar(max), groupname) as TBS from sysfilegroups where (upper(groupname) like '%"
                  + dataFile1
                  + "' or upper(groupname) like '%"
                  + dataFile2
                  + "') and (status & 8 <> 8)";
          break;
        }
      default:
        {
          return result;
        }
    }

    Cursor cursor = BasicSelect.cursor(connection, sql);
    result = cursor.next() ? cursor.getString(1).get() : "";
    cursor.close();

    if (result.isEmpty()) {
      return result;
    }

    switch (connection.vendor()) {
      case Oracle:
        return " TABLESPACE " + result;
      case SqlServer:
        return " ON " + result;
      default:
        throw new UnknownDatabaseException();
    }
  }
Esempio n. 3
0
 static void dropIndex(Connection conn, String tableName, String indexName) throws SQLException {
   switch (conn.vendor()) {
     case Postgres:
     case Oracle:
       dropIndexOracle(conn, tableName, indexName);
       break;
     case SqlServer:
       dropIndexSQLServer(conn, tableName, indexName);
       break;
     default:
       throw new UnsupportedOperationException();
   }
 }
Esempio n. 4
0
  void run(Connection connection) throws SQLException {
    Database database = connection.database();
    DatabaseVendor vendor = database.vendor();

    String sql =
        "CREATE "
            + (unique ? "UNIQUE " : "")
            + "INDEX "
            + vendor.quote((unique ? "UNQ_" : "IDX_") + table.name() + "_" + id)
            + " "
            + "ON "
            + database.tableName(table.name())
            + "("
            + formatIndexFields(vendor)
            + ")"
            + getTableSpace(connection);

    Statement.executeUpdate(connection, sql);
  }
Esempio n. 5
0
 private static void dropIndexSQLServer(Connection connection, String tableName, String indexName)
     throws SQLException {
   DatabaseVendor vendor = connection.vendor();
   String sql = "drop index " + vendor.quote(tableName) + "." + vendor.quote(indexName);
   Statement.executeUpdate(connection, sql);
 }
Esempio n. 6
0
 private static void dropIndexOracle(Connection connection, String tableName, String indexName)
     throws SQLException {
   Database database = connection.database();
   String sql = "drop index " + database.tableName(indexName);
   Statement.executeUpdate(connection, sql);
 }