InstructionHandle defaultHandle;
// (flag == 0)
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createGetField(className, ClassEnhancer.FN_Flag, Type.BYTE));
BranchInstruction flgIsZero = new IFEQ(null);
il.append(flgIsZero);
// (sm == null)
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createGetField(className, ClassEnhancer.FN_StateManager, BCELClassEnhancer.OT_StateManager));
BranchInstruction smIsNull = new IFNULL(null);
il.append(smIsNull);
// jdoStateManager
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createGetField(className, ClassEnhancer.FN_StateManager, BCELClassEnhancer.OT_StateManager));
il.append(InstructionConstants.ALOAD_0);
// the field index: 0, 1, 2...
il.append(BCELUtils.getBIPUSH(fieldConfig.getFieldId()));
if (cmd.getPersistenceCapableSuperclass() != null)
{
//add to field index the parentFieldCount
il.append(factory.createGetStatic(className, ClassEnhancer.FN_JdoInheritedFieldCount, Type.INT));
il.append(InstructionConstants.IADD);
}
// objPC.field
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createGetField(className, fieldName, nativeType));
// the value in parameter to set
il.append(InstructionFactory.createLoad(nativeType, 1));
// objPC.setXXXField
il.append(factory.createInvoke(ClassEnhancer.CN_StateManager, "set" + BCELUtils.getJDOMethodName(smType) + "Field",
Type.VOID, new Type[]{BCELClassEnhancer.OT_PersistenceCapable, Type.INT, smType, smType}, Constants.INVOKEINTERFACE));
il.append(InstructionConstants.RETURN);
// he value in parameter to set
defaultHandle = il.append(InstructionConstants.ALOAD_0);
il.append(InstructionFactory.createLoad(nativeType, 1));
// objPC.field =
il.append(factory.createPutField(className, targetField.getName(), nativeType));
//----detach------
if (cmd.isDetachable())
{
// jdoIsDetached()
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceCapable, ClassEnhancer.MN_JdoIsDetached,
Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEINTERFACE));
//1
il.append(InstructionConstants.ICONST_1);
// if (jdoIsDetached() == 1)
IF_ICMPEQ ifIsDetached = new IF_ICMPEQ(null);
il.append(ifIsDetached);
//return;
il.append(InstructionConstants.RETURN);
// jdoDetachedState[3].set(?)
// jdoDetachedState[3]
ifIsDetached.setTarget(il.append(InstructionConstants.ALOAD_0));
il.append(factory.createGetField(className, ClassEnhancer.FN_JdoDetachedState, BCELClassEnhancer.OT_ObjectArray));
il.append(InstructionConstants.ICONST_3);
il.append(InstructionConstants.AALOAD);
il.append(factory.createCheckCast(BCELClassEnhancer.OT_BitSet)); // Cast to BitSet
// the field index: 0, 1, 2...
il.append(BCELUtils.getBIPUSH(fieldConfig.getFieldId()));
if (cmd.getPersistenceCapableSuperclass() != null)
{
//add to field index the parentFieldCount
il.append(factory.createGetStatic(className, ClassEnhancer.FN_JdoInheritedFieldCount, Type.INT));
il.append(InstructionConstants.IADD);
}
// set(?)
il.append(factory.createInvoke(ClassEnhancer.CN_BitSet, "set", Type.VOID, new Type[]{Type.INT}, Constants.INVOKEVIRTUAL));
}
//----detach------
il.append(InstructionConstants.RETURN);
flgIsZero.setTarget(defaultHandle);
smIsNull.setTarget(defaultHandle);
}