influxORM代码调整

This commit is contained in:
2023-04-25 10:23:43 +08:00
parent 8aeb21265c
commit 3b6579dda5
9 changed files with 822 additions and 35 deletions

View File

@@ -22,7 +22,10 @@ public class InfluxProxyMapperFactory<T> implements FactoryBean {
@Override
public Object getObject() throws Exception {
Object proxyInstance = Proxy.newProxyInstance(
interfaceClass.getClassLoader(), new Class[]{interfaceClass}, new ProxyMapper(new ParameterHandler(), executor, new ResultSetHandler()));
interfaceClass.getClassLoader(),
new Class[]{interfaceClass},
new ProxyMapper(new ParameterHandler(), executor, new ResultSetHandler())
);
return proxyInstance;
}

View File

@@ -1,12 +1,14 @@
package com.njcn.influx.base;
import cn.hutool.core.util.ArrayUtil;
import com.njcn.influx.ano.Delete;
import com.njcn.influx.ano.Select;
import com.njcn.influx.ano.Insert;
import com.njcn.influx.core.InfluxExecutor;
import com.njcn.influx.core.ParameterHandler;
import com.njcn.influx.core.ResultSetHandler;
import com.njcn.influx.query.InfluxQueryWrapper;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
@@ -27,8 +29,22 @@ public class ProxyMapper implements InvocationHandler {
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public Object invoke(Object proxy, Method method, Object[] args) {
Annotation[] annotations = method.getAnnotations();
//没有注解的。查看参数是否为InfluxQueryWrapper
if (ArrayUtil.isEmpty(annotations)) {
Parameter[] parameters = method.getParameters();
if (args.length == 1 && args[0] instanceof InfluxQueryWrapper) {
InfluxQueryWrapper influxQueryWrapper = (InfluxQueryWrapper) args[0];
Class resultType = influxQueryWrapper.getResultEntity();
List<Object> resultList = executor.select(influxQueryWrapper.generateSql(), resultType);
//根据返回类型返回结果
Class<?> returnType = method.getReturnType();
return resultSetHandler.handleResultSet(resultList, returnType);
}
}
//采用注解的形式即将sql写在注解里
if (annotations.length == 1) {
Annotation annotation = annotations[0];
Class<? extends Annotation> annotationType = annotation.annotationType();
@@ -56,11 +72,9 @@ public class ProxyMapper implements InvocationHandler {
//拼接sql
String sql = deleteAnnotation.value();
Parameter[] parameters = method.getParameters();
String database = deleteAnnotation.database();
sql = parameterHandler.handleParameter(parameters, args, sql);
//执行sql
executor.delete(sql, database);
executor.delete(sql);
}
}
return null;