예제 #1
0
  /**
   * Initialize index information
   *
   * @throws SQLException
   */
  private void initIndexes() throws SQLException {
    if (isView() || isRemote()) return;

    // first try to initialize using the index query spec'd in the .properties
    // do this first because some DB's (e.g. Oracle) do 'bad' things with getIndexInfo()
    // (they try to do a DDL analyze command that has some bad side-effects)
    if (initIndexes(properties.getProperty("selectIndexesSql"))) return;

    // couldn't, so try the old fashioned approach
    ResultSet rs = null;

    try {
      rs = db.getMetaData().getIndexInfo(null, getSchema(), getName(), false, true);

      while (rs.next()) {
        if (rs.getShort("TYPE") != DatabaseMetaData.tableIndexStatistic) addIndex(rs);
      }
    } catch (SQLException exc) {
      logger.warning(
          "Unable to extract index info for table '"
              + getName()
              + "' in schema '"
              + getSchema()
              + "': "
              + exc);
    } finally {
      if (rs != null) rs.close();
    }
  }
예제 #2
0
  /**
   * Try to initialize index information based on the specified SQL
   *
   * @return boolean <code>true</code> if it worked, otherwise <code>false</code>
   */
  private boolean initIndexes(String selectIndexesSql) {
    if (selectIndexesSql == null) return false;

    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      stmt = db.prepareStatement(selectIndexesSql, getName());
      rs = stmt.executeQuery();

      while (rs.next()) {
        if (rs.getShort("TYPE") != DatabaseMetaData.tableIndexStatistic) addIndex(rs);
      }
    } catch (SQLException sqlException) {
      logger.warning("Failed to query index information with SQL: " + selectIndexesSql);
      logger.warning(sqlException.toString());
      return false;
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (Exception exc) {
          exc.printStackTrace();
        }
      }
      if (stmt != null) {
        try {
          stmt.close();
        } catch (Exception exc) {
          exc.printStackTrace();
        }
      }
    }

    return true;
  }