01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
20: import javax.transaction.SystemException;
21: import javax.transaction.UserTransaction;
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 userTransaction;
40:
41: /**
42: * Create a new JtaTransactionObject for the given JTA UserTransaction.
43: * @param userTransaction the JTA UserTransaction for the current transaction
44: * (either a shared object or retrieved through a fresh per-transaction lookuip)
45: */
46: public JtaTransactionObject(UserTransaction userTransaction) {
47: this .userTransaction = userTransaction;
48: }
49:
50: /**
51: * Return the JTA UserTransaction object for the current transaction.
52: */
53: public UserTransaction getUserTransaction() {
54: return userTransaction;
55: }
56:
57: /**
58: * This implementation checks the UserTransaction's rollback-only flag.
59: */
60: public boolean isRollbackOnly() {
61: try {
62: return (getUserTransaction().getStatus() == Status.STATUS_MARKED_ROLLBACK);
63: } catch (SystemException ex) {
64: throw new TransactionSystemException(
65: "JTA failure on getStatus", ex);
66: }
67: }
68:
69: }
|