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.ModelException; 42 import com.sun.jdo.api.persistence.model.jdo.*; 43 44 import com.sun.jdo.api.persistence.support.JDOUserException; 45 import com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper; 46 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLC; 47 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.JDOQLElements; 48 import com.sun.jdo.spi.persistence.support.ejb.ejbqlc.EJBQLException; 49 50 import com.sun.jdo.spi.persistence.utility.I18NHelper; 51 import com.sun.jdo.spi.persistence.utility.generator.*; 52 import com.sun.jdo.spi.persistence.utility.logging.Logger; 53 54 59 class JDOConcreteBean20Generator extends JDOConcreteBeanGenerator { 60 61 private EJBQLC ejbqlc; 63 64 70 private Map jdoqlElementsMap; 71 72 private StringBuffer cascadeDelete = null; 74 75 private String gbody = null; 77 78 private String sbody = null; 80 81 84 static final String SIGNATURE = 85 "$RCSfile: JDOConcreteBean20Generator.java,v $ $Revision: 1.2 $"; 87 JDOConcreteBean20Generator(ClassLoader loader, 88 Model model, 89 NameMapper nameMapper) 90 throws IOException { 91 92 super(loader, model, nameMapper); 93 CMP20TemplateFormatter.initHelpers(); 94 95 addCodeGeneratorClassSignature(getSignaturesOfGeneratorClasses()); 98 99 ejbqlc = new EJBQLC(model, nameMapper); 101 } 102 103 112 Collection validate(AbstractMethodHelper methodHelper, String beanName) { 113 Collection rc = super.validate(methodHelper, beanName); 114 115 this.beanName = beanName; 116 rc.addAll(validateEJBQL(methodHelper)); 117 118 return rc; 119 } 120 121 122 124 void addInterfaces() throws IOException { 125 super.addInterfaces(); 126 jdoHelperWriter.addInterface(CMP20TemplateFormatter.helper20Interface_); 127 } 128 129 131 void setHelperSuperclass() throws IOException { 132 jdoHelperWriter.setSuperclass(CMP20TemplateFormatter.helper20Impl_); 133 } 134 135 137 void addImportStatements(JavaFileWriter concreteImplFileWriter, 138 JavaFileWriter helperFileWriter) throws IOException { 139 140 super.addImportStatements(concreteImplFileWriter, helperFileWriter); 141 concreteImplFileWriter.addImport( 142 CMP20TemplateFormatter.ejbHashSetImport_, null); 143 } 144 145 147 void generateTypeSpecificMethods(PersistenceFieldElement[] allFields, 148 AbstractMethodHelper methodHelper) throws IOException { 149 150 super.generateTypeSpecificMethods(allFields, methodHelper); 151 152 generateGetSetMethods(allFields); 154 155 generateSelectors(methodHelper); 157 158 } 159 160 162 private void generateGetSetMethods(PersistenceFieldElement[] fields) 163 throws IOException { 164 int i, count = ((fields != null) ? fields.length : 0); 165 setPKField = null; cascadeDelete = new StringBuffer (); 167 168 StringBuffer cmrcleanbodyBuf = new StringBuffer (CMP20TemplateFormatter.none_); 170 171 for (i = 0; i < count; i++) { 172 PersistenceFieldElement pfe = fields[i]; 173 174 if (PersistenceFieldElement.PERSISTENT == pfe.getPersistenceType()) { 175 176 gbody = null; 178 sbody = null; 179 180 FieldInfo fieldInfo = new FieldInfo(model, nameMapper, pfe, beanName, pcname); 181 182 if (fieldInfo.isGeneratedField) { 183 if (fieldInfo.isKey) { 187 setPKField = fieldInfo.setter; 191 } 192 continue; 193 } 194 195 if (!(pfe instanceof RelationshipElement)) { 196 generateCMPGetSetBodies(fieldInfo); 197 198 } else { if (isUpdateable) { 200 generateCMRGetSetBodies(fieldInfo, cmrcleanbodyBuf); 201 202 } else { 203 logger.log(Logger.WARNING, I18NHelper.getMessage(messages, 204 "CMG.CMRAccessNotAllowed", beanName, fieldInfo.name)); 206 gbody = CMPROTemplateFormatter.accessNotAllowedTemplate; 207 sbody = CMPROTemplateFormatter.updateNotAllowedTemplate; 208 } 209 } 210 211 CMPTemplateFormatter.addGenericMethod( 213 fieldInfo.getter, Modifier.PUBLIC, fieldInfo.type, 214 CMP20TemplateFormatter.getBodyAsStrings(gbody), 215 concreteImplWriter); 216 217 oneParam[0] = fieldInfo.type; 218 concreteImplWriter.addMethod(fieldInfo.setter, Modifier.PUBLIC, CMP20TemplateFormatter.void_, param0, oneParam, null, CMP20TemplateFormatter.getBodyAsStrings(sbody), null); } 227 } 228 229 CMPTemplateFormatter.addGenericMethod( 231 CMP20TemplateFormatter.jdoCleanCollectionRef_, 232 CMP20TemplateFormatter.getBodyAsStrings(cmrcleanbodyBuf.toString()), 233 concreteImplWriter); 234 } 235 236 239 private void generateCMPGetSetBodies(FieldInfo fieldInfo) { 240 241 sbody = CMPROTemplateFormatter.updateNotAllowedTemplate; 244 245 loadNonDFGField(fieldInfo); 247 248 if( fieldInfo.requireCloneOnGetAndSet ) { 249 twoParams[0] = fieldInfo.getter; 252 twoParams[1] = fieldInfo.type; 253 gbody = CMP20TemplateFormatter.copygformatter.format(twoParams); 254 255 if (isUpdateable) { 256 twoParams[0] = fieldInfo.setter; 257 if (!fieldInfo.isKey) { 258 sbody = CMP20TemplateFormatter.copysformatter.format(twoParams); 259 } else { 260 String [] params = new String [] {concreteImplName, fieldInfo.name}; 261 sbody = CMP20TemplateFormatter.assertpksformatter.format(params) + 262 CMP20TemplateFormatter.pkcopysformatter.format(twoParams); 263 } 264 } 265 266 } else if( fieldInfo.isByteArray ) { 267 oneParam[0] = fieldInfo.getter; 270 gbody = CMP20TemplateFormatter.arraygformatter.format(oneParam); 271 272 if (isUpdateable) { 273 oneParam[0] = fieldInfo.setter; 274 sbody = CMP20TemplateFormatter.arraysformatter.format(oneParam); 275 } 276 } else if( fieldInfo.isSerializable ) { 277 280 threeParams[0] = fieldInfo.getter; 281 threeParams[1] = fieldInfo.type; 282 threeParams[2] = concreteImplName; 283 gbody = CMP20TemplateFormatter.sfldgformatter.format(threeParams); 284 285 if (isUpdateable) { 286 twoParams[0] = fieldInfo.setter; 287 twoParams[1] = concreteImplName; 288 sbody = CMP20TemplateFormatter.sfldsformatter.format(twoParams); 289 } 290 } else { 291 oneParam[0] = fieldInfo.getter; 292 gbody = CMP20TemplateFormatter.gformatter.format(oneParam); 293 294 if (isUpdateable) { 295 oneParam[0] = fieldInfo.setter; 296 if (!fieldInfo.isKey) { 297 sbody = CMP20TemplateFormatter.sformatter.format(oneParam); 298 299 } else { 300 StringBuffer sb = new StringBuffer (); 301 if (!fieldInfo.isPrimitive) { 302 twoParams[0] = concreteImplName; 303 twoParams[1] = fieldInfo.name; 304 sb.append( 305 CMP20TemplateFormatter.assertpksformatter.format(twoParams)); 306 } 307 308 sb.append(requireTrimOnSet(fieldInfo.type) ? 309 CMP20TemplateFormatter.pkstringsformatter.format(oneParam) : 310 CMP20TemplateFormatter.pksformatter.format(oneParam)); 311 312 sbody = sb.toString(); 313 } 314 } 315 } 316 317 } 318 319 324 private void generateCMRGetSetBodies(FieldInfo fieldInfo, 325 StringBuffer cmrcleanbodyBuf) throws IOException { 326 327 RelationshipElement rel = (RelationshipElement)fieldInfo.pfe; 328 329 String otherPC = model.getRelatedClass(rel); 330 boolean manySide = model.isCollection(fieldInfo.type); 331 332 if (logger.isLoggable(Logger.FINE)) { 333 RelationshipElement otherField = rel.getInverseRelationship(model); 334 String otherFieldName = ((otherField != null) ? 335 nameMapper.getEjbFieldForPersistenceField(otherPC, 336 otherField.getName()) : 337 null); 338 339 logger.fine("manySide: " + manySide); logger.fine("Field: " + otherFieldName); } 342 343 String otherEJB = nameMapper.getEjbNameForPersistenceClass(otherPC); 344 String otherImpl = nameMapper.getConcreteBeanClassForEjbName(otherEJB); 345 MessageFormat mformat = null; 346 347 if (manySide) { 348 threeParams[0] = fieldInfo.getter; 349 threeParams[1] = fieldInfo.name; 350 threeParams[2] = otherImpl; 351 gbody = CMP20TemplateFormatter.cmrCgformatter.format(threeParams); 352 353 fourParams[0] = otherImpl; 354 fourParams[1] = fieldInfo.setter; 355 fourParams[2] = fieldInfo.getter; 356 fourParams[3] = fieldInfo.name; 357 sbody = CMP20TemplateFormatter.cmrCsformatter.format(fourParams); 358 359 mformat = CMP20TemplateFormatter.cmrcdCformatter; 360 361 twoParams[0] = fieldInfo.type; 362 twoParams[1] = fieldInfo.name; 363 CMP20TemplateFormatter.addPrivateField( 364 CMP20TemplateFormatter.cmrvformatter.format(twoParams), 365 0, concreteImplWriter); 366 367 oneParam[0] = fieldInfo.name; 368 cmrcleanbodyBuf.append(CMP20TemplateFormatter.cleancmrformatter.format(oneParam)); 369 370 } else { fourParams[0] = otherPC; 372 fourParams[1] = fieldInfo.getter; 373 fourParams[2] = fieldInfo.type; 374 fourParams[3] = otherImpl; 375 gbody = CMP20TemplateFormatter.cmrgformatter.format(fourParams); 376 377 threeParams[0] = otherPC; 378 threeParams[1] = otherImpl; 379 threeParams[2] = fieldInfo.setter; 380 sbody = CMP20TemplateFormatter.cmrsformatter.format(threeParams); 381 382 mformat = CMP20TemplateFormatter.cmrcdformatter; 383 384 } 385 386 if (rel.getDeleteAction() == RelationshipElement.CASCADE_ACTION) { 387 twoParams[0] = fieldInfo.getter; 388 twoParams[1] = otherImpl; 389 cascadeDelete.append(mformat.format(twoParams)); 390 try { 391 rel.setDeleteAction(RelationshipElement.NONE_ACTION); 393 } catch (ModelException me) { 394 logger.log(Logger.SEVERE, I18NHelper.getMessage(messages, 395 "CMG.ModelExceptionOnDeleteAction", me)); } 397 } 398 399 } 400 401 409 private Collection validateEJBQL(AbstractMethodHelper methodHelper) { 410 Collection rc = new ArrayList(); 411 jdoqlElementsMap = new HashMap(); 412 413 List methods = new ArrayList(methodHelper.getFinders()); 414 methods.addAll(methodHelper.getSelectors()); 415 for (int i = 0; i < methods.size(); i++) { 416 Method m = (Method )methods.get(i); 417 String mname = m.getName(); 418 if (mname.equals(CMP20TemplateFormatter.findByPrimaryKey_)) { 419 continue; 421 } 422 423 try { 424 jdoqlElementsMap.put(m, 426 ejbqlc.compile(methodHelper.getQueryString(m), m, 427 methodHelper.getQueryReturnType(m), 428 mname.startsWith(CMP20TemplateFormatter.find_), 429 beanName)); 430 } catch (EJBQLException e) { 431 rc.add(e); 432 } 433 } 434 435 return rc; 436 } 437 438 444 JDOQLElements getJDOQLElements(Method m, 445 AbstractMethodHelper methodHelper) throws IOException { 446 JDOQLElements rs = (JDOQLElements)jdoqlElementsMap.get(m); 449 if (rs == null) { 450 if (logger.isLoggable(Logger.FINE)) { 451 logger.fine("JDOQLElements NOT FOUND for: " + m.getName()); 452 } 453 454 rs = ejbqlc.compile(methodHelper.getQueryString(m), m, 455 methodHelper.getQueryReturnType(m), true, beanName); 456 } 457 458 return rs; 459 } 460 461 463 private void generateSelectors(AbstractMethodHelper methodHelper) throws IOException { 464 List selectors = methodHelper.getSelectors(); 465 boolean debug = logger.isLoggable(Logger.FINE); 466 if (debug) { 467 logger.fine("Selectors: " + selectors.size()); } 469 470 for (int i = 0; i < selectors.size(); i++) { 471 Method m = (Method )selectors.get(i); 472 String mname = m.getName(); 473 474 if (debug) { 475 logger.fine("Selector: " + mname); } 477 478 JDOQLElements rs = (JDOQLElements)jdoqlElementsMap.get(m); 479 if (rs == null) { 480 if (debug) { 481 logger.fine("JDOQLElements NOT FOUND for: " + mname); 482 } 483 484 rs = ejbqlc.compile(methodHelper.getQueryString(m), m, 486 methodHelper.getQueryReturnType(m), false, beanName); 487 } 488 489 String returnType = m.getReturnType().getName(); 490 CMP20TemplateFormatter.addGenericMethod( 491 m, mname, returnType, 492 generateSelectorMethodBody(methodHelper, rs, mname, m, returnType, i), 493 concreteImplWriter); 494 } 495 } 496 497 505 String getEJBCreateMethodBody(String createName, 506 String [] exc, String parametersList, 507 String parametersListWithSeparator) { 508 509 if (!containsException(exc, CMP20TemplateFormatter.CreateException_)) { 512 throw new JDOUserException(I18NHelper.getMessage(messages, 513 "EXC_NoCreateException", createName, abstractBean)); } 515 516 String body = CMPROTemplateFormatter.accessNotAllowedTemplate; 519 if (isUpdateable) { 520 sixParams[0] = pcname; 521 sixParams[1] = createName; 522 sixParams[2] = parametersList; 523 sixParams[4] = concreteImplName; 524 sixParams[5] = parametersListWithSeparator; 525 526 if (pkClass.equals(Object .class.getName())) { 527 sixParams[3] = setPKField; 528 529 body = CMP20TemplateFormatter.cunpkformatter.format(sixParams); 530 } else { 531 sixParams[3] = pkClass; 532 body = CMP20TemplateFormatter.cformatter.format(sixParams); 533 } 534 } 535 536 return body; 537 } 538 539 546 String getEJBPostCreateMethodBody(String postCreateName, 547 String parametersList, String parametersListWithSeparator) { 548 549 String body = CMPTemplateFormatter.none_; 552 553 if (isUpdateable) { 554 twoParams[0] = postCreateName; 555 twoParams[1] = parametersList; 556 557 body = CMP20TemplateFormatter.postcformatter.format(twoParams); 558 } 559 560 return body; 561 } 562 563 566 String getEJBRemoveMethodBody() { 567 String body = CMPROTemplateFormatter.updateNotAllowedTemplate; 570 if (isUpdateable) { 571 if (cascadeDelete.length() > 0) { 573 oneParam[0] = CMP20TemplateFormatter.startCascadeDeleteTemplate + 574 cascadeDelete.append( 575 CMP20TemplateFormatter.endCascadeDeleteTemplate). 576 toString(); 577 } else { 578 oneParam[0] = CMP20TemplateFormatter.none_; 579 } 580 581 body = CMP20TemplateFormatter.rmformatter.format(oneParam); 582 } 583 584 return body; 585 } 586 587 591 void generateKnownMethods(AbstractMethodHelper methodHelper) 592 throws IOException { 593 594 super.generateKnownMethods(methodHelper); 595 596 String [] exc = null; 597 String [] st = CMP20TemplateFormatter.otherPublicMethodsArray; 598 for (int i = 0; i < st.length; i++) { 599 String mname = st[i]; 600 exc = getExceptionList(methodHelper, mname); 601 602 String body = CMPROTemplateFormatter.updateNotAllowedTemplate; 603 if (isUpdateable || mname.equals(CMPTemplateFormatter.ejbLoad_)) { 605 body = CMP20TemplateFormatter.helpers.getProperty(mname); 606 } else if (mname.equals(CMPTemplateFormatter.jdoCleanAllRefs_)) { 607 body = CMPROTemplateFormatter.jdoCleanAllRefsTemplate; 608 } 609 610 concreteImplWriter.addMethod(mname, Modifier.PUBLIC, CMP20TemplateFormatter.void_, null, null, exc, CMP20TemplateFormatter.getBodyAsStrings(body), null); } 619 620 } 621 622 625 void generateHelperClassMethods() throws IOException { 626 627 super.generateHelperClassMethods(); 628 oneParam[0] = CMP20TemplateFormatter.assertInstanceOfLocalInterfaceImplTemplate; 630 631 jdoHelperWriter.addMethod(CMP20TemplateFormatter.assertInstanceOfLocalInterfaceImpl_, Modifier.PUBLIC, CMP20TemplateFormatter.void_, param0, objectType, null, oneParam, null); } 640 641 645 void generateConversions() throws IOException { 646 647 super.generateConversions(); 648 649 if (hasLocalInterface == false) { 651 String [] pcParams = new String [] {CMP20TemplateFormatter.pc_, 652 CMP20TemplateFormatter.jdoPersistenceManager_}; 653 String [] pcParamTypes = new String [] {CMP20TemplateFormatter.Object_, 654 CMP20TemplateFormatter.jdoPersistenceManagerClass_}; 655 656 String [] body = CMP20TemplateFormatter.getBodyAsStrings( 657 CMP20TemplateFormatter.returnNull_); 658 659 jdoHelperWriter.addMethod(CMP20TemplateFormatter.convertPCToEJBLocalObject_, Modifier.PUBLIC, CMP20TemplateFormatter.ejbLocalObject_, pcParams, pcParamTypes, null, body, null); 668 String [] pcParamsX = new String [] {CMP20TemplateFormatter.pc_, 669 CMP20TemplateFormatter.jdoPersistenceManager_, 670 CMP20TemplateFormatter.context_}; 671 String [] pcParamTypesX = new String [] {CMP20TemplateFormatter.Object_, 672 CMP20TemplateFormatter.jdoPersistenceManagerClass_, 673 CMP20TemplateFormatter.ejbContext_}; 674 jdoHelperWriter.addMethod(CMP20TemplateFormatter.convertPCToEJBLocalObject_, Modifier.PUBLIC, CMP20TemplateFormatter.ejbLocalObject_, pcParamsX, pcParamTypesX, null, body, null); 683 684 twoParams[0] = CMP20TemplateFormatter.ejbLocalObject_; 685 twoParams[1] = CMP20TemplateFormatter.jdoPersistenceManagerClass_; 686 jdoHelperWriter.addMethod(CMP20TemplateFormatter.convertEJBLocalObjectToPC_, Modifier.PUBLIC, CMP20TemplateFormatter.Object_, param0PM, twoParams, null, body, null); } 695 } 696 697 711 private String generateSelectorMethodBody(AbstractMethodHelper methodHelper, 712 JDOQLElements jdoqlElements, 713 String mname, 714 Method m, 715 String returnType, 716 int index) throws IOException { 717 718 StringBuffer body = new StringBuffer (); 719 720 oneParam[0] = concreteImplName; 722 body.append(CMP20TemplateFormatter.preselectformatter.format(oneParam)); 723 724 body.append(generateFinderSelectorCommonBody(methodHelper, 726 jdoqlElements, 727 mname, 728 m, 729 returnType, 730 index)); 731 732 if (isSingleObjectSelector(m)) { 735 body.append(generateResultHandlingForSingleSelector( 736 jdoqlElements, mname, m, methodHelper, returnType)); 737 } else { 738 body.append(generateResultHandlingForMultiSelector( 739 jdoqlElements, m, methodHelper)); 740 } 741 742 return body.toString(); 743 } 744 745 746 756 private String generateResultHandlingForMultiSelector( 757 JDOQLElements jdoqlElements, 758 Method m, 759 AbstractMethodHelper methodHelper) { 760 761 boolean convertToSet = false; 762 String body = null; 763 MessageFormat mformat = null; 764 oneParam[0] = m.getName(); 766 767 if (isSelectorReturningSet(m)) convertToSet = true; 770 771 int queryReturnType = methodHelper.getQueryReturnType(m); 772 if ((queryReturnType == AbstractMethodHelper.NO_RETURN) && 773 jdoqlElements.isPCResult()) { 774 queryReturnType = AbstractMethodHelper.LOCAL_RETURN; 778 } 779 780 switch (queryReturnType) { 781 case (AbstractMethodHelper.LOCAL_RETURN): 782 mformat = CMP20TemplateFormatter.multiselectorconvformatter; 783 threeParams[0] = 784 getConcreteBeanForPCClass(jdoqlElements.getResultType()); 785 threeParams[1] = convertToSet ? 786 CMP20TemplateFormatter.convertCollectionPCToEJBLocalObjectSet_ : 787 CMP20TemplateFormatter.convertCollectionPCToEJBLocalObject_; 788 threeParams[2] = CMP20TemplateFormatter.catchClauseTemplate; 789 body = mformat.format(threeParams); 790 break; 791 case (AbstractMethodHelper.REMOTE_RETURN): 792 mformat = CMP20TemplateFormatter.multiselectorconvformatter; 793 threeParams[0] = 794 getConcreteBeanForPCClass(jdoqlElements.getResultType()); 795 threeParams[1] = convertToSet ? 796 CMP20TemplateFormatter.convertCollectionPCToEJBObjectSet_ : 797 CMP20TemplateFormatter.convertCollectionPCToEJBObject_; 798 threeParams[2] = CMP20TemplateFormatter.catchClauseTemplate; 799 body = mformat.format(threeParams); 800 break; 801 case (AbstractMethodHelper.NO_RETURN): 802 default: 803 mformat = convertToSet ? 804 CMP20TemplateFormatter.multiselectorsetformatter : 805 CMP20TemplateFormatter.multiselectorformatter; 806 oneParam[0] = CMP20TemplateFormatter.catchClauseTemplate; 807 body = mformat.format(oneParam); 808 break; 809 } 810 811 return body; 812 } 813 814 827 private String generateResultHandlingForSingleSelector( 828 JDOQLElements jdoqlElements, 829 String mname, 830 Method m, 831 AbstractMethodHelper methodHelper, 832 String returnType) { 833 834 StringBuffer body = new StringBuffer (); 835 MessageFormat mformat = null; 836 String jdoResultType = jdoqlElements.getResultType(); 837 String ejbName = null; 838 if (!jdoqlElements.isAggregate()) { 841 mformat = CMP20TemplateFormatter.singleselectorformatter; 842 oneParam[0] = mname; 843 body.append(mformat.format(oneParam)); 844 } 845 846 oneParam[0] = CMP20TemplateFormatter.none_; 848 849 int queryReturnType = methodHelper.getQueryReturnType(m); 850 if ((queryReturnType == AbstractMethodHelper.NO_RETURN) && 851 jdoqlElements.isPCResult()) { 852 queryReturnType = AbstractMethodHelper.LOCAL_RETURN; 856 } 857 858 switch (queryReturnType) { 860 case (AbstractMethodHelper.LOCAL_RETURN): 861 ejbName = nameMapper.getEjbNameForPersistenceClass(jdoResultType); 862 mformat = CMP20TemplateFormatter.singleselectorreturnconvformatter; 863 fourParams[0] = nameMapper.getLocalInterfaceForEjbName(ejbName); 864 fourParams[1] = nameMapper.getConcreteBeanClassForEjbName(ejbName); 865 fourParams[2] = CMP20TemplateFormatter.convertPCToEJBLocalObject_; 866 fourParams[3] = CMP20TemplateFormatter.catchClauseTemplate; 867 body.append(mformat.format(fourParams)); 868 break; 869 case (AbstractMethodHelper.REMOTE_RETURN): 870 ejbName = nameMapper.getEjbNameForPersistenceClass(jdoResultType); 871 mformat = CMP20TemplateFormatter.singleselectorreturnconvformatter; 872 fourParams[0] = nameMapper.getRemoteInterfaceForEjbName(ejbName); 873 fourParams[1] = nameMapper.getConcreteBeanClassForEjbName(ejbName); 874 fourParams[2] = CMP20TemplateFormatter.convertPCToEJBObject_; 875 fourParams[3] = CMP20TemplateFormatter.catchClauseTemplate; 876 body.append(mformat.format(fourParams)); 877 break; 878 case (AbstractMethodHelper.NO_RETURN): 879 default: 880 Class returnTypeClass = m.getReturnType(); 881 if (jdoqlElements.isAggregate()) { 883 if (returnTypeClass.isPrimitive()) { 884 mformat = CMP20TemplateFormatter.aggregateselectorprimitivereturnformatter; 885 fourParams[0] = mname; 886 fourParams[1] = jdoResultType; 887 fourParams[2] = CMP20TemplateFormatter.dot_ + 888 CMP20TemplateFormatter.getUnwrapMethodName(returnTypeClass); 889 fourParams[3] = CMP20TemplateFormatter.catchClauseTemplate; 890 body.append(mformat.format(fourParams)); 891 } else if (returnTypeClass.getName().equals(jdoResultType)) { 892 mformat = CMP20TemplateFormatter.aggregateselectorreturnformatter; 893 twoParams[0] = jdoResultType; 894 twoParams[1] = CMP20TemplateFormatter.catchClauseTemplate; 895 body.append(mformat.format(twoParams)); 896 } else if (returnTypeClass.isAssignableFrom( 897 java.math.BigDecimal .class)) { 898 mformat = CMP20TemplateFormatter.aggregateselectorreturnbigdecimalconvformatter; 899 twoParams[0] = jdoResultType; 900 twoParams[1] = CMP20TemplateFormatter.catchClauseTemplate; 901 body.append(mformat.format(twoParams)); 902 } else if (returnTypeClass.isAssignableFrom( 903 java.math.BigInteger .class)) { 904 mformat = CMP20TemplateFormatter.aggregateselectorreturnbigintegerconvformatter; 905 twoParams[0] = jdoResultType; 906 twoParams[1] = CMP20TemplateFormatter.catchClauseTemplate; 907 body.append(mformat.format(twoParams)); 908 909 } else { 910 mformat = CMP20TemplateFormatter.aggregateselectorreturnconvformatter; 911 fourParams[0] = returnType; 912 fourParams[1] = jdoResultType; 913 fourParams[2] = CMP20TemplateFormatter.dot_ + 914 CMP20TemplateFormatter.getUnwrapMethodName( 915 CMP20TemplateFormatter.getPrimitiveClass( 916 CMP20TemplateFormatter.getPrimitiveName(returnTypeClass))); 917 fourParams[3] = CMP20TemplateFormatter.catchClauseTemplate; 918 body.append(mformat.format(fourParams)); 919 } 920 } else { 921 mformat = CMP20TemplateFormatter.singleselectorreturnformatter; 928 if (returnTypeClass.isPrimitive()) { 929 threeParams[0] = CMP20TemplateFormatter.getWrapperName(returnType); 930 threeParams[1] = CMP20TemplateFormatter.dot_ + 931 CMP20TemplateFormatter.getUnwrapMethodName(returnTypeClass); 932 threeParams[2] = CMP20TemplateFormatter.catchClauseTemplate; 933 } else { 934 threeParams[0] = returnType; 935 threeParams[1] = CMP20TemplateFormatter.none_; 936 threeParams[2] = CMP20TemplateFormatter.catchClauseTemplate; 937 } 938 body.append(mformat.format(threeParams)); 939 } 940 941 break; 942 } 943 944 return body.toString(); 945 } 946 947 955 String generateFinderSelectorParamCheck(Method m, 956 String [] parameterEjbNames) { 957 StringBuffer checkBody = new StringBuffer (); 958 959 Class [] paramTypes = m.getParameterTypes(); 960 int paramLength = paramTypes.length; 961 String paramClassName = null; 962 for (int i = 0; i < paramLength; i++) { 963 if (parameterEjbNames[i] != null) { 964 paramClassName = paramTypes[i].getName(); 965 String concreteImplName = 966 nameMapper.getConcreteBeanClassForEjbName( 967 parameterEjbNames[i]); 968 twoParams[0] = concreteImplName; 969 twoParams[1] = CMP20TemplateFormatter.param_ + i; 970 971 if (nameMapper.isLocalInterface(paramClassName)) { 972 checkBody.append(CMP20TemplateFormatter.finderselectorchecklocalformatter.format(twoParams)); 973 } else { checkBody.append(CMP20TemplateFormatter.finderselectorcheckremoteformatter.format(twoParams)); 975 } 976 } 977 } 978 979 return checkBody.toString(); 980 } 981 982 988 boolean isFinderReturningEnumeration(Method finder) { 989 return false; 990 } 991 992 997 private boolean isSingleObjectSelector(Method finder) { 998 return (!(finder.getReturnType().equals(java.util.Collection .class) || 999 finder.getReturnType().equals(java.util.Set .class))); 1000 } 1001 1002 1007 private boolean isSelectorReturningSet(Method selector) { 1008 return (selector.getReturnType().equals(java.util.Set .class)); 1009 } 1010 1011 1016 String getSignaturesOfGeneratorClasses() 1017 { 1018 StringBuffer signatures = new StringBuffer (). 1019 1020 append(super.getSignaturesOfGeneratorClasses()). 1022 append(CMPTemplateFormatter.signatureDelimiter_). 1023 1024 append(JDOConcreteBean20Generator.SIGNATURE). 1026 append(CMPTemplateFormatter.signatureDelimiter_). 1027 1028 append(CMP20TemplateFormatter.signature2_0Template). 1030 append(CMPTemplateFormatter.signatureDelimiter_). 1031 1032 append(EJBQLC.SIGNATURE); 1034 1035 return signatures.toString(); 1036 } 1037 1038} 1039 1040 | Popular Tags |