EntityFullFunc

This commit is contained in:
redkale
2024-09-23 11:11:59 +08:00
parent a060075d08
commit 6162e71d29
6 changed files with 419 additions and 32 deletions

View File

@@ -185,8 +185,25 @@ public final class Asms {
} else if (clazz == double.class) {
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
} else if (clazz == boolean[].class) {
mv.visitTypeInsn(CHECKCAST, "[Z");
} else if (clazz == byte[].class) {
mv.visitTypeInsn(CHECKCAST, "[B");
} else if (clazz == short[].class) {
mv.visitTypeInsn(CHECKCAST, "[S");
} else if (clazz == char[].class) {
mv.visitTypeInsn(CHECKCAST, "[C");
} else if (clazz == int[].class) {
mv.visitTypeInsn(CHECKCAST, "[I");
} else if (clazz == float[].class) {
mv.visitTypeInsn(CHECKCAST, "[F");
} else if (clazz == long[].class) {
mv.visitTypeInsn(CHECKCAST, "[J");
} else if (clazz == double[].class) {
mv.visitTypeInsn(CHECKCAST, "[D");
} else {
mv.visitTypeInsn(CHECKCAST, clazz.getName().replace('.', '/'));
mv.visitTypeInsn(
CHECKCAST, (clazz.isArray() ? "[" : "") + clazz.getName().replace('.', '/'));
}
}

View File

