private String generateConstraintName(Table table) { if (constraintName == null) { constraintName = getSchema().getUniqueConstraintName( session, table); } return constraintName; }
@Override public int update() { try { return tryUpdate(); } catch (DbException e) { for (Index index : createdIndexes) { session.getDatabase().removeSchemaObject(session, index); } throw e; } finally { getSchema().freeUniqueName(constraintName); } }
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) { int indexId = getObjectId(); IndexType indexType; if (unique) { // for unique constraints indexType = IndexType.createUnique(t.isPersistIndexes(), false); } else { // constraints indexType = IndexType.createNonUnique(t.isPersistIndexes()); } indexType.setBelongsToConstraint(true); String prefix = constraintName == null ? "CONSTRAINT" : constraintName; String indexName = t.getSchema().getUniqueIndexName(session, t, prefix + "_INDEX_"); try { Index index = t.addIndex(session, indexName, indexId, cols, indexType, true, null); createdIndexes.add(index); return index; } finally { getSchema().freeUniqueName(indexName); } }
Table table = getSchema().findTableOrView(session, tableName); if (table == null) { if (ifTableExists) { if (getSchema().findConstraint(session, constraintName) != null) { if (ifNotExists) { return 0; indexColumns, indexType, true, null); } finally { getSchema().freeUniqueName(indexName); int constraintId = getObjectId(); String name = generateConstraintName(table); ConstraintUnique pk = new ConstraintUnique(getSchema(), constraintId, name, table, true); pk.setColumns(indexColumns); ConstraintUnique unique = new ConstraintUnique(getSchema(), id, name, table, false); unique.setColumns(indexColumns); int id = getObjectId(); String name = generateConstraintName(table); ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table); TableFilter filter = new TableFilter(session, table, null, false, null, 0, null); checkExpression.mapColumns(filter, 0); ConstraintReferential refConstraint = new ConstraintReferential(getSchema(),
private String generateConstraintName(DbObject obj, int id) throws SQLException { if (constraintName == null) { constraintName = getSchema().getUniqueConstraintName(obj); } return constraintName; }
private String generateConstraintName(Table table) { if (constraintName == null) { constraintName = getSchema().getUniqueConstraintName( session, table); } return constraintName; }
private String generateConstraintName(Table table) { if (constraintName == null) { constraintName = getSchema().getUniqueConstraintName( session, table); } return constraintName; }
public int update() throws SQLException { try { return tryUpdate(); } finally { getSchema().freeUniqueName(constraintName); } }
@Override public int update() { try { return tryUpdate(); } catch (DbException e) { for (Index index : createdIndexes) { session.getDatabase().removeSchemaObject(session, index); } throw e; } finally { getSchema().freeUniqueName(constraintName); } }
@Override public int update() { try { return tryUpdate(); } catch (DbException e) { for (Index index : createdIndexes) { session.getDatabase().removeSchemaObject(session, index); } throw e; } finally { getSchema().freeUniqueName(constraintName); } }
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) { int indexId = getObjectId(); IndexType indexType; if (unique) { // for unique constraints indexType = IndexType.createUnique(t.isPersistIndexes(), false); } else { // constraints indexType = IndexType.createNonUnique(t.isPersistIndexes()); } indexType.setBelongsToConstraint(true); String prefix = constraintName == null ? "CONSTRAINT" : constraintName; String indexName = t.getSchema().getUniqueIndexName(session, t, prefix + "_INDEX_"); try { Index index = t.addIndex(session, indexName, indexId, cols, indexType, true, null); createdIndexes.add(index); return index; } finally { getSchema().freeUniqueName(indexName); } }
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) { int indexId = getObjectId(); IndexType indexType; if (unique) { // for unique constraints indexType = IndexType.createUnique(t.isPersistIndexes(), false); } else { // constraints indexType = IndexType.createNonUnique(t.isPersistIndexes()); } indexType.setBelongsToConstraint(true); String prefix = constraintName == null ? "CONSTRAINT" : constraintName; String indexName = t.getSchema().getUniqueIndexName(session, t, prefix + "_INDEX_"); try { Index index = t.addIndex(session, indexName, indexId, cols, indexType, true, null); createdIndexes.add(index); return index; } finally { getSchema().freeUniqueName(indexName); } }
private Index createIndex(Table t, IndexColumn[] cols, boolean unique) throws SQLException { int indexId = getObjectId(true, false); IndexType indexType; if (unique) { // TODO default index (hash or not; memory or not or same as table) // for unique constraints indexType = IndexType.createUnique(t.isPersistent(), false); } else { // TODO default index (memory or not or same as table) for unique // constraints indexType = IndexType.createNonUnique(t.isPersistent()); } indexType.setBelongsToConstraint(true); String prefix = constraintName == null ? "CONSTRAINT" : constraintName; String indexName = t.getSchema().getUniqueIndexName(t, prefix + "_INDEX_"); Index idx; try { idx = t.addIndex(session, indexName, indexId, cols, indexType, Index.EMPTY_HEAD, null); } finally { getSchema().freeUniqueName(indexName); } return idx; }
Table table = getSchema().findTableOrView(session, tableName); if (table == null) { if (ifTableExists) { if (getSchema().findConstraint(session, constraintName) != null) { if (ifNotExists) { return 0; indexColumns, indexType, true, null); } finally { getSchema().freeUniqueName(indexName); int constraintId = getObjectId(); String name = generateConstraintName(table); ConstraintUnique pk = new ConstraintUnique(getSchema(), constraintId, name, table, true); pk.setColumns(indexColumns); ConstraintUnique unique = new ConstraintUnique(getSchema(), id, name, table, false); unique.setColumns(indexColumns); int id = getObjectId(); String name = generateConstraintName(table); ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table); TableFilter filter = new TableFilter(session, table, null, false, null, 0); checkExpression.mapColumns(filter, 0); ConstraintReferential ref = new ConstraintReferential(getSchema(),
Table table = getSchema().findTableOrView(session, tableName); if (table == null) { if (ifTableExists) { if (getSchema().findConstraint(session, constraintName) != null) { if (ifNotExists) { return 0; indexColumns, indexType, true, null); } finally { getSchema().freeUniqueName(indexName); int constraintId = getObjectId(); String name = generateConstraintName(table); ConstraintUnique pk = new ConstraintUnique(getSchema(), constraintId, name, table, true); pk.setColumns(indexColumns); ConstraintUnique unique = new ConstraintUnique(getSchema(), id, name, table, false); unique.setColumns(indexColumns); int id = getObjectId(); String name = generateConstraintName(table); ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table); TableFilter filter = new TableFilter(session, table, null, false, null, 0); checkExpression.mapColumns(filter, 0); ConstraintReferential ref = new ConstraintReferential(getSchema(),
session.commit(true); Database db = session.getDatabase(); Table table = getSchema().getTableOrView(session, tableName); if (getSchema().findConstraint(constraintName) != null) { throw Message.getSQLException(ErrorCode.CONSTRAINT_ALREADY_EXISTS_1, constraintName); index = table.addIndex(session, indexName, id, indexColumns, indexType, Index.EMPTY_HEAD, null); } finally { getSchema().freeUniqueName(indexName); int constraintId = getObjectId(true, true); String name = generateConstraintName(table, constraintId); ConstraintUnique pk = new ConstraintUnique(getSchema(), constraintId, name, table, true); pk.setColumns(indexColumns); pk.setIndex(index, true); ConstraintUnique unique = new ConstraintUnique(getSchema(), id, name, table, false); unique.setColumns(indexColumns); unique.setIndex(index, isOwner); int id = getObjectId(true, true); String name = generateConstraintName(table, id); ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table); TableFilter filter = new TableFilter(session, table, null, false, null); checkExpression.mapColumns(filter, 0); ConstraintReferential ref = new ConstraintReferential(getSchema(), id, name, table); ref.setColumns(indexColumns); ref.setIndex(index, isOwner);