Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / execute / RowTriggerExecutor.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/execute/RowTriggerExecutor.java
new file mode 100644 (file)
index 0000000..a4512d5
--- /dev/null
@@ -0,0 +1,128 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.execute.RowTriggerExecutor\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.execute;\r
+\r
+import org.apache.derby.iapi.sql.execute.CursorResultSet;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+import org.apache.derby.iapi.sql.Activation;\r
+\r
+/**\r
+ * A row trigger executor is an object that executes\r
+ * a row trigger.  It is instantiated at execution time.\r
+ * There is one per row trigger.\r
+ */\r
+public class RowTriggerExecutor extends GenericTriggerExecutor\r
+{\r
+       /**\r
+        * Constructor\r
+        *\r
+        * @param tec the execution context\r
+        * @param triggerd the trigger descriptor\r
+        * @param activation the activation\r
+        * @param lcc the lcc\r
+        */\r
+       RowTriggerExecutor\r
+       (\r
+               InternalTriggerExecutionContext tec, \r
+               TriggerDescriptor                               triggerd,\r
+               Activation                                              activation,\r
+               LanguageConnectionContext               lcc\r
+       )\r
+       {\r
+               super(tec, triggerd, activation, lcc);\r
+       }\r
+\r
+       /**\r
+        * Fire the trigger based on the event.\r
+        *\r
+        * @param event the trigger event\r
+        * @param brs   the before result set\r
+        * @param ars   the after result set\r
+        *\r
+        * @exception StandardExcetion on error or general trigger\r
+        *      exception\r
+        */\r
+       void fireTrigger \r
+       (\r
+               TriggerEvent            event, \r
+               CursorResultSet         brs, \r
+               CursorResultSet         ars\r
+       ) throws StandardException\r
+       {\r
+               tec.setTrigger(triggerd);\r
+               \r
+               try\r
+               {\r
+                       while (true)\r
+                       {\r
+                               if (brs != null)\r
+                               {\r
+                                       if (brs.getNextRow() == null)   \r
+                                               break;\r
+                               }\r
+       \r
+                               if (ars != null)\r
+                               {\r
+                                       if (ars.getNextRow() == null)   \r
+                                               break;\r
+                               }\r
+       \r
+                               tec.setBeforeResultSet(brs == null ? \r
+                                               null : \r
+                                               TemporaryRowHolderResultSet.\r
+                                                                          getNewRSOnCurrentRow(activation, brs));\r
+                                       \r
+                               tec.setAfterResultSet(ars == null ? \r
+                                                                         null : \r
+                                                                         TemporaryRowHolderResultSet.\r
+                                                                         getNewRSOnCurrentRow(activation, ars));\r
+\r
+                               /*      \r
+                                       This is the key to handling autoincrement values that might\r
+                                       be seen by insert triggers. For an AFTER ROW trigger, update\r
+                                       the autoincrement counters before executing the SPS for the\r
+                                       trigger.\r
+                               */\r
+                               if (event.isAfter()) \r
+                                       tec.updateAICounters();\r
+\r
+                               executeSPS(getAction());\r
+                               \r
+                               /*\r
+                                 For BEFORE ROW triggers, update the ai values after the SPS\r
+                                 has been executed. This way the SPS will see ai values from\r
+                                 the previous row.\r
+                               */\r
+                               if (event.isBefore())\r
+                                       tec.updateAICounters();\r
+                       }\r
+               } \r
+               finally\r
+               {\r
+                       clearSPS();\r
+                       tec.clearTrigger();\r
+               }\r
+       }\r
+}\r