/** Constructor declaration for PK and UNIQUE */ public Constraint(HsqlName name, Table t, Index index, int type) { core = new ConstraintCore(); this.name = name; constType = type; core.mainTable = t; core.mainIndex = index; core.mainCols = index.getColumns(); }
void setColumnsIndexes(Table table) { if (constType == Constraint.FOREIGN_KEY) { if (mainColSet == null) { core.mainCols = core.mainTable.getPrimaryKey(); if (core.mainCols == null) { throw Error.error(ErrorCode.X_42581); } } else if (core.mainCols == null) { core.mainCols = core.mainTable.getColumnIndexes(mainColSet); } if (core.refCols == null) { core.refCols = table.getColumnIndexes(refColSet); } } else if (mainColSet != null) { core.mainCols = table.getColumnIndexes(mainColSet); } }
/** * Used to update constrains to reflect structural changes in a table. Prior checks must ensure * that this method does not throw. * * @param session Session * @param oldTable reference to the old version of the table * @param newTable referenct to the new version of the table * @param colIndex index at which table column is added or removed * @param adjust -1, 0, +1 to indicate if column is added or removed @ */ void updateTable(Session session, Table oldTable, Table newTable, int colIndex, int adjust) { if (oldTable == core.mainTable) { core.mainTable = newTable; if (core.mainIndex != null) { core.mainIndex = core.mainTable.getIndex(core.mainIndex.getName().name); core.mainCols = ArrayUtil.toAdjustedColumnArray(core.mainCols, colIndex, adjust); } } if (oldTable == core.refTable) { core.refTable = newTable; if (core.refIndex != null) { core.refIndex = core.refTable.getIndex(core.refIndex.getName().name); core.refCols = ArrayUtil.toAdjustedColumnArray(core.refCols, colIndex, adjust); } } // CHECK if (constType == CHECK) { recompile(session, newTable); } }
/** * General constructor for foreign key constraints. * * @param name name of constraint * @param refCols list of referencing columns * @param mainTableName referenced table * @param mainCols list of referenced columns * @param type constraint type * @param deleteAction triggered action on delete * @param updateAction triggered action on update */ public Constraint( HsqlName name, HsqlName refTableName, OrderedHashSet refCols, HsqlName mainTableName, OrderedHashSet mainCols, int type, int deleteAction, int updateAction, int matchType) { core = new ConstraintCore(); this.name = name; constType = type; mainColSet = mainCols; core.refTableName = refTableName; core.mainTableName = mainTableName; refColSet = refCols; core.deleteAction = deleteAction; core.updateAction = updateAction; core.matchType = matchType; }
Constraint duplicate() { Constraint copy = new Constraint(); copy.core = core.duplicate(); copy.name = name; copy.constType = constType; copy.isForward = isForward; // copy.check = check; copy.isNotNull = isNotNull; copy.notNullColumnIndex = notNullColumnIndex; copy.rangeVariable = rangeVariable; copy.schemaObjectNames = schemaObjectNames; return copy; }
ConstraintCore duplicate() { ConstraintCore copy = new ConstraintCore(); copy.refName = refName; copy.mainName = mainName; copy.uniqueName = uniqueName; copy.mainTable = mainTable; copy.mainCols = mainCols; copy.mainIndex = mainIndex; copy.refTable = refTable; copy.refCols = refCols; copy.refIndex = refIndex; copy.deleteAction = deleteAction; copy.updateAction = updateAction; copy.matchType = matchType; return copy; }