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.exception;
023:
024: import java.rmi.RemoteException;
025: import javax.ejb.CreateException;
026: import javax.ejb.EJBException;
027: import javax.ejb.EntityBean;
028: import javax.ejb.EntityContext;
029: import javax.ejb.FinderException;
030:
031: /**
032: * A test of entity beans exceptions.
033: *
034: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
035: * @version $Revision: 57211 $
036: */
037: public class EntityExceptionTesterBean implements EntityBean {
038: private EntityContext ctx;
039:
040: String key;
041:
042: public String ejbCreate(String key) throws CreateException {
043: this .key = key;
044: return key;
045: }
046:
047: public void ejbPostCreate(String key) throws CreateException {
048: }
049:
050: public String ejbFindByPrimaryKey(String key)
051: throws FinderException {
052: throw new FinderException("Error, bean instance was discarded!");
053: }
054:
055: public String getKey() {
056: return key;
057: }
058:
059: public void applicationExceptionInTx() throws ApplicationException {
060: throw new ApplicationException(
061: "Application exception from within "
062: + "an inherited transaction");
063: }
064:
065: public void applicationExceptionInTxMarkRollback()
066: throws ApplicationException {
067: ctx.setRollbackOnly();
068: throw new ApplicationException(
069: "Application exception from within "
070: + "an inherited transaction");
071: }
072:
073: public void applicationErrorInTx() {
074: throw new ApplicationError("Application error from within "
075: + "an inherited transaction");
076: }
077:
078: public void ejbExceptionInTx() {
079: throw new EJBException("EJB exception from within "
080: + "an inherited transaction");
081: }
082:
083: public void runtimeExceptionInTx() {
084: throw new RuntimeException("Runtime exception from within "
085: + "an inherited transaction");
086: }
087:
088: public void remoteExceptionInTx() throws RemoteException {
089: throw new RemoteException("Remote exception from within "
090: + "an inherited transaction");
091: }
092:
093: public void applicationExceptionNewTx() throws ApplicationException {
094: throw new ApplicationException(
095: "Application exception from within "
096: + "a new container transaction");
097: }
098:
099: public void applicationExceptionNewTxMarkRollback()
100: throws ApplicationException {
101: ctx.setRollbackOnly();
102: throw new ApplicationException(
103: "Application exception from within "
104: + "a new container transaction");
105: }
106:
107: public void applicationErrorNewTx() {
108: throw new ApplicationError("Application error from within "
109: + "a new container transaction");
110: }
111:
112: public void ejbExceptionNewTx() {
113: throw new EJBException("EJB exception from within "
114: + "a new container transaction");
115: }
116:
117: public void runtimeExceptionNewTx() {
118: throw new RuntimeException("Runtime exception from within "
119: + "a new container transaction");
120: }
121:
122: public void remoteExceptionNewTx() throws RemoteException {
123: throw new RemoteException("Remote exception from within "
124: + "a new container transaction");
125: }
126:
127: public void applicationExceptionNoTx() throws ApplicationException {
128: throw new ApplicationException("Application exception without "
129: + "a transaction");
130: }
131:
132: public void applicationErrorNoTx() {
133: throw new ApplicationError("Application error from within "
134: + " an inherited transaction");
135: }
136:
137: public void ejbExceptionNoTx() {
138: throw new EJBException("EJB exception without "
139: + "a transaction");
140: }
141:
142: public void runtimeExceptionNoTx() {
143: throw new RuntimeException("Runtime exception without "
144: + "a transaction");
145: }
146:
147: public void remoteExceptionNoTx() throws RemoteException {
148: throw new RemoteException("Remote exception without "
149: + "a transaction");
150: }
151:
152: public void setEntityContext(EntityContext ctx) {
153: this .ctx = ctx;
154: }
155:
156: public void unsetEntityContext() {
157: }
158:
159: public void ejbLoad() {
160: }
161:
162: public void ejbStore() {
163: }
164:
165: public void ejbActivate() {
166: }
167:
168: public void ejbPassivate() {
169: }
170:
171: public void ejbRemove() {
172: }
173: }
|