X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=test%2Fenterprise%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Ftest%2Ftransactions%2FAutoCreateUserTransaction.java;fp=test%2Fenterprise%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Ftest%2Ftransactions%2FAutoCreateUserTransaction.java;h=7b5124be3dac1c5026850e8b392dd5653c15fc8d;hb=ee7fa42171c628c71bf072131b4b67b79316129c;hp=0000000000000000000000000000000000000000;hpb=8dd32e931b348cf53d3e8567c7a092735ea46253;p=utils diff --git a/test/enterprise/src/main/java/org/wamblee/test/transactions/AutoCreateUserTransaction.java b/test/enterprise/src/main/java/org/wamblee/test/transactions/AutoCreateUserTransaction.java new file mode 100644 index 00000000..7b5124be --- /dev/null +++ b/test/enterprise/src/main/java/org/wamblee/test/transactions/AutoCreateUserTransaction.java @@ -0,0 +1,76 @@ +/* + * Copyright 2005-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.test.transactions; + +import javax.transaction.HeuristicMixedException; +import javax.transaction.HeuristicRollbackException; +import javax.transaction.NotSupportedException; +import javax.transaction.RollbackException; +import javax.transaction.SystemException; +import javax.transaction.UserTransaction; + +/** + * User transaction implemenetation that automatically creates thread specific transaction if needed. + * + * @author Erik Brakkee + * + */ +public class AutoCreateUserTransaction implements UserTransaction { + + private SimpleTransactionManager manager; + + public AutoCreateUserTransaction(SimpleTransactionManager aManager) { + manager = aManager; + } + + private UserTransaction getTransaction() { + return manager.getOrCreateThreadSpecificTransaction(); + } + + @Override + public void begin() throws NotSupportedException, SystemException { + getTransaction().begin(); + } + + @Override + public void commit() throws RollbackException, HeuristicMixedException, + HeuristicRollbackException, SecurityException, IllegalStateException, + SystemException { + getTransaction().commit(); + } + + @Override + public int getStatus() throws SystemException { + return getTransaction().getStatus(); + } + + @Override + public void rollback() throws IllegalStateException, SecurityException, + SystemException { + getTransaction().rollback(); + } + + @Override + public void setRollbackOnly() throws IllegalStateException, SystemException { + getTransaction().setRollbackOnly(); + } + + @Override + public void setTransactionTimeout(int aSeconds) throws SystemException { + getTransaction().setTransactionTimeout(aSeconds); + } + +}