Exemplo n.º 1
0
 /**
  * Get a list of all table columns for the given combination of schema name and table name.
  *
  * @param conn database connection
  * @param schema schema name
  * @param table table name
  * @return list of all table columns
  * @throws SQLException Thrown if an SQL statement failed to be executed.
  */
 private static String[] getColumns(final Connection conn, final String schema, final String table)
     throws SQLException {
   final ArrayList<String> result = new ArrayList<String>();
   final DatabaseMetaData metaData = conn.getMetaData();
   ResultSet rs = null;
   try {
     rs = metaData.getColumns(conn.getCatalog(), schema, table, null);
     final int columns = rs.getMetaData().getColumnCount();
     while (rs.next()) {
       final StringBuilder column = new StringBuilder();
       for (int index = 4; (index <= columns) && (index <= 22); index++) {
         // ignore column position
         if (index != 17) {
           if (column.length() > 0) {
             column.append('/');
           }
           column.append(rs.getString(index));
         }
       }
       result.add(column.toString());
     }
   } finally {
     IOUtils.closeResultSet(rs);
   }
   return result.toArray(new String[result.size()]);
 }
Exemplo n.º 2
0
 /**
  * Get a list of all schemas for the given connection.
  *
  * @param conn database connection
  * @return list of all schemas
  * @throws SQLException Thrown if an SQL statement failed to be executed.
  */
 private static String[] getSchemaNames(final Connection conn) throws SQLException {
   final ArrayList<String> result = new ArrayList<String>();
   final DatabaseMetaData metaData = conn.getMetaData();
   ResultSet rs = null;
   try {
     rs = metaData.getSchemas();
     while (rs.next()) {
       final String schema = rs.getString(1);
       if (KNOWN_SCHEMAS.contains(schema.toLowerCase(Locale.ENGLISH))) {
         result.add(schema);
       }
     }
   } finally {
     IOUtils.closeResultSet(rs);
   }
   return result.toArray(new String[result.size()]);
 }
Exemplo n.º 3
0
 /**
  * Get a list of all tables for the given schema.
  *
  * @param conn database connection
  * @param schema schema name
  * @return list of all tables
  * @throws SQLException Thrown if an SQL statement failed to be executed.
  */
 private static String[] getTableNames(final Connection conn, final String schema)
     throws SQLException {
   final ArrayList<String> result = new ArrayList<String>();
   final DatabaseMetaData metaData = conn.getMetaData();
   ResultSet rs = null;
   try {
     rs = metaData.getTables(conn.getCatalog(), schema, null, new String[] {"TABLE"});
     while (rs.next()) {
       final String name = rs.getString(3);
       // ignore dynamically created tables for statistics manager
       if (!"sm".equalsIgnoreCase(schema)
           || VALID_SM_TABLES.contains(name.toLowerCase(Locale.ENGLISH))) {
         result.add(name);
       }
     }
   } finally {
     IOUtils.closeResultSet(rs);
   }
   return result.toArray(new String[result.size()]);
 }
Exemplo n.º 4
0
 /**
  * Get a list of all primary keys that are defined for the table.
  *
  * @param conn database connection
  * @param schema schema name
  * @param table table name
  * @return list of all primary keys
  * @throws SQLException Thrown if an SQL statement failed to be executed.
  */
 private static String[] getPrimaryKeys(
     final Connection conn, final String schema, final String table) throws SQLException {
   final ArrayList<String> result = new ArrayList<String>();
   final DatabaseMetaData metaData = conn.getMetaData();
   ResultSet rs = null;
   try {
     rs = metaData.getPrimaryKeys(conn.getCatalog(), schema, table);
     while (rs.next()) {
       final StringBuilder indexInfo = new StringBuilder();
       for (int index = 4; index <= 6; index++) {
         if (indexInfo.length() > 0) {
           indexInfo.append('/');
         }
         indexInfo.append(rs.getString(index));
       }
       result.add(indexInfo.toString());
     }
   } finally {
     IOUtils.closeResultSet(rs);
   }
   return result.toArray(new String[result.size()]);
 }