public String dropIndex(Index index, boolean quoteIdentifiers, boolean qualifyNames) { return DROP + SPACE + INDEX + SPACE + getName(index.getTable(), quoteIdentifiers, qualifyNames) + DOT + getName(index, quoteIdentifiers, false) + NEWLINE; }
public String dropTableConstraint( Index uniqueIndex, boolean quoteIdentifiers, boolean qualifyNames) { return ALTER + SPACE + TABLE + SPACE + getName(uniqueIndex.getTable(), quoteIdentifiers, qualifyNames) + " DROP CONSTRAINT " + getName(uniqueIndex, quoteIdentifiers, false) + NEWLINE; //$NON-NLS-1$ }
public ReferenceConstraint findConstraintByIndex(Index index) { Iterator it = this.elements.iterator(); while (it.hasNext()) { Object elem = it.next(); if (elem instanceof ReferenceConstraint && ((ReferenceConstraint) elem).getName().equals(index.getName())) { return (ReferenceConstraint) elem; } } return null; }
public String addUniqueConstraint( Index constraint, boolean quoteIdentifiers, boolean qualifyNames) { String statement = ALTER + SPACE + TABLE + SPACE + getName(constraint.getTable(), quoteIdentifiers, qualifyNames) + SPACE; statement += this.getAddUniqueConstraintClause(constraint, quoteIdentifiers); return statement + NEWLINE; }
public String createIndex(Index index, boolean quoteIdentifiers, boolean qualifyNames) { String statement = CREATE + SPACE; if (index.isUnique()) { statement += UNIQUE + SPACE; } statement += INDEX + SPACE + getName(index, quoteIdentifiers, false) + SPACE + ON + SPACE + getName(index.getTable(), quoteIdentifiers, qualifyNames) + SPACE + LEFT_PARENTHESIS + getIndexKeyColumns(index, quoteIdentifiers) + RIGHT_PARENTHESIS; statement += NEWLINE + WITH + SPACE + LEFT_PARENTHESIS + generateIndexOptions(index) + RIGHT_PARENTHESIS; return statement + NEWLINE; }
public String addForeignKey( ForeignKey foreignKey, boolean quoteIdentifiers, boolean qualifyNames) { UniqueConstraint uniqueConstraint = foreignKey.getUniqueConstraint(); Index index = foreignKey.getUniqueIndex(); Table parentTable = null; String parentKey = null; if (uniqueConstraint != null) { parentTable = uniqueConstraint.getBaseTable(); parentKey = this.getKeyColumns(uniqueConstraint, quoteIdentifiers); } else if (index != null) { parentTable = index.getTable(); parentKey = this.getParentKeyColumns(index, quoteIdentifiers); } if (parentTable == null) { this.getEngineeringCallBack() .writeMessage( MessageFormat.format( GenericCatalogMessages.FE_PARENT_TABLLE_OR_KEY_DO_NOT_EXIST, new Object[] {foreignKey.getName()})); return null; } String statement = ALTER + SPACE + TABLE + SPACE + getName(foreignKey.getBaseTable(), quoteIdentifiers, qualifyNames) + SPACE + ADD + SPACE + CONSTRAINT + SPACE + getName(foreignKey, quoteIdentifiers) + SPACE + FOREIGN_KEY + SPACE + LEFT_PARENTHESIS + this.getKeyColumns(foreignKey, quoteIdentifiers) + RIGHT_PARENTHESIS + NEWLINE; statement += TAB + REFERENCES + SPACE + getName(parentTable, quoteIdentifiers, qualifyNames) + SPACE + LEFT_PARENTHESIS + parentKey + RIGHT_PARENTHESIS; ReferentialActionType action = foreignKey.getOnDelete(); if (action != ReferentialActionType.RESTRICT_LITERAL && action != ReferentialActionType.NO_ACTION_LITERAL) { statement += NEWLINE + TAB + ON + SPACE + DELETE + SPACE; statement += getReferentialAction(action); } action = foreignKey.getOnUpdate(); if (action != ReferentialActionType.RESTRICT_LITERAL && action != ReferentialActionType.NO_ACTION_LITERAL) { statement += NEWLINE + TAB + ON + SPACE + UPDATE + SPACE; statement += getReferentialAction(action); } if (foreignKey.isDeferrable()) { statement += NEWLINE + TAB + getDeferrableClause(foreignKey); } return statement + NEWLINE; }