001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jca.ejb;
023:
024: import javax.ejb.EJBException;
025: import javax.ejb.SessionBean;
026: import javax.ejb.SessionContext;
027: import javax.ejb.TransactionRolledbackLocalException;
028: import javax.naming.InitialContext;
029: import javax.transaction.TransactionRolledbackException;
030:
031: import org.jboss.logging.Logger;
032: import org.jboss.test.jca.interfaces.XAExceptionSession;
033: import org.jboss.test.jca.interfaces.XAExceptionSessionHome;
034: import org.jboss.test.jca.interfaces.XAExceptionSessionLocal;
035: import org.jboss.test.jca.interfaces.XAExceptionSessionLocalHome;
036:
037: /**
038: * XAExceptionTestSessionBean.java
039: *
040: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
041: * @version <tt>$Revision: 57211 $</tt>
042: *
043: * @ejb:bean name="XAExceptionTestSession"
044: * jndi-name="test/XAExceptionTestSessionHome"
045: * view-type="remote"
046: * type="Stateless"
047: * @ejb.transaction type="Never"
048: */
049: public class XAExceptionTestSessionBean implements SessionBean {
050:
051: /** The serialVersionUID */
052: private static final long serialVersionUID = 1L;
053:
054: private Logger log = Logger.getLogger(getClass());
055:
056: /**
057: * Describe <code>ejbCreate</code> method here.
058: * @ejb.interface-method
059: */
060: public void ejbCreate() {
061: }
062:
063: /**
064: * Describe <code>testXAException</code> method here.
065: * @ejb.interface-method
066: */
067: public void testXAExceptionToTransactionRolledbackException() {
068: try {
069: XAExceptionSessionHome xh = (XAExceptionSessionHome) new InitialContext()
070: .lookup("test/XAExceptionSessionHome");
071: XAExceptionSession x = xh.create();
072: try {
073: x.testXAExceptionToTransactionRolledbackException();
074: } catch (TransactionRolledbackException tre) {
075: log.info("Test worked");
076: return;
077: }
078: } catch (Exception e) {
079: log.info("unexpected exception", e);
080: throw new EJBException("Unexpected exception: " + e);
081: }
082: throw new EJBException("No exception");
083: }
084:
085: /**
086: * Describe <code>testXAException</code> method here.
087: * @ejb.interface-method
088: */
089: public void testXAExceptionToTransactionRolledbackLocalException() {
090: try {
091: XAExceptionSessionLocalHome xh = (XAExceptionSessionLocalHome) new InitialContext()
092: .lookup("test/XAExceptionSessionLocalHome");
093: XAExceptionSessionLocal x = xh.create();
094: try {
095: x.testXAExceptionToTransactionRolledbackException();
096: } catch (TransactionRolledbackLocalException tre) {
097: log.info("Test worked");
098: return;
099: }
100: } catch (Exception e) {
101: log.info("unexpected exception", e);
102: throw new EJBException("Unexpected exception: " + e);
103: }
104: throw new EJBException("No exception");
105: }
106:
107: /**
108: * Describe <code>testXAException</code> method here.
109: * @ejb.interface-method
110: */
111: public void testRMERRInOnePCToTransactionRolledbackException() {
112: try {
113: XAExceptionSessionHome xh = (XAExceptionSessionHome) new InitialContext()
114: .lookup("test/XAExceptionSessionHome");
115: XAExceptionSession x = xh.create();
116: try {
117: x.testRMERRInOnePCToTransactionRolledbackException();
118: } catch (TransactionRolledbackException tre) {
119: log.info("Test worked");
120: return;
121: }
122: } catch (Exception e) {
123: log.info("unexpected exception", e);
124: throw new EJBException("Unexpected exception: " + e);
125: }
126: throw new EJBException("No exception");
127: }
128:
129: /**
130: * Describe <code>testXAException</code> method here.
131: * @ejb.interface-method
132: */
133: public void testXAExceptionToTransactionRolledbacLocalkException() {
134: try {
135: XAExceptionSessionLocalHome xh = (XAExceptionSessionLocalHome) new InitialContext()
136: .lookup("test/XAExceptionSessionLocalHome");
137: XAExceptionSessionLocal x = xh.create();
138: try {
139: x.testRMERRInOnePCToTransactionRolledbackException();
140: } catch (TransactionRolledbackLocalException tre) {
141: log.info("Test worked");
142: return;
143: }
144: } catch (Exception e) {
145: log.info("unexpected exception", e);
146: throw new EJBException("Unexpected exception: " + e);
147: }
148: throw new EJBException("No exception");
149: }
150:
151: public void ejbActivate() {
152: }
153:
154: public void ejbPassivate() {
155: }
156:
157: public void ejbRemove() {
158: }
159:
160: public void setSessionContext(SessionContext ctx) {
161: }
162:
163: public void unsetSessionContext() {
164: }
165:
166: }
|