Пример #1
0
  /** Basic test of DatabaseMetaData functions that access system tables */
  public void testTwo() throws Exception {

    Connection conn = newConnection();
    int updateCount;

    try {
      TestUtil.testScript(conn, "testrun/hsqldb/TestSelf.txt");

      DatabaseMetaData dbmeta = conn.getMetaData();

      dbmeta.allProceduresAreCallable();
      dbmeta.getBestRowIdentifier(null, null, "T_1", DatabaseMetaData.bestRowTransaction, true);
      dbmeta.getCatalogs();
      dbmeta.getColumnPrivileges(null, "PUBLIC", "T_1", "%");
      dbmeta.getColumns("PUBLIC", "PUBLIC", "T_1", "%");
      dbmeta.getCrossReference(null, null, "T_1", null, null, "T_1");
      dbmeta.getExportedKeys(null, null, "T_1");
      dbmeta.getFunctionColumns(null, "%", "%", "%");
      dbmeta.getFunctions(null, "%", "%");
      dbmeta.getImportedKeys("PUBLIC", "PUBLIC", "T_1");
      dbmeta.getIndexInfo("PUBLIC", "PUBLIC", "T1", true, true);
      dbmeta.getPrimaryKeys("PUBLIC", "PUBLIC", "T_1");
      dbmeta.getProcedureColumns(null, null, "%", "%");
      dbmeta.getProcedures("PUBLIC", "%", "%");
      dbmeta.getSchemas(null, "#");
      dbmeta.getTablePrivileges(null, "%", "%");
      dbmeta.getUDTs(null, "%", "%", new int[] {Types.DISTINCT});

    } catch (Exception e) {
      assertTrue("unable to prepare or execute DDL", false);
    } finally {
      conn.close();
    }
  }
  /**
   * Check the schema exists and if not we will use the default schema
   *
   * @return
   * @throws SQLException
   */
  private boolean isOracleSchemaValid() throws SQLException {

    logger.entering(CLASSNAME, "isOracleSchemaValid");
    boolean result = false;
    Connection conn = null;
    DatabaseMetaData dbmd = null;
    ResultSet rs = null;

    try {
      conn = getConnectionToDefaultSchema();
      dbmd = conn.getMetaData();
      rs = dbmd.getSchemas();

      while (rs.next()) {

        String schemaname = rs.getString("TABLE_SCHEM");
        if (schema.equalsIgnoreCase(schemaname)) {
          logger.exiting(CLASSNAME, "isSchemaValid", true);
          return true;
        }
      }
    } catch (SQLException e) {
      logger.severe(e.getLocalizedMessage());
      throw e;
    } finally {
      cleanupConnection(conn, rs, null);
    }
    logger.exiting(CLASSNAME, "isOracleSchemaValid", false);

    return result;
  }
Пример #3
0
 @Test
 public void columnOrderOfgetSchemas() throws SQLException {
   ResultSet rs = meta.getSchemas();
   assertFalse(rs.next());
   ResultSetMetaData rsmeta = rs.getMetaData();
   assertEquals(rsmeta.getColumnCount(), 2);
   assertEquals(rsmeta.getColumnName(1), "TABLE_SCHEM");
   assertEquals(rsmeta.getColumnName(2), "TABLE_CATALOG");
 }
 public ResultSet getSchemas() throws SQLException {
   _conn.checkOpen();
   try {
     return DelegatingResultSet.wrapResultSet(_conn, _meta.getSchemas());
   } catch (SQLException e) {
     handleException(e);
     throw new AssertionError();
   }
 }
Пример #5
0
  @Signature
  public Memory getSchemas(Environment env) throws SQLException {
    ResultSet schemas = metaData.getSchemas();
    ArrayMemory r = new ArrayMemory();

    while (schemas.next()) {
      r.add(new PSqlResult(env, schemas).toArray(env));
    }

    return r.toConstant();
  }
