コード例 #1
0
  protected ResultSet getValues(
      RDBMSInformationTarget rdbmsInformationTarget, Statement statement, String identifier)
      throws SQLException {
    AbstactDialect dialect = getDialect(rdbmsInformationTarget);
    if (dialect == null) return null;

    String query =
        "SELECT "
            + dialect.getSQLColumnNamePrefix()
            + rdbmsInformationTarget.getColumnName()
            + dialect.getSQLColumnNameSuffix();

    if (identifier != null)
      query +=
          "," + dialect.getSQLColumnNamePrefix() + identifier + dialect.getSQLColumnNameSuffix();

    query +=
        " FROM "
            + dialect.getSQLTableNamePrefix()
            + rdbmsInformationTarget.getTableName()
            + dialect.getSQLTableNameSuffix();

    statement.executeQuery(query);
    try {
      return statement.getResultSet();
    } catch (Exception e) {
      logger.error("Error occured when getting result set", e);
      return null;
    }
  }
コード例 #2
0
 protected String getIdentifier(
     RDBMSInformationTarget rdbmsInformationTarget, Connection connection) throws SQLException {
   ResultSet rs = null;
   String identifier = null;
   try {
     rs =
         connection
             .getMetaData()
             .getPrimaryKeys(
                 rdbmsInformationTarget.getCatalogName(),
                 rdbmsInformationTarget.getSchemaName(),
                 rdbmsInformationTarget.getTableName());
     if (rs.next()) {
       identifier = rs.getString("COLUMN_NAME");
       if (rs.next()) // currently we do not support more than one pk;
       return null;
     }
     return identifier;
   } catch (SQLException e) {
     throw e;
   } finally {
     if (rs != null && !rs.isClosed()) rs.close();
   }
 }