1 18 package org.objectweb.speedo.generation.generator.lib; 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.Comparator ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 import javax.jdo.FetchPlan; 30 31 import org.apache.velocity.VelocityContext; 32 import org.apache.velocity.context.Context; 33 import org.objectweb.asm.Constants; 34 import org.objectweb.asm.Type; 35 import org.objectweb.jorm.generator.lib.CommonHelper; 36 import org.objectweb.jorm.lib.JormPathHelper; 37 import org.objectweb.jorm.metainfo.api.Class; 38 import org.objectweb.jorm.metainfo.api.ClassProject; 39 import org.objectweb.jorm.metainfo.api.ClassRef; 40 import org.objectweb.jorm.metainfo.api.GenClassRef; 41 import org.objectweb.jorm.metainfo.api.Mapping; 42 import org.objectweb.jorm.metainfo.api.NameDef; 43 import org.objectweb.jorm.metainfo.api.Reference; 44 import org.objectweb.jorm.metainfo.api.TypedElement; 45 import org.objectweb.jorm.type.api.PType; 46 import org.objectweb.speedo.api.SpeedoException; 47 import org.objectweb.speedo.api.SpeedoProperties; 48 import org.objectweb.speedo.api.UserFieldMapping; 49 import org.objectweb.speedo.genclass.SupportedGenClass; 50 import org.objectweb.speedo.generation.lib.NamingRules; 51 import org.objectweb.speedo.metadata.SpeedoArray; 52 import org.objectweb.speedo.metadata.SpeedoClass; 53 import org.objectweb.speedo.metadata.SpeedoCollection; 54 import org.objectweb.speedo.metadata.SpeedoExtension; 55 import org.objectweb.speedo.metadata.SpeedoFetchGroup; 56 import org.objectweb.speedo.metadata.SpeedoField; 57 import org.objectweb.speedo.metadata.SpeedoIdentity; 58 import org.objectweb.speedo.metadata.SpeedoMap; 59 import org.objectweb.speedo.metadata.SpeedoNullValue; 60 import org.objectweb.speedo.metadata.SpeedoVersion; 61 import org.objectweb.util.monolog.api.BasicLevel; 62 63 67 public abstract class SpeedoGenerator 68 extends AbstractVelocityGenerator 69 implements SupportedGenClass { 70 71 protected static CommonHelper jormTools = new CommonHelper(); 72 73 74 protected Context getContext(SpeedoClass jdoClass) throws SpeedoException { 75 76 int nbField = jdoClass.computeFieldNumbers(); 77 Context ctx = new VelocityContext(); 79 ctx.put("helper", this); 80 ctx.put("isNotAbstract", new Boolean (!jdoClass.isAbstract)); 81 ctx.put("isAbstract", new Boolean (jdoClass.isAbstract)); 82 ctx.put("withLog", new Boolean (!jdoClass.isAbstract)); 83 ctx.put("package", jdoClass.jdoPackage.name); 84 ctx.put("mapper", scp.mapperName); 85 ctx.put("projectName", scp.projectName); 86 ctx.put("isSerializable", new Boolean (jdoClass.isSerializable)); 87 ctx.put("detachable", new Boolean (jdoClass.isDetachable)); 88 89 ctx.put("baseClassName", jdoClass.name); 91 ctx.put("classNameBinding", NamingRules.bindingName(jdoClass.name)); 92 ctx.put("classNameMapping", NamingRules.mappingName(jdoClass.name)); 93 ctx.put("classNameProxy", NamingRules.proxyName(jdoClass.name)); 94 ctx.put("classNameFields", NamingRules.fieldsName(jdoClass.name)); 95 ctx.put("classNameHome", NamingRules.homeName(jdoClass.name)); 96 ctx.put("classNameKey", NamingRules.keyName(jdoClass.name)); 97 ctx.put("classNameAccessor", NamingRules.accessorName(jdoClass.name)); 98 99 ctx.put("hasSuperclass", Boolean.valueOf(jdoClass.superClassName != null)); 101 ctx.put("superClassName", jdoClass.superClassName); 102 ctx.put("hasSubClasses", Boolean.valueOf( 103 !jdoClass.jormclass.getSubClasses().isEmpty())); 104 105 if (jdoClass.identityType == SpeedoIdentity.CONTAINER_ID) { 107 ctx.put("isContainerId", Boolean.TRUE); 108 ctx.put("isContainerIdValue", "true"); 109 } else { 110 ctx.put("isContainerId", Boolean.FALSE); 111 ctx.put("isContainerIdValue", "false"); 112 } 113 String gcpnamehints = scp.nmf.getNamingManager(jdoClass).getGCPNameHints( 114 jdoClass, getClassNameDef(jdoClass.jormclass)); 115 ctx.put("gcPNameHints", gcpnamehints); 116 117 if(jdoClass.version != null){ 119 ctx.put("versioningStrategy", new Byte (jdoClass.version.strategy)); 120 ctx.put("isDatetime", (jdoClass.version.strategy == SpeedoVersion.DATE_TIME)?Boolean.TRUE:Boolean.FALSE); 121 ctx.put("isVersioned", Boolean.TRUE); 122 ctx.put("versionString", "Speedo" + SpeedoVersion.toString(jdoClass.version.strategy)); 123 } 124 else{ 125 ctx.put("versioningStrategy", new Byte (SpeedoVersion.NO_VERSION)); 126 ctx.put("isVersioned", Boolean.FALSE); 127 } 128 129 List fields = new ArrayList (jdoClass.jdoField.size()); 131 ctx.put("fields", fields); 132 133 List referenceFields = new ArrayList (jdoClass.jdoField.size()); 134 ctx.put("referenceFields", referenceFields); 135 136 List primitiveFields = new ArrayList (jdoClass.jdoField.size()); 137 ctx.put("primitiveFields", primitiveFields); 138 139 List fieldsToSerialize = new ArrayList (jdoClass.jdoField.size()); 140 ctx.put("fieldsToSerialize", fieldsToSerialize); 141 142 StringBuffer maxLongVals = new StringBuffer ("new long[]{"); 143 String sep = ""; 144 int ndlong = (jdoClass.computeFieldNumbers() / 64) + 1; 145 for (int i = 0; i < ndlong; i++) { 146 maxLongVals.append(sep); 147 maxLongVals.append("Long.MAX_VALUE"); 148 sep = ", "; 149 } 150 maxLongVals.append("}"); 151 ctx.put("serializedFieldsId", maxLongVals); 152 ctx.put("declLong", "long[]"); 153 ctx.put("useofLong", "fields"); 154 155 boolean hasRef = false; 156 ctx.put("needSpeedoGenClassListener", new Boolean (false)); 157 158 for (Iterator it = jdoClass.jdoField.values().iterator(); it.hasNext();) { 159 SpeedoField sp = (SpeedoField) it.next(); 160 Field f = new Field(); 161 fields.add(f); 162 if ((sp.access & Constants.ACC_TRANSIENT) == 0 163 && (sp.access & Constants.ACC_STATIC) == 0) { 164 fieldsToSerialize.add(f); 165 } 166 fillFieldInfo(f, sp, nbField, ctx); 167 hasRef = hasRef || !f.isClassical; 168 if (f.isReference) { 169 referenceFields.add(f); 170 } else { 171 primitiveFields.add(f); 172 } 173 } 174 175 List fetchGroups = new ArrayList (jdoClass.jdoFetchGroup.size()); 177 boolean defaultRedefined = false; 178 boolean valuesRedefined = false; 179 ctx.put("fetchGroups", fetchGroups); 180 for (Iterator it = jdoClass.jdoFetchGroup.values().iterator(); it.hasNext();) { 181 SpeedoFetchGroup sfg = (SpeedoFetchGroup) it.next(); 182 if(sfg.name.equals(FetchPlan.DEFAULT)) 183 defaultRedefined = true; 184 else if(sfg.name.equals(FetchPlan.VALUES)) 185 valuesRedefined = true; 186 FetchGroup fg = new FetchGroup(); 187 fetchGroups.add(fg); 188 fillFetchGroupInfo(fg, sfg); 189 } 190 ctx.put("defaultRedefined", new Boolean (defaultRedefined)); 191 ctx.put("valuesRedefined", new Boolean (valuesRedefined)); 192 ctx.put("hasRef", new Boolean (hasRef)); 193 return ctx; 194 } 195 196 public void fillFetchGroupInfo(FetchGroup fg, SpeedoFetchGroup sfg) throws SpeedoException { 197 fg.name = sfg.name; 198 fg.postload = sfg.postLoad; 199 fg.fields = new ArrayList ( sfg.getFields().size()); 201 Iterator it = sfg.getFields().values().iterator(); 202 while(it.hasNext()){ 203 SpeedoField sf = (SpeedoField) it.next(); 204 Field f = new Field(); 205 fg.fields.add(f); 206 fillFieldInfo4FetchGroup(f, sf); 207 } 208 fg.nestedFetchGroups = new ArrayList (sfg.getNestedFetchGroups().size()); 210 Iterator itFG = sfg.getNestedFetchGroups().keySet().iterator(); 211 while(itFG.hasNext()){ 212 fg.nestedFetchGroups.add(itFG.next()); 213 } 214 } 215 216 public void fillFieldInfo4FetchGroup(Field f, SpeedoField sf){ 217 f.name = sf.name; 218 f.depth = sf.depth; 219 f.fetchGroup = sf.fetchGroup; 220 if(f.fetchGroup != null) 221 f.name += SpeedoFetchGroup.FG_SLASH + f.fetchGroup; 222 if(f.depth > 0) 223 f.name += SpeedoFetchGroup.FG_AT + f.depth; 224 } 225 226 public void fillFieldInfo(Field f, 227 SpeedoField sp, 228 int nbField, 229 Context ctx) throws SpeedoException { 230 SpeedoClass jdoClass = sp.jdoClass; 231 f.name = sp.name; 232 TypedElement te = jdoClass.jormclass.getTypedElement(f.name); 233 f.type = sp.type(); 234 f.nameUpperFirst = Character.toUpperCase(f.name.charAt(0)) 235 + f.name.substring(1); 236 f.number = sp.number; 237 f.getter = NamingRules.getterName(sp.jdoClass, sp.name); 238 f.setter = NamingRules.setterName(sp.jdoClass, sp.name); 239 f.isClassical = isClassicalType(sp.type()); 240 f.modifier = sp.modifier(); 241 f.isKey = sp.primaryKey; 242 f.jormmeth = jormTools.upperFL(te.getName()); 243 f.jormfield = te.getName(); 244 f.isNotauthorizedToBeNull = (sp.nullValue == SpeedoNullValue.EXCEPTION); 245 f.declaration = sp.publicSignature(); 246 f.defaultFetchGroup = sp.defaultFetchGroup; 247 String cacheName = sp.getExtensionValueByKey(SpeedoProperties.USER_CACHE); 248 if (cacheName != null) { 249 f.userCacheNames = Collections.singleton(cacheName); 250 } else { 251 f.userCacheNames = Collections.EMPTY_SET; 252 } 253 254 Type fieldType = Type.getReturnType(sp.desc); 256 if (!f.isClassical && fieldType.getSort() == Type.OBJECT) { 257 SpeedoClass jdoclass = scp.smi.getSpeedoClass( 258 fieldType.getClassName(), 259 sp.jdoClass.jdoPackage.jdoXMLDescriptor); 260 if (jdoclass != null) { 261 f.isContainerId = 262 jdoclass.identityType == SpeedoIdentity.CONTAINER_ID; 263 } else { 264 f.isContainerId = true; 265 } 266 f.isArray = false; 267 } else { 268 f.isArray = sp.jdoTuple instanceof SpeedoArray; 269 } 270 271 f.jormMeth = jormTools.upperFL(f.name); 272 273 f.jormFieldIdLongPos = sp.number / 64; 275 f.jormFieldId = 1L << (sp.number % 64); 276 f.jormFielIdDecl = "new long[]{"; 277 String sep = ""; 278 for (int i = 0; i <= (nbField / 64); i++) { 279 f.jormFielIdDecl += sep + (i == f.jormFieldIdLongPos 280 ? f.jormFieldId + "L" : "0L"); 281 sep = ", "; 282 } 283 f.jormFielIdDecl += "}"; 284 285 f.isReference = jormTools.isReference(te); 286 if (f.isReference) { fillReferenceInfo(f, sp, te, ctx, fieldType); 288 } else { f.jormType = te.getType().getJavaName(); 290 f.memoryType = sp.type(); 291 f.jormcast = sp.type(); 292 f.toMemory = "val"; 293 if (te.getType().getTypeCode() == PType.TYPECODE_SERIALIZED) { 294 f.toMemory = "(" + f.memoryType + ")" + f.toMemory; 295 } 296 f.toStorage = f.name; 297 fillUserFieldMappingInfo(f, sp); 298 } 299 300 } 301 302 303 public void fillReferenceInfo(Field f, 304 SpeedoField sp, 305 TypedElement te, 306 Context ctx, 307 Type asmType) throws SpeedoException { 308 f.jormType = "Object"; 309 f.isMultiValued = jormTools.isGenClassRef(te); 310 f.depth = sp.depth; 311 if (f.isMultiValued) { 313 if (sp.jdoTuple instanceof SpeedoCollection) 314 f.jormcast = "java.util.Collection"; 315 else if (sp.jdoTuple instanceof SpeedoMap) 316 f.jormcast = "java.util.Map"; 317 else if (sp.jdoTuple instanceof SpeedoArray) 318 f.jormcast = te.getType().getJormName() + "[]"; 319 else 320 f.jormcast = "Object"; 321 322 String [] s = getCollectionClass(asmType); 323 f.memoryType = s[0]; 324 f.gcproxy = s[1]; 325 f.gcJDKImpl = s[2]; 326 GenClassRef gcr = (GenClassRef) te; 327 if (gcr.isClassRef()) { 328 f.accessorClassName = NamingRules.fieldsName(gcr.getClassRef().getMOClass().getFQName()); 329 } 330 } else { 331 f.jormcast = te.getType().getJormName(); 332 333 f.memoryType = te.getType().getJormName(); 334 f.accessorClassName = NamingRules.fieldsName(f.memoryType); 335 } 336 337 f.linkedField = getLinkedField((Reference) te); 338 SpeedoExtension se = sp.getExtension( 340 SpeedoProperties.VENDOR_NAME, 341 SpeedoProperties.CASCADE_DELETE); 342 f.isCascadeDelete = se != null 343 && ("true".equalsIgnoreCase(se.value) 344 || "yes".equalsIgnoreCase(se.value) 345 || "on".equalsIgnoreCase(se.value) 346 || "oui".equalsIgnoreCase(se.value)); 347 348 fillRelationInfo(f, sp, te, ctx, asmType); 349 } 350 351 public void fillRelationInfo(Field f, 352 SpeedoField sp, 353 TypedElement te, 354 Context ctx, 355 Type asmType) throws SpeedoException { 356 if (sp.relationType == SpeedoField.NO_RELATION) { 357 return; 358 } 359 SpeedoClass jdoClass = sp.jdoClass; 360 SpeedoExtension ext = sp.getExtension(SpeedoProperties.VENDOR_NAME, 361 SpeedoProperties.REVERSE_FIELD); 362 f.reverse = ext.value; 363 f.reverseGetter = NamingRules.getterName(null, ext.value); 364 f.reverseSetter = NamingRules.setterName(null, ext.value); 365 f.coherentSetter = NamingRules.coherentSetterName(sp.jdoClass, sp.name); 366 switch (sp.relationType) { 367 case SpeedoField.ONE_ONE_RELATION: 368 f.is11Relation = true; 369 break; 370 371 case SpeedoField.ONE_MANY_RELATION: 372 f.is1MRelation = true; 373 if (sp.jdoTuple instanceof SpeedoCollection) { 374 f.elemType = (String ) ((SpeedoCollection) sp.jdoTuple).elementType; 375 } else if (sp.jdoTuple instanceof SpeedoMap) { 376 f.elemType = (String ) ((SpeedoMap) sp.jdoTuple).valueType; 377 f.keyField = NamingRules.getterName(null, 378 sp.getExtensionValueByKey(SpeedoProperties.KEY_FIELD)) 379 + "()"; 380 f.isMap = true; 381 } else { 382 throw new SpeedoException( 383 "Unmanaged relation with this multivalued field: " 384 + sp.jdoTuple); 385 } 386 if (f.elemType.indexOf('.') == -1) { 387 f.elemType = jdoClass.jdoPackage.name + '.' + f.elemType; 388 } 389 ctx.put("needSpeedoGenClassListener", new Boolean (true)); 390 break; 391 392 case SpeedoField.MANY_ONE_RELATION: 393 f.isM1Relation = true; 394 SpeedoClass fieldClass = 396 jdoClass.jdoPackage.jdoXMLDescriptor.getSpeedoClass(sp.type(), true); 397 SpeedoField reverseField = (SpeedoField) fieldClass.jdoField.get(ext.value); 399 f.reverseNumber = reverseField.number; 400 if (reverseField.jdoTuple instanceof SpeedoMap) { 401 f.reverseIsMap = true; 402 f.reverseKeyField = NamingRules.getterName(null, 403 reverseField.getExtensionValueByKey(SpeedoProperties.KEY_FIELD)) 404 + "()"; 405 } 406 break; 407 408 case SpeedoField.MANY_MANY_RELATION: 409 f.isMMRelation = true; 410 if (sp.jdoTuple instanceof SpeedoMap) { 411 f.reverseIsMap = true; 412 } 413 f.elemType = (String ) ((SpeedoCollection) sp.jdoTuple).elementType; 414 if (f.elemType.indexOf('.') == -1) { 415 f.elemType = jdoClass.jdoPackage.name + '.' + f.elemType; 416 } 417 SpeedoClass _fieldClass = 419 jdoClass.jdoPackage.jdoXMLDescriptor.getSpeedoClass(f.elemType, true); 420 f.reverseNumber = ((SpeedoField) _fieldClass.jdoField.get(ext.value)).number; 422 ctx.put("needSpeedoGenClassListener", new Boolean (true)); 423 break; 424 } 425 } 426 427 public void fillUserFieldMappingInfo(Field f, SpeedoField sp) 428 throws SpeedoException { 429 SpeedoExtension se = 430 sp.getExtensionByKey(SpeedoProperties.FIELD_CONVERTER); 431 if (se == null) { 432 return; 433 } 434 f.userFieldMapping = se.value; 435 UserFieldMapping ufm = null; 436 try { 437 ufm = (UserFieldMapping) java.lang.Class.forName(se.value) 438 .newInstance(); 439 } catch (Exception e) { 440 throw new SpeedoException( 441 "Impossible to instanciate the UserFieldMapping class '" 442 + se.value + "' for the field '" + sp.name 443 + "' of the class '" + sp.jdoClass.getFQName() + "':", e); 444 } 445 if (ufm.getStorageType().isPrimitive()) { 446 f.toMemory = "new " 447 + getJavaLangType(ufm.getStorageType()) 448 + "(" + f.toMemory + ")"; 449 } 450 451 if (ufm.getMemoryType().isPrimitive()) { 452 f.toStorage = "new " 453 + getJavaLangType(ufm.getMemoryType()) 454 + "(" + f.toStorage + ")"; 455 } 456 457 f.toMemory = f.name + "UFM.toMemory(" + f.toMemory + ")"; 458 f.toStorage = f.name + "UFM.toStorage(" + f.toStorage + ")"; 459 460 if (ufm.getStorageType().isPrimitive()) { 461 f.toStorage = "((" 462 + getJavaLangType(ufm.getStorageType()) 463 + ") " + f.toStorage + ")." 464 + getValueGetter(ufm.getStorageType()) + "()"; 465 } else { 466 f.toStorage = "(" 467 + ufm.getStorageType().getName() 468 + ") " + f.toStorage; 469 } 470 471 if (ufm.getMemoryType().isPrimitive()) { 472 f.toMemory = "((" 473 + getJavaLangType(ufm.getMemoryType()) 474 + ") " + f.toMemory + ")." 475 + getValueGetter(ufm.getMemoryType()) + "()"; 476 } else { 477 f.toMemory = "(" 478 + ufm.getMemoryType().getName() 479 + ") " + f.toMemory; 480 } 481 482 } 483 484 private String getLinkedField(Reference r) { 485 String res = null; 486 if (r instanceof GenClassRef) { 487 res = JormPathHelper.getPath((GenClassRef) r, false); 488 } else if (r instanceof ClassRef) { 489 res = JormPathHelper.getPath((ClassRef) r); 490 } 491 return res; 492 } 493 494 protected String getValueGetter(java.lang.Class c) { 495 return c.getName() + "Value"; 496 } 497 498 public final java.lang.Class [][] PRIMITIVE_TYPES = { 499 {Boolean.TYPE, Boolean .class}, 500 {Byte.TYPE, Byte .class}, 501 {Character.TYPE, Character .class}, 502 {Short.TYPE, Short .class}, 503 {Integer.TYPE, Integer .class}, 504 {Long.TYPE, Long .class}, 505 {Float.TYPE, Float .class}, 506 {Double.TYPE, Double .class} 507 }; 508 509 protected String getJavaLangType(java.lang.Class c) { 510 for (int i = 0; i < PRIMITIVE_TYPES.length; i++) { 511 if (c == PRIMITIVE_TYPES[i][0]) { 512 return PRIMITIVE_TYPES[i][1].getName(); 513 } 514 } 515 return null; 516 } 517 518 protected String [] getCollectionClass(Type fieldtype) { 519 String [] res = new String [3]; 520 res[0] = fieldtype.getClassName(); 521 for (int i = 0; i < GC_IMPL.length && res[1] == null; i++) { 522 if (GC_IMPL[i][0].equals(res[0])) { 523 res[1] = GC_IMPL[i][1]; 524 res[2] = GC_IMPL[i][2]; 525 } 526 } 527 if (res[1] == null) { 528 logger.log(BasicLevel.ERROR, "Type " + res[0] 529 + " is not supported for a persistent field"); 530 } 531 return res; 532 } 533 534 public String getPNameGetter(PType type) { 535 switch (type.getTypeCode()) { 536 case PType.TYPECODE_CHAR: 537 return "pngetCharField"; 538 case PType.TYPECODE_OBJCHAR: 539 return "pngetOcharField"; 540 case PType.TYPECODE_BYTE: 541 return "pngetByteField"; 542 case PType.TYPECODE_OBJBYTE: 543 return "pngetObyteField"; 544 case PType.TYPECODE_SHORT: 545 return "pngetShortField"; 546 case PType.TYPECODE_OBJSHORT: 547 return "pngetOshortField"; 548 case PType.TYPECODE_INT: 549 return "pngetIntField"; 550 case PType.TYPECODE_OBJINT: 551 return "pngetOintField"; 552 case PType.TYPECODE_LONG: 553 return "pngetLongField"; 554 case PType.TYPECODE_OBJLONG: 555 return "pngetOlongField"; 556 case PType.TYPECODE_STRING: 557 return "pngetStringField"; 558 case PType.TYPECODE_DATE: 559 return "pngetDateField"; 560 case PType.TYPECODE_CHARARRAY: 561 return "pngetCharArrayField"; 562 case PType.TYPECODE_BYTEARRAY: 563 return "pngetByteArrayField"; 564 default : 565 return null; 566 } 567 } 568 569 protected Mapping getMapping(Class clazz) throws SpeedoException { 570 ClassProject cp = clazz.getClassProject(scp.projectName); 571 if (cp == null) { 572 throw new SpeedoException("No classproject found for the class " 573 + clazz.getFQName() + " and the project " + scp.projectName); 574 } 575 int idx = scp.mapperName.indexOf('.'); 576 Mapping m = cp.getMapping(idx == -1 577 ? scp.mapperName 578 : scp.mapperName.substring(0, idx)); 579 if (m == null) { 580 throw new SpeedoException("No mapping found for the class " 581 + clazz.getFQName() + ", the project " + scp.projectName 582 + " and the mapper " + scp.mapperName); 583 } 584 return m; 585 } 586 587 protected NameDef getClassNameDef(Class clazz) throws SpeedoException { 588 return getMapping(clazz).getClassMapping() 589 .getIdentifierMapping().getNameDef(); 590 } 591 592 protected Map computeUserCaches(SpeedoClass sc) { 593 Map userCaches = new HashMap (); 594 computeUserCaches(sc, userCaches, true); 595 for (Iterator iter = userCaches.values().iterator(); iter.hasNext();) { 596 List element = (List ) iter.next(); 597 Collections.sort(element, new Comparator () { 598 public int compare(Object o1, Object o2) { 599 return ((SpeedoField) o1).name.compareTo(((SpeedoField) o2).name); 600 } 601 }); 602 } 603 return userCaches; 604 } 605 606 protected void computeUserCaches(SpeedoClass sc, Map userCaches, boolean addNew) { 607 for(Iterator it = sc.jdoField.values().iterator(); it.hasNext();) { 608 SpeedoField sf = (SpeedoField) it.next(); 609 String cacheName = sf.getExtensionValueByKey(SpeedoProperties.USER_CACHE); 610 if (cacheName == null) { 611 continue; 612 } 613 List sfs = (List ) userCaches.get(cacheName); 614 if (sfs == null) { 615 if (!addNew) { 616 continue; 617 } 618 sfs = new ArrayList (); 619 userCaches.put(cacheName, sfs); 620 } 621 sfs.add(sf); 622 } 623 if (sc.superClassName != null && sc.superClassName.length() > 0) { 624 computeUserCaches(sc.getSuper(), userCaches, true); 625 } 626 } 627 628 public class Field { 629 protected String name; 630 public String nameUpperFirst; 631 public long number; 632 public String getter; 633 public String setter; 634 public String coherentSetter; 635 public String reverse; 636 public int reverseNumber; 637 public String reverseGetter; 638 public String reverseSetter; 639 public String modifier; 640 public boolean isClassical; 641 public boolean isContainerId; 642 public boolean isArray; 643 public String declaration; 644 public boolean isKey; 645 public String jormMeth; 646 public int jormFieldIdLongPos; 647 public long jormFieldId; 648 public String jormFielIdDecl; 649 public String jormType; 650 public String linkedField; 651 public String memoryType; 652 public String elemType; 653 public boolean isMultiValued = false; 654 public boolean isReference = false; 655 public boolean is11Relation = false; 656 public boolean is1MRelation = false; 657 public boolean isM1Relation = false; 658 public boolean isMMRelation = false; 659 public boolean isMap; 660 public boolean reverseIsMap; 661 public String reverseKeyField; 662 public String keyField; 663 public String toMemory = null; 664 public String toStorage = null; 665 public String userFieldMapping = null; 666 public boolean isCascadeDelete = false; 667 public int depth; 668 public String fetchGroup; 669 public boolean defaultFetchGroup; 670 671 protected String jormfield; 672 protected String jormcast; 673 protected String jormmeth; 674 protected String type; 675 protected boolean isNotauthorizedToBeNull = false; 676 679 public String gcproxy; 680 public String gcJDKImpl; 681 682 public String accessorClassName; 683 684 687 public Collection userCacheNames; 688 689 public String getNameUpperFirst() { 690 return nameUpperFirst; 691 } 692 693 public void setNameUpperFirst(String nameUpperFirst) { 694 this.nameUpperFirst = nameUpperFirst; 695 } 696 697 public boolean getIsReference() { 698 return isReference; 699 } 700 701 public int getJormFieldIdLongPos() { 702 return jormFieldIdLongPos; 703 } 704 705 public String getGcproxy() { 706 return gcproxy; 707 } 708 709 public String getGcJDKImpl() { 710 return gcJDKImpl; 711 } 712 713 public String getName() { 714 return name; 715 } 716 717 public long getNumber() { 718 return number; 719 } 720 721 public String getGetter() { 722 return getter; 723 } 724 725 public String getSetter() { 726 return setter; 727 } 728 729 public String getModifier() { 730 return modifier; 731 } 732 733 public boolean isClassical() { 734 return isClassical; 735 } 736 737 public boolean isContainerId() { 738 return isContainerId; 739 } 740 741 public boolean isArray() { 742 return isArray; 743 } 744 745 public boolean getIsRelation() { 746 return is11Relation || is1MRelation || isM1Relation || isMMRelation; 747 } 748 749 public boolean getIs11Relation() { 750 return is11Relation; 751 } 752 753 public boolean getIs1MRelation() { 754 return is1MRelation; 755 } 756 757 public boolean getIsM1Relation() { 758 return isM1Relation; 759 } 760 761 public boolean getIsMMRelation() { 762 return isMMRelation; 763 } 764 765 public boolean getIsxMRelation() { 766 return is1MRelation || isMMRelation; 767 } 768 769 public boolean getIsMap() { 770 return isMap; 771 } 772 773 public boolean getReverseIsMap() { 774 return reverseIsMap; 775 } 776 777 public boolean getDefaultFetchGroup(){ 778 return defaultFetchGroup; 779 } 780 781 public String getReverseKeyField() { 782 return reverseKeyField; 783 } 784 785 public String getReverse() { 786 return reverse; 787 } 788 789 public boolean getIsCascadeDelete() { 790 return isCascadeDelete; 791 } 792 793 public int getReverseNumber() { 794 return reverseNumber; 795 } 796 797 public String getReverseGetter() { 798 return reverseGetter; 799 } 800 801 public String getReverseSetter() { 802 return reverseSetter; 803 } 804 805 public String getCoherentSetter() { 806 return coherentSetter; 807 } 808 809 public String getDeclaration() { 810 return declaration; 811 } 812 813 public boolean isKey() { 814 return isKey; 815 } 816 817 public String getJormMeth() { 818 return jormMeth; 819 } 820 821 public long getJormFieldId() { 822 return jormFieldId; 823 } 824 825 public String getJormType() { 826 return jormType; 827 } 828 829 public String getLinkedField() { 830 return linkedField; 831 } 832 833 public String getMemoryType() { 834 return memoryType; 835 } 836 837 public String getElemType() { 838 return elemType; 839 } 840 841 public boolean getIsMultiValued() { 842 return isMultiValued; 843 } 844 845 public String getJormFielIdDecl() { 846 return jormFielIdDecl; 847 } 848 849 public String getToMemory() { 850 return toMemory; 851 } 852 853 public String getToStorage() { 854 return toStorage; 855 } 856 857 public String getUserFieldMapping() { 858 return userFieldMapping; 859 } 860 861 public String getJormfield() { 862 return jormfield; 863 } 864 865 public String getJormcast() { 866 return jormcast; 867 } 868 869 public String getJormmeth() { 870 return jormmeth; 871 } 872 873 public String getType() { 874 return type; 875 } 876 877 public boolean getIsNotauthorizedToBeNull() { 878 return isNotauthorizedToBeNull; 879 } 880 881 public String getKeyField() { 882 return keyField; 883 } 884 885 public int getDepth() { 886 return depth; 887 } 888 889 public String getFetchGroup() { 890 return fetchGroup; 891 } 892 893 894 public String getAccessorClassName() { 895 return accessorClassName; 896 } 897 898 public Collection getUserCacheNames() { 899 return userCacheNames; 900 } 901 } 902 903 public class FetchGroup{ 904 public String name; 905 public boolean postload; 906 907 910 public List nestedFetchGroups; 911 912 public List fields; 913 914 public List getFields() { 915 return fields; 916 } 917 918 public String getName() { 919 return name; 920 } 921 922 public List getNestedFetchGroups() { 923 return nestedFetchGroups; 924 } 925 926 public boolean isPostload() { 927 return postload; 928 } 929 930 } 931 932 } 933 | Popular Tags |