01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.openejb.util;
17:
18: import javax.transaction.Transaction;
19: import javax.transaction.TransactionManager;
20: import javax.transaction.Status;
21: import javax.transaction.SystemException;
22:
23: /**
24: * @version $Revision: 450758 $ $Date: 2006-09-28 01:40:18 -0700 $
25: */
26: public final class TransactionUtils {
27: private TransactionUtils() {
28: }
29:
30: public static Transaction getTransactionIfActive(
31: TransactionManager transactionManager) {
32: Transaction transaction = null;
33: int status = Status.STATUS_NO_TRANSACTION;
34: try {
35: transaction = transactionManager.getTransaction();
36: if (transaction != null)
37: status = transaction.getStatus();
38: } catch (SystemException ignored) {
39: }
40:
41: if (transaction != null && status == Status.STATUS_ACTIVE
42: || status == Status.STATUS_MARKED_ROLLBACK) {
43: return transaction;
44: }
45: return null;
46: }
47:
48: public static boolean isTransactionActive(
49: TransactionManager transactionManager) {
50: try {
51: int status = transactionManager.getStatus();
52: return status == Status.STATUS_ACTIVE
53: || status == Status.STATUS_MARKED_ROLLBACK;
54: } catch (SystemException ignored) {
55: return false;
56: }
57: }
58:
59: public static boolean isActive(Transaction transaction) {
60: try {
61: int status = transaction.getStatus();
62: return status == Status.STATUS_ACTIVE
63: || status == Status.STATUS_MARKED_ROLLBACK;
64: } catch (SystemException ignored) {
65: return false;
66: }
67: }
68: }
|