![JAR search and dependency download from the Maven repository](/logo.png)
com.avaje.ebean.enhance.agent.MethodIsEmbeddedNewOrDirty Maven / Gradle / Ivy
package com.avaje.ebean.enhance.agent;
import com.avaje.ebean.enhance.asm.ClassVisitor;
import com.avaje.ebean.enhance.asm.Label;
import com.avaje.ebean.enhance.asm.MethodVisitor;
import com.avaje.ebean.enhance.asm.Opcodes;
import java.util.List;
/**
* Used to detect if a class has been enhanced.
*
* Moved to use this over just relying on the existence of the EntityBean interface
* to make the enhancement more robust.
*
*/
public class MethodIsEmbeddedNewOrDirty implements Opcodes, EnhanceConstants {
/**
* Generate the _ebean_isEmbeddedNewOrDirty() method.
*
*
* public boolean _ebean_isEmbeddedNewOrDirty() {
* // for each embedded bean field...
* if (entityBeanIntercept.isEmbeddedNewOrDirty(embeddedBeanField)) return true;
* ...
* return false;
* }
*
*/
public static void addMethod(ClassVisitor cv, ClassMeta classMeta) {
String className = classMeta.getClassName();
MethodVisitor mv;
mv = cv.visitMethod(ACC_PUBLIC, "_ebean_isEmbeddedNewOrDirty", "()Z", null, null);
mv.visitCode();
Label labelBegin = null;
Label labelNext = null;
List allFields = classMeta.getAllFields();
for (int i = 0; i < allFields.size(); i++) {
FieldMeta fieldMeta = allFields.get(i);
if (fieldMeta.isEmbedded()){
Label l0 = labelNext;
if (l0 == null) {
l0 = new Label();
}
if (labelBegin == null){
labelBegin = l0;
}
mv.visitLabel(l0);
mv.visitLineNumber(0, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, className, INTERCEPT_FIELD, L_INTERCEPT);
mv.visitVarInsn(ALOAD, 0);
fieldMeta.appendSwitchGet(mv, classMeta, false);
mv.visitMethodInsn(INVOKEVIRTUAL, C_INTERCEPT, "isEmbeddedNewOrDirty", "(Ljava/lang/Object;)Z", false);
labelNext = new Label();
mv.visitJumpInsn(IFEQ, labelNext);
mv.visitInsn(ICONST_1);
mv.visitInsn(IRETURN);
}
}
if (labelNext == null){
labelNext = new Label();
}
if (labelBegin == null){
labelBegin = labelNext;
}
mv.visitLabel(labelNext);
mv.visitLineNumber(1, labelNext);
mv.visitInsn(ICONST_0);
mv.visitInsn(IRETURN);
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitLocalVariable("this", "L"+className+";", null, labelBegin, l3, 0);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy