/** * Returns the columns list which is not nullable * * @param table * @return */ public static List getNotNullableColumns(BaseTable table) { if (table == null || table.getColumns() == null) { return new ArrayList(0); } List notNullableColumns = new ArrayList(); Iterator iter = table.getColumns().iterator(); while (iter.hasNext()) { Column col = (Column) iter.next(); if (!col.isNullable()) { notNullableColumns.add(col); } } return notNullableColumns; }
public static void removeColumnFromRefConstraints(BaseTable table, Column column) { Iterator iter = table.getConstraints().iterator(); while (iter.hasNext()) { Constraint constraint = (Constraint) iter.next(); if (constraint instanceof ReferenceConstraint) { ReferenceConstraint refConstraint = (ReferenceConstraint) constraint; if (refConstraint.getMembers().contains(column)) { refConstraint.getMembers().remove(column); } } } }
/** * Returns all the foreign keys which reference the given column * * @param table * @param column * @return */ public static List getMatchedColumnForeignKeys(BaseTable table, Column column) { List constraints = new ArrayList(); Iterator iter = table.getForeignKeys().iterator(); while (iter.hasNext()) { ForeignKey fk = (ForeignKey) iter.next(); List members = fk.getMembers(); if (members.size() < 1) { continue; } if (members.contains(column)) { constraints.add(fk); } } return constraints; }
public static List getMatchedColumnCheckConstraint(BaseTable table, Column column) { List constraints = new ArrayList(); Iterator iter = table.getConstraints().iterator(); while (iter.hasNext()) { Constraint obj = (Constraint) iter.next(); if (obj instanceof SybaseASABaseColumnCheckConstraint) { SybaseASABaseColumnCheckConstraint columnCk = (SybaseASABaseColumnCheckConstraint) obj; if (columnCk.getColumn() == column) { constraints.add(obj); } } } return constraints; }
/** * Returns all the unique constraints of the given table which only reference the given column * * @param table the base table * @param column the referencing column * @return */ public static List getMatchedColumnUniqueConstraint(BaseTable table, Column column) { List constraints = new ArrayList(); Iterator iter = table.getUniqueConstraints().iterator(); while (iter.hasNext()) { UniqueConstraint unique = (UniqueConstraint) iter.next(); List members = unique.getMembers(); if (members.size() != 1) { continue; } if (members.get(0).equals(column)) { constraints.add(unique); } } return constraints; }
/** * Checks if the given column is referenced in one of the reference constraints of the given table * * @param table * @param column * @return */ public static boolean isReferencedColumn(BaseTable table, Column column) { Iterator iter = table.getConstraints().iterator(); while (iter.hasNext()) { Constraint constraint = (Constraint) iter.next(); if (constraint instanceof ReferenceConstraint) { ReferenceConstraint refConstraint = (ReferenceConstraint) constraint; if (refConstraint.getMembers().contains(column)) { return true; } } if (constraint instanceof SybaseASABaseColumnCheckConstraint) { SybaseASABaseColumnCheckConstraint columnCk = (SybaseASABaseColumnCheckConstraint) constraint; if (columnCk.getColumn() == column) { return true; } } } return false; }
public String createTable(BaseTable table, boolean quoteIdentifiers, boolean qualifyNames) { StringBuffer statement = new StringBuffer(); boolean isTemp = table instanceof TemporaryTable; statement.append(CREATE).append(SPACE); if (isTemp) { if (((TemporaryTable) table).isLocal()) { statement.append(LOCAL).append(SPACE); } else { statement.append(GLOBAL).append(SPACE); } statement.append(TEMPORARY).append(SPACE); } statement .append(TABLE) .append(SPACE) .append(getName(table, quoteIdentifiers, qualifyNames)) .append(SPACE); statement.append(LEFT_PARENTHESIS).append(NEWLINE); List items = new ArrayList(); items.addAll(table.getColumns()); items.addAll(getTableConstraints(table)); Iterator it = items.iterator(); boolean first = true; while (it.hasNext()) { Object item = it.next(); String clause; if (item instanceof Column) { clause = getColumnString((Column) item, quoteIdentifiers); } else if (item instanceof CheckConstraint) { clause = getCheckConstraintClause((CheckConstraint) item, quoteIdentifiers); } else if (item instanceof UniqueConstraint) { clause = getUniqueConstraintClause((UniqueConstraint) item, quoteIdentifiers); } else { continue; } if (!first) { statement.append(COMMA); statement.append(NEWLINE); } else { first = false; } statement.append(TAB).append(clause); } statement.append(NEWLINE).append(RIGHT_PARENTHESIS); if (isTemp) { statement.append(NEWLINE).append(TAB).append(ON_COMMIT).append(SPACE); if (((TemporaryTable) table).isDeleteOnCommit()) { statement.append(DELETE).append(SPACE); } else { statement.append(PRESERVE).append(SPACE); } statement.append(ROWS); } return statement.append(NEWLINE).toString(); }