db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r1517823 [1/2] - in /db/derby/code/trunk: java/engine/org/apache/derby/iapi/sql/dictionary/ java/engine/org/apache/derby/impl/sql/catalog/ java/engine/org/apache/derby/impl/sql/compile/ java/engine/org/apache/derby/impl/sql/execute/ java/en...
Date Tue, 27 Aug 2013 14:05:04 GMT
Author: dag
Date: Tue Aug 27 14:05:03 2013
New Revision: 1517823

URL: http://svn.apache.org/r1517823
Log:
DERBY-532 Support deferrable constraints

Patch derby-532-syntax-binding-dict-all-1. This patch wires in the syntax
for deferred constraints (aka "constraint characteristics"). It also
does

- binding checks for CREATE TABLE constraints and SET constraints
  statement (new). Binding is still missing for ALTER TABLE
  constraints clauses.

- temporarily throws not yet implemented (0A000.S) for all usage
  *except* when characteristics coincide with the current (and future)
  Derby defaults, i.e. NOT DEFERRABLE [INITIALLY IMMEDIATE] ENFORCED

- checks inconsistencies in characteristics (illegal combinations), cf.
  42X97 "Conflicting constraint characteristics for constraint"

- implements implied DEFERRABLE of (only) INITIALLY DEFERRED is
  specified.

- if the property "derby.constraintsTesting" is set, persists
  characteristics to dictionary by overloading the existing STATE
  character according to specification. This property will go away
  once the feature set is implemented, only implemented not to be able
  to test dictionary persistence

- throws 42XAK "Constraint characteristics not allowed for NOT NULL."
  for NOT NULL characteristics since this constraint type is not
  explicitly implemented as a constraint in Derby (yet, at least)

- adds a new test, ConstraintCharacteristicsTest to test the above and
  wires it into the lang suite.

(part 2):
- Elaborates ALTER TABLE ALTER TABLE, correcting syntax, adding name
  binding and updating dictionary (subject to the property
  derby.constraintsTesting) in a new AlterConstraintConstantAction
  class.

- Built out tests in ConstraintCharacteristicsTest to systematically
  check all possible characteristics combinations in all cases, and
  adding tests for ALTER TABLE ALTER TABLE, including dictionary
  updates.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ConstraintCharacteristicsTest.java
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/CheckConstraintDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptorList.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ForeignKeyConstraintDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/KeyConstraintDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ReferencedKeyConstraintDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSCONSTRAINTSRowFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropConstraintConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/SetConstraintsConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/UpdatableVTIConstantAction.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/db2Compatibility.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/_Suite.java
    db/derby/code/trunk/tools/ide/netbeans/nbproject/project.xml

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/CheckConstraintDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/CheckConstraintDescriptor.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/CheckConstraintDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/CheckConstraintDescriptor.java Tue Aug 27 14:05:03 2013
@@ -145,7 +145,7 @@ public class CheckConstraintDescriptor e
 		/*
 		** If we are disabled, we never fire
 		*/
