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.core.transaction;
17:
18: import org.apache.openejb.ApplicationException;
19: import org.apache.openejb.SystemException;
20:
21: import java.rmi.RemoteException;
22:
23: /**
24: * 17.6.2.6 Never
25: *
26: * The Container invokes an enterprise Bean method whose transaction attribute
27: * is set to Never without a transaction context defined by the EJB spec.
28: *
29: * The client is required to call without a transaction context.
30: *
31: * ¥ If the client calls with a transaction context, the Container throws the
32: * java.rmi.RemoteException exception if the client is a remote client, or
33: * the javax.ejb.EJBException if the client is a local client.
34: * ¥ If the client calls without a transaction context, the Container performs
35: * the same steps as described in the NotSupported case.
36: *
37: */
38: public class TxNever extends TransactionPolicy {
39:
40: public TxNever(TransactionContainer container) {
41: super (Type.Never, container);
42: }
43:
44: public void beforeInvoke(Object instance, TransactionContext context)
45: throws SystemException, ApplicationException {
46:
47: try {
48:
49: if (context.getTransactionManager().getTransaction() != null) {
50:
51: throw new ApplicationException(new RemoteException(
52: "Transactions not supported"));
53: }
54:
55: } catch (javax.transaction.SystemException se) {
56: logger.error("Exception during getTransaction()", se);
57: throw new SystemException(se);
58: }
59: }
60:
61: public void afterInvoke(Object instance, TransactionContext context)
62: throws ApplicationException, SystemException {
63: }
64:
65: public void handleApplicationException(Throwable appException,
66: boolean rollback, TransactionContext context)
67: throws ApplicationException, SystemException {
68: if (rollback && context.currentTx != null)
69: markTxRollbackOnly(context.currentTx);
70:
71: throw new ApplicationException(appException);
72: }
73:
74: public void handleSystemException(Throwable sysException,
75: Object instance, TransactionContext context)
76: throws ApplicationException, SystemException {
77: /* [1] Log the system exception or error *********/
78: logSystemException(sysException, context);
79:
80: /* [2] Discard instance. *************************/
81: discardBeanInstance(instance, context.callContext);
82:
83: /* [3] Throw RemoteException to client ***********/
84: throwExceptionToServer(sysException);
85: }
86:
87: }
|