// if (!_persistence_attributeName_vh.isInstantiated()) {
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, tcw.classDetails.getClassName(), ClassWeaver.PERSISTENCE_FIELDNAME_PREFIX + attributeName + ClassWeaver.PERSISTENCE_FIELDNAME_POSTFIX, ClassWeaver.VHI_SIGNATURE);
mv.visitMethodInsn(INVOKEINTERFACE, ClassWeaver.VHI_SHORT_SIGNATURE, "isInstantiated", "()Z", true);
Label l0 = new Label();
mv.visitJumpInsn(IFNE, l0);
// Need to disable change tracking when the set method is called to avoid thinking the attribute changed.
if (tcw.classDetails.shouldWeaveChangeTracking()) {
// PropertyChangeListener temp_persistence_listener = _persistence_listener;
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, tcw.classDetails.getClassName(), "_persistence_listener", ClassWeaver.PCL_SIGNATURE);
mv.visitVarInsn(ASTORE, 4);
// _persistence_listener = null;
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(ACONST_NULL);
mv.visitFieldInsn(PUTFIELD, tcw.classDetails.getClassName(), "_persistence_listener", ClassWeaver.PCL_SIGNATURE);
}
// setAttributeName((AttributeType)_persistence_attributeName_vh.getValue());
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, tcw.classDetails.getClassName(), ClassWeaver.PERSISTENCE_FIELDNAME_PREFIX + attributeName + ClassWeaver.PERSISTENCE_FIELDNAME_POSTFIX, ClassWeaver.VHI_SIGNATURE);
mv.visitMethodInsn(INVOKEINTERFACE, ClassWeaver.VHI_SHORT_SIGNATURE, "getValue", "()Ljava/lang/Object;", true);
mv.visitTypeInsn(CHECKCAST, referenceClassName.replace('.','/'));
mv.visitMethodInsn(INVOKEVIRTUAL, tcw.classDetails.getClassName(), setterMethodName, "(" + referenceClassType.getDescriptor() + ")V", false);
if (tcw.classDetails.shouldWeaveChangeTracking()) {
// _persistence_listener = temp_persistence_listener;
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 4);
mv.visitFieldInsn(PUTFIELD, tcw.classDetails.getClassName(), "_persistence_listener", ClassWeaver.PCL_SIGNATURE);
}
// }
mv.visitLabel(l0);
}
} else {
attributeDetails = tcw.classDetails.getSetterMethodToAttributeDetails().get(methodName);
boolean isSetMethod = (attributeDetails != null) && this.methodDescriptor.equals(attributeDetails.getSetterMethodSignature());
if (attributeDetails == null){
VirtualAttributeMethodInfo info = tcw.classDetails.getInfoForVirtualSetMethod(methodName);
if (info != null && this.methodDescriptor.equals(ClassWeaver.VIRTUAL_GETTER_SIGNATURE) ){
isGetMethod = true;
isVirtual = true;
referenceClassName = "java.lang.Object";
setterMethodName = methodName;
referenceClassType = Type.getType(ClassWeaver.OBJECT_SIGNATURE);
getterMethodName = info.getGetMethodName();
}
} else {
attributeName = attributeDetails.getAttributeName();
referenceClassName = attributeDetails.getReferenceClassName();
setterMethodName = attributeDetails.getSetterMethodName();
referenceClassType = attributeDetails.getReferenceClassType();
getterMethodName = attributeDetails.getGetterMethodName();
isVirtual = attributeDetails.isVirtualProperty();
}
if (isVirtual){
valueHoldingLocation = 2;
valueStorageLocation = 3;
}
if (isVirtual || (isSetMethod && !attributeDetails.hasField())) {
if(tcw.classDetails.shouldWeaveChangeTracking()) {
if(tcw.classDetails.shouldWeaveFetchGroups()) {
// if this is a primitive, get the wrapper class
String wrapper = ClassWeaver.wrapperFor(referenceClassType.getSort());
mv.visitInsn(ACONST_NULL);
if (wrapper != null){
mv.visitVarInsn(ASTORE, valueStorageLocation + 1);
} else {
mv.visitVarInsn(ASTORE, valueStorageLocation);
}
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, tcw.classDetails.getClassName(), "_persistence_listener", "Ljava/beans/PropertyChangeListener;");
Label l0 = new Label();
mv.visitJumpInsn(IFNULL, l0);
/**
* The code below constructs the following code
*
* AttributeType oldAttribute = getAttribute() // for Objects
*
* AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); // for primitives
*/
// 1st part of invoking constructor for primitives to wrap them
if (wrapper != null) {
mv.visitTypeInsn(NEW, wrapper);
mv.visitInsn(DUP);
}
// Call the getter
// getAttribute()
mv.visitVarInsn(ALOAD, 0);
String getterArgument = "";
String getterReturn = referenceClassType.getDescriptor();
if (isVirtual){
getterArgument = ClassWeaver.STRING_SIGNATURE;
getterReturn = ClassWeaver.OBJECT_SIGNATURE;
mv.visitVarInsn(ALOAD, 1);
}
mv.visitMethodInsn(INVOKEVIRTUAL, tcw.classDetails.getClassName(), getterMethodName, "(" + getterArgument + ")" + getterReturn, false);
if (wrapper != null){
// 2nd part of using constructor.
mv.visitMethodInsn(INVOKESPECIAL, wrapper, "<init>", "(" + referenceClassType.getDescriptor() + ")V", false);
mv.visitVarInsn(ASTORE, valueStorageLocation + 1);
} else {
// store the result
mv.visitVarInsn(ASTORE, valueStorageLocation);
}
Label l1 = new Label();
mv.visitJumpInsn(GOTO, l1);
mv.visitLabel(l0);
mv.visitVarInsn(ALOAD, 0);
if (isVirtual){