AbstractMemberMetaData fields[] = cmd.getManagedMembers();
int objectIdInstance = 2;
if ((objectIdClass != null) && (objectIdClass.length() > 0))
{
ObjectType objectIdClassType = new ObjectType(objectIdClass);
il.append(InstructionConstants.ALOAD_1);
IFNE oidClassIsNotNull = new IFNE(null);
il.append(factory.createInstanceOf(objectIdClassType));
il.append(oidClassIsNotNull);
createThrowException(ClassEnhancer.CN_ClassCastException, "key class is not " + objectIdClass + " or null");
oidClassIsNotNull.setTarget(il.append(InstructionConstants.ALOAD_1));
il.append(factory.createCast(Type.OBJECT, objectIdClassType));
lv_o[0] = il.append(new ASTORE(objectIdInstance));
if (fields != null)
{
for (int i = 0; i < fields.length; i++)
{
AbstractMemberMetaData fieldConfig = (AbstractMemberMetaData)fields[i];
if (fieldConfig.isPrimaryKey())
{
//support for identifying relationships
//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());