Class ClassWeaver
- java.lang.Object
-
- org.eclipse.persistence.internal.libraries.asm.ClassVisitor
-
- org.eclipse.persistence.internal.libraries.asm.EclipseLinkClassVisitor
-
- org.eclipse.persistence.internal.jpa.weaving.ClassWeaver
-
- All Implemented Interfaces:
org.eclipse.persistence.internal.libraries.asm.Opcodes
public class ClassWeaver extends org.eclipse.persistence.internal.libraries.asm.EclipseLinkClassVisitor implements org.eclipse.persistence.internal.libraries.asm.OpcodesINTERNAL: Weaves classes to allow them to support EclipseLink indirection. Classes are weaved to add a variable of type ValueHolderInterface for each attribute that uses indirection. In addition, access methods are added for the new variable. Also, triggers the process of weaving the methods of the class.- See Also:
MethodWeaver
-
-
Field Summary
-
Fields inherited from interface org.eclipse.persistence.internal.libraries.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM10_EXPERIMENTAL, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V9
-
-
Constructor Summary
Constructors Constructor Description ClassWeaver(org.eclipse.persistence.internal.libraries.asm.ClassVisitor classWriter, ClassDetails classDetails)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFetchGroupMethods(ClassDetails classDetails)Adds get/set method for FetchGroupTracker interface.voidaddFetchGroupVariables()Add a variable of type FetchGroup, Session to the class.voidaddGetPropertyChangeListener(ClassDetails classDetails)Add the implementation of the changeTracker_getPropertyChangeListener method to the class.voidaddGetterMethodForFieldAccess(ClassDetails classDetails, AttributeDetails attributeDetails)Adds a convenience method used to replace a GETFIELD when field access is used.voidaddGetterMethodForValueHolder(ClassDetails classDetails, AttributeDetails attributeDetails)Add a get method for the newly added valueholder.voidaddInitializerForValueHolder(ClassDetails classDetails, AttributeDetails attributeDetails)Add a method that allows us to lazily initialize a valueholder we have woven in This allows us to avoid initializing valueholders in the constructor.voidaddPersistenceEntityMethods(ClassDetails classDetails)Adds get/set method for PersistenceEntity interface.voidaddPersistenceEntityVariables()Add a variable of type Object to the class.voidaddPersistenceGetSet(ClassDetails classDetails)Add an internal generic get and set method.voidaddPersistenceNew(ClassDetails classDetails)Add an internal empty constructor, and new method.voidaddPersistencePostClone(ClassDetails classDetails)Add an internal post clone method.voidaddPersistenceRestMethods(ClassDetails classDetails)voidaddPersistenceRestVariables()voidaddPropertyChange(ClassDetails classDetails)Add a method to track property changes.voidaddPropertyChangeListener(boolean attributeAccess)Add a variable of type PropertyChangeListener to the class.voidaddSetPropertyChangeListener(ClassDetails classDetails)Add the implementation of the changeTracker_setPropertyChangeListener method to the class.voidaddSetterMethodForFieldAccess(ClassDetails classDetails, AttributeDetails attributeDetails)Adds a convenience method used to replace a PUTFIELD when field access is used.voidaddSetterMethodForValueHolder(ClassDetails classDetails, AttributeDetails attributeDetails)Add a set method for the newly added ValueHolder.voidaddShallowClone(ClassDetails classDetails)Add an internal shallow clone method.voidaddValueHolder(AttributeDetails attributeDetails)Add a variable of type ValueHolderInterface to the class.static StringgetWeavedValueHolderGetMethodName(String attributeName)Return the get method name weaved for a value-holder attribute.static StringgetWeavedValueHolderSetMethodName(String attributeName)Return the set method name weaved for a value-holder attribute.static booleanisJAXBOnPath()Return if the JAXB classes are on the classpath (if they are the XmlTransient annotation is added).static voidunwrapPrimitive(AttributeDetails attribute, org.eclipse.persistence.internal.libraries.asm.MethodVisitor visitor)Used for primitive conversion.voidvisit(int version, int access, String name, String signature, String superName, String[] interfaces)Visit the class byte-codes and modify to weave Persistence interfaces.voidvisitEnd()Visit the end of the class byte codes.org.eclipse.persistence.internal.libraries.asm.MethodVisitorvisitMethod(int access, String methodName, String desc, String signature, String[] exceptions)Construct a MethodWeaver and allow it to process the method.static StringwrapperFor(int sort)Used for primitive conversion.-
Methods inherited from class org.eclipse.persistence.internal.libraries.asm.EclipseLinkClassVisitor
visit
-
-
-
-
Field Detail
-
PERSISTENCE_WEAVED_SHORT_SIGNATURE
public static final String PERSISTENCE_WEAVED_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
TW_LAZY_SHORT_SIGNATURE
public static final String TW_LAZY_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
VHI_CLASSNAME
public static final String VHI_CLASSNAME
- See Also:
- Constant Field Values
-
VH_SHORT_SIGNATURE
public static final String VH_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
VHI_SHORT_SIGNATURE
public static final String VHI_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
VHI_SIGNATURE
public static final String VHI_SIGNATURE
- See Also:
- Constant Field Values
-
TW_CT_SHORT_SIGNATURE
public static final String TW_CT_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PCL_SHORT_SIGNATURE
public static final String PCL_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PCL_SIGNATURE
public static final String PCL_SIGNATURE
- See Also:
- Constant Field Values
-
CT_SHORT_SIGNATURE
public static final String CT_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PCE_SHORT_SIGNATURE
public static final String PCE_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PCE_SIGNATURE
public static final String PCE_SIGNATURE
- See Also:
- Constant Field Values
-
PERSISTENCE_ENTITY_SHORT_SIGNATURE
public static final String PERSISTENCE_ENTITY_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PERSISTENCE_OBJECT_SHORT_SIGNATURE
public static final String PERSISTENCE_OBJECT_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PERSISTENCE_OBJECT_SIGNATURE
public static final String PERSISTENCE_OBJECT_SIGNATURE
- See Also:
- Constant Field Values
-
VECTOR_SIGNATURE
public static final String VECTOR_SIGNATURE
- See Also:
- Constant Field Values
-
OBJECT_SIGNATURE
public static final String OBJECT_SIGNATURE
- See Also:
- Constant Field Values
-
STRING_SIGNATURE
public static final String STRING_SIGNATURE
- See Also:
- Constant Field Values
-
CACHEKEY_SIGNATURE
public static final String CACHEKEY_SIGNATURE
- See Also:
- Constant Field Values
-
WEAVED_FETCHGROUPS_SHORT_SIGNATURE
public static final String WEAVED_FETCHGROUPS_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
FETCHGROUP_TRACKER_SIGNATURE
public static final String FETCHGROUP_TRACKER_SIGNATURE
- See Also:
- Constant Field Values
-
FETCHGROUP_TRACKER_SHORT_SIGNATURE
public static final String FETCHGROUP_TRACKER_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
FETCHGROUP_SHORT_SIGNATURE
public static final String FETCHGROUP_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
FETCHGROUP_SIGNATURE
public static final String FETCHGROUP_SIGNATURE
- See Also:
- Constant Field Values
-
SESSION_SIGNATURE
public static final String SESSION_SIGNATURE
- See Also:
- Constant Field Values
-
ENTITY_MANAGER_IMPL_SHORT_SIGNATURE
public static final String ENTITY_MANAGER_IMPL_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
PBOOLEAN_SIGNATURE
public static final String PBOOLEAN_SIGNATURE
- See Also:
- Constant Field Values
-
LONG_SIGNATURE
public static final String LONG_SIGNATURE
- See Also:
- Constant Field Values
-
WEAVED_REST_LAZY_SHORT_SIGNATURE
public static final String WEAVED_REST_LAZY_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
LIST_RELATIONSHIP_INFO_SIGNATURE
public static final String LIST_RELATIONSHIP_INFO_SIGNATURE
- See Also:
- Constant Field Values
-
LIST_RELATIONSHIP_INFO_GENERIC_SIGNATURE
public static final String LIST_RELATIONSHIP_INFO_GENERIC_SIGNATURE
- See Also:
- Constant Field Values
-
LINK_SIGNATURE
public static final String LINK_SIGNATURE
- See Also:
- Constant Field Values
-
ITEM_LINKS_SIGNATURE
public static final String ITEM_LINKS_SIGNATURE
- See Also:
- Constant Field Values
-
CLONEABLE_SHORT_SIGNATURE
public static final String CLONEABLE_SHORT_SIGNATURE
- See Also:
- Constant Field Values
-
JPA_TRANSIENT_DESCRIPTION
public static final String JPA_TRANSIENT_DESCRIPTION
- See Also:
- Constant Field Values
-
XML_TRANSIENT_DESCRIPTION
public static final String XML_TRANSIENT_DESCRIPTION
- See Also:
- Constant Field Values
-
PERSISTENCE_SET
public static final String PERSISTENCE_SET
- See Also:
- Constant Field Values
-
PERSISTENCE_GET
public static final String PERSISTENCE_GET
- See Also:
- Constant Field Values
-
PERSISTENCE_FIELDNAME_PREFIX
public static final String PERSISTENCE_FIELDNAME_PREFIX
- See Also:
- Constant Field Values
-
PERSISTENCE_FIELDNAME_POSTFIX
public static final String PERSISTENCE_FIELDNAME_POSTFIX
- See Also:
- Constant Field Values
-
VIRTUAL_GETTER_SIGNATURE
public static final String VIRTUAL_GETTER_SIGNATURE
- See Also:
- Constant Field Values
-
VIRTUAL_SETTER_SIGNATURE
public static final String VIRTUAL_SETTER_SIGNATURE
- See Also:
- Constant Field Values
-
classDetails
protected ClassDetails classDetails
Stores information on the class gathered from the temp class loader and descriptor.
-
alreadyWeaved
protected boolean alreadyWeaved
-
weaved
public boolean weaved
-
weavedLazy
public boolean weavedLazy
-
weavedPersistenceEntity
public boolean weavedPersistenceEntity
-
weavedChangeTracker
public boolean weavedChangeTracker
-
weavedFetchGroups
public boolean weavedFetchGroups
-
weavedRest
public boolean weavedRest
-
-
Constructor Detail
-
ClassWeaver
public ClassWeaver(org.eclipse.persistence.internal.libraries.asm.ClassVisitor classWriter, ClassDetails classDetails)
-
-
Method Detail
-
wrapperFor
public static String wrapperFor(int sort)
Used for primitive conversion. Returns the name of the class that wraps a given type.
-
unwrapPrimitive
public static void unwrapPrimitive(AttributeDetails attribute, org.eclipse.persistence.internal.libraries.asm.MethodVisitor visitor)
Used for primitive conversion. Returns the name conversion method for the given type.
-
getWeavedValueHolderGetMethodName
public static String getWeavedValueHolderGetMethodName(String attributeName)
Return the get method name weaved for a value-holder attribute.
-
getWeavedValueHolderSetMethodName
public static String getWeavedValueHolderSetMethodName(String attributeName)
Return the set method name weaved for a value-holder attribute.
-
isJAXBOnPath
public static boolean isJAXBOnPath()
Return if the JAXB classes are on the classpath (if they are the XmlTransient annotation is added).
-
addValueHolder
public void addValueHolder(AttributeDetails attributeDetails)
Add a variable of type ValueHolderInterface to the class. When this method has been run, the class will contain a variable declaration similar to the following: private ValueHolderInterface _persistence_variableName_vh;
-
addPropertyChangeListener
public void addPropertyChangeListener(boolean attributeAccess)
Add a variable of type PropertyChangeListener to the class. When this method has been run, the class will contain a variable declaration similar to the following private transient _persistence_listener;
-
addGetPropertyChangeListener
public void addGetPropertyChangeListener(ClassDetails classDetails)
Add the implementation of the changeTracker_getPropertyChangeListener method to the class. The result is a method that looks as follows: public PropertyChangeListener _persistence_getPropertyChangeListener() { return _persistence_listener; }
-
addSetPropertyChangeListener
public void addSetPropertyChangeListener(ClassDetails classDetails)
Add the implementation of the changeTracker_setPropertyChangeListener method to the class. The result is a method that looks as follows: public void _persistence_setPropertyChangeListener(PropertyChangeListener propertychangelistener){ _persistence_listener = propertychangelistener; }
-
addPropertyChange
public void addPropertyChange(ClassDetails classDetails)
Add a method to track property changes. The method will look as follows: public void _toplink_propertyChange(String s, Object obj, Object obj1){ if(_persistence_listener != null && obj != obj1){ _persistence_listener.propertyChange(new PropertyChangeEvent(this, s, obj, obj1)); } }
-
addInitializerForValueHolder
public void addInitializerForValueHolder(ClassDetails classDetails, AttributeDetails attributeDetails)
Add a method that allows us to lazily initialize a valueholder we have woven in This allows us to avoid initializing valueholders in the constructor. protected void _persistence_initialize_attribute_vh(){ if(_persistence_attribute_vh == null){ _persistence_attribute_vh = new ValueHolder(this.attribute); // or new ValueHolder() if property access. _persistence_attribute_vh.setIsNewlyWeavedValueHolder(true); } }
-
addGetterMethodForValueHolder
public void addGetterMethodForValueHolder(ClassDetails classDetails, AttributeDetails attributeDetails)
Add a get method for the newly added valueholder. Adds a method of the following form: public WeavedAttributeValueHolderInterface _persistence_getfoo_vh(){ _persistence_initialize_attributeName_vh(); if (_persistence_vh.isCoordinatedWithProperty() || _persistence_foo_vh.isNewlyWeavedValueHolder()){ EntityC object = (EntityC)getFoo(); if (object != _persistence_foo_vh.getValue()){ setFoo(object); } } return _persistence_foo_vh; }
-
addSetterMethodForValueHolder
public void addSetterMethodForValueHolder(ClassDetails classDetails, AttributeDetails attributeDetails)
Add a set method for the newly added ValueHolder. Adds a method of this form: public void _persistence_setfoo_vh(WeavedAttributeValueHolderInterface valueholderinterface){ _persistence_foo_vh = valueholderinterface; if (valueholderinterface.isInstantiated()){ Object object = getFoo(); Object value = valueholderinterface.getValue(); if (object != value){ setFoo((EntityC)value); } } else { foo = null; } }
-
addSetterMethodForFieldAccess
public void addSetterMethodForFieldAccess(ClassDetails classDetails, AttributeDetails attributeDetails)
Adds a convenience method used to replace a PUTFIELD when field access is used. The method follows the following form: public void _persistence_set_variableName((VariableClas) argument) { _persistence_checkFetchedForSet("variableName"); _persistence_initialize_variableName_vh(); _persistence_propertyChange("variableName", this.variableName, argument); // if change tracking enabled, wrapping primitives, i.e. Long.valueOf(item) this.variableName = argument; _persistence_variableName_vh.setValue(variableName); // if lazy enabled }
-
addGetterMethodForFieldAccess
public void addGetterMethodForFieldAccess(ClassDetails classDetails, AttributeDetails attributeDetails)
Adds a convenience method used to replace a GETFIELD when field access is used. The method follows the following form: public (VariableClass) _persistence_get_variableName() { _persistence_checkFetched("variableName"); _persistence_initialize_variableName_vh(); this.variableName = ((VariableClass))_persistence_variableName_vh.getValue(); return this.variableName; }
-
addPersistenceEntityVariables
public void addPersistenceEntityVariables()
Add a variable of type Object to the class. When this method has been run, the class will contain a variable declarations similar to the following: private Object _persistence_primaryKey;
-
addPersistencePostClone
public void addPersistencePostClone(ClassDetails classDetails)
Add an internal post clone method. This will clone value holders to avoid change original/clone to effect the other. public Object _persistence_post_clone() { this._attribute_vh = this._attribute_vh.clone(); ... this._persistence_listener = null; return this; }
-
addPersistenceRestMethods
public void addPersistenceRestMethods(ClassDetails classDetails)
-
addPersistenceRestVariables
public void addPersistenceRestVariables()
-
addShallowClone
public void addShallowClone(ClassDetails classDetails)
Add an internal shallow clone method. This can be used to optimize uow cloning. public Object _persistence_shallow_clone() { return super.clone(); }
-
addPersistenceNew
public void addPersistenceNew(ClassDetails classDetails)
Add an internal empty constructor, and new method. This is used to avoid unnecessary initialization and avoid reflection. public void _persistence_new(PersistenceObject factory) { return new ClassType(factory); } public ClassType(PersistenceObject factory) { super(); }
-
addPersistenceGetSet
public void addPersistenceGetSet(ClassDetails classDetails)
Add an internal generic get and set method. This is used to avoid reflection. public Object _persistence_get(String attribute) { if (attribute == "address") { return this.address; } if (attribute == "city") { return this.city; } return null; } public void _persistence_set(int index, Object value) { if (attribute == "address") { this.address = (String)value; } else if (attribute == "city") { this.city = (String)city; } }
-
addPersistenceEntityMethods
public void addPersistenceEntityMethods(ClassDetails classDetails)
Adds get/set method for PersistenceEntity interface. This adds the following methods: public Object _persistence_getId() { return _persistence_primaryKey; } public void _persistence_setId(Object primaryKey) { this._persistence_primaryKey = primaryKey; }
-
addFetchGroupVariables
public void addFetchGroupVariables()
Add a variable of type FetchGroup, Session to the class. When this method has been run, the class will contain a variable declarations similar to the following: private FetchGroup _persistence_fetchGroup; private boolean _persistence_shouldRefreshFetchGroup; private Session _persistence_session;
-
addFetchGroupMethods
public void addFetchGroupMethods(ClassDetails classDetails)
Adds get/set method for FetchGroupTracker interface. This adds the following methods: public Session _persistence_getSession() { return _persistence_session; } public void _persistence_setSession(Session session) { this._persistence_session = session; } public FetchGroup _persistence_getFetchGroup() { return _persistence_fetchGroup; } public void _persistence_setFetchGroup(FetchGroup fetchGroup) { this._persistence_fetchGroup = fetchGroup; } public boolean _persistence_shouldRefreshFetchGroup() { return _persistence_shouldRefreshFetchGroup; } public void _persistence_setShouldRefreshFetchGroup(boolean shouldRefreshFetchGroup) { this._persistence_shouldRefreshFetchGroup = shouldRefreshFetchGroup; } public void _persistence_resetFetchGroup() { } public void _persistence_isAttributeFetched(String attribute) { return this._persistence_fetchGroup == null || _persistence_fetchGroup.containsAttribute(attribute); } public void _persistence_checkFetched(String attribute) { if (this._persistence_fetchGroup != null) { EntityManagerImpl.processUnfetchedAttribute(this, attribute); } } public void _persistence_checkSetFetched(String attribute) { if (this._persistence_fetchGroup != null) { EntityManagerImpl.processUnfetchedAttributeForSet(this, attribute); } }
-
visit
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)Visit the class byte-codes and modify to weave Persistence interfaces. This add PersistenceWeaved, PersistenceWeavedLazy, PersistenceWeavedChangeTracking, PersistenceEntity, ChangeTracker. The new interfaces are pass to the super weaver.- Overrides:
visitin classorg.eclipse.persistence.internal.libraries.asm.ClassVisitor
-
visitMethod
public org.eclipse.persistence.internal.libraries.asm.MethodVisitor visitMethod(int access, String methodName, String desc, String signature, String[] exceptions)Construct a MethodWeaver and allow it to process the method.- Overrides:
visitMethodin classorg.eclipse.persistence.internal.libraries.asm.ClassVisitor
-
visitEnd
public void visitEnd()
Visit the end of the class byte codes. Add any new methods or variables to the end.- Overrides:
visitEndin classorg.eclipse.persistence.internal.libraries.asm.ClassVisitor
-
-