private static void addConditionForSerialField(DBAttributeDescriptor attr, StringBuffer sqlSeq) {
    sqlSeq.append(" (");
    sqlSeq.append(" column_name = '" + attr.getName() + "'");
    sqlSeq.append("  and table_name = '" + attr.getTableName() + "'");
    if (attr.getSchemaName() != null && attr.getSchemaName().length() > 0) {
      sqlSeq.append("  and table_schema = '" + attr.getSchemaName() + "'");
    }

    sqlSeq.append("  and table_catalog = '" + attr.getCatalogName() + "'");
    sqlSeq.append(")");
  }
  private static void initializeSerialFields(Connection connection, DBFeatureType featureType)
      throws java.sql.SQLException, DataException {
    DBAttributeDescriptor attr;

    ArrayList serialCandidates = new ArrayList();
    Iterator iter = featureType.iterator();
    while (iter.hasNext()) {
      attr = (DBAttributeDescriptor) iter.next();
      if (attr.getSqlTypeName().equals("int4")
          && attr.getTableName() != null
          && attr.getTableName().length() > 0) {
        serialCandidates.add(attr);
      }
    }
    if (serialCandidates.size() == 0) {
      return;
    }
    Statement st = connection.createStatement();
    StringBuffer sqlSeq =
        new StringBuffer(
            "select table_catalog,table_schema,table_name,column_name from information_schema.columns where column_default like 'nextval(%'  and ( ");
    iter = serialCandidates.iterator();
    String sql;
    int i;
    for (i = 0; i < serialCandidates.size() - 1; i++) {
      attr = (DBAttributeDescriptor) serialCandidates.get(i);
      addConditionForSerialField(attr, sqlSeq);
      sqlSeq.append(" or ");
    }
    attr = (DBAttributeDescriptor) serialCandidates.get(i);
    addConditionForSerialField(attr, sqlSeq);

    sqlSeq.append(")");
    sql = sqlSeq.toString();
    ResultSet rs = st.executeQuery(sql);
    while (rs.next()) {
      iter = serialCandidates.iterator();
      while (iter.hasNext()) {
        attr = (DBAttributeDescriptor) iter.next();
        if (rs.getString("column_name").equals(attr.getName())) {
          attr.setAutoIncrement(true);
          serialCandidates.remove(attr);
          break;
        }
      }
    }
  }