-		if (!isEnabled)
+        if (!enforced())
 		{
 			return false;
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptor.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptor.java Tue Aug 27 14:05:03 2013
@@ -60,11 +60,11 @@ public abstract class ConstraintDescript
 	// field that we want users to be able to know about
 	public static final int SYSCONSTRAINTS_STATE_FIELD = 6;
 
-	TableDescriptor		table;
-	final String				constraintName;
-	private final boolean				deferrable;
-	private final boolean				initiallyDeferred;
-	boolean				isEnabled;
+    TableDescriptor       table;
+    final String          constraintName;
+    private boolean deferrable;
+    private boolean initiallyDeferred;
+    private boolean enforced;
 	private final int[]				referencedColumns;
 	final UUID					constraintId;
 	private final SchemaDescriptor	schemaDesc;
@@ -81,6 +81,7 @@ public abstract class ConstraintDescript
 	 * @param referencedColumns columns that the constraint references
 	 * @param constraintId		UUID of constraint
 	 * @param schemaDesc		SchemaDescriptor
+     * @param enforced          Is the constraint enforced?
 	 */
 
 	ConstraintDescriptor(
@@ -92,7 +93,7 @@ public abstract class ConstraintDescript
 			int[] referencedColumns,
 			UUID constraintId,
 			SchemaDescriptor schemaDesc,
-			boolean isEnabled
+            boolean enforced
 			)
 	{
 		super( dataDictionary );
@@ -100,11 +101,11 @@ public abstract class ConstraintDescript
 		this.table = table;
 		this.constraintName = constraintName;
 		this.deferrable = deferrable;
-		this.initiallyDeferred = initiallyDeferred;
+        this.initiallyDeferred = initiallyDeferred;
 		this.referencedColumns = referencedColumns;
 		this.constraintId = constraintId;
 		this.schemaDesc = schemaDesc;
-		this.isEnabled = isEnabled;
+        this.enforced = enforced;
 	}
 
 
@@ -161,29 +162,34 @@ public abstract class ConstraintDescript
 
 	/**
 	 * Returns TRUE if the constraint is deferrable
-	 * (we will probably not do deferrable constraints in the
-	 * initial release, but I want this to be part of the interface).
 	 *
-	 * @return	TRUE if the constraint is deferrable, FALSE if not
+     * @return  TRUE if the constraint is DEFERRABLE, FALSE if it is
+     *          NOT DEFERRABLE.
 	 */
-	public boolean	deferrable()
+    public boolean deferrable()
 	{
 		return deferrable;
 	}
 
+    public void setDeferrable(boolean b) {
+        deferrable = b;
+    }
+
 	/**
 	 * Returns TRUE if the constraint is initially deferred
-	 * (we will probably not do initially deferred constraints
-	 * in the initial release, but I want this to be part of the interface).
 	 *
-	 * @return	TRUE if the constraint is initially deferred,
-	 *		FALSE if not
+     * @return  TRUE if the constraint is initially DEFERRED,
+     *      FALSE if the constraint is initially IMMEDIATE
 	 */
 	public boolean	initiallyDeferred()
 	{
-		return initiallyDeferred;
+        return initiallyDeferred;
 	}
 
+    public void setInitiallyDeferred(boolean b) {
+        initiallyDeferred = b;
+    }
+
 	/**
 	 * Returns an array of column ids (i.e. ordinal positions) for
 	 * the columns referenced in this table for a primary key, unique
@@ -238,32 +244,18 @@ public abstract class ConstraintDescript
 	}
 
 	/**
-	 * Is this constraint active?
+     * Is this constraint enforced?
 	 *
 	 * @return true/false
 	 */
-	public boolean isEnabled()
-	{
-		return isEnabled;
-	}
-
-	/**
-	 * Set the constraint to enabled.
-	 * Does not update the data dictionary
-	 */
-	public void setEnabled()
+    public boolean enforced()
 	{
-		isEnabled = true;
+        return enforced;
 	}
 
-	/**
-	 * Set the constraint to disabled.
-	 * Does not update the data dictionary
-	 */
-	public void setDisabled()
-	{
-		isEnabled = false;
-	}
+    public void setEnforced(boolean b) {
+        enforced = b;
+    }
 
 	/**
 	 * Is this constraint referenced?  Return
@@ -277,7 +269,7 @@ public abstract class ConstraintDescript
 	}
 
 	/**
-	 * Get the number of enabled fks that
+     * Get the number of enforced fks that
 	 * reference this key.  Overriden by
 	 * ReferencedKeyConstraints.
 	 *
@@ -456,7 +448,7 @@ public abstract class ConstraintDescript
 				"constraintName: " + constraintName + "\n" +
 				"constraintId: " + constraintId + "\n" +
 				"deferrable: " + deferrable + "\n" +
-				"initiallyDeferred: " + initiallyDeferred + "\n" +
+                "initiallyDeferred: " + initiallyDeferred + "\n" +
                "referencedColumns: " +
                     Arrays.toString(referencedColumns) + "\n" +
 				"schemaDesc: " + schemaDesc + "\n"

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptorList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptorList.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptorList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ConstraintDescriptorList.java Tue Aug 27 14:05:03 2013
@@ -193,17 +193,17 @@ public class ConstraintDescriptorList ex
 	}
 
 	/**
-	 * Return a list of constraints where enabled is
+     * Return a list of constraints where enforced is
 	 * as passed in.
 	 *
-	 * @param enabled true or false
+     * @param enforced true or false
 	 *
 	 * @return a constraint descriptor list built from this.  Always
 	 * a new list even if all the elements in this were of the correct
 	 * type (i.e. not optimized for the case where every element is
 	 * desired).
 	 */
-	public ConstraintDescriptorList getConstraintDescriptorList(boolean enabled)
+    public ConstraintDescriptorList getConstraintDescriptorList(boolean enforced)
 	{
 		ConstraintDescriptorList cdl = new ConstraintDescriptorList();
 		int size = size();
@@ -212,7 +212,7 @@ public class ConstraintDescriptorList ex
 		{
 			ConstraintDescriptor cd = elementAt(index);
 
-			if (cd.isEnabled() == enabled)
+            if (cd.enforced() == enforced)
 			{
 				cdl.add(cd);
 			}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/DataDictionary.java Tue Aug 27 14:05:03 2013
@@ -210,6 +210,7 @@ public interface DataDictionary
 	public static final int CHECK_CONSTRAINT = 4;
 	public static final int DROP_CONSTRAINT = 5;
 	public static final int FOREIGNKEY_CONSTRAINT = 6;
+    public static final int MODIFY_CONSTRAINT = 7;
 
 	/** Modes returned from startReading() */
 	public static final int COMPILE_ONLY_MODE = 0;
@@ -834,13 +835,13 @@ public interface DataDictionary
 
 	/**
 	 * Load up the constraint descriptor list for this table
-	 * descriptor and return it.  If the descriptor list
-	 * is already loaded up, it is retuned without further
+     * descriptor (or all) and return it.  If the descriptor list
+     * is already loaded up, it is returned without further
 	 * ado.
 	 *
-	 * @param td			The table descriptor.
-	 *
-	 * @return The ConstraintDescriptorList for the table
+     * @param td The table descriptor.
+     * @return   The ConstraintDescriptorList for the table. If null, return
+     *           a list of all the constraint descriptors in all schemas.
 	 *
 	 * @exception StandardException		Thrown on failure
 	 */

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ForeignKeyConstraintDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ForeignKeyConstraintDescriptor.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ForeignKeyConstraintDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ForeignKeyConstraintDescriptor.java Tue Aug 27 14:05:03 2013
@@ -62,7 +62,7 @@ public class ForeignKeyConstraintDescrip
 	 * @param indexId			The UUID for the backing index
 	 * @param schemaDesc		The SchemaDescriptor for the constraint
 	 * @param referencedConstraintDescriptor	is referenced constraint descriptor
-	 * @param isEnabled			is the constraint enabled?
+     * @param enforced          is the constraint enforced?
 	 */
 	protected ForeignKeyConstraintDescriptor(
 		    DataDictionary dataDictionary,
@@ -75,14 +75,14 @@ public class ForeignKeyConstraintDescrip
 			UUID indexId,
 			SchemaDescriptor schemaDesc,
 			ReferencedKeyConstraintDescriptor referencedConstraintDescriptor,
-			boolean isEnabled,
+            boolean enforced,
 			int raDeleteRule,
 			int raUpdateRule
 			)							
 	{
 		super(dataDictionary, table, constraintName, deferrable,
 			  initiallyDeferred, fkColumns,
-			  constraintId, indexId, schemaDesc, isEnabled);
+              constraintId, indexId, schemaDesc, enforced);
 
 		this.referencedConstraintDescriptor = referencedConstraintDescriptor;
 		this.raDeleteRule = raDeleteRule;
@@ -102,7 +102,7 @@ public class ForeignKeyConstraintDescrip
 	 * @param indexId			The UUID for the backing index
 	 * @param schemaDesc		The SchemaDescriptor for the constraint
 	 * @param referencedConstraintId	is referenced constraint id
-	 * @param isEnabled			is the constraint enabled?
+     * @param enforced          {@code true} if this constraint is enforced
 	 */
 	ForeignKeyConstraintDescriptor(
 		    DataDictionary dataDictionary,
@@ -115,14 +115,14 @@ public class ForeignKeyConstraintDescrip
 			UUID indexId,
 			SchemaDescriptor schemaDesc,
 			UUID referencedConstraintId,
-			boolean isEnabled,
+            boolean enforced,
 			int raDeleteRule,
 			int raUpdateRule
 			)							
 	{
 		super(dataDictionary, table, constraintName, deferrable,
 			  initiallyDeferred, fkColumns,
-			  constraintId, indexId, schemaDesc, isEnabled);
+              constraintId, indexId, schemaDesc, enforced);
 		this.referencedConstraintId = referencedConstraintId;
 		this.raDeleteRule = raDeleteRule;
 		this.raUpdateRule = raUpdateRule;
@@ -236,7 +236,7 @@ public class ForeignKeyConstraintDescrip
 		/*
 		** If we are disabled, we never fire
 		*/
-		if (!isEnabled)
+        if (!enforced())
 		{
 			return false;
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/KeyConstraintDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/KeyConstraintDescriptor.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/KeyConstraintDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/KeyConstraintDescriptor.java Tue Aug 27 14:05:03 2013
@@ -62,7 +62,7 @@ public abstract class KeyConstraintDescr
 	 * @param constraintId		UUID of constraint
 	 * @param indexId			The UUID for the backing index
 	 * @param schemaDesc		The SchemaDescriptor for the constraint
-	 * @param isEnabled			is this constraint enabled
+     * @param enforced          {@code true} if this constraint is enforced
 	 */
 	KeyConstraintDescriptor(
 		    DataDictionary dataDictionary,
@@ -74,12 +74,12 @@ public abstract class KeyConstraintDescr
 			UUID constraintId,
 			UUID indexId,
 			SchemaDescriptor schemaDesc,
-			boolean isEnabled
+            boolean enforced
 			)							
 	{
 		super(dataDictionary, table, constraintName, deferrable,
 			  initiallyDeferred, referencedColumns,
-			  constraintId, schemaDesc, isEnabled);
+              constraintId, schemaDesc, enforced);
 		this.indexId = indexId;
 	}
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ReferencedKeyConstraintDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ReferencedKeyConstraintDescriptor.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ReferencedKeyConstraintDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/ReferencedKeyConstraintDescriptor.java Tue Aug 27 14:05:03 2013
@@ -50,7 +50,7 @@ public class ReferencedKeyConstraintDesc
 
 	int			referenceCount;
 
-	// enabled foreign keys
+    // enforced foreign keys
 	private	ConstraintDescriptorList fkEnabledConstraintList;
 	// all foreign keys
 	private	ConstraintDescriptorList fkConstraintList;
@@ -71,8 +71,8 @@ public class ReferencedKeyConstraintDesc
 	 * @param constraintId		UUID of constraint
 	 * @param indexId			The UUID for the backing index
 	 * @param schemaDesc		The SchemaDescriptor for the constraint
-	 * @param isEnabled			is the constraint enabled?
-	 * @param referenceCount	number of FKs (enabled only)
+     * @param enforced          is the constraint enforced?
+     * @param referenceCount    number of FKs (enforced only)
 	 */
 	protected ReferencedKeyConstraintDescriptor(int constraintType,
 		    DataDictionary dataDictionary,
@@ -84,13 +84,13 @@ public class ReferencedKeyConstraintDesc
 			UUID constraintId,
 			UUID indexId,
 			SchemaDescriptor schemaDesc,
-			boolean	isEnabled,
+            boolean enforced,
 			int referenceCount
 			)							
 	{
 		super(dataDictionary, table, constraintName, deferrable,
 			  initiallyDeferred, columns, 
-			  constraintId, indexId, schemaDesc, isEnabled);
+              constraintId, indexId, schemaDesc, enforced);
 		this.referenceCount = referenceCount;
 		this.constraintType = constraintType;
 	}
@@ -248,7 +248,7 @@ public class ReferencedKeyConstraintDesc
 		
 	/**
 	 * Is this constraint referenced? Returns
-	 * true if there are enabled fks that 
+     * true if there are enforced fks that
 	 * reference this constraint.
 	 *
 	 * @return false
@@ -260,7 +260,7 @@ public class ReferencedKeyConstraintDesc
 	}
 
 	/**
-	 * Get the number of enabled fks that
+     * Get the number of enforced fks that
 	 * reference this key.
 	 *
 	 * @return the number of fks
@@ -308,7 +308,7 @@ public class ReferencedKeyConstraintDesc
 		/*
 		** If we are disabled, we never fire
 		*/
-		if (!isEnabled)
+        if (!enforced())
 		{
 			return false;
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/TriggerDescriptor.java Tue Aug 27 14:05:03 2013
@@ -79,7 +79,7 @@ import java.io.IOException;
  * <li> public ReferencedColumns getReferencedColumnsDescriptor()
  * <li> public int[] getReferencedCols();
  * <li> public int[] getReferencedColsInTriggerAction();
- * <li> public boolean isEnabled();
+ * <li> public boolean enforced();
  * <li> public void setEnabled();
  * <li> public void setDisabled();
  * <li> public boolean needsToFire(int stmtType, int[] modifiedCols)
@@ -140,7 +140,7 @@ public class TriggerDescriptor extends U
 	 * @param eventMask	TriggerDescriptor.TRIGGER_EVENT_XXXX
 	 * @param isBefore	is this a before (as opposed to after) trigger 
 	 * @param isRow		is this a row trigger or statement trigger
-	 * @param isEnabled	is this trigger enabled or disabled
+     * @param isEnabled  is this trigger enabled or disabled
 	 * @param td		the table upon which this trigger is defined
 	 * @param whenSPSId	the sps id for the when clause (may be null)
 	 * @param actionSPSId	the spsid for the trigger action (may be null)
@@ -488,9 +488,9 @@ public class TriggerDescriptor extends U
     }
 
 	/**
-	 * Is this trigger enabled
+     * Is this trigger enforced
 	 *
-	 * @return true if it is enabled
+     * @return true if it is enforced
 	 */
 	public boolean isEnabled()
 	{
@@ -498,7 +498,7 @@ public class TriggerDescriptor extends U
 	}
 
 	/**
-	 * Mark this trigger as enabled
+     * Mark this trigger as enforced
 	 *
 	 */
 	public void setEnabled()

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java Tue Aug 27 14:05:03 2013
@@ -4742,7 +4742,7 @@ public final class	DataDictionaryImpl
 		getConstraintDescriptorViaHeap(
 						(ScanQualifier[][]) null,
 						ti,
-						(TupleDescriptor) null,
+                        (TupleDescriptor) null,
 						list);
 		return list;
 	}
@@ -6228,7 +6228,7 @@ public final class	DataDictionaryImpl
 
 	/**
 	 * Return a list of foreign keys constraints referencing
-	 * this constraint.  Returns both enabled and disabled
+     * this constraint.  Returns both enforced and not enforced
 	 * foreign keys.  
 	 *
 	 * @param constraintId	The id of the referenced constraint
@@ -6463,12 +6463,12 @@ public final class	DataDictionaryImpl
 	 * Update the constraint descriptor in question.  Updates
 	 * every row in the base conglomerate.  
 	 *
-	 * @param cd					The Constraintescriptor
+     * @param cd                    The Constraint descriptor
 	 * @param formerUUID			The UUID for this column in SYSCONSTRAINTS,
-	 *								may differ from what is in cd if this
+     *                              may differ from what is in {@code cd} if this
 	 *								is the column that is being set.
-	 * @param colsToSet 			Array of ints of columns to be modified,
-	 *								1 based.  May be null (all cols).
+     * @param colsToSet             Array of integers of columns to be modified,
+     *                              1 based.  May be null (all columns).
 	 * @param tc					The TransactionController to use
 	 *
 	 * @exception StandardException		Thrown on failure

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSCONSTRAINTSRowFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSCONSTRAINTSRowFactory.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSCONSTRAINTSRowFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/SYSCONSTRAINTSRowFactory.java Tue Aug 27 14:05:03 2013
@@ -46,6 +46,7 @@ import org.apache.derby.iapi.types.DataV
 import org.apache.derby.iapi.types.SQLChar;
 import org.apache.derby.iapi.types.SQLInteger;
 import org.apache.derby.iapi.types.SQLVarchar;
+import org.apache.derby.impl.sql.compile.ConstraintDefinitionNode;
 
 /**
  * Factory for creating a SYSCONTRAINTS row.
@@ -62,7 +63,7 @@ public class SYSCONSTRAINTSRowFactory ex
 	protected static final int		SYSCONSTRAINTS_CONSTRAINTNAME = 3;
 	protected static final int		SYSCONSTRAINTS_TYPE = 4;
 	protected static final int		SYSCONSTRAINTS_SCHEMAID = 5;
-	protected static final int		SYSCONSTRAINTS_STATE = ConstraintDescriptor.SYSCONSTRAINTS_STATE_FIELD;
+    public static final int     SYSCONSTRAINTS_STATE = ConstraintDescriptor.SYSCONSTRAINTS_STATE_FIELD;
 	protected static final int		SYSCONSTRAINTS_REFERENCECOUNT = 7;
 
 	protected static final int		SYSCONSTRAINTS_INDEX1_ID = 0;
@@ -129,7 +130,14 @@ public class SYSCONSTRAINTSRowFactory ex
 		String					tableID = null;
 		String					constraintName = null;
 		String					schemaID = null;
-		boolean					isEnabled = true;
+
+        boolean                 deferrable =
+            ConstraintDefinitionNode.DEFERRABLE_DEFAULT;
+        boolean                 initiallyDeferred =
+            ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT;
+        boolean                 enforced =
+            ConstraintDefinitionNode.ENFORCED_DEFAULT;
+
 		int						referenceCount = 0;
 
 		if (td != null)
@@ -174,8 +182,13 @@ public class SYSCONSTRAINTSRowFactory ex
 			}
 
 			schemaID = constraint.getSchemaDescriptor().getUUID().toString();
-			isEnabled = constraint.isEnabled();
-			referenceCount = constraint.getReferenceCount();
+
+            // constraint characteristics
+            deferrable = constraint.deferrable();
+            initiallyDeferred   = constraint.initiallyDeferred();
+            enforced   = constraint.enforced();
+
+            referenceCount = constraint.getReferenceCount();
 		}
 
 		/* Insert info into sysconstraints */
@@ -203,7 +216,8 @@ public class SYSCONSTRAINTSRowFactory ex
 		row.setColumn(SYSCONSTRAINTS_SCHEMAID, new SQLChar(schemaID));
 
 		/* 6th column is STATE (char(1)) */
-		row.setColumn(SYSCONSTRAINTS_STATE, new SQLChar(isEnabled ? "E" : "D"));
+        row.setColumn(SYSCONSTRAINTS_STATE,
+            new SQLChar(encodeCharacteristics(deferrable, initiallyDeferred, enforced)));
 
 		/* 7th column is REFERENCED */
 		row.setColumn(SYSCONSTRAINTS_REFERENCECOUNT, new SQLInteger(referenceCount));
@@ -211,6 +225,56 @@ public class SYSCONSTRAINTSRowFactory ex
 		return row;
 	}
 
