//if the class has metadata, it is PersistenceCapable
//add JDOHelper.getObjectId(fieldXXXX);
MetaDataManager mgr = cmd.getMetaDataManager();
AbstractClassMetaData cmd = mgr.getMetaDataForClass(fieldConfig.getType(),
enhancer.getClassLoaderResolver());
BCELMember fieldMethod = ((BCELFieldPropertyMetaData)fieldConfig).getEnhanceField();
if (cmd != null && cmd.getIdentityType() != IdentityType.NONDURABLE)
{
// Identifying Relationships (PC field as primary key)
il.append(InstructionConstants.ALOAD_0);
//jdoGetPersistenceManager().getObjectById(id.field,false)
// jdoGetPersistenceManager
il.append(InstructionConstants.ALOAD_0);
il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceCapable, ClassEnhancer.MN_JdoGetPersistenceManager,
BCELClassEnhancer.OT_PersistenceManager, Type.NO_ARGS, Constants.INVOKEINTERFACE));
// getObjectById(id.field,false)
// id.field
createGetField(
objectIdClass,
fieldConfig.getName(),
new ObjectType(cmd.getObjectidClass()),
fieldConfig.isProperty(),
getModifiers(objectIdClass, fieldConfig.getName()),
InstructionFactory.createLoad(objectIdClassType, objectIdInstance));
// false
il.append(InstructionConstants.ICONST_0);
// getObjectById
il.append(factory.createInvoke(ClassEnhancer.CN_PersistenceManager, "getObjectById", Type.OBJECT,
new Type[]{Type.OBJECT, Type.BOOLEAN}, Constants.INVOKEINTERFACE));
il.append(factory.createCast(Type.OBJECT, fieldMethod.getType()));
createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
}
else
{
// Single Field Identity
if (mgr.getApiAdapter().isSingleFieldIdentityClass(objectIdClass))
{
if (Object.class.isAssignableFrom(fieldConfig.getType()) && fieldConfig.getType() != String.class)
{
// Object wrapper type
Type primitiveType = null;
if (objectIdClass.equals(LongIdentity.class.getName()))
{
primitiveType = Type.LONG;
}
else if (objectIdClass.equals(CharIdentity.class.getName()))
{
primitiveType = Type.CHAR;
}
else if (objectIdClass.equals(IntIdentity.class.getName()))
{
primitiveType = Type.INT;
}
else if (objectIdClass.equals(ShortIdentity.class.getName()))
{
primitiveType = Type.SHORT;
}
else if (objectIdClass.equals(ByteIdentity.class.getName()))
{
primitiveType = Type.BYTE;
}
else if (objectIdClass.equals(StringIdentity.class.getName()))
{
primitiveType = Type.STRING;
}
else if (objectIdClass.equals(ObjectIdentity.class.getName()))
{
primitiveType = Type.OBJECT;
}
il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
if (primitiveType == Type.OBJECT)
{
// id = (field_type)o.getKey();
il.append(InstructionFactory.createLoad(Type.OBJECT, 2));
il.append(factory.createInvoke(objectIdClass, "getKey", primitiveType, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createCheckCast(new ObjectType(fieldConfig.getTypeName())));
createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
}
else
{
// id = new Integer(o.getKey());
il.append(factory.createNew(fieldConfig.getType().getName()));
il.append(InstructionConstants.DUP);
il.append(InstructionFactory.createLoad(Type.OBJECT, 2));
il.append(factory.createInvoke(objectIdClass, "getKey", primitiveType, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(factory.createInvoke(fieldConfig.getType().getName(), "<init>", Type.VOID,
new Type[]{primitiveType}, Constants.INVOKESPECIAL));
createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
}
}
else
{
// Primitive type
il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
il.append(InstructionFactory.createLoad(Type.OBJECT, 2));
il.append(factory.createInvoke(objectIdClass, "getKey", fieldMethod.getType(), Type.NO_ARGS,
Constants.INVOKEVIRTUAL));
createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
}
}
// Users Application Identity class
else
{
il.append(InstructionConstants.ALOAD_0);
createGetField(
objectIdClass,
fieldConfig.getName(),
fieldMethod.getType(),
fieldConfig.isProperty(),
getModifiers(objectIdClass, fieldConfig.getName()),
InstructionFactory.createLoad(objectIdClassType, objectIdInstance));
createPutField(fieldConfig.getName(), fieldMethod.getType(), fieldConfig.isProperty());
}
}
}
}
}