private boolean isSameAsPrimaryKeyColumns(UniqueKey uniqueKey) { if (primaryKey == null || !primaryKey.columnIterator().hasNext()) { // happens for many-to-many tables return false; } return primaryKey.getColumns().containsAll(uniqueKey.getColumns()) && uniqueKey.getColumns().containsAll(primaryKey.getColumns()); }
/** * Called when the column is removed from its table. Removes the column from all table constraints * and indexes, then invalidates it. */ void remove() { Table table = getTable(); if (table == null) return; Schema schema = table.getSchema(); if (schema != null && schema.getSchemaGroup() != null) { Schema[] schemas = schema.getSchemaGroup().getSchemas(); Table[] tabs; ForeignKey[] fks; Column[] cols; Column[] pks; for (int i = 0; i < schemas.length; i++) { tabs = schemas[i].getTables(); for (int j = 0; j < tabs.length; j++) { fks = tabs[j].getForeignKeys(); for (int k = 0; k < fks.length; k++) { cols = fks[k].getColumns(); pks = fks[k].getPrimaryKeyColumns(); for (int l = 0; l < cols.length; l++) if (this.equals(cols[l]) || this.equals(pks[l])) fks[k].removeJoin(cols[l]); cols = fks[k].getConstantColumns(); for (int l = 0; l < cols.length; l++) if (this.equals(cols[l])) fks[k].removeJoin(cols[l]); pks = fks[k].getConstantPrimaryKeyColumns(); for (int l = 0; l < pks.length; l++) if (this.equals(pks[l])) fks[k].removeJoin(pks[l]); if (fks[k].getColumns().length == 0 && fks[k].getConstantColumns().length == 0) tabs[j].removeForeignKey(fks[k]); } } } } Index[] idxs = table.getIndexes(); for (int i = 0; i < idxs.length; i++) if (idxs[i].removeColumn(this) && idxs[i].getColumns().length == 0) table.removeIndex(idxs[i]); Unique[] unqs = table.getUniques(); for (int i = 0; i < unqs.length; i++) if (unqs[i].removeColumn(this) && unqs[i].getColumns().length == 0) table.removeUnique(unqs[i]); PrimaryKey pk = table.getPrimaryKey(); if (pk != null && pk.removeColumn(this) && pk.getColumns().length == 0) table.removePrimaryKey(); _table = null; }