1 2 12 package com.versant.core.metadata.generator; 13 14 import com.versant.core.metadata.*; 15 import com.versant.core.common.*; 16 import com.versant.core.compiler.ClassSpec; 17 import com.versant.core.jdo.VersantPersistenceManagerImp; 18 import com.versant.core.jdo.PCStateMan; 19 import com.versant.core.jdo.VersantStateManager; 20 import com.versant.core.server.OIDGraph; 21 import com.versant.core.util.IntArray; 22 import com.versant.core.util.OIDObjectOutput; 23 import com.versant.core.util.OIDObjectInput; 24 25 import javax.jdo.JDOFatalInternalException; 26 import javax.jdo.spi.PersistenceCapable; 27 import java.util.*; 28 import java.math.BigDecimal ; 29 import java.io.*; 30 31 34 public abstract class StateSrcGenerator { 35 36 protected ClassMetaData cmd; 37 protected String className; 38 protected ArrayList imutableTypeList; 39 protected ArrayList nonObjectClassTypeList; 40 protected ArrayList realNonObjectClassTypeList; 41 protected HashMap getFieldToClass; 42 protected HashMap classToSetField; 43 protected HashMap classToGetFieldAbs; 44 protected HashMap classToSetFieldAbs; 45 protected HashMap classToInternalSetField; 46 protected HashMap classToInternalSetFieldAbs; 47 protected HashMap typeToResultSetGetField; 48 protected HashMap typeToPreparedStatementSetField; 49 protected HashMap wrapperTypesToPrimative; 50 protected HashMap primativeTypesToWrapper; 51 protected HashMap wrapperTypesToValue; 52 protected HashMap wrapperStringToValue; 53 protected HashMap primClassToSerReadMethod; 54 protected HashMap primClassToSerWriteMethod; 55 56 protected static final String CLASS_META_DATA_CLASS = ClassMetaData.class.getName(); 57 protected static final String FIELD_META_DATA_CLASS = FieldMetaData.class.getName(); 58 protected static final String OID_SUPER_CLASS = OID.class.getName(); 59 protected static final String STATE_SUPER_CLASS = State.class.getName(); 60 protected static final String INT_ARRAY = IntArray.class.getName(); 61 62 protected ClassSpec spec; 63 64 66 67 protected final String FIELD_NOT_FOUND_EXCEPTION = "javax.jdo.JDOFatalInternalException"; 68 protected final String FILLED_FIELD_NAME = "filled"; 69 protected final String DIRTY_FIELD_NAME = "dirtyFields"; 70 protected final String RESOLVED_NAME = "resolved"; 71 public static final String JDBC_CONVERTER_FIELD_PREFIX = "jdbcConverter_"; 72 public static final String SCHEMA_FIELD_PREFIX = "schemaField_"; 73 public static final String VDS_FIELD_PREFIX = "vdsField_"; 74 75 protected int totalNoOfFields; 76 77 public StateSrcGenerator() { 78 typeToResultSetGetField = new HashMap(); 79 typeToResultSetGetField.put(int.class, "getInt"); 80 typeToResultSetGetField.put(byte.class, "getByte"); 81 typeToResultSetGetField.put(short.class, "getShort"); 82 typeToResultSetGetField.put(float.class, "getFloat"); 83 typeToResultSetGetField.put(double.class, "getDouble"); 84 typeToResultSetGetField.put(long.class, "getLong"); 85 typeToResultSetGetField.put(boolean.class, "getBoolean"); 86 typeToResultSetGetField.put(String .class, "getString"); 87 typeToResultSetGetField.put(byte[].class, "getBytes"); 88 typeToResultSetGetField.put(java.math.BigDecimal .class,"getBigDecimal"); 95 typeToPreparedStatementSetField = new HashMap(); 96 typeToPreparedStatementSetField.put(int.class, "setInt"); 97 typeToPreparedStatementSetField.put(byte.class, "setByte"); 98 typeToPreparedStatementSetField.put(short.class, "setShort"); 99 typeToPreparedStatementSetField.put(float.class, "setFloat"); 100 typeToPreparedStatementSetField.put(double.class, "setDouble"); 101 typeToPreparedStatementSetField.put(long.class, "setLong"); 102 typeToPreparedStatementSetField.put(boolean.class, "setBoolean"); 103 typeToPreparedStatementSetField.put(String .class, "setString"); 104 typeToPreparedStatementSetField.put(Object .class, "setObject"); 105 typeToPreparedStatementSetField.put(byte[].class,"setBytes"); 106 typeToPreparedStatementSetField.put(BigDecimal .class, "setBigDecimal"); 107 113 114 115 getFieldToClass = new HashMap(); 116 getFieldToClass.put("getIntField", int.class); 117 getFieldToClass.put("getByteField", byte.class); 118 getFieldToClass.put("getCharField", char.class); 119 getFieldToClass.put("getShortField", short.class); 120 getFieldToClass.put("getFloatField", float.class); 121 getFieldToClass.put("getDoubleField", double.class); 122 getFieldToClass.put("getLongField", long.class); 123 getFieldToClass.put("getLongFieldInternal", long.class); 124 getFieldToClass.put("getBooleanField", boolean.class); 125 getFieldToClass.put("getStringField", String .class); 126 127 classToSetField = new HashMap(); 128 classToSetField.put(int.class, "setIntField"); 129 classToSetField.put(byte.class, "setByteField"); 130 classToSetField.put(long.class, "setLongField"); 131 classToSetField.put(char.class, "setCharField"); 132 classToSetField.put(short.class, "setShortField"); 133 classToSetField.put(float.class, "setFloatField"); 134 classToSetField.put(double.class, "setDoubleField"); 135 classToSetField.put(boolean.class, "setBooleanField"); 136 classToSetField.put(String .class, "setStringField"); 137 138 classToGetFieldAbs = new HashMap(); 139 classToGetFieldAbs.put(int.class, "getIntFieldAbs"); 140 classToGetFieldAbs.put(byte.class, "getByteFieldAbs"); 141 classToGetFieldAbs.put(char.class, "getCharFieldAbs"); 142 classToGetFieldAbs.put(short.class, "getShortFieldAbs"); 143 classToGetFieldAbs.put(float.class, "getFloatFieldAbs"); 144 classToGetFieldAbs.put(double.class, "getDoubleFieldAbs"); 145 classToGetFieldAbs.put(long.class, "getLongFieldAbs"); 146 classToGetFieldAbs.put(boolean.class, "getBooleanFieldAbs"); 147 classToGetFieldAbs.put(String .class, "getStringFieldAbs"); 148 149 classToSetFieldAbs = new HashMap(); 150 classToSetFieldAbs.put(int.class, "setIntFieldAbs"); 151 classToSetFieldAbs.put(byte.class, "setByteFieldAbs"); 152 classToSetFieldAbs.put(long.class, "setLongFieldAbs"); 153 classToSetFieldAbs.put(char.class, "setCharFieldAbs"); 154 classToSetFieldAbs.put(short.class, "setShortFieldAbs"); 155 classToSetFieldAbs.put(float.class, "setFloatFieldAbs"); 156 classToSetFieldAbs.put(double.class, "setDoubleFieldAbs"); 157 classToSetFieldAbs.put(boolean.class, "setBooleanFieldAbs"); 158 classToSetFieldAbs.put(String .class, "setStringFieldAbs"); 159 160 classToInternalSetField = new HashMap(); 161 classToInternalSetField.put(int.class, "setInternalIntField"); 162 classToInternalSetField.put(byte.class, "setInternalByteField"); 163 classToInternalSetField.put(long.class, "setInternalLongField"); 164 classToInternalSetField.put(char.class, "setInternalCharField"); 165 classToInternalSetField.put(short.class, "setInternalShortField"); 166 classToInternalSetField.put(float.class, "setInternalFloatField"); 167 classToInternalSetField.put(double.class, "setInternalDoubleField"); 168 classToInternalSetField.put(String .class, "setInternalStringField"); 169 classToInternalSetField.put(boolean.class, "setInternalBooleanField"); 170 171 classToInternalSetFieldAbs = new HashMap(); 172 classToInternalSetFieldAbs.put(int.class, "setInternalIntFieldAbs"); 173 classToInternalSetFieldAbs.put(byte.class, "setInternalByteFieldAbs"); 174 classToInternalSetFieldAbs.put(long.class, "setInternalLongFieldAbs"); 175 classToInternalSetFieldAbs.put(char.class, "setInternalCharFieldAbs"); 176 classToInternalSetFieldAbs.put(short.class, "setInternalShortFieldAbs"); 177 classToInternalSetFieldAbs.put(float.class, "setInternalFloatFieldAbs"); 178 classToInternalSetFieldAbs.put(double.class, 179 "setInternalDoubleFieldAbs"); 180 classToInternalSetFieldAbs.put(String .class, 181 "setInternalStringFieldAbs"); 182 classToInternalSetFieldAbs.put(boolean.class, 183 "setInternalBooleanFieldAbs"); 184 185 186 wrapperTypesToPrimative = new HashMap(8); 187 wrapperTypesToPrimative.put(Integer .class, Integer.TYPE); 188 wrapperTypesToPrimative.put(Byte .class, Byte.TYPE); 189 wrapperTypesToPrimative.put(Short .class, Short.TYPE); 190 wrapperTypesToPrimative.put(Float .class, Float.TYPE); 191 wrapperTypesToPrimative.put(Double .class, Double.TYPE); 192 wrapperTypesToPrimative.put(Long .class, Long.TYPE); 193 wrapperTypesToPrimative.put(Boolean .class, Boolean.TYPE); 194 wrapperTypesToPrimative.put(Character .class, Character.TYPE); 195 196 primativeTypesToWrapper = new HashMap(8); 197 primativeTypesToWrapper.put(Integer.TYPE, "Integer"); 198 primativeTypesToWrapper.put(Byte.TYPE, "Byte"); 199 primativeTypesToWrapper.put(Character.TYPE, "Character"); 200 primativeTypesToWrapper.put(Short.TYPE, "Short"); 201 primativeTypesToWrapper.put(Float.TYPE, "Float"); 202 primativeTypesToWrapper.put(Double.TYPE, "Double"); 203 primativeTypesToWrapper.put(Long.TYPE, "Long"); 204 primativeTypesToWrapper.put(Boolean.TYPE, "Boolean"); 205 206 wrapperTypesToValue = new HashMap(8); 207 wrapperTypesToValue.put(Integer .class, "intValue"); 208 wrapperTypesToValue.put(Byte .class, "byteValue"); 209 wrapperTypesToValue.put(Character .class, "charValue"); 210 wrapperTypesToValue.put(Short .class, "shortValue"); 211 wrapperTypesToValue.put(Float .class, "floatValue"); 212 wrapperTypesToValue.put(Double .class, "doubleValue"); 213 wrapperTypesToValue.put(Long .class, "longValue"); 214 wrapperTypesToValue.put(Boolean .class, "booleanValue"); 215 216 wrapperStringToValue = new HashMap(8); 217 wrapperStringToValue.put("Integer", "intValue"); 218 wrapperStringToValue.put("Byte", "byteValue"); 219 wrapperStringToValue.put("Character", "charValue"); 220 wrapperStringToValue.put("Short", "shortValue"); 221 wrapperStringToValue.put("Float", "floatValue"); 222 wrapperStringToValue.put("Double", "doubleValue"); 223 wrapperStringToValue.put("Long", "longValue"); 224 wrapperStringToValue.put("Boolean", "booleanValue"); 225 226 nonObjectClassTypeList = new ArrayList(); 227 nonObjectClassTypeList.add(int.class); 228 nonObjectClassTypeList.add(byte.class); 229 nonObjectClassTypeList.add(long.class); 230 nonObjectClassTypeList.add(char.class); 231 nonObjectClassTypeList.add(short.class); 232 nonObjectClassTypeList.add(float.class); 233 nonObjectClassTypeList.add(double.class); 234 nonObjectClassTypeList.add(boolean.class); 235 nonObjectClassTypeList.add(String .class); 236 237 realNonObjectClassTypeList = new ArrayList(); 238 realNonObjectClassTypeList.add(int.class); 239 realNonObjectClassTypeList.add(byte.class); 240 realNonObjectClassTypeList.add(long.class); 241 realNonObjectClassTypeList.add(char.class); 242 realNonObjectClassTypeList.add(short.class); 243 realNonObjectClassTypeList.add(float.class); 244 realNonObjectClassTypeList.add(double.class); 245 realNonObjectClassTypeList.add(boolean.class); 246 247 primClassToSerReadMethod = new HashMap(8); 248 primClassToSerReadMethod.put(int.class, "readInt"); 249 primClassToSerReadMethod.put(byte.class, "readByte"); 250 primClassToSerReadMethod.put(char.class, "readChar"); 251 primClassToSerReadMethod.put(short.class, "readShort"); 252 primClassToSerReadMethod.put(float.class, "readFloat"); 253 primClassToSerReadMethod.put(double.class, "readDouble"); 254 primClassToSerReadMethod.put(long.class, "readLong"); 255 primClassToSerReadMethod.put(boolean.class, "readBoolean"); 256 257 primClassToSerWriteMethod = new HashMap(8); 258 primClassToSerWriteMethod.put(int.class, "writeInt"); 259 primClassToSerWriteMethod.put(byte.class, "writeByte"); 260 primClassToSerWriteMethod.put(char.class, "writeChar"); 261 primClassToSerWriteMethod.put(short.class, "writeShort"); 262 primClassToSerWriteMethod.put(float.class, "writeFloat"); 263 primClassToSerWriteMethod.put(double.class, "writeDouble"); 264 primClassToSerWriteMethod.put(long.class, "writeLong"); 265 primClassToSerWriteMethod.put(boolean.class, "writeBoolean"); 266 267 imutableTypeList = new ArrayList(); 268 imutableTypeList.add(java.util.Locale .class); 269 imutableTypeList.add(java.math.BigDecimal .class); 270 imutableTypeList.add(java.math.BigInteger .class); 271 imutableTypeList.add(Integer .class); 272 imutableTypeList.add(Byte .class); 273 imutableTypeList.add(Character .class); 274 imutableTypeList.add(Short .class); 275 imutableTypeList.add(Float .class); 276 imutableTypeList.add(Double .class); 277 imutableTypeList.add(Long .class); 278 imutableTypeList.add(Boolean .class); 279 imutableTypeList.add(String .class); 280 281 } 282 283 286 public ClassSpec generateState(ClassMetaData cmd) { 287 288 this.cmd = cmd; 289 this.className = cmd.stateClassName; 290 this.totalNoOfFields = cmd.stateFields.length; 291 spec = new ClassSpec(null, className, State.class.getName()); 292 293 spec.addImportsForJavaLang(); 294 spec.addImport(OID.class.getName()); 295 spec.addImport(State.class.getName()); 296 spec.addImport(ClassMetaData.class.getName()); 297 spec.addImport(FieldMetaData.class.getName()); 298 spec.addImport(ModelMetaData.class.getName()); 299 spec.addImport(ObjectOutput.class.getName()); 300 spec.addImport(ObjectInput.class.getName()); 301 spec.addImport(DataInputStream.class.getName()); 302 spec.addImport(DataOutputStream.class.getName()); 303 spec.addImport(IOException.class.getName()); 304 spec.addImport(JDOFatalInternalException.class.getName()); 305 spec.addImport(VersantPersistenceManagerImp.class.getName()); 306 spec.addImport(PersistenceCapable.class.getName()); 307 spec.addImport(FetchGroup.class.getName()); 308 spec.addImport(OIDGraph.class.getName()); 309 spec.addImport(StateUtil.class.getName()); 310 spec.addImport(PCStateMan.class.getName()); 311 spec.addImport(SerUtils.class.getName()); 312 spec.addImport(OIDObjectOutput.class.getName()); 313 spec.addImport(OIDObjectInput.class.getName()); 314 spec.addImport(Utils.class.getName()); 315 spec.addImport(PersistenceContext.class.getName()); 316 spec.addImport(VersantStateManager.class.getName()); 317 318 addFields(); 319 addInitStatics(); 320 321 addConstructor(); addSetClassMetaData(); addNewInstance(); 325 addAllGetXXXFields(); addAllSetInternalXXXFields(); addAllSetXXXFields(); addAllGetXXXFieldsAbs(); addAllSetInternalXXXFieldsAbs(); addAllSetXXXFieldsAbs(); addHasSameFields(); addCopyFields(); addClear(); addMakeDirty(); addSetFilled(); 336 addIsDirtyInt(); addGetClassIndex(); addHashCode(); addEqualsObject(); addContainsField(); addMakeClean(); addClearNonFilled(); addUpdateNonFilled(); addGetCopy(); addGetFieldNos(); addContainsApplicationIdentityFields(); addGetInternalObjectField(); addGetInternalObjectFieldAbs(); addIsNull(); addHasSameNullFields(); addFindDirectEdges(); addReplaceNewObjectOIDs(); addIsDirty(); addIsHollow(); addUpdateFrom(); addGetPass1FieldNos(); addGetPass2FieldNos(); addContainsPass1Fields(); addGetPass1FieldRefFieldNosWithNewOids(); 360 addContainsPass2Fields(); addIsEmpty(); addContainFields(); addGetClassMetaData(); addGetClassMetaDataJMD(); addCompareToPass1(); addClearTransactionNonPersistentFields(); addToString(); addClearCollectionFields(); addContainsFetchGroup(); addReplaceSCOFields(); addClearApplicationIdentityFields(); 372 addCopyKeyFieldsFromOID(); 373 addCheckKeyFields(); 374 addCopyKeyFieldsUpdate(); 375 addClearSCOFields(); 376 addGetNullFields(); 377 addContainsFieldAbs(); 378 addMakeDirtyAbs(); 379 addContainFieldsAbs(); 380 addGetResolvableObjectFieldAbs(); 381 addClearNonAutoSetFields(); 382 addUpdateAutoSetFieldsCreated(); 383 addUpdateAutoSetFieldsModified(); 384 addGetResolvableObjectField(); addAddRefs(); addWriteExternal(); 387 addReadExternal(); 388 389 addCopyOptimisticLockingField(); 390 addCopyFieldsForOptimisticLocking(); 391 addGetDirtyState(); addRetrieve(); 393 addClearDirtyFields(); 394 addPrepare(); addContainsValidAppIdFields(); 396 addUnmanageSCOFields(); 397 addVersion(); 398 addIsResolvedForClient(); 399 addGetOptimisticLockingValue(); 400 addOneToManyInverseFieldsForL2Evict(); 401 402 addClearFilledFlags(); 403 addFillForRead(); 404 addIsFieldNullorZero(); 405 406 return spec; 407 } 408 409 413 protected void addInitStatics() { 414 StringBuffer buf = new StringBuffer (); 415 buf.append("\tpublic static boolean initStatics(ModelMetaData jmd) {\n"); 416 addInitStaticsBody(buf); 417 buf.append("\t\treturn true;\n"); 418 buf.append("\t}"); 419 spec.addMethod(buf.toString()); 420 } 421 422 protected void addInitStaticsBody(StringBuffer buf) { 423 buf.append("\t\tif (cmd != null) return false;\n"); 424 buf.append("\t\tcmd = jmd.classes[" + cmd.index + "];\n"); 425 } 426 427 protected void addOneToManyInverseFieldsForL2Evict() { 428 434 StringBuffer buf = new StringBuffer (); 435 buf.append("\n\tpublic final void addOneToManyInverseFieldsForL2Evict(VersantPersistenceManagerImp pm) {\n"); 436 int num = cmd.stateFields.length; 437 for (int i = 0; i < num; i++) { 438 FieldMetaData fmd = cmd.stateFields[i]; 439 if (fmd.isDetail && !fmd.managed) { 440 int fieldNo = fmd.stateFieldNo; 441 buf.append("\t\tif (_"+ fieldNo +" != null) {\n"); 442 buf.append("\t\t\tpm.evictFromL2CacheAfterCommitImp(_" + fieldNo + ");\n"); 443 buf.append("\t\t}\n"); 444 } 445 } 446 buf.append("\t}\n"); 447 spec.addMethod(buf.toString()); 448 } 449 450 protected void addFillForRead() { 451 StringBuffer buf = new StringBuffer (); 452 467 buf.append("\n\tpublic final void fillForRead(State dest, VersantPersistenceManagerImp pm) {\n"); 468 if (cmd.storeAllFields) { 469 buf.append("\t\t"+ className +" state = ("+ className +")dest;\n"); 470 471 boolean haveOID = false; 472 int num = cmd.stateFields.length; 473 for (int i = 0; i < num; i++) { 474 FieldMetaData fmd = cmd.stateFields[i]; 475 if (fmd.category == MDStatics.CATEGORY_REF || 476 fmd.category == MDStatics.CATEGORY_POLYREF) { 477 haveOID = true; 478 } 479 } 480 if (haveOID) { 481 buf.append("\t\tPersistenceCapable pc = null;\n"); 482 } 483 for (int i = 0; i < num; i++) { 484 FieldMetaData fmd = cmd.stateFields[i]; 485 int fieldNum = fmd.stateFieldNo; 486 if (fmd.fake) { 487 buf.append("\t\tstate._"+ fieldNum +" = _"+ fieldNum +";\n"); 488 } else { 489 int cat = fmd.category; 490 if (cat == MDStatics.CATEGORY_REF 491 || cat == MDStatics.CATEGORY_POLYREF) { 492 buf.append("\t\tif (_"+ fieldNum +" instanceof PersistenceCapable) {\n"); 493 buf.append("\t\t\tpc = (PersistenceCapable)_" + fieldNum + ";\n"); 494 buf.append("\t\t\tif (pc.jdoGetPersistenceManager() != null) {\n"); 495 buf.append("\t\t\t\tstate._" + fieldNum + " = StateUtil.getPValueForRef(pc, pm);\n"); 496 buf.append("\t\t\t}\n"); 497 buf.append("\t\t} else {\n"); 498 buf.append("\t\t\tstate._" + fieldNum + " = _" + fieldNum + ";\n"); 499 buf.append("\t\t}\n"); 500 } 501 } 502 } 503 boolean doMask = false; 504 int[] masks = new int[getNumOfControlFields()]; 505 for (int i = 0; i < num; i++) { 506 507 if (cmd.stateFields[i].fake || 508 cmd.stateFields[i].category == MDStatics.CATEGORY_REF || 509 cmd.stateFields[i].category == MDStatics.CATEGORY_POLYREF) { 510 int fieldNum = cmd.stateFields[i].stateFieldNo; 511 doMask = true; 512 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 513 } 514 } 515 if (doMask) { 516 for (int i = 0; i < masks.length; i++) { 517 if (masks[i] != 0){ 518 buf.append("\t\tstate.filled"+i+" |= "+ masks[i] +";\n"); 519 } 520 } 521 } 522 } 523 buf.append("\t}\n"); 524 spec.addMethod(buf.toString()); 525 } 526 527 protected void addGetOptimisticLockingValue() { 528 StringBuffer buf = new StringBuffer (); 529 buf.append("\n\tpublic final Object getOptimisticLockingValue() {\n"); 533 if (cmd.optimisticLockingField != null) { 534 FieldMetaData fmd = cmd.optimisticLockingField; 535 switch (fmd.typeCode) { 536 case MDStatics.DATE: 537 buf.append("\t\treturn _" + fmd.stateFieldNo + ";\n"); 538 break; 539 case MDStatics.LONG: 540 buf.append("\t\treturn new Long(_" + fmd.stateFieldNo + ");\n"); 541 break; 542 case MDStatics.INT: 543 buf.append("\t\treturn new Integer(_" + fmd.stateFieldNo + ");\n"); 544 break; 545 case MDStatics.SHORT: 546 buf.append("\t\treturn new Short(_"+ fmd.stateFieldNo +");\n"); 547 break; 548 case MDStatics.BYTE: 549 buf.append("\t\treturn new Byte(_" + fmd.stateFieldNo + ");\n"); 550 break; 551 default: 552 throw BindingSupportImpl.getInstance().internal("Invalid typeCode " + fmd.typeCode + 553 " for version field: stateFieldNo " + fmd.stateFieldNo + 554 " " + fmd.name); 555 } 556 } else { 557 buf.append("\t\treturn null;\n"); 558 } 559 buf.append("\t}\n"); 560 spec.addMethod(buf.toString()); 561 } 562 563 protected void addVersion() { 564 StringBuffer buf = new StringBuffer (); 565 buf.append("\n\tpublic final String getVersion() {\n"); 569 buf.append("\t\treturn \""+ Debug.VERSION +"\";\n"); 570 buf.append("\t}\n"); 571 spec.addMethod(buf.toString()); 572 } 573 574 575 protected void addClearDirtyFields() { 576 StringBuffer buf = new StringBuffer (); 577 buf.append("\n\tpublic final void clearDirtyFields() {\n"); 591 int num = getNumOfControlFields(); 592 for (int i = 0; i < num; i++) { 593 buf.append("\t\tfilled"+i+" &= ~dirtyFields"+i+";\n"); 594 buf.append("\t\tresolved"+i+" &= ~dirtyFields"+i+";\n"); 595 buf.append("\t\tdirtyFields"+i+" = 0;\n"); 596 } 597 buf.append("\t}\n"); 598 spec.addMethod(buf.toString()); 599 } 600 601 602 protected void addUpdateAutoSetFieldsCreated() { 603 StringBuffer buf = new StringBuffer (); 604 buf.append("\n\tpublic final void updateAutoSetFieldsCreated(java.util.Date now) {\n"); 609 if (cmd.hasAutoSetFields) { 610 FieldMetaData[] stateFields = cmd.stateFields; 611 for (int fieldNo = stateFields.length - 1;fieldNo >= 0; fieldNo--) { 612 FieldMetaData fmd = cmd.stateFields[fieldNo]; 613 int autoset = fmd.autoSet; 614 if (autoset != MDStatics.AUTOSET_CREATED && autoset != MDStatics.AUTOSET_BOTH) { 615 continue; 616 } 617 switch (fmd.typeCode) { 618 case MDStatics.DATE: 619 buf.append("\t\t_"+ fieldNo +" = now;\n"); 620 buf.append("\t\t"+ getFilledFieldName(fieldNo) +" |= "+ getFieldIndex(fieldNo) +";\n"); 621 622 break; 623 case MDStatics.INT: 624 case MDStatics.SHORT: 625 case MDStatics.BYTE: 626 buf.append("\t\t_" + fieldNo + " = 1;\n"); 627 buf.append("\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 628 break; 629 default: 630 throw BindingSupportImpl.getInstance().internal("Invalid typeCode " + fmd.typeCode + 631 " for autoset field: stateFieldNo " + fieldNo + 632 " " + fmd.name); 633 } 634 } 635 } 636 buf.append("\t}\n"); 637 spec.addMethod(buf.toString()); 638 } 639 640 protected void addUpdateAutoSetFieldsModified() { 641 StringBuffer buf = new StringBuffer (); 642 buf.append("\n\tpublic final void updateAutoSetFieldsModified(java.util.Date now, State oldState) {\n"); 647 if (cmd.hasAutoSetFields) { 648 FieldMetaData[] stateFields = cmd.stateFields; 649 for (int fieldNo = stateFields.length - 1;fieldNo >= 0; fieldNo--) { 650 FieldMetaData fmd = cmd.stateFields[fieldNo]; 651 int autoset = fmd.autoSet; 652 if (autoset != MDStatics.AUTOSET_MODIFIED && autoset != MDStatics.AUTOSET_BOTH) { 653 continue; 654 } 655 switch (fmd.typeCode) { 656 case MDStatics.DATE: 657 buf.append("\t\t_" + fieldNo + " = now;\n"); 658 buf.append("\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 659 break; 660 case MDStatics.INT: 661 buf.append("\t\t_" + fieldNo + " = (oldState.getIntField(" + fieldNo + ") + 1 & " + 0x7FFFFFFF + ");\n"); 662 buf.append("\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 663 break; 664 case MDStatics.SHORT: 665 buf.append("\t\t_"+ fieldNo +" = (short) (oldState.getShortField("+ fieldNo +") + 1 & "+ 0x7FFF +");\n"); 666 buf.append("\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 667 break; 668 case MDStatics.BYTE: 669 buf.append("\t\t_" + fieldNo + " = (byte) (oldState.getByteField(" + fieldNo + ") + 1 & " + 0x7F + ");\n"); 670 buf.append("\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 671 break; 672 default: 673 throw BindingSupportImpl.getInstance().internal("Invalid typeCode " + fmd.typeCode + 674 " for autoset field: stateFieldNo " + fieldNo + 675 " " + fmd.name); 676 } 677 } 678 } 679 buf.append("\t}\n"); 680 spec.addMethod(buf.toString()); 681 } 682 683 684 685 protected void addClearNonAutoSetFields() { 686 StringBuffer buf = new StringBuffer (); 687 buf.append("\n\tpublic final void clearNonAutoSetFields() {\n"); 696 int[] masks = new int[getNumOfControlFields()]; 697 int num = cmd.nonAutoSetStateFieldNos.length; 698 for (int i = 0; i < num; i++) { 699 int fieldNum = cmd.nonAutoSetStateFieldNos[i]; 700 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 701 } 702 int maskLenght = masks.length; 703 for (int i = 0; i < maskLenght; i++) { 704 if (masks[i] != 0) { 705 buf.append("\t\tfilled"+i+" = filled"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 706 buf.append("\t\tresolved"+i+" = resolved"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 707 } 708 } 709 for (int i = 0; i < num; i++) { 710 int fieldNum = cmd.nonAutoSetStateFieldNos[i]; 711 FieldMetaData data = cmd.stateFields[fieldNum]; 712 if (data.type.isPrimitive()) { 713 continue; 714 } 715 buf.append("\t\t_"+ fieldNum +" = null;\n"); 716 } 717 buf.append("\t}\n"); 718 spec.addMethod(buf.toString()); 719 } 720 721 protected void addMakeDirtyAbs() { 722 StringBuffer buf = new StringBuffer (); 723 buf.append("\n\tpublic final void makeDirtyAbs(int absFieldNo) {\n"); 727 buf.append("\t\tmakeDirty(cmd.absToRel[absFieldNo]);\n"); 728 buf.append("\t}\n"); 729 spec.addMethod(buf.toString()); 730 } 731 732 protected void addContainsFieldAbs() { 733 StringBuffer buf = new StringBuffer (); 734 buf.append("\n\tpublic final boolean containsFieldAbs(int absFieldNo) {\n"); 738 buf.append("\t\treturn containsField(cmd.absToRel[absFieldNo]);\n"); 739 buf.append("\t}\n"); 740 spec.addMethod(buf.toString()); 741 } 742 743 protected void addGetNullFields() { 744 StringBuffer buf = new StringBuffer (); 745 746 769 buf.append("\n\tprivate final int getNullFields(int index) {\n"); 770 buf.append("\t\tint filled = 0;\n"); 771 buf.append("\t\tint nullFields = 0;\n"); 772 buf.append("\t\tswitch (index) {\n"); 773 int switchCount = getNumOfControlFields(); 774 for (int i = 0; i < switchCount; i++) { 775 buf.append("\t\t\tcase "+i+":\n"); 776 buf.append("\t\t\t\tfilled = filled"+i+";\n"); 777 List objectList = getRealObjectFields(i); 778 for (Iterator iter = objectList.iterator(); iter.hasNext();) { 779 FieldMetaData data = (FieldMetaData) iter.next(); 780 int fieldNo = data.stateFieldNo; 781 buf.append("\t\t\t\tif ((filled & "+ getFieldIndex(fieldNo) +") != 0 && _"+ fieldNo +" == null) {\n"); 782 buf.append("\t\t\t\t\tnullFields |= "+ getFieldIndex(fieldNo) +";\n"); 783 buf.append("\t\t\t\t}\n"); 784 } 785 buf.append("\t\t\t\treturn nullFields;\n"); 786 } 787 buf.append("\t\t}\n"); 788 buf.append("\t\treturn nullFields;\n"); 789 buf.append("\t}\n"); 790 spec.addMethod(buf.toString()); 791 } 792 793 protected void addClearSCOFields() { 794 StringBuffer buf = new StringBuffer (); 795 buf.append("\n\tpublic final void clearSCOFields() {\n"); 809 int[] masks = new int[getNumOfControlFields()]; 810 int num = cmd.scoFieldNos.length; 811 for (int i = 0; i < num; i++) { 812 int fieldNum = cmd.scoFieldNos[i]; 813 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 814 } 815 int maskLenght = masks.length; 816 for (int i = 0; i < maskLenght; i++) { 817 if (masks[i] != 0) { 818 buf.append("\t\tfilled"+i+" = filled"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 819 buf.append("\t\tresolved"+i+" = resolved"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 820 } 821 } 822 for (int i = 0; i < num; i++) { 823 int fieldNum = cmd.scoFieldNos[i]; 824 buf.append("\t\t_"+ fieldNum +" = null;\n"); 825 } 826 buf.append("\t}\n"); 827 spec.addMethod(buf.toString()); 828 } 829 830 protected void addCopyKeyFieldsUpdate() { 831 StringBuffer buf = new StringBuffer (); 832 buf.append("\n\tpublic final void copyKeyFieldsUpdate(OID oid) {\n"); 833 buf.append("\t}\n"); 834 spec.addMethod(buf.toString()); 835 } 836 837 protected void addCopyKeyFieldsFromOID() { 838 StringBuffer buf = new StringBuffer (); 839 buf.append("\n\tpublic final void copyKeyFields(OID oid) {\n"); 840 buf.append("\t}\n"); 841 spec.addMethod(buf.toString()); 842 } 843 844 protected void addCheckKeyFields() { 845 StringBuffer buf = new StringBuffer (); 846 buf.append("\n\tpublic final boolean checkKeyFields(OID oid) {\n"); 847 buf.append("\t\treturn true;\n"); 848 buf.append("\t}\n"); 849 spec.addMethod(buf.toString()); 850 851 } 852 853 protected void addClearApplicationIdentityFields() { 854 StringBuffer buf = new StringBuffer (); 855 buf.append("\n\tpublic final void clearApplicationIdentityFields() {\n"); 856 buf.append("\t}\n"); 857 spec.addMethod(buf.toString()); 858 } 859 860 protected boolean isDate(int fieldNo) { 861 FieldMetaData info = cmd.stateFields[fieldNo]; 862 if (info.type.isAssignableFrom(Date.class)) { 863 return true; 864 } 865 return false; 866 } 867 868 protected boolean isDate(FieldMetaData fmd) { 869 if (fmd.type.isAssignableFrom(Date.class)) { 870 return true; 871 } 872 return false; 873 } 874 875 protected void addReplaceSCOFields() { 876 StringBuffer buf = new StringBuffer (); 877 890 buf.append("\n\tpublic final int replaceSCOFields(PersistenceCapable owner, VersantPersistenceManagerImp sm, int absFields[]) {\n"); 891 buf.append("\t\tint count = 0;\n"); 892 int numSCO = cmd.scoFieldNos.length; 893 if (numSCO > 0) { 894 for (int i = 0; i < numSCO; i++) { 895 int fieldNo = cmd.scoFieldNos[i]; 896 boolean isDate = isDate(fieldNo); 897 buf.append("\t\tif (_" + fieldNo + " != null) {\n"); 898 buf.append("\t\t\t_"+ fieldNo +" = "+(isDate ? "(java.util.Date)":"")+"cmd.stateFields["+ fieldNo +"].createSCO(sm, sm.getInternalSM(owner), cmd.stateFields[" + fieldNo + "], owner, _" + fieldNo + ");\n"); 899 buf.append("\t\t\tabsFields[count++] = cmd.stateFields["+ fieldNo +"].managedFieldNo;\n"); 900 buf.append("\t\t}\n"); 901 } 902 } 903 buf.append("\t\treturn count;\n"); 904 buf.append("\t}\n"); 905 spec.addMethod(buf.toString()); 906 } 907 908 909 protected void addUnmanageSCOFields() { 910 StringBuffer buf = new StringBuffer (); 911 buf.append("\n\tpublic final void unmanageSCOFields() {\n"); 920 int numSCO = cmd.scoFieldNos.length; 921 if (numSCO > 0) { 922 for (int i = 0; i < numSCO; i++) { 923 int fieldNo = cmd.scoFieldNos[i]; 924 buf.append("\t\tif (_"+ fieldNo +" instanceof com.versant.core.jdo.sco.VersantSimpleSCO) {\n"); 925 buf.append("\t\t\t((com.versant.core.jdo.sco.VersantSimpleSCO) _"+ fieldNo +").makeTransient();\n"); 926 buf.append("\t\t}\n"); 927 } 928 } 929 buf.append("\t}\n"); 930 spec.addMethod(buf.toString()); 931 } 932 933 934 protected void addContainsFetchGroup() { 935 StringBuffer buf = new StringBuffer (); 936 buf.append("\n\tpublic final boolean containsFetchGroup(FetchGroup fetchGroup) {\n"); 950 buf.append("\t\tfor (; fetchGroup != null; fetchGroup = fetchGroup.superFetchGroup) {\n"); 951 buf.append("\t\t\tint fgn[] = fetchGroup.stateFieldNos;\n"); 952 buf.append("\t\t\tfor (int i = fgn.length - 1; i >= 0; i--) {\n"); 953 buf.append("\t\t\t\tif (!containsField(fgn[i])) {\n"); 954 buf.append("\t\t\t\t\treturn false;\n"); 955 buf.append("\t\t\t\t}\n"); 956 buf.append("\t\t\t}\n\n"); 957 buf.append("\t\t}\n\n"); 958 buf.append("\t\treturn true;\n"); 959 buf.append("\t}\n"); 960 spec.addMethod(buf.toString()); 961 } 962 963 964 protected void addClearCollectionFields() { 965 StringBuffer buf = new StringBuffer (); 966 buf.append("\n\tpublic final void clearCollectionFields() {\n"); 974 int[] masks = new int[getNumOfControlFields()]; 975 int num = cmd.stateFields.length; 976 for (int i = 0; i < num; i++) { 977 int category = cmd.stateFields[i].category; 978 if (category == MDStatics.CATEGORY_COLLECTION || 979 category == MDStatics.CATEGORY_MAP || 980 category == MDStatics.CATEGORY_ARRAY) { 981 int fieldNum = cmd.stateFields[i].stateFieldNo; 982 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 983 } 984 } 985 int maskLenght = masks.length; 986 for (int i = 0; i < maskLenght; i++) { 987 if (masks[i] != 0) { 988 buf.append("\t\tfilled"+i+" = filled"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 989 buf.append("\t\tresolved"+i+" = resolved"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 990 } 991 } 992 for (int i = 0; i < num; i++) { 993 int category = cmd.stateFields[i].category; 994 if (category == MDStatics.CATEGORY_COLLECTION || 995 category == MDStatics.CATEGORY_MAP || 996 category == MDStatics.CATEGORY_ARRAY) { 997 FieldMetaData data = cmd.stateFields[i]; 998 buf.append("\t\t_"+ data.stateFieldNo +" = null;\n"); 999 } 1000 } 1001 buf.append("\t}\n"); 1002 spec.addMethod(buf.toString()); 1003 } 1004 1005 1006 1007 1008 protected void addToString() { 1009 StringBuffer buf = new StringBuffer (); 1010 1011 1039 buf.append("\n\tpublic String toString() {\n"); 1040 buf.append("\t\tStringBuffer s = new StringBuffer(\"\\n|---------------------------------------------------------------------------------\\n| " + className + "@\");\n"); 1041 buf.append("\t\ttry{\n"); 1042 buf.append("\t\t\ts.append(Integer.toHexString(System.identityHashCode(this)));\n"); 1043 buf.append("\t\t\ts.append(\"\\n|---------------------------------------------------------------------------------\");\n"); 1044 1045 int maxNameLenght = 0; 1046 for (int j = 0; j < cmd.stateFields.length; j++) { 1047 if (cmd.stateFields[j].name.length() > maxNameLenght) { 1048 maxNameLenght = cmd.stateFields[j].name.length(); 1049 } 1050 } 1051 buf.append("\t\t\ts.append(\"\\n| INDEX | FILLED | DIRTY | RESOLVE | " + getBufName("NAME", 1052 maxNameLenght) + " | VALUE \\n\");\n"); 1053 buf.append("\t\t\ts.append(\"|---------------------------------------------------------------------------------\");\n"); 1054 int totalNum = cmd.stateFields.length; 1055 for (int i = 0; i < totalNum; i++) { 1056 FieldMetaData fmd = cmd.stateFields[i]; 1057 int fieldNum = getFieldNo(fmd); 1058 int index = getFieldIndex(fieldNum); 1059 String fieldRealName = fmd.name; 1060 String filledFieldName = getFilledFieldName(fieldNum); 1061 String resolvedFieldName = getResolvedFieldName(fieldNum); 1062 String dirtyFieldName = getDirtyFieldName(fieldNum); 1063 String fieldName = getFieldName(fieldNum); 1064 1065 if (fieldNum < 10) { 1066 buf.append("\t\t\ts.append(\"\\n| " + fieldNum + " \");\n"); 1067 } else if (fieldNum < 100) { 1068 buf.append("\t\t\ts.append(\"\\n| " + fieldNum + " \");\n"); 1069 } else { 1070 buf.append("\t\t\ts.append(\"\\n| " + fieldNum + " \");\n"); 1071 } 1072 1073 1074 buf.append("\t\t\ts.append((" + filledFieldName + " & " + index + ") == 0 ? \"| 0 \" : \"| 1 \");\n"); 1075 1076 buf.append("\t\t\ts.append((" + dirtyFieldName + " & " + index + ") == 0 ? \"| 0 \" : \"| 1 \");\n"); 1077 1078 buf.append("\t\t\ts.append((" + resolvedFieldName + " & " + index + ") == 0 ? \"| 0 \" : \"| 1 \");\n"); 1079 1080 buf.append("\t\t\ts.append(\"| " + getBufName(fieldRealName, maxNameLenght) + " | \");\n"); 1081 1082 if (isOID(fmd)) { 1083 buf.append("\t\t\ts.append(("+ fieldName +" instanceof OID) ? ((Object) (((OID)"+ fieldName +").toSString())) : "+ fieldName +");\n"); 1084 } else { 1085 buf.append("\t\t\ts.append(" + fieldName + ");\n"); 1086 } 1087 } 1088 buf.append("\t\t\ts.append(\"\\n|---------------------------------------------------------------------------------\");\n"); 1089 buf.append("\t\t} catch(java.lang.Exception e){\n"); 1090 buf.append("\t\t\ts = new StringBuffer(e.getMessage());\n"); 1091 buf.append("\t\t}\n"); 1092 buf.append("\t\treturn s.toString();\n"); 1093 buf.append("\t}\n"); 1094 spec.addMethod(buf.toString()); 1095 1096 } 1097 1098 protected String getBufName(String name, int maxLenght) { 1099 int bufLenght = maxLenght - name.length(); 1100 StringBuffer buf = new StringBuffer (name); 1101 for (int i = 0; i < bufLenght; i++) { 1102 buf.append(" "); 1103 } 1104 return buf.toString(); 1105 } 1106 1107 protected void addClearTransactionNonPersistentFields() { 1108 StringBuffer buf = new StringBuffer (); 1109 buf.append("\n\tpublic final void clearTransactionNonPersistentFields() {\n"); 1113 int[] masks = new int[getNumOfControlFields()]; 1114 int num = cmd.txFieldNos.length; 1115 for (int i = 0; i < num; i++) { 1116 int fieldNum = cmd.txFieldNos[i]; 1117 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 1118 } 1119 int maskLenght = masks.length; 1120 for (int i = 0; i < maskLenght; i++) { 1121 if (masks[i] != 0) { 1122 buf.append("\t\tdirtyFields"+i+" = dirtyFields"+i+" & "+ (masks[i] ^ 0xFFFFFFFF) +";\n"); 1123 } 1124 } 1125 buf.append("\t}\n"); 1126 spec.addMethod(buf.toString()); 1127 } 1128 1129 1130 protected void addCompareToPass1() { 1131 StringBuffer buf = new StringBuffer (); 1132 1137 1138 1150 buf.append("\n\tpublic final int compareToPass1(State state) {\n"); 1151 buf.append("\t\t" + className + " s = ("+className+") state;\n"); 1152 int[] masks = new int[getNumOfControlFields()]; 1153 int num = cmd.stateFields.length; 1154 for (int i = 0; i < num; i++) { 1155 if (cmd.stateFields[i].primaryField) { 1156 int fieldNum = cmd.stateFields[i].stateFieldNo; 1157 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 1158 } 1159 } 1160 int maskLenght = masks.length; 1161 for (int i = 0; i < maskLenght; i++) { 1162 if (i == 0) { 1163 buf.append("\t\tint ans = ((filled0 & "+ masks[i] +") - (s.filled0 & " + masks[i] + "))"); 1164 } else { 1165 buf.append(" + ((filled"+i+" & "+ masks[i] +") - (s.filled"+i+" & "+ masks[i] +"))"); 1166 } 1167 1168 } 1169 buf.append(";\n"); 1170 buf.append("\t\treturn ans;\n"); 1171 buf.append("\t}\n"); 1172 spec.addMethod(buf.toString()); 1173 } 1174 1175 protected void addGetClassMetaDataJMD() { 1176 StringBuffer buf = new StringBuffer (); 1177 buf.append("\n\tpublic final ClassMetaData getClassMetaData(ModelMetaData jmd) {\n"); 1178 buf.append("\t\treturn cmd;\n"); 1179 buf.append("\t}\n"); 1180 spec.addMethod(buf.toString()); 1181 } 1182 1183 protected void addGetClassMetaData() { 1184 StringBuffer buf = new StringBuffer (); 1185 buf.append("\n\tpublic final ClassMetaData getClassMetaData() {\n"); 1189 buf.append("\t\treturn cmd;\n"); 1190 buf.append("\t}\n"); 1191 spec.addMethod(buf.toString()); 1192 } 1193 1194 protected void addContainFields() { 1195 StringBuffer buf = new StringBuffer (); 1196 1197 1207 1217 buf.append("\n\tpublic final boolean containFields(int fieldNos[]) {\n"); 1218 buf.append("\t\tint numOfFields = fieldNos.length;\n"); 1219 buf.append("\t\tfor (int i = 0; i < numOfFields; i++) {\n"); 1220 int controlNum = getNumOfControlFields(); 1221 if (controlNum == 1) { 1222 buf.append("\t\t\tif ((filled0 & 1 << fieldNos[i]) == 0) {\n"); 1223 1224 } else { buf.append("\t\t\tif (!containsField(fieldNos[i])) {\n"); 1226 } 1227 buf.append("\t\t\t\treturn false;\n"); 1228 buf.append("\t\t\t}\n"); 1229 buf.append("\t\t}\n\n"); 1230 buf.append("\t\treturn true;\n"); 1231 buf.append("\t}\n"); 1232 spec.addMethod(buf.toString()); 1233 } 1234 1235 1236 1237 protected void addContainFieldsAbs() { 1238 StringBuffer buf = new StringBuffer (); 1239 buf.append("\n\tpublic final boolean containFieldsAbs(int absfieldNos[]) {\n"); 1250 buf.append("\t\tint numOfFields = absfieldNos.length;\n"); 1251 buf.append("\t\tint managedFieldNos[] = cmd.absToRel;\n"); 1252 buf.append("\t\tfor (int i = 0; i < numOfFields; i++) {\n"); 1253 buf.append("\t\t\tif (!containsField(managedFieldNos[absfieldNos[i]])) {\n"); 1254 buf.append("\t\t\t\treturn false;\n"); 1255 buf.append("\t\t\t}\n"); 1256 buf.append("\t\t}\n"); 1257 buf.append("\t\treturn true;\n"); 1258 buf.append("\t}\n"); 1259 spec.addMethod(buf.toString()); 1260 } 1261 1262 protected void addIsEmpty() { 1263 StringBuffer buf = new StringBuffer (); 1264 1265 1269 buf.append("\n\tpublic final boolean isEmpty() {\n"); 1270 int num = getNumOfControlFields(); 1271 for (int i = 0; i < num; i++) { 1272 if (i == 0) { 1273 buf.append("\t\treturn filled0 == 0"); 1274 } else { 1275 buf.append(" && filled" + i + " == 0"); 1276 } 1277 } 1278 buf.append(";\n"); 1279 buf.append("\t}\n"); 1280 spec.addMethod(buf.toString()); 1281 } 1282 1283 protected void addContainsPass2Fields() { 1284 StringBuffer buf = new StringBuffer (); 1285 buf.append("\n\tpublic final boolean containsPass2Fields() {\n"); 1286 boolean doMask = false; 1287 int[] masks = new int[getNumOfControlFields()]; 1288 int num = cmd.stateFields.length; 1289 for (int i = 0; i < num; i++) { 1290 if (cmd.stateFields[i].secondaryField) { 1291 int fieldNum = cmd.stateFields[i].stateFieldNo; 1292 doMask = true; 1293 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 1294 } 1295 } 1296 if (!doMask) { 1297 buf.append("\t\treturn false;\n"); 1298 } else { 1299 for (int i = 0; i < masks.length; i++) { 1300 buf.append("\t\tif ((filled" + i + " & " + masks[i] + ") != 0) {\n"); 1301 buf.append("\t\t\treturn true;\n"); 1302 buf.append("\t\t}\n"); 1303 } 1304 buf.append("\t\treturn false;\n"); 1305 } 1306 buf.append("\t}\n"); 1307 spec.addMethod(buf.toString()); 1308 } 1309 1310 protected void addContainsPass1Fields() { 1311 StringBuffer buf = new StringBuffer (); 1312 buf.append("\n\tpublic final boolean containsPass1Fields() {\n"); 1322 boolean doMask = false; 1323 int[] masks = new int[getNumOfControlFields()]; 1324 int num = cmd.stateFields.length; 1325 for (int i = 0; i < num; i++) { 1326 if (cmd.stateFields[i].primaryField) { 1327 int fieldNum = cmd.stateFields[i].stateFieldNo; 1328 doMask = true; 1329 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 1330 } 1331 } 1332 if (!doMask) { 1333 buf.append("\t\treturn false;\n"); 1334 } else { 1335 for (int i = 0; i < masks.length; i++) { 1336 buf.append("\t\tif ((filled"+i+" & "+ masks[i] +") != 0) {\n"); 1337 buf.append("\t\t\treturn true;\n"); 1338 buf.append("\t\t}\n"); 1339 } 1340 buf.append("\t\treturn false;\n"); 1341 } 1342 buf.append("\t}\n"); 1343 spec.addMethod(buf.toString()); 1344 } 1345 1346 protected void addGetPass1FieldNos() { 1347 StringBuffer buf = new StringBuffer (); 1348 1367 buf.append("\n\tpublic final int getPass1FieldNos(int buf[]) {\n"); 1368 buf.append("\t\tint c = 0;\n"); 1369 boolean first = true; int num = getNumOfControlFields(); 1371 for (int i = 0; i < num; i++) { 1372 List fields = getPass1Fields(i); 1373 if (fields.isEmpty()) { 1374 continue; 1375 } 1376 if (first) { 1377 buf.append("\t\tint filled = filled"+i+";\n"); 1378 first = false; 1379 } else { 1380 buf.append("\t\tfilled = filled"+i+";\n"); 1381 } 1382 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1383 FieldMetaData fmd = (FieldMetaData) iter.next(); 1384 int fieldNo = fmd.stateFieldNo; 1385 buf.append("\t\tif ((filled & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 1386 buf.append("\t\t\tbuf[c++] = "+ fieldNo +";\n"); 1387 buf.append("\t\t}\n"); 1388 } 1389 } 1390 buf.append("\t\treturn c;\n"); 1391 buf.append("\t\t}\n"); 1392 spec.addMethod(buf.toString()); 1393 } 1394 1395 protected void addGetPass1FieldRefFieldNosWithNewOids() { 1396 StringBuffer buf = new StringBuffer (); 1397 1416 buf.append("\n\tpublic final int getPass1FieldRefFieldNosWithNewOids(int buf[]) {\n"); 1417 buf.append("\t\tint c = 0;\n"); 1418 boolean first = true; int num = getNumOfControlFields(); 1420 for (int i = 0; i < num; i++) { 1421 List fields = getPass1FieldAndRefOrPolyRefFields(i); 1422 if (fields.isEmpty()) { 1423 continue; 1424 } 1425 if (first) { 1426 buf.append("\t\tint filled = filled" + i + ";\n"); 1427 first = false; 1428 } else { 1429 buf.append("\t\tfilled = filled" + i + ";\n"); 1430 } 1431 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1432 FieldMetaData fmd = (FieldMetaData) iter.next(); 1433 int fieldNo = fmd.stateFieldNo; 1434 buf.append("\t\tif ((filled & " + getFieldIndex(fieldNo) + ") != 0) {\n"); 1435 buf.append("\t\t\tbuf[c++] = " + fieldNo + ";\n"); 1436 buf.append("\t\t}\n"); 1437 } 1438 } 1439 buf.append("\t\treturn c;\n"); 1440 buf.append("\t\t}\n"); 1441 spec.addMethod(buf.toString()); 1442 } 1443 1444 protected void addGetPass2FieldNos() { 1445 StringBuffer buf = new StringBuffer (); 1446 buf.append("\n\tpublic final int getPass2FieldNos(int buf[]) {\n"); 1447 buf.append("\t\tint c = 0;\n"); 1448 boolean first = true; int num = getNumOfControlFields(); 1450 for (int i = 0; i < num; i++) { 1451 List fields = getPass2Fields(i); 1452 if (fields.isEmpty()) { 1453 continue; 1454 } 1455 if (first) { 1456 buf.append("\t\tint filled = filled" + i + ";\n"); 1457 first = false; 1458 } else { 1459 buf.append("\t\tfilled = filled" + i + ";\n"); 1460 } 1461 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1462 FieldMetaData fmd = (FieldMetaData) iter.next(); 1463 int fieldNo = fmd.stateFieldNo; 1464 buf.append("\t\tif ((filled & " + getFieldIndex(fieldNo) + ") != 0) {\n"); 1465 buf.append("\t\t\tbuf[c++] = " + fieldNo + ";\n"); 1466 buf.append("\t\t}\n"); 1467 } 1468 } 1469 buf.append("\t\treturn c;\n"); 1470 buf.append("\t\t}\n"); 1471 spec.addMethod(buf.toString()); 1472 } 1473 1474 1475 protected void addIsHollow() { 1476 StringBuffer buf = new StringBuffer (); 1477 1481 buf.append("\n\tpublic final boolean isHollow() {\n"); 1482 int num = getNumOfControlFields(); 1483 for (int i = 0; i < num; i++) { 1484 if (i == 0) { 1485 buf.append("\t\treturn filled0 == 0"); 1486 } else { 1487 buf.append(" && filled"+i+" == 0"); 1488 } 1489 } 1490 buf.append(";\n"); 1491 buf.append("\t}\n"); 1492 spec.addMethod(buf.toString()); 1493 } 1494 1495 protected void addSetClassMetaData() { 1496 StringBuffer buf = new StringBuffer (); 1497 buf.append("\n\tpublic final void setClassMetaData(ClassMetaData classmetadata) {\n\t}\n"); 1498 spec.addMethod(buf.toString()); 1499 } 1500 1501 1502 1503 protected void addReplaceNewObjectOIDs() { 1504 StringBuffer buf = new StringBuffer (); 1505 buf.append("\n\tpublic final boolean replaceNewObjectOIDs(int fieldNos[], int fieldNosLength) {\n"); 1523 List oidList = getOIDsFieldsMetaData(); 1524 if (oidList.isEmpty()) { 1525 buf.append("\t\treturn false;\n"); 1526 buf.append("\t}\n"); 1527 } else { 1528 buf.append("\t\tboolean containsUnResolvedNewOids = false;\n"); 1529 buf.append("\t\tfor (int i = 0; i < fieldNosLength; i++) {\n"); 1530 buf.append("\t\t\tswitch (fieldNos[i]) {\n"); 1531 for (Iterator iter = oidList.iterator(); iter.hasNext();) { 1532 FieldMetaData field = (FieldMetaData) iter.next(); 1533 int fieldNo = field.stateFieldNo; 1534 buf.append("\t\t\t\tcase "+ fieldNo +":\n"); 1535 buf.append("\t\t\t\t\tif (_" + fieldNo + " instanceof com.versant.core.common.NewObjectOID) {\n"); 1536 buf.append("\t\t\t\t\t\tif (((com.versant.core.common.NewObjectOID) _" + fieldNo + ").realOID == null) {\n"); 1537 buf.append("\t\t\t\t\t\t\tcontainsUnResolvedNewOids = true;\n"); 1538 buf.append("\t\t\t\t\t\t} else {\n"); 1539 buf.append("\t\t\t\t\t\t\t_"+ fieldNo +" = ((com.versant.core.common.NewObjectOID) _"+ fieldNo +").realOID;\n"); 1540 buf.append("\t\t\t\t\t\t}\n"); 1541 buf.append("\t\t\t\t\t}\n"); 1542 buf.append("\t\t\t\t\tbreak;\n\n"); 1543 } 1544 buf.append("\t\t\t\tdefault:\n"); 1546 buf.append("\t\t\t\t\tbreak;\n\n"); 1547 buf.append("\t\t\t}\n"); 1548 buf.append("\t\t}\n"); 1549 buf.append("\t\treturn containsUnResolvedNewOids;\n"); 1550 buf.append("\t}\n"); 1551 } 1552 spec.addMethod(buf.toString()); 1553 } 1554 1555 protected void addGetDirtyState() { 1556 StringBuffer buf = new StringBuffer (); 1557 buf.append("\n\tpublic boolean fillToStoreState(State stateToStore, PersistenceContext pm, VersantStateManager sm) {\n"); 1558 if (!cmd.storeAllFields) { 1559 buf.append("\t\t" + className + " state = (" + className + ")stateToStore;\n"); 1560 buf.append("\t\tif (isDirty()) {\n"); 1561 buf.append("\t\t\tboolean prepare = false;\n"); 1562 int num = getNumOfControlFields(); 1563 for (int i = 0; i < num; i++) { 1564 if (i == 0) { 1565 buf.append("\t\t\tint toCheck = state.filled" + i + " = dirtyFields" + i + ";\n"); 1566 } else { 1567 buf.append("\t\t\ttoCheck = state.filled" + i + " = dirtyFields" + i + ";\n"); 1568 } 1569 List fields = getFields(i); 1570 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1571 FieldMetaData fmd = (FieldMetaData) iter.next(); 1572 int fieldNo = fmd.stateFieldNo; 1573 buf.append("\t\t\tif ((toCheck & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 1574 if (isOID(fmd) || isCollection(fmd) || isMap(fmd) || isPolyRef(fmd) || isPCArray(fmd) || isExternalized(fmd)) { 1575 buf.append("\t\t\t\tprepare = true;\n"); 1576 } else if (fmd.type.equals(java.util.Date .class)) { 1577 buf.append("\t\t\t\tprepare = true;\n"); 1578 } 1579 buf.append("\t\t\t\tstate._"+ fieldNo +" = _"+ fieldNo +";\n"); 1580 buf.append("\t\t\t}\n"); 1581 } 1582 } 1583 buf.append("\t\t\tif (prepare) {\n"); 1584 buf.append("\t\t\t\tstate.prepare(pm, sm);\n"); 1585 buf.append("\t\t\t}\n"); 1586 buf.append("\t\t} else {\n"); 1587 buf.append("\t\t\tstate = null;\n"); 1588 buf.append("\t\t}\n"); 1589 buf.append("\t\treturn state != null;\n"); 1590 } else { buf.append("\t\t" + className + " state = (" + className + ")stateToStore;\n"); 1592 buf.append("\t\tif (isDirty()) {\n"); 1593 int num = getNumOfControlFields(); 1594 boolean toCheck_Start = true; 1595 for (int i = 0; i < num; i++) { 1596 int hash = getPrimaryHash(i); 1597 if (hash == 0) { 1598 continue; 1599 } 1600 if (toCheck_Start){ 1601 buf.append("\t\t\tint toCheck = state.filled" + i + " |= filled" + i + " & " + hash + ";\n"); 1602 toCheck_Start = false; 1603 } else { 1604 buf.append("\t\t\ttoCheck = state.filled" + i + " |= filled" + i + " & " + hash + ";\n"); 1605 } 1606 List fields = getPrimaryFields(i); 1607 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1608 FieldMetaData fmd = (FieldMetaData) iter.next(); 1609 int fieldNo = fmd.stateFieldNo; 1610 buf.append("\t\t\tif ((toCheck & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 1611 buf.append("\t\t\t\tstate._"+ fieldNo +" = _"+ fieldNo +";\n"); 1612 buf.append("\t\t\t}\n"); 1613 } 1614 } 1615 1616 for (int i = 0; i < num; i++) { 1617 int hash = getSecondaryHash(i); 1618 if (hash == 0) { 1619 continue; 1620 } 1621 if (toCheck_Start) { 1622 buf.append("\t\t\tint toCheck = state.filled" + i + " |= dirtyFields" + i + " & " + hash + ";\n"); 1623 toCheck_Start = false; 1624 } else { 1625 buf.append("\t\t\ttoCheck = state.filled" + i + " |= dirtyFields" + i + " & " + hash + ";\n"); 1626 } 1627 List fields = getSecondaryFields(i); 1628 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1629 FieldMetaData fmd = (FieldMetaData) iter.next(); 1630 int fieldNo = fmd.stateFieldNo; 1631 buf.append("\t\t\tif ((toCheck & " + getFieldIndex(fieldNo) + ") != 0) {\n"); 1632 buf.append("\t\t\t\tstate._" + fieldNo + " = _" + fieldNo + ";\n"); 1633 buf.append("\t\t\t}\n"); 1634 } 1635 } 1636 buf.append("\t\t\tstate.prepare(pm, sm);\n"); 1637 buf.append("\t\t} else {\n"); 1638 buf.append("\t\t\tstate = null;\n"); 1639 buf.append("\t\t}\n"); 1640 buf.append("\t\treturn state != null;\n"); 1641 } 1642 buf.append("\t}\n"); 1643 spec.addMethod(buf.toString()); 1644 } 1645 1646 protected void addFindDirectEdges() { 1647 StringBuffer buf = new StringBuffer (); 1648 buf.append("\n\tpublic final void findDirectEdges(OIDGraph graph, "+ INT_ARRAY +" edges) {\n"); 1649 List list = getDirectRefFieldsMetaData(); 1650 if (list.isEmpty()) { 1651 buf.append("\t}\n"); 1652 } else { 1653 ListIterator iter = list.listIterator(); 1654 while (iter.hasNext()) { 1655 iter.next(); 1656 } 1657 while (iter.hasPrevious()) { 1658 FieldMetaData field = (FieldMetaData) iter.previous(); 1659 int fieldNum = field.stateFieldNo; 1660 int index = getFieldIndex(fieldNum); 1661 String filledName = getFilledFieldName(fieldNum); 1662 1663 buf.append("\t\tif (("+ filledName +" & "+index+") != 0) {\n"); 1664 buf.append("\t\t\tfindDirectEdges(graph, cmd, "+ fieldNum+", this, edges);\n"); 1665 buf.append("\t\t}\n"); 1666 } 1667 buf.append("\t}\n"); 1668 } 1669 spec.addMethod(buf.toString()); 1670 } 1671 1672 protected void addHasSameNullFields() { 1673 StringBuffer buf = new StringBuffer (); 1674 buf.append("\n\tpublic final boolean hasSameNullFields(State state, State mask) {\n"); 1675 buf.append("\t\treturn true;\n"); 1676 buf.append("\t}\n"); 1677 spec.addMethod(buf.toString()); 1678 } 1679 1680 protected void addIsNull() { 1681 StringBuffer buf = new StringBuffer (); 1682 buf.append("\n\tpublic final boolean isNull(int fieldNo) {\n"); 1683 List fields = getAllRealObjectFields(); 1684 if (fields.isEmpty()) { 1685 buf.append("\t\treturn false;\n"); 1686 } else if (fields.size() == 1) { 1687 for (Iterator iter = fields.iterator(); iter.hasNext();) { 1688 int fieldNo = getFieldNo((FieldMetaData) iter.next()); 1689 buf.append("\t\treturn _"+ fieldNo +" == null;\n"); 1690 } 1691 } else { 1692 buf.append("\t\tswitch (fieldNo) {\n"); 1693 for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();) { 1694 FieldMetaData info = (FieldMetaData) fieldIter.next(); 1695 int fieldNo = getFieldNo(info); 1696 buf.append("\t\t\tcase " + fieldNo + ":\n"); 1697 buf.append("\t\t\t\treturn _" + fieldNo + " == null;\n\n"); 1698 } 1699 buf.append("\t\t\tdefault:\n"); 1700 buf.append("\t\t\t\treturn false;\n"); 1701 buf.append("\t\t}\n"); 1702 } 1703 buf.append("\t}\n"); 1704 spec.addMethod(buf.toString()); 1705 } 1706 1707 protected FetchGroup findFirstRefFG(ClassMetaData cmd) { 1708 if (cmd.refFetchGroup != null) return cmd.refFetchGroup; 1709 if (cmd.refFetchGroup == null && cmd.pcSuperMetaData == null) return null; 1710 return findFirstRefFG(cmd.pcSuperMetaData); 1711 } 1712 1713 protected void addAddRefs() { 1714 StringBuffer buf = new StringBuffer (); 1715 buf.append("\n\tpublic final void addRefs(VersantPersistenceManagerImp pm, PCStateMan sm) {\n"); 1716 FetchGroup fg = findFirstRefFG(cmd); if (fg != null) { 1719 buf.append("\t\tif (isDirty()) {\n"); 1720 while (fg != null) { 1721 int[] fieldNos = fg.stateFieldNos; 1722 int fieldNum = 0; 1723 FieldMetaData fmd = null; 1724 for (int i = 0; i < fieldNos.length; i++) { 1729 fieldNum = fieldNos[i]; 1730 fmd = cmd.stateFields[fieldNum]; 1731 if (fmd.persistenceModifier == MDStatics.PERSISTENCE_MODIFIER_TRANSACTIONAL) { 1732 continue; 1733 } 1734 buf.append("\t\t\tif (("+ getDirtyFieldName(fieldNum) +" & "+ getFieldIndex(fieldNum) +") != 0 && _"+ fieldNum +" != null) {\n"); 1735 switch (fmd.category) { 1736 case MDStatics.CATEGORY_ARRAY: 1737 buf.append("\t\t\t\tStateUtil.doReachable((Object[])_" + fieldNum + ", pm);\n"); 1739 break; 1740 case MDStatics.CATEGORY_COLLECTION: 1741 buf.append("\t\t\t\tStateUtil.doReachable((java.util.Collection)_" + fieldNum + ", pm);\n"); 1743 break; 1744 case MDStatics.CATEGORY_MAP: 1745 buf.append("\t\t\t\tStateUtil.doReachable((java.util.Map) _"+ fieldNum +", pm, cmd.stateFields["+ fieldNum +"]);\n"); 1746 break; 1747 case MDStatics.CATEGORY_REF: 1748 case MDStatics.CATEGORY_POLYREF: 1749 if (fmd.embedded) { 1750 buf.append( 1751 "\t\t\t\t\tStateUtil.doReachableEmbeddedReference(\n" + 1752 "\t\t\t\t\t\t(PersistenceCapable)_"+ fieldNum +", pm, sm, cmd.stateFields["+ fieldNum +"]);\n"); 1753 } else { 1754 buf.append("\t\t\t\t\tStateUtil.doReachable((PersistenceCapable)_"+ fieldNum +", pm);\n"); 1755 } 1756 break; 1757 default: 1758 fmd.dump(); 1759 throw BindingSupportImpl.getInstance().internal("className = " + className); 1760 } 1761 buf.append("\t\t\t}\n"); 1762 } 1763 fg = fg.superFetchGroup; 1764 } 1765 buf.append("\t\t}\n"); 1766 } 1767 buf.append("\t}\n"); 1768 spec.addMethod(buf.toString()); 1769 } 1770 1771 protected void addRetrieve() { 1772 StringBuffer buf = new StringBuffer (); 1773 buf.append("\n\tpublic final void retrieve(VersantPersistenceManagerImp sm) {\n"); 1774 FetchGroup fg = cmd.refFetchGroup; 1775 if (fg != null) { 1776 while (fg != null) { 1777 int[] fieldNos = fg.stateFieldNos; 1778 int fieldNum = 0; 1779 FieldMetaData fmd = null; 1780 for (int i = fieldNos.length - 1; i >= 0; i--) { 1781 fieldNum = fieldNos[i]; 1782 fmd = cmd.stateFields[fieldNum]; 1783 if (fmd.persistenceModifier == MDStatics.PERSISTENCE_MODIFIER_TRANSACTIONAL) { 1784 continue; 1785 } 1786 buf.append("\t\tif (_"+ fieldNum +" != null) {\n"); 1787 switch (fmd.category) { 1788 case MDStatics.CATEGORY_ARRAY: 1789 buf.append("\t\t\tsm.retrieveAllImp((Object[])_"+ fieldNum +");\n"); 1790 break; 1791 case MDStatics.CATEGORY_COLLECTION: 1792 buf.append("\t\t\tsm.retrieveAllImp((java.util.Collection)_" + fieldNum + ");\n"); 1793 break; 1794 case MDStatics.CATEGORY_MAP: 1795 buf.append("\t\t\tStateUtil.retrieve((java.util.Map) _"+ fieldNum +", sm, cmd.stateFields["+ fieldNum +"]);\n"); 1796 break; 1797 case MDStatics.CATEGORY_REF: 1798 case MDStatics.CATEGORY_POLYREF: 1799 buf.append("\t\t\tsm.retrieveImp(_" + fieldNum + ");\n"); 1800 break; 1801 1802 default: 1803 fmd.dump(); 1804 throw BindingSupportImpl.getInstance().internal("className = " + className); 1805 } 1806 buf.append("\t\t}\n"); 1807 } 1808 fg = fg.superFetchGroup; 1809 } 1810 } 1811 buf.append("\t}\n"); 1812 spec.addMethod(buf.toString()); 1813 1814 } 1815 1816 protected void addGetResolvableObjectField() { 1817 StringBuffer buf = new StringBuffer (); 1818 buf.append("\n\tpublic Object getObjectField(int stateFieldNo, PersistenceCapable owningPC, PersistenceContext pm, OID oid) {\n"); 1819 List fields = getObjectFieldsMetaData(); 1820 if (fields.isEmpty()) { 1821 buf.append("\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1822 } else if (fields.size() == 1) { 1823 for (Iterator singelIter = fields.iterator(); 1824 singelIter.hasNext();) { 1825 FieldMetaData info = (FieldMetaData) singelIter.next(); 1826 int fieldNo = getFieldNo(info); 1827 buf.append("\t\tif (stateFieldNo == " + fieldNo + "){\n"); 1828 addGetResolvableObjectFieldImp(info, buf, fieldNo); 1829 buf.append("\t\t} else {\n"); 1830 buf.append("\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1831 buf.append("\t\t}\n"); 1832 } 1833 } else { 1834 buf.append("\t\tswitch (stateFieldNo) {\n"); 1835 for (Iterator fieldIter = fields.iterator();fieldIter.hasNext();) { 1836 FieldMetaData info = (FieldMetaData) fieldIter.next(); 1837 int fieldNo = getFieldNo(info); 1838 buf.append("\t\t\tcase "+ fieldNo +":\n"); 1839 addGetResolvableObjectFieldImp(info, buf, fieldNo); 1840 } 1841 buf.append("\t\t\tdefault :\n"); 1842 buf.append("\t\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1843 buf.append("\t\t}\n"); 1844 } 1845 buf.append("\t}\n"); 1846 spec.addMethod(buf.toString()); 1847 } 1848 1849 protected void addGetResolvableObjectFieldImp(FieldMetaData info, StringBuffer buf, int fieldNo) { 1850 if (cmd.isEmbeddedRef(fieldNo)) { 1851 buf.append("\t\t\t\tif (_" + fieldNo +" == null && (" + getResolvedFieldName(fieldNo) + " & " + getFieldIndex(fieldNo) + ") == 0) {\n"); 1852 buf.append("\t\t\t\t\t_" + fieldNo + 1853 " = pm.getObjectByIdForState(null, " + fieldNo + ", " + cmd.index + ", oid);\n"); 1854 buf.append("\t\t\t\t\t" + getResolvedFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 1855 buf.append("\t\t\t\t};\n"); 1856 buf.append("\t\t\t\treturn _" + fieldNo + ";\n"); 1857 return; 1858 } 1859 boolean done = false; 1860 if (info.scoField) { 1861 if (info.category == MDStatics.CATEGORY_ARRAY) { 1862 if (info.isElementTypePC()) { 1863 buf.append("\t\t\tif (_" + fieldNo + " != null) {\n"); 1864 buf.append("\t\t\t\tif ((" + getResolvedFieldName(fieldNo) + " & " + getFieldIndex(fieldNo) + ") == 0) {\n"); 1865 buf.append("\t\t\t\t\t_"+ fieldNo +" = resolveArrayOIDs((Object[]) _"+ fieldNo +", pm, cmd.stateFields["+ fieldNo +"].elementType);\n"); 1866 done = true; 1867 } 1868 } else { 1869 boolean isDate = info.typeCode == MDStatics.DATE; 1870 buf.append("\t\t\tif (_" + fieldNo + " != null) {\n"); 1871 buf.append("\t\t\t\tif ((" + getResolvedFieldName(fieldNo) + " & " + getFieldIndex(fieldNo) + ") == 0) {\n"); 1872 buf.append("\t\t\t\t\t_"+ fieldNo +" = "+ (isDate ? "(java.util.Date)" : "") +"cmd.stateFields["+ fieldNo +"].createSCO(pm, pm.getInternalSM(owningPC), cmd.stateFields["+ fieldNo +"], owningPC, _"+ fieldNo +");\n"); 1873 done = true; 1874 } 1875 } else { 1876 int cat = info.category; 1877 if (cat == MDStatics.CATEGORY_EXTERNALIZED) { 1878 buf.append("\t\t\tif (_" + fieldNo + " != null) {\n"); 1879 buf.append("\t\t\t\tif ((" + getResolvedFieldName(fieldNo) + " & " + getFieldIndex(fieldNo) + ") == 0) {\n"); 1880 buf.append("\t\t\t\t\t_"+ fieldNo +" = cmd.stateFields["+ fieldNo +"].externalizer.fromExternalForm(pm, _"+ fieldNo +");\n"); 1881 done = true; 1882 } else if (cat == MDStatics.CATEGORY_REF || cat == MDStatics.CATEGORY_POLYREF) { 1883 buf.append("\t\t\tif (_"+ fieldNo +" != null) {\n"); 1884 buf.append("\t\t\t\tif (("+ getResolvedFieldName(fieldNo) +" & "+ getFieldIndex(fieldNo) +") == 0) {\n"); 1885 buf.append("\t\t\t\t\t_"+ fieldNo +" = pm.getObjectByIdForState((OID)_"+ fieldNo +", "+ fieldNo +", "+ cmd.index +", oid);\n"); 1886 done = true; 1887 } 1888 } 1890 1891 if (done) { 1892 buf.append("\t\t\t\t\t" + getResolvedFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 1893 buf.append("\t\t\t\t}\n"); 1894 buf.append("\t\t\t\treturn _" + fieldNo + ";\n"); 1895 buf.append("\t\t\t} else {\n"); 1896 buf.append("\t\t\t\treturn null;\n"); 1897 buf.append("\t\t\t}\n"); 1898 } else { 1899 buf.append("\t\t\t"+ getResolvedFieldName(fieldNo) +" |= "+ getFieldIndex(fieldNo) +";\n"); 1900 buf.append("\t\t\treturn _"+ fieldNo +";\n"); 1901 } 1902 } 1903 1904 protected void addGetResolvableObjectFieldAbs() { 1905 StringBuffer buf = new StringBuffer (); 1906 buf.append("\n\tpublic final Object getObjectFieldAbs(int absFieldNo, PersistenceCapable owningPC, PersistenceContext sm, OID oid) {\n"); 1910 buf.append("\t\treturn getObjectField(cmd.absToRel[absFieldNo], owningPC, sm, oid);\n"); 1911 buf.append("\t}\n"); 1912 spec.addMethod(buf.toString()); 1913 } 1914 1915 protected boolean isOID(FieldMetaData info) { 1916 if (info.category == MDStatics.CATEGORY_REF) { 1917 return true; 1918 } 1919 return false; 1920 } 1921 1922 protected boolean isObject(FieldMetaData fmd) { 1923 return isOID(fmd) || isCollection(fmd) || isMap(fmd) || isArray(fmd) 1924 || isPolyRef(fmd) || isExternalized(fmd); 1925 } 1926 1927 protected boolean isExternalized(FieldMetaData fmd) { 1928 if (fmd.category == MDStatics.CATEGORY_EXTERNALIZED) { 1929 return true; 1930 } 1931 return false; 1932 } 1933 1934 1935 protected void addGetInternalObjectField() { 1936 StringBuffer buf = new StringBuffer (); 1937 1938 1945 1946 buf.append("\n\tpublic final Object getInternalObjectField(int field) {\n"); 1947 List fields = getObjectFieldsMetaData(); 1948 if (fields.isEmpty()) { 1949 buf.append("\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1950 } else if (fields.size() == 1) { 1951 for (Iterator singelIter = fields.iterator(); 1952 singelIter.hasNext();) { 1953 int fieldNo = getFieldNo((FieldMetaData) singelIter.next()); 1954 buf.append("\t\tif (field == "+ fieldNo +") {\n"); 1955 buf.append("\t\t\treturn _"+fieldNo+";\n"); 1956 buf.append("\t\t} else {\n"); 1957 buf.append("\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1958 buf.append("\t\t}\n"); 1959 } 1960 } else { 1961 buf.append("\t\tswitch (field) {\n"); 1962 for (Iterator fieldIter = fields.iterator();fieldIter.hasNext();) { 1963 int fieldNo = getFieldNo((FieldMetaData) fieldIter.next()); 1964 buf.append("\t\t\tcase "+ fieldNo +":\n"); 1965 buf.append("\t\t\t\treturn _"+ fieldNo +";\n\n"); 1966 } 1967 buf.append("\t\t\tdefault:\n"); 1969 buf.append("\t\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1970 buf.append("\t\t}\n"); 1971 } 1972 buf.append("\t}\n"); 1973 spec.addMethod(buf.toString()); 1974 } 1975 1976 1977 1978 protected void addGetInternalObjectFieldAbs() { 1979 StringBuffer buf = new StringBuffer (); 1980 1981 1992 buf.append("\n\tpublic final Object getInternalObjectFieldAbs(int absField) {\n"); 1993 List fields = getObjectFieldsMetaDataAbs(); 1994 if (fields.isEmpty()) { 1995 buf.append("\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 1996 } else if (fields.size() == 1) { 1997 for (Iterator singelIter = fields.iterator(); 1998 singelIter.hasNext();) { 1999 FieldMetaData info = (FieldMetaData) singelIter.next(); 2000 int fieldNo = getFieldNo(info); 2001 buf.append("\t\tif (absField == " + getAbsFieldNo(info) + ") {\n"); 2002 buf.append("\t\t\treturn _" + fieldNo + ";\n"); 2003 buf.append("\t\t} else {\n"); 2004 buf.append("\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 2005 buf.append("\t\t}\n"); 2006 } 2007 } else { 2008 buf.append("\t\tswitch (absField) {\n"); 2009 for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();) { 2010 FieldMetaData info = (FieldMetaData) fieldIter.next(); 2011 int fieldNo = getFieldNo(info); 2012 buf.append("\t\t\tcase " + getAbsFieldNo(info) + ":\n"); 2013 buf.append("\t\t\t\treturn _" + fieldNo + ";\n\n"); 2014 } 2015 buf.append("\t\t\tdefault:\n"); 2017 buf.append("\t\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 2018 buf.append("\t\t}\n"); 2019 } 2020 buf.append("\t}\n"); 2021 spec.addMethod(buf.toString()); 2022 } 2023 2024 protected void addContainsApplicationIdentityFields() { 2025 StringBuffer buf = new StringBuffer (); 2026 buf.append("\n\tpublic final boolean containsApplicationIdentityFields() {\n"); 2027 buf.append("\t\treturn false;\n"); 2028 buf.append("\t}\n"); 2029 spec.addMethod(buf.toString()); 2030 } 2031 2032 protected abstract void addContainsValidAppIdFields(); 2033 2034 protected void addUpdateFrom() { 2035 StringBuffer buf = new StringBuffer (); 2036 2053 buf.append("\n\tpublic final void updateFrom(State state) {\n"); 2054 buf.append("\t\t"+className+" other = ("+ className +") state;\n"); 2055 int num = getNumOfControlFields(); 2056 for (int i = 0; i < num; i++) { 2057 if (i == 0) { 2058 buf.append("\t\tint otherFilled = other.filled0;\n"); 2059 buf.append("\t\tfilled0 |= otherFilled;\n"); 2060 } else { 2061 buf.append("\t\totherFilled = other.filled"+i+";\n"); 2062 buf.append("\t\tfilled"+i+" |= otherFilled;\n"); 2063 } 2064 List fields = getFields(i); 2065 for (Iterator iter = fields.iterator(); iter.hasNext();) { 2066 FieldMetaData fmd = (FieldMetaData) iter.next(); 2067 int fieldNo = fmd.stateFieldNo; 2068 buf.append("\t\tif ((otherFilled & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 2069 buf.append("\t\t\t_"+ fieldNo +" = other._"+ fieldNo +";\n"); 2070 buf.append("\t\t}\n"); 2071 } 2072 } 2073 buf.append("\t}\n"); 2074 spec.addMethod(buf.toString()); 2075 } 2076 2077 protected void addGetCopy() { 2078 StringBuffer buf = new StringBuffer (); 2079 2080 buf.append("\n\tpublic final State getCopy() {\n"); 2097 buf.append("\t\t"+ className +" copy = new "+ className +"();\n"); 2098 int contNum = getNumOfControlFields(); 2099 for (int i = 0; i < contNum; i++) { 2100 buf.append("\t\tcopy.filled"+i+" = filled"+i+";\n"); 2101 } 2102 int num = cmd.stateFields.length; 2103 for (int i = 0; i < num; i++) { 2104 buf.append("\t\tcopy._"+ i +" = _"+ i +";\n"); 2105 } 2106 buf.append("\t\treturn copy;\n"); 2107 buf.append("\t}\n"); 2108 spec.addMethod(buf.toString()); 2109 } 2110 2111 protected void addPrepare() { 2112 StringBuffer buf = new StringBuffer (); 2113 buf.append("\n\tpublic void prepare(PersistenceContext pm, VersantStateManager sm) {\n"); 2114 int num = cmd.stateFields.length; 2115 for (int i = 0; i < num; i++) { 2116 FieldMetaData fmd = cmd.stateFields[i]; 2117 int fieldNum = fmd.stateFieldNo; 2118 2119 boolean doIt = false; 2120 if (fmd.scoField) { 2121 if (fmd.typeCode == MDStatics.DATE) { 2122 doIt = true; 2123 } else { 2124 switch (fmd.category) { 2125 case MDStatics.CATEGORY_ARRAY: 2126 if (fmd.isElementTypePC()) { 2127 doIt = true; 2128 } 2129 break; 2130 case MDStatics.CATEGORY_COLLECTION: 2131 case MDStatics.CATEGORY_MAP: 2132 doIt = true; 2133 break; 2134 default: 2135 throw BindingSupportImpl.getInstance().internal("No logic defined for field type " 2136 + MDStaticUtils.toSimpleName(fmd.typeCode) 2137 + " field name = " + fmd.name); 2138 } 2139 } 2140 } else { 2141 int cat = fmd.category; 2142 if (cat == MDStatics.CATEGORY_EXTERNALIZED) { 2143 doIt = true; 2144 } else if (cat == MDStatics.CATEGORY_REF || cat == MDStatics.CATEGORY_POLYREF) { 2145 doIt = true; 2146 } 2147 } 2148 2149 if (doIt) { boolean isDate = fmd.typeCode == MDStatics.DATE; 2151 if (fmd.scoField) { 2152 if (isDate) { 2153 buf.append("\t\tif (("+ getFilledFieldName(fieldNum) +" & "+ getFieldIndex(fieldNum) +") != 0 && _"+ fieldNum +" != null) {\n"); 2154 buf.append("\t\t\t_"+ fieldNum +" = StateUtil.getPValueForSCO(_"+ fieldNum +");\n"); 2155 buf.append("\t\t}\n"); 2156 } else { 2157 switch (fmd.category) { 2158 case MDStatics.CATEGORY_ARRAY: 2159 buf.append("\t\tif (("+ getFilledFieldName(fieldNum) +" & "+ getFieldIndex(fieldNum) +") != 0 && _"+ fieldNum +" != null && !(_"+ fieldNum +" instanceof OID[])) {\n"); 2160 buf.append("\t\t\t_"+ fieldNum +" = resolveArrayValues((Object[]) _"+ fieldNum +", pm);\n"); 2161 buf.append("\t\t}\n"); 2162 break; 2163 case MDStatics.CATEGORY_COLLECTION: 2164 buf.append("\t\tif ((" + getFilledFieldName(fieldNum) + " & " + getFieldIndex(fieldNum) + ") != 0 && _" + fieldNum + " != null && !(_" + fieldNum + " instanceof OID[])) {\n"); 2165 buf.append("\t\t\t_"+ fieldNum +" = StateUtil.getPValueForSCO((java.util.Collection)_"+ fieldNum +", pm, sm, cmd.stateFields["+ fieldNum +"]);\n"); 2166 buf.append("\t\t}\n"); 2167 break; 2168 case MDStatics.CATEGORY_MAP: 2169 buf.append("\t\tif ((" + getFilledFieldName(fieldNum) + " & " + getFieldIndex(fieldNum) + ") != 0 && _" + fieldNum + " != null && !(_" + fieldNum + " instanceof "+ MapEntries.class.getName() +")) {\n"); 2170 buf.append("\t\t\t_" + fieldNum + " = StateUtil.getPValueForSCO((java.util.Map)_" + fieldNum + ", pm, cmd.stateFields[" + fieldNum + "]);\n"); 2171 buf.append("\t\t}\n"); 2172 break; 2173 case MDStatics.CATEGORY_TRANSACTIONAL: 2174 break; 2175 default: 2176 throw BindingSupportImpl.getInstance().internal("No logic defined for field type " 2177 + MDStaticUtils.toSimpleName(fmd.typeCode) 2178 + " field name = " + fmd.name); 2179 } 2180 } 2181 } else { 2182 int cat = fmd.category; 2183 if (cat == MDStatics.CATEGORY_EXTERNALIZED) { 2184 buf.append("\t\tif ((" + getFilledFieldName(fieldNum) + " & " + getFieldIndex(fieldNum) + ") != 0 && _" + fieldNum + " != null) {\n"); 2185 buf.append("\t\t\t_"+ fieldNum +" = cmd.stateFields["+ fieldNum +"].externalizer.toExternalForm(pm.getPersistenceManager() , _"+ fieldNum +");\n"); 2186 buf.append("\t\t}\n"); 2187 } else if (cat == MDStatics.CATEGORY_REF || cat == MDStatics.CATEGORY_POLYREF) { 2188 if (fmd.embedded) { 2189 buf.append("\t\t_" + fieldNum + " = null;\n"); 2190 } else { 2191 buf.append("\t\tif ((" + getFilledFieldName(fieldNum) + " & "+ getFieldIndex(fieldNum) +") != 0 && (_"+ fieldNum +" instanceof PersistenceCapable)) {\n"); 2192 buf.append("\t\t\t_"+ fieldNum +" = StateUtil.getPValueForRef((PersistenceCapable)_"+ fieldNum +", pm);\n"); 2193 buf.append("\t\t}\n"); 2194 } 2195 } 2196 } 2197 } 2198 } 2199 buf.append("\t}\n"); 2200 spec.addMethod(buf.toString()); 2201 } 2202 2203 protected void addCopyFieldsForOptimisticLocking() { 2204 StringBuffer buf = new StringBuffer (); 2205 2206 buf.append("\n\tpublic final void copyFieldsForOptimisticLocking(State state, VersantPersistenceManagerImp sm) {\n"); 2238 buf.append("\t\t"+className+" s = (" + className + ")state;\n"); 2239 2240 int num = getNumOfControlFields(); 2241 for (int i = 0; i < num; i++) { 2242 if (i == 0) { 2243 buf.append("\t\tint toCheck = ~filled" + i + " & s.filled" + i + ";\n"); 2244 } else { 2245 buf.append("\t\ttoCheck = ~filled" + i + " & s.filled" + i + ";\n"); 2246 } 2247 buf.append("\t\tfilled" + i + " |= toCheck & "+ getPrimativeHashForIndex(i) +";\n"); 2248 List fields = getFields(i); 2249 for (Iterator iter = fields.iterator(); iter.hasNext();) { 2250 FieldMetaData fmd = (FieldMetaData) iter.next(); 2251 int fieldNo = fmd.stateFieldNo; 2252 boolean isPrimative = fmd.type.isPrimitive(); 2253 if (isPrimative) { 2254 buf.append("\t\tif ((toCheck & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 2255 buf.append("\t\t\t_"+ fieldNo +" = s._"+ fieldNo +";\n"); 2256 buf.append("\t\t}\n"); 2257 } else { 2258 buf.append("\t\tif ((toCheck & "+ getFieldIndex(fieldNo) +") != 0 && s._"+ fieldNo +" != null) {\n"); 2259 if (fmd.typeCode == MDStatics.DATE) { buf.append("\t\t\tif ((s."+ getResolvedFieldName(fieldNo) +" & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 2261 buf.append("\t\t\t\t_"+ fieldNo +" = (java.util.Date)s._"+ fieldNo +".clone();\n"); 2262 buf.append("\t\t\t} else {\n"); 2263 buf.append("\t\t\t\t_"+ fieldNo +" = s._" + fieldNo + ";\n"); 2264 buf.append("\t\t\t}\n"); 2265 buf.append("\t\t\t"+ getFilledFieldName(fieldNo) +" |= "+ getFieldIndex(fieldNo) +";\n"); 2266 } else if (fmd.category == MDStatics.CATEGORY_REF 2267 || fmd.category == MDStatics.CATEGORY_POLYREF) { buf.append("\t\t\tif ((s." + getResolvedFieldName(fieldNo) + " & " + getFieldIndex(fieldNo) + ") != 0) {\n"); 2269 buf.append("\t\t\t\t_" + fieldNo + " = sm.getInternalOID((PersistenceCapable)s._" + fieldNo + ");\n"); 2270 buf.append("\t\t\t} else {\n"); 2271 buf.append("\t\t\t\t_" + fieldNo + " = s._" + fieldNo + ";\n"); 2272 buf.append("\t\t\t}\n"); 2273 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 2274 2275 } else { buf.append("\t\t\t_" + fieldNo + " = s._" + fieldNo + ";\n"); 2277 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 2278 } 2279 buf.append("\t\t}\n"); 2280 } 2281 } 2282 } 2283 buf.append("\t}\n"); 2284 spec.addMethod(buf.toString()); 2285 } 2286 2287 protected void addGetFieldNos() { 2288 StringBuffer buf = new StringBuffer (); 2289 2310 buf.append("\n\tpublic final int getFieldNos(int buf[]) {\n"); 2311 buf.append("\t\tint c = 0;\n"); 2312 int num = getNumOfControlFields(); 2313 for (int i = 0; i < num; i++) { 2314 if (i == 0) { 2315 buf.append("\t\tint filled = filled0;\n"); 2316 } else { 2317 buf.append("\t\tfilled = filled"+i+";\n"); 2318 } 2319 List fields = getFields(i); 2320 for (Iterator iter = fields.iterator(); iter.hasNext();) { 2321 FieldMetaData fmd = (FieldMetaData) iter.next(); 2322 int fieldNo = fmd.stateFieldNo; 2323 buf.append("\t\tif ((filled & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 2324 buf.append("\t\t\tbuf[c++] = "+ fieldNo +";\n"); 2325 buf.append("\t\t}\n"); 2326 } 2327 } 2328 buf.append("\t\treturn c;\n"); 2329 buf.append("\t}\n"); 2330 spec.addMethod(buf.toString()); 2331 } 2332 2333 protected void addUpdateNonFilled() { 2334 StringBuffer buf = new StringBuffer (); 2335 2362 buf.append("\n\tpublic final void updateNonFilled(State state) {\n"); 2363 buf.append("\t\t" + className + " s = (" + className + ") state;\n"); 2364 int num = getNumOfControlFields(); 2365 for (int i = 0; i < num; i++) { 2366 if (i == 0) { 2367 buf.append("\t\tint toCheck = ~filled0 & s.filled0;\n"); 2368 buf.append("\t\tfilled0 |= toCheck;\n"); 2369 } else { 2370 buf.append("\t\ttoCheck = ~filled"+i+" & s.filled"+i+";\n"); 2371 buf.append("\t\tfilled"+i+" |= toCheck;\n"); 2372 } 2373 List fields = getFields(i); 2374 for (Iterator iter = fields.iterator(); iter.hasNext();) { 2375 FieldMetaData fmd = (FieldMetaData) iter.next(); 2376 int fieldNo = fmd.stateFieldNo; 2377 String fieldName = getFieldName(fieldNo); 2378 buf.append("\t\tif ((toCheck & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 2379 buf.append("\t\t\t"+ fieldName +" = s."+ fieldName +";\n"); 2380 buf.append("\t\t}\n"); 2381 } 2382 2383 } 2384 buf.append("\t}\n"); 2385 spec.addMethod(buf.toString()); 2386 } 2387 2388 protected void addCopyOptimisticLockingField() { 2389 StringBuffer buf = new StringBuffer (); 2390 2391 2401 buf.append("\n\tpublic final void copyOptimisticLockingField(State state) {\n"); 2402 if (cmd.optimisticLockingField == null){ 2403 buf.append("\t\treturn;\n"); 2404 } else { 2405 buf.append("\t\t" + className + " gState = (" + className + ")state;\n"); 2406 int fieldNo = cmd.optimisticLockingField.stateFieldNo; 2407 String filled = getFilledFieldName(fieldNo); 2408 int index = getFieldIndex(fieldNo); 2409 buf.append("\t\tif ((gState."+ filled +" & "+ index +") != 0) {\n"); 2410 buf.append("\t\t\t_"+ fieldNo +" = gState._"+ fieldNo +";\n"); 2411 buf.append("\t\t\t"+ filled +" |= "+ index +";\n"); 2412 buf.append("\t\t}\n"); 2413 } 2414 buf.append("\t}\n"); 2415 spec.addMethod(buf.toString()); 2416 2417 } 2418 2419 protected void addClearNonFilled() { 2420 StringBuffer buf = new StringBuffer (); 2421 2431 buf.append("\n\tpublic final void clearNonFilled(State state) {\n"); 2432 buf.append("\t\t"+ className +" s = ("+ className +") state;\n"); 2433 int num = getNumOfControlFields(); 2434 int[] masks = new int[num]; 2436 int lenght = cmd.stateFields.length; 2437 for (int i = 0; i < lenght; i++) { 2438 if (cmd.stateFields[i].autoSet != MDStatics.AUTOSET_NO) { 2439 int fieldNum = cmd.stateFields[i].stateFieldNo; 2440 masks[getLocalVarIndex(0, fieldNum)] += getFieldIndex(fieldNum); 2441 } 2442 } 2443 2444 for (int i = 0; i < num; i++) { 2445 if (i == 0) { 2446 buf.append("\t\tint filled = filled0;\n"); 2447 } else { 2448 buf.append("\t\tfilled = filled"+i+";\n"); 2449 } 2450 buf.append("\t\tfilled"+i+" = filled & "+ masks[i] +" | filled & s.filled"+i+";\n"); 2451 } 2452 buf.append("\t}\n"); 2453 spec.addMethod(buf.toString()); 2454 2455 } 2456 2457 protected void addMakeClean() { 2458 StringBuffer buf = new StringBuffer (); 2459 buf.append("\n\tpublic final void makeClean() {\n"); 2465 int num = getNumOfControlFields(); 2466 for (int i = 0; i < num; i++) { 2467 buf.append("\t\tdirtyFields"+i+" = 0;\n"); 2468 } 2469 buf.append("\t}\n"); 2470 spec.addMethod(buf.toString()); 2471 } 2472 2473 protected void addIsResolvedForClient() { 2474 StringBuffer buf = new StringBuffer (); 2475 buf.append("\n\tpublic final boolean isResolvedForClient(int stateFieldNo) {\n"); 2488 int num = getNumOfControlFields(); 2489 if (num == 1) { 2490 buf.append("\t\treturn (resolved0 & 1 << stateFieldNo) != 0;\n"); 2491 } else { 2492 for (int i = 0; i < num; i++) { 2493 buf.append("\t\tif (stateFieldNo < "+ ((32 * i) + 32) +") {\n"); 2494 buf.append("\t\t\treturn (resolved"+i+" & 1 << stateFieldNo) != 0;\n"); 2495 buf.append("\t\t}\n"); 2496 } 2497 buf.append("\t\treturn false;\n"); 2498 } 2499 buf.append("\t}\n"); 2500 spec.addMethod(buf.toString()); 2501 } 2502 2503 protected void addContainsField() { 2504 StringBuffer buf = new StringBuffer (); 2505 2506 buf.append("\n\tpublic final boolean containsField(int fieldNo) {\n"); 2507 int num = getNumOfControlFields(); 2508 if (num == 1) { 2509 buf.append("\t\treturn (filled0 & 1 << fieldNo) != 0;\n"); 2510 } else { 2511 for (int i = 0; i < num; i++) { 2512 buf.append("\t\tif (fieldNo < "+ ((32 * i) + 32) +") {\n"); 2513 buf.append("\t\t\treturn (filled"+ i +" & 1 << fieldNo) != 0;\n"); 2514 buf.append("\t\t}\n"); 2515 } 2516 buf.append("\t\treturn false;\n"); 2517 } 2518 buf.append("\t}\n"); 2519 spec.addMethod(buf.toString()); 2520 } 2521 2522 protected void addEqualsObject() { 2523 StringBuffer buf = new StringBuffer (); 2524 2525 2548 2549 buf.append("\n\tpublic final boolean equals(Object object) {\n"); 2550 buf.append("\t\tif (hashCode() != object.hashCode()) {\n"); 2551 buf.append("\t\t\treturn false;\n"); 2552 buf.append("\t\t}\n"); 2553 buf.append("\t\tif (object instanceof "+ className +") {\n"); 2554 buf.append("\t\t\t"+ className +" other = ("+ className +") object;\n"); 2555 FieldMetaData[] fields = cmd.stateFields; 2556 for (int i = 0; i < fields.length; i++) { 2557 FieldMetaData fmd = fields[i]; 2558 Class classType = fmd.type; 2559 String fieldName = getFieldName(i); 2560 boolean isPrimitive = classType.isPrimitive(); 2561 if (isPrimitive) { 2562 buf.append("\t\t\tif ("+ fieldName +" != other."+ fieldName +") {\n"); 2563 buf.append("\t\t\t\treturn false;\n"); 2564 buf.append("\t\t\t}\n"); 2565 } else { buf.append("\t\t\tif (" + fieldName + " != null) {\n"); 2567 buf.append("\t\t\t\tif (!"+ fieldName +".equals(other."+ fieldName +")) {\n"); 2568 buf.append("\t\t\t\t\treturn false;\n"); 2569 buf.append("\t\t\t\t}\n"); 2570 buf.append("\t\t\t} else if (other."+ fieldName +" != null) {\n"); 2571 buf.append("\t\t\t\treturn false;\n"); 2572 buf.append("\t\t\t}\n"); 2573 } 2574 2575 } 2576 buf.append("\t\t\treturn true;\n"); 2577 buf.append("\t\t} else {\n"); 2578 buf.append("\t\t\treturn false;\n"); 2579 buf.append("\t\t}\n"); 2580 buf.append("\t}\n"); 2581 spec.addMethod(buf.toString()); 2582 } 2583 2584 protected void addHashCode() { 2585 StringBuffer buf = new StringBuffer (); 2586 2590 buf.append("\n\tpublic final int hashCode() {\n"); 2591 buf.append("\t\treturn "+ cmd.classId); 2592 int num = getNumOfControlFields(); 2593 for (int i = 0; i < num; i++) { 2594 buf.append(" + " + FILLED_FIELD_NAME + i); 2595 } 2596 buf.append(";\n"); 2597 buf.append("\t}\n"); 2598 spec.addMethod(buf.toString()); 2599 } 2600 2601 protected void addGetClassIndex() { 2602 StringBuffer buf = new StringBuffer (); 2603 2606 2607 buf.append("\n\tpublic final int getClassIndex() {\n"); 2608 buf.append("\t\treturn "+ cmd.index +";\n"); 2609 buf.append("\t}\n"); 2610 spec.addMethod(buf.toString()); 2611 } 2612 2613 protected void addIsDirtyInt() { 2614 StringBuffer buf = new StringBuffer (); 2615 2616 2629 2630 buf.append("\n\tpublic final boolean isDirty(int fieldNo) {\n"); 2631 int num = getNumOfControlFields(); 2632 if (num == 1) { 2633 buf.append("\t\treturn (dirtyFields0 & 1 << fieldNo) != 0;\n"); 2634 } else { 2635 for (int i = 0; i < num; i++) { 2636 buf.append("\t\tif (fieldNo < "+ ((32 * i) + 32) +") {\n"); 2637 buf.append("\t\t\treturn (dirtyFields"+ i +" & 1 << fieldNo) != 0;\n"); 2638 buf.append("\t\t}\n"); 2639 } 2640 buf.append("\t\treturn false;\n"); 2641 } 2642 buf.append("\t}\n"); 2643 spec.addMethod(buf.toString()); 2644 2645 2646 2647 } 2648 2649 protected void addMakeDirty() { 2650 StringBuffer buf = new StringBuffer (); 2651 2652 2665 2666 buf.append("\n\tpublic final void makeDirty(int fieldNo) {\n"); 2667 int num = getNumOfControlFields(); 2668 if (num == 1) { 2669 buf.append("\t\tdirtyFields0 |= 1 << fieldNo;\n"); 2670 } else { 2671 for (int i = 0; i < num; i++) { 2672 buf.append("\t\tif (fieldNo < "+ ((32 * i) + 32) +") {\n"); 2673 buf.append("\t\t\tdirtyFields"+i+" |= 1 << fieldNo;\n"); 2674 buf.append("\t\t\treturn;\n"); 2675 buf.append("\t\t}\n"); 2676 } 2677 } 2678 buf.append("\t}\n"); 2679 spec.addMethod(buf.toString()); 2680 } 2681 2682 protected void addSetFilled() { 2683 StringBuffer buf = new StringBuffer (); 2684 2685 buf.append("\n\tpublic final void setFilled(int fieldNo) {\n"); 2686 int num = getNumOfControlFields(); 2687 if (num == 1) { 2688 buf.append("\t\tfilled0 |= 1 << fieldNo;\n"); 2689 } else { 2690 for (int i = 0; i < num; i++) { 2691 buf.append("\t\tif (fieldNo < " + ((32 * i) + 32) + ") {\n"); 2692 buf.append("\t\t\tfilled" + i + " |= 1 << fieldNo;\n"); 2693 buf.append("\t\t\treturn;\n"); 2694 buf.append("\t\t}\n"); 2695 } 2696 } 2697 buf.append("\t}\n"); 2698 spec.addMethod(buf.toString()); 2699 2700 } 2701 2702 protected void addClearFilledFlags() { 2703 StringBuffer buf = new StringBuffer (); 2704 buf.append("\n\tpublic final void clearFilledFlags() {\n"); 2708 int num = getNumOfControlFields(); 2709 for (int i = 0; i < num; i++) { 2710 buf.append("\t\tfilled"+i+" = 0;\n"); 2711 } 2712 buf.append("\t}\n"); 2713 spec.addMethod(buf.toString()); 2714 } 2715 2716 protected void addClear() { 2717 StringBuffer buf = new StringBuffer (); 2718 2719 buf.append("\n\tpublic final void clear() {\n"); 2720 int num = getNumOfControlFields(); 2721 for (int i = 0; i < num; i++) { 2722 buf.append("\t\t"+ FILLED_FIELD_NAME +i+" = 0;\n"); 2723 buf.append("\t\t"+ DIRTY_FIELD_NAME +i+" = 0;\n"); 2724 buf.append("\t\t"+ RESOLVED_NAME +i+" = 0;\n"); 2725 } 2726 List objectList = getAllRealObjectFields(); 2727 for (Iterator iter = objectList.iterator(); iter.hasNext();) { 2728 FieldMetaData info = (FieldMetaData) iter.next(); 2729 int fieldNo = getFieldNo(info); 2730 buf.append("\t\t_" + fieldNo + " = null;\n"); 2731 } 2732 buf.append("\t}\n"); 2733 spec.addMethod(buf.toString()); 2734 } 2735 2736 2737 2738 protected void addIsDirty() { 2739 StringBuffer buf = new StringBuffer (); 2740 buf.append("\n\tpublic final boolean isDirty() {\n"); 2744 int num = getNumOfControlFields(); 2745 for (int i = 0; i < num; i++) { 2746 if (i == 0) { 2747 buf.append("\t\treturn dirtyFields0 != 0"); 2748 } else { 2749 buf.append(" || dirtyFields"+i+" != 0"); 2750 } 2751 } 2752 buf.append(";\n"); 2753 buf.append("\t}\n"); 2754 spec.addMethod(buf.toString()); 2755 } 2756 2757 protected void addCopyFields() { 2758 StringBuffer buf = new StringBuffer (); 2759 buf.append("\n\tpublic final void copyFields(OID oid) {\n"); 2760 buf.append("\t}\n"); 2761 spec.addMethod(buf.toString()); 2762 } 2763 2764 2767 protected void addAllSetXXXFields() { 2768 Set keys = classToSetField.keySet(); 2769 for (Iterator typeIter = keys.iterator(); typeIter.hasNext();) { 2770 Class type = (Class ) typeIter.next(); 2771 addSetXXXField(type); 2772 } 2773 addSetObjectField(); 2774 addSetObjectFieldUnresolved(); 2775 } 2776 2777 2780 protected void addAllSetXXXFieldsAbs() { 2781 Set keys = classToSetFieldAbs.keySet(); 2782 for (Iterator typeIter = keys.iterator(); typeIter.hasNext();) { 2783 Class type = (Class ) typeIter.next(); 2784 addSetXXXFieldAbs(type); 2785 } 2786 addSetObjectFieldAbs(); 2787 addSetObjectFieldUnresolvedAbs(); 2788 } 2789 2790 2793 protected void addAllSetInternalXXXFields() { 2794 Set keys = classToInternalSetField.keySet(); 2795 for (Iterator typeIter = keys.iterator(); typeIter.hasNext();) { 2796 Class type = (Class ) typeIter.next(); 2797 addSetInternalXXXField(type); 2798 } 2799 addSetInternalObjectField(); 2800 } 2801 2802 2805 protected void addAllSetInternalXXXFieldsAbs() { 2806 Set keys = classToInternalSetFieldAbs.keySet(); 2807 for (Iterator typeIter = keys.iterator(); typeIter.hasNext();) { 2808 Class type = (Class ) typeIter.next(); 2809 addSetInternalXXXFieldAbs(type); 2810 } 2811 addSetInternalObjectFieldAbs(); 2812 } 2813 2814 2817 protected void addAllGetXXXFields() { 2818 Set keys = getFieldToClass.keySet(); 2819 for (Iterator typeIter = keys.iterator(); typeIter.hasNext();) { 2820 String type = (String ) typeIter.next(); 2821 addGetXXXField(type); 2822 } 2823 } 2824 2825 2828 protected void addAllGetXXXFieldsAbs() { 2829 Set keys = classToGetFieldAbs.keySet(); 2830 for (Iterator typeIter = keys.iterator(); typeIter.hasNext();) { 2831 Class type = (Class ) typeIter.next(); 2832 addGetXXXFieldAbs(type); 2833 } 2834 } 2835 2836 protected String getWriteMethod(int index) { 2837 int newIndex = totalNoOfFields - (index * 32); 2838 if (newIndex <= 8) { 2839 return "writeByte"; 2840 } else if (newIndex <= 16) { 2841 return "writeShort"; 2842 } else { 2843 return "writeInt"; 2844 } 2845 } 2846 2847 protected String getReadMethod(int index) { 2848 int newIndex = totalNoOfFields - (index * 32); 2849 if (newIndex <= 8) { 2850 return "readByte"; 2851 } else if (newIndex <= 16) { 2852 return "readShort"; 2853 } else { 2854 return "readInt"; 2855 } 2856 } 2857 2858 protected String getOIDName(FieldMetaData fmd) { 2859 return fmd.typeMetaData.oidClassName; 2861 } 2862 2863 protected void addWriteExternal() { 2864 StringBuffer buf = new StringBuffer (); 2865 buf.append("\n\tpublic void writeExternal(OIDObjectOutput os) throws java.io.IOException {\n"); 2866 Class bigIntegerType = java.math.BigInteger .class; 2867 boolean isBigInteger = false; for (int i = 0; i < cmd.stateFields.length; i++) { 2869 FieldMetaData info = cmd.stateFields[i]; 2870 if (!isExternalized(info)) { 2871 Class type = info.type; 2872 if (type.equals(bigIntegerType)) { 2873 isBigInteger = true; 2874 } 2875 } 2876 } 2877 if (isBigInteger) { 2878 buf.append("\t\tbyte bytes[] = null;\n"); 2879 } 2880 int num = getNumOfControlFields(); 2881 for (int i = 0; i < num; i++) { 2882 if (i == 0) { 2883 buf.append("\t\tint filled = filled0;\n"); 2884 } else { 2885 buf.append("\t\tfilled = filled"+i+";\n"); 2886 } 2887 if (i == 0) { 2888 buf.append("\t\tint nullFields = getNullFields(0);\n"); 2889 } else { 2890 buf.append("\t\tnullFields = getNullFields("+i+");\n"); 2891 } 2892 buf.append("\t\tos."+ getWriteMethod(i) +"(filled);\n"); 2893 buf.append("\t\tos."+ getWriteMethod(i) +"(nullFields);\n"); 2894 2895 List fields = getFields(i); 2896 for (Iterator iter = fields.iterator(); iter.hasNext();) { 2897 FieldMetaData info = (FieldMetaData) iter.next(); 2898 int fieldNo = info.stateFieldNo; 2899 if (info.category != MDStatics.CATEGORY_TRANSACTIONAL) { 2900 Class type = info.type; 2904 if (isExternalized(info)) { 2905 buf.append("\t\tif ((filled & "+ getFieldIndex(fieldNo) +") != 0 && (nullFields & "+ getFieldIndex(fieldNo) +") == 0) {\n"); 2906 buf.append("\t\t\tSerUtils.writeObject(_" + fieldNo + ", os);\n"); 2907 buf.append("\t\t}\n"); 2908 2909 } else if (info.type.isPrimitive()) { buf.append("\t\tif ((filled & " + getFieldIndex(fieldNo) + ") != 0) {\n"); 2911 buf.append("\t\t\tos."+ primClassToSerWriteMethod.get(type) +"(_"+ fieldNo +");\n"); 2912 buf.append("\t\t}\n"); 2913 } else { buf.append("\t\tif ((filled & " + getFieldIndex(fieldNo) + ") != 0 && (nullFields & " + getFieldIndex(fieldNo) + ") == 0) {\n"); 2915 if (isOID(info) || isPolyRef(info)) { 2916 buf.append("\t\t\tos.write((OID)_"+ fieldNo +");\n"); 2917 } else if (isCollection(info)) { 2918 buf.append("\t\t\tSerUtils.writeCollectionOrMapField(os, cmd.stateFields[" + fieldNo + "], _" + fieldNo + ");\n"); 2919 } else if (isMap(info)) { 2920 buf.append("\t\t\tSerUtils.writeCollectionOrMapField(os, cmd.stateFields[" + fieldNo + "], _" + fieldNo + ");\n"); 2921 } else if (isArray(info)) { 2922 if (isPCArray(info)) { 2923 buf.append("\t\t\tSerUtils.writeArrayField(cmd.stateFields[" + fieldNo + "], os, _" + fieldNo + ");\n"); 2924 } else { 2925 buf.append("\t\t\tSerUtils.writeArrayField("+ info.componentTypeCode +", os, _" + fieldNo + ");\n"); 2926 } 2927 } else { 2928 if (type.equals(String .class)) { 2929 buf.append("\t\tUtils.writeLongUTF8(_" + fieldNo + ", os);\n"); 2930 } else if (type.equals(java.util.Locale .class)) { 2931 buf.append("\t\t\tos.writeUTF(_" + fieldNo + ".getLanguage());\n"); 2932 buf.append("\t\t\tos.writeUTF(_" + fieldNo + ".getCountry());\n"); 2933 buf.append("\t\t\tos.writeUTF(_" + fieldNo + ".getVariant());\n"); 2934 } else if (type.equals(java.math.BigDecimal .class)) { 2935 buf.append("\t\t\tos.writeUTF(_" + fieldNo + ".toString());\n"); 2936 } else if (type.equals(java.math.BigInteger .class)) { 2937 buf.append("\t\t\tbytes = _" + fieldNo + ".toByteArray();\n"); 2938 buf.append("\t\t\tos.writeInt(bytes.length);\n"); 2939 buf.append("\t\t\tos.write(bytes);\n"); 2940 } else if (type.equals(java.util.Date .class)) { 2941 buf.append("\t\t\tos.writeLong(_" + fieldNo + ".getTime());\n"); 2942 } else if (type.equals(java.net.URL .class)) { 2943 buf.append("\t\t\tos.writeUTF(_" + fieldNo + ".toString());\n"); 2944 } else if (type.equals(java.io.File .class)) { 2945 buf.append("\t\t\tos.writeUTF(_" + fieldNo + ".toString());\n"); 2946 } else if (type.equals(java.sql.Timestamp .class)) { 2947 buf.append("\t\t\tos.writeLong(_" + fieldNo + ".getTime());\n"); 2948 } else if (wrapperTypesToPrimative.containsKey(type)) { buf.append("\t\t\tos." + 2950 primClassToSerWriteMethod.get(wrapperTypesToPrimative.get(type)) + 2951 "(_" + fieldNo + "."+ wrapperTypesToValue.get(type) +"());\n"); 2952 } else { 2953 buf.append("\t\t\tSerUtils.writeObject(_" + fieldNo + ", os);\n"); 2954 } 2955 } 2956 buf.append("\t\t}\n"); 2957 } 2958 } 2962 } 2963 } 2964 buf.append("\t}\n"); 2965 spec.addMethod(buf.toString()); 2966 } 2967 2968 protected void addExpect() { 2969 StringBuffer buf = new StringBuffer (); 2970 buf.append( 2971 " private void expect(OIDObjectInput in, String s) throws java.io.IOException {\n" + 2972 " String got;\n" + 2973 " try {\n" + 2974 " got = in.readUTF();\n" + 2975 " } catch (IOException e) {\n" + 2976 " throw new RuntimeException(\"Expected '\" + s +\n" + 2977 " \"': \" + e, e);\n" + 2978 " }\n" + 2979 " if (!s.equals(got)) {\n" + 2980 " throw new RuntimeException(\"Expected '\" + s +\n" + 2981 " \"' got '\" + got + \"'\");\n" + 2982 " }\n" + 2983 " }"); 2984 spec.addMethod(buf.toString()); 2985 } 2986 2987 protected void addReadExternal() { 2988 StringBuffer buf = new StringBuffer (); 2990 buf.append("\n\tpublic void readExternal(OIDObjectInput is) throws java.lang.ClassNotFoundException, java.io.IOException {\n"); 2991 Class bigIntegerType = java.math.BigInteger .class; 2992 boolean isBigInteger = false; for (int i = 0; i < cmd.stateFields.length; i++) { 2994 FieldMetaData info = cmd.stateFields[i]; 2995 if (!isExternalized(info)) { 2996 Class type = info.type; 2997 if (type.equals(bigIntegerType)) { 2998 isBigInteger = true; 2999 } 3000 } 3001 } 3002 if (isBigInteger) { 3003 buf.append("\t\tbyte bytes[] = null;\n"); 3004 } 3005 3006 int num = getNumOfControlFields(); 3007 for (int i = 0; i < num; i++) { 3008 if (i == 0) { 3009 buf.append("\t\tint filled = filled0 = is." + getReadMethod(i) + "();\n"); 3010 } else { 3011 buf.append("\t\tfilled = filled" + i + " = is." + getReadMethod(i) + "();\n"); 3012 } 3013 if (i == 0) { 3014 buf.append("\t\tint nullFields = is." + getReadMethod(i) + "();\n"); 3015 } else { 3016 buf.append("\t\tnullFields = is." + getReadMethod(i) + "();\n"); 3017 } 3018 List fields = getFields(i); 3019 for (Iterator iter = fields.iterator(); iter.hasNext();) { 3020 FieldMetaData info = (FieldMetaData) iter.next(); 3021 int fieldNo = info.stateFieldNo; 3022 if (info.category != MDStatics.CATEGORY_TRANSACTIONAL) { 3023 Class type = info.type; 3027 if (isExternalized(info)) { 3028 buf.append("\t\tif ((filled & "+ getFieldIndex(fieldNo) +") != 0 && (nullFields & "+ getFieldIndex(fieldNo) +") == 0) {\n"); 3029 buf.append("\t\t\t_"+ fieldNo +" = SerUtils.readObject(is);\n"); 3030 buf.append("\t\t}\n"); 3031 } else if (type.isPrimitive()) { buf.append("\t\tif ((filled & "+ getFieldIndex(fieldNo) +") != 0) {\n"); 3033 buf.append("\t\t\t_"+ fieldNo +" = is."+ primClassToSerReadMethod.get(type) +"();\n"); 3034 buf.append("\t\t}\n"); 3035 } else { buf.append("\t\tif ((filled & " + getFieldIndex(fieldNo) + ") != 0 && (nullFields & " + getFieldIndex(fieldNo) + ") == 0) {\n"); 3037 3038 if (isOID(info) || isPolyRef(info)) { 3040 buf.append("\t\t\t_" + fieldNo + " = is.readOID();\n"); 3041 } else if (isCollection(info)) { 3042 buf.append("\t\t\t_" + fieldNo + " = SerUtils.readCollectionOrMapField(is, cmd.stateFields[" + fieldNo + "]);\n"); 3043 } else if (isMap(info)) { 3044 buf.append("\t\t\t_" + fieldNo + " = SerUtils.readCollectionOrMapField(is, cmd.stateFields[" + fieldNo + "]);\n"); 3045 } else if (isArray(info)) { 3046 if (isPCArray(info)) { 3047 buf.append("\t\t\t_" + fieldNo + " = SerUtils.readArrayField(cmd.stateFields[" + fieldNo + "], is);\n"); 3048 } else { 3049 buf.append("\t\t\t_" + fieldNo + " = SerUtils.readArrayField("+ info.componentTypeCode +", is);\n"); 3050 } 3051 } else { 3052 if (type.equals(String .class)) { 3053 buf.append("\t\t\t_" + fieldNo + " = Utils.readLongUTF8(is);\n"); 3054 } else if (type.equals(java.util.Locale .class)) { 3055 buf.append("\t\t\t_" + fieldNo + " = new java.util.Locale(is.readUTF(), is.readUTF(), is.readUTF());\n"); 3056 } else if (type.equals(java.math.BigDecimal .class)) { 3057 buf.append("\t\t\t_" + fieldNo + " = new java.math.BigDecimal(is.readUTF());\n"); 3058 } else if (type.equals(java.math.BigInteger .class)) { 3059 buf.append("\t\t\tbytes = new byte[is.readInt()];\n"); 3060 buf.append("\t\t\tis.readFully(bytes);\n"); 3061 buf.append("\t\t\t_" + fieldNo + " = new java.math.BigInteger(bytes);\n"); 3062 } else if (type.equals(java.util.Date .class)) { 3063 buf.append("\t\t\t_" + fieldNo + " = new java.util.Date(is.readLong());\n"); 3064 } else if (type.equals(java.net.URL .class)) { 3065 buf.append("\t\t\t_" + fieldNo + " = new java.net.URL(is.readUTF());\n"); 3066 } else if (type.equals(java.io.File .class)) { 3067 buf.append("\t\t\t_" + fieldNo + " = new java.io.File(is.readUTF());\n"); 3068 } else if (type.equals(java.sql.Timestamp .class)) { 3069 buf.append("\t\t\t_" + fieldNo + " = new java.sql.Timestamp(is.readLong());\n"); 3070 } else if (wrapperTypesToPrimative.containsKey(type)) { buf.append("\t\t_" + fieldNo + " = new "+ type.getName() +"(is."+ primClassToSerReadMethod.get(wrapperTypesToPrimative.get(type)) +"());\n"); 3072 } else { 3073 buf.append("\t\t\t_" + fieldNo + " = ("+type.getName()+")SerUtils.readObject(is);\n"); 3074 3075 } 3076 } 3077 buf.append("\t\t}\n"); 3078 } 3079 } 3083 } 3084 } 3085 buf.append("\t}\n"); 3086 spec.addMethod(buf.toString()); 3087 } 3088 3089 3093 protected void addConstructor() { 3094 StringBuffer buf = new StringBuffer (); 3095 buf.append("\n\tpublic "); 3096 buf.append(className); 3097 buf.append("(){\n\t}\n"); 3098 spec.addMethod(buf.toString()); 3099 } 3100 3101 3108 protected void addNewInstance() { 3109 StringBuffer buf = new StringBuffer (); 3110 3111 3116 buf.append("\n\tpublic final State newInstance() {\n"); 3117 buf.append("\t\treturn new "); 3118 buf.append(className); 3119 buf.append("();\n\t}\n"); 3120 spec.addMethod(buf.toString()); 3121 } 3122 3123 3129 protected void addFields() { 3130 spec.addField("public static "+ CLASS_META_DATA_CLASS + " cmd"); 3131 int num = getNumOfControlFields(); 3132 for (int i = 0; i < num; i++) { 3133 spec.addField("public int " + FILLED_FIELD_NAME + i); 3134 spec.addField("public int " + DIRTY_FIELD_NAME + i); 3135 spec.addField("public int " + RESOLVED_NAME + i); 3136 } 3137 FieldMetaData[] fields = cmd.stateFields; 3138 for (int i = 0; i < fields.length; i++) { 3139 if (isObject(fields[i])) { spec.addField("public Object " + getFieldName(i)); 3141 } else { 3142 spec.addField("public " + fields[i].type.getName() + " " + getFieldName(i)); 3143 } 3144 } 3145 } 3146 3147 3151 protected List getFields(Class type) { 3152 ArrayList list = new ArrayList(); 3153 FieldMetaData[] fields = cmd.stateFields; 3154 for (int i = 0; i < fields.length; i++) { 3155 FieldMetaData field = fields[i]; 3156 if (field.type.equals(type)) { 3157 list.add(field); 3158 } 3159 } 3160 return list; 3161 } 3162 3163 3167 3168 protected List getFieldsAbs(Class type) { 3169 ArrayList list = new ArrayList(); 3170 FieldMetaData[] fields = cmd.stateFields; 3171 for (int i = 0; i < fields.length; i++) { 3172 FieldMetaData field = fields[i]; 3173 if (field.type.equals(type)) { 3174 if (field.managedFieldNo != -1) { 3175 list.add(field); 3176 } 3177 } 3178 } 3179 return list; 3180 } 3181 3182 3183 3184 3187 protected List getObjectFields() { ArrayList list = new ArrayList(); 3189 FieldMetaData[] fields = cmd.stateFields; 3190 for (int i = 0; i < fields.length; i++) { 3191 FieldMetaData field = fields[i]; 3192 if (!getFieldToClass.containsValue(field.type)) { 3193 list.add(field); 3194 } 3195 } 3196 return list; 3197 } 3198 3199 3202 protected List getObjectFieldsAbs() { ArrayList list = new ArrayList(); 3204 FieldMetaData[] fields = cmd.stateFields; 3205 for (int i = 0; i < fields.length; i++) { 3206 FieldMetaData field = fields[i]; 3207 if (!getFieldToClass.containsValue(field.type)) { 3208 if (field.managedFieldNo != -1) { 3209 list.add(field); 3210 } 3211 } 3212 } 3213 return list; 3214 } 3215 3216 3219 protected List getObjectFieldsMetaData() { ArrayList list = new ArrayList(); 3221 FieldMetaData[] fields = cmd.stateFields; 3222 for (int i = 0; i < fields.length; i++) { 3223 FieldMetaData field = fields[i]; 3224 if (!nonObjectClassTypeList.contains(field.type)) { 3225 list.add(field); 3226 } 3227 } 3228 return list; 3229 } 3230 3231 3234 protected List getObjectFieldsMetaDataAbs() { ArrayList list = new ArrayList(); 3236 FieldMetaData[] fields = cmd.stateFields; 3237 for (int i = 0; i < fields.length; i++) { 3238 FieldMetaData field = fields[i]; 3239 if (!nonObjectClassTypeList.contains(field.type)) { 3240 if (field.managedFieldNo != -1) { 3241 list.add(field); 3242 } 3243 } 3244 } 3245 return list; 3246 } 3247 3248 protected List getAllRealObjectFields() { 3249 ArrayList list = new ArrayList(); 3250 FieldMetaData[] fields = cmd.stateFields; 3251 for (int i = 0; i < fields.length; i++) { 3252 FieldMetaData field = fields[i]; 3253 if (!realNonObjectClassTypeList.contains(field.type)) { 3254 list.add(field); 3255 } 3256 } 3257 return list; 3258 } 3259 3260 protected List getRealObjectFields(int index) { 3261 int to = ((index + 1) * 32) - 1; 3262 int from = (index * 32) - 1; 3263 ArrayList list = new ArrayList(); 3264 FieldMetaData[] fields = cmd.stateFields; 3265 for (int i = 0; i < fields.length; i++) { 3266 FieldMetaData field = fields[i]; 3267 if (!realNonObjectClassTypeList.contains(field.type)) { 3268 if (field.stateFieldNo > from && field.stateFieldNo <= to) { 3269 list.add(field); 3270 } 3271 } 3272 } 3273 return list; 3274 } 3275 3276 protected int getPrimaryHash(int index) { 3277 int hash = 0; 3278 List list = getPrimaryFields(index); 3279 for (Iterator iter = list.iterator(); iter.hasNext();) { 3280 FieldMetaData fmd = (FieldMetaData) iter.next(); 3281 hash += getFieldIndex(fmd.stateFieldNo); 3282 } 3283 return hash; 3284 } 3285 3286 protected int getSecondaryHash(int index) { 3287 int hash = 0; 3288 List list = getSecondaryFields(index); 3289 for (Iterator iter = list.iterator(); iter.hasNext();) { 3290 FieldMetaData fmd = (FieldMetaData) iter.next(); 3291 hash += getFieldIndex(fmd.stateFieldNo); 3292 } 3293 return hash; 3294 } 3295 3296 protected List getPrimaryFields(int index) { 3297 ArrayList primFields = new ArrayList(); 3298 List list = getFields(index); 3299 for (Iterator iter = list.iterator(); iter.hasNext();) { 3300 FieldMetaData fmd = (FieldMetaData) iter.next(); 3301 if (fmd.primaryField) { 3302 primFields.add(fmd); 3303 } 3304 } 3305 return primFields; 3306 } 3307 3308 protected List getPrimaryFields() { 3309 ArrayList primFields = new ArrayList(); 3310 FieldMetaData[] fields = cmd.stateFields; 3311 primFields.ensureCapacity(fields.length); 3312 for (int i = 0; i < fields.length; i++) { 3313 FieldMetaData fmd = fields[i]; 3314 if (fmd.primaryField) { 3315 primFields.add(fmd); 3316 } 3317 } 3318 return primFields; 3319 } 3320 3321 protected List getSecondaryFields() { 3322 ArrayList primFields = new ArrayList(); 3323 FieldMetaData[] fields = cmd.stateFields; 3324 primFields.ensureCapacity(fields.length); 3325 for (int i = 0; i < fields.length; i++) { 3326 FieldMetaData fmd = fields[i]; 3327 if (fmd.secondaryField) { 3328 primFields.add(fmd); 3329 } 3330 } 3331 return primFields; 3332 } 3333 3334 protected List getSecondaryFields(int index) { 3335 ArrayList primFields = new ArrayList(); 3336 List list = getFields(index); 3337 for (Iterator iter = list.iterator(); iter.hasNext();) { 3338 FieldMetaData fmd = (FieldMetaData) iter.next(); 3339 if (fmd.secondaryField) { 3340 primFields.add(fmd); 3341 } 3342 } 3343 return primFields; 3344 } 3345 3346 protected List getFields(int index) { 3347 int to = ((index + 1) * 32) - 1; 3348 int from = (index * 32) - 1; 3349 ArrayList list = new ArrayList(); 3350 FieldMetaData[] fields = cmd.stateFields; 3351 for (int i = 0; i < fields.length; i++) { 3352 FieldMetaData field = fields[i]; 3353 if (field.stateFieldNo > from && field.stateFieldNo <= to) { 3354 list.add(field); 3355 } 3356 } 3357 return list; 3358 } 3359 3360 protected int getPrimativeHashForIndex(int index) { 3361 int hash = 0; 3362 int to = ((index + 1) * 32) - 1; 3363 int from = (index * 32) - 1; 3364 FieldMetaData[] fields = cmd.stateFields; 3365 for (int i = 0; i < fields.length; i++) { 3366 FieldMetaData field = fields[i]; 3367 if (field.stateFieldNo > from && field.stateFieldNo <= to) { 3368 if (field.type.isPrimitive()) { 3369 hash += getFieldIndex(field.stateFieldNo); 3370 } 3371 } 3372 } 3373 return hash; 3374 } 3375 3376 protected List getPass1Fields(int index) { 3377 int to = ((index + 1) * 32) - 1; 3378 int from = (index * 32) - 1; 3379 ArrayList list = new ArrayList(); 3380 FieldMetaData[] fields = cmd.stateFields; 3381 for (int i = 0; i < fields.length; i++) { 3382 FieldMetaData field = fields[i]; 3383 if (field.stateFieldNo > from && field.stateFieldNo <= to) { 3384 if (field.primaryField) { 3385 list.add(field); 3386 } 3387 } 3388 } 3389 return list; 3390 } 3391 3392 protected List getPass2Fields(int index) { 3393 int to = ((index + 1) * 32) - 1; 3394 int from = (index * 32) - 1; 3395 ArrayList list = new ArrayList(); 3396 FieldMetaData[] fields = cmd.stateFields; 3397 for (int i = 0; i < fields.length; i++) { 3398 FieldMetaData field = fields[i]; 3399 if (field.stateFieldNo > from && field.stateFieldNo <= to) { 3400 if (field.secondaryField) { 3401 list.add(field); 3402 } 3403 } 3404 } 3405 return list; 3406 } 3407 3408 protected List getOIDsFieldsMetaData() { 3409 ArrayList list = new ArrayList(); 3410 FieldMetaData[] fields = cmd.stateFields; 3411 for (int i = 0; i < fields.length; i++) { 3412 FieldMetaData field = fields[i]; 3413 if (field.category == MDStatics.CATEGORY_REF 3414 || field.category == MDStatics.CATEGORY_POLYREF) { 3415 list.add(field); 3416 } 3417 } 3418 return list; 3419 } 3420 3421 protected List getPass1FieldAndRefOrPolyRefFields(int index) { 3422 int to = ((index + 1) * 32) - 1; 3423 int from = (index * 32) - 1; 3424 ArrayList list = new ArrayList(); 3425 FieldMetaData[] fields = cmd.stateFields; 3426 for (int i = 0; i < fields.length; i++) { 3427 FieldMetaData field = fields[i]; 3428 if (field.stateFieldNo > from && field.stateFieldNo <= to) { 3429 if (field.primaryField) { 3430 if (field.category == MDStatics.CATEGORY_REF || 3431 field.category == MDStatics.CATEGORY_POLYREF) { 3432 list.add(field); 3433 } 3434 } 3435 } 3436 } 3437 return list; 3438 } 3439 3440 protected LinkedList getDirectRefFieldsMetaData() { 3441 LinkedList list = new LinkedList(); 3443 FieldMetaData[] fields = cmd.stateFields; 3444 for (int i = 0; i < fields.length; i++) { 3445 FieldMetaData field = fields[i]; 3446 if (field.isDirectRef()) { 3447 list.add(field); 3448 } 3449 } 3450 3451 return list; 3452 } 3453 3454 protected List getPass1FieldsMetaData() { 3455 ArrayList list = new ArrayList(); 3456 FieldMetaData[] fields = cmd.stateFields; 3457 list.ensureCapacity(fields.length); 3458 for (int i = 0; i < fields.length; i++) { 3459 FieldMetaData field = fields[i]; 3460 if (field.primaryField) { 3461 list.add(field); 3462 } 3463 } 3464 return list; 3465 } 3466 3467 3472 protected void addGetXXXField(String methodName) { 3473 StringBuffer buf = new StringBuffer (); 3474 Class type = (Class ) getFieldToClass.get(methodName); 3475 buf.append("\n\tpublic final "+ type.getName() +" "+ methodName +"(int field){\n"); 3476 List fields = getFields(type); 3477 if (fields.isEmpty()) { 3478 buf.append("\t\tthrow new "+ FIELD_NOT_FOUND_EXCEPTION +"(\"There were no " + 3479 type.toString() + " fields found for field number \"+field);\n"); 3480 } else if (fields.size() == 1) { 3481 for (Iterator singelIter = fields.iterator(); singelIter.hasNext();) { 3482 FieldMetaData info = (FieldMetaData) singelIter.next(); 3483 buf.append("\t\tif (field == " + getFieldNo(info) + ") {\n"); 3484 buf.append("\t\t\treturn "+ getFieldName(getFieldNo(info)) +";\n"); 3485 buf.append("\t\t} else {\n"); 3486 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3487 "(\"The specified " + type.toString() + 3488 " field was not found for field number \"+field);\n\t\t}\n"); 3489 } 3490 } else { 3491 buf.append("\t\tswitch (field) {\n"); 3492 for (Iterator fieldIter = fields.iterator();fieldIter.hasNext();) { 3493 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3494 buf.append("\t\t\tcase " + getFieldNo(info) + ":\n"); 3495 buf.append("\t\t\t\treturn " + getFieldName(getFieldNo(info)) + ";\n\n"); 3496 } 3497 buf.append("\t\t\tdefault:\n"); 3498 buf.append("\t\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3499 "(\"The specified " + type.toString() + 3500 " field was not found for field number \"+field);\n\t\t}\n"); 3501 } 3502 buf.append("\t}\n"); 3503 spec.addMethod(buf.toString()); 3504 } 3505 3506 3507 3508 3509 3514 protected void addGetXXXFieldAbs(Class type) { 3515 StringBuffer buf = new StringBuffer (); 3516 buf.append("\n\tpublic final " + type.getName() + " " + 3517 (String ) classToGetFieldAbs.get(type) + "(int absField){\n"); 3518 List fields = getFieldsAbs(type); 3519 if (fields.isEmpty()) { 3520 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + "(\"There were no " + 3521 type.toString() + " fields found for field number \"+absField);\n"); 3522 } else if (fields.size() == 1) { 3523 for (Iterator singelIter = fields.iterator(); singelIter.hasNext();) { 3524 FieldMetaData info = (FieldMetaData) singelIter.next(); 3525 buf.append("\t\tif (absField == " + getAbsFieldNo(info) + ") {\n"); 3526 buf.append("\t\t\treturn " + getFieldName(getFieldNo(info)) + ";\n"); 3527 buf.append("\t\t} else {\n"); 3528 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3529 "(\"The specified " + type.toString() + 3530 " field was not found for field number \"+absField);\n\t\t}\n"); 3531 } 3532 } else { 3533 buf.append("\t\tswitch (absField) {\n"); 3534 for (Iterator fieldIter = fields.iterator(); fieldIter.hasNext();) { 3535 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3536 buf.append("\t\t\tcase " + getAbsFieldNo(info) + ":\n"); 3537 buf.append("\t\t\t\treturn " + getFieldName(getFieldNo(info)) + ";\n\n"); 3538 } 3539 buf.append("\t\t\tdefault:\n"); 3540 buf.append("\t\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3541 "(\"The specified " + type.toString() + 3542 " field was not found for absField number \"+absField);\n\t\t}\n"); 3543 } 3544 buf.append("\t}\n"); 3545 spec.addMethod(buf.toString()); 3546 } 3547 3548 3553 protected void addSetXXXField(Class type) { 3554 StringBuffer buf = new StringBuffer (); 3555 buf.append("\n\tpublic final void " + (String ) classToSetField.get(type) + 3556 "(int field," + type.getName() + " newValue){\n"); 3557 List fields = getFields(type); 3558 if (fields.isEmpty()) { 3559 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3560 "(\"There were no " + type.toString() + " fields found to set.\");\n"); 3561 } else if (fields.size() == 1) { 3562 for (Iterator singelIter = fields.iterator(); 3563 singelIter.hasNext();) { 3564 FieldMetaData info = (FieldMetaData) singelIter.next(); 3565 int fieldNo = getFieldNo(info); 3566 buf.append("\t\tif(field == " + fieldNo + "){\n "); 3567 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3568 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3569 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3570 buf.append("\t\t} else {\n"); 3571 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3572 "(\"The specified " + type.toString() + " field was not found.\");\n"); 3573 buf.append("\t\t}\n"); 3574 } 3575 } else { 3576 buf.append("\t\tswitch(field){\n"); 3577 for (Iterator fieldIter = fields.iterator(); 3578 fieldIter.hasNext();) { 3579 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3580 int fieldNo = getFieldNo(info); 3581 buf.append("\t\tcase " + getFieldNo(info) + ":\n"); 3582 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3583 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3584 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3585 buf.append("\t\t\tbreak;\n\n"); 3586 } 3587 buf.append("\t\tdefault:\n"); 3589 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3590 "(\"The specified " + type.toString() + 3591 " field was not found for field number \"+field);\n\t\t}\n"); 3592 } 3593 buf.append("\t}\n"); 3594 spec.addMethod(buf.toString()); 3595 } 3596 3597 3602 protected void addSetXXXFieldAbs(Class type) { 3603 StringBuffer buf = new StringBuffer (); 3604 buf.append("\n\tpublic final void " + (String ) classToSetFieldAbs.get(type) + 3605 "(int absField," + type.getName() + " newValue){\n"); 3606 List fields = getFieldsAbs(type); 3607 if (fields.isEmpty()) { 3608 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3609 "(\"There were no " + type.toString() + " absField found to set.\");\n"); 3610 } else if (fields.size() == 1) { 3611 for (Iterator singelIter = fields.iterator(); 3612 singelIter.hasNext();) { 3613 FieldMetaData info = (FieldMetaData) singelIter.next(); 3614 int fieldNo = getFieldNo(info); 3615 buf.append("\t\tif(absField == " + getAbsFieldNo(info) + "){\n "); 3616 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3617 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3618 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3619 buf.append("\t\t} else {\n"); 3620 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3621 "(\"The specified " + type.toString() + " absField was not found.\");\n"); 3622 buf.append("\t\t}\n"); 3623 } 3624 } else { 3625 buf.append("\t\tswitch(absField){\n"); 3626 for (Iterator fieldIter = fields.iterator(); 3627 fieldIter.hasNext();) { 3628 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3629 int fieldNo = getFieldNo(info); 3630 buf.append("\t\tcase " + getAbsFieldNo(info) + ":\n"); 3631 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3632 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3633 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3634 buf.append("\t\t\tbreak;\n\n"); 3635 } 3636 buf.append("\t\tdefault:\n"); 3638 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3639 "(\"The specified " + type.toString() + 3640 " field was not found for absField number \"+absField);\n\t\t}\n"); 3641 } 3642 buf.append("\t}\n"); 3643 spec.addMethod(buf.toString()); 3644 } 3645 3646 3649 protected void addSetObjectFieldUnresolved() { 3650 StringBuffer buf = new StringBuffer (); 3651 3652 buf.append("\n\tpublic final void setObjectFieldUnresolved(int field,Object newValue){\n"); 3653 List fields = getObjectFields(); 3654 if (fields.isEmpty()) { 3655 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3656 "(\"There were no Object fields found to set.\");\n"); 3657 } else if (fields.size() == 1) { 3658 for (Iterator singelIter = fields.iterator(); 3659 singelIter.hasNext();) { 3660 FieldMetaData info = (FieldMetaData) singelIter.next(); 3661 int fieldNo = getFieldNo(info); 3662 buf.append("\t\tif(field == " + fieldNo + "){\n "); 3663 if (isObject(info)) { 3664 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3665 } else { 3666 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3667 } 3668 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3669 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " &= " + getFieldIndexMask(fieldNo) + ";\n"); 3670 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3671 3672 buf.append("\t\t} else {\n"); 3673 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3674 "(\"The specified " + info.type.getName() + " field was not found.\");\n"); 3675 buf.append("\t\t}\n"); 3676 } 3677 } else { 3678 buf.append("\t\tswitch(field){\n"); 3679 for (Iterator fieldIter = fields.iterator(); 3680 fieldIter.hasNext();) { 3681 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3682 int fieldNo = getFieldNo(info); 3683 buf.append("\t\tcase " + getFieldNo(info) + ":\n"); 3684 3685 3686 if (isObject(info)) { 3687 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3688 } else { 3689 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3690 } 3691 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3692 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " &= " + getFieldIndexMask(fieldNo) + ";\n"); 3693 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3694 3695 buf.append("\t\t\tbreak;\n\n"); 3696 } 3697 buf.append("\t\tdefault:\n"); 3699 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3700 "(\"The specified Object field was not found for field number \"+field);\n\t\t}\n"); 3701 3702 } 3703 buf.append("\t}\n"); 3704 spec.addMethod(buf.toString()); 3705 } 3706 3707 3710 protected void addSetObjectField() { 3711 StringBuffer buf = new StringBuffer (); 3712 buf.append("\n\tpublic final void setObjectField(int field, Object newValue){\n"); 3713 List fields = getObjectFields(); 3714 if (fields.isEmpty()) { 3715 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3716 "(\"There were no Object fields found to set.\");\n"); 3717 } else if (fields.size() == 1) { 3718 for (Iterator singelIter = fields.iterator(); 3719 singelIter.hasNext();) { 3720 FieldMetaData info = (FieldMetaData) singelIter.next(); 3721 int fieldNo = getFieldNo(info); 3722 buf.append("\t\tif(field == " + fieldNo + "){\n "); 3723 if (isObject(info)) { 3724 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3725 } else { 3726 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3727 } 3728 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3729 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3730 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3731 3732 3733 3734 buf.append("\t\t} else {\n"); 3735 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3736 "(\"The specified " + info.type.getName() + " field was not found.\");\n"); 3737 buf.append("\t\t}\n"); 3738 } 3739 } else { 3740 buf.append("\t\tswitch(field){\n"); 3741 for (Iterator fieldIter = fields.iterator(); 3742 fieldIter.hasNext();) { 3743 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3744 int fieldNo = getFieldNo(info); 3745 buf.append("\t\tcase " + getFieldNo(info) + ":\n"); 3746 3747 3748 if (isObject(info)) { 3749 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3750 } else { 3751 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3752 } 3753 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3754 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3755 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3756 3757 buf.append("\t\t\tbreak;\n\n"); 3758 } 3759 buf.append("\t\tdefault:\n"); 3761 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3762 "(\"The specified Object field was not found for field number \"+field);\n\t\t}\n"); 3763 3764 } 3765 buf.append("\t}\n"); 3766 spec.addMethod(buf.toString()); 3767 } 3768 3769 3772 protected void addSetObjectFieldUnresolvedAbs() { 3773 StringBuffer buf = new StringBuffer (); 3774 3775 buf.append("\n\tpublic final void setObjectFieldUnresolvedAbs(int absfield,Object newValue){\n"); 3776 List fields = getObjectFieldsAbs(); 3777 if (fields.isEmpty()) { 3778 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3779 "(\"There were no Object fields found to set.\");\n"); 3780 } else if (fields.size() == 1) { 3781 for (Iterator singelIter = fields.iterator(); 3782 singelIter.hasNext();) { 3783 FieldMetaData info = (FieldMetaData) singelIter.next(); 3784 int fieldNo = getFieldNo(info); 3785 buf.append("\t\tif(absfield == " + getAbsFieldNo(info) + "){\n "); 3786 if (isObject(info)) { 3787 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3788 } else { 3789 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3790 } 3791 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3792 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " &= " + getFieldIndexMask(fieldNo) + ";\n"); 3793 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3794 3795 buf.append("\t\t} else {\n"); 3796 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3797 "(\"The specified " + info.type.getName() + " field was not found.\");\n"); 3798 buf.append("\t\t}\n"); 3799 } 3800 } else { 3801 buf.append("\t\tswitch(absfield){\n"); 3802 for (Iterator fieldIter = fields.iterator(); 3803 fieldIter.hasNext();) { 3804 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3805 int fieldNo = getFieldNo(info); 3806 buf.append("\t\tcase " + getAbsFieldNo(info) + ":\n"); 3807 if (isObject(info)) { 3808 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3809 } else { 3810 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3811 } 3812 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3813 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " &= " + getFieldIndexMask(fieldNo) + ";\n"); 3814 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3815 3816 buf.append("\t\t\tbreak;\n\n"); 3817 } 3818 buf.append("\t\tdefault:\n"); 3820 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3821 "(\"The specified Object field was not found for field number \"+absfield);\n\t\t}\n"); 3822 3823 } 3824 buf.append("\t}\n"); 3825 spec.addMethod(buf.toString()); 3826 } 3827 3828 3831 protected void addSetObjectFieldAbs() { 3832 StringBuffer buf = new StringBuffer (); 3833 3834 buf.append("\n\tpublic final void setObjectFieldAbs(int absfield, Object newValue){\n"); 3835 List fields = getObjectFieldsAbs(); 3836 if (fields.isEmpty()) { 3837 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3838 "(\"There were no Object fields found to set.\");\n"); 3839 } else if (fields.size() == 1) { 3840 for (Iterator singelIter = fields.iterator(); 3841 singelIter.hasNext();) { 3842 FieldMetaData info = (FieldMetaData) singelIter.next(); 3843 int fieldNo = getFieldNo(info); 3844 buf.append("\t\tif(absfield == " + getAbsFieldNo(info) + "){\n "); 3845 if (isObject(info)) { 3846 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3847 } else { 3848 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3849 } 3850 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3851 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3852 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3853 3854 buf.append("\t\t} else {\n"); 3855 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3856 "(\"The specified " + info.type.getName() + " field was not found.\");\n"); 3857 buf.append("\t\t}\n"); 3858 } 3859 } else { 3860 buf.append("\t\tswitch(absfield){\n"); 3861 for (Iterator fieldIter = fields.iterator(); 3862 fieldIter.hasNext();) { 3863 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3864 int fieldNo = getFieldNo(info); 3865 buf.append("\t\tcase " + getAbsFieldNo(info) + ":\n"); 3866 3867 if (isObject(info)) { 3868 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3869 } else { 3870 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 3871 } 3872 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3873 buf.append("\t\t\t" + getResolvedFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3874 buf.append("\t\t\t" + getDirtyFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3875 3876 buf.append("\t\t\tbreak;\n\n"); 3877 } 3878 buf.append("\t\tdefault:\n"); 3880 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3881 "(\"The specified Object field was not found for field number \"+absfield);\n\t\t}\n"); 3882 3883 } 3884 buf.append("\t}\n"); 3885 spec.addMethod(buf.toString()); 3886 } 3887 3888 protected void addHasSameFields() { 3889 StringBuffer buf = new StringBuffer (); 3890 3891 3897 3898 buf.append("\n\tpublic final boolean hasSameFields(State state){\n"); 3899 buf.append("\t\t"+ className + " s = ("+className+")state;\n"); 3900 int num = getNumOfControlFields(); 3901 for (int i = 0; i < num; i++) { 3902 if (i == 0) { 3903 buf.append("\t\treturn (filled0 ^ s.filled0) == 0"); 3904 } else { 3905 buf.append(" && (filled"+i+" ^ s.filled"+i+") == 0"); 3906 } 3907 } 3908 buf.append(";\n"); 3909 buf.append("\t}\n"); 3910 spec.addMethod(buf.toString()); 3911 } 3912 3913 3918 protected void addSetInternalXXXField(Class type) { 3919 StringBuffer buf = new StringBuffer (); 3920 buf.append("\n\tpublic final void " + (String ) classToInternalSetField.get(type) + 3921 "(int field,"+ type.getName() +" newValue){\n"); 3922 List fields = getFields(type); 3923 if (fields.isEmpty()) { 3924 buf.append("\t\tthrow new "+ FIELD_NOT_FOUND_EXCEPTION+ 3925 "(\"There were no " + type.toString() + " fields found to set.\");\n\t}\n"); 3926 } else if (fields.size() == 1) { 3927 for (Iterator singelIter = fields.iterator(); 3928 singelIter.hasNext();) { 3929 FieldMetaData info = (FieldMetaData) singelIter.next(); 3930 int fieldNo = getFieldNo(info); 3931 buf.append("\t\tif(field == "+ fieldNo +"){\n "); 3932 buf.append("\t\t\t"+ getFieldName(fieldNo) +" = newValue;\n"); 3933 buf.append("\t\t\t"+ getFilledFieldName(fieldNo) +" |= "+ getFieldIndex(fieldNo) +";\n"); 3934 buf.append("\t\t} else {\n"); 3935 buf.append("\t\t\tthrow new JDOFatalInternalException(\"The specified " + type.getName() + " field was not found.\");\n"); 3936 buf.append("\t\t}\n"); 3937 buf.append("\t}\n"); 3938 } 3939 } else { 3940 buf.append("\t\tswitch(field){\n"); 3941 for (Iterator fieldIter = fields.iterator(); 3942 fieldIter.hasNext();) { 3943 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3944 int fieldNo = getFieldNo(info); 3945 buf.append("\t\tcase " + getFieldNo(info) + ":\n"); 3946 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3947 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3948 buf.append("\t\t\tbreak;\n\n"); 3949 } 3950 buf.append("\t\tdefault:\n"); 3952 buf.append("\t\t\tthrow new JDOFatalInternalException(\"The specified "+ type.getName() +" field was not found.\");\n"); 3953 buf.append("\t\t}\n"); 3954 buf.append("\t}\n"); 3955 } 3956 spec.addMethod(buf.toString()); 3957 } 3958 3959 3964 protected void addSetInternalXXXFieldAbs(Class type) { 3965 StringBuffer buf = new StringBuffer (); 3966 buf.append("\n\tpublic final void " + (String ) classToInternalSetFieldAbs.get(type) + 3967 "(int absField," + type.getName() + " newValue){\n"); 3968 List fields = getFieldsAbs(type); 3969 if (fields.isEmpty()) { 3970 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3971 "(\"There were no " + type.toString() + " fields found to set.\");\n"); 3972 } else if (fields.size() == 1) { 3973 for (Iterator singelIter = fields.iterator(); 3974 singelIter.hasNext();) { 3975 FieldMetaData info = (FieldMetaData) singelIter.next(); 3976 int fieldNo = getFieldNo(info); 3977 buf.append("\t\tif(absField == " + getAbsFieldNo(info) + "){\n "); 3978 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3979 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3980 buf.append("\t\t} else {\n"); 3981 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3982 "(\"The specified " + type.toString() + " field was not found.\");\n"); 3983 buf.append("\t\t}\n"); 3984 } 3985 } else { 3986 buf.append("\t\tswitch(absField){\n"); 3987 for (Iterator fieldIter = fields.iterator(); 3988 fieldIter.hasNext();) { 3989 FieldMetaData info = (FieldMetaData) fieldIter.next(); 3990 int fieldNo = getFieldNo(info); 3991 buf.append("\t\tcase " + getAbsFieldNo(info) + ":\n"); 3992 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 3993 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 3994 buf.append("\t\t\tbreak;\n\n"); 3995 } 3996 buf.append("\t\tdefault:\n"); 3998 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 3999 "(\"The specified " + type.toString() + 4000 " field was not found for field number \"+absField);\n\t\t}\n"); 4001 4002 } 4003 buf.append("\t}\n"); 4004 spec.addMethod(buf.toString()); 4005 } 4006 4007 protected int getFieldNo(FieldMetaData fmd) { 4008 return fmd.stateFieldNo; 4009 } 4010 4011 protected int getAbsFieldNo(FieldMetaData fmd) { 4012 return fmd.managedFieldNo; 4013 } 4014 4015 4018 protected void addSetInternalObjectField() { 4019 StringBuffer buf = new StringBuffer (); 4020 4021 buf.append("\n\tpublic final void setInternalObjectField(int field,Object newValue){\n"); 4022 List fields = getObjectFields(); 4023 if (fields.isEmpty()) { 4024 buf.append("\t\tthrow new "+ FIELD_NOT_FOUND_EXCEPTION+ 4025 "(\"There were no Object fields found to set.\");\n\t}\n"); 4026 } else if (fields.size() == 1) { 4027 for (Iterator singelIter = fields.iterator(); 4028 singelIter.hasNext();) { 4029 FieldMetaData info = (FieldMetaData) singelIter.next(); 4030 int fieldNo = getFieldNo(info); 4031 buf.append("\t\tif(field == "+ fieldNo +"){\n "); 4032 if (isObject(info)) { 4033 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 4034 } else { 4035 buf.append("\t\t\t" + getFieldName(fieldNo) + " = ("+ info.type.getName() +")newValue;\n"); 4036 } 4037 buf.append("\t\t\t"+ getFilledFieldName(fieldNo) +" |= "+ getFieldIndex(fieldNo) +";\n"); 4038 buf.append("\t\t} else {\n"); 4039 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 4040 "(\"The specified " + info.type.getName() + " field was not found.\");\n"); 4041 buf.append("\t\t}\n\t}\n"); 4042 } 4043 } else { 4044 buf.append("\t\tswitch(field){\n"); 4045 for (Iterator fieldIter = fields.iterator(); 4046 fieldIter.hasNext();) { 4047 FieldMetaData info = (FieldMetaData) fieldIter.next(); 4048 int fieldNo = getFieldNo(info); 4049 buf.append("\t\tcase " + getFieldNo(info) + ":\n"); 4050 4051 4052 if (isObject(info)) { 4053 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 4054 } else { 4055 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 4056 } 4057 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 4058 buf.append("\t\t\treturn;\n"); 4059 } 4060 buf.append("\t\tdefault:\n"); 4062 buf.append("\t\t\tthrow new JDOFatalInternalException(\"The specified Object field was not found.\");\n"); 4063 buf.append("\t\t}\n"); 4064 buf.append("\t}\n"); 4065 4066 } 4067 spec.addMethod(buf.toString()); 4068 } 4069 4070 4073 protected void addSetInternalObjectFieldAbs() { 4074 StringBuffer buf = new StringBuffer (); 4075 4076 buf.append("\n\tpublic final void setInternalObjectFieldAbs(int absField,Object newValue){\n"); 4077 List fields = getObjectFieldsAbs(); 4078 if (fields.isEmpty()) { 4079 buf.append("\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 4080 "(\"There were no Object fields found to set.\");\n"); 4081 } else if (fields.size() == 1) { 4082 for (Iterator singelIter = fields.iterator(); 4083 singelIter.hasNext();) { 4084 FieldMetaData info = (FieldMetaData) singelIter.next(); 4085 int fieldNo = getFieldNo(info); 4086 buf.append("\t\tif(absField == " + getAbsFieldNo(info) + "){\n "); 4087 if (isObject(info)) { 4088 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 4089 } else { 4090 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 4091 } 4092 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 4093 buf.append("\t\t} else {\n"); 4094 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 4095 "(\"The specified " + info.type.getName() + " field was not found.\");\n"); 4096 buf.append("\t\t}\n"); 4097 } 4098 } else { 4099 buf.append("\t\tswitch(absField){\n"); 4100 for (Iterator fieldIter = fields.iterator(); 4101 fieldIter.hasNext();) { 4102 FieldMetaData info = (FieldMetaData) fieldIter.next(); 4103 int fieldNo = getFieldNo(info); 4104 buf.append("\t\tcase " + getAbsFieldNo(info) + ":\n"); 4105 4106 4107 if (isObject(info)) { 4108 buf.append("\t\t\t" + getFieldName(fieldNo) + " = newValue;\n"); 4109 } else { 4110 buf.append("\t\t\t" + getFieldName(fieldNo) + " = (" + info.type.getName() + ")newValue;\n"); 4111 } 4112 buf.append("\t\t\t" + getFilledFieldName(fieldNo) + " |= " + getFieldIndex(fieldNo) + ";\n"); 4113 buf.append("\t\t\tbreak;\n\n"); 4114 } 4115 buf.append("\t\tdefault:\n"); 4117 buf.append("\t\t\tthrow new " + FIELD_NOT_FOUND_EXCEPTION + 4118 "(\"The specified Object field was not found for field number \"+absField);\n\t\t}\n"); 4119 4120 } 4121 buf.append("\t}\n"); 4122 spec.addMethod(buf.toString()); 4123 } 4124 4125 protected boolean isCollection(FieldMetaData info) { 4126 if (info.category == MDStatics.CATEGORY_COLLECTION) { 4127 return true; 4128 } 4129 return false; 4130 } 4131 4132 protected boolean isArray(FieldMetaData info) { 4133 if (info.category == MDStatics.CATEGORY_ARRAY) { 4134 return true; 4135 } 4136 return false; 4137 } 4138 4139 protected boolean isPrimitiveArray(FieldMetaData info) { 4140 if (info.category == MDStatics.CATEGORY_ARRAY) { 4141 if (info.componentType.isPrimitive() || 4142 imutableTypeList.contains(info.componentType)) { 4143 return true; 4144 } 4145 } 4146 return false; 4147 } 4148 4149 protected boolean isPCArray(FieldMetaData fmd) { 4150 if (fmd.category == MDStatics.CATEGORY_ARRAY && fmd.scoField && fmd.isElementTypePC()) { 4151 return true; 4152 } 4153 return false; 4154 } 4155 4156 protected boolean isMap(FieldMetaData info) { 4157 if (info.category == MDStatics.CATEGORY_MAP) { 4158 return true; 4159 } 4160 return false; 4161 } 4162 4163 protected boolean isPolyRef(FieldMetaData info) { 4164 if (info.category == MDStatics.CATEGORY_POLYREF) { 4165 return true; 4166 } 4167 return false; 4168 } 4169 4170 protected String getFieldName(int fieldNum) { 4171 return "_" + fieldNum; 4172 } 4173 4174 protected int getNumOfControlFields() { 4175 return (totalNoOfFields / 32) + 1; 4176 } 4177 4178 protected String getFilledFieldName(int fieldNum) { 4179 return FILLED_FIELD_NAME + (fieldNum / 32); 4180 } 4181 4182 protected int getLocalVarIndex(int firstIndex, int fieldNo) { 4183 return (fieldNo / 32) + firstIndex; 4184 } 4185 4186 protected String getDirtyFieldName(int fieldNum) { 4187 return DIRTY_FIELD_NAME + (fieldNum / 32); 4188 } 4189 4190 protected String getResolvedFieldName(int fieldNum) { 4191 return RESOLVED_NAME + (fieldNum / 32); 4192 } 4193 4194 protected int getFieldIndex(int fieldNum) { 4195 return 1 << fieldNum; 4196 } 4197 4198 protected int getFieldIndexMask(int fieldNum) { 4199 return 0xffffffff ^ getFieldIndex(fieldNum); 4200 } 4201 4202 protected ClassMetaData getTopPCSuperClassMetaData() { 4203 return cmd.pcHeirachy[0]; 4204 } 4205 4206 protected void addIsFieldNullorZero() { 4207 StringBuffer buf = new StringBuffer (); 4208 buf.append("\n\tpublic boolean isFieldNullorZero(int stateFieldNo){\n"); 4209 FieldMetaData[] fields = cmd.stateFields; 4210 int count = 0; 4211 for (int i = 0; i < fields.length; i++) { 4212 FieldMetaData f = fields[i]; 4213 boolean obf = isObject(f); 4214 if (obf || Number .class.isAssignableFrom(f.type) 4215 || Boolean .class.isAssignableFrom(f.type)) { 4216 if (count++ == 0) { 4217 buf.append("\t\tswitch (stateFieldNo) {\n"); 4218 } 4219 buf.append("\t\t\tcase " + i + ":\t"); 4220 String fn = getFieldName(i); 4221 if (obf) { 4222 buf.append("return " + fn + " == null;\n"); 4223 } else { 4224 switch (f.typeCode) { 4225 case MDStatics.BOOLEAN: 4226 buf.append("return !" + fn + ";\n"); 4227 break; 4228 case MDStatics.BOOLEANW: 4229 buf.append("return " + fn + " == null || !((Boolean)" + fn + ").booleanValue();\n"); 4230 break; 4231 case MDStatics.BYTEW: 4232 case MDStatics.SHORTW: 4233 case MDStatics.INTW: 4234 buf.append("return " + fn + " == null || ((Number)" + fn + ").intValue() == 0;\n"); 4235 break; 4236 case MDStatics.LONGW: 4237 buf.append("return " + fn + " == null || ((Number)" + fn + ").longValue() == 0L;\n"); 4238 break; 4239 case MDStatics.FLOATW: 4240 buf.append("return " + fn + " == null || ((Number)" + fn + ").floatValue() == 0.0f;\n"); 4241 break; 4242 case MDStatics.DOUBLEW: 4243 case MDStatics.BIGDECIMAL: 4244 case MDStatics.BIGINTEGER: 4245 buf.append("return " + fn + " == null || ((Number)" + fn + ").doubleValue() == 0.0;\n"); 4246 break; 4247 default: 4248 buf.append("return " + getFieldName(i) + " == 0;"); 4249 } 4250 } 4251 } 4252 } 4253 if (count > 0) { 4254 buf.append("\t\t};\n"); 4255 } 4256 buf.append("\t\nreturn false;\n"); 4257 buf.append("\t}\n"); 4258 spec.addMethod(buf.toString()); 4259 } 4260 4261} 4262 4263 | Popular Tags |