KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2005 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.Status JavaDoc;
20 import javax.transaction.SystemException JavaDoc;
21 import javax.transaction.UserTransaction JavaDoc;
22
23 import org.springframework.transaction.TransactionSystemException;
24 import org.springframework.transaction.support.SmartTransactionObject;
25
26 /**
27  * JTA transaction object, representing a UserTransaction.
28  * Used as transaction object by JtaTransactionManager.
29  *
30  * <p>Note: This is an SPI class, not intended to be used by applications.
31  *
32  * @author Juergen Hoeller
33  * @since 1.1
34  * @see JtaTransactionManager
35  * @see javax.transaction.UserTransaction
36  */

37 public class JtaTransactionObject implements SmartTransactionObject {
38
39     private final UserTransaction JavaDoc userTransaction;
40
41
42     /**
43      * Create a new JtaTransactionObject for the given JTA UserTransaction.
44      * @param userTransaction the JTA UserTransaction for the current transaction
45      * (either a shared object or retrieved through a fresh per-transaction lookuip)
46      */

47     public JtaTransactionObject(UserTransaction JavaDoc userTransaction) {
48         this.userTransaction = userTransaction;
49     }
50
51     /**
52      * Return the JTA UserTransaction object for the current transaction.
53      */

54     public UserTransaction JavaDoc getUserTransaction() {
55         return userTransaction;
56     }
57
58
59     /**
60      * This implementation checks the UserTransaction's rollback-only flag.
61      */

62     public boolean isRollbackOnly() {
63         try {
64             return (getUserTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK);
65         }
66         catch (SystemException JavaDoc ex) {
67             throw new TransactionSystemException("JTA failure on getStatus", ex);
68         }
69     }
70
71 }
72
Popular Tags