updateColumnsRefs((Table) src_view.getParent(), src_view.getGroupbycols(), (Table) dest_view.getParent(), dest_view.getGroupbycols());
// Index
} else if (src_item instanceof Index) {
// ColumnRefs
Index src_idx = (Index) src_item;
Index dest_idx = (Index) clone;
updateColumnsRefs((Table) src_idx.getParent(), src_idx.getColumns(), (Table) dest_idx.getParent(), dest_idx.getColumns());
// Constraint
} else if (src_item instanceof Constraint) {
// ColumnRefs
Constraint src_cons = (Constraint) src_item;
Constraint dest_cons = (Constraint) clone;
Table src_fkey_tbl = src_cons.getForeignkeytable();
if (src_fkey_tbl != null) {
Database dest_db = (Database) dest_cons.getParent().getParent();
Table dest_fkey_tbl = dest_db.getTables().get(src_fkey_tbl.getName());
if (dest_fkey_tbl != null) {
dest_cons.setForeignkeytable(dest_fkey_tbl);
for (ColumnRef src_cref : ((Constraint) src_item).getForeignkeycols()) {
CatalogCloner.clone(src_cref, dest_catalog);
// Correct what it's pointing to
ColumnRef dest_colref = dest_cons.getForeignkeycols().get(src_cref.getName());
assert (dest_colref != null);
dest_colref.setColumn(dest_fkey_tbl.getColumns().get(src_cref.getColumn().getName()));
} // FOR
}
}
// Important: We have to add ConstraintRefs to Columns *after* we add the columns
Table src_tbl = (Table) src_cons.getParent();
Table dest_tbl = (Table) dest_cons.getParent();
for (Column src_col : src_tbl.getColumns()) {
Column dest_col = dest_tbl.getColumns().get(src_col.getName());
assert (dest_col != null);
for (ConstraintRef src_conref : src_col.getConstraints()) {
if (!src_conref.getConstraint().equals(src_cons))
continue;
CatalogCloner.clone(src_conref, dest_catalog);
// Correct what it's pointing to
ConstraintRef dest_conref = dest_col.getConstraints().get(src_conref.getName());
assert (dest_conref != null);
// System.out.println("dest_tbl: " + dest_tbl);
// System.out.println("dest_tbl.getConstraints(): " +
// CatalogUtil.debug(dest_tbl.getConstraints()));
// System.out.println("src_confref: " + src_conref);
// System.out.println("src_confref.getConstraint(): " +
// src_conref.getConstraint());
dest_conref.setConstraint(dest_tbl.getConstraints().get(src_conref.getConstraint().getName()));
} // FOR
} // FOR
Index src_index = src_cons.getIndex();
if (src_index != null) {
Index dest_index = dest_tbl.getIndexes().get(src_index.getName());
dest_cons.setIndex(dest_index);
}
// StmtParameter
} else if (src_item instanceof StmtParameter) {