001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: EntityJdbcCmp1Desc.java 6407 2005-03-11 12:34:28Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.deployment.api;
025:
026: import java.lang.reflect.Field;
027: import java.lang.reflect.Method;
028: import java.util.Iterator;
029: import org.objectweb.jonas_ejb.deployment.xml.AssemblyDescriptor;
030: import org.objectweb.jonas_ejb.deployment.xml.CmpFieldJdbcMapping;
031: import org.objectweb.jonas_ejb.deployment.xml.Entity;
032: import org.objectweb.jonas_ejb.deployment.xml.FinderMethodJdbcMapping;
033: import org.objectweb.jonas_ejb.deployment.xml.JonasEntity;
034: import org.objectweb.jonas_ejb.deployment.xml.JdbcMapping;
035: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
036: import org.objectweb.jonas_ejb.deployment.xml.JonasMethod;
037: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
038:
039: /**
040: * Class to hold meta-information related to an CMP v1 entity bean with jdbc data store.
041: * @author Christophe Ney [cney@batisseurs.com] : Initial developer
042: * @author Helene Joanin
043: */
044: // TODO : fill mapping information with defaults values (same as CMP 2)
045: // to accept to have optional mapping information in the jonas-ejb-jar.xml.
046: // TODO : Review this class, many methods are common with EntityJdbcCmp2yDesc
047: public class EntityJdbcCmp1Desc extends EntityCmp1Desc {
048:
049: String jdbcTableName;
050: String datasourceJndiName;
051:
052: /**
053: * constructor: called when the DeploymentDescriptor is read.
054: * Currently, called by both GenIC and createContainer.
055: */
056: public EntityJdbcCmp1Desc(ClassLoader classLoader, Entity ent,
057: AssemblyDescriptor asd, JonasEntity jEnt,
058: JLinkedList jMDRList, String fileName)
059: throws DeploymentDescException {
060:
061: super (classLoader, ent, asd, jEnt, jMDRList, fileName);
062:
063: // check for jdbcMapping
064: JdbcMapping jm = jEnt.getJdbcMapping();
065: if (jm == null) {
066: throw new DeploymentDescException(
067: "jdbc-mapping missing for bean " + ent.getEjbName());
068: }
069:
070: // populate field descriptor map with jdbc information
071: for (Iterator i = jm.getCmpFieldJdbcMappingList().iterator(); i
072: .hasNext();) {
073: CmpFieldJdbcMapping cmpFieldJdbcMapping = (CmpFieldJdbcMapping) i
074: .next();
075: String fn = cmpFieldJdbcMapping.getFieldName();
076: FieldDesc f = (FieldDesc) fieldDesc.get(fn);
077: if (f == null) {
078: throw new DeploymentDescException(
079: "field-name "
080: + fn
081: + " listed in cmp-field-jdbc-mapping is not of cmp-field of bean "
082: + ent.getEjbName());
083: }
084: ((FieldJdbcDesc) f).setJdbcFieldName(cmpFieldJdbcMapping
085: .getJdbcFieldName());
086: }
087: // check that all cmp fields are jdbc
088: for (Iterator j = fieldDesc.values().iterator(); j.hasNext();) {
089: FieldJdbcDesc fd = (FieldJdbcDesc) j.next();
090: if (fd.getJdbcFieldName() == null) {
091: throw new DeploymentDescException(
092: "field-name "
093: + fd.getName()
094: + " is missing in cmp-field-jdbc-mapping for bean "
095: + ent.getEjbName());
096: }
097: }
098:
099: // populate method descriptor map with jdbc information
100: for (Iterator i = jm.getFinderMethodJdbcMappingList()
101: .iterator(); i.hasNext();) {
102: FinderMethodJdbcMapping fmj = ((FinderMethodJdbcMapping) i
103: .next());
104: JonasMethod m = fmj.getJonasMethod();
105: for (Iterator j = getMethodDescIterator(); j.hasNext();) {
106: MethodJdbcCmp1Desc md = (MethodJdbcCmp1Desc) j.next();
107: int matchStatus = md.matchPattern(null, m
108: .getMethodName(), m.getMethodParams());
109: md.overwriteJdbcWhereClause(fmj.getJdbcWhereClause(),
110: matchStatus);
111: }
112: }
113:
114: // jndi name of the datasource
115: datasourceJndiName = jm.getJndiName();
116:
117: // table name
118: jdbcTableName = jm.getJdbcTableName();
119:
120: // optionnal parameter automatic-pk
121: if (jm.getAutomaticPk() != null) {
122: jdbcAutomaticPk = jm.getAutomaticPk().equalsIgnoreCase(
123: "true");
124: }
125: }
126:
127: /**
128: * Get the datasource jndi name
129: * @return String representation of the jndi name
130: */
131: public String getDatasourceJndiName() {
132: return datasourceJndiName;
133: }
134:
135: /**
136: * Get jdbc specific descriptor for a given field.
137: * Used by GenIC
138: * @param field of the bean class
139: * @return Descriptor for the given field
140: */
141: public FieldJdbcDesc getFieldJdbcDesc(Field field) {
142: return (FieldJdbcDesc) super .getCmpFieldDesc(field);
143: }
144:
145: /**
146: * Get the associated DataBase table name in case of container persistence type.
147: * Used by GenIC (This information is JOnAS specific).
148: * @return Name of the database table where entity bean is stored
149: */
150: public String getJdbcTableName() {
151: return jdbcTableName;
152: }
153:
154: /**
155: * factory method for method descriptors
156: */
157: protected MethodDesc newMethodDescInstance(Method meth,
158: Class classDef, int index) {
159: return new MethodJdbcCmp1Desc(this , meth, classDef, index);
160: }
161:
162: /**
163: * String representation of the object for test purpose
164: * @return String representation of this object
165: */
166: public String toString() {
167: StringBuffer ret = new StringBuffer();
168: ret.append(super .toString());
169: ret.append("\ngetDatasourceJndiName()="
170: + getDatasourceJndiName());
171: ret.append("\ngetJdbcTableName()=" + getJdbcTableName());
172: return ret.toString();
173: }
174:
175: }
|