db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r523884 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Date Thu, 29 Mar 2007 23:54:28 GMT
Author: djd
Date: Thu Mar 29 16:54:27 2007
New Revision: 523884

URL: http://svn.apache.org/viewvc?view=rev&rev=523884
Log:
DERBY-2490 (partial) Cleanup in GenericLanguageConnectionContext for the current use
of read-only nested transaction. Part of a series of changes to align the LCC use
of nested transactions with the api provided by the store, including moving
all calls to get a nested transaction for an LCC to be through the LCC and not via
its transaction directly.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java?view=diff&rev=523884&r1=523883&r2=523884
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/conn/GenericLanguageConnectionContext.java
Thu Mar 29 16:54:27 2007
@@ -149,19 +149,20 @@
 	private final TransactionController tran;
 
 	/**
-	 * If non-null indicates that a nested user transaction is in progress.
+	 * If non-null indicates that a read-only nested 
+     * user transaction is in progress.
 	 */
-	private TransactionController childTransaction;
+	private TransactionController readOnlyNestedTransaction;
 	
 	/**
 	 * queryNestingDepth is a counter used to keep track of how many calls 
-	 * have been made to begin nested transactions. Only the first call 
+	 * have been made to begin read-only nested transactions. Only the first call 
 	 * actually starts a Nested User Transaction with the store. Subsequent
 	 * calls simply increment this counter. commitNestedTransaction only
 	 * decrements the counter and when it drops to 0 actually commits the 
 	 * nested user transaction.
 	 */
-	protected int queryNestingDepth;
+	private int queryNestingDepth;
 
 	protected DataValueFactory dataFactory;
 	protected LanguageFactory langFactory;
@@ -1128,6 +1129,16 @@
 		{
 			finishDDTransaction();
 		}
+        
+        // Check that any nested transaction has been destoyed
+        // before a commit.
+        if (SanityManager.DEBUG)
+        {
+            if (readOnlyNestedTransaction != null)
+            {
+                SanityManager.THROWASSERT("Nested transaction active!");
+            }
+        }
 
 		// now commit the Store transaction
 		TransactionController tc = getTransactionExecute();
@@ -1325,6 +1336,16 @@
 			tempTablesAndRollback();
 
 		finishDDTransaction();
+        
+        // If a nested transaction is active then
+        // ensure it is destroyed before working
+        // with the user transaction.
+        if (readOnlyNestedTransaction != null)
+        {
+            readOnlyNestedTransaction.destroy();
+            readOnlyNestedTransaction = null;
+            queryNestingDepth = 0;
+        }
 
 		// now rollback the Store transaction
 		TransactionController tc = getTransactionExecute();
@@ -1334,6 +1355,7 @@
 				((XATransactionController)tc).xa_rollback();
 			else
 				tc.abort(); 
+            
 			// reset the savepoints to the new
 			// location, since any outer nesting
 			// levels expet there to be a savepoint
@@ -1449,10 +1471,14 @@
 	 */
 	public void beginNestedTransaction(boolean readOnly) throws StandardException
 	{
-		if (childTransaction == null)
-			childTransaction = tran.startNestedUserTransaction(readOnly);
+        // DERBY-2490 incremental rework, currently this is only called
+        // with read-only true. Future changes will have this
+        // method support read-write nested transactions as well
+        // instead of callers using the startNestedUserTransaction
+        // directly on tran.
+		if (readOnlyNestedTransaction == null)
+			readOnlyNestedTransaction = tran.startNestedUserTransaction(readOnly);
 		queryNestingDepth++;
-		return;
 	}
 
 	public void commitNestedTransaction()
@@ -1460,10 +1486,9 @@
 	{
 		if (--queryNestingDepth == 0)
 		{
-			childTransaction.commit();
-			childTransaction.destroy();
-			childTransaction = null;
-			return;
+			readOnlyNestedTransaction.commit();
+			readOnlyNestedTransaction.destroy();
+			readOnlyNestedTransaction = null;
 		}
 	}
 
@@ -1474,7 +1499,7 @@
 	 */
 	public TransactionController getTransactionCompile()
 	{
-		return (childTransaction != null) ? childTransaction : tran;
+		return (readOnlyNestedTransaction != null) ? readOnlyNestedTransaction : tran;
 	}
 
 	public TransactionController getTransactionExecute()



Mime
View raw message