KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > deadlock > bean > EnterpriseEntityBean


1
2 //Title: telkel
3
//Version:
4
//Copyright: Copyright (c) 1999
5
//Author: Marc Fleury
6
//Company: telkel
7

8 /*
9   * JBoss, Home of Professional Open Source
10   * Copyright 2005, JBoss Inc., and individual contributors as indicated
11   * by the @authors tag. See the copyright.txt in the distribution for a
12   * full listing of individual contributors.
13   *
14   * This is free software; you can redistribute it and/or modify it
15   * under the terms of the GNU Lesser General Public License as
16   * published by the Free Software Foundation; either version 2.1 of
17   * the License, or (at your option) any later version.
18   *
19   * This software is distributed in the hope that it will be useful,
20   * but WITHOUT ANY WARRANTY; without even the implied warranty of
21   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22   * Lesser General Public License for more details.
23   *
24   * You should have received a copy of the GNU Lesser General Public
25   * License along with this software; if not, write to the Free
26   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
28   */

29 package org.jboss.test.deadlock.bean;
30
31 import java.util.Arrays JavaDoc;
32
33 import javax.ejb.*;
34
35 import org.jboss.ejb.plugins.TxInterceptorCMT;
36 import org.jboss.test.deadlock.interfaces.BeanOrder;
37 import org.jboss.test.deadlock.interfaces.EnterpriseEntityLocalHome;
38 import org.jboss.test.deadlock.interfaces.EnterpriseEntityLocal;
39 import org.jboss.test.deadlock.interfaces.EnterpriseEntityHome;
40 import org.jboss.test.deadlock.interfaces.EnterpriseEntity;
41
42 public abstract class EnterpriseEntityBean implements EntityBean
43 {
44    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
45    
46   private EntityContext entityContext;
47   public int otherField = 0;
48
49   public String JavaDoc ejbCreate(String JavaDoc name) throws CreateException {
50       setName(name);
51        return null;
52   }
53
54   public void ejbPostCreate(String JavaDoc name) throws CreateException {
55
56        
57        EJBLocalObject ejbObject = entityContext.getEJBLocalObject();
58        
59        if (ejbObject == null) {
60            log.debug("******************************* NULL EJBOBJECT in ejbPostCreate");
61        }
62        else {
63             log.debug("&&&&&&&&&&&&&&&& EJBObject found in ejbPostCreate id is "+ejbObject.getPrimaryKey());
64        }
65
66   }
67
68   public void ejbActivate() {
69   }
70
71   public void ejbLoad() {
72   }
73
74   public void ejbPassivate() {
75
76   }
77
78   public void ejbRemove() throws RemoveException {
79   }
80
81   public void ejbStore() {
82       
83   }
84
85   public abstract String JavaDoc getName();
86
87   public abstract void setName(String JavaDoc name);
88
89   public String JavaDoc callBusinessMethodA() {
90
91      return "EntityBean.callBusinessMethodA() called, my primaryKey is "+
92             entityContext.getPrimaryKey().toString();
93   }
94   
95   public String JavaDoc callBusinessMethodB() {
96
97      
98      EJBObject ejbObject = entityContext.getEJBObject();
99      
100      if (ejbObject == null)
101         return "NULL EJBOBJECT";
102      
103      else
104         return ejbObject.toString();
105   }
106   
107   
108    public String JavaDoc callBusinessMethodB(String JavaDoc words) {
109     
110      
111      EJBObject ejbObject = entityContext.getEJBObject();
112      
113      if (ejbObject == null)
114         return "NULL EJBOBJECT";
115      
116      else
117         return ejbObject.toString()+ " words "+words;
118   
119     }
120
121   public abstract void setOtherField(int value);
122   
123   public abstract int getOtherField();
124
125   public abstract void setNext(EnterpriseEntityLocal next);
126   
127   public abstract EnterpriseEntityLocal getNext();
128
129   public void callAnotherBean(BeanOrder beanOrder)
130   {
131      // End of the chain
132
if (beanOrder.next == beanOrder.order.length-1)
133         return;
134
135      // Call the next in the chain
136
try
137      {
138         EnterpriseEntityLocalHome home = (EnterpriseEntityLocalHome)entityContext.getEJBLocalObject().getEJBLocalHome();
139         beanOrder.next++;
140         EnterpriseEntityLocal nextBean = home.findByPrimaryKey(beanOrder.order[beanOrder.next]);
141         try
142         {
143            nextBean.callAnotherBean(beanOrder);
144         }
145         finally
146         {
147            beanOrder.next--;
148         }
149      }
150      catch (Exception JavaDoc e)
151      {
152         Exception JavaDoc a = TxInterceptorCMT.isADE(e);
153         if (a == null)
154         {
155            log.error("Error next=" + beanOrder.next + " order=" + Arrays.asList(beanOrder.order), e);
156            throw new EJBException("callAnotherBean failed " + e.toString());
157         }
158         else
159         {
160            throw new EJBException ("ADE", a);
161         }
162      }
163   }
164   
165   public EnterpriseEntity createEntity(String JavaDoc newName) {
166
167     EnterpriseEntity newBean;
168     try{
169         EJBObject ejbObject = entityContext.getEJBObject();
170         if (ejbObject == null)
171         log.debug("************************** NULL EJBOBJECT");
172         else
173         log.debug("************************** OK EJBOBJECT");
174         
175         EnterpriseEntityHome home = (EnterpriseEntityHome)entityContext.getEJBObject().getEJBHome();
176         newBean = (EnterpriseEntity)home.create(newName);
177
178     
179     }catch(Exception JavaDoc e)
180     {
181         log.debug("failed", e);
182         throw new EJBException("create entity did not work check messages");
183     }
184      
185      return newBean;
186   }
187   
188   public void setEntityContext(EntityContext context) {
189      entityContext = context;
190   }
191
192   public void unsetEntityContext() {
193     entityContext = null;
194   }
195 }
196
Popular Tags