1 23 24 25 26 31 32 package com.sun.jdo.spi.persistence.support.ejb.ejbc; 33 34 import java.util.*; 35 import java.io.IOException ; 36 import java.lang.reflect.Method ; 37 import java.lang.reflect.Modifier ; 38 import java.text.MessageFormat ; 39 40 import com.sun.jdo.api.persistence.model.Model; 41 import com.sun.jdo.api.persistence.model.jdo.*; 42 43 import com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper; 44 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.JDOQLElements; 45 46 import com.sun.jdo.spi.persistence.utility.I18NHelper; 47 import com.sun.jdo.spi.persistence.utility.generator.*; 48 import com.sun.jdo.spi.persistence.utility.logging.Logger; 49 50 55 class JDOConcreteBean11Generator extends JDOConcreteBeanGenerator { 56 57 60 static final String SIGNATURE = "$RCSfile: JDOConcreteBean11Generator.java,v $ $Revision: 1.2 $"; 62 JDOConcreteBean11Generator(ClassLoader loader, 63 Model model, 64 NameMapper nameMapper) 65 throws IOException { 66 67 super (loader, model, nameMapper); 68 CMP11TemplateFormatter.initHelpers(); 69 70 addCodeGeneratorClassSignature(getSignaturesOfGeneratorClasses()); 73 } 74 75 77 void addInterfaces() throws IOException { 78 super.addInterfaces(); 79 jdoHelperWriter.addInterface(CMP11TemplateFormatter.helper11Interface_); 80 } 81 82 84 void setHelperSuperclass() throws IOException { 85 jdoHelperWriter.setSuperclass(CMP11TemplateFormatter.helper11Impl_); 86 } 87 88 90 void generateTypeSpecificMethods(PersistenceFieldElement[] allFields, 91 AbstractMethodHelper methodHelper) throws IOException { 92 93 super.generateTypeSpecificMethods(allFields, methodHelper); 94 generateLoadStoreMethods(allFields); 95 } 96 97 100 void generateFields() throws IOException { 101 102 super.generateFields(); 103 CMP11TemplateFormatter.addPrivateField( 104 CMP11TemplateFormatter.one_oneVariablesTemplate, 105 0, concreteImplWriter); 106 } 107 108 109 111 void generateLoadStoreMethods(PersistenceFieldElement[] fields) 112 throws IOException { 113 int i, count = ((fields != null) ? fields.length : 0); 114 StringBuffer lbody = new StringBuffer (); 115 StringBuffer sbody = new StringBuffer (CMPTemplateFormatter.none_); 116 117 for (i = 0; i < count; i++) { 118 PersistenceFieldElement pfe = fields[i]; 119 120 if (PersistenceFieldElement.PERSISTENT == pfe.getPersistenceType()) { 121 FieldInfo fieldInfo = new FieldInfo(model, nameMapper, pfe, beanName, pcname); 122 123 if (fieldInfo.isGeneratedField) { 124 if (fieldInfo.isKey) { 128 setPKField = fieldInfo.setter; 132 } 133 continue; 134 } 135 136 loadNonDFGField(fieldInfo); 138 139 if( fieldInfo.isByteArray) { 140 twoParams[0] = fieldInfo.name; 143 twoParams[1] = fieldInfo.getter; 144 lbody.append(CMP11TemplateFormatter.l11arrayformatter.format(twoParams)); 145 146 if (isUpdateable) { 147 threeParams[0] = fieldInfo.getter; 148 threeParams[1] = fieldInfo.name; 149 threeParams[2] = fieldInfo.setter; 150 sbody.append(CMP11TemplateFormatter.s11arrayformatter.format(threeParams)); 151 } 152 153 } else if( fieldInfo.isSerializable ) { 154 157 fourParams[0] = fieldInfo.name; 158 fourParams[1] = fieldInfo.getter; 159 fourParams[2] = fieldInfo.type; 160 fourParams[3] = concreteImplName; 161 lbody.append(CMP11TemplateFormatter.l11Serializableformatter.format(fourParams)); 162 163 if (isUpdateable) { 164 fourParams[0] = fieldInfo.getter; 165 fourParams[1] = fieldInfo.name; 166 fourParams[2] = fieldInfo.setter; 167 fourParams[3] = concreteImplName; 168 sbody.append(CMP11TemplateFormatter.s11Serializableformatter.format(fourParams)); 169 } 170 171 } else if (fieldInfo.requireCloneOnGetAndSet) { 172 threeParams[0] = fieldInfo.getter; 173 threeParams[1] = fieldInfo.type; 174 threeParams[2] = fieldInfo.name; 175 lbody.append(CMP11TemplateFormatter.l11copyformatter.format(threeParams)); 176 177 if (isUpdateable) { 178 fourParams[0] = fieldInfo.getter; 179 fourParams[1] = fieldInfo.name; 180 fourParams[2] = fieldInfo.setter; 181 fourParams[3] = fieldInfo.type; 182 if (!pfe.isKey()) { 183 sbody.append(CMP11TemplateFormatter.s11copyformatter.format(fourParams)); 184 } else { 185 twoParams[0] = concreteImplName; 186 twoParams[1] = fieldInfo.name; 187 sbody.append(CMP11TemplateFormatter.assertpks11formatter.format(twoParams)). 188 append(CMP11TemplateFormatter.pkcopy11formatter.format(fourParams)); 189 } 190 } 191 192 } else { 193 twoParams[0] = fieldInfo.name; 194 twoParams[1] = fieldInfo.getter; 195 lbody.append(CMP11TemplateFormatter.l11formatter.format(twoParams)); 196 197 if (isUpdateable) { 198 threeParams[0] = fieldInfo.getter; 199 threeParams[1] = fieldInfo.name; 200 threeParams[2] = fieldInfo.setter; 201 if (!pfe.isKey()) { 202 sbody.append(CMP11TemplateFormatter.s11formatter.format(threeParams)); 203 } else { 204 if (!fieldInfo.isPrimitive) { 205 twoParams[0] = concreteImplName; 206 twoParams[1] = fieldInfo.name; 207 sbody.append( 208 CMP11TemplateFormatter.assertpks11formatter.format(twoParams)); 209 } 210 211 sbody.append(requireTrimOnSet(fieldInfo.type) ? 212 CMP11TemplateFormatter.pkstring11formatter.format(threeParams) : 213 CMP11TemplateFormatter.pks11formatter.format(threeParams)); 214 } 215 } 216 217 } 218 } 219 } 220 221 CMPTemplateFormatter.addGenericMethod( 223 CMP11TemplateFormatter.loadFields1_1_, 224 CMP11TemplateFormatter.getBodyAsStrings(lbody.toString()), 225 concreteImplWriter); 226 227 CMPTemplateFormatter.addGenericMethod( 229 CMP11TemplateFormatter.storeFields1_1_, 230 CMP11TemplateFormatter.getBodyAsStrings(sbody.toString()), 231 concreteImplWriter); 232 } 233 234 240 JDOQLElements getJDOQLElements(Method m, 241 AbstractMethodHelper methodHelper) throws IOException { 242 243 return getJDOQLElementsForCMP11(m, methodHelper); 245 } 246 247 255 String getEJBCreateMethodBody(String createName, 256 String [] exc, String parametersList, 257 String parametersListWithSeparator) { 258 259 String body = CMPROTemplateFormatter.accessNotAllowedTemplate; 262 263 if (isUpdateable) { 264 if (pkClass.equals(Object .class.getName())) { 267 fiveParams[0] = pcname; 268 fiveParams[1] = parametersList; 269 fiveParams[2] = setPKField; 270 fiveParams[3] = concreteImplName; 271 fiveParams[4] = parametersListWithSeparator; 272 body = CMP11TemplateFormatter.c11unpkformatter.format(fiveParams); 273 274 } else { 275 sixParams[0] = pcname; 276 sixParams[1] = parametersList; 277 sixParams[2] = pkClass; 278 sixParams[3] = concreteImplName; 279 String s = getException(exc, CMP11TemplateFormatter.DuplicateKeyException_, 280 CMP11TemplateFormatter.CreateException_); 281 int l = s.lastIndexOf(CMP11TemplateFormatter.dot_); 282 sixParams[4] = (l > 0)? s.substring(l + 1) : s; 283 sixParams[5] = parametersListWithSeparator; 284 body = CMP11TemplateFormatter.c11formatter.format(sixParams); 285 286 } 287 } 288 return body; 289 } 290 291 298 String getEJBPostCreateMethodBody(String postCreateName, 299 String parametersList, String parametersListWithSeparator) { 300 301 String body = CMPTemplateFormatter.none_; 304 305 if (isUpdateable) { 306 twoParams[0] = parametersList; 307 twoParams[1] = parametersListWithSeparator; 308 body = CMP11TemplateFormatter.postc11formatter.format(twoParams); 309 } 310 311 return body; 312 } 313 314 317 String getEJBRemoveMethodBody() { 318 319 String body = CMPROTemplateFormatter.updateNotAllowedTemplate; 322 323 if (isUpdateable) { 324 body = CMP11TemplateFormatter.ejbRemove1_1Template; 326 } 327 328 return body; 329 } 330 331 335 void generateKnownMethods(AbstractMethodHelper methodHelper) 336 throws IOException { 337 338 super.generateKnownMethods(methodHelper); 339 340 String [] exc = null; 341 String [] st = CMP11TemplateFormatter.otherPublicMethodsArray; 342 for (int i = 0; i < st.length; i++) { 343 String mname = st[i]; 344 exc = getExceptionList(methodHelper, mname); 345 346 String body = CMPROTemplateFormatter.updateNotAllowedTemplate; 347 if (isUpdateable || mname.equals(CMPTemplateFormatter.ejbLoad_)) { 349 body = CMP11TemplateFormatter.helpers.getProperty( 350 mname + "1_1"); } else if (mname.equals(CMPTemplateFormatter.jdoCleanAllRefs_)) { 352 body = CMPROTemplateFormatter.jdoCleanAllRefsTemplate; 353 } 354 355 concreteImplWriter.addMethod(mname, Modifier.PUBLIC, CMP11TemplateFormatter.void_, null, null, exc, CMP11TemplateFormatter.getBodyAsStrings(body), null); } 364 365 } 366 367 372 boolean isFinderReturningEnumeration(Method finder) { 373 return (finder.getReturnType().equals(java.util.Enumeration .class)); 374 } 375 376 381 String generateQueryIgnoreCache() 382 { 383 oneParam[0] = CMP11TemplateFormatter.true_; 384 return CMP11TemplateFormatter.querysetignorecacheformatter.format(oneParam); 385 } 386 387 396 private JDOQLElements getJDOQLElementsForCMP11(Method m, 397 AbstractMethodHelper methodHelper) { 398 399 String params = methodHelper.getJDOParameterDeclaration(m); 400 String variables = methodHelper.getJDOVariableDeclaration(m); 401 String filter = methodHelper.getJDOFilterExpression(m); 402 String ordering = methodHelper.getJDOOrderingSpecification(m); 403 return new JDOQLElements( 404 pcname, params, variables, filter, ordering, "this", pcname, true, false, null ); 418 419 } 420 421 426 String getSignaturesOfGeneratorClasses() 427 { 428 StringBuffer signatures = new StringBuffer (). 429 430 append(super.getSignaturesOfGeneratorClasses()). 432 append(CMPTemplateFormatter.signatureDelimiter_). 433 434 append(JDOConcreteBean11Generator.SIGNATURE). 436 append(CMPTemplateFormatter.signatureDelimiter_). 437 438 append(CMP11TemplateFormatter.signature1_1Template); 440 441 return signatures.toString(); 442 } 443 444 } 445 446 | Popular Tags |