org.datanucleus.enhancer.asm.method
Class JdoCopyKeyFieldsFromObjectId

java.lang.Object
  extended by org.datanucleus.enhancer.ClassMethod
      extended by org.datanucleus.enhancer.asm.ASMClassMethod
          extended by org.datanucleus.enhancer.asm.method.JdoCopyKeyFieldsFromObjectId

public class JdoCopyKeyFieldsFromObjectId
extends ASMClassMethod

Method to generate the method "jdoCopyKeyFieldsFromObjectId" using ASM. For datastore/nondurable identity this is

 public void jdoCopyKeyFieldsFromObjectId(PersistenceCapable.ObjectIdFieldConsumer fc, Object oid)
 {
 }
 
and for SingleFieldIdentity it is
 public void jdoCopyKeyFieldsFromObjectId(PersistenceCapable.ObjectIdFieldConsumer fc, Object oid)
 {
     if (fc == null)
         throw new IllegalArgumentException("ObjectIdFieldConsumer is null");
     if (!(oid instanceof YYYIdentity))
         throw new ClassCastException("oid is not instanceof javax.jdo.identity.YYYIdentity");
     YYYIdentity o = (YYYIdentity) oid;
     fc.storeYYYField(1, o.getKey());
 }
 
and for user-defined primary keys
 public void jdoCopyKeyFieldsFromObjectId(PersistenceCapable.ObjectIdFieldConsumer fc, Object oid)
 {
     if (fc == null)
         throw new IllegalArgumentException("ObjectIdFieldConsumer is null");
     if (!(oid instanceof UserPrimaryKey))
         throw new ClassCastException("oid is not instanceof mydomain.UserPrimaryKey");
     UserPrimaryKey o = (UserPrimaryKey) oid;
     try
     {
         fc.storeYYYField(1, o.id);
         fc.storeZZZField(2, o.name);
     }
     catch(Exception e) {}
 }
 
and for CompoundIdentity
 public void jdoCopyKeyFieldsFromObjectId(PersistenceCapable.ObjectIdFieldConsumer fc, Object oid)
 {
     if (fc == null)
         throw new IllegalArgumentException("ObjectIdFieldConsumer is null");
     if (!(oid instanceof UserPrimaryKey))
         throw new ClassCastException("oid is not instanceof mydomain.UserPrimaryKey");
     UserPrimaryKey o = (UserPrimaryKey) oid;
     try
     {
         fc.storeYYYField(1, o.id);
         fc.storeZZZField(2, jdoGetPersistenceManager().getObjectById(o.zzz, false));
     }
     catch (Exception e) {}
 }
 
(the try-catch is for cases where we set the fields with reflection and it can throw an exception). There are some differences for fields .v. properties and also if fields in the PK are private.

Version:
$Revision: 1.20 $

Field Summary
 
Fields inherited from class org.datanucleus.enhancer.asm.ASMClassMethod
visitor
 
Fields inherited from class org.datanucleus.enhancer.ClassMethod
access, argNames, argTypes, enhancer, exceptions, LOCALISER, methodName, returnType
 
Constructor Summary
JdoCopyKeyFieldsFromObjectId(ClassEnhancer enhancer, java.lang.String name, int access, java.lang.Object returnType, java.lang.Object[] argTypes, java.lang.String[] argNames)
          Constructor.
 
Method Summary
 void execute()
          Method to add the contents of the class method.
static JdoCopyKeyFieldsFromObjectId getInstance(ASMClassEnhancer enhancer)
           
 
Methods inherited from class org.datanucleus.enhancer.asm.ASMClassMethod
getClassEnhancer, getDescriptor, initialise, initialise
 
Methods inherited from class org.datanucleus.enhancer.ClassMethod
close, equals, getAccess, getMethodAdditionMessage, getName, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdoCopyKeyFieldsFromObjectId

public JdoCopyKeyFieldsFromObjectId(ClassEnhancer enhancer,
                                    java.lang.String name,
                                    int access,
                                    java.lang.Object returnType,
                                    java.lang.Object[] argTypes,
                                    java.lang.String[] argNames)
Constructor.

Parameters:
enhancer - ClassEnhancer
name - Name of method
access - Access type
returnType - Return type
argTypes - Argument types
argNames - Argument names
Method Detail

getInstance

public static JdoCopyKeyFieldsFromObjectId getInstance(ASMClassEnhancer enhancer)

execute

public void execute()
Method to add the contents of the class method.

Specified by:
execute in class ClassMethod


Copyright © 2011. All Rights Reserved.