Label reflectionFieldStart = null;
for (int i=0;i<pkFieldNums.length;i++)
{
AbstractMemberMetaData fmd = enhancer.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[i]);
String fieldTypeDesc = Type.getDescriptor(fmd.getType());
AbstractClassMetaData acmd = enhancer.getClassMetaData().getMetaDataManager().getMetaDataForClass(
fmd.getType(), enhancer.getClassLoaderResolver());
int pkFieldModifiers = ClassUtils.getModifiersForFieldOfClass(enhancer.getClassLoaderResolver(),
objectIdClass, fmd.getName());
// Check if the PK field type is a PC (CompoundIdentity)
if (acmd != null && acmd.getIdentityType() != IdentityType.NONDURABLE)
{
// CompoundIdentity, this field of the PK is a PC
if (fmd.isProperty())
{
// Persistent Property so use o.setXXX((XXX.Key)JDOHelper.getObjectId(jdoGetXXX()))
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(),
"jdoGet" + fmd.getName(), "()" + Type.getDescriptor(fmd.getType()));
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
"getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
// TODO Use properties here
visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
}
else if (Modifier.isPublic(pkFieldModifiers))
{
// Persistent Field public, so use o.xxx = (XXX.Key)JDOHelper.getObjectId(xxx);
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
fmd.getName(), fieldTypeDesc);
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
"getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
}
else
{
// Persistent Field private/protected so use reflection
// TODO Use reflection here
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(),
fmd.getName(), fieldTypeDesc);
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, "javax/jdo/JDOHelper",
"getObjectId", "(Ljava/lang/Object;)Ljava/lang/Object;");
visitor.visitTypeInsn(Opcodes.CHECKCAST, acmd.getObjectidClass().replace('.', '/'));
// TODO Use reflection here
visitor.visitFieldInsn(Opcodes.PUTFIELD, ACN_objectIdClass,
fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
}
}
else
{
// Standard application-identity field