+    /*
+     * Encode the characteristics of the constraints into a single character.
+     *
+     * {deferrable, initiallyDeferred, enforced}     -> 'e'
+     * {deferrable, initiallyDeferred, not enforced} -> 'd'
+     * {deferrable, immediate, enforced}             -> 'i'
+     * {deferrable, immediate, not enforced}         -> 'j'
+     * {not deferrable, immediate, enforced}         -> 'E'
+     * {not deferrable, immediate, not enforced      -> 'D'
+     *
+     * Other combinations are prohibited and not used. Note that the
+     * value 'E' is only value used prior to version 10.11, and as
+     * such upward compatibily since by default, constraints are {not
+     * deferrable, immediate, enforced}.
+     */
+    private String encodeCharacteristics(
+            boolean deferrable, boolean initiallyDeferred, boolean enforced) {
+        char c;
+
+        if (deferrable) {
+            if (initiallyDeferred) {
+                if (enforced) {
+                    c = 'e'; // deferrable initially deferred enforced
+                } else {
+                    c = 'd'; // deferrable initially deferred not enforced
+                }
+            } else {
+                if (enforced) {
+                    c = 'i'; // deferrable initially immediate enforced
+                } else {
+                    c = 'j'; // deferrable initially immediate not enforced
+                }
+            }
+        } else {
+            if (initiallyDeferred) {
+                if (SanityManager.DEBUG) {
+                    SanityManager.NOTREACHED();
+                }
+                c = 'E';
+            } else {
+                if (enforced) {
+                    c = 'E'; // not deferrable initially immediate enforced
+                } else {
+                    c = 'D'; // not deferrable initially immediate not enforced
+                }
+            }
+        }
+
+        return String.valueOf(c);
+    }
 
 	///////////////////////////////////////////////////////////////////////////
 	//
@@ -257,7 +321,12 @@ public class SYSCONSTRAINTSRowFactory ex
 		String				constraintName;
 		String				constraintSType;
 		String				constraintStateStr;
-		boolean				constraintEnabled;
+        boolean             deferrable =
+                ConstraintDefinitionNode.DEFERRABLE_DEFAULT;
+        boolean             initiallyDeferred =
+                ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT;
+        boolean             enforced =
+                ConstraintDefinitionNode.ENFORCED_DEFAULT;
 		int					referenceCount;
 		String				constraintUUIDString;
 		String				schemaUUIDString;
@@ -420,16 +489,41 @@ public class SYSCONSTRAINTSRowFactory ex
 				"Sixth column (state) type incorrect");
 		}
 
