KickJava   Java API By Example, From Geeks To Geeks.

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


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: EntityJdbcCmp2Desc.java,v 1.24 2004/09/17 09:44:19 joaninh 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.*;
32 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
33 import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
34
35 /**
36  * Class to hold meta-information related to an CMP v2 entity bean with jdbc data store.
37  * @author Christophe Ney [cney@batisseurs.com] : Initial developer
38  * @author Helene Joanin on May 2003: code cleanup
39  * @author Helene Joanin on May 2003: complement for legacy first version
40  */

41
42 // TODO : Review this class, many methods are common with EntityJdbcCmp1Desc
43

44 public class EntityJdbcCmp2Desc extends EntityCmp2Desc {
45
46     protected String JavaDoc dsname;
47     protected String JavaDoc jdbcTableName = null;
48
49     /**
50      * constructor: called when the DeploymentDescriptor is read.
51      * Currently, called by both GenIC and createContainer.
52      */

53     public EntityJdbcCmp2Desc(ClassLoader JavaDoc classLoader,
54                               Entity ent,
55                               AssemblyDescriptor asd,
56                               JonasEntity jEnt,
57                               DeploymentDescEjb2 dc2d,
58                               JLinkedList jMDRList,
59                               String JavaDoc fileName)
60         throws DeploymentDescException {
61
62         super(classLoader, ent, asd, jEnt, dc2d, jMDRList, fileName);
63
64         // check for jdbcMapping
65
JdbcMapping jm = jEnt.getJdbcMapping();
66         if (jm == null) {
67             throw new DeploymentDescException("jdbc-mapping missing for bean " + ent.getEjbName());
68         }
69
70         // jndi name of the datasource
71
dsname = jm.getJndiName();
72
73         // jdbc table name
74
if (jm.getJdbcTableName() != null) {
75             if (jm.getJdbcTableName().length() != 0) {
76                 jdbcTableName = jm.getJdbcTableName();
77             }
78         }
79         if (jdbcTableName == null) {
80             // Default value
81
jdbcTableName = getAbstractSchemaName().toUpperCase() + "_";
82         }
83
84         // Default mapping information for cmp fields
85
for (Iterator JavaDoc i = fieldDesc.keySet().iterator();i.hasNext();) {
86             String JavaDoc fn = (String JavaDoc) i.next();
87             ((FieldJdbcDesc)(fieldDesc.get(fn))).setJdbcFieldName(fn + "_");
88         }
89
90         // mapping information for cmp fields from jonas DD
91
for (Iterator JavaDoc i = jm.getCmpFieldJdbcMappingList().iterator();i.hasNext();) {
92             CmpFieldJdbcMapping fm = (CmpFieldJdbcMapping) i.next();
93             String JavaDoc fn = fm.getFieldName();
94             String JavaDoc cn = fm.getJdbcFieldName();
95             String JavaDoc ct = null;
96             if (fm.getSqlType() != null) {
97                 ct = fm.getSqlType();
98             }
99             FieldJdbcDesc fdesc = (FieldJdbcDesc) fieldDesc.get(fn);
100             if (fdesc == null) {
101                 throw new DeploymentDescException("field-name " + fn
102                                                   + " listed in cmp-field-jdbc-mapping is not of cmp-field of bean " + ent.getEjbName());
103             }
104             fdesc.setJdbcFieldName(cn);
105             if (ct != null) {
106                 fdesc.setSqlType(ct);
107             }
108         }
109         // Specific mapping for primary key auto generated (type = java.lang.Object) if tag <automatic-pk-field-name> is specified
110
if (isUndefinedPK() && this.getJdbcAutomaticPkFieldName()!= null) {
111            ((FieldJdbcDesc)(fieldDesc.get("JONASAUTOPKFIELD"))).setJdbcFieldName(this.getJdbcAutomaticPkFieldName());
112         }
113     }
114
115     /**
116      * field descriptor factory method
117      */

118     protected FieldDesc newFieldDescInstance() {
119         return new FieldJdbcDesc();
120     }
121
122     /**
123      * Get the datasource jndi name
124      * @return String representation of the jndi name
125      */

126     public String JavaDoc getDatasourceJndiName() {
127         return dsname;
128     }
129
130     /**
131      * Get the associated DataBase table name.
132      * @return Name of the database table where entity bean is stored
133      */

134     public String JavaDoc getJdbcTableName() {
135         return jdbcTableName;
136     }
137
138     /**
139      * String representation of the object for test purpose
140      * @return String representation of this object
141      */

142     public String JavaDoc toString() {
143         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
144         ret.append(super.toString());
145         ret.append("\ngetDatasourceJndiName()=" + getDatasourceJndiName());
146         ret.append("\ngetJdbcTableName()=" + getJdbcTableName());
147         return ret.toString();
148     }
149
150
151 }
152
Popular Tags