01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.core.stateful;
18:
19: import javax.transaction.UserTransaction;
20: import javax.transaction.NotSupportedException;
21: import javax.transaction.SystemException;
22: import javax.transaction.HeuristicMixedException;
23: import javax.transaction.HeuristicRollbackException;
24: import javax.transaction.RollbackException;
25:
26: import org.apache.openejb.persistence.JtaEntityManagerRegistry;
27: import org.apache.openejb.core.ThreadContext;
28: import org.apache.openejb.core.CoreDeploymentInfo;
29: import org.apache.openejb.BeanType;
30:
31: public class StatefulUserTransaction implements UserTransaction {
32: private final UserTransaction userTransaction;
33: private final JtaEntityManagerRegistry jtaEntityManagerRegistry;
34:
35: public StatefulUserTransaction(UserTransaction userTransaction,
36: JtaEntityManagerRegistry jtaEntityManagerRegistry) {
37: this .userTransaction = userTransaction;
38: this .jtaEntityManagerRegistry = jtaEntityManagerRegistry;
39: }
40:
41: public void begin() throws NotSupportedException, SystemException {
42: userTransaction.begin();
43:
44: // get the callContext
45: ThreadContext callContext = ThreadContext.getThreadContext();
46: if (callContext == null) {
47: // someone is using the user transaction out side of the component
48: return;
49: }
50:
51: // get the deployment info
52: CoreDeploymentInfo deploymentInfo = callContext
53: .getDeploymentInfo();
54: if (deploymentInfo.getComponentType() != BeanType.STATEFUL) {
55: // some other non-stateful ejb is using our user transaction
56: return;
57: }
58:
59: // get the primary key
60: Object primaryKey = callContext.getPrimaryKey();
61: if (primaryKey == null) {
62: // is is not a bean method
63: return;
64: }
65: jtaEntityManagerRegistry.transactionStarted(
66: (String) deploymentInfo.getDeploymentID(), primaryKey);
67: }
68:
69: public void commit() throws HeuristicMixedException,
70: HeuristicRollbackException, IllegalStateException,
71: RollbackException, SecurityException, SystemException {
72: userTransaction.commit();
73: }
74:
75: public int getStatus() throws SystemException {
76: return userTransaction.getStatus();
77: }
78:
79: public void rollback() throws IllegalStateException,
80: SecurityException, SystemException {
81: userTransaction.rollback();
82: }
83:
84: public void setRollbackOnly() throws IllegalStateException,
85: SystemException {
86: userTransaction.setRollbackOnly();
87: }
88:
89: public void setTransactionTimeout(int i) throws SystemException {
90: userTransaction.setTransactionTimeout(i);
91: }
92: }
|