예제 #1
0
  /**
   * Removes previous ra/dec index, if it is found.
   *
   * @param dbConn database connection
   * @param tapTableInfo current database information.
   * @return 'true' if the field has been updated.
   * @throws DBException
   */
  public static boolean removePrevRaDecIfExists(
      JDBCPooledFunctions dbConn, TapTableInfo tapTableInfo) throws DBException {
    String raColumn = null;
    String decColumn = null;
    int flags = 0;
    for (String tableColumnName : tapTableInfo.getTableColumnNames()) {
      // tapTableInfo contains database current info: flags is an integer in database (it can be
      // null)
      flags = Utils.getFlagsFromTapTable(tapTableInfo, tableColumnName);
      if ((flags & Utils.TAP_COLUMN_TABLE_FLAG_RA) > 0) {
        raColumn = tableColumnName;
        continue;
      }
      if ((flags & Utils.TAP_COLUMN_TABLE_FLAG_DEC) > 0) {
        decColumn = tableColumnName;
        continue;
      }
    }
    if (raColumn == null || decColumn == null) {
      // wrong ra/dec specification, no index created.
      return false;
    }

    // we have the previous ra/dec indexed columns, remove them
    dbConn.removeRaAndDecIndexes(
        tapTableInfo.getSchemaName(),
        tapTableInfo.getTableName(),
        raColumn,
        decColumn,
        Utils.TAP_TABLE_TYPE_RADEC);
    return true;
  }
예제 #2
0
  /**
   * Creates a ra/dec index.<br>
   * Checks whether ra/dec are already indexed.<br>
   * The previous ra/dec index is removed (if it is found).<br>
   *
   * @param dbConn database connection.
   * @param tapTableInfo current database information.
   * @param raColumn
   * @param decColumn
   * @return 'true' if the field has been updated.
   * @throws DBException
   */
  public static boolean indexRaDec(
      JDBCPooledFunctions dbConn, TapTableInfo tapTableInfo, String raColumn, String decColumn)
      throws DBException {
    if (raColumn == null) {
      throw new IllegalArgumentException("Ra column not found");
    }
    if (decColumn == null) {
      throw new IllegalArgumentException("Dec column not found");
    }

    // If it is already indexed, do not index again.
    // Remove old Ra/Dec if they are not the same columns.
    boolean alreadyIndexed = Utils.areAlreadyIndexedRaDec(tapTableInfo, raColumn, decColumn);
    if (alreadyIndexed) {
      // Nothing to do, ra/dec are already indexed on the same columns.
      return false;
    }

    // Not the same columns.
    // Remove previous ra/dec if they exists
    removePrevRaDecIfExists(dbConn, tapTableInfo);

    // Create new indexes
    dbConn.createRaAndDecIndexes(
        tapTableInfo.getSchemaName(),
        tapTableInfo.getTableName(),
        raColumn,
        decColumn,
        Utils.TAP_TABLE_TYPE_RADEC);
    return true;
  }