1 /*** 2 * 3 * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 **/ 18 package org.apache.geronimo.transaction.context; 19 20 import javax.transaction.HeuristicMixedException; 21 import javax.transaction.HeuristicRollbackException; 22 import javax.transaction.RollbackException; 23 import javax.transaction.Synchronization; 24 import javax.transaction.SystemException; 25 import javax.transaction.Transaction; 26 import javax.transaction.xa.XAResource; 27 28 /*** 29 * The GeronimoTransactionDelegate wraps a GeronimoTransactionContext 30 * so that it can be used as a Transaction. 31 * 32 * @version $Revision: 1.1 $ 33 * @author <a href="mailto:gnt@codehaus.org">Guillaume Nodet</a> 34 */ 35 class GeronimoTransactionDelegate implements Transaction { 36 37 private GeronimoTransactionContext context; 38 39 GeronimoTransactionDelegate(GeronimoTransactionContext context) { 40 this.context = context; 41 } 42 43 public GeronimoTransactionContext getContext() { 44 return context; 45 } 46 47 public void commit() throws HeuristicMixedException, HeuristicRollbackException, RollbackException, SecurityException, SystemException { 48 if (context.txnManager.transactionContextManager.getContext() != context) { 49 throw new IllegalStateException("Cannot commit if the transaction is not bound to the current thread"); 50 } 51 context.txnManager.commit(); 52 } 53 54 public boolean delistResource(XAResource xaResource, int flag) throws IllegalStateException, SystemException { 55 return context.delistResource(xaResource, flag); 56 } 57 58 public boolean enlistResource(XAResource xaResource) throws IllegalStateException, RollbackException, SystemException { 59 return context.enlistResource(xaResource); 60 } 61 62 public int getStatus() throws SystemException { 63 return context.getTransaction().getStatus(); 64 } 65 66 public void registerSynchronization(Synchronization synchronization) throws IllegalStateException, RollbackException, SystemException { 67 context.registerSynchronization(synchronization); 68 } 69 70 public void rollback() throws IllegalStateException, SystemException { 71 if (context.txnManager.transactionContextManager.getContext() != context) { 72 throw new IllegalStateException("Cannot commit if the transaction is not bound to the current thread"); 73 } 74 context.txnManager.rollback(); 75 } 76 77 public void setRollbackOnly() throws IllegalStateException, SystemException { 78 context.setRollbackOnly(); 79 } 80 }