@@ -362,9 +362,10 @@ public class EntityBuilder<T> {
}
}
} else {
Object[] cps = new Object[this.constructorParameters.length];
for (int i = 0; i < this.constructorAttributes.length; i++) {
Attribute<T, Serializable> attr = this.constructorAttributes[i];
Attribute<T, Serializable>[] constructorAttrs = this.constructorAttributes;
Object[] cps = new Object[constructorAttrs.length];
for (int i = 0; i < constructorAttrs.length; i++) {
Attribute<T, Serializable> attr = constructorAttrs[i];
String sqlCol = getSQLColumn(null, attr.field());
if (sqlColumns.contains(sqlCol)) {
cps[i] = getFieldValue(row, attr, 0);
@@ -425,9 +426,10 @@ public class EntityBuilder<T> {
if (this.constructorParameters == null) {
obj = creator.create();
} else {
Object[] cps = new Object[this.constructorParameters.length];
for (int i = 0; i < this.constructorAttributes.length; i++) {
Attribute<T, Serializable> attr = this.constructorAttributes[i];
Attribute<T, Serializable>[] constructorAttrs = this.constructorAttributes;
Object[] cps = new Object[constructorAttrs.length];
for (int i = 0; i < constructorAttrs.length; i++) {
Attribute<T, Serializable> attr = constructorAttrs[i];
if (sels.test(attr.field())) {
cps[i] = getFieldValue(row, attr, 0);
}
@@ -460,6 +462,9 @@ public class EntityBuilder<T> {
}
public T getFullEntityValue(final Serializable... values) {
if (this.fullFunc != null) {
return this.fullFunc.getObject(values);
}
return getEntityValue(
constructorAttributes, constructorAttributes == null ? attributes : unconstructorAttributes, values);
}
@@ -491,7 +496,7 @@ public class EntityBuilder<T> {
if (this.constructorParameters == null) {
obj = creator.create();
} else {
Object[] cps = new Object[this.constructorParameters.length];
Object[] cps = new Object[constructorAttrs.length];
for (int i = 0; i < constructorAttrs.length; i++) {
Attribute<T, Serializable> attr = constructorAttrs[i];
if (attr != null) {
@@ -530,7 +535,7 @@ public class EntityBuilder<T> {
if (this.constructorParameters == null) {
obj = creator.create();
} else {
Object[] cps = new Object[this.constructorParameters.length];
Object[] cps = new Object[constructorAttrs.length];
for (int i = 0; i < constructorAttrs.length; i++) {
Attribute<T, Serializable> attr = constructorAttrs[i];
if (attr != null) {

View File

@@ -7,18 +7,18 @@ package org.redkale.source;
import java.io.Serializable;
import java.util.Objects;
import org.redkale.annotation.ClassDepends;
import org.redkale.asm.AnnotationVisitor;
import org.redkale.asm.Asms;
import org.redkale.asm.ClassWriter;
import org.redkale.asm.FieldVisitor;
import org.redkale.asm.Label;
import org.redkale.asm.MethodVisitor;
import org.redkale.asm.Opcodes;
import static org.redkale.asm.Opcodes.AALOAD;
import static org.redkale.asm.Opcodes.ACC_BRIDGE;
import static org.redkale.asm.Opcodes.ACC_FINAL;
import static org.redkale.asm.Opcodes.ACC_PUBLIC;
import static org.redkale.asm.Opcodes.ACC_SUPER;
import static org.redkale.asm.Opcodes.ACC_SYNTHETIC;
import static org.redkale.asm.Opcodes.ACC_VARARGS;
import static org.redkale.asm.Opcodes.ACONST_NULL;
import static org.redkale.asm.Opcodes.ALOAD;
import static org.redkale.asm.Opcodes.ANEWARRAY;
@@ -68,6 +68,8 @@ public abstract class EntityFullFunc<T> {
public abstract T getObject(DataResultSetRow row);
public abstract T getObject(Serializable... values);
@ClassDepends
protected void setFieldValue(int attrIndex, DataResultSetRow row, T obj) {
Attribute<T, Serializable> attr = attrs[attrIndex];
@@ -99,6 +101,7 @@ public abstract class EntityFullFunc<T> {
final String rowDesc = Type.getDescriptor(DataResultSetRow.class);
final String rowName = DataResultSetRow.class.getName().replace('.', '/');
final String objectDesc = Type.getDescriptor(Object.class);
final String serisDesc = Type.getDescriptor(Serializable[].class);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (String.class.getClassLoader() != entityType.getClassLoader()) {
@@ -117,9 +120,7 @@ public abstract class EntityFullFunc<T> {
// -------------------------------------------------------------
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
FieldVisitor fv;
MethodVisitor mv;
AnnotationVisitor av0;
cw.visit(
V11,
ACC_PUBLIC + ACC_FINAL + ACC_SUPER,
@@ -150,7 +151,7 @@ public abstract class EntityFullFunc<T> {
mv.visitMaxs(4, 4);
mv.visitEnd();
}
{ // getObject
{ // getObject(DataResultSetRow row)
mv = cw.visitMethod(ACC_PUBLIC, "getObject", "(" + rowDesc + ")" + entityDesc, null, null);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "wasNull", "()Z", true);
@@ -185,12 +186,13 @@ public abstract class EntityFullFunc<T> {
}
if (attr.type() == boolean.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(ICONST_0);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getBoolean", "(IZ)Z", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(Z)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -203,12 +205,13 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == short.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(ICONST_0);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getShort", "(IS)S", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(S)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -221,12 +224,13 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == int.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(ICONST_0);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getInteger", "(II)I", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(I)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -239,12 +243,13 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == float.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(FCONST_0);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getFloat", "(IF)F", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(F)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -257,12 +262,13 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == long.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(LCONST_0);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getLong", "(IJ)J", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(J)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -275,12 +281,13 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == double.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(DCONST_0);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getDouble", "(ID)D", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(D)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -293,12 +300,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == Boolean.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getBoolean", "(I)Ljava/lang/Boolean;", true);
mv.visitMethodInsn(
INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/Boolean;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -310,11 +317,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == Short.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getShort", "(I)Ljava/lang/Short;", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/Short;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -326,12 +334,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == Integer.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getInteger", "(I)Ljava/lang/Integer;", true);
mv.visitMethodInsn(
INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/Integer;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -343,11 +351,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == Float.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getFloat", "(I)Ljava/lang/Float;", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/Float;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -359,11 +368,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == Long.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getLong", "(I)Ljava/lang/Long;", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/Long;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -375,11 +385,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == Double.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getDouble", "(I)Ljava/lang/Double;", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/Double;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -391,11 +402,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == String.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getString", "(I)Ljava/lang/String;", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "(Ljava/lang/String;)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -407,11 +419,12 @@ public abstract class EntityFullFunc<T> {
}
} else if (attr.type() == byte[].class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // row
Asms.visitInsn(mv, attrIndex);
mv.visitMethodInsn(INVOKEINTERFACE, rowName, "getBytes", "(I)[B", true);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), "([B)V", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
continue;
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
@@ -435,7 +448,7 @@ public abstract class EntityFullFunc<T> {
mv.visitMaxs(5, 3);
mv.visitEnd();
}
{ // 虚拟 getObject 方法
{ // 虚拟 getObject(DataResultSetRow row)
mv = cw.visitMethod(
ACC_PUBLIC | ACC_BRIDGE | ACC_SYNTHETIC, "getObject", "(" + rowDesc + ")" + objectDesc, null, null);
mv.visitVarInsn(ALOAD, 0);
@@ -445,6 +458,320 @@ public abstract class EntityFullFunc<T> {
mv.visitMaxs(2, 2);
mv.visitEnd();
}
{ // getObject(Serializable... values)
mv = cw.visitMethod(ACC_PUBLIC | ACC_VARARGS, "getObject", "(" + serisDesc + ")" + entityDesc, null, null);
// creator.create()
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, supDynName, "creator", creatorDesc);
mv.visitInsn(ICONST_0);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
mv.visitMethodInsn(INVOKEINTERFACE, creatorName, "create", "([Ljava/lang/Object;)" + objectDesc, true);
mv.visitTypeInsn(CHECKCAST, entityName);
mv.visitVarInsn(ASTORE, 2);
for (int i = 0; i < attrs.length; i++) {
final int attrIndex = i;
final Attribute<T, Serializable> attr = attrs[i];
java.lang.reflect.Method setter = null;
java.lang.reflect.Field field = null;
try {
setter = entityType.getMethod("set" + Utility.firstCharUpperCase(attr.field()), attr.type());
} catch (Exception e) {
try {
field = entityType.getField(attr.field());
} catch (Exception e2) {
// do nothing
}
}
if (setter == null && field == null) {
throw new SourceException("Not found '" + attr.field() + "' setter method or public field ");
}
if (attr.type() == boolean.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Z");
}
} else if (attr.type() == short.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Short");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Short");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false);
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "S");
}
} else if (attr.type() == int.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "I");
}
} else if (attr.type() == float.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "F");
}
} else if (attr.type() == long.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "J");
}
} else if (attr.type() == double.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "D");
}
} else if (attr.type() == Boolean.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/Boolean;");
}
} else if (attr.type() == Short.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Short");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Short");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/Short;");
}
} else if (attr.type() == Integer.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/Integer;");
}
} else if (attr.type() == Float.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/Float;");
}
} else if (attr.type() == Long.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/Long;");
}
} else if (attr.type() == Double.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/Double;");
}
} else if (attr.type() == String.class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/String");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "java/lang/String");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "Ljava/lang/String;");
}
} else if (attr.type() == byte[].class) {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "[B");
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
mv.visitTypeInsn(CHECKCAST, "[B");
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), "[B");
}
} else {
if (setter != null) {
String desc = Type.getMethodDescriptor(setter);
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
Asms.visitCheckCast(mv, setter.getParameterTypes()[0]);
mv.visitMethodInsn(INVOKEVIRTUAL, entityName, setter.getName(), desc, false);
} else if (field != null) {
String desc = Type.getDescriptor(field.getType());
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitVarInsn(ALOAD, 1); // values
Asms.visitInsn(mv, attrIndex);
mv.visitInsn(AALOAD);
Asms.visitCheckCast(mv, field.getType());
mv.visitFieldInsn(PUTFIELD, entityName, field.getName(), desc);
}
}
}
mv.visitVarInsn(ALOAD, 2); // obj
mv.visitInsn(ARETURN);
mv.visitMaxs(3, 3);
mv.visitEnd();
}
{ // 虚拟 getObject(Serializable... values)
int access = ACC_PUBLIC | ACC_BRIDGE | ACC_VARARGS | ACC_SYNTHETIC;
mv = cw.visitMethod(access, "getObject", "(" + serisDesc + ")" + objectDesc, null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "getObject", "(" + serisDesc + ")" + entityDesc, false);
mv.visitInsn(ARETURN);
mv.visitMaxs(2, 2);
mv.visitEnd();
}
cw.visitEnd();
byte[] bytes = cw.toByteArray();