Пример #6
0
 public static String[] getSchemas(Connection connection) throws Exception {
   if (connection != null) {
     List<String> schemaList = new ArrayList<String>();
     DatabaseMetaData mObject = connection.getMetaData();
     ResultSet schemas = mObject.getSchemas();
     while (schemas.next()) {
       schemaList.add(schemas.getString(DBConstants.DataServiceGenerator.TABLE_SCHEM));
     }
     String str[] = schemaList.toArray(new String[schemaList.size()]);
     return str;
   } else {
     return null;
   }
 }
  /**
   * Returns schemas in the currently connected database. {@inheritDoc}
   *
   * @see com.continuent.tungsten.replicator.database.Database#getSchemas()
   */
  public ArrayList<String> getSchemas() throws SQLException {
    ArrayList<String> schemas = new ArrayList<String>();

    try {
      DatabaseMetaData md = this.getDatabaseMetaData();
      ResultSet rs = md.getSchemas();
      while (rs.next()) {
        schemas.add(rs.getString("TABLE_SCHEM"));
      }
      rs.close();
    } finally {
    }

    return schemas;
  }
Пример #8
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()]);
 }
Пример #9
0
 @Test
 public void testSchemas() throws Exception {
   TestMMDatabaseMetaData.compareResultSet(dbMetadata.getSchemas()); // $NON-NLS-1$
 }
  /** TODO: runTask definition. */
  private void runTask() {
    connection = null;
    try {
      connection = DatabaseFactory.createDatabase(url, user, password);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try {
      connection.connect();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    if (ignoreTablesFile != null) {
      ignoreTablesDefinition = new ChunkDefinitions(ignoreTablesFile);
      try {
        ignoreTablesDefinition.parseFile();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    // Check whether we have to use a chunk definition file
    if (chunkDefFile != null) {
      logger.info("Using definition from file " + chunkDefFile);
      chunkDefinition = new ChunkDefinitions(chunkDefFile);
      try {
        chunkDefinition.parseFile();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ReplicatorException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      LinkedList<ChunkRequest> chunksDefinitions = chunkDefinition.getChunksDefinitions();
      for (ChunkRequest chunkRequest : chunksDefinitions) {
        if (chunkRequest.getTable() != null) {
          try {
            Table table =
                connection.findTable(chunkRequest.getSchema(), chunkRequest.getTable(), true);

            if (table != null)
              generateChunksForTable(table, chunkRequest.getChunkSize(), chunkRequest.getColumns());
            else
              logger.warn(
                  "Failed while processing table "
                      + chunkRequest.getSchema()
                      + "."
                      + chunkRequest.getTable()
                      + " : table not found.");
          } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (ReplicatorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        } else if (chunkRequest.getSchema() != null) {
          generateChunksForSchema(chunkRequest.getSchema());
        }
      }
    } else {
      try {
        DatabaseMetaData databaseMetaData = connection.getDatabaseMetaData();
        ResultSet schemasRs = databaseMetaData.getSchemas();
        while (schemasRs.next()) {
          String schemaName = schemasRs.getString("TABLE_SCHEM");
          // TODO: System schemas could be needed -> this needs a
          // setting
          if (!connection.isSystemSchema(schemaName)) {
            generateChunksForSchema(schemaName);
          }
        }
        schemasRs.close();
      } catch (SQLException e) {
        logger.error(e);
      } catch (Exception e) {
        logger.error(e);
      }
    }

    // Stop threads
    for (int i = 0; i < extractChannels; i++) {
      logger.info("Posting job complete request " + i);
      try {
        chunks.put(new NumericChunk());
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    if (logger.isDebugEnabled()) logger.debug(this.getName() + " done.");
  }
 public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException {
   return throwExceptionDelegate.getSchemas(catalog, schemaPattern);
 }
 public ResultSet getSchemas() throws SQLException {
   return throwExceptionDelegate.getSchemas();
 }