db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1559218 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/MergeResultSet.java testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
Date Fri, 17 Jan 2014 18:50:16 GMT
Author: rhillegas
Date: Fri Jan 17 18:50:15 2014
New Revision: 1559218

URL: http://svn.apache.org/r1559218
Log:
DERBY-3155: Make cleanup logic in MergeResultSet more closely resemble the cleanup logic in
InsertResultSet; commit derby-3155-15-aa-replumbMergeResultSetCleanup.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeResultSet.java?rev=1559218&r1=1559217&r2=1559218&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeResultSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/MergeResultSet.java
Fri Jan 17 18:50:15 2014
@@ -60,6 +60,8 @@ class MergeResultSet extends NoRowsResul
     private long                        _rowCount;
     private TemporaryRowHolderImpl[]    _thenRows;
 
+	private int						numOpens;
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // CONSTRUCTOR
@@ -95,6 +97,15 @@ class MergeResultSet extends NoRowsResul
     {
         setup();
 
+		if (numOpens++ == 0)
+		{
+			_drivingLeftJoin.openCore();
+		}
+		else
+		{
+			_drivingLeftJoin.reopenCore();
+		}
+
         boolean rowsFound = collectAffectedRows();
         if ( !rowsFound )
         {
@@ -124,7 +135,6 @@ class MergeResultSet extends NoRowsResul
         }
 
         _rowCount = 0L;
-        _drivingLeftJoin.openCore();
     }
     
     /**
@@ -149,12 +159,15 @@ class MergeResultSet extends NoRowsResul
             
             _constants.getMatchingClause( i ).cleanUp();
         }
+
+        if ( _drivingLeftJoin != null ) { _drivingLeftJoin.close(); }
+		numOpens = 0;
     }
 
 
     public void finish() throws StandardException
     {
-        _drivingLeftJoin.finish();
+        if ( _drivingLeftJoin != null ) { _drivingLeftJoin.finish(); }
         super.finish();
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java?rev=1559218&r1=1559217&r2=1559218&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/MergeStatementTest.java
Fri Jan 17 18:50:15 2014
@@ -4565,6 +4565,75 @@ public class MergeStatementTest extends 
         goodStatement( dboConnection, "drop table t1_027" );
     }
     
+    /**
+     * <p>
+     * Verify that you can drive MERGE statements from row-based triggers.
+     * </p>
+     */
+    public  void    test_028_basicRowTrigger()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+
+        //
+        // create schema
+        //
+        goodStatement
+            (
+             dboConnection,
+             "create view singlerow_028( x ) as values 1"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t1_028( x int )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create table t2_028( y int )"
+             );
+        goodStatement
+            (
+             dboConnection,
+             "create trigger tr after insert on t1_028\n" +
+             "referencing new as new\n" +
+             "for each row\n" +
+             "merge into t2_028\n" +
+             "using singlerow_028 on t2_028.y = new.x\n" +
+             "when not matched then insert ( y ) values ( new.x )\n"
+             );
+
+        // now exercise the trigger
+        goodStatement
+            (
+             dboConnection,
+             "insert into t1_028 values 1,2,3,4,5,4,3,2,1,1,1,2,3,100"
+             );
+        assertResults
+            (
+             dboConnection,
+             "select * from t2_028 order by y",
+             new String[][]
+             {
+                 { "1" },
+                 { "2" },
+                 { "3" },
+                 { "4" },
+                 { "5" },
+                 { "100" },
+             },
+             false
+             );
+
+        //
+        // drop schema
+        //
+        goodStatement( dboConnection, "drop table t1_028" );
+        goodStatement( dboConnection, "drop table t2_028" );
+        goodStatement( dboConnection, "drop view singlerow_028" );
+    }
+    
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // ROUTINES



Mime
View raw message