1 25 26 package org.objectweb.jonas_ejb.deployment.api; 27 28 import java.lang.reflect.Field ; 29 import java.lang.reflect.Method ; 30 import java.util.Iterator ; 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 46 50 public class EntityJdbcCmp1Desc extends EntityCmp1Desc { 51 52 53 String jdbcTableName; 54 String datasourceJndiName; 55 59 public EntityJdbcCmp1Desc(ClassLoader classLoader, Entity ent, 60 AssemblyDescriptor asd, JonasEntity jEnt, 61 JLinkedList jMDRList, String fileName) 62 throws DeploymentDescException { 63 64 super(classLoader, ent, asd, jEnt, jMDRList, fileName); 65 66 JdbcMapping jm = jEnt.getJdbcMapping(); 68 if (jm == null) { 69 throw new DeploymentDescException("jdbc-mapping missing for bean " + ent.getEjbName()); 70 } 71 72 for (Iterator i = jm.getCmpFieldJdbcMappingList().iterator(); i.hasNext(); ) { 74 CmpFieldJdbcMapping cmpFieldJdbcMapping = (CmpFieldJdbcMapping) i.next(); 75 String 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 for (Iterator 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 for (Iterator i = jm.getFinderMethodJdbcMappingList().iterator(); i.hasNext(); ) { 94 FinderMethodJdbcMapping fmj = ((FinderMethodJdbcMapping) i.next()); 95 JonasMethod m = fmj.getJonasMethod(); 96 for (Iterator 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 datasourceJndiName = jm.getJndiName(); 105 106 jdbcTableName = jm.getJdbcTableName(); 108 109 if (jm.getAutomaticPk() != null) { 111 jdbcAutomaticPk = jm.getAutomaticPk().equalsIgnoreCase("true"); 112 } 113 } 114 115 116 120 public String getDatasourceJndiName() { 121 return datasourceJndiName; 122 } 123 124 130 public FieldJdbcDesc getFieldJdbcDesc(Field field) { 131 return (FieldJdbcDesc) super.getCmpFieldDesc(field); 132 } 133 134 135 140 public String getJdbcTableName() { 141 return jdbcTableName; 142 } 143 144 147 protected MethodDesc newMethodDescInstance(Method meth, Class classDef, int index) { 148 return new MethodJdbcCmp1Desc(this, meth, classDef, index); 149 } 150 151 155 public String toString() { 156 StringBuffer ret = new StringBuffer (); 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 |