KickJava   Java API By Example, From Geeks To Geeks.

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


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: EntityJdbcCmp1Desc.java,v 1.17 2005/03/11 12:34:28 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.deployment.api;
27
28 import java.lang.reflect.Field JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
32 import org.objectweb.jonas_ejb.deployment.xml.CmpFieldJdbcMapping;
33 import org.objectweb.jonas_ejb.deployment.xml.Entity;
34 import org.objectweb.jonas_ejb.deployment.xml.FinderMethodJdbcMapping;
35 import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
36 import org.objectweb.jonas_ejb.deployment.xml.JdbcMapping;
37 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
38 import org.objectweb.jonas_ejb.deployment.xml.JonasMethod;
39 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
40
41 /**
42  * Class to hold meta-information related to an CMP v1 entity bean with jdbc data store.
43  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
44  * @author Helene Joanin
45 */

46 // TODO : fill mapping information with defaults values (same as CMP 2)
47
// to accept to have optional mapping information in the jonas-ejb-jar.xml.
48
// TODO : Review this class, many methods are common with EntityJdbcCmp2yDesc
49

50 public class EntityJdbcCmp1Desc extends EntityCmp1Desc {
51
52
53     String JavaDoc jdbcTableName;
54     String JavaDoc datasourceJndiName;
55     /**
56      * constructor: called when the DeploymentDescriptor is read.
57      * Currently, called by both GenIC and createContainer.
58      */

59     public EntityJdbcCmp1Desc(ClassLoader JavaDoc classLoader, Entity ent,
60                   AssemblyDescriptor asd, JonasEntity jEnt,
61                   JLinkedList jMDRList, String JavaDoc fileName)
62         throws DeploymentDescException {
63
64         super(classLoader, ent, asd, jEnt, jMDRList, fileName);
65
66         // check for jdbcMapping
67
JdbcMapping jm = jEnt.getJdbcMapping();
68         if (jm == null) {
69             throw new DeploymentDescException("jdbc-mapping missing for bean " + ent.getEjbName());
70         }
71
72         // populate field descriptor map with jdbc information
73
for (Iterator JavaDoc i = jm.getCmpFieldJdbcMappingList().iterator(); i.hasNext(); ) {
74             CmpFieldJdbcMapping cmpFieldJdbcMapping = (CmpFieldJdbcMapping) i.next();
75             String JavaDoc fn = cmpFieldJdbcMapping.getFieldName();
76             FieldDesc f = (FieldDesc) fieldDesc.get(fn);
77             if (f == null) {
78                 throw new DeploymentDescException("field-name " + fn
79                                                   + " listed in cmp-field-jdbc-mapping is not of cmp-field of bean " + ent.getEjbName());
80             }
81             ((FieldJdbcDesc) f).setJdbcFieldName(cmpFieldJdbcMapping.getJdbcFieldName());
82         }
83         // check that all cmp fields are jdbc
84
for (Iterator JavaDoc j = fieldDesc.values().iterator(); j.hasNext();) {
85             FieldJdbcDesc fd = (FieldJdbcDesc) j.next();
86             if (fd.getJdbcFieldName() == null) {
87                 throw new DeploymentDescException("field-name " + fd.getName()
88                                                   + " is missing in cmp-field-jdbc-mapping for bean " + ent.getEjbName());
89             }
90         }
91
92         // populate method descriptor map with jdbc information
93
for (Iterator JavaDoc i = jm.getFinderMethodJdbcMappingList().iterator(); i.hasNext(); ) {
94             FinderMethodJdbcMapping fmj = ((FinderMethodJdbcMapping) i.next());
95             JonasMethod m = fmj.getJonasMethod();
96             for (Iterator JavaDoc j = getMethodDescIterator(); j.hasNext();) {
97                 MethodJdbcCmp1Desc md = (MethodJdbcCmp1Desc) j.next();
98                 int matchStatus = md.matchPattern(null, m.getMethodName(), m.getMethodParams());
99                 md.overwriteJdbcWhereClause(fmj.getJdbcWhereClause(), matchStatus);
100             }
101         }
102
103         // jndi name of the datasource
104
datasourceJndiName = jm.getJndiName();
105
106         // table name
107
jdbcTableName = jm.getJdbcTableName();
108
109         // optionnal parameter automatic-pk
110
if (jm.getAutomaticPk() != null) {
111             jdbcAutomaticPk = jm.getAutomaticPk().equalsIgnoreCase("true");
112         }
113     }
114
115
116     /**
117      * Get the datasource jndi name
118      * @return String representation of the jndi name
119      */

120     public String JavaDoc getDatasourceJndiName() {
121         return datasourceJndiName;
122     }
123
124     /**
125      * Get jdbc specific descriptor for a given field.
126      * Used by GenIC
127      * @param field of the bean class
128      * @return Descriptor for the given field
129      */

130     public FieldJdbcDesc getFieldJdbcDesc(Field JavaDoc field) {
131         return (FieldJdbcDesc) super.getCmpFieldDesc(field);
132     }
133
134
135     /**
136      * Get the associated DataBase table name in case of container persistence type.
137      * Used by GenIC (This information is JOnAS specific).
138      * @return Name of the database table where entity bean is stored
139      */

140     public String JavaDoc getJdbcTableName() {
141         return jdbcTableName;
142     }
143
144     /**
145      * factory method for method descriptors
146      */

147     protected MethodDesc newMethodDescInstance(Method JavaDoc meth, Class JavaDoc classDef, int index) {
148         return new MethodJdbcCmp1Desc(this, meth, classDef, index);
149     }
150
151     /**
152      * String representation of the object for test purpose
153      * @return String representation of this object
154      */

155     public String JavaDoc toString() {
156         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
157         ret.append(super.toString());
158         ret.append("\ngetDatasourceJndiName()=" + getDatasourceJndiName());
159         ret.append("\ngetJdbcTableName()=" + getJdbcTableName());
160         return ret.toString();
161     }
162
163
164 }
165
166
Popular Tags