View File

@@ -34,6 +34,8 @@ public class FullBean {
private double money;
private byte bit;
private Boolean flag2;
private Short status2;
@@ -58,8 +60,17 @@ public class FullBean {
return name;
}
public void setName(String name) {
public FullBean setName(String name) {
this.name = name;
return this;
}
public byte getBit() {
return bit;
}
public void setBit(byte bit) {
this.bit = bit;
}
public byte[] getImg() {

View File

@@ -34,6 +34,8 @@ public class FullBean2 {
public double money;
public byte bit;
public Boolean flag2;
public Short status2;

View File

@@ -5,6 +5,7 @@
package org.redkale.test.source;
import java.io.Serializable;
import java.math.BigInteger;
import org.redkale.source.DataResultSetRow;
import org.redkale.source.EntityFullFunc;
import org.redkale.util.Attribute;
@@ -32,6 +33,8 @@ public class FullBeanDynFunc extends EntityFullFunc<FullBean> {
setFieldValue(4, row, rs); // number: BigInteger
setFieldValue(4, row, rs); // bit: Byte
rs.setFlag(row.getBoolean(5, false));
rs.setStatus(row.getShort(6, (short) 0));
rs.setId(row.getInteger(7, 0));
@@ -47,4 +50,26 @@ public class FullBeanDynFunc extends EntityFullFunc<FullBean> {
rs.setMoney2(row.getDouble(10));
return rs;
}
@Override
public FullBean getObject(Serializable... values) {
FullBean rs = creator.create();
rs.setSeqid((Long) values[0]);
rs.setName((String) values[1]);
rs.setImg((byte[]) values[2]);
rs.setNumber((BigInteger) values[3]);
rs.setFlag((Boolean) values[4]);
rs.setStatus((Short) values[5]);
rs.setId((Integer) values[6]);
rs.setCreateTime((Long) values[7]);
rs.setPoint((Float) values[8]);
rs.setMoney((Double) values[9]);
rs.setFlag2((Boolean) values[10]);
rs.setStatus2((Short) values[11]);
rs.setId2((Integer) values[12]);
rs.setCreateTime2((Long) values[13]);
rs.setPoint2((Float) values[14]);
rs.setMoney2((Double) values[15]);
return rs;
}
}