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: import javax.transaction.InvalidTransactionException;
022:
023: /**
024: * 17.6.2.1 NotSupported
025: *
026: * The Container invokes an enterprise Bean method whose transaction attribute
027: * is set to NotSupported with an unspecified transaction context.
028: *
029: * If a client calls with a transaction context, the container suspends the
030: * association of the transaction context with the current thread before
031: * invoking the enterprise bean's business method. The container resumes the
032: * suspended association when the business method has completed. The suspended
033: * transaction context of the client is not passed to the resource managers or
034: * other enterprise Bean objects that are invoked from the business method.
035: *
036: * If the business method invokes other enterprise beans, the Container passes
037: * no transaction context with the invocation.
038: *
039: * Refer to Subsection 17.6.5 for more details of how the Container can
040: * implement this case.
041: *
042: */
043: public class TxNotSupported extends TransactionPolicy {
044:
045: public TxNotSupported(TransactionContainer container) {
046: super (Type.NotSupported, container);
047: }
048:
049: public void beforeInvoke(Object instance, TransactionContext context)
050: throws SystemException, ApplicationException {
051:
052: try {
053:
054: context.clientTx = context.getTransactionManager()
055: .suspend();
056: } catch (javax.transaction.SystemException se) {
057: throw new SystemException(se);
058: }
059: context.currentTx = null;
060:
061: }
062:
063: public void afterInvoke(Object instance, TransactionContext context)
064: throws ApplicationException, SystemException {
065:
066: if (context.clientTx != null) {
067: try {
068: context.getTransactionManager()
069: .resume(context.clientTx);
070: } catch (InvalidTransactionException ite) {
071:
072: logger
073: .error("Could not resume the client's transaction, the transaction is no longer valid: "
074: + ite.getMessage());
075: } catch (IllegalStateException e) {
076:
077: logger
078: .error("Could not resume the client's transaction: "
079: + e.getMessage());
080: } catch (javax.transaction.SystemException e) {
081:
082: logger
083: .error("Could not resume the client's transaction: The transaction reported a system exception: "
084: + e.getMessage());
085: }
086: }
087: }
088:
089: public void handleApplicationException(Throwable appException,
090: boolean rollback, TransactionContext context)
091: throws ApplicationException, SystemException {
092: if (rollback && context.currentTx != null)
093: markTxRollbackOnly(context.currentTx);
094:
095: throw new ApplicationException(appException);
096: }
097:
098: public void handleSystemException(Throwable sysException,
099: Object instance, TransactionContext context)
100: throws ApplicationException, SystemException {
101: /* [1] Log the system exception or error *********/
102: logSystemException(sysException, context);
103:
104: /* [2] Discard instance. *************************/
105: discardBeanInstance(instance, context.callContext);
106:
107: /* [3] Throw RemoteException to client ***********/
108: throwExceptionToServer(sysException);
109: }
110:
111: }
|