示例#1
0
  /*
   * Generates Primary Key constraint string if table has a PK
   * Will be of form: "CONSTRAINT pkName PRIMARY KEY (col1)"
   */
  private static String getPkConstraint(UnitOfWork uow, TeiidVersion teiidVersion, Table table)
      throws KException {
    StringBuilder sb = new StringBuilder();

    // Look for pk column
    PrimaryKey pk = table.getPrimaryKey(uow);
    if (pk != null) {
      sb.append("CONSTRAINT "); // $NON-NLS-1$
      sb.append(escapeSQLName(teiidVersion, pk.getName(uow)));
      sb.append(" PRIMARY KEY ("); // $NON-NLS-1$
      Column[] pkCols = pk.getColumns(uow);
      for (int i = 0; i < pkCols.length; i++) {
        if (i != 0) sb.append(StringConstants.COMMA + StringConstants.SPACE);
        sb.append(escapeSQLName(teiidVersion, pkCols[i].getName(uow)));
      }
      sb.append(StringConstants.CLOSE_BRACKET);
    }
    return sb.toString();
  }
示例#2
0
  private static Set<String> getConstraintColumnNames(UnitOfWork uow, Table table)
      throws KException {
    Set<String> constraintCols = new HashSet<String>();

    // Add primary key column if present
    PrimaryKey pk = table.getPrimaryKey(uow);
    if (pk != null) {
      Column[] pkCols = pk.getColumns(uow);
      for (Column pkCol : pkCols) {
        constraintCols.add(pkCol.getName(uow));
      }
    } else {
      // Add UC column names if present
      UniqueConstraint[] ucs = table.getUniqueConstraints(uow);
      for (UniqueConstraint uc : ucs) {
        Column[] ucCols = uc.getColumns(uow);
        for (Column col : ucCols) {
          constraintCols.add(col.getName(uow));
        }
      }
    }

    return constraintCols;
  }