KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > deployment > api > EntityDesc


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: EntityDesc.java,v 1.34 2004/12/01 10:33:25 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas_ejb.deployment.api;
28
29 import java.util.Iterator JavaDoc;
30
31 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
32 import org.objectweb.jonas_ejb.deployment.xml.Entity;
33 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
34 import org.objectweb.jonas_ejb.lib.BeanNaming;
35 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
36 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
37 import org.objectweb.util.monolog.api.BasicLevel;
38
39
40 /**
41  * Base class to hold meta-information related to an entity bean.
42  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
43  * @author Helene Joanin
44  * @author Helene Joanin: take into account ejbSelect() methods.
45  * @author Helene Joanin: unsetting transaction attribute set to a default value.
46  */

47 public abstract class EntityDesc extends BeanDesc {
48
49
50     /**
51      * remote methods for which no transaction attribute is to be set
52      */

53     protected static final String JavaDoc METHODS_REMOTE_NO_TX = ",getEJBHome,getHandle,getPrimaryKey,isIdentical,";
54
55     /**
56      * home methods for which no transaction attribute is to be set
57      */

58     protected static final String JavaDoc METHODS_HOME_NO_TX = ",getEJBMetaData,getHomeHandle,";
59
60     /**
61      * This field contains the class name of the factory instanciate by the
62      * container.
63      */

64     protected Class JavaDoc primaryKeyClass;
65     protected boolean reentrant;
66     protected int passivationTimeout = 0;
67     protected int inactivityTimeout = 0;
68     protected boolean shared = false;
69     protected boolean prefetch = false;
70
71     // Field used for pk auto-generate
72
protected boolean jdbcAutomaticPk = false; // first implementation with specific tag into JOnAS Descriptor file
73
protected boolean pkObjectType = false; // second implementation with prim-key-type=java.lang.Object (cf spec ?14.1.9.3)
74

75     // mapping cleanup policy
76
public static final int CLEANUP_NONE = 0;
77     public static final int CLEANUP_CREATE = 1;
78     public static final int CLEANUP_REMOVEDATA = 2;
79     public static final int CLEANUP_REMOVEALL = 3;
80     protected int cleanup = CLEANUP_CREATE;
81
82     // lock policy
83
public static final int LOCK_CONTAINER_READ_UNCOMMITTED = 0;
84     public static final int LOCK_CONTAINER_SERIALIZED = 1;
85     public static final int LOCK_CONTAINER_READ_COMMITTED = 2;
86     public static final int LOCK_DATABASE = 3;
87     public static final int LOCK_READ_ONLY = 4;
88     protected int lockPolicy = LOCK_CONTAINER_SERIALIZED;
89
90     /**
91      * constructor to be used by parent node
92      */

93     public EntityDesc(ClassLoader JavaDoc classLoader,
94                        Entity ent,
95                        AssemblyDescriptor asd,
96                        JonasEntity jEnt,
97                        JLinkedList jMDRList,
98                        String JavaDoc fileName)
99         throws DeploymentDescException {
100
101         super(classLoader, ent, jEnt, asd, jMDRList, fileName);
102
103         // primary Key class
104
try {
105             // Test for automatic PK
106
if (ent.getPrimKeyClass().equalsIgnoreCase("Object") || ent.getPrimKeyClass().equalsIgnoreCase("java.lang.Object")) {
107                 primaryKeyClass = classLoader.loadClass("java.lang.Integer");
108                 pkObjectType = true;
109             }
110             else
111                 primaryKeyClass = classLoader.loadClass(ent.getPrimKeyClass());
112         } catch (ClassNotFoundException JavaDoc e) {
113             throw new DeploymentDescException("Primary Key class not found for bean " + this.ejbName, e);
114         }
115
116         // passivation timeout
117
if (jEnt.getPassivationTimeout() != null) {
118             String JavaDoc tstr = jEnt.getPassivationTimeout();
119             Integer JavaDoc tval = new Integer JavaDoc(tstr);
120             passivationTimeout = tval.intValue();
121         }
122
123         // inactivity timeout
124
if (jEnt.getInactivityTimeout() != null) {
125             String JavaDoc tstr = jEnt.getInactivityTimeout();
126             Integer JavaDoc tval = new Integer JavaDoc(tstr);
127             inactivityTimeout = tval.intValue();
128         }
129
130         // reentrant
131
if (ent.getReentrant().equalsIgnoreCase("True")) {
132             reentrant = true;
133         } else if (ent.getReentrant().equalsIgnoreCase("False")) {
134             reentrant = false;
135         } else {
136             throw new DeploymentDescException("Invalid reentrant value for bean " + this.ejbName);
137         }
138
139         // prefetch
140
if (jEnt.getPrefetch() != null) {
141             if (jEnt.getPrefetch().equalsIgnoreCase("True")) {
142                 prefetch = true;
143             } else if (jEnt.getPrefetch().equalsIgnoreCase("False")) {
144                 prefetch = false;
145             } else {
146                 throw new DeploymentDescException("Invalid prefetch value for bean " + this.ejbName);
147             }
148         }
149
150         // min-pool-size
151
if (jEnt.getMinPoolSize() != null) {
152             String JavaDoc tstr = jEnt.getMinPoolSize();
153             Integer JavaDoc tval = new Integer JavaDoc(tstr);
154             poolMin = tval.intValue();
155         }
156
157         // max-cache-size
158
if (jEnt.getMaxCacheSize() != null) {
159             String JavaDoc tstr = jEnt.getMaxCacheSize();
160             Integer JavaDoc tval = new Integer JavaDoc(tstr);
161             cacheMax = tval.intValue();
162         }
163
164         // lock policy. Possible values are :
165
// container-serialized =
166
// container-read-committed =
167
// database =
168
if (jEnt.getLockPolicy() != null) {
169             String JavaDoc tstr = jEnt.getLockPolicy();
170             if (tstr.equals("container-serialized")) {
171                 lockPolicy = LOCK_CONTAINER_SERIALIZED;
172                 shared = false;
173             } else if (tstr.equals("container-read-committed")) {
174                 lockPolicy = LOCK_CONTAINER_READ_COMMITTED;
175                 shared = true;
176             } else if (tstr.equals("container-read-uncommitted")) {
177                 lockPolicy = LOCK_CONTAINER_READ_UNCOMMITTED;
178                 shared = true;
179             } else if (tstr.equals("database")) {
180                 lockPolicy = LOCK_DATABASE;
181                 shared = true;
182             } else if (tstr.equals("read-only")) {
183                 lockPolicy = LOCK_READ_ONLY;
184             } else {
185                 throw new DeploymentDescException("Invalid lock-policy value for bean " + jEnt.getEjbName());
186             }
187         }
188
189         // shared
190
if (jEnt.getShared() != null) {
191             if (jEnt.getShared().equalsIgnoreCase("True")) {
192                 shared = true;
193             } else if (jEnt.getShared().equalsIgnoreCase("False")) {
194                 shared = false;
195             } else {
196                 throw new DeploymentDescException("Invalid shared value for bean " + this.ejbName);
197             }
198         }
199
200         // cleanup policy. Possible values are :
201
// create = create table only if does not exist yet. (default)
202
// none = nothing is done (not implemented)
203
// removeall = drop table and recreate it.
204
// removedata = remove all data if exist, create table if does not exist.
205
if (jEnt.getCleanup() != null) {
206             String JavaDoc tstr = jEnt.getCleanup();
207             if (tstr.equals("create")) {
208                 cleanup = CLEANUP_CREATE;
209             } else if (tstr.equals("none")) {
210                 cleanup = CLEANUP_NONE;
211             } else if (tstr.equals("removeall")) {
212                 cleanup = CLEANUP_REMOVEALL;
213             } else if (tstr.equals("removedata")) {
214                 cleanup = CLEANUP_REMOVEDATA;
215             } else {
216                 throw new DeploymentDescException("Invalid cleanup value for bean " + jEnt.getEjbName());
217             }
218         }
219
220         // cache TxAttribute for ejbTimeout
221
for (Iterator JavaDoc i = getMethodDescIterator(); i.hasNext();) {
222             MethodDesc methd = (MethodDesc) i.next();
223             if (methd.getMethod().getName().equals("ejbTimeout")) {
224                 timerTxAttribute = methd.getTxAttribute();
225                 ejbTimeoutSignature = BeanNaming.getSignature(getEjbName(), methd.getMethod());
226             }
227         }
228     }
229
230     /**
231      * @return the cleanup policy for this bean
232      */

233     public int getCleanupPolicy() {
234         return cleanup;
235     }
236
237     /**
238      * @return the lock policy for this bean
239      */

240     public int getLockPolicy() {
241         return lockPolicy;
242     }
243
244     /**
245      * check that trans-attribute is valid for bean
246      */

247     protected void checkTxAttribute(MethodDesc md) throws DeploymentDescException {
248         java.lang.reflect.Method JavaDoc m = md.getMethod();
249         if (md.getTxAttribute() == MethodDesc.TX_NOT_SET) {
250             // exclude method list for home interface
251
if (javax.ejb.EJBHome JavaDoc.class.isAssignableFrom(m.getDeclaringClass())
252                 && (METHODS_HOME_NO_TX.indexOf("," + m.getName() + ",") != -1)) {
253                 return;
254             }
255             // exclude method list for remote interface
256
if (javax.ejb.EJBObject JavaDoc.class.isAssignableFrom(m.getDeclaringClass())
257                 && (METHODS_REMOTE_NO_TX.indexOf("," + m.getName() + ",") != -1)) {
258                 return;
259             }
260             // exclude ejbSelect methods
261
if (md.isEjbSelect()) {
262                 return;
263             }
264             // trans-attribute not set !
265
// trace a warning and set the tx-attribute with the default value
266
logger.log(BasicLevel.WARN,
267                        "trans-attribute missing for method "
268                        + m.toString() + " in entity bean "
269                        + getEjbName()
270                        + " (set to the default value "
271                        + MethodDesc.TX_STR_DEFAULT_VALUE
272                        + ")");
273             md.setTxAttribute(MethodDesc.TX_STR_DEFAULT_VALUE);
274         }
275     }
276
277     /**
278      * Get the passivation timeout value
279      */

280     public int getPassivationTimeout() {
281         return passivationTimeout;
282     }
283
284     /**
285      * Get the inactivity timeout value
286      */

287     public int getInactivityTimeout() {
288         return inactivityTimeout;
289     }
290
291     /**
292      * Get the entity's primary key class.
293      * @return Class for the primary key
294      */

295     public Class JavaDoc getPrimaryKeyClass() {
296         return primaryKeyClass;
297     }
298
299     /**
300      * Assessor for reentrant entity bean
301      * @return true for reentrant entity bean
302      */

303     public boolean isReentrant() {
304         return reentrant;
305     }
306
307     /**
308      * @return true for shared entity bean
309      */

310     public boolean isShared() {
311         return shared;
312     }
313
314     /**
315      * @return true for prefetch entity bean
316      */

317     public boolean isPrefetch() {
318         return prefetch;
319     }
320
321     /**
322      * Assessor for existence of automatic-pk element to True value
323      * @param field public field of the bean class
324      * @return true if automatic-pk element value is true else otherwise false
325      */

326     public boolean isAutomaticPk() {
327         return jdbcAutomaticPk;
328     }
329
330     /**
331      * Assessor for primary key undefined (declare like java.lang.Object type)
332      * @param field public field of the bean class
333      * @return true if primary key is undefined (java.lang.Object type)
334      */

335     public boolean isUndefinedPK() {
336         return pkObjectType;
337     }
338
339     /**
340      * String representation of the object for test purpose
341      * @return String representation of this object
342      */

343     public String JavaDoc toString() {
344         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
345         ret.append(super.toString());
346         ret.append("\ngetPrimaryKeyClass() =" + getPrimaryKeyClass().toString());
347         ret.append("\nisReentrant() =" + isReentrant());
348         ret.append("\ngetPassivationTimeout() =" + getPassivationTimeout());
349         ret.append("\ngetInactivityTimeout() =" + getInactivityTimeout());
350         ret.append("\nisShared() =" + isShared());
351         ret.append("\ngetPoolMin() =" + getPoolMin());
352         ret.append("\ngetCacheMax() =" + getCacheMax());
353         return ret.toString();
354     }
355
356 }
357
358
Popular Tags