List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:December 20 2007 1:35pm
Subject:Rev 295: Merged. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/telco-6.3
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/telco-6.3

------------------------------------------------------------
revno: 295
revision-id:mtaylor@stripped
parent: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: telco-6.3
timestamp: Thu 2007-12-20 11:35:47 -0200
message:
  Merged.
modified:
  java/com/mysql/cluster/ndbj/NdbJtaTransaction.java
ndbjtatransaction.ja-20071220020348-va7lrb65xv544s7l-1
  java/com/mysql/cluster/ndbj/NdbTransactionManager.java
ndbtransactionmanage-20071220020348-va7lrb65xv544s7l-2
  java/testsuite/ndbj/BasicTest.java basictest.java-20070529154705-qmbr2wjlqu4mcnay-1
    ------------------------------------------------------------
    revno: 192.1.25.1.107.1.63
    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
    ------------------------------------------------------------
    revno: 192.1.25.1.107.1.62
    revision-id:mtaylor@stripped
    parent: mtaylor@stripped
    committer: Monty Taylor <mtaylor@stripped>
    branch nick: devel
    timestamp: Thu 2007-12-20 10:06:40 -0200
    message:
      And actually removed the NdbImplementedException
    modified:
      java/com/mysql/cluster/ndbj/NdbTransactionManager.java
ndbtransactionmanage-20071220020348-va7lrb65xv544s7l-2
    ------------------------------------------------------------
    revno: 192.1.25.1.107.1.61
    revision-id:mtaylor@stripped
    parent: mtaylor@stripped
    committer: Monty Taylor <mtaylor@stripped>
    branch nick: devel
    timestamp: Thu 2007-12-20 10:05:56 -0200
    message:
      Fixed a type error in NdbTransactionManager
    modified:
      java/com/mysql/cluster/ndbj/NdbTransactionManager.java
ndbtransactionmanage-20071220020348-va7lrb65xv544s7l-2
    ------------------------------------------------------------
    revno: 192.1.25.1.107.1.60
    revision-id:mtaylor@stripped
    parent: mtaylor@stripped
    committer: Monty Taylor <mtaylor@stripped>
    branch nick: devel
    timestamp: Thu 2007-12-20 00:45:12 -0200
    message:
      Implemented TransactionManager methods. Even though we shouldn't share Ndb objects
between threads, I stuck the NdbTransaction in a ThreadLocal just to be sure. 
    modified:
      java/com/mysql/cluster/ndbj/NdbTransactionManager.java
ndbtransactionmanage-20071220020348-va7lrb65xv544s7l-2
=== 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/com/mysql/cluster/ndbj/NdbTransactionManager.java'
--- a/java/com/mysql/cluster/ndbj/NdbTransactionManager.java	2007-12-20 02:23:51 +0000
+++ b/java/com/mysql/cluster/ndbj/NdbTransactionManager.java	2007-12-20 12:06:40 +0000
@@ -6,8 +6,8 @@
 import javax.transaction.NotSupportedException;
 import javax.transaction.RollbackException;
 import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
 import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
 
 public abstract class NdbTransactionManager implements TransactionManager {
 
@@ -15,9 +15,12 @@
 	
 	public void begin() throws NotSupportedException, SystemException {
 
-		NdbTransaction transaction;
+		NdbTransaction transaction = context.get();
+		if (transaction != null) { 
+			throw new IllegalStateException("Can't begin - already have a transaction");
+		}
 		try {
-		transaction = startTransaction();
+			transaction = startTransaction();
 		} catch (NdbApiException e) { 
 			throw new SystemException(e.message);
 		}
@@ -28,61 +31,61 @@
 	public void commit() throws RollbackException, HeuristicMixedException,
 			HeuristicRollbackException, SecurityException,
 			IllegalStateException, SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("commit");
-
+		NdbTransaction transaction = getTransaction();
+		transaction.commit();
 	}
 
+
 	public int getStatus() throws SystemException {
-		// TODO Auto-generated method stub
-		// return 0;
-		throw new NotImplementedException("getStatus");
 
+		NdbTransaction transaction = getTransaction();
+		return transaction.getStatus();
+		
 	}
 
-	public Transaction getTransaction() throws SystemException {
-		// TODO Auto-generated method stub
-		// return null;
-		throw new NotImplementedException("getTransaction");
-
+	public NdbTransaction getTransaction() throws SystemException {
+		NdbTransaction transaction = context.get();
+		if (transaction==null) { 
+			throw new IllegalStateException("no transaction to commit");
+		}
+		return transaction;
 	}
 
 	public void resume(Transaction arg0) throws InvalidTransactionException,
 			IllegalStateException, SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("resume");
+		NdbTransaction transaction = context.get();
+		if (transaction != null) {
+			throw new IllegalStateException("Can't resume - already have a transaction");
+		} else if (arg0.getClass().isInstance(NdbTransaction.class)) { 
+			context.set((NdbTransaction)arg0);
+		} else { 
+			throw new InvalidTransactionException("Ndb only manages NdbTransactions");
+		}
 
 	}
 
 	public void rollback() throws IllegalStateException, SecurityException,
 			SystemException {
-		// TODO Auto-generated method stub
-		// 
-		throw new NotImplementedException("rollback");
-
+		NdbTransaction transaction = getTransaction();
+		transaction.rollback();
 	}
 
 	public void setRollbackOnly() throws IllegalStateException, SystemException {
 		// TODO Auto-generated method stub
 		// 
 		throw new NotImplementedException("setRollbackOnly");
-
 	}
 
 	public void setTransactionTimeout(int arg0) throws SystemException {
 		// TODO Auto-generated method stub
 		// 
 		throw new NotImplementedException("setTransactionTimeout");
-
 	}
 
-	public Transaction suspend() throws SystemException {
-		// TODO Auto-generated method stub
-		// return null;
-		throw new NotImplementedException("suspend");
-
+	public NdbTransaction suspend() throws SystemException {
+		NdbTransaction transaction = getTransaction();
+		context.remove();
+		return transaction;
 	}
 
 	public abstract NdbTransaction startTransaction() throws NdbApiException;

=== 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 295: Merged. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/telco-6.3Monty Taylor20 Dec