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.deadlock.bean;
023:
024: import java.util.Arrays;
025:
026: import javax.ejb.*;
027:
028: import org.jboss.ejb.plugins.TxInterceptorCMT;
029: import org.jboss.test.deadlock.interfaces.BeanOrder;
030: import org.jboss.test.deadlock.interfaces.EnterpriseEntityLocalHome;
031: import org.jboss.test.deadlock.interfaces.EnterpriseEntityLocal;
032: import org.jboss.test.deadlock.interfaces.EnterpriseEntityHome;
033: import org.jboss.test.deadlock.interfaces.EnterpriseEntity;
034:
035: public abstract class EnterpriseEntityBean implements EntityBean {
036: org.apache.log4j.Category log = org.apache.log4j.Category
037: .getInstance(getClass());
038:
039: private EntityContext entityContext;
040: public int otherField = 0;
041:
042: public String ejbCreate(String name) throws CreateException {
043: setName(name);
044: return null;
045: }
046:
047: public void ejbPostCreate(String name) throws CreateException {
048:
049: EJBLocalObject ejbObject = entityContext.getEJBLocalObject();
050:
051: if (ejbObject == null) {
052: log
053: .debug("******************************* NULL EJBOBJECT in ejbPostCreate");
054: } else {
055: log
056: .debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreate id is "
057: + ejbObject.getPrimaryKey());
058: }
059:
060: }
061:
062: public void ejbActivate() {
063: }
064:
065: public void ejbLoad() {
066: }
067:
068: public void ejbPassivate() {
069:
070: }
071:
072: public void ejbRemove() throws RemoveException {
073: }
074:
075: public void ejbStore() {
076:
077: }
078:
079: public abstract String getName();
080:
081: public abstract void setName(String name);
082:
083: public String callBusinessMethodA() {
084:
085: return "EntityBean.callBusinessMethodA() called, my primaryKey is "
086: + entityContext.getPrimaryKey().toString();
087: }
088:
089: public String callBusinessMethodB() {
090:
091: EJBObject ejbObject = entityContext.getEJBObject();
092:
093: if (ejbObject == null)
094: return "NULL EJBOBJECT";
095:
096: else
097: return ejbObject.toString();
098: }
099:
100: public String callBusinessMethodB(String words) {
101:
102: EJBObject ejbObject = entityContext.getEJBObject();
103:
104: if (ejbObject == null)
105: return "NULL EJBOBJECT";
106:
107: else
108: return ejbObject.toString() + " words " + words;
109:
110: }
111:
112: public abstract void setOtherField(int value);
113:
114: public abstract int getOtherField();
115:
116: public abstract void setNext(EnterpriseEntityLocal next);
117:
118: public abstract EnterpriseEntityLocal getNext();
119:
120: public void callAnotherBean(BeanOrder beanOrder) {
121: // End of the chain
122: if (beanOrder.next == beanOrder.order.length - 1)
123: return;
124:
125: // Call the next in the chain
126: try {
127: EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome) entityContext
128: .getEJBLocalObject().getEJBLocalHome();
129: beanOrder.next++;
130: EnterpriseEntityLocal nextBean = home
131: .findByPrimaryKey(beanOrder.order[beanOrder.next]);
132: try {
133: nextBean.callAnotherBean(beanOrder);
134: } finally {
135: beanOrder.next--;
136: }
137: } catch (Exception e) {
138: Exception a = TxInterceptorCMT.isADE(e);
139: if (a == null) {
140: log.error("Error next=" + beanOrder.next + " order="
141: + Arrays.asList(beanOrder.order), e);
142: throw new EJBException("callAnotherBean failed "
143: + e.toString());
144: } else {
145: throw new EJBException("ADE", a);
146: }
147: }
148: }
149:
150: public EnterpriseEntity createEntity(String newName) {
151:
152: EnterpriseEntity newBean;
153: try {
154: EJBObject ejbObject = entityContext.getEJBObject();
155: if (ejbObject == null)
156: log.debug("************************** NULL EJBOBJECT");
157: else
158: log.debug("************************** OK EJBOBJECT");
159:
160: EnterpriseEntityHome home = (EnterpriseEntityHome) entityContext
161: .getEJBObject().getEJBHome();
162: newBean = (EnterpriseEntity) home.create(newName);
163:
164: } catch (Exception e) {
165: log.debug("failed", e);
166: throw new EJBException(
167: "create entity did not work check messages");
168: }
169:
170: return newBean;
171: }
172:
173: public void setEntityContext(EntityContext context) {
174: entityContext = context;
175: }
176:
177: public void unsetEntityContext() {
178: entityContext = null;
179: }
180: }
|