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: EntityJdbcCmp2Desc.java 5450 2004-09-17 09:44:19Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.deployment.api;
025:
026: import java.util.Iterator;
027:
028: import org.objectweb.jonas_ejb.deployment.xml.*;
029: import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
030: import org.objectweb.jonas_lib.deployment.xml.JLinkedList;
031:
032: /**
033: * Class to hold meta-information related to an CMP v2 entity bean with jdbc data store.
034: * @author Christophe Ney [cney@batisseurs.com] : Initial developer
035: * @author Helene Joanin on May 2003: code cleanup
036: * @author Helene Joanin on May 2003: complement for legacy first version
037: */
038:
039: // TODO : Review this class, many methods are common with EntityJdbcCmp1Desc
040: public class EntityJdbcCmp2Desc extends EntityCmp2Desc {
041:
042: protected String dsname;
043: protected String jdbcTableName = null;
044:
045: /**
046: * constructor: called when the DeploymentDescriptor is read.
047: * Currently, called by both GenIC and createContainer.
048: */
049: public EntityJdbcCmp2Desc(ClassLoader classLoader, Entity ent,
050: AssemblyDescriptor asd, JonasEntity jEnt,
051: DeploymentDescEjb2 dc2d, JLinkedList jMDRList,
052: String fileName) throws DeploymentDescException {
053:
054: super (classLoader, ent, asd, jEnt, dc2d, jMDRList, fileName);
055:
056: // check for jdbcMapping
057: JdbcMapping jm = jEnt.getJdbcMapping();
058: if (jm == null) {
059: throw new DeploymentDescException(
060: "jdbc-mapping missing for bean " + ent.getEjbName());
061: }
062:
063: // jndi name of the datasource
064: dsname = jm.getJndiName();
065:
066: // jdbc table name
067: if (jm.getJdbcTableName() != null) {
068: if (jm.getJdbcTableName().length() != 0) {
069: jdbcTableName = jm.getJdbcTableName();
070: }
071: }
072: if (jdbcTableName == null) {
073: // Default value
074: jdbcTableName = getAbstractSchemaName().toUpperCase() + "_";
075: }
076:
077: // Default mapping information for cmp fields
078: for (Iterator i = fieldDesc.keySet().iterator(); i.hasNext();) {
079: String fn = (String) i.next();
080: ((FieldJdbcDesc) (fieldDesc.get(fn))).setJdbcFieldName(fn
081: + "_");
082: }
083:
084: // mapping information for cmp fields from jonas DD
085: for (Iterator i = jm.getCmpFieldJdbcMappingList().iterator(); i
086: .hasNext();) {
087: CmpFieldJdbcMapping fm = (CmpFieldJdbcMapping) i.next();
088: String fn = fm.getFieldName();
089: String cn = fm.getJdbcFieldName();
090: String ct = null;
091: if (fm.getSqlType() != null) {
092: ct = fm.getSqlType();
093: }
094: FieldJdbcDesc fdesc = (FieldJdbcDesc) fieldDesc.get(fn);
095: if (fdesc == null) {
096: throw new DeploymentDescException(
097: "field-name "
098: + fn
099: + " listed in cmp-field-jdbc-mapping is not of cmp-field of bean "
100: + ent.getEjbName());
101: }
102: fdesc.setJdbcFieldName(cn);
103: if (ct != null) {
104: fdesc.setSqlType(ct);
105: }
106: }
107: // Specific mapping for primary key auto generated (type = java.lang.Object) if tag <automatic-pk-field-name> is specified
108: if (isUndefinedPK()
109: && this .getJdbcAutomaticPkFieldName() != null) {
110: ((FieldJdbcDesc) (fieldDesc.get("JONASAUTOPKFIELD")))
111: .setJdbcFieldName(this
112: .getJdbcAutomaticPkFieldName());
113: }
114: }
115:
116: /**
117: * field descriptor factory method
118: */
119: protected FieldDesc newFieldDescInstance() {
120: return new FieldJdbcDesc();
121: }
122:
123: /**
124: * Get the datasource jndi name
125: * @return String representation of the jndi name
126: */
127: public String getDatasourceJndiName() {
128: return dsname;
129: }
130:
131: /**
132: * Get the associated DataBase table name.
133: * @return Name of the database table where entity bean is stored
134: */
135: public String getJdbcTableName() {
136: return jdbcTableName;
137: }
138:
139: /**
140: * String representation of the object for test purpose
141: * @return String representation of this object
142: */
143: public String toString() {
144: StringBuffer ret = new StringBuffer();
145: ret.append(super .toString());
146: ret.append("\ngetDatasourceJndiName()="
147: + getDatasourceJndiName());
148: ret.append("\ngetJdbcTableName()=" + getJdbcTableName());
149: return ret.toString();
150: }
151:
152: }
|