KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > jta > UserTransactionAdapter


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.transaction.jta;
18
19 import javax.transaction.HeuristicMixedException JavaDoc;
20 import javax.transaction.HeuristicRollbackException JavaDoc;
21 import javax.transaction.NotSupportedException JavaDoc;
22 import javax.transaction.RollbackException JavaDoc;
23 import javax.transaction.SystemException JavaDoc;
24 import javax.transaction.TransactionManager JavaDoc;
25 import javax.transaction.UserTransaction JavaDoc;
26
27 import org.springframework.util.Assert;
28
29 /**
30  * Adapter for a JTA UserTransaction handle, taking a JTA
31  * {@link javax.transaction.TransactionManager} reference and creating
32  * a JTA {@link javax.transaction.UserTransaction} handle for it.
33  *
34  * <p>The JTA UserTransaction interface is an exact subset of the JTA
35  * TransactionManager interface. Unfortunately, it does not serve as
36  * super-interface of TransactionManager, though, which requires an
37  * adapter such as this class to be used when intending to talk to
38  * a TransactionManager handle through the UserTransaction interface.
39  *
40  * <p>Used internally by Spring's {@link JtaTransactionManager} for certain
41  * scenarios. Not intended for direct use in application code.
42  *
43  * @author Juergen Hoeller
44  * @since 1.1.5
45  */

46 public class UserTransactionAdapter implements UserTransaction JavaDoc {
47
48     private final TransactionManager JavaDoc transactionManager;
49
50
51     /**
52      * Create a new UserTransactionAdapter for the given TransactionManager.
53      * @param transactionManager the JTA TransactionManager to wrap
54      */

55     public UserTransactionAdapter(TransactionManager JavaDoc transactionManager) {
56         Assert.notNull(transactionManager, "TransactionManager must not be null");
57         this.transactionManager = transactionManager;
58     }
59
60     /**
61      * Return the JTA TransactionManager that this adapter delegates to.
62      */

63     public final TransactionManager JavaDoc getTransactionManager() {
64         return this.transactionManager;
65     }
66
67
68     public void begin() throws NotSupportedException JavaDoc, SystemException JavaDoc {
69         this.transactionManager.begin();
70     }
71
72     public void commit()
73             throws RollbackException JavaDoc, HeuristicMixedException JavaDoc, HeuristicRollbackException JavaDoc,
74             SecurityException JavaDoc, IllegalStateException JavaDoc, SystemException JavaDoc {
75
76         this.transactionManager.commit();
77     }
78
79     public int getStatus() throws SystemException JavaDoc {
80         return this.transactionManager.getStatus();
81     }
82
83     public void rollback() throws IllegalStateException JavaDoc, SecurityException JavaDoc, SystemException JavaDoc {
84         this.transactionManager.rollback();
85     }
86
87     public void setRollbackOnly() throws IllegalStateException JavaDoc, SystemException JavaDoc {
88         this.transactionManager.setRollbackOnly();
89     }
90
91     public void setTransactionTimeout(int timeout) throws SystemException JavaDoc {
92         this.transactionManager.setTransactionTimeout(timeout);
93     }
94
95 }
96
Popular Tags