db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1524645 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute: GenericTriggerExecutor.java RowTriggerExecutor.java StatementTriggerExecutor.java
Date Thu, 19 Sep 2013 07:51:45 GMT
Author: kahatlen
Date: Thu Sep 19 07:51:45 2013
New Revision: 1524645

URL: http://svn.apache.org/r1524645
Log:
DERBY-534: Support use of the WHEN clause in CREATE TRIGGER statements

Move common logic for executing WHEN clause and trigger action to the
base class GenericTriggerExecutor. In addition to reducing code
duplication, the change makes row triggers reuse the prepared
statement for the WHEN clause (same as it already does for the trigger
action), and it makes statement triggers not leave the before and
after result sets open if the WHEN clause evaluates to false.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java?rev=1524645&r1=1524644&r2=1524645&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/GenericTriggerExecutor.java
Thu Sep 19 07:51:45 2013
@@ -112,7 +112,7 @@ abstract class GenericTriggerExecutor
 		return whenClause;
 	}
 
-	protected SPSDescriptor getAction() throws StandardException
+    private SPSDescriptor getAction() throws StandardException
 	{
 		if (!actionRetrieved)
 		{
@@ -134,7 +134,7 @@ abstract class GenericTriggerExecutor
      *         to {@code TRUE}, {@code false} otherwise
 	 * @exception StandardException on error
 	 */
-    final boolean executeSPS(SPSDescriptor sps, boolean isWhen)
+    private boolean executeSPS(SPSDescriptor sps, boolean isWhen)
             throws StandardException
 	{
 		boolean recompile = false;
@@ -301,7 +301,7 @@ abstract class GenericTriggerExecutor
 	}
 
 	/**
-     * Cleanup after executing the SPS for the trigger action.
+     * Cleanup after executing the SPS for the WHEN clause and trigger action.
 	 *
 	 * @exception StandardException on error
 	 */
@@ -312,34 +312,32 @@ abstract class GenericTriggerExecutor
         }
         actionPS = null;
         spsActionActivation = null;
+
+        if (spsWhenActivation != null) {
+            spsWhenActivation.close();
+        }
+        whenPS = null;
+        spsWhenActivation = null;
 	}
 
     /**
-     * Evaluate the WHEN clause, if there is one, and return whether the
-     * trigger action should be executed.
+     * <p>
+     * Execute the WHEN clause SPS and the trigger action SPS.
+     * </p>
+     *
+     * <p>
+     * If there is no WHEN clause, the trigger action should always be
+     * executed. If there is a WHEN clause, the trigger action should only
+     * be executed if the WHEN clause returns TRUE.
+     * </p>
      *
-     * @return {@code true} if the trigger action should be executed (that is,
-     *   if there is no WHEN clause or if the WHEN clause evaluates to TRUE),
-     *   {@code false} otherwise
-     * @throws StandardException if an error happens when executing the
-     *   WHEN clause
+     * @throws StandardException if trigger execution fails
      */
-    final boolean executeWhenClause() throws StandardException {
+    final void executeWhenClauseAndAction() throws StandardException {
         SPSDescriptor whenClauseDescriptor = getWhenClause();
-
-        if (whenClauseDescriptor == null) {
-            // Always execute the trigger action if there is no WHEN clause.
-            return true;
-        }
-
-        try {
-            return executeSPS(whenClauseDescriptor, true);
-        } finally {
-            if (spsWhenActivation != null) {
-                spsWhenActivation.close();
-            }
-            whenPS = null;
-            spsWhenActivation = null;
+        if (whenClauseDescriptor == null ||
+                executeSPS(whenClauseDescriptor, true)) {
+            executeSPS(getAction(), false);
         }
     }
 } 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java?rev=1524645&r1=1524644&r2=1524645&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
Thu Sep 19 07:51:45 2013
@@ -110,11 +110,7 @@ class RowTriggerExecutor extends Generic
 				if (event.isAfter()) 
 					tec.updateAICounters();
 
-                // Execute the trigger action only if the WHEN clause returns
-                // TRUE or there is no WHEN clause.
-                if (executeWhenClause()) {
-                    executeSPS(getAction(), false);
-                }
+                executeWhenClauseAndAction();
 				
 				/*
 				  For BEFORE ROW triggers, update the ai values after the SPS

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java?rev=1524645&r1=1524644&r2=1524645&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/StatementTriggerExecutor.java
Thu Sep 19 07:51:45 2013
@@ -78,15 +78,11 @@ class StatementTriggerExecutor extends G
 		tec.setBeforeResultSet(brs);
 		tec.setAfterResultSet(ars);
 
-        // Execute the trigger action only if the WHEN clause returns
-        // TRUE or there is no WHEN clause.
-        if (executeWhenClause()) {
-            try {
-                executeSPS(getAction(), false);
-            } finally {
-                clearSPS();
-                tec.clearTrigger();
-            }
+        try {
+            executeWhenClauseAndAction();
+        } finally {
+            clearSPS();
+            tec.clearTrigger();
         }
 	}
 }



Mime
View raw message