From: Monty Taylor Date: December 20 2007 2:46am Subject: Rev 384: Implemented TransactionManager methods. Even though we shouldn't share Ndb objects between threads, I stuck the NdbTransaction in a ThreadLocal just to be sure. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel List-Archive: http://lists.mysql.com/ndb-connectors/562 Message-Id: At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel ------------------------------------------------------------ revno: 384 revision-id:mtaylor@stripped parent: mtaylor@stripped committer: Monty Taylor 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/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 02:45:12 +0000 @@ -6,7 +6,6 @@ import javax.transaction.NotSupportedException; import javax.transaction.RollbackException; import javax.transaction.SystemException; -import javax.transaction.Transaction; import javax.transaction.TransactionManager; public abstract class NdbTransactionManager implements TransactionManager { @@ -15,9 +14,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 +30,59 @@ 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"); - - } - - public Transaction getTransaction() throws SystemException { - // TODO Auto-generated method stub - // return null; - throw new NotImplementedException("getTransaction"); - - } - - public void resume(Transaction arg0) throws InvalidTransactionException, + + NdbTransaction transaction = getTransaction(); + return transaction.getStatus(); + + } + + public NdbTransaction getTransaction() throws SystemException { + NdbTransaction transaction = context.get(); + if (transaction==null) { + throw new IllegalStateException("no transaction to commit"); + } + return transaction; + } + + public void resume(NdbTransaction arg0) throws InvalidTransactionException, IllegalStateException, SystemException { - // TODO Auto-generated method stub - // + NdbTransaction transaction = context.get(); + if (transaction != null) { + throw new IllegalStateException("Can't resume - already have a transaction"); + } + context.set(arg0); throw new NotImplementedException("resume"); } 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;