001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.core.transaction;
017:
018: import org.apache.openejb.ApplicationException;
019: import org.apache.openejb.SystemException;
020:
021: /**
022: * 17.6.2.3 Supports
023: *
024: * The Container invokes an enterprise Bean method whose transaction attribute
025: * is set to Supports as follows.
026: *
027: * ¥ If the client calls with a transaction context, the Container performs
028: * the same steps as described in the Required case.
029: *
030: * ¥ If the client calls without a transaction context, the Container performs
031: * the same steps as described in the NotSupported case.
032: *
033: * The Supports transaction attribute must be used with caution. This is
034: * because of the different transactional semantics provided by the two
035: * possible modes of execution. Only the enterprise beans that will
036: * execute correctly in both modes should use the Supports transaction
037: * attribute.
038: *
039: */
040: public class TxSupports extends TransactionPolicy {
041:
042: public TxSupports(TransactionContainer container) {
043: super (Type.Supports, container);
044: }
045:
046: public void beforeInvoke(Object instance, TransactionContext context)
047: throws SystemException, ApplicationException {
048:
049: try {
050:
051: context.clientTx = context.getTransactionManager()
052: .getTransaction();
053: context.currentTx = context.clientTx;
054:
055: } catch (javax.transaction.SystemException se) {
056: throw new SystemException(se);
057: }
058: }
059:
060: public void afterInvoke(Object instance, TransactionContext context)
061: throws ApplicationException, SystemException {
062:
063: }
064:
065: public void handleApplicationException(Throwable appException,
066: boolean rollback, TransactionContext context)
067: throws ApplicationException, SystemException {
068: if (rollback && context.currentTx != null)
069: markTxRollbackOnly(context.currentTx);
070:
071: throw new ApplicationException(appException);
072: }
073:
074: public void handleSystemException(Throwable sysException,
075: Object instance, TransactionContext context)
076: throws ApplicationException, SystemException {
077:
078: boolean runningInTransaction = (context.currentTx != null);
079:
080: if (runningInTransaction) {
081: /* [1] Log the system exception or error *********/
082: logSystemException(sysException, context);
083:
084: /* [2] Mark the transaction for rollback. ********/
085: markTxRollbackOnly(context.currentTx);
086:
087: /* [3] Discard instance. *************************/
088: discardBeanInstance(instance, context.callContext);
089:
090: /* [4] TransactionRolledbackException to client **/
091: throwTxExceptionToServer(sysException);
092:
093: } else {
094: /* [1] Log the system exception or error *********/
095: logSystemException(sysException, context);
096:
097: /* [2] Discard instance. *************************/
098: discardBeanInstance(instance, context.callContext);
099:
100: /* [3] Throw RemoteException to client ***********/
101: throwExceptionToServer(sysException);
102: }
103:
104: }
105:
106: }
|