Package org.datanucleus.enhancer
Class PrimaryKeyGenerator
- java.lang.Object
-
- org.datanucleus.enhancer.PrimaryKeyGenerator
-
public class PrimaryKeyGenerator extends java.lang.ObjectClass to handle the generation of a PK class for a persistable class. The primary key class is generated as its own class, rather than as an inner class of the original class. NOTE: This will only currently handle persistable fields. If you require persistable properties then get the code and extend this.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) ClassEnhancerclassEnhancerThe enhancer being used.(package private) java.lang.StringclassName_ASMASM name of the PK class ("mydomain/MyClass_PK").(package private) java.lang.StringclassName_DescNameASM type descriptor name of the PK class ("Lmydomain/MyClass_PK;").(package private) AbstractClassMetaDatacmdMetadata for the class that needs a primary key class.(package private) java.lang.StringpkClassNameName of the primary key class ("mydomain.MyClass_PK").(package private) java.lang.StringstringSeparator
-
Constructor Summary
Constructors Constructor Description PrimaryKeyGenerator(AbstractClassMetaData cmd, ClassEnhancer enhancer)Constructor for a PK generator for the specified class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddDefaultConstructor(ClassWriter cw)Method to add an empty default constructor.protected voidaddFields(ClassWriter cw)Method to add fields to match the PK fields of the persistable classprotected voidaddMethodEquals(ClassWriter cw)Method to add an equals() method.protected voidaddMethodHashCode(ClassWriter cw)Method to add a hashCode() method.protected voidaddMethodToString(ClassWriter cw)Method to add a toString() method.protected voidaddStringConstructor(ClassWriter cw)Method to add a constructor taking in a String.byte[]generate()Method to generate the primary key class.protected java.lang.StringgetTypeNameForField(AbstractMemberMetaData mmd)
-
-
-
Field Detail
-
cmd
final AbstractClassMetaData cmd
Metadata for the class that needs a primary key class.
-
pkClassName
final java.lang.String pkClassName
Name of the primary key class ("mydomain.MyClass_PK").
-
className_ASM
final java.lang.String className_ASM
ASM name of the PK class ("mydomain/MyClass_PK").
-
className_DescName
final java.lang.String className_DescName
ASM type descriptor name of the PK class ("Lmydomain/MyClass_PK;").
-
classEnhancer
final ClassEnhancer classEnhancer
The enhancer being used.
-
stringSeparator
java.lang.String stringSeparator
-
-
Constructor Detail
-
PrimaryKeyGenerator
public PrimaryKeyGenerator(AbstractClassMetaData cmd, ClassEnhancer enhancer)
Constructor for a PK generator for the specified class.- Parameters:
cmd- Metadata for the class that needs a primary key classenhancer- The enhancer being used
-
-
Method Detail
-
generate
public byte[] generate()
Method to generate the primary key class.- Returns:
- The bytes for this pk class
-
addFields
protected void addFields(ClassWriter cw)
Method to add fields to match the PK fields of the persistable class- Parameters:
cw- The ClassWriter to use
-
getTypeNameForField
protected java.lang.String getTypeNameForField(AbstractMemberMetaData mmd)
-
addDefaultConstructor
protected void addDefaultConstructor(ClassWriter cw)
Method to add an empty default constructor.- Parameters:
cw- The ClassWriter to use
-
addStringConstructor
protected void addStringConstructor(ClassWriter cw)
Method to add a constructor taking in a String.- Parameters:
cw- The ClassWriter to use
-
addMethodToString
protected void addMethodToString(ClassWriter cw)
Method to add a toString() method.- Parameters:
cw- The ClassWriter to use
-
addMethodEquals
protected void addMethodEquals(ClassWriter cw)
Method to add an equals() method.- Parameters:
cw- The ClassWriter to use
-
addMethodHashCode
protected void addMethodHashCode(ClassWriter cw)
Method to add a hashCode() method.- Parameters:
cw- The ClassWriter to use
-
-