DataSqlMapperBuilder
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
package org.redkale.asm;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.redkale.annotation.Param;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
@@ -64,23 +66,37 @@ public class AsmMethodBean {
|
||||
}
|
||||
|
||||
public List<String> fieldNameList() {
|
||||
return paramNameList(null);
|
||||
}
|
||||
|
||||
public List<String> paramNameList(Method method) {
|
||||
if (params == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
int index = 0;
|
||||
Parameter[] ps = method == null ? null : method.getParameters();
|
||||
List<String> rs = new ArrayList<>(params.size());
|
||||
for (AsmMethodParam p : params) {
|
||||
rs.add(p.getName());
|
||||
Param pann = ps == null ? null : ps[index].getAnnotation(Param.class);
|
||||
rs.add(pann == null ? p.getName() : pann.value());
|
||||
index++;
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
public String[] fieldNameArray() {
|
||||
return paramNameArray(null);
|
||||
}
|
||||
|
||||
public String[] paramNameArray(Method method) {
|
||||
if (params == null) {
|
||||
return null;
|
||||
}
|
||||
Parameter[] ps = method == null ? null : method.getParameters();
|
||||
String[] rs = new String[params.size()];
|
||||
for (int i = 0; i < rs.length; i++) {
|
||||
rs[i] = params.get(i).getName();
|
||||
Param pann = ps == null ? null : ps[i].getAnnotation(Param.class);
|
||||
rs[i] = pann == null ? params.get(i).getName() : pann.value();
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
mv.visitMaxs(20, 20);
|
||||
mv.visitEnd();
|
||||
CacheAction action = new CacheAction(
|
||||
new CacheEntry(cached), method, serviceType, methodBean.fieldNameArray(), dynFieldName);
|
||||
new CacheEntry(cached), method, serviceType, methodBean.paramNameArray(method), dynFieldName);
|
||||
actions.put(dynFieldName, action);
|
||||
}
|
||||
{ // ThrowSupplier
|
||||
@@ -217,7 +217,11 @@ public class CacheAsmMethodBoost extends AsmMethodBoost {
|
||||
String dynFieldName = cached.dynField();
|
||||
AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method);
|
||||
CacheAction action = new CacheAction(
|
||||
new CacheEntry(cached), method, serviceType, methodBean.fieldNameArray(), dynFieldName);
|
||||
new CacheEntry(cached),
|
||||
method,
|
||||
serviceType,
|
||||
methodBean.paramNameArray(method),
|
||||
dynFieldName);
|
||||
actionMap.put(dynFieldName, action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public final class DataSqlMapperBuilder {
|
||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||
M mapper = (M) newClazz.getDeclaredConstructor().newInstance();
|
||||
{
|
||||
{ // DataSqlSource
|
||||
Field c = newClazz.getDeclaredField("_source");
|
||||
c.setAccessible(true);
|
||||
c.set(mapper, source);
|
||||
}
|
||||
{
|
||||
{ // Entity Class
|
||||
Field c = newClazz.getDeclaredField("_type");
|
||||
c.setAccessible(true);
|
||||
c.set(mapper, entityType);
|
||||
@@ -120,7 +120,7 @@ public final class DataSqlMapperBuilder {
|
||||
}
|
||||
DataNativeSqlInfo sqlInfo = nativeSqlParser.parse(signFunc, source.getType(), sql.value());
|
||||
AsmMethodBean methodBean = selfMethodBeans.get(AsmMethodBoost.getMethodBeanKey(method));
|
||||
List<String> fieldNames = methodBean.fieldNameList();
|
||||
List<String> fieldNames = methodBean.paramNameList(method);
|
||||
Class resultClass = resultClass(method);
|
||||
int flipperIndex = -1;
|
||||
if (resultClass.isAssignableFrom(Sheet.class)) {
|
||||
@@ -397,6 +397,7 @@ public final class DataSqlMapperBuilder {
|
||||
throw new SourceException(
|
||||
"Entity Class " + entityClass.getName() + " must be on Annotation @Entity");
|
||||
}
|
||||
return entityClass;
|
||||
}
|
||||
}
|
||||
throw new SourceException("Not found entity class from " + mapperType.getName());
|
||||
|
||||
Reference in New Issue
Block a user