List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:December 20 2007 12:51pm
Subject:Rev 387: Added support for NdbJtaTransaction in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 387
revision-id:mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Thu 2007-12-20 10:51:01 -0200
message:
  Added support for NdbJtaTransaction
modified:
  java/com/mysql/cluster/ndbj/NdbJtaTransaction.java
ndbjtatransaction.ja-20071220020348-va7lrb65xv544s7l-1
  java/testsuite/ndbj/BasicTest.java basictest.java-20070529154705-qmbr2wjlqu4mcnay-1
=== modified file 'java/com/mysql/cluster/ndbj/NdbJtaTransaction.java'
--- a/java/com/mysql/cluster/ndbj/NdbJtaTransaction.java	2007-12-20 02:23:51 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbJtaTransaction.java	2007-12-20 12:51:01 +0000
@@ -8,15 +8,38 @@
 import javax.transaction.Transaction;
 import javax.transaction.xa.XAResource;
 
-public class NdbJtaTransaction implements Transaction {
+public abstract class NdbJtaTransaction implements Transaction {
 
+	private Synchronization synchronization = null;
+	private boolean rollbackOnly = false;
+	private boolean inCommit = false;
+	
+	public abstract int execute(ExecType execType, AbortOption abortOption, boolean force)
throws NdbApiException;
+	
 	public void commit() throws RollbackException, HeuristicMixedException,
 			HeuristicRollbackException, SecurityException,
 			IllegalStateException, SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("commit");
-
+		inCommit = true;
+		int retVal = -1;
+		if (synchronization != null) 
+			synchronization.beforeCompletion();
+		try { 
+			if (rollbackOnly) { 
+				throw new RollbackException("Rollback requested");
+			}
+			retVal = execute(ExecType.Commit,AbortOption.AbortOnError,false);
+		} catch (NdbApiException e) { 
+			rollback();
+			throw new RollbackException("Transaction failed and was rolled back: "+e.message);
+		} catch (RollbackException rbE) { 
+			rollback();
+			throw rbE;
+		} finally { 
+			if (synchronization != null)
+				synchronization.afterCompletion(retVal);
+			inCommit = false;
+		}
+		
 	}
 
 	public boolean delistResource(XAResource arg0, int arg1)
@@ -42,26 +65,29 @@
 
 	}
 
-	public void registerSynchronization(Synchronization arg0)
+	public void registerSynchronization(Synchronization theSynchronization)
 			throws RollbackException, IllegalStateException, SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("registerSynchronization");
-
+			synchronization = theSynchronization;
 	}
 
 	public void rollback() throws IllegalStateException, SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("rollback");
-
+		int retVal = -1;
+		if (!inCommit && synchronization != null) {
+			synchronization.beforeCompletion();
+		}
+		try { 
+			retVal = execute(ExecType.Rollback,AbortOption.AbortOnError,false);
+		} catch (NdbApiException e) { 
+			throw new SystemException("Couldn't rollback - something is seriously wrong: " +
e.message);
+		} finally { 
+			if (!inCommit && synchronization != null) {
+				synchronization.afterCompletion(retVal);
+			}
+		}
 	}
 
 	public void setRollbackOnly() throws IllegalStateException, SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("setRollbackOnly");
-
+		rollbackOnly = true;
 	}
 
 }

=== modified file 'java/testsuite/ndbj/BasicTest.java'
--- a/java/testsuite/ndbj/BasicTest.java	2007-12-09 22:26:12 +0000
+++ b/java/testsuite/ndbj/BasicTest.java	2007-12-20 12:51:01 +0000
@@ -22,7 +22,25 @@
 		this.createTable("basic_test", "(id int, name varchar(32), age int, primary key(id))
engine=ndbcluster");
 		
 	}
-
+	
+    public void testFinallyStilExecutes() {
+        boolean finallyExecuted = false;
+
+        try {
+            try {
+                throw new NdbApiException("test finally execution");
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            } finally {
+                finallyExecuted = true;
+            }
+        } catch (Exception expected) {
+            //
+        }
+
+        assertTrue(finallyExecuted);
+    }
+	
 	public void testSingleInsertString() throws NdbApiException,SQLException { 
 	
 		trans = ndb.startTransaction();

Thread
Rev 387: Added support for NdbJtaTransaction in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/develMonty Taylor20 Dec