Search in sources :

Example 1 with ConstraintConstantAction

use of org.apache.derby.impl.sql.execute.ConstraintConstantAction in project derby by apache.

the class AlterTableNode method prepConstantAction.

/**
 *	Generate arguments to constant action. Called by makeConstantAction() in this class and in
 *	our subclass RepAlterTableNode.
 *
 * @exception StandardException		Thrown on failure
 */
private void prepConstantAction() throws StandardException {
    if (tableElementList != null) {
        genColumnInfo();
    }
    if (numConstraints > 0) {
        conActions = new ConstraintConstantAction[numConstraints];
        tableElementList.genConstraintActions(false, conActions, getRelativeName(), schemaDescriptor, getDataDictionary());
        for (int conIndex = 0; conIndex < conActions.length; conIndex++) {
            ConstraintConstantAction cca = conActions[conIndex];
            if (cca instanceof CreateConstraintConstantAction) {
                int constraintType = cca.getConstraintType();
                if (constraintType == DataDictionary.PRIMARYKEY_CONSTRAINT) {
                    DataDictionary dd = getDataDictionary();
                    // Check to see if a constraint of the same type
                    // already exists
                    ConstraintDescriptorList cdl = dd.getConstraintDescriptors(baseTable);
                    if (cdl.getPrimaryKey() != null) {
                        throw StandardException.newException(SQLState.LANG_ADD_PRIMARY_KEY_FAILED1, baseTable.getQualifiedName());
                    }
                }
            }
        }
    }
}
Also used : ConstraintConstantAction(org.apache.derby.impl.sql.execute.ConstraintConstantAction) CreateConstraintConstantAction(org.apache.derby.impl.sql.execute.CreateConstraintConstantAction) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) CreateConstraintConstantAction(org.apache.derby.impl.sql.execute.CreateConstraintConstantAction)

Aggregations

ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)1 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)1 ConstraintConstantAction (org.apache.derby.impl.sql.execute.ConstraintConstantAction)1 CreateConstraintConstantAction (org.apache.derby.impl.sql.execute.CreateConstraintConstantAction)1