Module org.eclipse.persistence.jpa
Class MethodWeaver
java.lang.Object
org.eclipse.persistence.asm.MethodVisitor
org.eclipse.persistence.asm.EclipseLinkMethodVisitor
org.eclipse.persistence.internal.jpa.weaving.MethodWeaver
Processes all the methods of a class to weave in persistence code such as,
lazy value holder, change tracking and fetch groups.
For FIELD access, changes references to GETFIELD and PUTFIELD to call weaved get/set methods.
For Property access, modifies the getters and setters.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected String
protected boolean
Determines if we are at the first line of a method.protected ClassWeaver
Fields inherited from class org.eclipse.persistence.asm.EclipseLinkMethodVisitor
methodVisitor
Fields inherited from class org.eclipse.persistence.asm.MethodVisitor
customMethodVisitor
-
Constructor Summary
ConstructorDescriptionMethodWeaver
(ClassWeaver tcw, String methodName, String methodDescriptor, MethodVisitor mv) -
Method Summary
Modifier and TypeMethodDescriptionvisitAnnotation
(String desc, boolean visible) void
visitAttribute
(Attribute attr) void
visitEnd()
void
visitFieldInsn
(int opcode, String owner, String name, String desc) void
visitIincInsn
(int var, int increment) void
visitInsn
(int opcode) void
visitIntInsn
(int opcode, int operand) void
visitJumpInsn
(int opcode, Label label) void
visitLabel
(Label label) void
visitLdcInsn
(Object cst) void
visitLineNumber
(int line, Label start) void
void
visitLookupSwitchInsn
(Label dflt, int[] keys, Label[] labels) void
visitMaxs
(int maxStack, int maxLocals) void
visitMethodInsn
(int opcode, String owner, String name, String desc, boolean intf) void
visitMultiANewArrayInsn
(String desc, int dims) void
visitTableSwitchInsn
(int min, int max, Label dflt, Label... labels) void
visitTryCatchBlock
(Label start, Label end, Label handler, String type) void
visitTypeInsn
(int opcode, String desc) void
visitVarInsn
(int opcode, int var) void
weaveAttributesIfRequired
(int opcode, String owner, String name, String desc) Change GETFIELD and PUTFIELD for fields that use attribute access to make use of new convenience methods.void
Makes modifications to the beginning of a method.void
Modifies methods just before the return.Methods inherited from class org.eclipse.persistence.asm.EclipseLinkMethodVisitor
unwrap, visitAnnotationSuper, visitAttributeSuper, visitCode, visitFieldInsnSuper, visitFrame, visitIincInsnSuper, visitInsnSuper, visitIntInsnSuper, visitJumpInsnSuper, visitLabelSuper, visitLdcInsnSuper, visitLineNumberSuper, visitLocalVariableSuper, visitLookupSwitchInsnSuper, visitMaxsSuper, visitMethodInsnSuper, visitMultiANewArrayInsnSuper, visitTableSwitchInsnSuper, visitTryCatchBlockSuper, visitTypeInsnSuper, visitVarInsnSuper
Methods inherited from class org.eclipse.persistence.asm.MethodVisitor
setCustomMethodVisitor
-
Field Details
-
tcw
-
methodName
-
methodDescriptor
-
methodStarted
protected boolean methodStartedDetermines if we are at the first line of a method.
-
-
Constructor Details
-
MethodWeaver
-
-
Method Details
-
visitInsn
public void visitInsn(int opcode) - Overrides:
visitInsn
in classEclipseLinkMethodVisitor
-
visitIntInsn
public void visitIntInsn(int opcode, int operand) - Overrides:
visitIntInsn
in classEclipseLinkMethodVisitor
-
visitVarInsn
public void visitVarInsn(int opcode, int var) - Overrides:
visitVarInsn
in classEclipseLinkMethodVisitor
-
visitTypeInsn
- Overrides:
visitTypeInsn
in classEclipseLinkMethodVisitor
-
visitFieldInsn
- Overrides:
visitFieldInsn
in classEclipseLinkMethodVisitor
-
visitMethodInsn
- Overrides:
visitMethodInsn
in classEclipseLinkMethodVisitor
-
visitJumpInsn
- Overrides:
visitJumpInsn
in classEclipseLinkMethodVisitor
-
visitLabel
- Overrides:
visitLabel
in classEclipseLinkMethodVisitor
-
visitLdcInsn
- Overrides:
visitLdcInsn
in classEclipseLinkMethodVisitor
-
visitIincInsn
public void visitIincInsn(int var, int increment) - Overrides:
visitIincInsn
in classEclipseLinkMethodVisitor
-
visitTableSwitchInsn
- Overrides:
visitTableSwitchInsn
in classEclipseLinkMethodVisitor
-
visitLookupSwitchInsn
- Overrides:
visitLookupSwitchInsn
in classEclipseLinkMethodVisitor
-
visitMultiANewArrayInsn
- Overrides:
visitMultiANewArrayInsn
in classEclipseLinkMethodVisitor
-
visitTryCatchBlock
- Overrides:
visitTryCatchBlock
in classEclipseLinkMethodVisitor
-
visitMaxs
public void visitMaxs(int maxStack, int maxLocals) - Overrides:
visitMaxs
in classEclipseLinkMethodVisitor
-
visitLocalVariable
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) - Overrides:
visitLocalVariable
in classEclipseLinkMethodVisitor
-
visitLineNumber
- Overrides:
visitLineNumber
in classEclipseLinkMethodVisitor
-
visitAttribute
- Overrides:
visitAttribute
in classEclipseLinkMethodVisitor
-
visitAnnotation
- Overrides:
visitAnnotation
in classEclipseLinkMethodVisitor
-
visitEnd
public void visitEnd()- Overrides:
visitEnd
in classEclipseLinkMethodVisitor
-
weaveAttributesIfRequired
Change GETFIELD and PUTFIELD for fields that use attribute access to make use of new convenience methods. A GETFIELD for an attribute named 'variableName' will be replaced by a call to: _persistence_get_variableName() A PUTFIELD for an attribute named 'variableName' will be replaced by a call to: _persistence_set_variableName(variableName) -
weaveBeginningOfMethodIfRequired
public void weaveBeginningOfMethodIfRequired()Makes modifications to the beginning of a method. 1. Modifies getter method for attributes using property access In a getter method for 'attributeName', the following lines are added at the beginning of the method _persistence_checkFetched("attributeName"); _persistence_initialize_attributeName_vh(); if (!_persistence_attributeName_vh.isInstantiated()) { PropertyChangeListener temp_persistence_listener = _persistence_listener; _persistence_listener = null; setAttributeName((AttributeType)_persistence_attributeName_vh.getValue()); _persistence_listener = temp_persistence_listener; } 2. Modifies setter methods to store old value of attribute If weaving for fetch groups: // if weaving for change tracking: if(_persistence_listener != null) // for Objects AttributeType oldAttribute = getAttribute() // for primitives AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); e.g. Double oldAttribute = Double.valueOf(getAttribute()); else _persistence_checkFetchedForSet("attributeName"); _persistence_propertyChange("attributeName", oldAttribute, argument); otherwise (not weaving for fetch groups): // for Objects AttributeType oldAttribute = getAttribute() // for primitives AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); e.g. Double oldAttribute = Double.valueOf(getAttribute()); _persistence_propertyChange("attributeName", oldAttribute, argument); // if not weaving for change tracking, but for fetch groups only: _persistence_checkFetchedForSet("attributeName"); 3. Modifies getter Method for attributes using virtual access add: _persistence_checkFetched(name); 4. Modifies setter Method for attributes using virtual access add code of the following form: Object obj = null; if(_persistence_listener != null){ obj = get(name); } else { _persistence_checkFetchedForSet(name); } _persistence_propertyChange(name, obj, value); _persistence_checkFetchedForSet(name) call will be excluded if weaving of fetch groups is not enabled _persistence_propertyChange(name, obj, value); will be excluded if weaving of change tracking is not enabled -
weaveEndOfMethodIfRequired
public void weaveEndOfMethodIfRequired()Modifies methods just before the return. In a setter method for a LAZY mapping, for 'attributeName', the following lines are added at the end of the method. _persistence_initialize_attributeName_vh(); _persistence_attributeName_vh.setValue(argument); _persistence_attributeName_vh.setIsCoordinatedWithProperty(true); In a setter method for a non-LAZY mapping, the followings lines are added if change tracking is activated: _persistence_propertyChange("attributeName", oldAttribute, argument); Note: This code will wrap primitives by adding a call to the primitive constructor.
-