+        // Cf. the encoding description in javadoc for
+        // #encodeCharacteristics.
 		switch (constraintStateStr.charAt(0))
 		{
 			case 'E': 
-				constraintEnabled = true;
+                deferrable = false;
+                initiallyDeferred = false;
+                enforced = true;
 				break;
 			case 'D':
-				constraintEnabled = false;
-				break;
+                deferrable = false;
+                initiallyDeferred = false;
+                enforced = false;
+				break;
+            case 'e':
+                deferrable = true;
+                initiallyDeferred = true;
+                enforced = true;
+                break;
+            case 'd':
+                deferrable = true;
+                initiallyDeferred = true;
+                enforced = false;
+                break;
+            case 'i':
+                deferrable = true;
+                initiallyDeferred = false;
+                enforced = true;
+                break;
+            case 'j':
+                deferrable = true;
+                initiallyDeferred = false;
+                enforced = false;
+                break;
 			default: 
-				constraintEnabled = true;
 				if (SanityManager.DEBUG)
 				{
 					SanityManager.THROWASSERT("Invalidate state value '"
@@ -449,14 +543,14 @@ public class SYSCONSTRAINTSRowFactory ex
 				constraintDesc = ddg.newPrimaryKeyConstraintDescriptor(
 										td, 
 										constraintName, 
-										false, //deferable,
-										false, //initiallyDeferred,
+                                        deferrable,
+                                        initiallyDeferred,
 										keyColumns,//genReferencedColumns(dd, td), //int referencedColumns[],
 										constraintUUID,
 										((SubKeyConstraintDescriptor) 
 											parentTupleDescriptor).getIndexId(),
 										schema,
-										constraintEnabled,
+                                        enforced,
 										referenceCount);
 				break;
 
@@ -464,14 +558,14 @@ public class SYSCONSTRAINTSRowFactory ex
 				constraintDesc = ddg.newUniqueConstraintDescriptor(
 										td, 
 										constraintName, 
-										false, //deferable,
-										false, //initiallyDeferred,
+                                        deferrable,
+                                        initiallyDeferred,
 										keyColumns,//genReferencedColumns(dd, td), //int referencedColumns[],
 										constraintUUID,
 										((SubKeyConstraintDescriptor) 
 											parentTupleDescriptor).getIndexId(),
 										schema,
-										constraintEnabled,
+                                        enforced,
 										referenceCount);
 				break;
 
@@ -485,15 +579,15 @@ public class SYSCONSTRAINTSRowFactory ex
 				constraintDesc = ddg.newForeignKeyConstraintDescriptor(
 										td, 
 										constraintName, 
-										false, //deferable,
-										false, //initiallyDeferred,
+                                        deferrable,
+                                        initiallyDeferred,
 										keyColumns,//genReferencedColumns(dd, td), //int referencedColumns[],
 										constraintUUID,
 										((SubKeyConstraintDescriptor) 
 											parentTupleDescriptor).getIndexId(),
 										schema,
 										referencedConstraintId,
-										constraintEnabled,
+                                        enforced,
 										((SubKeyConstraintDescriptor) 
 											parentTupleDescriptor).getRaDeleteRule(),
 										((SubKeyConstraintDescriptor) 
@@ -511,15 +605,15 @@ public class SYSCONSTRAINTSRowFactory ex
 				constraintDesc = ddg.newCheckConstraintDescriptor(
 										td, 
 										constraintName, 
-										false, //deferable,
-										false, //initiallyDeferred,
+                                        deferrable,
+                                        initiallyDeferred,
 										constraintUUID,
 										((SubCheckConstraintDescriptor) 
 											parentTupleDescriptor).getConstraintText(),
 										((SubCheckConstraintDescriptor) 
 											parentTupleDescriptor).getReferencedColumnsDescriptor(),
 										schema,
-										constraintEnabled);
+                                        enforced);
 				break;
 		}
 		return constraintDesc;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ConstraintDefinitionNode.java Tue Aug 27 14:05:03 2013
@@ -38,7 +38,7 @@ import org.apache.derby.iapi.sql.diction
  *
  */
 
-class ConstraintDefinitionNode extends TableElementNode
+public class ConstraintDefinitionNode extends TableElementNode
 {
 	
 	private TableName constraintName;
@@ -56,6 +56,15 @@ class ConstraintDefinitionNode extends T
 	private int				 behavior;
     private int verifyType;
 
+    public final static boolean DEFERRABLE_DEFAULT = false;
+    public final static boolean INITIALLY_DEFERRED_DEFAULT = false;
+    public final static boolean ENFORCED_DEFAULT = true;
+
+    /**
+     * boolean[3]: {deferrable?, initiallyDeferred?, enforced?}
+     */
+    private boolean[] characteristics;
+
     ConstraintDefinitionNode(
                     TableName constraintName,
                     int constraintType,
@@ -87,6 +96,23 @@ class ConstraintDefinitionNode extends T
         this.verifyType = verifyType;
 	}
 
+
+    void setCharacteristics(boolean[] cc) {
+        characteristics = cc.clone();
+    }
+
+    boolean[] getCharacteristics() {
+        if (characteristics == null) {
+            characteristics = new boolean[]{
+                ConstraintDefinitionNode.DEFERRABLE_DEFAULT,
+                ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT,
+                ConstraintDefinitionNode.ENFORCED_DEFAULT
+            };
+        }
+
+        return characteristics.clone();
+    }
+
 	/**
 	 * Convert this object to a String.  See comments in QueryTreeNode.java
 	 * for how this should be done for tree printing.
@@ -167,7 +193,7 @@ class ConstraintDefinitionNode extends T
 	}
 
 	/**
-		To support dropping exisiting constraints that may have mismatched schema names
+        To support dropping existing constraints that may have mismatched schema names
 		we need to support ALTER TABLE S1.T DROP CONSTRAINT S2.C.
 		If a constraint name was specified this returns it, otherwise it returns null.
 	*/
@@ -285,9 +311,11 @@ class ConstraintDefinitionNode extends T
 	}
 
 	/**
-	 * Is this a foreign key constraint.
+     * Does this constraint require a backing index for its implementation?
 	 *
-	 * @return boolean	Whether or not this is a unique key constraint
+     * @return boolean  {@code true} if this constraint requires a backing
+     *                  index, i.e. if is a foreign key, primary key or
+     *                  unique key constraint
 	 */
 	boolean requiresBackingIndex()
 	{
@@ -303,9 +331,10 @@ class ConstraintDefinitionNode extends T
 	}	
 
 	/**
-	 * Is this a foreign key constraint.
+     * Is this a primary key or unique constraint?
 	 *
-	 * @return boolean	Whether or not this is a unique key constraint
+     * @return boolean  {@code true} if this is a primary key or
+     *                  unique key constraint
 	 */
 	boolean requiresUniqueIndex()
 	{
@@ -433,7 +462,8 @@ class ConstraintDefinitionNode extends T
 	}
 
 	/**
-	 * Return the behavior of this constriant (DropStatementNode.xxx)	
+     * Return the behavior of this constraint.
+     * See {@link org.apache.derby.iapi.sql.StatementType#DROP_CASCADE} etc.
 	 *
 	 * @return the behavior
 	 */

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java?rev=1517823&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SetConstraintsNode.java Tue Aug 27 14:05:03 2013
@@ -0,0 +1,130 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.compile.SetConstraintsNode
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package     org.apache.derby.impl.sql.compile;
+
+import java.util.List;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.services.context.ContextManager;
+import org.apache.derby.shared.common.sanity.SanityManager;
+import org.apache.derby.iapi.sql.compile.CompilerContext;
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
+import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList;
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
+import org.apache.derby.iapi.sql.execute.ConstantAction;
+
+/**
+ * A SetConstraintsNode is the root of a QueryTree that represents a
+ * SET CONSTRAINTS statement.
+ */
+
+class SetConstraintsNode extends MiscellaneousStatementNode
+{
+    /**
+     * List of strings representing the constraints we want to
+     * set. If empty, this means ALL.
+     */
+    final private List<TableName> constraints;
+
+    /**
+     * Encodes IMMEDIATE (false), DEFERRED (true)
+     */
+    final private boolean deferred;
+
+    /**
+     *
+     * @param constraints List of strings representing the constraints
+     *                    we want to set (empty means ALL).
+     * @param deferred    Encodes IMMEDIATE ({@code false}) or DEFERRED
+     *                    ({@code true})
+     * @param cm          The context manager
+     * @throws StandardException
+     */
+    SetConstraintsNode(
+            List<TableName> constraints,
+            boolean deferred,
+            ContextManager cm) {
+        super(cm);
+        this.constraints = constraints;
+        this.deferred = deferred;
+    }
+
+    /**
+     * Convert this object to a String.  See comments in QueryTreeNode.java
+     * for how this should be done for tree printing.
+     *
+     * @return  This object as a String
+     */
+    @Override
+    public String toString()
+    {
+        if (SanityManager.DEBUG) {
+            return super.toString() + formatList(constraints) + ":" +
+                    (deferred ? " DEFERRED" : " IMMEDIATE")  + "\n";
+        } else {
+            return "";
+        }
+    }
+
+    String formatList(List<TableName> constraints) {
+        StringBuilder sb = new StringBuilder();
+
+        for (TableName tn : constraints) {
+            sb.append(tn);
+            sb.append(", ");
+        }
+
+        return sb.substring(0, Math.max(0, sb.length() - 2));
+    }
+
+    public String statementToString()
+    {
+        return "SET CONSTRAINTS";
+    }
+
+    /**
+     * Create the Constant information that will drive the guts of
+     * Execution.
+     *
+     * @exception StandardException         Thrown on failure
+     */
+    @Override
+    public ConstantAction   makeConstantAction() throws StandardException
+    {
+        return getGenericConstantActionFactory().
+            getSetConstraintsConstantAction(constraints, deferred);
+    }
+
+    @Override
+    public void bindStatement() throws StandardException
+    {
+        final DataDictionary dd = getDataDictionary();
+
+        if (constraints != null) {
+            for (TableName c : constraints) {
+                c.bind(dd);
+            }
+        }
+    }
+
+}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementList.java Tue Aug 27 14:05:03 2013
@@ -276,7 +276,8 @@ class TableElementList extends QueryTree
             checkForDuplicateConstraintNames(ddlStmt, constraintNames, cdn.getConstraintMoniker());
 
 			/* Make sure that the constraint we are trying to drop exists */
-			if (cdn.getConstraintType() == DataDictionary.DROP_CONSTRAINT)
+            if (cdn.getConstraintType() == DataDictionary.DROP_CONSTRAINT ||
+                cdn.getConstraintType() == DataDictionary.MODIFY_CONSTRAINT)
 			{
 				/*
 				** If no schema descriptor, then must be an invalid
@@ -298,7 +299,7 @@ class TableElementList extends QueryTree
 										false);
 					if (cd == null)
 					{
-						throw StandardException.newException(SQLState.LANG_DROP_NON_EXISTENT_CONSTRAINT,
+                        throw StandardException.newException(SQLState.LANG_DROP_OR_ALTER_NON_EXISTING_CONSTRAINT,
 								(sd.getSchemaName() + "."+ dropConstraintName),
 								td.getQualifiedName());
 					}
@@ -501,7 +502,7 @@ class TableElementList extends QueryTree
 								coldef.getAutoinc_create_or_modify_Start_Increment() : -1));
 
 			/* Remember how many constraints that we've seen */
-			if (coldef.hasConstraint())
+        if (coldef.hasConstraint())
 			{
 				numConstraints++;
 			}
@@ -999,6 +1000,7 @@ class TableElementList extends QueryTree
 			}
 
 			int constraintType = constraintDN.getConstraintType();
+            boolean[] cChars = constraintDN.getCharacteristics();
 			String constraintText = constraintDN.getConstraintText();
 
 			/*
@@ -1076,6 +1078,19 @@ class TableElementList extends QueryTree
 												 constraintDN.getDropBehavior(),
                                                  constraintDN.getVerifyType());
 			}
+            else if (constraintType == DataDictionary.MODIFY_CONSTRAINT) {
+                conActions[conActionIndex] =
+                    getGenericConstantActionFactory().
+                        getAlterConstraintConstantAction(
+                                                 constraintName,
+                                                 constraintDN.getDropSchemaName(),
+                                                 cChars,
+                                                 tableName,
+                                                 td.getUUID(),
+                                                 tableSd.getSchemaName(),
+                                                 indexAction);
+
+            }
 			else
 			{
 				ProviderList apl = constraintDN.getAuxiliaryProviderList();
@@ -1107,6 +1122,7 @@ class TableElementList extends QueryTree
 						getCreateConstraintConstantAction(
 												 constraintName, 
 											     constraintType,
+                                                 cChars,
                                                  forCreateTable,
 												 tableName, 
 												 ((td != null) ? td.getUUID() : (UUID) null),
@@ -1114,7 +1130,6 @@ class TableElementList extends QueryTree
 												 columnNames,
 												 indexAction,
 												 constraintText,
-												 true, 		// enabled
 												 refInfo,
 												 providerInfos);
 			}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementNode.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/TableElementNode.java Tue Aug 27 14:05:03 2013
@@ -47,6 +47,7 @@ class TableElementNode extends QueryTree
 	public	static	final	int	AT_DROP_CONSTRAINT				= 5;
 	public	static	final	int	AT_MODIFY_COLUMN				= 6;
 	public	static	final	int	AT_DROP_COLUMN					= 7;
+    public  static  final   int AT_MODIFY_CONSTRAINT            = 8;
 
 
 	/////////////////////////////////////////////////////////////////////////

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Tue Aug 27 14:05:03 2013
@@ -2329,6 +2329,7 @@ TOKEN [IGNORE_CASE] :
 |	<DEFINER: "definer">
 |	<DETERMINISTIC: "deterministic">
 |   <DYNAMIC: "dynamic">
+|   <ENFORCED: "enforced">
 |	<FORTRAN: "fortran">
 |   <GENERATED: "generated">
 |	<IDENTITY_VAL_LOCAL: "identity_val_local">
@@ -3050,29 +3051,83 @@ spsSetStatement() throws StandardExcepti
 	StatementNode statementNode;
 }
 {
-        LOOKAHEAD ( { getToken(1).kind == SET && getToken(2).kind != CURRENT } )
+    LOOKAHEAD ( { getToken(1).kind == SET && getToken(2).kind != CURRENT } )
 	<SET>
-        (
-                statementNode = setIsolationStatement() |
-	        statementNode = setSchemaStatement() |
-            statementNode = setMessageLocaleStatement() |
-            statementNode = setRoleStatement()
-        )
+    (
+        statementNode = setIsolationStatement() |
+        statementNode = setSchemaStatement() |
+        statementNode = setMessageLocaleStatement() |
+        statementNode = setRoleStatement() |
+        statementNode = setConstraintsStatement()
+    )
 	{
 		return statementNode;
 	}
 |
-        LOOKAHEAD ( { getToken(1).kind == SET && getToken(2).kind == CURRENT } )
+    LOOKAHEAD ( { getToken(1).kind == SET && getToken(2).kind == CURRENT } )
 	<SET>
-        (
-	        statementNode = setSchemaStatement() |
-                statementNode = setIsolationStatement()
-
-        )
+    (
+        statementNode = setSchemaStatement() |
+        statementNode = setIsolationStatement()
+    )
 	{
 		return statementNode;
 	}
 }
+
+
+/**
+ * <A NAME="constraintsReference">constraintsReference</A>
+ */
+void
+constraintsReference(List<TableName> constraints) throws StandardException :
+{
+    TableName constraint;
+}
+{
+    constraint = qualifiedName(Limits.MAX_IDENTIFIER_LENGTH)
+    {
+        constraints.add(constraint);
+    }
+}
+
+
+/**
+ * <A NAME="setConstraintsStatement">setConstraintsStatement</A>
+ */
+StatementNode
+setConstraintsStatement() throws StandardException :
+{
+    List<TableName> constraints = new ArrayList<TableName>();
+    boolean initiallyDeferred;
+}
+{
+    <CONSTRAINTS>
+    (
+        constraintsReference(constraints)
+        ( <COMMA> constraintsReference(constraints) )*
+    |
+        <ALL>
+        {
+            constraints = null;
+        }
+    )
+    (
+        <DEFERRED>
+        {
+            initiallyDeferred = true;
+        }
+    |
+        <IMMEDIATE>
+        {
+            initiallyDeferred = false;
+        }
+    )
+    {
+        return new SetConstraintsNode(constraints, initiallyDeferred, cm);
+    }
+}
+
 		
 /*
  * <A NAME="preparableSQLDataStatement">preparableSQLDataStatement</A>
@@ -12532,22 +12587,26 @@ ConstraintDefinitionNode
 tableConstraint(TableName constraintName) throws StandardException :
 {
 	ConstraintDefinitionNode tcdn;
+    boolean[] cc = null;
 }
 {
-	tcdn = uniqueConstraintDefinition(constraintName) 
-	{
-		return tcdn;
-	}
-|
-	tcdn = referentialConstraintDefinition(constraintName) 
-	{
-		return tcdn;
-	}
-|
-	tcdn = checkConstraintDefinition(constraintName, null)
-	{
-		return tcdn;
-	}
+    (
+        tcdn = uniqueConstraintDefinition(constraintName)
+    |
+        tcdn = referentialConstraintDefinition(constraintName)
+    |
+        tcdn = checkConstraintDefinition(constraintName, null)
+    )
+
+    [ cc = constraintCharacteristics() ]
+
+    {
+        if (cc != null) {
+            tcdn.setCharacteristics(cc);
+        }
+
+        return tcdn;
+    }
 }
 
 ConstraintDefinitionNode
@@ -12710,6 +12769,135 @@ deleteReferentialAction() :
 	   )
 }
 
+
+/*
+ * <A NAME="constraintCharacteristics">constraintCharacteristics</A>
+ */
+boolean[]
+constraintCharacteristics() throws StandardException :
+{
+    boolean deferrable =
+        ConstraintDefinitionNode.DEFERRABLE_DEFAULT;
+    boolean initiallyDeferred =
+        ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT;
+    boolean enforced =
+        ConstraintDefinitionNode.ENFORCED_DEFAULT;
+    boolean explicitlySpecified[] =
+        new boolean[]{false, false}; // deferrable, initiallyDeferred
+}
+{
+    (
+        ( initiallyDeferred = initiallyDeferred()
+          {
+              explicitlySpecified[1] = true;
+          } )
+
+        [ LOOKAHEAD ( { getToken(1).kind == DEFERRABLE || getToken(2).kind == DEFERRABLE } )
+          deferrable = deferrable()
+          {
+              explicitlySpecified[0] = true;
+          } ]
+
+        [ LOOKAHEAD ( { getToken(1).kind == ENFORCED || getToken(2).kind == ENFORCED } )
+          enforced = constraintEnforcement() ]
+    |
+        LOOKAHEAD ( { getToken(1).kind == DEFERRABLE || getToken(2).kind == DEFERRABLE } )
+        ( deferrable = deferrable()
+          {
+              explicitlySpecified[0] = true;
+          } )
+
+        [ initiallyDeferred = initiallyDeferred()
+          {
+              explicitlySpecified[1] = true;
+          } ]
+
+        [ LOOKAHEAD ( { getToken(1).kind == ENFORCED || getToken(2).kind == ENFORCED } )
+          enforced = constraintEnforcement() ]
+    |
+        LOOKAHEAD ( { getToken(1).kind == ENFORCED || getToken(2).kind == ENFORCED } )
+        enforced = constraintEnforcement()
+    )
+    {
+        if (!explicitlySpecified[0] &&
+            explicitlySpecified[1] && initiallyDeferred) {
+            // "INITIALLY DEFERRED" implies "DEFERRABLE"
+            deferrable = true;
+        }
+
+        if (explicitlySpecified[0] && (!deferrable) &&
+            explicitlySpecified[1] && initiallyDeferred) {
+            // "NOT DEFERRABLE INITIALLY DEFERRED" is inconsistent
+            throw StandardException.newException(
+                SQLState.LANG_INCONSISTENT_CONSTRAINT_CHARACTERISTICS);
+        }
+
+        return new boolean[]{deferrable, initiallyDeferred, enforced};
+    }
+}
+
+/*
+ * <A NAME="initiallyDeferred">initiallyDeferred</A>
+ */
+boolean
+initiallyDeferred() :
+{
+}
+{
+    <INITIALLY>
+    (
+        <IMMEDIATE>
+        {
+            return false;
+        }
+    |   <DEFERRED>
+        {
+            return true;
+        }
+    )
+}
+
+/*
+ * <A NAME="deferrable">deferrable</A>
+ */
+boolean
+deferrable() :
+{
+    boolean deferrable = true;
+}
+{
+    [ <NOT>
+      {
+          deferrable = false;
+      }
+    ]
+    <DEFERRABLE>
+    {
+        return deferrable;
+    }
+}
+
+/*
+ * <A NAME="constraintEnforcement">constraintEnforcement</A>
+ */
+boolean
+constraintEnforcement() :
+{
+    boolean enforced = true;
+}
+{
+    [ <NOT>
+      {
+          enforced = false;
+      }
+    ]
+    <ENFORCED>
+    {
+        return enforced;
+    }
+}
+
+
 /*
  * <A NAME="columnConstraintDefinition">columnConstraintDefinition</A>
  */
@@ -12719,13 +12907,24 @@ columnConstraintDefinition(DataTypeDescr
 						   String columnName) throws StandardException :
 {
 	int constraintType;
-	TableElementNode tcdn;
+    ConstraintDefinitionNode tcdn;
 	TableName constraintName = null;
+    boolean[] cc = null; // constraint characteristics
 }
 {
 	[ constraintName = constraintNameDefinition() ]
-		tcdn = columnConstraint(constraintName, dataTypeDescriptor, columnName)
+    tcdn = columnConstraint(constraintName, dataTypeDescriptor, columnName)
+    [ cc = constraintCharacteristics() ]
 	{
+        if (cc != null) {
+            if (tcdn == null) {
+                throw StandardException.newException(
+                    SQLState.LANG_NOT_NULL_CHARACTERISTICS);
+            }
+
+            tcdn.setCharacteristics(cc);
+        }
+
 		/* NOT NULL constraints are handled by marking the dataTypeDescriptor
 		 * as being non-nullable.
 		 */
@@ -13126,6 +13325,8 @@ alterTableAction(TableElementList tableE
 	Token				tok = null;
 	String				columnName;
 	long[]				autoIncrementInfo = new long[4];
+    boolean             enforced;
+    TableName           constraintName;
 }
 {
 	<ADD>
@@ -13147,6 +13348,7 @@ alterTableAction(TableElementList tableE
 		return lockGranularity;
 	}
 |
+        LOOKAHEAD ( { getToken(1).kind == ALTER && getToken(2).kind != CONSTRAINT } )
 	<ALTER> [ <COLUMN> ] columnName = identifier(Limits.MAX_IDENTIFIER_LENGTH, true) 
 		tableElement = columnAlterClause(columnName)
 	{
@@ -13155,6 +13357,32 @@ alterTableAction(TableElementList tableE
 		return lockGranularity;
 	}
 |
+    <ALTER> constraintName = constraintNameDefinition()
+    enforced = constraintEnforcement()
+    {
+        ConstraintDefinitionNode cdn = new ConstraintDefinitionNode(
+            constraintName,
+            DataDictionary.MODIFY_CONSTRAINT,
+            null,
+            null,
+            null,
+            null,
+            StatementType.DROP_DEFAULT,
+            DataDictionary.MODIFY_CONSTRAINT,
+            getContextManager());
+
+        boolean[] cc = new boolean[]{
+            ConstraintDefinitionNode.DEFERRABLE_DEFAULT,
+            ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT,
+            enforced};
+
+        cdn.setCharacteristics(cc);
+        changeType[0] = DDLStatementNode.MODIFY_TYPE;
+        tableElementList.addTableElement(cdn);
+
+        return lockGranularity;
+    }
+|
 	lockGranularity = DB2lockGranularityClause()
 	{
 		changeType[0] = DDLStatementNode.LOCKING_TYPE;
@@ -14452,6 +14680,7 @@ nonReservedKeyword()  :
 	|	tok = <DERBY>
 	|	tok = <DERBY_JDBC_RESULT_SET>
 	|	tok = <DOCUMENT>
+    |   tok = <ENFORCED>
 	|	tok = <EACH>
 	|	tok = <EMPTY>
 	|	tok = <EXCLUSIVE>

Added: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java?rev=1517823&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterConstraintConstantAction.java Tue Aug 27 14:05:03 2013
@@ -0,0 +1,175 @@
+/*
+
+   Derby - Class org.apache.derby.impl.sql.execute.AlterConstraintConstantAction
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derby.impl.sql.execute;
+
+import org.apache.derby.catalog.UUID;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.services.property.PropertyUtil;
+import org.apache.derby.iapi.sql.Activation;
+import org.apache.derby.iapi.sql.StatementType;
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.iapi.sql.depend.DependencyManager;
+import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
+import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList;
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;
+import org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor;
+import org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor;
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
+import org.apache.derby.iapi.sql.execute.ConstantAction;
+import org.apache.derby.iapi.store.access.TransactionController;
+import org.apache.derby.impl.sql.catalog.SYSCONSTRAINTSRowFactory;
+import org.apache.derby.impl.sql.compile.ConstraintDefinitionNode;
+
+/**
+ *  This class  describes actions that are ALWAYS performed for a
+ *  alter constraint at Execution time.
+ */
+
+public class AlterConstraintConstantAction extends ConstraintConstantAction
+{
+
+    private String constraintSchemaName;
+    boolean[] characteristics;
+
+    /**
+     *  Constructor.
+     *
+     *  @param constraintName           The constraint name.
+     *  @param constraintSchemaName     The schema that constraint lives in.
+     *  @param characteristics          The (presumably) altered enforcement
+     *                                  characteristics.
+     *  @param tableName                Table name.
+     *  @param tableId                  The UUID of table.
+     *  @param tableSchemaName          The schema that table lives in.
+     *  @param indexAction              IndexConstantAction for constraint
+     */
+    AlterConstraintConstantAction(
+                       String               constraintName,
+                       String               constraintSchemaName,
+                       boolean[]            characteristics,
+                       String               tableName,
+                       UUID                 tableId,
+                       String               tableSchemaName,
+                       IndexConstantAction indexAction)
+    {
+        super(constraintName, DataDictionary.DROP_CONSTRAINT, tableName,
+              tableId, tableSchemaName, indexAction);
+
+        this.constraintSchemaName = constraintSchemaName;
+        this.characteristics = characteristics.clone();
+    }
+
+    @Override
+    public  String  toString()
+    {
+        // Do not put this under SanityManager.DEBUG - it is needed for
+        // error reporting.
+        String ss = constraintSchemaName == null ? schemaName : constraintSchemaName;
+        return "ALTER CONSTRAINT " + ss + "." + constraintName;
+    }
+
+    /**
+     *  This is the guts of the Execution-time logic for ALTER CONSTRAINT.
+     *
+     *  @see ConstantAction#executeConstantAction
+     *
+     * @exception StandardException     Thrown on failure
+     */
+    public void executeConstantAction(
+            Activation activation ) throws StandardException {
+
+        final LanguageConnectionContext lcc =
+                activation.getLanguageConnectionContext();
+        final DataDictionary dd = lcc.getDataDictionary();
+        final DependencyManager dm = dd.getDependencyManager();
+        final TransactionController tc = lcc.getTransactionExecute();
+
+
+        /*
+        ** Inform the data dictionary that we are about to write to it.
+        ** There are several calls to data dictionary "get" methods here
+        ** that might be done in "read" mode in the data dictionary, but
+        ** it seemed safer to do this whole operation in "write" mode.
+        **
+        ** We tell the data dictionary we're done writing at the end of
+        ** the transaction.
+        */
+        dd.startWriting(lcc);
+
+        final TableDescriptor td = dd.getTableDescriptor(tableId);
+
+        if (td == null)
+        {
+            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
+        }
+
+        /* Table gets locked in AlterTableConstantAction */
+
+        /*
+        ** If the schema descriptor is null, then
+        ** we must have just read ourselves in.
+        ** So we will get the corresponding schema
+        ** descriptor from the data dictionary.
+        */
+
+        SchemaDescriptor tdSd = td.getSchemaDescriptor();
+        SchemaDescriptor constraintSd = constraintSchemaName == null
+                ? tdSd
+                : dd.getSchemaDescriptor(constraintSchemaName, tc, true);
+
+
+        /* Get the constraint descriptor for the index, along
+         * with an exclusive row lock on the row in sys.sysconstraints
+         * in order to ensure that no one else compiles against the
+         * index.
+         */
+        final ConstraintDescriptor conDesc =
+                dd.getConstraintDescriptorByName(td, constraintSd, constraintName, true);
+
+
+        if (conDesc == null) {
+            throw StandardException.newException(
+                    SQLState.LANG_DROP_OR_ALTER_NON_EXISTING_CONSTRAINT,
+                     constraintSd.getSchemaName() + "."+ constraintName,
+                    td.getQualifiedName());
+        }
+
+        if (characteristics[2] != ConstraintDefinitionNode.ENFORCED_DEFAULT) {
+            // Remove when feature DERBY-532 is completed
+            if (!PropertyUtil.getSystemProperty("derby.constraintsTesting",
+                    tableName).equals("true")) {
+                throw StandardException.newException(SQLState.NOT_IMPLEMENTED,
+                        "non-default enforcement");
+            }
+        }
+
+        // The first two characteristics are unused during ALTER CONSTRAINT; only
+        // enforcement can change.
+        conDesc.setEnforced(characteristics[2]);
+
+        int[] colsToSet = new int[1];
+        colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_STATE;
+        dd.updateConstraintDescriptor(conDesc, conDesc.getUUID(), colsToSet, tc);
+    }
+}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/AlterTableConstantAction.java Tue Aug 27 14:05:03 2013
@@ -538,7 +538,7 @@ class AlterTableConstantAction extends D
         // adjust dependencies on user defined types
         adjustUDTDependencies( lcc, dd, td, columnInfo, false );
 
-		/* Create/Drop any constraints */
+        /* Create/Drop/alter any constraints */
 		if (constraintActions != null)
 		{
 			for (int conIndex = 0; 
@@ -607,7 +607,8 @@ class AlterTableConstantAction extends D
 				{
 					if (SanityManager.DEBUG)
 					{
-						if (!(cca instanceof DropConstraintConstantAction))
+                        if (!(cca instanceof DropConstraintConstantAction ||
+                              cca instanceof AlterConstraintConstantAction))
 						{
 							SanityManager.THROWASSERT(
                                 "constraintActions[" + conIndex + 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateConstraintConstantAction.java Tue Aug 27 14:05:03 2013
@@ -55,6 +55,8 @@ import org.apache.derby.iapi.sql.Activat
 
 import org.apache.derby.iapi.store.access.TransactionController;
 import org.apache.derby.iapi.services.loader.ClassFactory;
+import org.apache.derby.iapi.services.property.PropertyUtil;
+import org.apache.derby.impl.sql.compile.ConstraintDefinitionNode;
 
 /**
  *	This class  describes actions that are ALWAYS performed for a
@@ -74,13 +76,16 @@ public class CreateConstraintConstantAct
 	private	ClassFactory	cf;
 
 	/*
-	** Is this constraint to be created as enabled or not.
+    ** Is this constraint to be created as enforced or not.
 	** The only way to create a disabled constraint is by
 	** publishing a disabled constraint.
 	*/
 	private boolean			enabled;
 
-	private ProviderInfo[] providerInfo;
+    // boolean[3]: {deferrable?, initiallyDeferred?, enforced?}
+    private boolean[]       characteristics;
+
+    private ProviderInfo[] providerInfo;
 
 	// CONSTRUCTORS
 
@@ -89,6 +94,7 @@ public class CreateConstraintConstantAct
 	 *
 	 *  @param constraintName	Constraint name.
 	 *  @param constraintType	Constraint type.
+     *  @param characteristics  Constraint characteristics
      *  @param forCreateTable   Constraint is being added for a CREATE TABLE
 	 *  @param tableName		Table name.
 	 *	@param tableId			UUID of table.
@@ -96,16 +102,13 @@ public class CreateConstraintConstantAct
 	 *  @param columnNames		String[] for column names
 	 *  @param indexAction		IndexConstantAction for constraint (if necessary)
 	 *  @param constraintText	Text for check constraint
-	 *  RESOLVE - the next parameter should go away once we use UUIDs
-	 *			  (Generated constraint names will be based off of uuids)
-	 *	@param enabled			Should the constraint be created as enabled 
-	 *							(enabled == true), or disabled (enabled == false).
 	 *	@param otherConstraint 	information about the constraint that this references
 	 *  @param providerInfo Information on all the Providers
 	 */
 	CreateConstraintConstantAction(
 		               String	constraintName,
 					   int		constraintType,
+                       boolean[] characteristics,
                        boolean  forCreateTable,
 		               String	tableName,
 					   UUID		tableId,
@@ -113,7 +116,6 @@ public class CreateConstraintConstantAct
 					   String[]	columnNames,
 					   IndexConstantAction indexAction,
 					   String	constraintText,
-					   boolean	enabled,
 				       ConstraintInfo	otherConstraint,
 					   ProviderInfo[] providerInfo)
 	{
@@ -122,7 +124,7 @@ public class CreateConstraintConstantAct
         this.forCreateTable = forCreateTable;
 		this.columnNames = columnNames;
 		this.constraintText = constraintText;
-		this.enabled = enabled;
+        this.characteristics = characteristics.clone();
 		this.otherConstraintInfo = otherConstraint;
 		this.providerInfo = providerInfo;
 	}
@@ -282,6 +284,23 @@ public class CreateConstraintConstantAct
 
 		UUID constraintId = uuidFactory.createUUID();
 
+        boolean[] defaults = new boolean[]{
+            ConstraintDefinitionNode.DEFERRABLE_DEFAULT,
+            ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT,
+            ConstraintDefinitionNode.ENFORCED_DEFAULT
+        };
+
+        for (int i=0; i < characteristics.length; i++) {
+            if (characteristics[i] != defaults[i]) {
+                // Remove when feature DERBY-532 is completed
+                if (!PropertyUtil.getSystemProperty("derby.constraintsTesting",
+                        tableName).equals("true")) {
+                    throw StandardException.newException(SQLState.NOT_IMPLEMENTED,
+                            "non-default constraint characteristics");
+                }
+            }
+        }
+
 		/* Now, lets create the constraint descriptor */
 		DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
 		switch (constraintType)
@@ -289,13 +308,13 @@ public class CreateConstraintConstantAct
 			case DataDictionary.PRIMARYKEY_CONSTRAINT:
 				conDesc = ddg.newPrimaryKeyConstraintDescriptor(
 								td, constraintName,
-								false, //deferable,
-								false, //initiallyDeferred,
+                                characteristics[0], //deferable,
+                                characteristics[1], //initiallyDeferred,
 								genColumnPositions(td, false), //int[],
 								constraintId, 
 								indexId, 
 								sd,
-								enabled,
+                                characteristics[2],
 								0				// referenceCount
 								);
 				dd.addConstraintDescriptor(conDesc, tc);
@@ -304,13 +323,13 @@ public class CreateConstraintConstantAct
 			case DataDictionary.UNIQUE_CONSTRAINT:
 				conDesc = ddg.newUniqueConstraintDescriptor(
 								td, constraintName,
-								false, //deferable,
-								false, //initiallyDeferred,
+                                characteristics[0], //deferable,
+                                characteristics[1], //initiallyDeferred,
 								genColumnPositions(td, false), //int[],
 								constraintId, 
 								indexId, 
 								sd,
-								enabled,
+                                characteristics[2],
 								0				// referenceCount
 								);
 				dd.addConstraintDescriptor(conDesc, tc);
@@ -319,13 +338,13 @@ public class CreateConstraintConstantAct
 			case DataDictionary.CHECK_CONSTRAINT:
 				conDesc = ddg.newCheckConstraintDescriptor(
 								td, constraintName,
-								false, //deferable,
-								false, //initiallyDeferred,
+                                characteristics[0], //deferable,
+                                characteristics[1], //initiallyDeferred,
 								constraintId, 
 								constraintText, 
 								new ReferencedColumnsDescriptorImpl(genColumnPositions(td, false)), //int[],
 								sd,
-								enabled
+                                characteristics[2]
 								);
 				dd.addConstraintDescriptor(conDesc, tc);
 				storeConstraintDependenciesOnPrivileges
@@ -339,14 +358,14 @@ public class CreateConstraintConstantAct
 				
 				conDesc = ddg.newForeignKeyConstraintDescriptor(
 								td, constraintName,
-								false, //deferable,
-								false, //initiallyDeferred,
+                                characteristics[0], //deferable,
+                                characteristics[1], //initiallyDeferred,
 								genColumnPositions(td, false), //int[],
 								constraintId,
 								indexId,
 								sd,
 								referencedConstraint,
-								enabled,
+                                characteristics[2],
 								otherConstraintInfo.getReferentialActionDeleteRule(),
 								otherConstraintInfo.getReferentialActionUpdateRule()
 								);
@@ -379,6 +398,10 @@ public class CreateConstraintConstantAct
 					 providerInfo);
 				break;
 
+            case DataDictionary.MODIFY_CONSTRAINT:
+                throw StandardException.newException(SQLState.NOT_IMPLEMENTED,
+                       "ALTER CONSTRAINT");
+
 			default:
 				if (SanityManager.DEBUG)
 				{
@@ -388,6 +411,9 @@ public class CreateConstraintConstantAct
 				break;
 		}
 
+
+
+
 		/* Create stored dependencies for each provider */
 		if (providerInfo != null)
 		{

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropConstraintConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropConstraintConstantAction.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropConstraintConstantAction.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DropConstraintConstantAction.java Tue Aug 27 14:05:03 2013
@@ -188,7 +188,7 @@ public class DropConstraintConstantActio
 			String errorName = constraintName == null ? "PRIMARY KEY" :
 								(constraintSd.getSchemaName() + "."+ constraintName);
 
-			throw StandardException.newException(SQLState.LANG_DROP_NON_EXISTENT_CONSTRAINT, 
+            throw StandardException.newException(SQLState.LANG_DROP_OR_ALTER_NON_EXISTING_CONSTRAINT,
 						errorName,
 						td.getQualifiedName());
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java?rev=1517823&r1=1517822&r2=1517823&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericConstantActionFactory.java Tue Aug 27 14:05:03 2013
@@ -85,27 +85,14 @@ public class GenericConstantActionFactor
 	/**
 	 * Get ConstantAction for SET CONSTRAINTS statement.
 	 *
-	 *  @param cdl			the constraints to set, if null,
-	 *						we'll go ahead and set them all
-	 *  @param enable		if true, turn them on, if false
-	 *						disable them
-	 *  @param unconditionallyEnforce	Replication sets this to true at
-	 *									the end of REFRESH. This forces us
-	 *									to run the included foreign key constraints even
-	 *									if they're already marked ENABLED.
-	 *	@param ddlList		Replication list of actions to propagate,
-	 *						null unless a replication source
-	 */
-	public	ConstantAction getSetConstraintsConstantAction
-	(
-		ConstraintDescriptorList	cdl,
-		boolean						enable,
-		boolean						unconditionallyEnforce,
-		Object[]					ddlList
-    )
-	{
-		// ignore rep arg
-		return new SetConstraintsConstantAction(cdl, enable, unconditionallyEnforce);
+     *  @param constraints  The constraints to set, if null,
+     *                      set them ALL.
+     *  @param initiallyDeferred   ncodes IMMEDIATE (false), DEFERRED (true)
+	 */
+    public  ConstantAction getSetConstraintsConstantAction(
+            List<TableName> constraints,
+            boolean         initiallyDeferred) {
+        return new SetConstraintsConstantAction(constraints, initiallyDeferred);
 	}
 
 
@@ -183,6 +170,9 @@ public class GenericConstantActionFactor
 	 *
 	 *  @param constraintName	Constraint name.
 	 *  @param constraintType	Constraint type.
+     *  @param constraintCharacteristics
+     *                          Constraint characteristics, see {@link
+     *  org.apache.derby.impl.sql.compile.ConstraintDefinitionNode#characteristics}
      *  @param forCreateTable   True if for a CREATE TABLE
 	 *  @param tableName		Table name.
 	 *	@param tableId			UUID of table.
@@ -190,8 +180,6 @@ public class GenericConstantActionFactor
 	 *  @param columnNames		String[] for column names
 	 *  @param indexAction		IndexConstantAction for constraint (if necessary)
 	 *  @param constraintText	Text for check constraint
-	 *	@param enabled			Should the constraint be created as enabled 
-	 *							(enabled == true), or disabled (enabled == false).
 	 *	@param otherConstraint	The referenced constraint, if a foreign key constraint
 	 *  @param providerInfo Information on all the Providers
 	 */
@@ -199,6 +187,7 @@ public class GenericConstantActionFactor
 	(
 		String				constraintName,
 		int					constraintType,
+        boolean[]           constraintCharacteristics,
         boolean             forCreateTable,
 		String				tableName,
 		UUID				tableId,
@@ -206,15 +195,23 @@ public class GenericConstantActionFactor
 		String[]			columnNames,
 		IndexConstantAction indexAction,
 		String				constraintText,
-		boolean				enabled,
 		ConstraintInfo		otherConstraint,
 		ProviderInfo[]		providerInfo
 	)
 	{
-		return new CreateConstraintConstantAction
-			( constraintName, constraintType, forCreateTable, tableName, 
-			  tableId, schemaName, columnNames, indexAction, constraintText, 
-			  enabled, otherConstraint, providerInfo );
+        return new CreateConstraintConstantAction(
+                constraintName,
+                constraintType,
+                constraintCharacteristics,
+                forCreateTable,
+                tableName,
+                tableId,
+                schemaName,
+                columnNames,
+                indexAction,
+                constraintText,
+                otherConstraint,
+                providerInfo );
 	}
 
 
@@ -554,6 +551,39 @@ public class GenericConstantActionFactor
 
 
 	/**
+     *  Make ConstantAction to drop a constraint.
+     *
+     *  @param constraintName   Constraint name.
+     *  @param constraintSchemaName     Constraint Schema Name
+     *  @param characteristics  The presumably altered characteristics
+     *  @param tableName        Table name.
+     *  @param tableId          UUID of table.
+     *  @param tableSchemaName  The schema that table lives in.
+     *  @param indexAction      IndexConstantAction for constraint (if necessary)
+     */
+    public  ConstraintConstantAction    getAlterConstraintConstantAction
+    (
+        String                  constraintName,
+        String                  constraintSchemaName,
+        boolean[]               characteristics,
+        String                  tableName,
+        UUID                    tableId,
+        String                  tableSchemaName,
+        IndexConstantAction     indexAction
+    )
+    {
+        return  new AlterConstraintConstantAction(
+                constraintName,
+                constraintSchemaName,
+                characteristics,
+                tableName,
+                tableId,
+                tableSchemaName,
+                indexAction);
+    }
+
+
+    /**
 	 *	Make the ConstantAction for a DROP INDEX statement.
 	 *
 	 *
@@ -782,7 +812,9 @@ public class GenericConstantActionFactor
 	/**
 	 *	Make the ConstantAction for an updatable VTI statement.
 	 *
-	 * @param deferred					Deferred mode?
+     * @param statementType             Statement type, cf.
+     * {@link org.apache.derby.vti.DeferModification#INSERT_STATEMENT} etc.
+     * @param deferred                  Deferred processing mode?
 	 *
 	 * @exception StandardException		Thrown on failure
 	 */
@@ -795,7 +827,9 @@ public class GenericConstantActionFactor
 	/**
 	 *	Make the ConstantAction for an updatable VTI statement.
 	 *
-	 * @param deferred					Deferred mode?
+     * @param statementType    Statement type, cf.
+     * {@link org.apache.derby.vti.DeferModification#INSERT_STATEMENT} etc.
+     * @param deferred         Deferred processing mode?
      * @param changedColumnIds Array of ids of changed columns
 	 *
 	 * @exception StandardException		Thrown on failure



Mime
View raw message