Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3439fab690 | ||
|
|
14274c8d04 | ||
|
|
b3cbd9be71 | ||
|
|
b1d810188c | ||
|
|
4b48f85162 | ||
|
|
738b02e1b9 | ||
|
|
dc487f9226 | ||
|
|
bb2f43c317 | ||
|
|
be61aef123 | ||
|
|
6ad7888e85 | ||
|
|
242adb3c9e | ||
|
|
8654c69d0c | ||
|
|
a7999ff160 | ||
|
|
9c04b8aab0 | ||
|
|
3643fefc9c | ||
|
|
47189901e5 | ||
|
|
2577684897 | ||
|
|
77396df8fd | ||
|
|
c517a1d469 | ||
|
|
b7d7e6567b | ||
|
|
67807e913e | ||
|
|
19a950dab5 | ||
|
|
79b91f8386 | ||
|
|
0359a4b7e9 | ||
|
|
d89f410749 | ||
|
|
850f6dd060 |
@@ -16,7 +16,7 @@ import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* API接口文档生成类,作用:生成Application实例中所有HttpServer的可用HttpServlet的API接口方法 <br>
|
||||
* 继承 HttpBaseServlet 是为了获取 WebAction 信息
|
||||
继承 HttpBaseServlet 是为了获取 WebMapping 信息
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
@@ -63,8 +63,8 @@ public class ApiDocs extends HttpBaseServlet {
|
||||
servletmap.put("name", ws.name());
|
||||
servletmap.put("comment", ws.comment());
|
||||
|
||||
List<Map> actionsList = new ArrayList<>();
|
||||
servletmap.put("actions", actionsList);
|
||||
List<Map> mappingsList = new ArrayList<>();
|
||||
servletmap.put("mappings", mappingsList);
|
||||
final Class selfClz = servlet.getClass();
|
||||
Class clz = servlet.getClass();
|
||||
HashSet<String> actionurls = new HashSet<>();
|
||||
@@ -72,18 +72,18 @@ public class ApiDocs extends HttpBaseServlet {
|
||||
if (Modifier.isAbstract(clz.getModifiers())) break;
|
||||
for (Method method : clz.getMethods()) {
|
||||
if (method.getParameterCount() != 2) continue;
|
||||
WebAction action = method.getAnnotation(WebAction.class);
|
||||
WebMapping action = method.getAnnotation(WebMapping.class);
|
||||
if (action == null) continue;
|
||||
if (!action.inherited() && selfClz != clz) continue; //忽略不被继承的方法
|
||||
final Map<String, Object> actionmap = new LinkedHashMap<>();
|
||||
final Map<String, Object> mappingmap = new LinkedHashMap<>();
|
||||
if (actionurls.contains(action.url())) continue;
|
||||
actionmap.put("url", prefix + action.url());
|
||||
mappingmap.put("url", prefix + action.url());
|
||||
actionurls.add(action.url());
|
||||
actionmap.put("auth", method.getAnnotation(AuthIgnore.class) == null);
|
||||
actionmap.put("actionid", action.actionid());
|
||||
actionmap.put("comment", action.comment());
|
||||
mappingmap.put("auth", method.getAnnotation(AuthIgnore.class) == null);
|
||||
mappingmap.put("actionid", action.actionid());
|
||||
mappingmap.put("comment", action.comment());
|
||||
List<Map> paramsList = new ArrayList<>();
|
||||
actionmap.put("params", paramsList);
|
||||
mappingmap.put("params", paramsList);
|
||||
List<String> results = new ArrayList<>();
|
||||
for (final Class rtype : action.results()) {
|
||||
results.add(rtype.getName());
|
||||
@@ -121,7 +121,7 @@ public class ApiDocs extends HttpBaseServlet {
|
||||
} while ((loop = loop.getSuperclass()) != Object.class);
|
||||
typesmap.put(rtype.getName(), typemap);
|
||||
}
|
||||
actionmap.put("results", results);
|
||||
mappingmap.put("results", results);
|
||||
for (WebParam param : method.getAnnotationsByType(WebParam.class)) {
|
||||
final Map<String, Object> parammap = new LinkedHashMap<>();
|
||||
final boolean isarray = param.type().isArray();
|
||||
@@ -171,11 +171,11 @@ public class ApiDocs extends HttpBaseServlet {
|
||||
|
||||
typesmap.put(ptype.getName(), typemap);
|
||||
}
|
||||
actionmap.put("result", action.result());
|
||||
actionsList.add(actionmap);
|
||||
mappingmap.put("result", action.result());
|
||||
mappingsList.add(mappingmap);
|
||||
}
|
||||
} while ((clz = clz.getSuperclass()) != HttpServlet.class);
|
||||
actionsList.sort((o1, o2) -> ((String) o1.get("url")).compareTo((String) o2.get("url")));
|
||||
mappingsList.sort((o1, o2) -> ((String) o1.get("url")).compareTo((String) o2.get("url")));
|
||||
servletsList.add(servletmap);
|
||||
}
|
||||
servletsList.sort((o1, o2) -> {
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.redkale.boot;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
* 协议地址组合对象, 对应application.xml 中 resources->group 节点信息
|
||||
@@ -72,4 +73,8 @@ public class GroupInfo {
|
||||
this.addrs = addrs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ package org.redkale.boot;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 根据application.xml中的server节点中的protocol值来适配Server的加载逻辑
|
||||
* 根据application.xml中的server节点中的protocol值来适配Server的加载逻辑, 只能注解在NodeServer子类上
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.redkale.net.sncp.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* SNCP Server节点的配置Server
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
if (html.length > 2) html.push(' <tr><th colspan="5" style="border-bottom:0;"> </th></tr>');
|
||||
html.push(' <tr><th colspan="5" style="border-top:' + ((html.length > 2) ? 0 : 1) + ';">' + (servlet.comment || '未知模块') + '</th></tr>');
|
||||
html.push(' <tr><th>请求URL</th><th>描 述</th><th>鉴 权</th><th>参 数 <span style="font-size:12px;">(粗体: 必填项; 红色: Header; 蓝色: Cookie)</span></th><th>输 出</th></tr>');
|
||||
for (var k = 0; k < servlet.actions.length; k++) {
|
||||
var action = servlet.actions[k];
|
||||
for (var k = 0; k < servlet.mappings.length; k++) {
|
||||
var action = servlet.mappings[k];
|
||||
html.push(' <tr>');
|
||||
html.push('<td style="color:#ff00ff;">' + action.url + '</td>');
|
||||
html.push('<td>' + action.comment + '</td>');
|
||||
|
||||
@@ -92,6 +92,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
this.register(InetSocketAddress.class, InetSocketAddressSimpledCoder.instance);
|
||||
this.register(Pattern.class, PatternSimpledCoder.instance);
|
||||
this.register(CompletionHandler.class, CompletionHandlerSimpledCoder.instance);
|
||||
this.register(AsyncHandler.class, AsyncHandlerSimpledCoder.instance);
|
||||
this.register(URL.class, URLSimpledCoder.instance);
|
||||
this.register(URI.class, URISimpledCoder.instance);
|
||||
//---------------------------------------------------------
|
||||
|
||||
@@ -67,7 +67,8 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
||||
clazz = (Class) type;
|
||||
}
|
||||
this.creator = factory.loadCreator(clazz);
|
||||
|
||||
if (this.creator == null) throw new ConvertException("Cannot create a creator for " + clazz);
|
||||
|
||||
final Set<DeMember> list = new HashSet();
|
||||
final String[] cps = ObjectEncoder.findConstructorProperties(this.creator);
|
||||
try {
|
||||
@@ -76,7 +77,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||
ref = factory.findRef(field);
|
||||
if (ref != null && ref.ignore()) continue;
|
||||
Type t = ObjectEncoder.createClassType(field.getGenericType(), this.type);
|
||||
Type t = TypeToken.createClassType(field.getGenericType(), this.type);
|
||||
list.add(new DeMember(ObjectEncoder.createAttribute(factory, clazz, field, null, null), factory.loadDecoder(t)));
|
||||
}
|
||||
final boolean reversible = factory.isReversible();
|
||||
@@ -99,7 +100,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
||||
}
|
||||
ref = factory.findRef(method);
|
||||
if (ref != null && ref.ignore()) continue;
|
||||
Type t = ObjectEncoder.createClassType(method.getGenericParameterTypes()[0], this.type);
|
||||
Type t = TypeToken.createClassType(method.getGenericParameterTypes()[0], this.type);
|
||||
list.add(new DeMember(ObjectEncoder.createAttribute(factory, clazz, null, null, method), factory.loadDecoder(t)));
|
||||
}
|
||||
if (cps != null) { //可能存在某些构造函数中的字段名不存在setter方法
|
||||
@@ -115,7 +116,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
||||
//不存在setter方法
|
||||
try {
|
||||
Field f = clazz.getDeclaredField(constructorField);
|
||||
Type t = ObjectEncoder.createClassType(f.getGenericType(), this.type);
|
||||
Type t = TypeToken.createClassType(f.getGenericType(), this.type);
|
||||
list.add(new DeMember(ObjectEncoder.createAttribute(factory, clazz, f, null, null), factory.loadDecoder(t)));
|
||||
} catch (NoSuchFieldException nsfe) { //不存在field, 可能存在getter方法
|
||||
char[] fs = constructorField.toCharArray();
|
||||
@@ -127,7 +128,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
||||
} catch (NoSuchMethodException ex) {
|
||||
getter = clazz.getMethod("is" + mn);
|
||||
}
|
||||
Type t = ObjectEncoder.createClassType(getter.getGenericParameterTypes()[0], this.type);
|
||||
Type t = TypeToken.createClassType(getter.getGenericParameterTypes()[0], this.type);
|
||||
list.add(new DeMember(ObjectEncoder.createAttribute(factory, clazz, null, getter, null), factory.loadDecoder(t)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
||||
if (Modifier.isStatic(field.getModifiers())) continue;
|
||||
ref = factory.findRef(field);
|
||||
if (ref != null && ref.ignore()) continue;
|
||||
Type t = createClassType(field.getGenericType(), this.type);
|
||||
Type t = TypeToken.createClassType(field.getGenericType(), this.type);
|
||||
list.add(new EnMember(createAttribute(factory, clazz, field, null, null), factory.loadEncoder(t)));
|
||||
}
|
||||
for (final Method method : clazz.getMethods()) {
|
||||
@@ -91,7 +91,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
||||
}
|
||||
ref = factory.findRef(method);
|
||||
if (ref != null && ref.ignore()) continue;
|
||||
Type t = createClassType(method.getGenericReturnType(), this.type);
|
||||
Type t = TypeToken.createClassType(method.getGenericReturnType(), this.type);
|
||||
list.add(new EnMember(createAttribute(factory, clazz, null, method, null), factory.loadEncoder(t)));
|
||||
}
|
||||
this.members = list.toArray(new EnMember[list.size()]);
|
||||
@@ -146,42 +146,6 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
||||
return "ObjectEncoder{" + "type=" + type + ", members=" + Arrays.toString(members) + '}';
|
||||
}
|
||||
|
||||
static Type createClassType(final Type type, final Type declaringType0) {
|
||||
if (TypeToken.isClassType(type)) return type;
|
||||
if (type instanceof ParameterizedType) { // e.g. Map<String, String>
|
||||
final ParameterizedType pt = (ParameterizedType) type;
|
||||
final Type[] paramTypes = pt.getActualTypeArguments();
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
paramTypes[i] = createClassType(paramTypes[i], declaringType0);
|
||||
}
|
||||
return TypeToken.createParameterizedType(pt.getOwnerType(), pt.getRawType(), paramTypes);
|
||||
}
|
||||
Type declaringType = declaringType0;
|
||||
if (declaringType instanceof Class) {
|
||||
do {
|
||||
declaringType = ((Class) declaringType).getGenericSuperclass();
|
||||
if (declaringType == Object.class) return Object.class;
|
||||
} while (declaringType instanceof Class);
|
||||
}
|
||||
//存在通配符则declaringType 必须是 ParameterizedType
|
||||
if (!(declaringType instanceof ParameterizedType)) return Object.class;
|
||||
final ParameterizedType declaringPType = (ParameterizedType) declaringType;
|
||||
final Type[] virTypes = ((Class) declaringPType.getRawType()).getTypeParameters();
|
||||
final Type[] desTypes = declaringPType.getActualTypeArguments();
|
||||
if (type instanceof WildcardType) { // e.g. <? extends Serializable>
|
||||
final WildcardType wt = (WildcardType) type;
|
||||
for (Type f : wt.getUpperBounds()) {
|
||||
for (int i = 0; i < virTypes.length; i++) {
|
||||
if (virTypes[i].equals(f)) return desTypes.length <= i ? Object.class : desTypes[i];
|
||||
}
|
||||
}
|
||||
} else if (type instanceof TypeVariable) { // e.g. <? extends E>
|
||||
for (int i = 0; i < virTypes.length; i++) {
|
||||
if (virTypes[i].equals(type)) return desTypes.length <= i ? Object.class : desTypes[i];
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
//
|
||||
// static Type makeGenericType(final Type type, final Type[] virGenericTypes, final Type[] realGenericTypes) {
|
||||
// if (type instanceof Class) { //e.g. String
|
||||
@@ -230,7 +194,6 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
||||
// }
|
||||
// return type;
|
||||
// }
|
||||
|
||||
static boolean contains(String[] values, String value) {
|
||||
for (String str : values) {
|
||||
if (str.equals(value)) return true;
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* 简易类的序列化和反序列化操作类
|
||||
* 能序列化为Boolean、Number或者字符串的类视为简易类
|
||||
* 简易类的序列化和反序列化操作类 <br>
|
||||
* 能序列化为Boolean、Number或者字符串的类视为简易类 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -11,7 +11,8 @@ import static org.redkale.convert.Reader.SIGN_NULL;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* 以ByteBuffer为数据载体的BsonReader
|
||||
*
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
@@ -123,13 +124,13 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
}
|
||||
}
|
||||
return ((((long) readByte() & 0xff) << 56)
|
||||
| (((long) readByte() & 0xff) << 48)
|
||||
| (((long) readByte() & 0xff) << 40)
|
||||
| (((long) readByte() & 0xff) << 32)
|
||||
| (((long) readByte() & 0xff) << 24)
|
||||
| (((long) readByte() & 0xff) << 16)
|
||||
| (((long) readByte() & 0xff) << 8)
|
||||
| (((long) readByte() & 0xff)));
|
||||
| (((long) readByte() & 0xff) << 48)
|
||||
| (((long) readByte() & 0xff) << 40)
|
||||
| (((long) readByte() & 0xff) << 32)
|
||||
| (((long) readByte() & 0xff) << 24)
|
||||
| (((long) readByte() & 0xff) << 16)
|
||||
| (((long) readByte() & 0xff) << 8)
|
||||
| (((long) readByte() & 0xff)));
|
||||
}
|
||||
|
||||
protected byte[] read(final int len) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.function.*;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
* 以ByteBuffer为数据载体的BsonWriter
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.redkale.convert.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
/**
|
||||
* BSON的ConvertFactory
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.redkale.convert.ext.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* BSON数据源
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
36
src/org/redkale/convert/ext/AsyncHandlerSimpledCoder.java
Normal file
36
src/org/redkale/convert/ext/AsyncHandlerSimpledCoder.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.convert.ext;
|
||||
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.util.AsyncHandler;
|
||||
|
||||
/**
|
||||
* AsyncHandlerSimpledCoder 的SimpledCoder实现, 只输出null
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @param <W> Writer输出的子类型
|
||||
*/
|
||||
public final class AsyncHandlerSimpledCoder<R extends Reader, W extends Writer> extends SimpledCoder<R, W, AsyncHandler> {
|
||||
|
||||
public static final AsyncHandlerSimpledCoder instance = new AsyncHandlerSimpledCoder();
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, AsyncHandler value) {
|
||||
out.writeObjectNull(AsyncHandler.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncHandler convertFrom(R in) {
|
||||
in.readObjectB(AsyncHandler.class);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,9 +11,10 @@ import org.redkale.convert.*;
|
||||
import static org.redkale.convert.Reader.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* 以ByteBuffer为数据载体的JsonReader <br>
|
||||
*
|
||||
* 只支持UTF-8格式
|
||||
*
|
||||
*
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.redkale.convert.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 以ByteBuffer为数据载体的JsonWriter
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.redkale.convert.ext.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* JSON的ConvertFactory
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -10,6 +10,7 @@ import static org.redkale.convert.Reader.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* JSON数据源
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -66,8 +66,8 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
/**
|
||||
* 配合 @WebAction 使用。
|
||||
* 用于对@WebAction方法中参数描述
|
||||
* 配合 @WebMapping 使用。
|
||||
* 用于对@WebMapping方法中参数描述
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
@@ -101,6 +101,34 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
WebParam[] value();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 WebMapping 替代。
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@Deprecated
|
||||
@Documented
|
||||
@Target({METHOD})
|
||||
@Retention(RUNTIME)
|
||||
protected @interface WebAction {
|
||||
|
||||
int actionid() default 0;
|
||||
|
||||
String url();
|
||||
|
||||
String[] methods() default {};//允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法
|
||||
|
||||
String comment() default ""; //备注描述
|
||||
|
||||
boolean inherited() default true; //是否能被继承, 当 HttpBaseServlet 被继承后该方法是否能被子类继承
|
||||
|
||||
String result() default "Object"; //输出结果的数据类型
|
||||
|
||||
Class[] results() default {}; //输出结果的数据类型集合,由于结果类型可能是泛型而注解的参数值不支持泛型,因此加入明细数据类型集合
|
||||
}
|
||||
|
||||
/**
|
||||
* 配合 HttpBaseServlet 使用。
|
||||
* 用于对@WebServlet对应的url进行细分。 其url必须是包含WebServlet中定义的前缀, 且不能是正则表达式
|
||||
@@ -113,7 +141,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
@Documented
|
||||
@Target({METHOD})
|
||||
@Retention(RUNTIME)
|
||||
protected @interface WebAction {
|
||||
protected @interface WebMapping {
|
||||
|
||||
int actionid() default 0;
|
||||
|
||||
@@ -153,7 +181,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
int seconds() default 15;
|
||||
}
|
||||
|
||||
private Map.Entry<String, Entry>[] actions;
|
||||
private Map.Entry<String, Entry>[] mappings;
|
||||
|
||||
public boolean preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
return true;
|
||||
@@ -162,7 +190,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
@Override
|
||||
public final void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
if (!preExecute(request, response)) return;
|
||||
for (Map.Entry<String, Entry> en : actions) {
|
||||
for (Map.Entry<String, Entry> en : mappings) {
|
||||
if (request.getRequestURI().startsWith(en.getKey())) {
|
||||
Entry entry = en.getValue();
|
||||
if (!entry.checkMethod(request.getMethod())) {
|
||||
@@ -193,13 +221,13 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
WebServlet ws = this.getClass().getAnnotation(WebServlet.class);
|
||||
if (ws != null && !ws.repair()) path = "";
|
||||
HashMap<String, Entry> map = load();
|
||||
this.actions = new Map.Entry[map.size()];
|
||||
this.mappings = new Map.Entry[map.size()];
|
||||
int i = -1;
|
||||
for (Map.Entry<String, Entry> en : map.entrySet()) {
|
||||
actions[++i] = new AbstractMap.SimpleEntry<>(path + en.getKey(), en.getValue());
|
||||
mappings[++i] = new AbstractMap.SimpleEntry<>(path + en.getKey(), en.getValue());
|
||||
}
|
||||
//必须要倒排序, /query /query1 /query12 确保含子集的优先匹配 /query12 /query1 /query
|
||||
Arrays.sort(actions, (o1, o2) -> o2.getKey().compareTo(o1.getKey()));
|
||||
Arrays.sort(mappings, (o1, o2) -> o2.getKey().compareTo(o1.getKey()));
|
||||
}
|
||||
|
||||
public final void postDestroy(HttpContext context, AnyValue config) {
|
||||
@@ -242,17 +270,20 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
if (exps.length > 0 && (exps.length != 1 || exps[0] != IOException.class)) continue;
|
||||
//-----------------------------------------------
|
||||
|
||||
final WebMapping mapping = method.getAnnotation(WebMapping.class);
|
||||
final WebAction action = method.getAnnotation(WebAction.class);
|
||||
if (action == null) continue;
|
||||
if (!action.inherited() && selfClz != clz) continue; //忽略不被继承的方法
|
||||
final int actionid = action.actionid();
|
||||
final String name = action.url().trim();
|
||||
if (mapping == null && action == null) continue;
|
||||
final boolean inherited = mapping == null ? action.inherited() : mapping.inherited();
|
||||
if (!inherited && selfClz != clz) continue; //忽略不被继承的方法
|
||||
final int actionid = mapping == null ? action.actionid() : mapping.actionid();
|
||||
final String name = mapping == null ? action.url().trim() : mapping.url().trim();
|
||||
final String[] methods = mapping == null ? action.methods() : mapping.methods();
|
||||
if (nameset.containsKey(name)) {
|
||||
if (nameset.get(name) != clz) continue;
|
||||
throw new RuntimeException(this.getClass().getSimpleName() + " has two same " + WebAction.class.getSimpleName() + "(" + name + ")");
|
||||
throw new RuntimeException(this.getClass().getSimpleName() + " has two same " + WebMapping.class.getSimpleName() + "(" + name + ")");
|
||||
}
|
||||
nameset.put(name, clz);
|
||||
map.put(name, new Entry(typeIgnore, serviceid, actionid, name, action.methods(), method, createHttpServlet(method)));
|
||||
map.put(name, new Entry(typeIgnore, serviceid, actionid, name, methods, method, createHttpServlet(method)));
|
||||
}
|
||||
} while ((clz = clz.getSuperclass()) != HttpBaseServlet.class);
|
||||
return map;
|
||||
|
||||
@@ -512,6 +512,123 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
return requestURI.substring(requestURI.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: short type = request.getRequstURILastPath((short)0); //type = 2
|
||||
*
|
||||
* @param defvalue 默认short值
|
||||
*
|
||||
* @return short值
|
||||
*/
|
||||
public short getRequstURILastPath(short defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
if (val.isEmpty()) return defvalue;
|
||||
return val.isEmpty() ? defvalue : Short.parseShort(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: short type = request.getRequstURILastPath(16, (short)0); //type = 2
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param defvalue 默认short值
|
||||
*
|
||||
* @return short值
|
||||
*/
|
||||
public short getRequstURILastPath(int radix, short defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
if (val.isEmpty()) return defvalue;
|
||||
return val.isEmpty() ? defvalue : Short.parseShort(val, radix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: int type = request.getRequstURILastPath(0); //type = 2
|
||||
*
|
||||
* @param defvalue 默认int值
|
||||
*
|
||||
* @return int值
|
||||
*/
|
||||
public int getRequstURILastPath(int defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
return val.isEmpty() ? defvalue : Integer.parseInt(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: int type = request.getRequstURILastPath(16, 0); //type = 2
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param defvalue 默认int值
|
||||
*
|
||||
* @return int值
|
||||
*/
|
||||
public int getRequstURILastPath(int radix, int defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
return val.isEmpty() ? defvalue : Integer.parseInt(val, radix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的float值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: float type = request.getRequstURILastPath(0.0f); //type = 2.0f
|
||||
*
|
||||
* @param defvalue 默认float值
|
||||
*
|
||||
* @return float值
|
||||
*/
|
||||
public float getRequstURILastPath(float defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
return val.isEmpty() ? defvalue : Float.parseFloat(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: long type = request.getRequstURILastPath(0L); //type = 2
|
||||
*
|
||||
* @param defvalue 默认long值
|
||||
*
|
||||
* @return long值
|
||||
*/
|
||||
public long getRequstURILastPath(long defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
return val.isEmpty() ? defvalue : Long.parseLong(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: long type = request.getRequstURILastPath(16, 0L); //type = 2
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param defvalue 默认long值
|
||||
*
|
||||
* @return long值
|
||||
*/
|
||||
public long getRequstURILastPath(int radix, long defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
return val.isEmpty() ? defvalue : Long.parseLong(val, radix);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的double值 <br>
|
||||
* 例如请求URL /pipes/record/query/2 <br>
|
||||
* 获取type参数: double type = request.getRequstURILastPath(0.0); //type = 2.0
|
||||
*
|
||||
* @param defvalue 默认double值
|
||||
*
|
||||
* @return double值
|
||||
*/
|
||||
public double getRequstURILastPath(double defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
return val.isEmpty() ? defvalue : Double.parseDouble(val);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 从prefix之后截取getRequestURI再对"/"进行分隔
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.nio.file.*;
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.logging.Level;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
@@ -200,6 +201,26 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建AsyncHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出
|
||||
*
|
||||
* @return AsyncHandler
|
||||
*/
|
||||
public AsyncHandler createAsyncHandler() {
|
||||
return AsyncHandler.create((v, a) -> {
|
||||
if (v instanceof org.redkale.service.RetResult) {
|
||||
finishJson((org.redkale.service.RetResult) v);
|
||||
} else if (v instanceof CharSequence) {
|
||||
finish(String.valueOf(v));
|
||||
} else {
|
||||
finishJson(v);
|
||||
}
|
||||
}, (t, a) -> {
|
||||
request.getContext().getLogger().log(Level.WARNING, "Servlet occur, forece to close channel. request = " + request, t);
|
||||
finish(500, null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象以JSON格式输出
|
||||
*
|
||||
@@ -457,7 +478,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* @param attachment 异步回调参数
|
||||
* @param handler 异步回调函数
|
||||
*/
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, CompletionHandler<Integer, A> handler) {
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, AsyncHandler<Integer, A> handler) {
|
||||
if (!this.headsended) {
|
||||
if (this.contentLength < 0) this.contentLength = buffer == null ? 0 : buffer.remaining();
|
||||
ByteBuffer headbuf = createHeader();
|
||||
@@ -796,7 +817,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
this.bufferHandler = bufferHandler;
|
||||
}
|
||||
|
||||
protected final class TransferFileHandler implements CompletionHandler<Integer, ByteBuffer> {
|
||||
protected final class TransferFileHandler implements AsyncHandler<Integer, ByteBuffer> {
|
||||
|
||||
private final AsynchronousFileChannel filechannel;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public final class Rest {
|
||||
final String attrDesc = Type.getDescriptor(org.redkale.util.Attribute.class);
|
||||
final String authDesc = Type.getDescriptor(HttpBaseServlet.AuthIgnore.class);
|
||||
final String cacheDesc = Type.getDescriptor(HttpBaseServlet.HttpCacheable.class);
|
||||
final String actionDesc = Type.getDescriptor(HttpBaseServlet.WebAction.class);
|
||||
final String mappingDesc = Type.getDescriptor(HttpBaseServlet.WebMapping.class);
|
||||
final String webparamDesc = Type.getDescriptor(HttpBaseServlet.WebParam.class);
|
||||
final String webparamsDesc = Type.getDescriptor(HttpBaseServlet.WebParams.class);
|
||||
final String sourcetypeDesc = Type.getDescriptor(HttpBaseServlet.ParamSourceType.class);
|
||||
@@ -122,7 +122,7 @@ public final class Rest {
|
||||
AsmMethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
Map<String, Object> classMap = new LinkedHashMap<>();
|
||||
List<Map<String, Object>> actionMaps = new ArrayList<>();
|
||||
List<Map<String, Object>> mappingMaps = new ArrayList<>();
|
||||
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
|
||||
|
||||
{ //RestDynamic
|
||||
@@ -175,7 +175,7 @@ public final class Rest {
|
||||
|
||||
final List<MappingEntry> entrys = new ArrayList<>();
|
||||
final Map<String, org.redkale.util.Attribute> restAttributes = new LinkedHashMap<>();
|
||||
|
||||
//获取所有可以转换成WebMapping的方法
|
||||
for (final Method method : serviceType.getMethods()) {
|
||||
if (Modifier.isStatic(method.getModifiers())) continue;
|
||||
Class[] extypes = method.getExceptionTypes();
|
||||
@@ -207,7 +207,9 @@ public final class Rest {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (entrys.isEmpty()) return null; //没有可WebAction的方法
|
||||
if (entrys.isEmpty()) return null; //没有可WebMapping的方法
|
||||
|
||||
//将每个Service可转换的方法生成HttpServlet对应的WebMapping方法
|
||||
for (final MappingEntry entry : entrys) {
|
||||
final Method method = entry.mappingMethod;
|
||||
final Class returnType = method.getReturnType();
|
||||
@@ -257,6 +259,7 @@ public final class Rest {
|
||||
int argIndex = 0;
|
||||
|
||||
List<Object[]> paramlist = new ArrayList<>();
|
||||
//解析方法中的每个参数
|
||||
for (final Parameter param : params) {
|
||||
final Class ptype = param.getType();
|
||||
String n = null;
|
||||
@@ -316,9 +319,9 @@ public final class Rest {
|
||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie});
|
||||
}
|
||||
|
||||
Map<String, Object> actionMap = new LinkedHashMap<>();
|
||||
{
|
||||
//设置 WebAction
|
||||
Map<String, Object> mappingMap = new LinkedHashMap<>();
|
||||
{ // 设置 Annotation
|
||||
//设置 WebMapping
|
||||
boolean reqpath = false;
|
||||
for (Object[] ps : paramlist) {
|
||||
if ("#".equals((String) ps[1])) {
|
||||
@@ -326,7 +329,7 @@ public final class Rest {
|
||||
break;
|
||||
}
|
||||
}
|
||||
av0 = mv.visitAnnotation(actionDesc, true);
|
||||
av0 = mv.visitAnnotation(mappingDesc, true);
|
||||
String url = "/" + defmodulename.toLowerCase() + "/" + entry.name + (reqpath ? "/" : "");
|
||||
av0.visit("url", url);
|
||||
av0.visit("actionid", entry.actionid);
|
||||
@@ -342,16 +345,16 @@ public final class Rest {
|
||||
av0.visit("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||
|
||||
av0.visitEnd();
|
||||
actionMap.put("url", url);
|
||||
actionMap.put("auth", entry.auth);
|
||||
actionMap.put("cachetimeout", entry.cacheseconds);
|
||||
actionMap.put("actionid", entry.actionid);
|
||||
actionMap.put("comment", entry.comment);
|
||||
actionMap.put("methods", entry.methods);
|
||||
actionMap.put("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||
mappingMap.put("url", url);
|
||||
mappingMap.put("auth", entry.auth);
|
||||
mappingMap.put("cachetimeout", entry.cacheseconds);
|
||||
mappingMap.put("actionid", entry.actionid);
|
||||
mappingMap.put("comment", entry.comment);
|
||||
mappingMap.put("methods", entry.methods);
|
||||
mappingMap.put("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||
}
|
||||
|
||||
{
|
||||
{ // 设置 Annotation
|
||||
av0 = mv.visitAnnotation(webparamsDesc, true);
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
//设置 WebParam
|
||||
@@ -373,10 +376,12 @@ public final class Rest {
|
||||
av0.visitEnd();
|
||||
}
|
||||
List<Map<String, Object>> paramMaps = new ArrayList<>();
|
||||
//获取每个参数的值
|
||||
boolean hasAsyncHandler = false;
|
||||
for (Object[] ps : paramlist) {
|
||||
Map<String, Object> paramMap = new LinkedHashMap<>();
|
||||
String pname = (String) ps[1]; //参数名
|
||||
Class ptype = (Class) ps[2];
|
||||
Class ptype = (Class) ps[2]; //参数类型
|
||||
int radix = (Integer) ps[3];
|
||||
String comment = (String) ps[4];
|
||||
boolean required = (Boolean) ps[5];
|
||||
@@ -391,7 +396,13 @@ public final class Rest {
|
||||
|
||||
paramMap.put("name", pname);
|
||||
paramMap.put("type", ptype.getName());
|
||||
if (annsid != null) { //HttpRequest.getSessionid(true|false)
|
||||
if (ptype == AsyncHandler.class) { //HttpResponse.createAsyncHandler()
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "createAsyncHandler", "()Lorg/redkale/util/AsyncHandler;", false);
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
hasAsyncHandler = true;
|
||||
} else if (annsid != null) { //HttpRequest.getSessionid(true|false)
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitInsn(annsid.create() ? ICONST_1 : ICONST_0);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getSessionid", "(Z)Ljava/lang/String;", false);
|
||||
@@ -723,7 +734,9 @@ public final class Rest {
|
||||
mv.visitVarInsn(ins[0], ins[1]);
|
||||
}
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, serviceTypeInternalName, method.getName(), methodDesc, false);
|
||||
if (returnType == void.class) {
|
||||
if (hasAsyncHandler) {
|
||||
mv.visitInsn(RETURN);
|
||||
} else if (returnType == void.class) {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKESTATIC, retInternalName, "success", "()" + retDesc, false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJson", "(" + retDesc + ")V", false);
|
||||
@@ -838,8 +851,8 @@ public final class Rest {
|
||||
maxLocals++;
|
||||
}
|
||||
mv.visitMaxs(maxStack, maxLocals);
|
||||
actionMap.put("params", paramMaps);
|
||||
actionMaps.add(actionMap);
|
||||
mappingMap.put("params", paramMaps);
|
||||
mappingMaps.add(mappingMap);
|
||||
} // end for each
|
||||
|
||||
for (String attrname : restAttributes.keySet()) {
|
||||
@@ -847,7 +860,7 @@ public final class Rest {
|
||||
fv.visitEnd();
|
||||
}
|
||||
|
||||
classMap.put("actions", actionMaps);
|
||||
classMap.put("mappings", mappingMaps);
|
||||
|
||||
{ //toString函数
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
|
||||
|
||||
@@ -40,7 +40,7 @@ public @interface RestMapping {
|
||||
String name() default "";
|
||||
|
||||
/**
|
||||
* 备注描述, 对应@WebAction.comment
|
||||
* 备注描述, 对应@WebMapping.comment
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@@ -54,7 +54,7 @@ public @interface RestMapping {
|
||||
boolean auth() default false;
|
||||
|
||||
/**
|
||||
* 操作ID值,鉴权时用到, 对应@WebAction.actionid
|
||||
* 操作ID值,鉴权时用到, 对应@WebMapping.actionid
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -68,7 +68,7 @@ public @interface RestMapping {
|
||||
int cacheseconds() default 0;
|
||||
|
||||
/**
|
||||
* 允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法, 对应@WebAction.methods
|
||||
* 允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法, 对应@WebMapping.methods
|
||||
*
|
||||
* @return String[]
|
||||
*/
|
||||
|
||||
@@ -85,7 +85,7 @@ public abstract class WebSocket {
|
||||
|
||||
//----------------------------------------------------------------
|
||||
/**
|
||||
* 发送消息体, 包含二进制/文本
|
||||
* 给自身发送消息体, 包含二进制/文本
|
||||
*
|
||||
* @param packet WebSocketPacket
|
||||
*
|
||||
@@ -99,7 +99,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送单一的文本消息
|
||||
* 给自身发送单一的文本消息
|
||||
*
|
||||
* @param text 不可为空
|
||||
*
|
||||
@@ -110,7 +110,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本消息
|
||||
* 给自身发送文本消息
|
||||
*
|
||||
* @param text 不可为空
|
||||
* @param last 是否最后一条
|
||||
@@ -139,7 +139,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送单一的二进制消息
|
||||
* 给自身发送单一的二进制消息
|
||||
*
|
||||
* @param data byte[]
|
||||
*
|
||||
@@ -150,7 +150,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送二进制消息
|
||||
* 给自身发送二进制消息
|
||||
*
|
||||
* @param data 不可为空
|
||||
* @param last 是否最后一条
|
||||
@@ -162,7 +162,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送消息, 消息类型是String或byte[]
|
||||
* 给自身发送消息, 消息类型是String或byte[]
|
||||
*
|
||||
* @param message 不可为空, 只能是String或者byte[]
|
||||
* @param last 是否最后一条
|
||||
@@ -289,7 +289,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线用户的节点地址列表
|
||||
* 获取指定groupid在线用户的节点地址列表
|
||||
*
|
||||
* @param groupid groupid
|
||||
*
|
||||
@@ -300,7 +300,7 @@ public abstract class WebSocket {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线用户的详细连接信息
|
||||
* 获取指定groupid在线用户的详细连接信息
|
||||
*
|
||||
* @param groupid groupid
|
||||
*
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.redkale.net.http;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import java.util.logging.*;
|
||||
@@ -128,7 +127,7 @@ public abstract class WebSocketServlet extends HttpServlet {
|
||||
response.setHeader("Connection", "Upgrade");
|
||||
response.addHeader("Upgrade", "websocket");
|
||||
response.addHeader("Sec-WebSocket-Accept", key);
|
||||
response.sendBody((ByteBuffer) null, null, new CompletionHandler<Integer, Void>() {
|
||||
response.sendBody((ByteBuffer) null, null, new AsyncHandler<Integer, Void>() {
|
||||
|
||||
@Override
|
||||
public void completed(Integer result, Void attachment) {
|
||||
|
||||
@@ -43,6 +43,10 @@ public final class SncpClient {
|
||||
|
||||
protected final Attribute[] paramAttrs; // 为null表示无RpcCall处理,index=0固定为null, 其他为参数标记的RpcCall回调方法
|
||||
|
||||
protected final int handlerFuncParamIndex;
|
||||
|
||||
protected final int handlerAttachParamIndex;
|
||||
|
||||
protected final int addressTargetParamIndex;
|
||||
|
||||
protected final int addressSourceParamIndex;
|
||||
@@ -60,16 +64,24 @@ public final class SncpClient {
|
||||
Annotation[][] anns = method.getParameterAnnotations();
|
||||
int targetAddrIndex = -1;
|
||||
int sourceAddrIndex = -1;
|
||||
|
||||
int handlerAttachIndex = -1;
|
||||
int handlerFuncIndex = -1;
|
||||
boolean hasattr = false;
|
||||
Attribute[] atts = new Attribute[paramTypes.length + 1];
|
||||
if (anns.length > 0) {
|
||||
Class<?>[] params = method.getParameterTypes();
|
||||
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (AsyncHandler.class.isAssignableFrom(params[i])) {
|
||||
handlerFuncIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < anns.length; i++) {
|
||||
if (anns[i].length > 0) {
|
||||
for (Annotation ann : anns[i]) {
|
||||
if (ann.annotationType() == RpcTargetAddress.class && SocketAddress.class.isAssignableFrom(params[i])) {
|
||||
if (ann.annotationType() == RpcAttachment.class) {
|
||||
handlerAttachIndex = i;
|
||||
} else if (ann.annotationType() == RpcTargetAddress.class && SocketAddress.class.isAssignableFrom(params[i])) {
|
||||
targetAddrIndex = i;
|
||||
} else if (ann.annotationType() == RpcSourceAddress.class && SocketAddress.class.isAssignableFrom(params[i])) {
|
||||
sourceAddrIndex = i;
|
||||
@@ -91,7 +103,18 @@ public final class SncpClient {
|
||||
}
|
||||
this.addressTargetParamIndex = targetAddrIndex;
|
||||
this.addressSourceParamIndex = sourceAddrIndex;
|
||||
this.handlerFuncParamIndex = handlerFuncIndex;
|
||||
this.handlerAttachParamIndex = handlerAttachIndex;
|
||||
this.paramAttrs = hasattr ? atts : null;
|
||||
if (handlerFuncIndex > 0) {
|
||||
Type handlerFuncType = this.paramTypes[handlerFuncIndex];
|
||||
if (handlerFuncType instanceof ParameterizedType) {
|
||||
ParameterizedType handlerpt = (ParameterizedType) handlerFuncType;
|
||||
//后续可以添加验证, AsyncHandler的第一个泛型必须与方法返回值类型相同, 第二个泛型必须与@RpcAttachment的参数类型相同
|
||||
//需要考虑AsyncHandler的子类形态, 有可能0、1、2、。。。多个泛型
|
||||
}
|
||||
this.paramTypes[handlerFuncIndex] = AsyncHandler.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,8 +245,9 @@ public final class SncpClient {
|
||||
|
||||
public void remoteSameGroup(final BsonConvert bsonConvert, final JsonConvert jsonConvert, Transport transport, final int index, final Object... params) {
|
||||
final SncpAction action = actions[index];
|
||||
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null; //不能让远程调用handler,因为之前本地方法已经调用过了
|
||||
for (InetSocketAddress addr : transport.getRemoteAddresses()) {
|
||||
remote0(bsonConvert, jsonConvert, transport, addr, action, params);
|
||||
remote0(null, bsonConvert, jsonConvert, transport, addr, action, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,8 +264,9 @@ public final class SncpClient {
|
||||
public void remoteDiffGroup(final BsonConvert bsonConvert, final JsonConvert jsonConvert, Transport[] transports, final int index, final Object... params) {
|
||||
if (transports == null || transports.length < 1) return;
|
||||
final SncpAction action = actions[index];
|
||||
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null; //不能让远程调用handler,因为之前本地方法已经调用过了
|
||||
for (Transport transport : transports) {
|
||||
remote0(bsonConvert, jsonConvert, transport, null, action, params);
|
||||
remote0(null, bsonConvert, jsonConvert, transport, null, action, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,8 +284,10 @@ public final class SncpClient {
|
||||
//只给远程模式调用的
|
||||
public <T> T remote(final BsonConvert bsonConvert, final JsonConvert jsonConvert, Transport transport, final int index, final Object... params) {
|
||||
final SncpAction action = actions[index];
|
||||
SncpFuture<byte[]> future = remote0(bsonConvert, jsonConvert, transport, null, action, params);
|
||||
|
||||
final AsyncHandler handlerFunc = action.handlerFuncParamIndex >= 0 ? (AsyncHandler) params[action.handlerFuncParamIndex] : null;
|
||||
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null;
|
||||
SncpFuture<byte[]> future = remote0(handlerFunc, bsonConvert, jsonConvert, transport, null, action, params);
|
||||
if (handlerFunc != null) return null;
|
||||
final BsonReader reader = bsonConvert.pollBsonReader();
|
||||
try {
|
||||
reader.setBytes(future.get(5, TimeUnit.SECONDS));
|
||||
@@ -282,22 +309,23 @@ public final class SncpClient {
|
||||
if (transports == null || transports.length < 1) return;
|
||||
remote(bsonConvert, jsonConvert, transports[0], index, params);
|
||||
for (int i = 1; i < transports.length; i++) {
|
||||
remote0(bsonConvert, jsonConvert, transports[i], null, actions[index], params);
|
||||
remote0(null, bsonConvert, jsonConvert, transports[i], null, actions[index], params);
|
||||
}
|
||||
}
|
||||
|
||||
private SncpFuture<byte[]> remote0(final BsonConvert bsonConvert, final JsonConvert jsonConvert, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||
private SncpFuture<byte[]> remote0(final AsyncHandler handler, final BsonConvert bsonConvert, final JsonConvert jsonConvert, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||
if ("rest".equalsIgnoreCase(transport.getSubprotocol())) {
|
||||
return remoteRest0(jsonConvert, transport, addr0, action, params);
|
||||
return remoteRest0(handler, jsonConvert, transport, addr0, action, params);
|
||||
}
|
||||
return remoteSncp0(bsonConvert, transport, addr0, action, params);
|
||||
return remoteSncp0(handler, bsonConvert, transport, addr0, action, params);
|
||||
}
|
||||
|
||||
private SncpFuture<byte[]> remoteRest0(final JsonConvert jsonConvert, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||
//尚未实现
|
||||
private SncpFuture<byte[]> remoteRest0(final AsyncHandler handler, final JsonConvert jsonConvert, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private SncpFuture<byte[]> remoteSncp0(final BsonConvert bsonConvert, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||
private SncpFuture<byte[]> remoteSncp0(final AsyncHandler handler, final BsonConvert bsonConvert, final Transport transport, final SocketAddress addr0, final SncpAction action, final Object... params) {
|
||||
Type[] myparamtypes = action.paramTypes;
|
||||
if (action.addressSourceParamIndex >= 0) params[action.addressSourceParamIndex] = this.clientAddress;
|
||||
final BsonWriter writer = bsonConvert.pollBsonWriter(transport.getBufferSupplier()); // 将head写入
|
||||
@@ -400,6 +428,24 @@ public final class SncpClient {
|
||||
future.set(this.body);
|
||||
transport.offerBuffer(buffer);
|
||||
transport.offerConnection(false, conn);
|
||||
if (handler != null) {
|
||||
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
||||
final BsonReader reader = bsonConvert.pollBsonReader();
|
||||
try {
|
||||
reader.setBytes(this.body);
|
||||
int i;
|
||||
while ((i = (reader.readByte() & 0xff)) != 0) {
|
||||
final Attribute attr = action.paramAttrs[i];
|
||||
attr.set(params[i - 1], bsonConvert.convertFrom(attr.type(), reader));
|
||||
}
|
||||
Object rs = bsonConvert.convertFrom(action.resultTypes, reader);
|
||||
handler.completed(rs, handlerAttach);
|
||||
} catch (Exception e) {
|
||||
handler.failed(e, handlerAttach);
|
||||
} finally {
|
||||
bsonConvert.offerBsonReader(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -408,6 +454,10 @@ public final class SncpClient {
|
||||
future.set(new RuntimeException(action.method + " sncp remote exec failed"));
|
||||
transport.offerBuffer(buffer);
|
||||
transport.offerConnection(true, conn);
|
||||
if (handler != null) {
|
||||
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
||||
handler.failed(exc, handlerAttach);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,6 +191,13 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
return !entry.isExpired();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final AsyncHandler<Boolean, K> handler, @RpcAttachment final K key) {
|
||||
boolean rs = exists(key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(K key) {
|
||||
if (key == null) return null;
|
||||
@@ -201,6 +208,13 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
return (V) entry.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(final AsyncHandler<V, K> handler, @RpcAttachment final K key) {
|
||||
V rs = get(key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public V getAndRefresh(K key, final int expireSeconds) {
|
||||
@@ -214,6 +228,13 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
return (V) entry.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getAndRefresh(final AsyncHandler<V, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
||||
V rs = getAndRefresh(key, expireSeconds);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void refresh(K key, final int expireSeconds) {
|
||||
@@ -224,6 +245,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
entry.expireSeconds = expireSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
||||
refresh(key, expireSeconds);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void set(K key, V value) {
|
||||
@@ -239,6 +266,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
||||
set(key, value);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void set(int expireSeconds, K key, V value) {
|
||||
@@ -254,6 +287,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(final AsyncHandler<Void, K> handler, final int expireSeconds, @RpcAttachment final K key, final V value) {
|
||||
set(expireSeconds, key, value);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void setExpireSeconds(K key, int expireSeconds) {
|
||||
@@ -263,6 +302,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
entry.expireSeconds = expireSeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpireSeconds(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
||||
setExpireSeconds(key, expireSeconds);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void remove(K key) {
|
||||
@@ -270,16 +315,36 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
container.remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(final AsyncHandler<Void, K> handler, @RpcAttachment final K key) {
|
||||
remove(key);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getCollection(final K key) {
|
||||
return (Collection<V>) get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getCollection(final AsyncHandler<Collection<V>, K> handler, @RpcAttachment final K key) {
|
||||
Collection<V> rs = getCollection(key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getCollectionAndRefresh(final K key, final int expireSeconds) {
|
||||
return (Collection<V>) getAndRefresh(key, expireSeconds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getCollectionAndRefresh(final AsyncHandler<Collection<V>, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
||||
Collection<V> rs = getCollectionAndRefresh(key, expireSeconds);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void appendListItem(K key, V value) {
|
||||
@@ -296,6 +361,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendListItem(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
||||
appendListItem(key, value);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void removeListItem(K key, V value) {
|
||||
@@ -305,6 +376,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
((Collection) entry.getValue()).remove(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListItem(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
||||
removeListItem(key, value);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void appendSetItem(K key, V value) {
|
||||
@@ -321,6 +398,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendSetItem(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
||||
appendSetItem(key, value);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun
|
||||
public void removeSetItem(K key, V value) {
|
||||
@@ -330,6 +413,12 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
((Set) entry.getValue()).remove(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSetItem(final AsyncHandler<Void, K> handler, @RpcAttachment final K key, final V value) {
|
||||
removeSetItem(key, value);
|
||||
if (handler != null) handler.completed(null, key);
|
||||
}
|
||||
|
||||
public static enum CacheEntryType {
|
||||
OBJECT, SET, LIST;
|
||||
}
|
||||
|
||||
@@ -33,336 +33,804 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
source.insert(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void insert(final AsyncHandler<Void, T[]> handler, @RpcAttachment @RpcCall(DataCallArrayAttribute.class) final T... values) {
|
||||
source.insert(values);
|
||||
if (handler != null) handler.completed(null, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(T... values) {
|
||||
return source.delete(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, T[]> handler, @RpcAttachment final T... values) {
|
||||
int rs = source.delete(values);
|
||||
if (handler != null) handler.completed(rs, values);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final Class<T> clazz, final Serializable... ids) {
|
||||
return source.delete(clazz, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, Serializable[]> handler, final Class<T> clazz, @RpcAttachment final Serializable... ids) {
|
||||
int rs = source.delete(clazz, ids);
|
||||
if (handler != null) handler.completed(rs, ids);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final Class<T> clazz, FilterNode node) {
|
||||
return source.delete(clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
int rs = source.delete(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final Class<T> clazz, final Flipper flipper, FilterNode node) {
|
||||
return source.delete(clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment FilterNode node) {
|
||||
int rs = source.delete(clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int update(T... values) {
|
||||
return source.update(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int update(final AsyncHandler<Integer, T[]> handler, @RpcAttachment final T... values) {
|
||||
int rs = source.update(values);
|
||||
if (handler != null) handler.completed(rs, values);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final Class<T> clazz, final Serializable id, final String column, final Serializable value) {
|
||||
return source.updateColumn(clazz, id, column, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable id, final String column, final Serializable value) {
|
||||
int rs = source.updateColumn(clazz, id, column, value);
|
||||
if (handler != null) handler.completed(rs, id);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final Class<T> clazz, final String column, final Serializable value, final FilterNode node) {
|
||||
return source.updateColumn(clazz, column, value, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final String column, final Serializable value, @RpcAttachment final FilterNode node) {
|
||||
int rs = source.updateColumn(clazz, column, value, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final Class<T> clazz, final Serializable id, final ColumnValue... values) {
|
||||
return source.updateColumn(clazz, id, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable id, final ColumnValue... values) {
|
||||
int rs = source.updateColumn(clazz, id, values);
|
||||
if (handler != null) handler.completed(rs, id);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final Class<T> clazz, final FilterNode node, final ColumnValue... values) {
|
||||
return source.updateColumn(clazz, node, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node, final ColumnValue... values) {
|
||||
int rs = source.updateColumn(clazz, node, values);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final Class<T> clazz, final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
return source.updateColumn(clazz, node, flipper, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
int rs = source.updateColumn(clazz, node, flipper, values);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(T bean, final String... columns) {
|
||||
return source.updateColumn(bean, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, @RpcAttachment final T bean, final String... columns) {
|
||||
int rs = source.updateColumn(bean, columns);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(T bean, final FilterNode node, final String... columns) {
|
||||
return source.updateColumn(bean, node, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, @RpcAttachment final FilterNode node, final String... columns) {
|
||||
int rs = source.updateColumn(bean, node, columns);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(T bean, final SelectColumn selects) {
|
||||
return source.updateColumn(bean, selects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, @RpcAttachment final T bean, final SelectColumn selects) {
|
||||
int rs = source.updateColumn(bean, selects);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(T bean, final FilterNode node, final SelectColumn selects) {
|
||||
return source.updateColumn(bean, node, selects);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, @RpcAttachment final FilterNode node, final SelectColumn selects) {
|
||||
int rs = source.updateColumn(bean, node, selects);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, FilterFunc func, final String column) {
|
||||
return source.getNumberResult(entityClass, func, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, @RpcAttachment final String column) {
|
||||
Number rs = source.getNumberResult(entityClass, func, column);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Number getNumberResult(final Class entityClass, FilterFunc func, final String column, FilterBean bean) {
|
||||
return getNumberResult(entityClass, func, column, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends FilterBean> Number getNumberResult(final AsyncHandler<Number, B> handler, final Class entityClass, final FilterFunc func, final String column, @RpcAttachment final B bean) {
|
||||
Number rs = source.getNumberResult(entityClass, func, column, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, FilterFunc func, final String column, FilterNode node) {
|
||||
return source.getNumberResult(entityClass, func, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, FilterNode> handler, final Class entityClass, final FilterFunc func, final String column, @RpcAttachment final FilterNode node) {
|
||||
Number rs = source.getNumberResult(entityClass, func, column, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, FilterFunc func, final Number defVal, final String column) {
|
||||
return source.getNumberResult(entityClass, func, defVal, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, @RpcAttachment final String column) {
|
||||
Number rs = source.getNumberResult(entityClass, func, defVal, column);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Number getNumberResult(final Class entityClass, FilterFunc func, final Number defVal, final String column, FilterBean bean) {
|
||||
return getNumberResult(entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, @RpcAttachment final String column, final FilterBean bean) {
|
||||
Number rs = source.getNumberResult(entityClass, func, defVal, column, bean);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, FilterFunc func, final Number defVal, final String column, FilterNode node) {
|
||||
return source.getNumberResult(entityClass, func, defVal, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, @RpcAttachment final String column, final FilterNode node) {
|
||||
Number rs = source.getNumberResult(entityClass, func, defVal, column, node);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final Class entityClass, final FilterFuncColumn... columns) {
|
||||
return source.getNumberMap(entityClass, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterFuncColumn[]> handler, final Class entityClass, @RpcAttachment final FilterFuncColumn... columns) {
|
||||
Map<String, N> rs = source.getNumberMap(entityClass, columns);
|
||||
if (handler != null) handler.completed(rs, columns);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final Class entityClass, final FilterBean bean, final FilterFuncColumn... columns) {
|
||||
return source.getNumberMap(entityClass, bean, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number, B extends FilterBean> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, B> handler, final Class entityClass, @RpcAttachment final B bean, final FilterFuncColumn... columns) {
|
||||
Map<String, N> rs = source.getNumberMap(entityClass, bean, columns);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final Class entityClass, final FilterNode node, final FilterFuncColumn... columns) {
|
||||
return source.getNumberMap(entityClass, node, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterNode> handler, final Class entityClass, @RpcAttachment final FilterNode node, final FilterFuncColumn... columns) {
|
||||
Map<String, N> rs = source.getNumberMap(entityClass, node, columns);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn) {
|
||||
return source.queryColumnMap(entityClass, keyColumn, func, funcColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, @RpcAttachment final String keyColumn, final FilterFunc func, final String funcColumn) {
|
||||
Map<K, N> rs = source.queryColumnMap(entityClass, keyColumn, func, funcColumn);
|
||||
if (handler != null) handler.completed(rs, keyColumn);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn, FilterBean bean) {
|
||||
return queryColumnMap(entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, @RpcAttachment final String keyColumn, final FilterFunc func, final String funcColumn, final FilterBean bean) {
|
||||
Map<K, N> rs = source.queryColumnMap(entityClass, keyColumn, func, funcColumn, bean);
|
||||
if (handler != null) handler.completed(rs, keyColumn);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn, FilterNode node) {
|
||||
return source.queryColumnMap(entityClass, keyColumn, func, funcColumn, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, @RpcAttachment final String keyColumn, final FilterFunc func, final String funcColumn, final FilterNode node) {
|
||||
Map<K, N> rs = source.queryColumnMap(entityClass, keyColumn, func, funcColumn, node);
|
||||
if (handler != null) handler.completed(rs, keyColumn);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final Serializable pk) {
|
||||
return source.find(clazz, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable pk) {
|
||||
T rs = source.find(clazz, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, SelectColumn selects, final Serializable pk) {
|
||||
return source.find(clazz, selects, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, SelectColumn selects, @RpcAttachment final Serializable pk) {
|
||||
T rs = source.find(clazz, selects, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final String column, final Serializable key) {
|
||||
return source.find(clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final String column, @RpcAttachment final Serializable key) {
|
||||
T rs = source.find(clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> T find(final Class<T> clazz, FilterBean bean) {
|
||||
return find(clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
T rs = source.find(clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, FilterNode node) {
|
||||
return source.find(clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
T rs = source.find(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> T find(final Class<T> clazz, final SelectColumn selects, FilterBean bean) {
|
||||
return find(clazz, selects, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final B bean) {
|
||||
T rs = source.find(clazz, selects, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
return source.find(clazz, selects, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final FilterNode node) {
|
||||
T rs = source.find(clazz, selects, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable pk) {
|
||||
return source.findColumn(clazz, column, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, @RpcAttachment final Serializable pk) {
|
||||
Serializable rs = source.findColumn(clazz, column, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final FilterBean bean) {
|
||||
return source.findColumn(clazz, column, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Serializable findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, @RpcAttachment final B bean) {
|
||||
Serializable rs = source.findColumn(clazz, column, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final FilterNode node) {
|
||||
return source.findColumn(clazz, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, @RpcAttachment final FilterNode node) {
|
||||
Serializable rs = source.findColumn(clazz, column, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable defValue, final Serializable pk) {
|
||||
return source.findColumn(clazz, column, defValue, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable defValue, @RpcAttachment final Serializable pk) {
|
||||
Serializable rs = source.findColumn(clazz, column, defValue, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable defValue, final FilterBean bean) {
|
||||
return source.findColumn(clazz, column, defValue, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Serializable findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final Serializable defValue, @RpcAttachment final B bean) {
|
||||
Serializable rs = source.findColumn(clazz, column, defValue, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable defValue, final FilterNode node) {
|
||||
return source.findColumn(clazz, column, defValue, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final Serializable defValue, @RpcAttachment final FilterNode node) {
|
||||
Serializable rs = source.findColumn(clazz, column, defValue, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final Class<T> clazz, final Serializable pk) {
|
||||
return source.exists(clazz, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final AsyncHandler<Boolean, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable pk) {
|
||||
boolean rs = source.exists(clazz, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> boolean exists(final Class<T> clazz, FilterBean bean) {
|
||||
return exists(clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> boolean exists(final AsyncHandler<Boolean, B> handler, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
boolean rs = source.exists(clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final Class<T> clazz, FilterNode node) {
|
||||
return source.exists(clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final AsyncHandler<Boolean, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
boolean rs = source.exists(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(String selectedColumn, Class<T> clazz, final String column, final Serializable key) {
|
||||
return source.queryColumnSet(selectedColumn, clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, String> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final String column, final Serializable key) {
|
||||
HashSet<V> rs = source.queryColumnSet(selectedColumn, clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, V extends Serializable> HashSet<V> queryColumnSet(String selectedColumn, Class<T> clazz, FilterBean bean) {
|
||||
return queryColumnSet(selectedColumn, clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, B> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
HashSet<V> rs = source.queryColumnSet(selectedColumn, clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(String selectedColumn, Class<T> clazz, FilterNode node) {
|
||||
return source.queryColumnSet(selectedColumn, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
HashSet<V> rs = source.queryColumnSet(selectedColumn, clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(String selectedColumn, Class<T> clazz, final String column, final Serializable key) {
|
||||
return source.queryColumnList(selectedColumn, clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, Serializable> handler, final String selectedColumn, final Class<T> clazz, final String column, @RpcAttachment final Serializable key) {
|
||||
List<V> rs = source.queryColumnList(selectedColumn, clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, V extends Serializable> List<V> queryColumnList(String selectedColumn, Class<T> clazz, FilterBean bean) {
|
||||
return queryColumnList(selectedColumn, clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> List<V> queryColumnList(final AsyncHandler<List<V>, B> handler, String selectedColumn, Class<T> clazz, @RpcAttachment final B bean) {
|
||||
List<V> rs = source.queryColumnList(selectedColumn, clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(String selectedColumn, Class<T> clazz, FilterNode node) {
|
||||
return source.queryColumnList(selectedColumn, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
List<V> rs = source.queryColumnList(selectedColumn, clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, V extends Serializable> List<V> queryColumnList(String selectedColumn, Class<T> clazz, Flipper flipper, FilterBean bean) {
|
||||
return queryColumnList(selectedColumn, clazz, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> List<V> queryColumnList(final AsyncHandler<List<V>, B> handler, String selectedColumn, Class<T> clazz, Flipper flipper, @RpcAttachment final B bean) {
|
||||
List<V> rs = source.queryColumnList(selectedColumn, clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(String selectedColumn, Class<T> clazz, Flipper flipper, FilterNode node) {
|
||||
return source.queryColumnList(selectedColumn, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
List<V> rs = source.queryColumnList(selectedColumn, clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T, V extends Serializable> Sheet<V> queryColumnSheet(String selectedColumn, Class<T> clazz, Flipper flipper, FilterBean bean) {
|
||||
return queryColumnSheet(selectedColumn, clazz, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> Sheet<V> queryColumnSheet(final AsyncHandler<Sheet<V>, B> handler, String selectedColumn, Class<T> clazz, Flipper flipper, @RpcAttachment B bean) {
|
||||
Sheet<V> rs = source.queryColumnSheet(selectedColumn, clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> Sheet<V> queryColumnSheet(String selectedColumn, Class<T> clazz, Flipper flipper, FilterNode node) {
|
||||
return source.queryColumnSheet(selectedColumn, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> Sheet<V> queryColumnSheet(final AsyncHandler<Sheet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
Sheet<V> rs = source.queryColumnSheet(selectedColumn, clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final String column, final Serializable key) {
|
||||
return source.queryList(clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final String column, @RpcAttachment final Serializable key) {
|
||||
List<T> rs = source.queryList(clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> List<T> queryList(final Class<T> clazz, final FilterBean bean) {
|
||||
return queryList(clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
List<T> rs = source.queryList(clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final FilterNode node) {
|
||||
return source.queryList(clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
List<T> rs = source.queryList(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final FilterBean bean) {
|
||||
return queryList(clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final B bean) {
|
||||
List<T> rs = source.queryList(clazz, selects, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
return source.queryList(clazz, selects, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final FilterNode node) {
|
||||
List<T> rs = source.queryList(clazz, selects, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final Flipper flipper, final String column, final Serializable key) {
|
||||
return source.queryList(clazz, flipper, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final Flipper flipper, final String column, @RpcAttachment final Serializable key) {
|
||||
List<T> rs = source.queryList(clazz, flipper, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> List<T> queryList(final Class<T> clazz, final Flipper flipper, final FilterBean bean) {
|
||||
return queryList(clazz, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
List<T> rs = source.queryList(clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
return source.queryList(clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
List<T> rs = source.queryList(clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterBean bean) {
|
||||
return queryList(clazz, selects, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
List<T> rs = source.queryList(clazz, selects, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
return source.queryList(clazz, selects, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
List<T> rs = source.queryList(clazz, selects, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Sheet<T> querySheet(final Class<T> clazz, final Flipper flipper, final FilterBean bean) {
|
||||
return querySheet(clazz, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
Sheet<T> rs = source.querySheet(clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
return source.querySheet(clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
Sheet<T> rs = source.querySheet(clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final <T> Sheet<T> querySheet(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterBean bean) {
|
||||
return querySheet(clazz, selects, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
Sheet<T> rs = source.querySheet(clazz, selects, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
return source.querySheet(clazz, selects, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
Sheet<T> rs = source.querySheet(clazz, selects, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
source.getClass().getMethod("close").invoke(source);
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.redkale.service;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -28,6 +29,39 @@ public @interface RetLabel {
|
||||
|
||||
String value();
|
||||
|
||||
public static abstract class AbstractRetCode {
|
||||
|
||||
protected static final Map<Integer, String> rets = new HashMap();
|
||||
|
||||
protected static void load(Class clazz) {
|
||||
rets.putAll(RetLoader.load(clazz));
|
||||
}
|
||||
|
||||
public static RetResult retResult(int retcode) {
|
||||
if (retcode == 0) return RetResult.success();
|
||||
return new RetResult(retcode, retInfo(retcode));
|
||||
}
|
||||
|
||||
public static RetResult retResult(int retcode, Object... args) {
|
||||
if (retcode == 0) return RetResult.success();
|
||||
if (args == null || args.length < 1) return new RetResult(retcode, retInfo(retcode));
|
||||
String info = MessageFormat.format(retInfo(retcode), args);
|
||||
return new RetResult(retcode, info);
|
||||
}
|
||||
|
||||
public static RetResult set(RetResult result, int retcode, Object... args) {
|
||||
if (retcode == 0) return result.retcode(0).retinfo("");
|
||||
if (args == null || args.length < 1) return result.retcode(retcode).retinfo(retInfo(retcode));
|
||||
String info = MessageFormat.format(retInfo(retcode), args);
|
||||
return result.retcode(retcode).retinfo(info);
|
||||
}
|
||||
|
||||
public static String retInfo(int retcode) {
|
||||
if (retcode == 0) return "成功";
|
||||
return rets.getOrDefault(retcode, "未知错误");
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class RetLoader {
|
||||
|
||||
public static Map<Integer, String> load(Class clazz) {
|
||||
|
||||
26
src/org/redkale/service/RpcAttachment.java
Normal file
26
src/org/redkale/service/RpcAttachment.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.service;
|
||||
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* SNCP协议中用于CompletionHandler回调函数中的attach字段。
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
public @interface RpcAttachment {
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ package org.redkale.source;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -51,4 +52,37 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
||||
|
||||
public void removeSetItem(final K key, final V value);
|
||||
|
||||
//----------------------异步版---------------------------------
|
||||
public boolean exists(final AsyncHandler<Boolean, K> handler, final K key);
|
||||
|
||||
public V get(final AsyncHandler<V, K> handler, final K key);
|
||||
|
||||
public V getAndRefresh(final AsyncHandler<V, K> handler, final K key, final int expireSeconds);
|
||||
|
||||
public void refresh(final AsyncHandler<Void, K> handler, final K key, final int expireSeconds);
|
||||
|
||||
public void set(final AsyncHandler<Void, K> handler, final K key, final V value);
|
||||
|
||||
public void set(final AsyncHandler<Void, K> handler, final int expireSeconds, final K key, final V value);
|
||||
|
||||
public void setExpireSeconds(final AsyncHandler<Void, K> handler, final K key, final int expireSeconds);
|
||||
|
||||
public void remove(final AsyncHandler<Void, K> handler, final K key);
|
||||
|
||||
public Collection<V> getCollection(final AsyncHandler<Collection<V>, K> handler, final K key);
|
||||
|
||||
public Collection<V> getCollectionAndRefresh(final AsyncHandler<Collection<V>, K> handler, final K key, final int expireSeconds);
|
||||
|
||||
public void appendListItem(final AsyncHandler<Void, K> handler, final K key, final V value);
|
||||
|
||||
public void removeListItem(final AsyncHandler<Void, K> handler, final K key, final V value);
|
||||
|
||||
public void appendSetItem(final AsyncHandler<Void, K> handler, final K key, final V value);
|
||||
|
||||
public void removeSetItem(final AsyncHandler<Void, K> handler, final K key, final V value);
|
||||
|
||||
default boolean isOpen(final AsyncHandler<Boolean, Void> handler) {
|
||||
if (handler != null) handler.completed(Boolean.TRUE, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,6 +246,12 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void insert(final AsyncHandler<Void, T[]> handler, final T... values) {
|
||||
insert(values);
|
||||
if (handler != null) handler.completed(null, values);
|
||||
}
|
||||
|
||||
private <T> void insert(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
if (values.length == 0) return;
|
||||
try {
|
||||
@@ -416,6 +422,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, T[]> handler, final T... values) {
|
||||
int rs = delete(values);
|
||||
if (handler != null) handler.completed(rs, values);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int delete(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
if (values.length == 0) return -1;
|
||||
final Attribute primary = info.getPrimary();
|
||||
@@ -441,6 +454,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, Serializable[]> handler, final Class<T> clazz, final Serializable... ids) {
|
||||
int rs = delete(clazz, ids);
|
||||
if (handler != null) handler.completed(rs, ids);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int delete(final Connection conn, final EntityInfo<T> info, Serializable... keys) {
|
||||
if (keys.length == 0) return -1;
|
||||
int c = -1;
|
||||
@@ -489,6 +509,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node) {
|
||||
int rs = delete(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(Class<T> clazz, final Flipper flipper, FilterNode node) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -503,6 +530,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final Flipper flipper, FilterNode node) {
|
||||
int rs = delete(clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int delete(final Connection conn, final EntityInfo<T> info, final Flipper flipper, final FilterNode node) {
|
||||
int c = -1;
|
||||
try {
|
||||
@@ -588,6 +622,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int update(final AsyncHandler<Integer, T[]> handler, final T... values) {
|
||||
int rs = update(values);
|
||||
if (handler != null) handler.completed(rs, values);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int update(final Connection conn, final EntityInfo<T> info, T... values) {
|
||||
try {
|
||||
Class clazz = info.getType();
|
||||
@@ -679,6 +720,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, final Serializable id, final String column, final Serializable value) {
|
||||
int rs = updateColumn(clazz, id, column, value);
|
||||
if (handler != null) handler.completed(rs, id);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int updateColumn(Connection conn, final EntityInfo<T> info, Serializable id, String column, final Serializable value) {
|
||||
try {
|
||||
int c = -1;
|
||||
@@ -741,6 +789,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final String column, final Serializable value, final FilterNode node) {
|
||||
int rs = updateColumn(clazz, column, value, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int updateColumn(Connection conn, final EntityInfo<T> info, String column, final Serializable value, FilterNode node) {
|
||||
try {
|
||||
int c = -1;
|
||||
@@ -818,6 +873,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, final Serializable id, final ColumnValue... values) {
|
||||
int rs = updateColumn(clazz, id, values);
|
||||
if (handler != null) handler.completed(rs, id);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int updateColumn(final Connection conn, final EntityInfo<T> info, final Serializable id, final ColumnValue... values) {
|
||||
if (values == null || values.length < 1) return -1;
|
||||
try {
|
||||
@@ -899,6 +961,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node, final ColumnValue... values) {
|
||||
int rs = updateColumn(clazz, node, values);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键值更新对象的多个column对应的值, 必须是Entity Class
|
||||
*
|
||||
@@ -924,6 +993,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
int rs = updateColumn(clazz, node, flipper, values);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int updateColumn(final Connection conn, final EntityInfo<T> info, final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
if (values == null || values.length < 1) return -1;
|
||||
try {
|
||||
@@ -1000,6 +1076,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return updateColumn(bean, SelectColumn.createIncludes(columns));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final String... columns) {
|
||||
int rs = updateColumn(bean, columns);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final T bean, final SelectColumn selects) {
|
||||
final EntityInfo<T> info = loadEntityInfo((Class<T>) bean.getClass());
|
||||
@@ -1014,6 +1097,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final SelectColumn selects) {
|
||||
int rs = updateColumn(bean, selects);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int updateColumns(final Connection conn, final EntityInfo<T> info, final T bean, final SelectColumn selects) {
|
||||
if (bean == null || selects == null) return -1;
|
||||
try {
|
||||
@@ -1076,6 +1166,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return updateColumn(bean, node, SelectColumn.createIncludes(columns));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, final FilterNode node, final String... columns) {
|
||||
int rs = updateColumn(bean, node, columns);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final T bean, final FilterNode node, final SelectColumn selects) {
|
||||
final EntityInfo<T> info = loadEntityInfo((Class<T>) bean.getClass());
|
||||
@@ -1090,6 +1187,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, final FilterNode node, final SelectColumn selects) {
|
||||
int rs = updateColumn(bean, node, selects);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> int updateColumns(final Connection conn, final EntityInfo<T> info, final T bean, final FilterNode node, final SelectColumn selects) {
|
||||
if (bean == null || node == null || selects == null) return -1;
|
||||
try {
|
||||
@@ -1191,36 +1295,83 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return getNumberResult(entityClass, func, null, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final String column) {
|
||||
Number rs = getNumberResult(entityClass, func, column);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, FilterBean bean) {
|
||||
return getNumberResult(entityClass, func, null, column, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends FilterBean> Number getNumberResult(final AsyncHandler<Number, B> handler, final Class entityClass, final FilterFunc func, final String column, final B bean) {
|
||||
Number rs = getNumberResult(entityClass, func, column, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final String column, final FilterNode node) {
|
||||
return getNumberResult(entityClass, func, null, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, FilterNode> handler, final Class entityClass, final FilterFunc func, final String column, final FilterNode node) {
|
||||
Number rs = getNumberResult(entityClass, func, column, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column) {
|
||||
return getNumberResult(entityClass, func, defVal, column, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column) {
|
||||
Number rs = getNumberResult(entityClass, func, defVal, column);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column, FilterBean bean) {
|
||||
return getNumberResult(entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterBean bean) {
|
||||
return getNumberResult(handler, entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final Class entityClass, final FilterFuncColumn... columns) {
|
||||
return getNumberMap(entityClass, (FilterNode) null, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterFuncColumn[]> handler, final Class entityClass, final FilterFuncColumn... columns) {
|
||||
Map<String, N> rs = getNumberMap(entityClass, columns);
|
||||
if (handler != null) handler.completed(rs, columns);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final Class entityClass, final FilterBean bean, final FilterFuncColumn... columns) {
|
||||
return getNumberMap(entityClass, FilterNodeBean.createFilterNode(bean), columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number, B extends FilterBean> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, B> handler, final Class entityClass, final B bean, final FilterFuncColumn... columns) {
|
||||
Map<String, N> rs = getNumberMap(entityClass, bean, columns);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final Class entityClass, final FilterNode node, final FilterFuncColumn... columns) {
|
||||
if (columns == null || columns.length == 0) return new HashMap<>();
|
||||
@@ -1285,6 +1436,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterNode> handler, final Class entityClass, final FilterNode node, final FilterFuncColumn... columns) {
|
||||
Map<String, N> rs = getNumberMap(entityClass, node, columns);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterNode node) {
|
||||
final EntityInfo info = loadEntityInfo(entityClass);
|
||||
@@ -1321,17 +1479,36 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterNode node) {
|
||||
Number rs = getNumberResult(entityClass, func, defVal, column, node);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
//-----------------------queryColumnMap-----------------------------
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn) {
|
||||
return queryColumnMap(entityClass, keyColumn, func, funcColumn, (FilterNode) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn) {
|
||||
Map<K, N> rs = queryColumnMap(entityClass, keyColumn, func, funcColumn);
|
||||
if (handler != null) handler.completed(rs, keyColumn);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, FilterFunc func, final String funcColumn, FilterBean bean) {
|
||||
return queryColumnMap(entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterBean bean) {
|
||||
return queryColumnMap(handler, entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, FilterNode node) {
|
||||
final EntityInfo info = loadEntityInfo(entityClass);
|
||||
@@ -1370,6 +1547,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterNode node) {
|
||||
Map<K, N> rs = queryColumnMap(entityClass, keyColumn, func, funcColumn, node);
|
||||
if (handler != null) handler.completed(rs, keyColumn);
|
||||
return rs;
|
||||
}
|
||||
|
||||
//-----------------------find----------------------------
|
||||
/**
|
||||
* 根据主键获取对象
|
||||
@@ -1385,6 +1569,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return find(clazz, (SelectColumn) null, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final Serializable pk) {
|
||||
T rs = find(clazz, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(Class<T> clazz, final SelectColumn selects, Serializable pk) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1417,26 +1608,61 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, SelectColumn selects, final Serializable pk) {
|
||||
T rs = find(clazz, selects, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final String column, final Serializable key) {
|
||||
return find(clazz, null, FilterNode.create(column, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final String column, final Serializable key) {
|
||||
T rs = find(clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final FilterBean bean) {
|
||||
return find(clazz, null, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final B bean) {
|
||||
T rs = find(clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final FilterNode node) {
|
||||
return find(clazz, null, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final FilterNode node) {
|
||||
T rs = find(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final SelectColumn selects, final FilterBean bean) {
|
||||
return find(clazz, selects, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean) {
|
||||
T rs = find(clazz, selects, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1469,21 +1695,49 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
T rs = find(clazz, selects, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable pk) {
|
||||
return findColumn(clazz, column, null, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable pk) {
|
||||
Serializable rs = findColumn(clazz, column, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final FilterBean bean) {
|
||||
return findColumn(clazz, column, null, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Serializable findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final B bean) {
|
||||
Serializable rs = findColumn(clazz, column, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final FilterNode node) {
|
||||
return findColumn(clazz, column, null, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final FilterNode node) {
|
||||
Serializable rs = findColumn(clazz, column, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable defValue, final Serializable pk) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1524,11 +1778,25 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable defValue, final Serializable pk) {
|
||||
Serializable rs = findColumn(clazz, column, defValue, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable defValue, final FilterBean bean) {
|
||||
return findColumn(clazz, column, defValue, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Serializable findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final Serializable defValue, final B bean) {
|
||||
Serializable rs = findColumn(clazz, column, defValue, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final Class<T> clazz, final String column, final Serializable defValue, final FilterNode node) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1569,6 +1837,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final Serializable defValue, final FilterNode node) {
|
||||
Serializable rs = findColumn(clazz, column, defValue, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(Class<T> clazz, Serializable pk) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1603,11 +1878,25 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final AsyncHandler<Boolean, Serializable> handler, final Class<T> clazz, final Serializable pk) {
|
||||
boolean rs = exists(clazz, pk);
|
||||
if (handler != null) handler.completed(rs, pk);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final Class<T> clazz, final FilterBean bean) {
|
||||
return exists(clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> boolean exists(final AsyncHandler<Boolean, B> handler, final Class<T> clazz, final B bean) {
|
||||
boolean rs = exists(clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final Class<T> clazz, final FilterNode node) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1642,47 +1931,110 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean exists(final AsyncHandler<Boolean, FilterNode> handler, final Class<T> clazz, final FilterNode node) {
|
||||
boolean rs = exists(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
//-----------------------list set----------------------------
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(String selectedColumn, Class<T> clazz, String column, Serializable key) {
|
||||
return queryColumnSet(selectedColumn, clazz, FilterNode.create(column, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, String> handler, final String selectedColumn, final Class<T> clazz, final String column, final Serializable key) {
|
||||
HashSet<V> rs = queryColumnSet(selectedColumn, clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, column);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(final String selectedColumn, final Class<T> clazz, final FilterBean bean) {
|
||||
return new LinkedHashSet<>(queryColumnList(selectedColumn, clazz, bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, B> handler, final String selectedColumn, final Class<T> clazz, final B bean) {
|
||||
HashSet<V> rs = queryColumnSet(selectedColumn, clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(String selectedColumn, Class<T> clazz, FilterNode node) {
|
||||
return new LinkedHashSet<>(queryColumnList(selectedColumn, clazz, node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final FilterNode node) {
|
||||
HashSet<V> rs = queryColumnSet(selectedColumn, clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final String selectedColumn, final Class<T> clazz, final String column, final Serializable key) {
|
||||
return queryColumnList(selectedColumn, clazz, FilterNode.create(column, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, Serializable> handler, final String selectedColumn, final Class<T> clazz, final String column, final Serializable key) {
|
||||
List<V> rs = queryColumnList(selectedColumn, clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final String selectedColumn, final Class<T> clazz, final FilterBean bean) {
|
||||
return queryColumnList(selectedColumn, clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> List<V> queryColumnList(final AsyncHandler<List<V>, B> handler, String selectedColumn, Class<T> clazz, B bean) {
|
||||
List<V> rs = queryColumnList(selectedColumn, clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final String selectedColumn, final Class<T> clazz, final FilterNode node) {
|
||||
return (List<V>) queryColumnSheet(false, selectedColumn, clazz, null, node).list(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final FilterNode node) {
|
||||
List<V> rs = queryColumnList(selectedColumn, clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterBean bean) {
|
||||
return queryColumnList(selectedColumn, clazz, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> List<V> queryColumnList(final AsyncHandler<List<V>, B> handler, String selectedColumn, Class<T> clazz, Flipper flipper, B bean) {
|
||||
List<V> rs = queryColumnList(selectedColumn, clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
return (List<V>) queryColumnSheet(false, selectedColumn, clazz, flipper, node).list(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, Flipper flipper, final FilterNode node) {
|
||||
List<V> rs = queryColumnList(selectedColumn, clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据指定参数查询对象某个字段的集合
|
||||
* <p>
|
||||
@@ -1700,11 +2052,25 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return queryColumnSheet(selectedColumn, clazz, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable, B extends FilterBean> Sheet<V> queryColumnSheet(final AsyncHandler<Sheet<V>, B> handler, String selectedColumn, Class<T> clazz, Flipper flipper, B bean) {
|
||||
Sheet<V> rs = queryColumnSheet(selectedColumn, clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> Sheet<V> queryColumnSheet(final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
return queryColumnSheet(true, selectedColumn, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, V extends Serializable> Sheet<V> queryColumnSheet(final AsyncHandler<Sheet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
Sheet<V> rs = queryColumnSheet(selectedColumn, clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T, V extends Serializable> Sheet<V> queryColumnSheet(final boolean needtotal, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
Sheet<T> sheet = querySheet(true, needtotal, clazz, SelectColumn.createIncludes(selectedColumn), flipper, node);
|
||||
final Sheet<V> rs = new Sheet<>();
|
||||
@@ -1735,6 +2101,13 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return queryList(clazz, FilterNode.create(column, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final String column, final Serializable key) {
|
||||
List<T> rs = queryList(clazz, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据过滤对象FilterBean查询对象集合
|
||||
*
|
||||
@@ -1749,11 +2122,25 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return queryList(clazz, (SelectColumn) null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final B bean) {
|
||||
List<T> rs = queryList(clazz, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final FilterNode node) {
|
||||
return queryList(clazz, (SelectColumn) null, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final FilterNode node) {
|
||||
List<T> rs = queryList(clazz, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据过滤对象FilterBean查询对象集合, 对象只填充或排除SelectField指定的字段
|
||||
*
|
||||
@@ -1769,36 +2156,85 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return queryList(clazz, selects, (Flipper) null, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean) {
|
||||
List<T> rs = queryList(clazz, selects, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
return queryList(clazz, selects, (Flipper) null, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
List<T> rs = queryList(clazz, selects, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final Flipper flipper, final String column, final Serializable key) {
|
||||
return queryList(clazz, flipper, FilterNode.create(column, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final Flipper flipper, final String column, final Serializable key) {
|
||||
List<T> rs = queryList(clazz, flipper, column, key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final Flipper flipper, final FilterBean bean) {
|
||||
return queryList(clazz, null, flipper, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final Flipper flipper, final B bean) {
|
||||
List<T> rs = queryList(clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
return queryList(clazz, null, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
List<T> rs = queryList(clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterBean bean) {
|
||||
return querySheet(true, false, clazz, selects, flipper, FilterNodeBean.createFilterNode(bean)).list(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final B bean) {
|
||||
List<T> rs = queryList(clazz, selects, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
return querySheet(true, false, clazz, selects, flipper, node).list(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
List<T> rs = queryList(clazz, selects, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
//-----------------------sheet----------------------------
|
||||
/**
|
||||
* 根据过滤对象FilterBean和翻页对象Flipper查询一页的数据
|
||||
@@ -1815,11 +2251,25 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return querySheet(clazz, null, flipper, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final Flipper flipper, final B bean) {
|
||||
Sheet<T> rs = querySheet(clazz, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
return querySheet(clazz, null, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
Sheet<T> rs = querySheet(clazz, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据过滤对象FilterBean和翻页对象Flipper查询一页的数据, 对象只填充或排除SelectField指定的字段
|
||||
*
|
||||
@@ -1836,11 +2286,25 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return querySheet(true, true, clazz, selects, flipper, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final B bean) {
|
||||
Sheet<T> rs = querySheet(clazz, selects, flipper, bean);
|
||||
if (handler != null) handler.completed(rs, bean);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
return querySheet(true, true, clazz, selects, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
Sheet<T> rs = querySheet(clazz, selects, flipper, node);
|
||||
if (handler != null) handler.completed(rs, node);
|
||||
return rs;
|
||||
}
|
||||
|
||||
private <T> Sheet<T> querySheet(final boolean readcache, final boolean needtotal, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node) {
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
final EntityCache<T> cache = info.getCache();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -56,6 +56,20 @@ public abstract class AnyValue {
|
||||
return new DefaultAnyValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的DefaultAnyValue对象
|
||||
*
|
||||
* @param name name
|
||||
* @param value value值
|
||||
*
|
||||
* @return DefaultAnyValue对象
|
||||
*/
|
||||
public static final DefaultAnyValue create(String name, Number value) {
|
||||
DefaultAnyValue conf = new DefaultAnyValue();
|
||||
conf.addValue(name, value);
|
||||
return conf;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建含name-value值的DefaultAnyValue对象
|
||||
*
|
||||
|
||||
122
src/org/redkale/util/AsyncHandler.java
Normal file
122
src/org/redkale/util/AsyncHandler.java
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.util;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.function.*;
|
||||
|
||||
/**
|
||||
* 异步回调函数
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <V> 结果对象的泛型
|
||||
* @param <A> 附件对象的泛型
|
||||
*/
|
||||
public interface AsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
|
||||
/**
|
||||
* 创建 AsyncHandler 对象
|
||||
*
|
||||
* @param <V> 结果对象的泛型
|
||||
* @param <A> 附件对象的泛型
|
||||
* @param success 成功的回调函数
|
||||
* @param fail 失败的回调函数
|
||||
*
|
||||
* @return AsyncHandler
|
||||
*/
|
||||
public static <V, A> AsyncHandler<V, A> create(final BiConsumer<V, A> success, final BiConsumer<Throwable, A> fail) {
|
||||
return new AsyncHandler<V, A>() {
|
||||
@Override
|
||||
public void completed(V result, A attachment) {
|
||||
if (success != null) success.accept(result, attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, A attachment) {
|
||||
if (fail != null) fail.accept(exc, attachment);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 AsyncHandler 对象
|
||||
*
|
||||
* @param <V> 结果对象的泛型
|
||||
* @param <A> 附件对象的泛型
|
||||
* @param success 成功的回调函数
|
||||
* @param fail 失败的回调函数
|
||||
* @param handler 子回调函数
|
||||
*
|
||||
* @return AsyncHandler
|
||||
*/
|
||||
public static <V, A> AsyncHandler<V, A> create(final BiConsumer<V, A> success, final BiConsumer<Throwable, A> fail, final AsyncHandler<V, A> handler) {
|
||||
return new AsyncHandler<V, A>() {
|
||||
@Override
|
||||
public void completed(V result, A attachment) {
|
||||
if (success != null) success.accept(result, attachment);
|
||||
if (handler != null) handler.completed(result, attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, A attachment) {
|
||||
if (fail != null) fail.accept(exc, attachment);
|
||||
if (handler != null) handler.failed(exc, attachment);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建没有返回结果的 AsyncHandler 对象
|
||||
*
|
||||
* @param <A> 附件对象的泛型
|
||||
* @param success 成功的回调函数
|
||||
* @param fail 失败的回调函数
|
||||
*
|
||||
* @return AsyncHandler
|
||||
*/
|
||||
public static <A> AsyncHandler<Void, A> createNoResultHandler(final Consumer<A> success, final BiConsumer<Throwable, A> fail) {
|
||||
return new AsyncHandler<Void, A>() {
|
||||
@Override
|
||||
public void completed(Void result, A attachment) {
|
||||
if (success != null) success.accept(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, A attachment) {
|
||||
if (fail != null) fail.accept(exc, attachment);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建没有附件对象的 AsyncNoResultHandler 对象
|
||||
*
|
||||
* @param <V> 结果对象的泛型
|
||||
* @param success 成功的回调函数
|
||||
* @param fail 失败的回调函数
|
||||
*
|
||||
* @return AsyncHandler
|
||||
*/
|
||||
public static <V> AsyncHandler<V, Void> createNoAttachHandler(final Consumer<V> success, final Consumer<Throwable> fail) {
|
||||
return new AsyncHandler<V, Void>() {
|
||||
@Override
|
||||
public void completed(V result, Void attachment) {
|
||||
if (success != null) success.accept(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {
|
||||
if (fail != null) fail.accept(exc);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({TYPE, METHOD, FIELD, PARAMETER})
|
||||
@Target({TYPE, METHOD, FIELD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, TYPE_PARAMETER})
|
||||
@Retention(RUNTIME)
|
||||
public @interface Comment {
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
import jdk.internal.org.objectweb.asm.Type;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
@@ -80,12 +81,92 @@ public interface Creator<T> {
|
||||
public static @interface ConstructorParameters {
|
||||
|
||||
String[] value();
|
||||
|
||||
static class CreatorInner {
|
||||
|
||||
static class SimpleClassVisitor extends ClassVisitor {
|
||||
|
||||
private final String constructorDesc;
|
||||
|
||||
private final List<String> fieldnames;
|
||||
|
||||
private boolean started;
|
||||
|
||||
public SimpleClassVisitor(int api, List<String> fieldnames, String constructorDesc) {
|
||||
super(api);
|
||||
this.fieldnames = fieldnames;
|
||||
this.constructorDesc = constructorDesc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
if (java.lang.reflect.Modifier.isStatic(access) || !"<init>".equals(name)) return null;
|
||||
if (constructorDesc != null && !constructorDesc.equals(desc)) return null;
|
||||
if (this.started) return null;
|
||||
this.started = true;
|
||||
return new MethodVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
|
||||
if (index > 0) fieldnames.add(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, String constructorDesc) {
|
||||
String n = clazz.getName();
|
||||
InputStream in = clazz.getResourceAsStream(n.substring(n.lastIndexOf('.') + 1) + ".class");
|
||||
if (in == null) return null;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
||||
byte[] bytes = new byte[1024];
|
||||
int pos;
|
||||
try {
|
||||
while ((pos = in.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, pos);
|
||||
}
|
||||
in.close();
|
||||
} catch (IOException io) {
|
||||
return null;
|
||||
}
|
||||
final List<String> fieldnames = new ArrayList<>();
|
||||
new ClassReader(out.toByteArray()).accept(new SimpleClassVisitor(Opcodes.ASM5, fieldnames, constructorDesc), 0);
|
||||
if (fieldnames.isEmpty()) return null;
|
||||
return getConstructorField(clazz, fieldnames.toArray(new String[fieldnames.size()]));
|
||||
}
|
||||
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, String[] names) {
|
||||
SimpleEntry<String, Class>[] se = new SimpleEntry[names.length];
|
||||
for (int i = 0; i < names.length; i++) { //查询参数名对应的Field
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(names[i]);
|
||||
se[i] = new SimpleEntry<>(field.getName(), field.getType());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return se;
|
||||
}
|
||||
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, Parameter[] params) {
|
||||
SimpleEntry<String, Class>[] se = new SimpleEntry[params.length];
|
||||
for (int i = 0; i < params.length; i++) { //查询参数名对应的Field
|
||||
try {
|
||||
Field field = clazz.getDeclaredField(params[i].getName());
|
||||
se[i] = new SimpleEntry<>(field.getName(), field.getType());
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return se;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建对象
|
||||
*
|
||||
* @param params 构造函数的参数
|
||||
*
|
||||
* @return 构建的对象
|
||||
*/
|
||||
public T create(Object... params);
|
||||
@@ -95,6 +176,7 @@ public interface Creator<T> {
|
||||
*
|
||||
* @param <T> 构建类的数据类型
|
||||
* @param clazz 构建类
|
||||
*
|
||||
* @return Creator对象
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -109,7 +191,7 @@ public interface Creator<T> {
|
||||
if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) {
|
||||
throw new RuntimeException("[" + clazz + "] is a interface or abstract class, cannot create it's Creator.");
|
||||
}
|
||||
for (final Method method : clazz.getDeclaredMethods()) {
|
||||
for (final Method method : clazz.getDeclaredMethods()) { //查找类中是否存在提供创建Creator实例的静态方法
|
||||
if (!Modifier.isStatic(method.getModifiers())) continue;
|
||||
if (method.getParameterTypes().length != 0) continue;
|
||||
if (method.getReturnType() != Creator.class) continue;
|
||||
@@ -133,53 +215,86 @@ public interface Creator<T> {
|
||||
return (Creator) Class.forName(newDynName.replace('/', '.')).newInstance();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
Constructor<T> constructor0 = null;
|
||||
for (Constructor c : clazz.getConstructors()) { //优先找public 的构造函数
|
||||
if (c.getParameterCount() == 0) {
|
||||
constructor0 = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) {//其次找非private带ConstructorProperties的构造函数
|
||||
for (Constructor c : clazz.getDeclaredConstructors()) {
|
||||
if (Modifier.isPrivate(c.getModifiers())) continue;
|
||||
if (c.getAnnotation(ConstructorProperties.class) != null) {
|
||||
constructor0 = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) {//再次找非private且带-parameters编译项的构造函数 java 8以上才支持
|
||||
for (Constructor c : clazz.getDeclaredConstructors()) {
|
||||
if (Modifier.isPrivate(c.getModifiers())) continue;
|
||||
Parameter[] params = c.getParameters();
|
||||
if (params.length == 0) continue;
|
||||
boolean flag = true;
|
||||
for (Parameter param : params) {
|
||||
try {
|
||||
clazz.getDeclaredField(param.getName());
|
||||
} catch (Exception e) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
constructor0 = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) {//最后找非private的空构造函数
|
||||
for (Constructor c : clazz.getDeclaredConstructors()) {
|
||||
if (Modifier.isPrivate(c.getModifiers())) continue;
|
||||
SimpleEntry<String, Class>[] constructorParameters0 = null; //构造函数的参数
|
||||
|
||||
if (constructor0 == null) { // 1、查找public的空参数构造函数
|
||||
for (Constructor c : clazz.getConstructors()) {
|
||||
if (c.getParameterCount() == 0) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = new SimpleEntry[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) { // 2、查找public带ConstructorProperties注解的构造函数
|
||||
for (Constructor c : clazz.getConstructors()) {
|
||||
ConstructorProperties cp = (ConstructorProperties) c.getAnnotation(ConstructorProperties.class);
|
||||
if (cp == null) continue;
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, cp.value());
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) { // 3、查找public且不带ConstructorProperties注解的构造函数
|
||||
List<Constructor> cs = new ArrayList<>();
|
||||
for (Constructor c : clazz.getConstructors()) {
|
||||
if (c.getAnnotation(ConstructorProperties.class) != null) continue;
|
||||
if (c.getParameterCount() < 1) continue;
|
||||
cs.add(c);
|
||||
}
|
||||
//优先参数最多的构造函数
|
||||
cs.sort((o1, o2) -> o2.getParameterCount() - o1.getParameterCount());
|
||||
for (Constructor c : cs) {
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, Type.getConstructorDescriptor(c));
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) { // 4、查找非private带ConstructorProperties的构造函数
|
||||
for (Constructor c : clazz.getDeclaredConstructors()) {
|
||||
if (Modifier.isPublic(c.getModifiers()) || Modifier.isPrivate(c.getModifiers())) continue;
|
||||
ConstructorProperties cp = (ConstructorProperties) c.getAnnotation(ConstructorProperties.class);
|
||||
if (cp == null) continue;
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, cp.value());
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constructor0 == null) { // 5、查找非private且不带ConstructorProperties的构造函数
|
||||
List<Constructor> cs = new ArrayList<>();
|
||||
for (Constructor c : clazz.getDeclaredConstructors()) {
|
||||
if (Modifier.isPublic(c.getModifiers()) || Modifier.isPrivate(c.getModifiers())) continue;
|
||||
if (c.getAnnotation(ConstructorProperties.class) != null) continue;
|
||||
if (c.getParameterCount() < 1) continue;
|
||||
cs.add(c);
|
||||
}
|
||||
//优先参数最多的构造函数
|
||||
cs.sort((o1, o2) -> o2.getParameterCount() - o1.getParameterCount());
|
||||
for (Constructor c : cs) {
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, Type.getConstructorDescriptor(c));
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final Constructor<T> constructor = constructor0;
|
||||
if (constructor == null) throw new RuntimeException("[" + clazz + "] have no public or java.beans.ConstructorProperties-Annotation constructor.");
|
||||
final SimpleEntry<String, Class>[] constructorParameters = constructorParameters0;
|
||||
if (constructor == null || constructorParameters == null) {
|
||||
throw new RuntimeException("[" + clazz + "] have no public or java.beans.ConstructorProperties-Annotation constructor.");
|
||||
}
|
||||
//-------------------------------------------------------------
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
FieldVisitor fv;
|
||||
@@ -187,7 +302,7 @@ public interface Creator<T> {
|
||||
AnnotationVisitor av0;
|
||||
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, "Ljava/lang/Object;L" + supDynName + "<" + interDesc + ">;", "java/lang/Object", new String[]{supDynName});
|
||||
|
||||
{//构造方法
|
||||
{//Creator自身的构造方法
|
||||
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
|
||||
@@ -197,36 +312,19 @@ public interface Creator<T> {
|
||||
}
|
||||
{//create 方法
|
||||
mv = cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, "create", "([Ljava/lang/Object;)L" + interName + ";", null, null);
|
||||
ConstructorProperties cps = constructor.getAnnotation(ConstructorProperties.class);
|
||||
String[] cparams = cps == null ? null : cps.value();
|
||||
if (cparams == null && constructor.getParameterCount() > 0) { // java 8 以上版本才支持的 -parameters 编译项
|
||||
Parameter[] params = constructor.getParameters();
|
||||
String[] ss = new String[params.length];
|
||||
for (int i = 0; i < ss.length; i++) {
|
||||
try {
|
||||
clazz.getDeclaredField(params[i].getName());
|
||||
} catch (Exception e) { //没有该字段,直接退出
|
||||
ss = null;
|
||||
break;
|
||||
}
|
||||
ss[i] = params[i].getName();
|
||||
}
|
||||
cparams = ss;
|
||||
}
|
||||
if (cparams != null) {
|
||||
if (constructorParameters.length > 0) {
|
||||
av0 = mv.visitAnnotation(Type.getDescriptor(ConstructorParameters.class), true);
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
for (String n : cparams) {
|
||||
av1.visit(null, n);
|
||||
for (SimpleEntry<String, Class> n : constructorParameters) {
|
||||
av1.visit(null, n.getKey());
|
||||
}
|
||||
av1.visitEnd();
|
||||
av0.visitEnd();
|
||||
}
|
||||
final Class[] paramTypes = constructor.getParameterTypes();
|
||||
final int[] iconsts = {ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5};
|
||||
{ //有Primitive数据类型且值为null的参数需要赋默认值
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
final Class pt = paramTypes[i];
|
||||
for (int i = 0; i < constructorParameters.length; i++) {
|
||||
final Class pt = constructorParameters[i].getValue();
|
||||
if (!pt.isPrimitive()) continue;
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
if (i < 6) {
|
||||
@@ -275,7 +373,7 @@ public interface Creator<T> {
|
||||
mv.visitInsn(DUP);
|
||||
//---------------------------------------
|
||||
{
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
for (int i = 0; i < constructorParameters.length; i++) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
if (i < 6) {
|
||||
mv.visitInsn(iconsts[i]);
|
||||
@@ -283,7 +381,7 @@ public interface Creator<T> {
|
||||
mv.visitIntInsn(BIPUSH, i);
|
||||
}
|
||||
mv.visitInsn(AALOAD);
|
||||
final Class ct = paramTypes[i];
|
||||
final Class ct = constructorParameters[i].getValue();
|
||||
if (ct.isPrimitive()) {
|
||||
final Class bigct = Array.get(Array.newInstance(ct, 1), 0).getClass();
|
||||
mv.visitTypeInsn(CHECKCAST, bigct.getName().replace('.', '/'));
|
||||
@@ -301,7 +399,7 @@ public interface Creator<T> {
|
||||
//---------------------------------------
|
||||
mv.visitMethodInsn(INVOKESPECIAL, interName, "<init>", Type.getConstructorDescriptor(constructor), false);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs((paramTypes.length > 0 ? (paramTypes.length + 3) : 2), 2);
|
||||
mv.visitMaxs((constructorParameters.length > 0 ? (constructorParameters.length + 3) : 2), 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{ //虚拟 create 方法
|
||||
|
||||
@@ -38,6 +38,7 @@ public abstract class TypeToken<T> {
|
||||
* 例如: Map< String, String > 返回 ture; Map< ? extends Serializable, String > 返回false;
|
||||
*
|
||||
* @param type Type对象
|
||||
*
|
||||
* @return 是否可反解析
|
||||
*/
|
||||
public final static boolean isClassType(final Type type) {
|
||||
@@ -55,12 +56,58 @@ public abstract class TypeToken<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态创建类型为ParameterizedType或Class的Type
|
||||
*
|
||||
* @param type 当前泛型
|
||||
* @param declaringType0 子类
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public static Type createClassType(final Type type, final Type declaringType0) {
|
||||
if (isClassType(type)) return type;
|
||||
if (type instanceof ParameterizedType) { // e.g. Map<String, String>
|
||||
final ParameterizedType pt = (ParameterizedType) type;
|
||||
final Type[] paramTypes = pt.getActualTypeArguments();
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
paramTypes[i] = createClassType(paramTypes[i], declaringType0);
|
||||
}
|
||||
return createParameterizedType(pt.getOwnerType(), pt.getRawType(), paramTypes);
|
||||
}
|
||||
Type declaringType = declaringType0;
|
||||
if (declaringType instanceof Class) {
|
||||
do {
|
||||
declaringType = ((Class) declaringType).getGenericSuperclass();
|
||||
if (declaringType == Object.class) return Object.class;
|
||||
} while (declaringType instanceof Class);
|
||||
}
|
||||
//存在通配符则declaringType 必须是 ParameterizedType
|
||||
if (!(declaringType instanceof ParameterizedType)) return Object.class;
|
||||
final ParameterizedType declaringPType = (ParameterizedType) declaringType;
|
||||
final Type[] virTypes = ((Class) declaringPType.getRawType()).getTypeParameters();
|
||||
final Type[] desTypes = declaringPType.getActualTypeArguments();
|
||||
if (type instanceof WildcardType) { // e.g. <? extends Serializable>
|
||||
final WildcardType wt = (WildcardType) type;
|
||||
for (Type f : wt.getUpperBounds()) {
|
||||
for (int i = 0; i < virTypes.length; i++) {
|
||||
if (virTypes[i].equals(f)) return desTypes.length <= i ? Object.class : desTypes[i];
|
||||
}
|
||||
}
|
||||
} else if (type instanceof TypeVariable) { // e.g. <? extends E>
|
||||
for (int i = 0; i < virTypes.length; i++) {
|
||||
if (virTypes[i].equals(type)) return desTypes.length <= i ? Object.class : desTypes[i];
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态创建 ParameterizedType
|
||||
*
|
||||
* @param ownerType0 ParameterizedType 的 ownerType
|
||||
* @param rawType0 ParameterizedType 的 rawType
|
||||
* @param actualTypeArguments0 ParameterizedType 的 actualTypeArguments
|
||||
*
|
||||
* @return Type
|
||||
*/
|
||||
public static Type createParameterizedType(final Type ownerType0, final Type rawType0, final Type... actualTypeArguments0) {
|
||||
@@ -104,8 +151,8 @@ public abstract class TypeToken<T> {
|
||||
final ParameterizedType that = (ParameterizedType) o;
|
||||
if (this == that) return true;
|
||||
return Objects.equals(ownerType, that.getOwnerType())
|
||||
&& Objects.equals(rawType, that.getRawType())
|
||||
&& Arrays.equals(actualTypeArguments, that.getActualTypeArguments());
|
||||
&& Objects.equals(rawType, that.getRawType())
|
||||
&& Arrays.equals(actualTypeArguments, that.getActualTypeArguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,6 +44,9 @@ public interface HttpRequestDesc {
|
||||
//更新sessionid
|
||||
public String changeSessionid();
|
||||
|
||||
//指定值更新sessionid
|
||||
public String changeSessionid(String newsessionid);
|
||||
|
||||
//使sessionid失效
|
||||
public void invalidateSession();
|
||||
|
||||
@@ -80,6 +83,46 @@ public interface HttpRequestDesc {
|
||||
//截取getRequestURI最后的一个/后面的部分
|
||||
public String getRequstURILastPath();
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: short type = request.getRequstURILastPath((short)0); //type = 2
|
||||
public short getRequstURILastPath(short defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: short type = request.getRequstURILastPath((short)0); //type = 2
|
||||
public short getRequstURILastPath(int radix, short defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: int type = request.getRequstURILastPath(0); //type = 2
|
||||
public int getRequstURILastPath(int defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: int type = request.getRequstURILastPath(0); //type = 2
|
||||
public int getRequstURILastPath(int radix, int defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的float值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: float type = request.getRequstURILastPath(0.f); //type = 2.f
|
||||
public float getRequstURILastPath(float defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的long值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: long type = request.getRequstURILastPath(0L); //type = 2
|
||||
public long getRequstURILastPath(long defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的long值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: long type = request.getRequstURILastPath(0L); //type = 2
|
||||
public long getRequstURILastPath(int radix, long defvalue);
|
||||
|
||||
// 获取请求URL最后的一个/后面的部分的double值 <br>
|
||||
// 例如请求URL /pipes/record/query/2 <br>
|
||||
// 获取type参数: double type = request.getRequstURILastPath(0.0); //type = 2.0
|
||||
public double getRequstURILastPath(double defvalue);
|
||||
|
||||
//从prefix之后截取getRequestURI再对"/"进行分隔
|
||||
public String[] getRequstURIPaths(String prefix);
|
||||
|
||||
@@ -222,24 +265,24 @@ public interface HttpRequestDesc {
|
||||
|
||||
//获取指定的参数double值, 没有返回默认double值
|
||||
public double getDoubleParameter(String name, double defaultValue);
|
||||
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", false, 0);
|
||||
public org.redkale.source.Flipper getFlipper();
|
||||
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", needcreate, 0);
|
||||
public org.redkale.source.Flipper getFlipper(boolean needcreate);
|
||||
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", false, maxLimit);
|
||||
public org.redkale.source.Flipper getFlipper(int maxLimit);
|
||||
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", needcreate, maxLimit)
|
||||
public org.redkale.source.Flipper getFlipper(boolean needcreate, int maxLimit);
|
||||
|
||||
|
||||
//获取翻页对象 http://redkale.org/pipes/records/list/offset:0/limit:20/sort:createtime%20ASC
|
||||
//http://redkale.org/pipes/records/list?flipper={'offset':0,'limit':20, 'sort':'createtime ASC'}
|
||||
//以上两种接口都可以获取到翻页对象
|
||||
public org.redkale.source.Flipper getFlipper(String name, boolean needcreate, int maxLimit);
|
||||
|
||||
|
||||
//获取HTTP上下文对象
|
||||
public HttpContext getContext();
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.util.AsyncHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -59,8 +59,11 @@ public interface HttpResponseDesc {
|
||||
public HttpResponse skipHeader();
|
||||
|
||||
//异步输出指定内容
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, CompletionHandler<Integer, A> handler);
|
||||
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, AsyncHandler<Integer, A> handler);
|
||||
|
||||
//创建AsyncHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出
|
||||
public AsyncHandler createAsyncHandler();
|
||||
|
||||
//关闭HTTP连接,如果是keep-alive则不强制关闭
|
||||
public void finish();
|
||||
|
||||
@@ -88,12 +91,6 @@ public interface HttpResponseDesc {
|
||||
//将RetResult对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret);
|
||||
|
||||
//将对象以JavaScript格式输出
|
||||
public void finishJsResult(String var, Object result);
|
||||
|
||||
//将对象以JavaScript格式输出
|
||||
public void finishJsResult(JsonConvert jsonConvert, String var, Object result);
|
||||
|
||||
//将指定字符串以响应结果输出
|
||||
public void finish(String obj);
|
||||
|
||||
@@ -106,6 +103,9 @@ public interface HttpResponseDesc {
|
||||
//以404状态码输出
|
||||
public void finish404();
|
||||
|
||||
//将指定byte[]按响应结果输出
|
||||
public void finish(final byte[] bs);
|
||||
|
||||
//将指定ByteBuffer按响应结果输出
|
||||
public void finish(ByteBuffer buffer);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.redkale.net.http.*;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.source.DataSource;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.Sheet;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 类说明:
|
||||
@@ -76,4 +76,13 @@ public class HelloService implements Service {
|
||||
return source.find(HelloEntity.class, id);
|
||||
}
|
||||
|
||||
//异步查询单个
|
||||
@RestMapping(name = "asyncfind")
|
||||
public HelloEntity findHello(AsyncHandler handler, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
if (source != null) source.find(handler, HelloEntity.class, id);
|
||||
HelloEntity rs = new HelloEntity();
|
||||
rs.setHelloname("Hello名称");
|
||||
if (handler != null) handler.completed(rs, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,13 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
String url = "http://127.0.0.1:" + port + "/pipes/hello/update?entity={}&bean2={}";
|
||||
System.out.println(Utility.postHttpContent(url, headers, null));
|
||||
|
||||
url = "http://127.0.0.1:" + port + "/pipes/hello/asyncfind/1234";
|
||||
System.out.println(Utility.postHttpContent(url, headers, null));
|
||||
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/create")
|
||||
@WebMapping(url = "/hello/create")
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
@@ -54,7 +57,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/delete/")
|
||||
@WebMapping(url = "/hello/delete/")
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
@@ -63,7 +66,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/update")
|
||||
@WebMapping(url = "/hello/update")
|
||||
public void update(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
String clientaddr = req.getRemoteAddr();
|
||||
@@ -75,7 +78,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/partupdate")
|
||||
@WebMapping(url = "/hello/partupdate")
|
||||
public void partupdate(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
@@ -87,7 +90,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/query")
|
||||
@WebMapping(url = "/hello/query")
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
@@ -101,7 +104,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/list")
|
||||
@WebMapping(url = "/hello/list")
|
||||
public void list(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
@@ -114,7 +117,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/find/")
|
||||
@WebMapping(url = "/hello/find/")
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
@@ -122,4 +125,11 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
resp.finishJson(bean);
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebMapping(url = "/hello/asyncfind/")
|
||||
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
service.findHello(resp.createAsyncHandler(), id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
private Map<String, HelloService2> _servicemap;
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/create", comment = "创建Hello对象")
|
||||
@WebMapping(url = "/hello/create", comment = "创建Hello对象")
|
||||
@WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
@@ -40,7 +40,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/delete/", comment = "根据id删除Hello对象")
|
||||
@WebMapping(url = "/hello/delete/", comment = "根据id删除Hello对象")
|
||||
@WebParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
@@ -50,7 +50,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/update", comment = "修改Hello对象")
|
||||
@WebMapping(url = "/hello/update", comment = "修改Hello对象")
|
||||
@WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
|
||||
public void update(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
@@ -62,7 +62,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/query", comment = "查询Hello对象列表")
|
||||
@WebMapping(url = "/hello/query", comment = "查询Hello对象列表")
|
||||
@WebParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
@@ -77,7 +77,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/find/", comment = "根据id删除Hello对象")
|
||||
@WebMapping(url = "/hello/find/", comment = "根据id删除Hello对象")
|
||||
@WebParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
|
||||
@@ -61,6 +61,11 @@ public class SncpTestService implements SncpTestIService {
|
||||
return "result: " + bean;
|
||||
}
|
||||
|
||||
public void queryResult(AsyncHandler<String, SncpTestBean> handler, @RpcAttachment SncpTestBean bean) {
|
||||
System.out.println(Thread.currentThread().getName() + " handler 运行了queryResult方法");
|
||||
if (handler != null) handler.completed("result: " + bean, bean);
|
||||
}
|
||||
|
||||
@RpcMultiRun
|
||||
public String updateBean(@RpcCall(CallAttribute.class) SncpTestBean bean) {
|
||||
bean.setId(System.currentTimeMillis());
|
||||
|
||||
@@ -36,10 +36,10 @@ public class CacheTestBean {
|
||||
Attribute nameattr = Attribute.create(CacheTestBean.class, "name");
|
||||
Attribute priceattr = Attribute.create(CacheTestBean.class, "price");
|
||||
BiFunction<DataSource, Class, List> fullloader = (s, z) -> list;
|
||||
Method method = EntityInfo.class.getDeclaredMethod("load", Class.class, int.class, boolean.class, Properties.class,
|
||||
Method method = EntityInfo.class.getDeclaredMethod("load", Class.class, boolean.class, Properties.class,
|
||||
DataSource.class, BiFunction.class);
|
||||
method.setAccessible(true);
|
||||
final EntityInfo<CacheTestBean> info = (EntityInfo<CacheTestBean>) method.invoke(null, CacheTestBean.class, 0, true, new Properties(), null, fullloader);
|
||||
final EntityInfo<CacheTestBean> info = (EntityInfo<CacheTestBean>) method.invoke(null, CacheTestBean.class, true, new Properties(), null, fullloader);
|
||||
EntityCache<CacheTestBean> cache = new EntityCache(info, null);
|
||||
cache.fullLoad();
|
||||
|
||||
|
||||
@@ -44,10 +44,10 @@ public class TestSourceCache {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final BiFunction<DataSource, Class, List> fullloader = (DataSource t, Class u) -> null;
|
||||
Method method = EntityInfo.class.getDeclaredMethod("load", Class.class, int.class, boolean.class, Properties.class,
|
||||
Method method = EntityInfo.class.getDeclaredMethod("load", Class.class, boolean.class, Properties.class,
|
||||
DataSource.class, BiFunction.class);
|
||||
method.setAccessible(true);
|
||||
final EntityInfo<TestEntity> info = (EntityInfo<TestEntity>) method.invoke(null, TestEntity.class, 0, false, new Properties(), null, fullloader);
|
||||
method.setAccessible(true);
|
||||
final EntityInfo<TestEntity> info = (EntityInfo<TestEntity>) method.invoke(null, TestEntity.class, false, new Properties(), null, fullloader);
|
||||
TestEntity[] entitys = new TestEntity[10_0000];
|
||||
for (int i = 0; i < entitys.length; i++) {
|
||||
entitys[i] = new TestEntity(i + 1, "用户_" + (i + 1));
|
||||
@@ -86,7 +86,7 @@ public class TestSourceCache {
|
||||
}
|
||||
cdl.await();
|
||||
e = System.currentTimeMillis() - s;
|
||||
System.out.println("十万条数据中查询一页记录耗时: " + e / 1000.0 + " 秒 " + sheet); // CopyOnWriteArrayList 0.798 ConcurrentLinkedQueue 1.063
|
||||
System.out.println("十万条数据中100并发查询一页循环10次记录耗时: " + e / 1000.0 + " 秒 " + sheet); // CopyOnWriteArrayList 0.798 ConcurrentLinkedQueue 1.063
|
||||
}
|
||||
|
||||
@VirtualEntity
|
||||
|
||||
Reference in New Issue
Block a user