Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30103e5c8f | ||
|
|
cbba7701d8 | ||
|
|
da53bd7db9 | ||
|
|
9e7999da0f | ||
|
|
2c96f991d5 | ||
|
|
67f8127452 | ||
|
|
bce498885e | ||
|
|
eb57a25698 | ||
|
|
4e83e5bf71 | ||
|
|
19a44ce8cf | ||
|
|
0bd0df3245 | ||
|
|
4f0163736f | ||
|
|
8d03f52f09 | ||
|
|
815267a590 | ||
|
|
77f8d442b2 | ||
|
|
aacda5d35e | ||
|
|
58d02f6471 | ||
|
|
c735874cff | ||
|
|
045029b4a9 | ||
|
|
f6b5882cd4 | ||
|
|
63a9005e6b | ||
|
|
c4923f317b | ||
|
|
15e03c0459 | ||
|
|
74f4ddf50b | ||
|
|
fdc868641d | ||
|
|
910eb88c55 | ||
|
|
b597131de4 | ||
|
|
56d5f97556 | ||
|
|
b364dd5811 | ||
|
|
4fec27498c | ||
|
|
7a195ecf23 | ||
|
|
95b7e819cd | ||
|
|
73d243aaf1 | ||
|
|
998fecdd51 | ||
|
|
b1ddc0e3a5 | ||
|
|
641ff4709d | ||
|
|
13f2fbf7d6 | ||
|
|
62f9882314 | ||
|
|
7f270eb9d7 | ||
|
|
974a6bfeaa | ||
|
|
4958b454af | ||
|
|
3531d0963d | ||
|
|
41e6497a2e |
@@ -28,7 +28,7 @@
|
||||
<!--
|
||||
【节点全局唯一】
|
||||
所有服务所需的资源
|
||||
-->
|
||||
-->
|
||||
<resources>
|
||||
<!--
|
||||
【节点全局唯一】
|
||||
@@ -59,7 +59,7 @@
|
||||
</group>
|
||||
<!--
|
||||
【节点全局唯一】
|
||||
全局的参数配置, 可以通过@Resource(name="property.xxxxxx") 进行注入, 被注解的字段类型只能是String、primitive class
|
||||
全局的参数配置, 可以通过@Resource(name="property.xxxxxx") 进行注入<property>的信息, 被注解的字段类型只能是String、primitive class
|
||||
如果name是system.property.开头的值将会在进程启动时进行System.setProperty("yyyy", "YYYYYY")操作。
|
||||
如果name是mimetype.property.开头的值将会在进程启动时进行MimeType.add("yyyy", "YYYYYY")操作。
|
||||
load: 加载文件,多个用;隔开。
|
||||
@@ -70,6 +70,8 @@
|
||||
System.setProperty("convert.bson.pool.size", "128");
|
||||
System.setProperty("convert.json.writer.buffer.defsize", "4096");
|
||||
System.setProperty("convert.bson.writer.buffer.defsize", "4096");
|
||||
|
||||
<properties>节点下也可包含非<property>节点,其节点可以通过@Resource(name="properties.xxxxxx")进行注入, 被注解的字段类型只能是AnyValue、AnyValue[]
|
||||
-->
|
||||
<properties load="config.properties">
|
||||
<property name="system.property.yyyy" value="YYYYYY"/>
|
||||
@@ -77,6 +79,7 @@
|
||||
<property name="xxxxxx" value="XXXXXXXX"/>
|
||||
<property name="xxxxxx" value="XXXXXXXX"/>
|
||||
</properties>
|
||||
|
||||
</resources>
|
||||
<!--
|
||||
protocol: required server所启动的协议,Redkale内置的有HTTP、SNCP,SNCP使用TCP实现;
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
<!-- 为NONE表示不启动缓存,@Cacheable 失效; 非NONE值(通常用ALL)表示开启缓存。 -->
|
||||
<shared-cache-mode>NONE</shared-cache-mode>
|
||||
<properties>
|
||||
<!--
|
||||
DataSource的实现类,没有设置默认为org.redkale.source.DataJdbcSource的实现,使用常规基于JDBC的数据库驱动一般无需设置
|
||||
-->
|
||||
<property name="javax.persistence.datasource" value="org.redkale.source.DataJdbcSource"/>
|
||||
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/dbuser?characterEncoding=utf8"/>
|
||||
<!--
|
||||
javax.persistence.jdbc.driver在JPA的值是JDBC驱动,Redkale有所不同,值应该是javax.sql.DataSource的子类。
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* API接口文档生成类,作用:生成Application实例中所有HttpServer的可用HttpServlet的API接口方法 <br>
|
||||
继承 HttpBaseServlet 是为了获取 WebMapping 信息
|
||||
* 继承 HttpBaseServlet 是为了获取 WebMapping 信息
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
@@ -205,7 +205,7 @@ public class ApiDocs extends HttpBaseServlet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response) throws IOException {
|
||||
return true;
|
||||
public void authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response, HttpServlet next) throws IOException {
|
||||
next.execute(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,6 +118,9 @@ public final class Application {
|
||||
//全局根ResourceFactory
|
||||
final ResourceFactory resourceFactory = ResourceFactory.root();
|
||||
|
||||
//服务配置项
|
||||
final AnyValue config;
|
||||
|
||||
//临时计数器
|
||||
CountDownLatch servicecdl; //会出现两次赋值
|
||||
|
||||
@@ -134,9 +137,6 @@ public final class Application {
|
||||
//日志
|
||||
private final Logger logger;
|
||||
|
||||
//服务配置项
|
||||
private final AnyValue config;
|
||||
|
||||
//服务启动时间
|
||||
private final long startTime = System.currentTimeMillis();
|
||||
|
||||
@@ -307,7 +307,7 @@ public final class Application {
|
||||
|
||||
File persist = new File(this.home, "conf/persistence.xml");
|
||||
final String homepath = this.home.getCanonicalPath();
|
||||
if (persist.isFile()) System.setProperty(DataDefaultSource.DATASOURCE_CONFPATH, persist.getCanonicalPath());
|
||||
if (persist.isFile()) System.setProperty(DataSources.DATASOURCE_CONFPATH, persist.getCanonicalPath());
|
||||
logger.log(Level.INFO, RESNAME_APP_HOME + "= " + homepath + "\r\n" + RESNAME_APP_ADDR + "= " + this.localAddress.getHostAddress());
|
||||
String lib = config.getValue("lib", "").trim().replace("${APP_HOME}", homepath);
|
||||
lib = lib.isEmpty() ? (homepath + "/conf") : (lib + ";" + homepath + "/conf");
|
||||
|
||||
@@ -191,11 +191,36 @@ public abstract class NodeServer {
|
||||
final NodeServer self = this;
|
||||
//---------------------------------------------------------------------------------------------
|
||||
final ResourceFactory appResFactory = application.getResourceFactory();
|
||||
//------------------------------------- 注册Resource --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
Resource res = field.getAnnotation(Resource.class);
|
||||
if (res == null || !res.name().startsWith("properties.")) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||
Class type = field.getType();
|
||||
if (type != AnyValue.class && type != AnyValue[].class) return;
|
||||
Object resource = null;
|
||||
final AnyValue resources = application.config.getAnyValue("resources");
|
||||
final AnyValue properties = resources == null ? null : resources.getAnyValue("properties");
|
||||
if (properties != null && type == AnyValue.class) {
|
||||
resource = properties.getAnyValue(res.name().substring("properties.".length()));
|
||||
appResFactory.register(resourceName, AnyValue.class, resource);
|
||||
} else if (properties != null && type == AnyValue[].class) {
|
||||
resource = properties.getAnyValues(res.name().substring("properties.".length()));
|
||||
appResFactory.register(resourceName, AnyValue[].class, resource);
|
||||
}
|
||||
field.set(src, resource);
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
}
|
||||
}, AnyValue.class, AnyValue[].class);
|
||||
|
||||
//------------------------------------- 注册DataSource --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||
DataSource source = new DataDefaultSource(resourceName);
|
||||
DataSource source = DataSources.createDataSource(resourceName);
|
||||
application.dataSources.add(source);
|
||||
appResFactory.register(resourceName, DataSource.class, source);
|
||||
|
||||
@@ -220,6 +245,8 @@ public abstract class NodeServer {
|
||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||
}
|
||||
}, DataSource.class);
|
||||
|
||||
//------------------------------------- 注册CacheSource --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, final String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Map的反序列化操作类
|
||||
* Map的反序列化操作类 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
|
||||
@@ -236,11 +236,11 @@ public class BsonWriter extends Writer {
|
||||
return;
|
||||
}
|
||||
char[] chars = Utility.charArray(value);
|
||||
if (chars.length > 255) throw new ConvertException("'" + value + "' has very long length");
|
||||
if (chars.length > 255) throw new ConvertException("'" + value + "' have very long length");
|
||||
byte[] bytes = new byte[chars.length + 1];
|
||||
bytes[0] = (byte) chars.length;
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (chars[i] > Byte.MAX_VALUE) throw new ConvertException("'" + value + "' has double-word");
|
||||
if (chars[i] > Byte.MAX_VALUE) throw new ConvertException("'" + value + "' have double-word");
|
||||
bytes[i + 1] = (byte) chars[i];
|
||||
}
|
||||
writeTo(bytes);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TypeSimpledCoder<R extends Reader, W extends Writer> extends Simple
|
||||
if (str == null) return null;
|
||||
try {
|
||||
return Class.forName(str);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 根Servlet, 一个Server只能存在一个根Servlet
|
||||
*
|
||||
*
|
||||
* 用于分发Request请求
|
||||
*
|
||||
* <p>
|
||||
@@ -34,9 +34,33 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
||||
|
||||
protected final AtomicLong illRequestCounter = new AtomicLong(); //错误请求次数
|
||||
|
||||
protected final Set<S> servlets = new HashSet<>();
|
||||
private final Object lock1 = new Object();
|
||||
|
||||
protected final Map<K, S> mappings = new HashMap<>();
|
||||
private Set<S> servlets = new HashSet<>();
|
||||
|
||||
private final Object lock2 = new Object();
|
||||
|
||||
private Map<K, S> mappings = new HashMap<>();
|
||||
|
||||
protected void putServlet(S servlet) {
|
||||
synchronized (lock1) {
|
||||
Set<S> newservlets = new HashSet<>(servlets);
|
||||
newservlets.add(servlet);
|
||||
this.servlets = newservlets;
|
||||
}
|
||||
}
|
||||
|
||||
protected void putMapping(K key, S value) {
|
||||
synchronized (lock2) {
|
||||
Map<K, S> newmappings = new HashMap<>(mappings);
|
||||
newmappings.put(key, value);
|
||||
this.mappings = newmappings;
|
||||
}
|
||||
}
|
||||
|
||||
protected S mappingServlet(K key) {
|
||||
return mappings.get(key);
|
||||
}
|
||||
|
||||
public abstract void addServlet(S servlet, Object attachment, AnyValue conf, K... mappings);
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public final class Transport {
|
||||
public AsyncConnection pollConnection(SocketAddress addr) {
|
||||
if (addr == null && remoteAddres.length == 1) addr = remoteAddres[0];
|
||||
final boolean rand = addr == null;
|
||||
if (rand && remoteAddres.length < 1) throw new RuntimeException("Transport (" + this.name + ") has no remoteAddress list");
|
||||
if (rand && remoteAddres.length < 1) throw new RuntimeException("Transport (" + this.name + ") have no remoteAddress list");
|
||||
try {
|
||||
if (tcp) {
|
||||
AsynchronousSocketChannel channel = null;
|
||||
|
||||
@@ -22,8 +22,8 @@ public class DefaultRestServlet extends RestHttpServlet<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response) throws IOException {
|
||||
return true;
|
||||
public void authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response, HttpServlet next) throws IOException {
|
||||
next.execute(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -183,37 +183,122 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
|
||||
private Map.Entry<String, Entry>[] mappings;
|
||||
|
||||
public boolean preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
private final HttpServlet authSuccessServlet = new HttpServlet() {
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
Entry entry = (Entry) request.attachment;
|
||||
if (entry.cacheseconds > 0) {//有缓存设置
|
||||
CacheEntry ce = entry.cache.get(request.getRequestURI());
|
||||
if (ce != null && ce.time + entry.cacheseconds > System.currentTimeMillis()) { //缓存有效
|
||||
response.setStatus(ce.status);
|
||||
response.setContentType(ce.contentType);
|
||||
response.finish(ce.getBuffers());
|
||||
return;
|
||||
}
|
||||
response.setBufferHandler(entry.cacheHandler);
|
||||
}
|
||||
entry.servlet.execute(request, response);
|
||||
}
|
||||
};
|
||||
|
||||
private final HttpServlet preSuccessServlet = new HttpServlet() {
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
for (Map.Entry<String, Entry> en : mappings) {
|
||||
if (request.getRequestURI().startsWith(en.getKey())) {
|
||||
Entry entry = en.getValue();
|
||||
if (!entry.checkMethod(request.getMethod())) {
|
||||
response.finishJson(new RetResult(RET_METHOD_ERROR, "Method(" + request.getMethod() + ") Error"));
|
||||
return;
|
||||
}
|
||||
request.attachment = entry;
|
||||
if (entry.ignore) {
|
||||
authSuccessServlet.execute(request, response);
|
||||
} else {
|
||||
authenticate(entry.moduleid, entry.actionid, request, response, authSuccessServlet);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new IOException(this.getClass().getName() + " not found method for URI(" + request.getRequestURI() + ")");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 预执行方法,在execute方法之前运行,通常用于常规统计或基础检测,例如 : <br>
|
||||
* <blockquote><pre>
|
||||
* @Override
|
||||
* public void preExecute(final HttpRequest request, final HttpResponse response, HttpServlet next) throws IOException {
|
||||
* if (finer) response.setRecycleListener((req, resp) -> { //记录处理时间比较长的请求
|
||||
* long e = System.currentTimeMillis() - ((HttpRequest) req).getCreatetime();
|
||||
* if (e > 200) logger.finer("http-execute-cost-time: " + e + " ms. request = " + req);
|
||||
* });
|
||||
* next.execute(request, response);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
* <p>
|
||||
*
|
||||
* @param request HttpRequest
|
||||
* @param response HttpResponse
|
||||
* @param next HttpServlet
|
||||
*
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
public void preExecute(HttpRequest request, HttpResponse response, final HttpServlet next) throws IOException {
|
||||
next.execute(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用 public void authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response, final HttpServlet next) throws IOException 代替
|
||||
*
|
||||
* @param moduleid int
|
||||
* @param actionid int
|
||||
* @param request HttpRequest
|
||||
* @param response HttpResponse
|
||||
*
|
||||
* @return boolean
|
||||
* @throws IOException IOException
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response) throws IOException {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户登录或权限验证, 没有注解为@AuthIgnore 的方法会执行authenticate方法, 若验证成功则必须调用next.execute(request, response);进行下一步操作, 例如: <br>
|
||||
* <blockquote><pre>
|
||||
* @Override
|
||||
* public void authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response, final HttpServlet next) throws IOException {
|
||||
* UserInfo info = currentUser(request);
|
||||
* if (info == null) {
|
||||
* response.finishJson(RET_UNLOGIN);
|
||||
* return;
|
||||
* } else if (!info.checkAuth(module, actionid)) {
|
||||
* response.finishJson(RET_AUTHILLEGAL);
|
||||
* return;
|
||||
* }
|
||||
* next.execute(request, response);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* @param moduleid 模块ID,来自@WebServlet.moduleid()
|
||||
* @param actionid 操作ID,来自@WebMapping.actionid()
|
||||
* @param request HttpRequest
|
||||
* @param response HttpResponse
|
||||
* @param next HttpServlet
|
||||
*
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
public abstract void authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response, final HttpServlet next) throws IOException;
|
||||
|
||||
@Override
|
||||
public final void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
if (!preExecute(request, response)) return;
|
||||
for (Map.Entry<String, Entry> en : mappings) {
|
||||
if (request.getRequestURI().startsWith(en.getKey())) {
|
||||
Entry entry = en.getValue();
|
||||
if (!entry.checkMethod(request.getMethod())) {
|
||||
response.finishJson(new RetResult(RET_METHOD_ERROR, "Method(" + request.getMethod() + ") Error"));
|
||||
return;
|
||||
}
|
||||
if (entry.ignore || authenticate(entry.moduleid, entry.actionid, request, response)) {
|
||||
if (entry.cacheseconds > 0) {//有缓存设置
|
||||
CacheEntry ce = entry.cache.get(request.getRequestURI());
|
||||
if (ce != null && ce.time + entry.cacheseconds > System.currentTimeMillis()) { //缓存有效
|
||||
response.setStatus(ce.status);
|
||||
response.setContentType(ce.contentType);
|
||||
response.finish(ce.getBuffers());
|
||||
return;
|
||||
}
|
||||
response.setBufferHandler(entry.cacheHandler);
|
||||
}
|
||||
entry.servlet.execute(request, response);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new IOException(this.getClass().getName() + " not found method for URI(" + request.getRequestURI() + ")");
|
||||
preExecute(request, response, preSuccessServlet);
|
||||
}
|
||||
|
||||
public final void preInit(HttpContext context, AnyValue config) {
|
||||
@@ -233,8 +318,6 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
public final void postDestroy(HttpContext context, AnyValue config) {
|
||||
}
|
||||
|
||||
public abstract boolean authenticate(int moduleid, int actionid, HttpRequest request, HttpResponse response) throws IOException;
|
||||
|
||||
protected void setHeader(HttpRequest request, String name, Serializable value) {
|
||||
request.header.setValue(name, String.valueOf(value));
|
||||
}
|
||||
@@ -280,7 +363,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
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 " + WebMapping.class.getSimpleName() + "(" + name + ")");
|
||||
throw new RuntimeException(this.getClass().getSimpleName() + " have two same " + WebMapping.class.getSimpleName() + "(" + name + ")");
|
||||
}
|
||||
nameset.put(name, clz);
|
||||
map.put(name, new Entry(typeIgnore, serviceid, actionid, name, methods, method, createHttpServlet(method)));
|
||||
@@ -304,7 +387,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
try {
|
||||
Class.forName(newDynName.replace('/', '.'));
|
||||
newDynName += "_" + (++i);
|
||||
} catch (Exception ex) {
|
||||
} catch (Throwable ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
|
||||
@Override
|
||||
public void init(HttpContext context, AnyValue config) {
|
||||
this.servlets.forEach(s -> {
|
||||
Collection<HttpServlet> servlets = getServlets();
|
||||
servlets.forEach(s -> {
|
||||
if (s instanceof WebSocketServlet) {
|
||||
((WebSocketServlet) s).preInit(context, getServletConf(s));
|
||||
} else if (s instanceof HttpBaseServlet) {
|
||||
@@ -47,7 +48,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
});
|
||||
final WatchFactory watch = context.getWatchFactory();
|
||||
if (watch != null) {
|
||||
this.servlets.forEach(s -> {
|
||||
servlets.forEach(s -> {
|
||||
watch.inject(s);
|
||||
});
|
||||
}
|
||||
@@ -71,7 +72,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
String resServlet = resConfig.getValue("servlet", HttpResourceServlet.class.getName());
|
||||
try {
|
||||
this.resourceHttpServlet = (HttpServlet) Class.forName(resServlet).newInstance();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
this.resourceHttpServlet = new HttpResourceServlet();
|
||||
logger.log(Level.WARNING, "init HttpResourceSerlvet(" + resServlet + ") error", e);
|
||||
}
|
||||
@@ -82,7 +83,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
try {
|
||||
final String uri = request.getRequestURI();
|
||||
Servlet<HttpContext, HttpRequest, HttpResponse> servlet = this.mappings.isEmpty() ? null : this.mappings.get(uri);
|
||||
Servlet<HttpContext, HttpRequest, HttpResponse> servlet = mappingServlet(uri);
|
||||
if (servlet == null && this.regArray != null) {
|
||||
for (SimpleEntry<Predicate<String>, HttpServlet> en : regArray) {
|
||||
if (en.getKey().test(uri)) {
|
||||
@@ -138,7 +139,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
regArray[regArray.length - 1] = new SimpleEntry<>(Pattern.compile(mapping).asPredicate(), servlet);
|
||||
}
|
||||
} else if (mapping != null && !mapping.isEmpty()) {
|
||||
super.mappings.put(mapping, servlet);
|
||||
putMapping(mapping, servlet);
|
||||
}
|
||||
if (this.allMapStrings.containsKey(mapping)) {
|
||||
Class old = this.allMapStrings.get(mapping);
|
||||
@@ -148,7 +149,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
}
|
||||
setServletConf(servlet, conf);
|
||||
servlet._prefix = prefix.toString();
|
||||
this.servlets.add(servlet);
|
||||
putServlet(servlet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +176,7 @@ public class HttpPrepareServlet extends PrepareServlet<String, HttpContext, Http
|
||||
@Override
|
||||
public void destroy(HttpContext context, AnyValue config) {
|
||||
this.resourceHttpServlet.destroy(context, config);
|
||||
this.servlets.forEach(s -> {
|
||||
getServlets().forEach(s -> {
|
||||
s.destroy(context, getServletConf(s));
|
||||
if (s instanceof WebSocketServlet) {
|
||||
((WebSocketServlet) s).postDestroy(context, getServletConf(s));
|
||||
|
||||
@@ -66,6 +66,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
private final String remoteAddrHeader;
|
||||
|
||||
Object attachment; //供 HttpBaseServlet传递Entry使用
|
||||
|
||||
public HttpRequest(HttpContext context, String remoteAddrHeader) {
|
||||
super(context);
|
||||
this.remoteAddrHeader = remoteAddrHeader;
|
||||
@@ -336,6 +338,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
this.boundary = false;
|
||||
this.bodyparsed = false;
|
||||
|
||||
this.attachment = null;
|
||||
|
||||
this.header.clear();
|
||||
this.params.clear();
|
||||
this.array.clear();
|
||||
|
||||
@@ -493,6 +493,37 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步输出指定内容
|
||||
*
|
||||
* @param <A> 泛型
|
||||
* @param buffers 输出内容
|
||||
* @param attachment 异步回调参数
|
||||
* @param handler 异步回调函数
|
||||
*/
|
||||
public <A> void sendBody(ByteBuffer[] buffers, A attachment, AsyncHandler<Integer, A> handler) {
|
||||
if (!this.headsended) {
|
||||
if (this.contentLength < 0) {
|
||||
int len = 0;
|
||||
if (buffers != null && buffers.length > 0) {
|
||||
for (ByteBuffer b : buffers) {
|
||||
len += b.remaining();
|
||||
}
|
||||
}
|
||||
this.contentLength = len;
|
||||
}
|
||||
ByteBuffer headbuf = createHeader();
|
||||
headbuf.flip();
|
||||
if (buffers == null || buffers.length == 0) {
|
||||
super.send(headbuf, attachment, handler);
|
||||
} else {
|
||||
super.send(Utility.unshift(buffers, headbuf), attachment, handler);
|
||||
}
|
||||
} else {
|
||||
super.send(buffers, attachment, handler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定文件按响应结果输出
|
||||
*
|
||||
|
||||
@@ -36,6 +36,8 @@ public final class Rest {
|
||||
|
||||
static final String REST_SERVICEMAP_FIELD_NAME = "_servicemap"; //如果只有name=""的Service资源,则实例中_servicemap必须为null
|
||||
|
||||
private static final String REST_PARAMTYPES_FIELD_NAME = "_paramtypes"; //存在泛型的参数数组 Type[][] 第1维度是方法的下标, 第二维度是参数的下标
|
||||
|
||||
private static final Set<String> EXCLUDERMETHODS = new HashSet<>();
|
||||
|
||||
static {
|
||||
@@ -58,6 +60,42 @@ public final class Rest {
|
||||
private Rest() {
|
||||
}
|
||||
|
||||
public static class MethodParamClassVisitor extends ClassVisitor {
|
||||
|
||||
private final Map<String, List<String>> fieldmap;
|
||||
|
||||
public MethodParamClassVisitor(int api, final Map<String, List<String>> fieldmap) {
|
||||
super(api);
|
||||
this.fieldmap = fieldmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
||||
if (java.lang.reflect.Modifier.isStatic(access)) return null;
|
||||
List<String> fieldnames = new ArrayList<>();
|
||||
fieldmap.put(name + ":" + desc, fieldnames);
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//返回的List中参数列表可能会比方法参数量多,因为方法内的临时变量也会存入list中, 所以需要list的元素集合比方法的参数多
|
||||
public static Map<String, List<String>> getMethodParamNames(Class clazz) {
|
||||
String n = clazz.getName();
|
||||
InputStream in = clazz.getResourceAsStream(n.substring(n.lastIndexOf('.') + 1) + ".class");
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
if (in == null) return map;
|
||||
try {
|
||||
new ClassReader(Utility.readBytesThenClose(in)).accept(new MethodParamClassVisitor(Opcodes.ASM5, map), 0);
|
||||
} catch (Exception e) { //无需理会
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
static String getWebModuleName(Class<? extends Service> serviceType) {
|
||||
final RestService controller = serviceType.getAnnotation(RestService.class);
|
||||
if (controller == null) return serviceType.getSimpleName().replaceAll("Service.*$", "").toLowerCase();
|
||||
@@ -99,10 +137,7 @@ public final class Rest {
|
||||
if (controller != null && controller.ignore()) return null; //标记为ignore=true不创建Servlet
|
||||
ClassLoader loader = Sncp.class.getClassLoader();
|
||||
String newDynName = serviceTypeInternalName.substring(0, serviceTypeInternalName.lastIndexOf('/') + 1) + "_Dyn" + serviceType.getSimpleName().replaceAll("Service.*$", "") + "RestServlet";
|
||||
try {
|
||||
return ((Class<T>) Class.forName(newDynName.replace('/', '.'))).newInstance();
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
Method currentUserMethod = null;
|
||||
try {
|
||||
currentUserMethod = baseServletClass.getDeclaredMethod("currentUser", HttpRequest.class);
|
||||
@@ -113,7 +148,7 @@ public final class Rest {
|
||||
final String defmodulename = getWebModuleName(serviceType);
|
||||
for (char ch : defmodulename.toCharArray()) {
|
||||
if (!((ch >= '0' && ch <= '9') || ch == '$' || ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) { //不能含特殊字符
|
||||
throw new RuntimeException(serviceType.getName() + " has illeal " + RestService.class.getSimpleName() + ".value, only 0-9 a-z A-Z _ $");
|
||||
throw new RuntimeException(serviceType.getName() + " have illeal " + RestService.class.getSimpleName() + ".value, only 0-9 a-z A-Z _ $");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +198,10 @@ public final class Rest {
|
||||
fv = cw.visitField(ACC_PRIVATE, REST_SERVICEMAP_FIELD_NAME, "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;" + serviceDesc + ">;", null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{ //_paramtypes字段 java.lang.reflect.Type[][]
|
||||
fv = cw.visitField(ACC_PRIVATE, REST_PARAMTYPES_FIELD_NAME, "[[Ljava/lang/reflect/Type;", null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{ //构造函数
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
|
||||
//mv.setDebug(true);
|
||||
@@ -176,6 +215,8 @@ public final class Rest {
|
||||
final List<MappingEntry> entrys = new ArrayList<>();
|
||||
final Map<String, org.redkale.util.Attribute> restAttributes = new LinkedHashMap<>();
|
||||
//获取所有可以转换成WebMapping的方法
|
||||
int methodidex = 0;
|
||||
final List<java.lang.reflect.Type[]> paramtypes = new ArrayList<>();
|
||||
for (final Method method : serviceType.getMethods()) {
|
||||
if (Modifier.isStatic(method.getModifiers())) continue;
|
||||
Class[] extypes = method.getExceptionTypes();
|
||||
@@ -195,21 +236,24 @@ public final class Rest {
|
||||
}
|
||||
}
|
||||
if (ignore) continue;
|
||||
paramtypes.add(method.getGenericParameterTypes());
|
||||
if (mappings.length == 0) { //没有Mapping,设置一个默认值
|
||||
MappingEntry entry = new MappingEntry(null, defmodulename, method);
|
||||
MappingEntry entry = new MappingEntry(methodidex, null, defmodulename, method);
|
||||
if (entrys.contains(entry)) throw new RuntimeException(serviceType.getName() + " on " + method.getName() + " 's mapping(" + entry.name + ") is repeat");
|
||||
entrys.add(entry);
|
||||
} else {
|
||||
for (RestMapping mapping : mappings) {
|
||||
MappingEntry entry = new MappingEntry(mapping, defmodulename, method);
|
||||
MappingEntry entry = new MappingEntry(methodidex, mapping, defmodulename, method);
|
||||
if (entrys.contains(entry)) throw new RuntimeException(serviceType.getName() + " on " + method.getName() + " 's mapping(" + entry.name + ") is repeat");
|
||||
entrys.add(entry);
|
||||
}
|
||||
}
|
||||
methodidex++;
|
||||
}
|
||||
if (entrys.isEmpty()) return null; //没有可WebMapping的方法
|
||||
|
||||
//将每个Service可转换的方法生成HttpServlet对应的WebMapping方法
|
||||
final Map<String, List<String>> asmParamMap = MethodParamClassVisitor.getMethodParamNames(serviceType);
|
||||
for (final MappingEntry entry : entrys) {
|
||||
final Method method = entry.mappingMethod;
|
||||
final Class returnType = method.getReturnType();
|
||||
@@ -256,11 +300,12 @@ public final class Rest {
|
||||
final int maxStack = 3 + params.length;
|
||||
List<int[]> varInsns = new ArrayList<>();
|
||||
int maxLocals = 4;
|
||||
int argIndex = 0;
|
||||
|
||||
List<String> asmParamNames = asmParamMap == null ? null : asmParamMap.get(method.getName() + ":" + Type.getMethodDescriptor(method));
|
||||
List<Object[]> paramlist = new ArrayList<>();
|
||||
//解析方法中的每个参数
|
||||
for (final Parameter param : params) {
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
final Parameter param = params[i];
|
||||
final Class ptype = param.getType();
|
||||
String n = null;
|
||||
String comment = "";
|
||||
@@ -303,13 +348,14 @@ public final class Rest {
|
||||
if (annpara != null) required = annpara.required();
|
||||
if (n == null) n = (annpara == null || annpara.name().isEmpty()) ? null : annpara.name();
|
||||
if (n == null && ptype == userType) n = "&"; //用户类型特殊处理
|
||||
if (n == null && asmParamNames != null && asmParamNames.size() > i) n = asmParamNames.get(i);
|
||||
if (n == null) {
|
||||
if (param.isNamePresent()) {
|
||||
n = param.getName();
|
||||
} else if (ptype == Flipper.class) {
|
||||
n = "flipper";
|
||||
} else {
|
||||
n = (++argIndex > 1) ? ("bean" + argIndex) : "bean";
|
||||
n = ("bean" + i);
|
||||
}
|
||||
}
|
||||
if (annhead == null && anncookie == null && annaddr == null
|
||||
@@ -380,6 +426,7 @@ public final class Rest {
|
||||
boolean hasAsyncHandler = false;
|
||||
for (Object[] ps : paramlist) {
|
||||
Map<String, Object> paramMap = new LinkedHashMap<>();
|
||||
final Parameter param = (Parameter) ps[0]; //参数类型
|
||||
String pname = (String) ps[1]; //参数名
|
||||
Class ptype = (Class) ps[2]; //参数类型
|
||||
int radix = (Integer) ps[3];
|
||||
@@ -396,11 +443,21 @@ public final class Rest {
|
||||
|
||||
paramMap.put("name", pname);
|
||||
paramMap.put("type", ptype.getName());
|
||||
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});
|
||||
if (AsyncHandler.class.isAssignableFrom(ptype)) { //HttpResponse.createAsyncHandler() or HttpResponse.createAsyncHandler(Class)
|
||||
if (ptype == AsyncHandler.class) {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "createAsyncHandler", "()Lorg/redkale/util/AsyncHandler;", false);
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(Type.getType(Type.getDescriptor(ptype)));
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "createAsyncHandler", "(Lorg/redkale/net/http/HttpResponse;Ljava/lang/Class;)Lorg/redkale/util/AsyncHandler;", false);
|
||||
mv.visitTypeInsn(CHECKCAST, ptype.getName().replace('.', '/'));
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
}
|
||||
hasAsyncHandler = true;
|
||||
} else if (annsid != null) { //HttpRequest.getSessionid(true|false)
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
@@ -644,7 +701,31 @@ public final class Rest {
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
} else { //其他Json对象
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(Type.getType(Type.getDescriptor(ptype)));
|
||||
if (param.getType() == param.getParameterizedType()) {
|
||||
mv.visitLdcInsn(Type.getType(Type.getDescriptor(ptype)));
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, REST_PARAMTYPES_FIELD_NAME, "[[Ljava/lang/reflect/Type;");
|
||||
if (entry.methodidx <= 5) { //方法下标
|
||||
mv.visitInsn(ICONST_0 + entry.methodidx);
|
||||
} else {
|
||||
mv.visitIntInsn(BIPUSH, entry.methodidx);
|
||||
}
|
||||
mv.visitInsn(AALOAD);
|
||||
int paramidx = 0;
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (params[i] == param) {
|
||||
paramidx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (paramidx <= 5) { //参数下标
|
||||
mv.visitInsn(ICONST_0 + paramidx);
|
||||
} else {
|
||||
mv.visitIntInsn(BIPUSH, paramidx);
|
||||
}
|
||||
mv.visitInsn(AALOAD);
|
||||
}
|
||||
mv.visitLdcInsn(pname);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, ishead ? "getJsonHeader" : "getJsonParameter", "(Ljava/lang/reflect/Type;Ljava/lang/String;)Ljava/lang/Object;", false);
|
||||
mv.visitTypeInsn(CHECKCAST, ptype.getName().replace('.', '/'));
|
||||
@@ -885,6 +966,12 @@ public final class Rest {
|
||||
attrField.setAccessible(true);
|
||||
attrField.set(obj, en.getValue());
|
||||
}
|
||||
Field typesfield = newClazz.getDeclaredField(REST_PARAMTYPES_FIELD_NAME);
|
||||
typesfield.setAccessible(true);
|
||||
java.lang.reflect.Type[][] paramtypeArray = new java.lang.reflect.Type[paramtypes.size()][];
|
||||
paramtypeArray = paramtypes.toArray(paramtypeArray);
|
||||
typesfield.set(obj, paramtypeArray);
|
||||
|
||||
return obj;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -916,8 +1003,9 @@ public final class Rest {
|
||||
}
|
||||
}
|
||||
|
||||
public MappingEntry(RestMapping mapping, final String defmodulename, Method method) {
|
||||
public MappingEntry(int methodidx, RestMapping mapping, final String defmodulename, Method method) {
|
||||
if (mapping == null) mapping = DEFAULT__MAPPING;
|
||||
this.methodidx = methodidx;
|
||||
this.ignore = mapping.ignore();
|
||||
String n = mapping.name().toLowerCase();
|
||||
if (n.isEmpty()) n = method.getName().toLowerCase().replace(defmodulename.toLowerCase(), "");
|
||||
@@ -930,6 +1018,8 @@ public final class Rest {
|
||||
this.comment = mapping.comment();
|
||||
}
|
||||
|
||||
public final int methodidx; // _paramtypes 的下标,从0开始
|
||||
|
||||
public final Method mappingMethod;
|
||||
|
||||
public final boolean ignore;
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
package org.redkale.net.http;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -36,4 +40,127 @@ public abstract class RestHttpServlet<T> extends HttpBaseServlet {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建AsyncHandler实例,将非字符串对象以JSON格式输出,字符串以文本输出 <br>
|
||||
*
|
||||
* 传入的AsyncHandler子类必须是public,且保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数。
|
||||
*
|
||||
* @param <H> AsyncHandler泛型
|
||||
* @param response HttpResponse
|
||||
* @param handlerClass Class
|
||||
*
|
||||
* @return AsyncHandler
|
||||
*/
|
||||
protected final <H extends AsyncHandler> H createAsyncHandler(HttpResponse response, final Class<H> handlerClass) {
|
||||
if (handlerClass == null || handlerClass == AsyncHandler.class) return (H) response.createAsyncHandler();
|
||||
Creator<H> creator = creators.get(handlerClass);
|
||||
if (creator == null) {
|
||||
creator = createCreator(handlerClass);
|
||||
creators.put(handlerClass, creator);
|
||||
}
|
||||
return (H) creator.create(response.createAsyncHandler());
|
||||
}
|
||||
|
||||
private static final ConcurrentHashMap<Class, Creator> creators = new ConcurrentHashMap<>();
|
||||
|
||||
private static <H extends AsyncHandler> Creator<H> createCreator(Class<H> handlerClass) {
|
||||
//生成规则与SncpAsyncHandler.Factory 很类似
|
||||
//-------------------------------------------------------------
|
||||
final boolean handlerinterface = handlerClass.isInterface();
|
||||
final String handlerClassName = handlerClass.getName().replace('.', '/');
|
||||
final String handlerName = AsyncHandler.class.getName().replace('.', '/');
|
||||
final String handlerDesc = Type.getDescriptor(AsyncHandler.class);
|
||||
final String newDynName = handlerClass.getName().replace('.', '/') + "_Dync" + AsyncHandler.class.getSimpleName() + "_" + (System.currentTimeMillis() % 10000);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
FieldVisitor fv;
|
||||
AsmMethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, newDynName, null, handlerinterface ? "java/lang/Object" : handlerClassName, handlerinterface ? new String[]{handlerClassName} : new String[]{handlerName});
|
||||
|
||||
{ //handler 属性
|
||||
fv = cw.visitField(ACC_PRIVATE, "handler", handlerDesc, null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{//构造方法
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "(" + handlerDesc + ")V", null, null));
|
||||
//mv.setDebug(true);
|
||||
{
|
||||
av0 = mv.visitAnnotation("Ljava/beans/ConstructorProperties;", true);
|
||||
{
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
av1.visit(null, "handler");
|
||||
av1.visitEnd();
|
||||
}
|
||||
av0.visitEnd();
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, handlerinterface ? "java/lang/Object" : handlerClassName, "<init>", "()V", false);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitFieldInsn(PUTFIELD, newDynName, "handler", handlerDesc);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
for (java.lang.reflect.Method method : handlerClass.getMethods()) { //
|
||||
if ("completed".equals(method.getName()) && method.getParameterCount() == 2) {
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "completed", Type.getMethodDescriptor(method), null, null));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "handler", handlerDesc);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, handlerName, "completed", "(Ljava/lang/Object;Ljava/lang/Object;)V", true);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
} else if ("failed".equals(method.getName()) && method.getParameterCount() == 2) {
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "failed", Type.getMethodDescriptor(method), null, null));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "handler", handlerDesc);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, handlerName, "failed", "(Ljava/lang/Throwable;Ljava/lang/Object;)V", true);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
} else if (handlerinterface || java.lang.reflect.Modifier.isAbstract(method.getModifiers())) {
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null));
|
||||
Class returnType = method.getReturnType();
|
||||
if (returnType == void.class) {
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(0, 1);
|
||||
} else if (returnType.isPrimitive()) {
|
||||
mv.visitInsn(ICONST_0);
|
||||
if (returnType == long.class) {
|
||||
mv.visitInsn(LRETURN);
|
||||
mv.visitMaxs(2, 1);
|
||||
} else if (returnType == float.class) {
|
||||
mv.visitInsn(FRETURN);
|
||||
mv.visitMaxs(2, 1);
|
||||
} else if (returnType == double.class) {
|
||||
mv.visitInsn(DRETURN);
|
||||
mv.visitMaxs(2, 1);
|
||||
} else {
|
||||
mv.visitInsn(IRETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
}
|
||||
} else {
|
||||
mv.visitInsn(ACONST_NULL);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
}
|
||||
mv.visitEnd();
|
||||
}
|
||||
}
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<AsyncHandler> newHandlerClazz = (Class<AsyncHandler>) new ClassLoader(handlerClass.getClassLoader()) {
|
||||
public final Class<?> loadClass(String name, byte[] b) {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
return (Creator<H>) Creator.create(newHandlerClazz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,14 +34,16 @@ public class RestOutput<T> {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public void addHeader(String name, Serializable value) {
|
||||
public RestOutput<T> addHeader(String name, Serializable value) {
|
||||
if (this.headers == null) this.headers = new HashMap<>();
|
||||
this.headers.put(name, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addCookie(HttpCookie cookie) {
|
||||
public RestOutput<T> addCookie(HttpCookie cookie) {
|
||||
if (this.cookies == null) this.cookies = new ArrayList<>();
|
||||
this.cookies.add(cookie);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getHeaders() {
|
||||
|
||||
@@ -32,9 +32,10 @@ public @interface RestParam {
|
||||
* name='&'表示当前用户; <br>
|
||||
* name='#'表示截取uri最后一段; <br>
|
||||
* name='#xxx:'表示从uri中/pipes/xxx:v/截取xxx:的值 <br>
|
||||
* 若方法名以find、delete开头且方法的参数只有一个且参数类型是基本数据类型或String,则默认值为"#" <br>
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
*/
|
||||
String name();
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class WebSocketNode {
|
||||
|
||||
//存放所有用户分布在节点上的队列信息,Set<InetSocketAddress> 为 sncpnode 的集合
|
||||
@Resource(name = "$")
|
||||
protected CacheSource<Serializable, InetSocketAddress> source;
|
||||
protected CacheSource<Serializable, InetSocketAddress> sncpNodes;
|
||||
|
||||
//存放本地节点上所有在线用户的队列信息,Set<String> 为 engineid 的集合
|
||||
protected final ConcurrentHashMap<Serializable, Set<String>> localNodes = new ConcurrentHashMap();
|
||||
@@ -85,7 +85,7 @@ public abstract class WebSocketNode {
|
||||
* @return 地址列表
|
||||
*/
|
||||
public Collection<InetSocketAddress> getOnlineNodes(final Serializable groupid) {
|
||||
return source == null ? null : source.getCollection(groupid);
|
||||
return sncpNodes == null ? null : sncpNodes.getCollection(groupid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +152,7 @@ public abstract class WebSocketNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((recent && rscode == 0) || remoteNode == null || source == null) {
|
||||
if ((recent && rscode == 0) || remoteNode == null || sncpNodes == null) {
|
||||
if (finest) {
|
||||
if ((recent && rscode == 0)) {
|
||||
logger.finest("websocket want send recent message success");
|
||||
@@ -163,7 +163,7 @@ public abstract class WebSocketNode {
|
||||
return rscode;
|
||||
}
|
||||
//-----------------------发送远程的-----------------------------
|
||||
Collection<InetSocketAddress> addrs = source.getCollection(groupid);
|
||||
Collection<InetSocketAddress> addrs = sncpNodes.getCollection(groupid);
|
||||
if (finest) logger.finest("websocket found groupid:" + groupid + " on " + addrs);
|
||||
if (addrs != null && !addrs.isEmpty()) { //对方连接在远程节点(包含本地节点),所以正常情况下addrs不会为空。
|
||||
if (recent) {
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.redkale.util.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public abstract class WebSocketServlet extends HttpServlet {
|
||||
public abstract class WebSocketServlet extends HttpServlet implements Resourcable {
|
||||
|
||||
@Comment("WebScoket服务器给客户端进行ping操作的间隔时间, 单位: 秒")
|
||||
public static final String WEBPARAM__LIVEINTERVAL = "liveinterval";
|
||||
@@ -69,7 +69,7 @@ public abstract class WebSocketServlet extends HttpServlet {
|
||||
|
||||
public final void preInit(HttpContext context, AnyValue conf) {
|
||||
InetSocketAddress addr = context.getServerAddress();
|
||||
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + name() + "]", this.node, logger);
|
||||
this.engine = new WebSocketEngine(addr.getHostString() + ":" + addr.getPort() + "-[" + resourceName() + "]", this.node, logger);
|
||||
if (this.node == null) this.node = createWebSocketNode();
|
||||
if (this.node == null) {
|
||||
this.node = new WebSocketNodeService();
|
||||
@@ -86,7 +86,8 @@ public abstract class WebSocketServlet extends HttpServlet {
|
||||
engine.close();
|
||||
}
|
||||
|
||||
public String name() {
|
||||
@Override
|
||||
public String resourceName() {
|
||||
return this.getClass().getSimpleName().replace("Servlet", "").replace("WebSocket", "").toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,40 @@ public abstract class Sncp {
|
||||
}
|
||||
}
|
||||
|
||||
static void checkAsyncModifier(Class param, Method method) {
|
||||
if (param == AsyncHandler.class) return;
|
||||
if (Modifier.isFinal(param.getModifiers())) {
|
||||
throw new RuntimeException("AsyncHandler Type Parameter on {" + method + "} cannot final modifier");
|
||||
}
|
||||
if (!Modifier.isPublic(param.getModifiers())) {
|
||||
throw new RuntimeException("AsyncHandler Type Parameter on {" + method + "} must be public modifier");
|
||||
}
|
||||
if (param.isInterface()) return;
|
||||
boolean constructorflag = false;
|
||||
for (Constructor c : param.getDeclaredConstructors()) {
|
||||
if (c.getParameterCount() == 0) {
|
||||
int mod = c.getModifiers();
|
||||
if (Modifier.isPublic(mod) || Modifier.isProtected(mod)) {
|
||||
constructorflag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (param.getDeclaredConstructors().length == 0) constructorflag = true;
|
||||
if (!constructorflag) throw new RuntimeException(param + " must have a empty parameter Constructor");
|
||||
for (Method m : param.getMethods()) {
|
||||
if (m.getName().equals("completed") && Modifier.isFinal(m.getModifiers())) {
|
||||
throw new RuntimeException(param + "'s completed method cannot final modifier");
|
||||
} else if (m.getName().equals("failed") && Modifier.isFinal(m.getModifiers())) {
|
||||
throw new RuntimeException(param + "'s failed method cannot final modifier");
|
||||
} else if (m.getName().equals("sncp_getParams") && Modifier.isFinal(m.getModifiers())) {
|
||||
throw new RuntimeException(param + "'s sncp_getParams method cannot final modifier");
|
||||
} else if (m.getName().equals("sncp_setParams") && Modifier.isFinal(m.getModifiers())) {
|
||||
throw new RuntimeException(param + "'s sncp_setParams method cannot final modifier");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <blockquote><pre>
|
||||
* public class TestService implements Service{
|
||||
@@ -139,16 +173,16 @@ public abstract class Sncp {
|
||||
* }
|
||||
*
|
||||
* @RpcMultiRun(selfrun = false)
|
||||
public void createSomeThing(TestBean bean){
|
||||
//do something
|
||||
}
|
||||
|
||||
@RpcMultiRun
|
||||
public String updateSomeThing(String id){
|
||||
return "hello" + id;
|
||||
}
|
||||
}
|
||||
</pre></blockquote>
|
||||
* public void createSomeThing(TestBean bean){
|
||||
* //do something
|
||||
* }
|
||||
*
|
||||
* @RpcMultiRun
|
||||
* public String updateSomeThing(String id){
|
||||
* return "hello" + id;
|
||||
* }
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* @Resource(name = "")
|
||||
@@ -235,11 +269,12 @@ public abstract class Sncp {
|
||||
for (char ch : name.toCharArray()) {
|
||||
if (!((ch >= '0' && ch <= '9') || ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))) normal = false;
|
||||
}
|
||||
if (!normal) throw new RuntimeException(serviceClass + "'s resource name is illegal, must be 0-9 _ a-z A-Z");
|
||||
newDynName += "_" + (normal ? name : hash(name));
|
||||
}
|
||||
try {
|
||||
return (Class<T>) Class.forName(newDynName.replace('/', '.'));
|
||||
} catch (Exception ex) {
|
||||
} catch (Throwable ex) {
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
|
||||
@@ -362,7 +397,13 @@ public abstract class Sncp {
|
||||
mv.visitInsn(mrun.samerun() ? ICONST_1 : ICONST_0);
|
||||
mv.visitInsn(mrun.diffrun() ? ICONST_1 : ICONST_0);
|
||||
int varindex = 0;
|
||||
boolean handlerFuncFlag = false;
|
||||
for (Class pt : paramtypes) {
|
||||
if (AsyncHandler.class.isAssignableFrom(pt)) {
|
||||
if (handlerFuncFlag) throw new RuntimeException(method + " have more than one AsyncHandler type parameter");
|
||||
checkAsyncModifier(pt, method);
|
||||
handlerFuncFlag = true;
|
||||
}
|
||||
if (pt.isPrimitive()) {
|
||||
if (pt == long.class) {
|
||||
mv.visitVarInsn(LLOAD, ++varindex);
|
||||
@@ -403,8 +444,15 @@ public abstract class Sncp {
|
||||
//mv.setDebug(true);
|
||||
{ //给参数加上 Annotation
|
||||
final Annotation[][] anns = method.getParameterAnnotations();
|
||||
boolean handlerAttachFlag = false;
|
||||
for (int k = 0; k < anns.length; k++) {
|
||||
for (Annotation ann : anns[k]) {
|
||||
if (ann.annotationType() == RpcAttachment.class) {
|
||||
if (handlerAttachFlag) {
|
||||
throw new RuntimeException(method + " have more than one @RpcAttachment parameter");
|
||||
}
|
||||
handlerAttachFlag = true;
|
||||
}
|
||||
if (ann instanceof SncpDyn || ann instanceof RpcMultiRun) continue; //必须过滤掉 RpcMultiRun、SncpDyn,否则生成远程模式Service时会出错
|
||||
visitAnnotation(mv.visitParameterAnnotation(k, Type.getDescriptor(ann.annotationType()), true), ann);
|
||||
}
|
||||
@@ -942,7 +990,7 @@ public abstract class Sncp {
|
||||
s.set(rs, sb.toString());
|
||||
}
|
||||
return rs;
|
||||
} catch (Exception ex) {
|
||||
} catch (Throwable ex) {
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
|
||||
|
||||
256
src/org/redkale/net/sncp/SncpAsyncHandler.java
Normal file
256
src/org/redkale/net/sncp/SncpAsyncHandler.java
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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.net.sncp;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
import org.redkale.convert.bson.*;
|
||||
import org.redkale.net.sncp.SncpDynServlet.SncpServletAction;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 异步回调函数 <br>
|
||||
*
|
||||
* public class _DyncSncpAsyncHandler extends XXXAsyncHandler implements SncpAsyncHandler
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <V> 结果对象的泛型
|
||||
* @param <A> 附件对象的泛型
|
||||
*/
|
||||
public interface SncpAsyncHandler<V, A> extends AsyncHandler<V, A> {
|
||||
|
||||
public Object[] sncp_getParams();
|
||||
|
||||
public void sncp_setParams(Object... params);
|
||||
|
||||
static class Factory {
|
||||
|
||||
/**
|
||||
* <blockquote><pre>
|
||||
*
|
||||
* 考虑点:
|
||||
* 1、AsyncHandler子类是接口,且还有其他多个方法
|
||||
* 2、AsyncHandler子类是类, 需要继承,且必须有空参数构造函数
|
||||
* 3、AsyncHandler子类无论是接口还是类,都可能存在其他泛型
|
||||
*
|
||||
* public class XXXAsyncHandler_DyncSncpAsyncHandler_4323 extends XXXAsyncHandler implements SncpAsyncHandler {
|
||||
*
|
||||
* private SncpAsyncHandler sncphandler;
|
||||
*
|
||||
* @java.beans.ConstructorProperties({"sncphandler"})
|
||||
* public XXXAsyncHandler_DyncSncpAsyncHandler_4323(SncpAsyncHandler sncphandler) {
|
||||
* super();
|
||||
* this.sncphandler = sncphandler;
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public void completed(Object result, Object attachment) {
|
||||
* sncphandler.completed(result, attachment);
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public void failed(Throwable exc, Object attachment) {
|
||||
* sncphandler.failed(exc, attachment);
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public Object[] sncp_getParams() {
|
||||
* return sncphandler.sncp_getParams();
|
||||
* }
|
||||
*
|
||||
* @Override
|
||||
* public void sncp_setParams(Object... params) {
|
||||
* sncphandler.sncp_setParams(params);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param handlerClass AsyncHandler类型或子类
|
||||
*
|
||||
* @return Creator
|
||||
*/
|
||||
public static Creator<SncpAsyncHandler> createCreator(Class<? extends AsyncHandler> handlerClass) {
|
||||
//-------------------------------------------------------------
|
||||
final boolean handlerinterface = handlerClass.isInterface();
|
||||
final String handlerClassName = handlerClass.getName().replace('.', '/');
|
||||
final String sncyHandlerName = SncpAsyncHandler.class.getName().replace('.', '/');
|
||||
final String sncyHandlerDesc = Type.getDescriptor(SncpAsyncHandler.class);
|
||||
final String newDynName = handlerClass.getName().replace('.', '/') + "_Dync" + SncpAsyncHandler.class.getSimpleName() + "_" + (System.currentTimeMillis() % 10000);
|
||||
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
FieldVisitor fv;
|
||||
AsmMethodVisitor mv;
|
||||
AnnotationVisitor av0;
|
||||
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, newDynName, null, handlerinterface ? "java/lang/Object" : handlerClassName, handlerinterface ? new String[]{handlerClassName, sncyHandlerName} : new String[]{sncyHandlerName});
|
||||
|
||||
{ //handler 属性
|
||||
fv = cw.visitField(ACC_PRIVATE, "sncphandler", sncyHandlerDesc, null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
{//构造方法
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "<init>", "(" + sncyHandlerDesc + ")V", null, null));
|
||||
//mv.setDebug(true);
|
||||
{
|
||||
av0 = mv.visitAnnotation("Ljava/beans/ConstructorProperties;", true);
|
||||
{
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
av1.visit(null, "sncphandler");
|
||||
av1.visitEnd();
|
||||
}
|
||||
av0.visitEnd();
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, handlerinterface ? "java/lang/Object" : handlerClassName, "<init>", "()V", false);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitFieldInsn(PUTFIELD, newDynName, "sncphandler", sncyHandlerDesc);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
|
||||
for (java.lang.reflect.Method method : handlerClass.getMethods()) { //
|
||||
if ("completed".equals(method.getName()) && method.getParameterCount() == 2) {
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "completed", Type.getMethodDescriptor(method), null, null));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncyHandlerDesc);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, sncyHandlerName, "completed", "(Ljava/lang/Object;Ljava/lang/Object;)V", true);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
} else if ("failed".equals(method.getName()) && method.getParameterCount() == 2) {
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "failed", Type.getMethodDescriptor(method), null, null));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncyHandlerDesc);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, sncyHandlerName, "failed", "(Ljava/lang/Throwable;Ljava/lang/Object;)V", true);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(3, 3);
|
||||
mv.visitEnd();
|
||||
} else if (handlerinterface || java.lang.reflect.Modifier.isAbstract(method.getModifiers())) {
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null));
|
||||
Class returnType = method.getReturnType();
|
||||
if (returnType == void.class) {
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(0, 1);
|
||||
} else if (returnType.isPrimitive()) {
|
||||
mv.visitInsn(ICONST_0);
|
||||
if (returnType == long.class) {
|
||||
mv.visitInsn(LRETURN);
|
||||
mv.visitMaxs(2, 1);
|
||||
} else if (returnType == float.class) {
|
||||
mv.visitInsn(FRETURN);
|
||||
mv.visitMaxs(2, 1);
|
||||
} else if (returnType == double.class) {
|
||||
mv.visitInsn(DRETURN);
|
||||
mv.visitMaxs(2, 1);
|
||||
} else {
|
||||
mv.visitInsn(IRETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
}
|
||||
} else {
|
||||
mv.visitInsn(ACONST_NULL);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
}
|
||||
mv.visitEnd();
|
||||
}
|
||||
}
|
||||
{ // sncp_getParams
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "sncp_getParams", "()[Ljava/lang/Object;", null, null));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncyHandlerDesc);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, sncyHandlerName, "sncp_getParams", "()[Ljava/lang/Object;", true);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(1, 1);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{ // sncp_setParams
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_VARARGS, "sncp_setParams", "([Ljava/lang/Object;)V", null, null));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "sncphandler", sncyHandlerDesc);
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, sncyHandlerName, "sncp_setParams", "([Ljava/lang/Object;)V", true);
|
||||
mv.visitInsn(RETURN);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
}
|
||||
cw.visitEnd();
|
||||
byte[] bytes = cw.toByteArray();
|
||||
Class<SncpAsyncHandler> newHandlerClazz = (Class<SncpAsyncHandler>) new ClassLoader(handlerClass.getClassLoader()) {
|
||||
public final Class<?> loadClass(String name, byte[] b) {
|
||||
return defineClass(name, b, 0, b.length);
|
||||
}
|
||||
}.loadClass(newDynName.replace('/', '.'), bytes);
|
||||
return Creator.create(newHandlerClazz);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class DefaultSncpAsyncHandler<V, A> implements SncpAsyncHandler<V, A> {
|
||||
|
||||
//为了在回调函数中调用_callParameter方法
|
||||
protected Object[] params;
|
||||
|
||||
protected SncpServletAction action;
|
||||
|
||||
protected BsonReader in;
|
||||
|
||||
protected BsonWriter out;
|
||||
|
||||
protected SncpRequest request;
|
||||
|
||||
protected SncpResponse response;
|
||||
|
||||
public DefaultSncpAsyncHandler(SncpServletAction action, BsonReader in, BsonWriter out, SncpRequest request, SncpResponse response) {
|
||||
this.action = action;
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(Object result, Object attachment) {
|
||||
try {
|
||||
action._callParameter(out, sncp_getParams());
|
||||
action.convert.convertTo(out, Object.class, result);
|
||||
response.finish(0, out);
|
||||
} catch (Exception e) {
|
||||
failed(e, attachment);
|
||||
} finally {
|
||||
action.convert.offerBsonReader(in);
|
||||
action.convert.offerBsonWriter(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
response.getContext().getLogger().log(Level.INFO, "sncp execute error(" + request + ")", exc);
|
||||
response.finish(SncpResponse.RETCODE_THROWEXCEPTION, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] sncp_getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sncp_setParams(Object... params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,8 @@ public final class SncpClient {
|
||||
|
||||
protected final Type[] paramTypes;
|
||||
|
||||
protected final Class[] paramClass;
|
||||
|
||||
protected final Attribute[] paramAttrs; // 为null表示无RpcCall处理,index=0固定为null, 其他为参数标记的RpcCall回调方法
|
||||
|
||||
protected final int handlerFuncParamIndex;
|
||||
@@ -51,8 +53,8 @@ public final class SncpClient {
|
||||
|
||||
protected final int addressSourceParamIndex;
|
||||
|
||||
public SncpAction(Method method, DLong actionid) {
|
||||
this.actionid = actionid;
|
||||
public SncpAction(final Class clazz, Method method, DLong actionid) {
|
||||
this.actionid = actionid == null ? Sncp.hash(method) : actionid;
|
||||
Type rt = method.getGenericReturnType();
|
||||
if (rt instanceof TypeVariable) {
|
||||
TypeVariable tv = (TypeVariable) rt;
|
||||
@@ -60,6 +62,7 @@ public final class SncpClient {
|
||||
}
|
||||
this.resultTypes = rt == void.class ? null : rt;
|
||||
this.paramTypes = method.getGenericParameterTypes();
|
||||
this.paramClass = method.getParameterTypes();
|
||||
this.method = method;
|
||||
Annotation[][] anns = method.getParameterAnnotations();
|
||||
int targetAddrIndex = -1;
|
||||
@@ -72,6 +75,10 @@ public final class SncpClient {
|
||||
Class<?>[] params = method.getParameterTypes();
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if (AsyncHandler.class.isAssignableFrom(params[i])) {
|
||||
if (handlerFuncIndex >= 0) {
|
||||
throw new RuntimeException(method + " have more than one AsyncHandler type parameter");
|
||||
}
|
||||
Sncp.checkAsyncModifier(params[i], method);
|
||||
handlerFuncIndex = i;
|
||||
break;
|
||||
}
|
||||
@@ -80,6 +87,9 @@ public final class SncpClient {
|
||||
if (anns[i].length > 0) {
|
||||
for (Annotation ann : anns[i]) {
|
||||
if (ann.annotationType() == RpcAttachment.class) {
|
||||
if (handlerAttachIndex >= 0) {
|
||||
throw new RuntimeException(method + " have more than one @RpcAttachment parameter");
|
||||
}
|
||||
handlerAttachIndex = i;
|
||||
} else if (ann.annotationType() == RpcTargetAddress.class && SocketAddress.class.isAssignableFrom(params[i])) {
|
||||
targetAddrIndex = i;
|
||||
@@ -106,14 +116,8 @@ public final class SncpClient {
|
||||
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;
|
||||
if (this.handlerFuncParamIndex >= 0 && method.getReturnType() != void.class) {
|
||||
throw new RuntimeException(method + " have AsyncHandler type parameter but return type is not void");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,14 +158,14 @@ public final class SncpClient {
|
||||
this.remote = remote;
|
||||
this.executor = executor;
|
||||
this.serviceClass = serviceClass;
|
||||
this.serviceversion = service.version();
|
||||
this.serviceversion = 0;
|
||||
this.clientAddress = clientAddress;
|
||||
this.name = serviceName;
|
||||
this.serviceid = Sncp.hash(serviceType.getName() + ':' + serviceName);
|
||||
final List<SncpAction> methodens = new ArrayList<>();
|
||||
//------------------------------------------------------------------------------
|
||||
for (java.lang.reflect.Method method : parseMethod(serviceClass)) {
|
||||
methodens.add(new SncpAction(method, Sncp.hash(method)));
|
||||
methodens.add(new SncpAction(serviceClass, method, Sncp.hash(method)));
|
||||
}
|
||||
this.actions = methodens.toArray(new SncpAction[methodens.size()]);
|
||||
this.addrBytes = clientAddress == null ? new byte[4] : clientAddress.getAddress().getAddress();
|
||||
@@ -172,7 +176,7 @@ public final class SncpClient {
|
||||
final List<SncpAction> actions = new ArrayList<>();
|
||||
//------------------------------------------------------------------------------
|
||||
for (java.lang.reflect.Method method : parseMethod(serviceClass)) {
|
||||
actions.add(new SncpAction(method, Sncp.hash(method)));
|
||||
actions.add(new SncpAction(serviceClass, method, Sncp.hash(method)));
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
@@ -216,7 +220,7 @@ public final class SncpClient {
|
||||
if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue;
|
||||
if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue;
|
||||
if (method.getName().equals("init") || method.getName().equals("destroy")) continue;
|
||||
if (method.getName().equals("version") || method.getName().equals("name")) continue;
|
||||
//if (method.getName().equals("version") || method.getName().equals("name")) continue;
|
||||
//if (onlySncpDyn && method.getAnnotation(SncpDyn.class) == null) continue;
|
||||
DLong actionid = Sncp.hash(method);
|
||||
Method old = actionids.get(actionid);
|
||||
@@ -296,7 +300,7 @@ public final class SncpClient {
|
||||
final Attribute attr = action.paramAttrs[i];
|
||||
attr.set(params[i - 1], bsonConvert.convertFrom(attr.type(), reader));
|
||||
}
|
||||
return bsonConvert.convertFrom(action.resultTypes, reader);
|
||||
return bsonConvert.convertFrom(action.handlerFuncParamIndex >= 0 ? Object.class : action.resultTypes, reader);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
||||
logger.log(Level.SEVERE, actions[index].method + " sncp (params: " + jsonConvert.convertTo(params) + ") remote error", e);
|
||||
throw new RuntimeException(actions[index].method + " sncp remote error", e);
|
||||
@@ -327,11 +331,12 @@ public final class SncpClient {
|
||||
|
||||
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;
|
||||
Class[] myparamclass = action.paramClass;
|
||||
if (action.addressSourceParamIndex >= 0) params[action.addressSourceParamIndex] = this.clientAddress;
|
||||
final BsonWriter writer = bsonConvert.pollBsonWriter(transport.getBufferSupplier()); // 将head写入
|
||||
writer.writeTo(DEFAULT_HEADER);
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
bsonConvert.convertTo(writer, myparamtypes[i], params[i]);
|
||||
bsonConvert.convertTo(writer, AsyncHandler.class.isAssignableFrom(myparamclass[i]) ? AsyncHandler.class : myparamtypes[i], params[i]);
|
||||
}
|
||||
final int reqBodyLength = writer.count() - HEADER_SIZE; //body总长度
|
||||
final long seqid = System.nanoTime();
|
||||
@@ -438,7 +443,7 @@ public final class SncpClient {
|
||||
final Attribute attr = action.paramAttrs[i];
|
||||
attr.set(params[i - 1], bsonConvert.convertFrom(attr.type(), reader));
|
||||
}
|
||||
Object rs = bsonConvert.convertFrom(action.resultTypes, reader);
|
||||
Object rs = bsonConvert.convertFrom(action.handlerFuncParamIndex >= 0 ? Object.class : action.resultTypes, reader);
|
||||
handler.completed(rs, handlerAttach);
|
||||
} catch (Exception e) {
|
||||
handler.failed(e, handlerAttach);
|
||||
@@ -481,7 +486,8 @@ public final class SncpClient {
|
||||
int version = buffer.getInt();
|
||||
if (version != this.serviceversion) throw new RuntimeException("sncp(" + action.method + ") response.serviceversion = " + serviceversion + ", but request.serviceversion =" + version);
|
||||
DLong raction = DLong.read(buffer);
|
||||
if (!action.actionid.equals(raction)) throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")");
|
||||
DLong actid = action.actionid;
|
||||
if (!actid.equals(raction)) throw new RuntimeException("sncp(" + action.method + ") response.actionid = " + action.actionid + ", but request.actionid =(" + raction + ")");
|
||||
buffer.getInt(); //地址
|
||||
buffer.getChar(); //端口
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
|
||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||
import jdk.internal.org.objectweb.asm.Type;
|
||||
import org.redkale.convert.bson.*;
|
||||
import org.redkale.net.sncp.SncpAsyncHandler.DefaultSncpAsyncHandler;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.service.RpcCall;
|
||||
@@ -63,7 +64,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue;
|
||||
if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue;
|
||||
if (method.getName().equals("init") || method.getName().equals("destroy")) continue;
|
||||
if (method.getName().equals("version") || method.getName().equals("name")) continue;
|
||||
//if (method.getName().equals("version") || method.getName().equals("name")) continue;
|
||||
final DLong actionid = Sncp.hash(method);
|
||||
SncpServletAction action = SncpServletAction.create(service, actionid, method);
|
||||
action.convert = convert;
|
||||
@@ -120,16 +121,30 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
BsonWriter out = action.convert.pollBsonWriter(bufferSupplier);
|
||||
out.writeTo(DEFAULT_HEADER);
|
||||
BsonReader in = action.convert.pollBsonReader();
|
||||
SncpAsyncHandler handler = null;
|
||||
try {
|
||||
if (action.handlerFuncParamIndex >= 0) {
|
||||
if (action.handlerFuncParamClass == AsyncHandler.class) {
|
||||
handler = new DefaultSncpAsyncHandler(action, in, out, request, response);
|
||||
} else {
|
||||
Creator<SncpAsyncHandler> creator = action.handlerCreator;
|
||||
if (creator == null) {
|
||||
creator = SncpAsyncHandler.Factory.createCreator(action.handlerFuncParamClass);
|
||||
action.handlerCreator = creator;
|
||||
}
|
||||
handler = creator.create(new DefaultSncpAsyncHandler(action, in, out, request, response));
|
||||
}
|
||||
}
|
||||
in.setBytes(request.getBody());
|
||||
action.action(in, out);
|
||||
response.finish(0, out);
|
||||
action.action(in, out, handler);
|
||||
if (handler == null) {
|
||||
response.finish(0, out);
|
||||
action.convert.offerBsonReader(in);
|
||||
action.convert.offerBsonWriter(out);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
response.getContext().getLogger().log(Level.INFO, "sncp execute error(" + request + ")", t);
|
||||
response.finish(SncpResponse.RETCODE_THROWEXCEPTION, null);
|
||||
} finally {
|
||||
action.convert.offerBsonReader(in);
|
||||
action.convert.offerBsonWriter(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +153,8 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
|
||||
public Method method;
|
||||
|
||||
public Creator<SncpAsyncHandler> handlerCreator;
|
||||
|
||||
@Resource
|
||||
protected BsonConvert convert;
|
||||
|
||||
@@ -145,7 +162,11 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
|
||||
protected java.lang.reflect.Type[] paramTypes; //index=0表示返回参数的type, void的返回参数类型为null
|
||||
|
||||
public abstract void action(final BsonReader in, final BsonWriter out) throws Throwable;
|
||||
protected int handlerFuncParamIndex = -1; //handlerFuncParamIndex>=0表示存在AsyncHandler参数
|
||||
|
||||
protected Class handlerFuncParamClass; //AsyncHandler参数的类型
|
||||
|
||||
public abstract void action(final BsonReader in, final BsonWriter out, final SncpAsyncHandler handler) throws Throwable;
|
||||
|
||||
public final void _callParameter(final BsonWriter out, final Object... params) {
|
||||
if (paramAttrs != null) {
|
||||
@@ -162,17 +183,25 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
/**
|
||||
* <blockquote><pre>
|
||||
* public class TestService implements Service {
|
||||
*
|
||||
* public boolean change(TestBean bean, String name, int id) {
|
||||
*
|
||||
* return false;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* public class DynActionTestService_change extends SncpServletAction {
|
||||
* public void insert(AsyncHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
* }
|
||||
*
|
||||
* public void update(long show, short v2, AsyncHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*
|
||||
* class DynActionTestService_change extends SncpServletAction {
|
||||
*
|
||||
* public TestService service;
|
||||
*
|
||||
* @Override
|
||||
* public void action(final BsonReader in, final BsonWriter out) throws Throwable {
|
||||
* @Override
|
||||
* public void action(BsonReader in, BsonWriter out, SncpAsyncHandler handler) throws Throwable {
|
||||
* TestBean arg1 = convert.convertFrom(paramTypes[1], in);
|
||||
* String arg2 = convert.convertFrom(paramTypes[2], in);
|
||||
* int arg3 = convert.convertFrom(paramTypes[3], in);
|
||||
@@ -180,7 +209,42 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
* _callParameter(out, arg1, arg2, arg3);
|
||||
* convert.convertTo(out, paramTypes[0], rs);
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class DynActionTestService_insert extends SncpServletAction {
|
||||
*
|
||||
* public TestService service;
|
||||
*
|
||||
* @Override
|
||||
* public void action(BsonReader in, BsonWriter out, SncpAsyncHandler handler) throws Throwable {
|
||||
* SncpAsyncHandler arg0 = handler;
|
||||
* convert.convertFrom(AsyncHandler.class, in);
|
||||
* TestBean arg1 = convert.convertFrom(paramTypes[2], in);
|
||||
* String arg2 = convert.convertFrom(paramTypes[3], in);
|
||||
* int arg3 = convert.convertFrom(paramTypes[4], in);
|
||||
* handler.sncp_setParams(arg0, arg1, arg2, arg3);
|
||||
* service.insert(arg0, arg1, arg2, arg3);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* class DynActionTestService_update extends SncpServletAction {
|
||||
*
|
||||
* public TestService service;
|
||||
*
|
||||
* @Override
|
||||
* public void action(BsonReader in, BsonWriter out, SncpAsyncHandler handler) throws Throwable {
|
||||
* long a1 = convert.convertFrom(paramTypes[1], in);
|
||||
* short a2 = convert.convertFrom(paramTypes[2], in);
|
||||
* SncpAsyncHandler a3 = handler;
|
||||
* convert.convertFrom(AsyncHandler.class, in);
|
||||
* TestBean arg1 = convert.convertFrom(paramTypes[4], in);
|
||||
* String arg2 = convert.convertFrom(paramTypes[5], in);
|
||||
* int arg3 = convert.convertFrom(paramTypes[6], in);
|
||||
* handler.sncp_setParams(a1, a2, a3, arg1, arg2, arg3);
|
||||
* service.update(a1, a2, a3, arg1, arg2, arg3);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param service Service
|
||||
@@ -195,6 +259,8 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
final String supDynName = SncpServletAction.class.getName().replace('.', '/');
|
||||
final String serviceName = serviceClass.getName().replace('.', '/');
|
||||
final String convertName = BsonConvert.class.getName().replace('.', '/');
|
||||
final String handlerName = SncpAsyncHandler.class.getName().replace('.', '/');
|
||||
final String asyncHandlerDesc = Type.getDescriptor(SncpAsyncHandler.class);
|
||||
final String convertReaderDesc = Type.getDescriptor(BsonReader.class);
|
||||
final String convertWriterDesc = Type.getDescriptor(BsonWriter.class);
|
||||
final String serviceDesc = Type.getDescriptor(serviceClass);
|
||||
@@ -204,7 +270,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
try {
|
||||
Class.forName(newDynName.replace('/', '.'));
|
||||
newDynName += "_";
|
||||
} catch (Exception ex) {
|
||||
} catch (Throwable ex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -236,15 +302,39 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex); //不可能会发生
|
||||
}
|
||||
int handlerFuncIndex = -1;
|
||||
Class handlerFuncClass = null;
|
||||
{ // action方法
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "action", "(" + convertReaderDesc + convertWriterDesc + ")V", null, new String[]{"java/lang/Throwable"}));
|
||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "action", "(" + convertReaderDesc + convertWriterDesc + asyncHandlerDesc + ")V", null, new String[]{"java/lang/Throwable"}));
|
||||
//mv.setDebug(true);
|
||||
int iconst = ICONST_1;
|
||||
int intconst = 1;
|
||||
int store = 3; //action的参数个数+1
|
||||
int store = 4; //action的参数个数+1
|
||||
final Class[] paramClasses = method.getParameterTypes();
|
||||
int[][] codes = new int[paramClasses.length][2];
|
||||
for (int i = 0; i < paramClasses.length; i++) { //参数
|
||||
if (AsyncHandler.class.isAssignableFrom(paramClasses[i])) {
|
||||
if (handlerFuncIndex >= 0) {
|
||||
throw new RuntimeException(method + " have more than one AsyncHandler type parameter");
|
||||
}
|
||||
Sncp.checkAsyncModifier(paramClasses[i], method);
|
||||
handlerFuncIndex = i;
|
||||
handlerFuncClass = paramClasses[i];
|
||||
mv.visitVarInsn(ALOAD, 3);
|
||||
mv.visitTypeInsn(CHECKCAST, paramClasses[i].getName().replace('.', '/'));
|
||||
mv.visitVarInsn(ASTORE, store);
|
||||
codes[i] = new int[]{ALOAD, store};
|
||||
store++;
|
||||
iconst++;
|
||||
intconst++;
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "convert", Type.getDescriptor(BsonConvert.class));
|
||||
mv.visitLdcInsn(Type.getType(Type.getDescriptor(AsyncHandler.class)));
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, convertName, "convertFrom", convertFromDesc, false);
|
||||
mv.visitInsn(POP);
|
||||
continue;
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "convert", Type.getDescriptor(BsonConvert.class));
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
@@ -296,6 +386,43 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
intconst++;
|
||||
store++;
|
||||
}
|
||||
if (handlerFuncIndex >= 0) { //调用SncpAsyncHandler.setParams(Object... params)
|
||||
mv.visitVarInsn(ALOAD, 3);
|
||||
if (paramClasses.length > 5) {
|
||||
mv.visitIntInsn(BIPUSH, paramClasses.length);
|
||||
} else {
|
||||
mv.visitInsn(paramClasses.length + ICONST_0);
|
||||
}
|
||||
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
|
||||
int insn = 3; //action的参数个数
|
||||
for (int j = 0; j < paramClasses.length; j++) {
|
||||
final Class pt = paramClasses[j];
|
||||
mv.visitInsn(DUP);
|
||||
insn++;
|
||||
if (j <= 5) {
|
||||
mv.visitInsn(ICONST_0 + j);
|
||||
} else {
|
||||
mv.visitIntInsn(BIPUSH, j);
|
||||
}
|
||||
if (pt.isPrimitive()) {
|
||||
if (pt == long.class) {
|
||||
mv.visitVarInsn(LLOAD, insn++);
|
||||
} else if (pt == float.class) {
|
||||
mv.visitVarInsn(FLOAD, insn++);
|
||||
} else if (pt == double.class) {
|
||||
mv.visitVarInsn(DLOAD, insn++);
|
||||
} else {
|
||||
mv.visitVarInsn(ILOAD, insn);
|
||||
}
|
||||
Class bigclaz = java.lang.reflect.Array.get(java.lang.reflect.Array.newInstance(pt, 1), 0).getClass();
|
||||
mv.visitMethodInsn(INVOKESTATIC, bigclaz.getName().replace('.', '/'), "valueOf", "(" + Type.getDescriptor(pt) + ")" + Type.getDescriptor(bigclaz), false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, insn);
|
||||
}
|
||||
mv.visitInsn(AASTORE);
|
||||
}
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, handlerName, "sncp_setParams", "([Ljava/lang/Object;)V", true);
|
||||
}
|
||||
{ //调用service
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, "service", serviceDesc);
|
||||
@@ -318,44 +445,45 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
}
|
||||
mv.visitVarInsn(ASTORE, store); //11
|
||||
}
|
||||
//------------------------- _callParameter 方法 --------------------------------
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
if (paramClasses.length <= 5) { //参数总数量
|
||||
mv.visitInsn(ICONST_0 + paramClasses.length);
|
||||
} else {
|
||||
mv.visitIntInsn(BIPUSH, paramClasses.length);
|
||||
}
|
||||
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
|
||||
int insn = 2;
|
||||
for (int j = 0; j < paramClasses.length; j++) {
|
||||
final Class pt = paramClasses[j];
|
||||
mv.visitInsn(DUP);
|
||||
insn++;
|
||||
if (j <= 5) {
|
||||
mv.visitInsn(ICONST_0 + j);
|
||||
if (handlerFuncIndex < 0) {
|
||||
//------------------------- _callParameter 方法 --------------------------------
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
if (paramClasses.length <= 5) { //参数总数量
|
||||
mv.visitInsn(ICONST_0 + paramClasses.length);
|
||||
} else {
|
||||
mv.visitIntInsn(BIPUSH, j);
|
||||
mv.visitIntInsn(BIPUSH, paramClasses.length);
|
||||
}
|
||||
if (pt.isPrimitive()) {
|
||||
if (pt == long.class) {
|
||||
mv.visitVarInsn(LLOAD, insn++);
|
||||
} else if (pt == float.class) {
|
||||
mv.visitVarInsn(FLOAD, insn++);
|
||||
} else if (pt == double.class) {
|
||||
mv.visitVarInsn(DLOAD, insn++);
|
||||
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
|
||||
int insn = 3;//action的参数个数
|
||||
for (int j = 0; j < paramClasses.length; j++) {
|
||||
final Class pt = paramClasses[j];
|
||||
mv.visitInsn(DUP);
|
||||
insn++;
|
||||
if (j <= 5) {
|
||||
mv.visitInsn(ICONST_0 + j);
|
||||
} else {
|
||||
mv.visitVarInsn(ILOAD, insn);
|
||||
mv.visitIntInsn(BIPUSH, j);
|
||||
}
|
||||
Class bigclaz = java.lang.reflect.Array.get(java.lang.reflect.Array.newInstance(pt, 1), 0).getClass();
|
||||
mv.visitMethodInsn(INVOKESTATIC, bigclaz.getName().replace('.', '/'), "valueOf", "(" + Type.getDescriptor(pt) + ")" + Type.getDescriptor(bigclaz), false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, insn);
|
||||
if (pt.isPrimitive()) {
|
||||
if (pt == long.class) {
|
||||
mv.visitVarInsn(LLOAD, insn++);
|
||||
} else if (pt == float.class) {
|
||||
mv.visitVarInsn(FLOAD, insn++);
|
||||
} else if (pt == double.class) {
|
||||
mv.visitVarInsn(DLOAD, insn++);
|
||||
} else {
|
||||
mv.visitVarInsn(ILOAD, insn);
|
||||
}
|
||||
Class bigclaz = java.lang.reflect.Array.get(java.lang.reflect.Array.newInstance(pt, 1), 0).getClass();
|
||||
mv.visitMethodInsn(INVOKESTATIC, bigclaz.getName().replace('.', '/'), "valueOf", "(" + Type.getDescriptor(pt) + ")" + Type.getDescriptor(bigclaz), false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, insn);
|
||||
}
|
||||
mv.visitInsn(AASTORE);
|
||||
}
|
||||
mv.visitInsn(AASTORE);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "_callParameter", "(" + convertWriterDesc + "[Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "_callParameter", "(" + convertWriterDesc + "[Ljava/lang/Object;)V", false);
|
||||
|
||||
//-------------------------直接返回 或者 调用convertTo方法 --------------------------------
|
||||
int maxStack = codes.length > 0 ? codes[codes.length - 1][1] : 1;
|
||||
if (returnClass == void.class) { //返回
|
||||
@@ -398,6 +526,8 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
types[0] = rt;
|
||||
System.arraycopy(ptypes, 0, types, 1, ptypes.length);
|
||||
instance.paramTypes = types;
|
||||
instance.handlerFuncParamIndex = handlerFuncIndex;
|
||||
instance.handlerFuncParamClass = handlerFuncClass;
|
||||
|
||||
org.redkale.util.Attribute[] atts = new org.redkale.util.Attribute[ptypes.length + 1];
|
||||
Annotation[][] anns = method.getParameterAnnotations();
|
||||
|
||||
@@ -30,26 +30,22 @@ public class SncpPrepareServlet extends PrepareServlet<DLong, SncpContext, SncpR
|
||||
|
||||
public void addServlet(SncpServlet servlet, AnyValue conf) {
|
||||
setServletConf(servlet, conf);
|
||||
synchronized (mappings) {
|
||||
mappings.put(servlet.getServiceid(), servlet);
|
||||
servlets.add(servlet);
|
||||
}
|
||||
putMapping(servlet.getServiceid(), servlet);
|
||||
putServlet(servlet);
|
||||
}
|
||||
|
||||
public List<SncpServlet> getSncpServlets() {
|
||||
ArrayList<SncpServlet> list = new ArrayList<>(servlets.size());
|
||||
servlets.forEach(x -> list.add((SncpServlet) x));
|
||||
return list;
|
||||
return new ArrayList<>(getServlets());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(SncpContext context, AnyValue config) {
|
||||
servlets.forEach(s -> s.init(context, getServletConf(s)));
|
||||
getServlets().forEach(s -> s.init(context, getServletConf(s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(SncpContext context, AnyValue config) {
|
||||
servlets.forEach(s -> s.destroy(context, getServletConf(s)));
|
||||
getServlets().forEach(s -> s.destroy(context, getServletConf(s)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,7 +54,7 @@ public class SncpPrepareServlet extends PrepareServlet<DLong, SncpContext, SncpR
|
||||
response.finish(pongBuffer.duplicate());
|
||||
return;
|
||||
}
|
||||
SncpServlet servlet = (SncpServlet) mappings.get(request.getServiceid());
|
||||
SncpServlet servlet = (SncpServlet) mappingServlet(request.getServiceid());
|
||||
if (servlet == null) {
|
||||
response.finish(SncpResponse.RETCODE_ILLSERVICEID, null); //无效serviceid
|
||||
} else {
|
||||
|
||||
@@ -82,7 +82,7 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
if (storeKeyStr != null && storeValueStr != null) {
|
||||
try {
|
||||
this.setStoreType(Class.forName(storeKeyStr), Class.forName(storeValueStr));
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
logger.log(Level.SEVERE, self.getClass().getSimpleName() + " load key & value store class (" + storeKeyStr + ", " + storeValueStr + ") error", e);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
if (expireHandlerClass != null) {
|
||||
try {
|
||||
this.expireHandler = (Consumer<CacheEntry>) Class.forName(expireHandlerClass).newInstance();
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
logger.log(Level.SEVERE, self.getClass().getSimpleName() + " new expirehandler class (" + expireHandlerClass + ") instance error", e);
|
||||
}
|
||||
}
|
||||
@@ -192,10 +192,9 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(final AsyncHandler<Boolean, K> handler, @RpcAttachment final K key) {
|
||||
public void exists(final AsyncHandler<Boolean, K> handler, @RpcAttachment final K key) {
|
||||
boolean rs = exists(key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,10 +208,9 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(final AsyncHandler<V, K> handler, @RpcAttachment final K key) {
|
||||
public void get(final AsyncHandler<V, K> handler, @RpcAttachment final K key) {
|
||||
V rs = get(key);
|
||||
if (handler != null) handler.completed(rs, key);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,10 +227,9 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getAndRefresh(final AsyncHandler<V, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
||||
public void 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
|
||||
@@ -327,10 +324,9 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getCollection(final AsyncHandler<Collection<V>, K> handler, @RpcAttachment final K key) {
|
||||
public void 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
|
||||
@@ -339,10 +335,9 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<V> getCollectionAndRefresh(final AsyncHandler<Collection<V>, K> handler, @RpcAttachment final K key, final int expireSeconds) {
|
||||
public void 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
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.redkale.source.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 实现进程间DataSource的缓存数据同步
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
@@ -26,20 +27,23 @@ public class DataCacheListenerService implements DataCacheListener, Service {
|
||||
|
||||
@Override
|
||||
@RpcMultiRun(selfrun = false, async = true)
|
||||
public <T> void insertCache(Class<T> clazz, T... entitys) {
|
||||
((DataDefaultSource) source).insertCache(clazz, entitys);
|
||||
public <T> int insertCache(Class<T> clazz, T... entitys) {
|
||||
if (!(source instanceof DataCacheListener)) return -2;
|
||||
return ((DataCacheListener) source).insertCache(clazz, entitys);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun(selfrun = false, async = true)
|
||||
public <T> void updateCache(Class<T> clazz, T... entitys) {
|
||||
((DataDefaultSource) source).updateCache(clazz, entitys);
|
||||
public <T> int updateCache(Class<T> clazz, T... entitys) {
|
||||
if (!(source instanceof DataCacheListener)) return -2;
|
||||
return ((DataCacheListener) source).updateCache(clazz, entitys);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RpcMultiRun(selfrun = false, async = true)
|
||||
public <T> void deleteCache(Class<T> clazz, Serializable... ids) {
|
||||
((DataDefaultSource) source).deleteCache(clazz, ids);
|
||||
public <T> int deleteCache(Class<T> clazz, Serializable... ids) {
|
||||
if (!(source instanceof DataCacheListener)) return -2;
|
||||
return ((DataCacheListener) source).deleteCache(clazz, ids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
|
||||
@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);
|
||||
source.insert(handler, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,10 +44,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void delete(final AsyncHandler<Integer, T[]> handler, @RpcAttachment final T... values) {
|
||||
source.delete(handler, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,10 +54,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void delete(final AsyncHandler<Integer, Serializable[]> handler, final Class<T> clazz, @RpcAttachment final Serializable... ids) {
|
||||
source.delete(handler, clazz, ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,10 +64,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
source.delete(handler, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,10 +74,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment FilterNode node) {
|
||||
source.delete(handler, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,10 +84,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void update(final AsyncHandler<Integer, T[]> handler, @RpcAttachment final T... values) {
|
||||
source.update(handler, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,10 +94,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable id, final String column, final Serializable value) {
|
||||
source.updateColumn(handler, clazz, id, column, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,10 +104,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final String column, final Serializable value, @RpcAttachment final FilterNode node) {
|
||||
source.updateColumn(handler, clazz, column, value, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,10 +114,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable id, final ColumnValue... values) {
|
||||
source.updateColumn(handler, clazz, id, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,10 +124,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node, final ColumnValue... values) {
|
||||
source.updateColumn(handler, clazz, node, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,10 +134,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node, final Flipper flipper, final ColumnValue... values) {
|
||||
source.updateColumn(handler, clazz, node, flipper, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,10 +144,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, T> handler, @RpcAttachment final T bean, final String... columns) {
|
||||
source.updateColumn(handler, bean, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -177,10 +154,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, @RpcAttachment final FilterNode node, final String... columns) {
|
||||
source.updateColumn(handler, bean, node, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,10 +164,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, T> handler, @RpcAttachment final T bean, final SelectColumn selects) {
|
||||
source.updateColumn(handler, bean, selects);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,10 +174,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, @RpcAttachment final FilterNode node, final SelectColumn selects) {
|
||||
source.updateColumn(handler, bean, node, selects);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,10 +184,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, @RpcAttachment final String column) {
|
||||
source.getNumberResult(handler, entityClass, func, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,10 +194,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <B extends FilterBean> void getNumberResult(final AsyncHandler<Number, B> handler, final Class entityClass, final FilterFunc func, final String column, @RpcAttachment final B bean) {
|
||||
source.getNumberResult(handler, entityClass, func, column, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,10 +204,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public void getNumberResult(final AsyncHandler<Number, FilterNode> handler, final Class entityClass, final FilterFunc func, final String column, @RpcAttachment final FilterNode node) {
|
||||
source.getNumberResult(handler, entityClass, func, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -249,10 +214,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, @RpcAttachment final String column) {
|
||||
source.getNumberResult(handler, entityClass, func, defVal, column);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,10 +224,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, @RpcAttachment final String column, final FilterBean bean) {
|
||||
source.getNumberResult(handler, entityClass, func, defVal, column, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,10 +234,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, @RpcAttachment final String column, final FilterNode node) {
|
||||
source.getNumberResult(handler, entityClass, func, defVal, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,10 +244,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <N extends Number> void getNumberMap(final AsyncHandler<Map<String, N>, FilterFuncColumn[]> handler, final Class entityClass, @RpcAttachment final FilterFuncColumn... columns) {
|
||||
source.getNumberMap(handler, entityClass, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -297,10 +254,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <N extends Number, B extends FilterBean> void getNumberMap(final AsyncHandler<Map<String, N>, B> handler, final Class entityClass, @RpcAttachment final B bean, final FilterFuncColumn... columns) {
|
||||
source.getNumberMap(handler, entityClass, bean, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,10 +264,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <N extends Number> void getNumberMap(final AsyncHandler<Map<String, N>, FilterNode> handler, final Class entityClass, @RpcAttachment final FilterNode node, final FilterFuncColumn... columns) {
|
||||
source.getNumberMap(handler, entityClass, node, columns);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -321,10 +274,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, K extends Serializable, N extends Number> void queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, @RpcAttachment final String keyColumn, final FilterFunc func, final String funcColumn) {
|
||||
source.queryColumnMap(handler, entityClass, keyColumn, func, funcColumn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,10 +284,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, K extends Serializable, N extends Number> void 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) {
|
||||
source.queryColumnMap(handler, entityClass, keyColumn, func, funcColumn, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -345,10 +294,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, K extends Serializable, N extends Number> void 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) {
|
||||
source.queryColumnMap(handler, entityClass, keyColumn, func, funcColumn, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -357,10 +304,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable pk) {
|
||||
source.find(handler, clazz, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -369,10 +314,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, SelectColumn selects, @RpcAttachment final Serializable pk) {
|
||||
source.find(handler, clazz, selects, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -381,10 +324,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final String column, @RpcAttachment final Serializable key) {
|
||||
source.find(handler, clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -393,10 +334,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void find(final AsyncHandler<T, B> handler, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
source.find(handler, clazz, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -405,10 +344,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
source.find(handler, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -417,10 +354,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void find(final AsyncHandler<T, B> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final B bean) {
|
||||
source.find(handler, clazz, selects, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,10 +364,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final FilterNode node) {
|
||||
source.find(handler, clazz, selects, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -441,10 +374,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, @RpcAttachment final Serializable pk) {
|
||||
source.findColumn(handler, clazz, column, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -453,10 +384,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, @RpcAttachment final B bean) {
|
||||
source.findColumn(handler, clazz, column, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -465,10 +394,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, @RpcAttachment final FilterNode node) {
|
||||
source.findColumn(handler, clazz, column, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -477,10 +404,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable defValue, @RpcAttachment final Serializable pk) {
|
||||
source.findColumn(handler, clazz, column, defValue, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -489,10 +414,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final Serializable defValue, @RpcAttachment final B bean) {
|
||||
source.findColumn(handler, clazz, column, defValue, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -501,10 +424,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final Serializable defValue, @RpcAttachment final FilterNode node) {
|
||||
source.findColumn(handler, clazz, column, defValue, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -513,10 +434,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void exists(final AsyncHandler<Boolean, Serializable> handler, final Class<T> clazz, @RpcAttachment final Serializable pk) {
|
||||
source.exists(handler, clazz, pk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -525,10 +444,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void exists(final AsyncHandler<Boolean, B> handler, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
source.exists(handler, clazz, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -537,10 +454,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void exists(final AsyncHandler<Boolean, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
source.exists(handler, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -549,10 +464,9 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable> void queryColumnSet(final AsyncHandler<HashSet<V>, String> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final String column, final Serializable key) {
|
||||
source.queryColumnSet(handler, selectedColumn, clazz, column, key);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -561,10 +475,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnSet(final AsyncHandler<HashSet<V>, B> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
source.queryColumnSet(handler, selectedColumn, clazz, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -573,10 +485,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable> void queryColumnSet(final AsyncHandler<HashSet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
source.queryColumnSet(handler, selectedColumn, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -585,10 +495,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable> void queryColumnList(final AsyncHandler<List<V>, Serializable> handler, final String selectedColumn, final Class<T> clazz, final String column, @RpcAttachment final Serializable key) {
|
||||
source.queryColumnList(handler, selectedColumn, clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -597,10 +505,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnList(final AsyncHandler<List<V>, B> handler, String selectedColumn, Class<T> clazz, @RpcAttachment final B bean) {
|
||||
source.queryColumnList(handler, selectedColumn, clazz, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -609,10 +515,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable> void queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
source.queryColumnList(handler, selectedColumn, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -621,10 +525,9 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnList(final AsyncHandler<List<V>, B> handler, String selectedColumn, Class<T> clazz, Flipper flipper, @RpcAttachment final B bean) {
|
||||
source.queryColumnList(handler, selectedColumn, clazz, flipper, bean);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -633,10 +536,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable> void queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
source.queryColumnList(handler, selectedColumn, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -645,10 +546,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnSheet(final AsyncHandler<Sheet<V>, B> handler, String selectedColumn, Class<T> clazz, Flipper flipper, @RpcAttachment B bean) {
|
||||
source.queryColumnSheet(handler, selectedColumn, clazz, flipper, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -657,10 +556,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, V extends Serializable> void queryColumnSheet(final AsyncHandler<Sheet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
source.queryColumnSheet(handler, selectedColumn, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -669,10 +566,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final String column, @RpcAttachment final Serializable key) {
|
||||
source.queryList(handler, clazz, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -681,10 +576,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, @RpcAttachment final B bean) {
|
||||
source.queryList(handler, clazz, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -693,10 +586,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, @RpcAttachment final FilterNode node) {
|
||||
source.queryList(handler, clazz, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -705,10 +596,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final B bean) {
|
||||
source.queryList(handler, clazz, selects, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -717,10 +606,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, @RpcAttachment final FilterNode node) {
|
||||
source.queryList(handler, clazz, selects, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -729,10 +616,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final Flipper flipper, final String column, @RpcAttachment final Serializable key) {
|
||||
source.queryList(handler, clazz, flipper, column, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -741,10 +626,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
source.queryList(handler, clazz, flipper, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -753,10 +636,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
source.queryList(handler, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -765,10 +646,9 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
source.queryList(handler, clazz, selects, flipper, bean);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -777,10 +657,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
source.queryList(handler, clazz, selects, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -789,10 +667,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
source.querySheet(handler, clazz, flipper, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -801,10 +677,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
source.querySheet(handler, clazz, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -813,10 +687,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T, B extends FilterBean> void querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final B bean) {
|
||||
source.querySheet(handler, clazz, selects, flipper, bean);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -825,10 +697,8 @@ public class DataSourceService implements DataSource, Service, AutoCloseable {
|
||||
}
|
||||
|
||||
@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;
|
||||
public <T> void querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, @RpcAttachment final FilterNode node) {
|
||||
source.querySheet(handler, clazz, selects, flipper, node);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,8 +8,8 @@ package org.redkale.service;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 所有Service的实现类不得声明为final, 允许远程模式的public方法都不能声明为final。
|
||||
* 注意: "$"是一个很特殊的Service.name值 。 被标记为@Resource(name = "$") 的Service的资源名与所属父Service的资源名一致。
|
||||
* 所有Service的实现类不得声明为final, 允许远程模式的public方法都不能声明为final。<br>
|
||||
* 注意: "$"是一个很特殊的Service.name值 。 被标记为@Resource(name = "$") 的Service的资源名与所属父Service的资源名一致。<br>
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* Service的资源类型
|
||||
@@ -19,6 +19,16 @@ import org.redkale.util.*;
|
||||
* 第二种方式需要在具体实现类上使用@ResourceType指明资源注入的类型。
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* 异步方法:
|
||||
* Service编写异步方法:
|
||||
* 1、异步方法有且仅有一个类型为AsyncHandler的参数。若参数类型为AsyncHandler子类,必须保证其子类可被继承且completed、failed可被重载且包含空参数的构造函数。
|
||||
* 2、异步方法返回类型必须是void。
|
||||
* 例如:
|
||||
* public void insertRecord(AsyncHandler<Integer, Record> handler, String name, @RpcAttachment Record record);
|
||||
*
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
@@ -46,14 +56,4 @@ public interface Service {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Service的接口版本号
|
||||
* <b>注: public方法的参数或返回类型或参数类型内部变更后改值必须进行改变</b>
|
||||
*
|
||||
* @return 接口版本号
|
||||
*/
|
||||
default int version() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,13 +70,13 @@ public class WebSocketNodeService extends WebSocketNode implements Service {
|
||||
|
||||
@Override
|
||||
public void connect(Serializable groupid, InetSocketAddress addr) {
|
||||
source.appendSetItem(groupid, addr);
|
||||
sncpNodes.appendSetItem(groupid, addr);
|
||||
if (finest) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + groupid + " connect from " + addr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(Serializable groupid, InetSocketAddress addr) {
|
||||
source.removeSetItem(groupid, addr);
|
||||
sncpNodes.removeSetItem(groupid, addr);
|
||||
if (finest) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + groupid + " disconnect from " + addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +53,11 @@ 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 void exists(final AsyncHandler<Boolean, K> handler, final K key);
|
||||
|
||||
public V get(final AsyncHandler<V, K> handler, final K key);
|
||||
public void 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 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);
|
||||
|
||||
@@ -69,9 +69,9 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
||||
|
||||
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 void 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 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);
|
||||
|
||||
@@ -81,8 +81,7 @@ public interface CacheSource<K extends Serializable, V extends Object> {
|
||||
|
||||
public void removeSetItem(final AsyncHandler<Void, K> handler, final K key, final V value);
|
||||
|
||||
default boolean isOpen(final AsyncHandler<Boolean, Void> handler) {
|
||||
default void isOpen(final AsyncHandler<Boolean, Void> handler) {
|
||||
if (handler != null) handler.completed(Boolean.TRUE, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,16 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p> 详情见: https://redkale.org
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public interface DataCacheListener {
|
||||
|
||||
public <T> void insertCache(Class<T> clazz, T... entitys);
|
||||
public <T> int insertCache(Class<T> clazz, T... entitys);
|
||||
|
||||
public <T> void updateCache(Class<T> clazz, T... entitys);
|
||||
public <T> int updateCache(Class<T> clazz, T... entitys);
|
||||
|
||||
public <T> void deleteCache(Class<T> clazz, Serializable... ids);
|
||||
public <T> int deleteCache(Class<T> clazz, Serializable... ids);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.*;
|
||||
import java.util.logging.*;
|
||||
import javax.annotation.Resource;
|
||||
import javax.xml.stream.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -25,13 +24,11 @@ import org.redkale.util.*;
|
||||
* @author zhangjx
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class DataDefaultSource implements DataSource, Function<Class, EntityInfo>, AutoCloseable {
|
||||
|
||||
public static final String DATASOURCE_CONFPATH = "DATASOURCE_CONFPATH";
|
||||
public final class DataJdbcSource implements DataSource, Resourcable, DataCacheListener, Function<Class, EntityInfo>, AutoCloseable {
|
||||
|
||||
private static final Flipper FLIPPER_ONE = new Flipper(1);
|
||||
|
||||
final Logger logger = Logger.getLogger(DataDefaultSource.class.getSimpleName());
|
||||
final Logger logger = Logger.getLogger(DataJdbcSource.class.getSimpleName());
|
||||
|
||||
final AtomicBoolean debug = new AtomicBoolean(logger.isLoggable(Level.FINEST));
|
||||
|
||||
@@ -41,124 +38,24 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
|
||||
final boolean cacheForbidden;
|
||||
|
||||
private final JDBCPoolSource readPool;
|
||||
private final PoolJdbcSource readPool;
|
||||
|
||||
private final JDBCPoolSource writePool;
|
||||
private final PoolJdbcSource writePool;
|
||||
|
||||
@Resource(name = "$")
|
||||
private DataCacheListener cacheListener;
|
||||
|
||||
private final BiFunction<DataSource, Class, List> fullloader = (s, t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||
|
||||
public DataDefaultSource() throws IOException {
|
||||
this("");
|
||||
}
|
||||
|
||||
public DataDefaultSource(final String unitName) throws IOException {
|
||||
this(unitName, System.getProperty(DATASOURCE_CONFPATH) == null
|
||||
? DataDefaultSource.class.getResource("/META-INF/persistence.xml")
|
||||
: new File(System.getProperty(DATASOURCE_CONFPATH)).toURI().toURL());
|
||||
}
|
||||
|
||||
public DataDefaultSource(final String unitName, URL url) throws IOException {
|
||||
if (url == null) url = this.getClass().getResource("/persistence.xml");
|
||||
InputStream in = url.openStream();
|
||||
Map<String, Properties> map = loadProperties(in);
|
||||
Properties readprop = null;
|
||||
Properties writeprop = null;
|
||||
if (unitName != null) {
|
||||
readprop = map.get(unitName);
|
||||
writeprop = readprop;
|
||||
if (readprop == null) {
|
||||
readprop = map.get(unitName + ".read");
|
||||
writeprop = map.get(unitName + ".write");
|
||||
}
|
||||
}
|
||||
if ((unitName == null || unitName.isEmpty()) || readprop == null) {
|
||||
String key = null;
|
||||
for (Map.Entry<String, Properties> en : map.entrySet()) {
|
||||
key = en.getKey();
|
||||
readprop = en.getValue();
|
||||
writeprop = readprop;
|
||||
break;
|
||||
}
|
||||
if (key != null && (key.endsWith(".read") || key.endsWith(".write"))) {
|
||||
if (key.endsWith(".read")) {
|
||||
writeprop = map.get(key.substring(0, key.lastIndexOf('.')) + ".write");
|
||||
} else {
|
||||
readprop = map.get(key.substring(0, key.lastIndexOf('.')) + ".read");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readprop == null) throw new RuntimeException("not found persistence properties (unit:" + unitName + ")");
|
||||
this.name = unitName;
|
||||
this.conf = url;
|
||||
this.readPool = new JDBCPoolSource(this, "read", readprop);
|
||||
this.writePool = new JDBCPoolSource(this, "write", writeprop);
|
||||
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
||||
}
|
||||
|
||||
public DataDefaultSource(String unitName, Properties readprop, Properties writeprop) {
|
||||
public DataJdbcSource(String unitName, Properties readprop, Properties writeprop) {
|
||||
this.name = unitName;
|
||||
this.conf = null;
|
||||
this.readPool = new JDBCPoolSource(this, "read", readprop);
|
||||
this.writePool = new JDBCPoolSource(this, "write", writeprop);
|
||||
this.readPool = new PoolJdbcSource(this, "read", readprop);
|
||||
this.writePool = new PoolJdbcSource(this, "write", writeprop);
|
||||
this.cacheForbidden = "NONE".equalsIgnoreCase(readprop.getProperty("shared-cache-mode"));
|
||||
}
|
||||
|
||||
public static Map<String, DataDefaultSource> create(final InputStream in) {
|
||||
Map<String, Properties> map = loadProperties(in);
|
||||
Map<String, Properties[]> maps = new HashMap<>();
|
||||
map.entrySet().stream().forEach((en) -> {
|
||||
if (en.getKey().endsWith(".read") || en.getKey().endsWith(".write")) {
|
||||
String key = en.getKey().substring(0, en.getKey().lastIndexOf('.'));
|
||||
if (maps.containsKey(key)) return;
|
||||
boolean read = en.getKey().endsWith(".read");
|
||||
Properties rp = read ? en.getValue() : map.get(key + ".read");
|
||||
Properties wp = read ? map.get(key + ".write") : en.getValue();
|
||||
maps.put(key, new Properties[]{rp, wp});
|
||||
} else {
|
||||
maps.put(en.getKey(), new Properties[]{en.getValue(), en.getValue()});
|
||||
}
|
||||
});
|
||||
Map<String, DataDefaultSource> result = new HashMap<>();
|
||||
maps.entrySet().stream().forEach((en) -> {
|
||||
result.put(en.getKey(), new DataDefaultSource(en.getKey(), en.getValue()[0], en.getValue()[1]));
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
static Map<String, Properties> loadProperties(final InputStream in0) {
|
||||
final Map<String, Properties> map = new LinkedHashMap();
|
||||
Properties result = new Properties();
|
||||
boolean flag = false;
|
||||
try (final InputStream in = in0) {
|
||||
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(in);
|
||||
while (reader.hasNext()) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
if ("persistence-unit".equalsIgnoreCase(reader.getLocalName())) {
|
||||
if (!result.isEmpty()) result = new Properties();
|
||||
map.put(reader.getAttributeValue(null, "name"), result);
|
||||
flag = true;
|
||||
} else if (flag && "property".equalsIgnoreCase(reader.getLocalName())) {
|
||||
String name = reader.getAttributeValue(null, "name");
|
||||
String value = reader.getAttributeValue(null, "value");
|
||||
if (name == null) continue;
|
||||
result.put(name, value);
|
||||
} else if (flag && "shared-cache-mode".equalsIgnoreCase(reader.getLocalName())) {
|
||||
result.put(reader.getLocalName(), reader.getElementText());
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public final String name() {
|
||||
public final String resourceName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -376,14 +273,17 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
return prestmt;
|
||||
}
|
||||
|
||||
public <T> void insertCache(Class<T> clazz, T... values) {
|
||||
if (values.length == 0) return;
|
||||
@Override
|
||||
public <T> int insertCache(Class<T> clazz, T... values) {
|
||||
if (values.length == 0) return 0;
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
final EntityCache<T> cache = info.getCache();
|
||||
if (cache == null) return;
|
||||
if (cache == null) return -1;
|
||||
int c = 0;
|
||||
for (T value : values) {
|
||||
cache.insert(value);
|
||||
c += cache.insert(value);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
//-------------------------deleteCache--------------------------
|
||||
@@ -423,10 +323,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int delete(final AsyncHandler<Integer, T[]> handler, final T... values) {
|
||||
public <T> void 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) {
|
||||
@@ -455,10 +354,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -510,10 +408,9 @@ 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) {
|
||||
public <T> void 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
|
||||
@@ -531,10 +428,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -574,6 +470,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int deleteCache(Class<T> clazz, Serializable... ids) {
|
||||
if (ids.length == 0) return 0;
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -623,10 +520,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int update(final AsyncHandler<Integer, T[]> handler, final T... values) {
|
||||
public <T> void 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) {
|
||||
@@ -721,10 +617,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -790,10 +685,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -874,10 +768,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -962,10 +855,9 @@ 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) {
|
||||
public <T> void 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -994,10 +886,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -1077,10 +968,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final String... columns) {
|
||||
public <T> void 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
|
||||
@@ -1098,10 +988,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -1167,10 +1056,9 @@ 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 String... columns) {
|
||||
public <T> void 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
|
||||
@@ -1188,10 +1076,9 @@ 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) {
|
||||
public <T> void 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) {
|
||||
@@ -1263,6 +1150,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> int updateCache(Class<T> clazz, T... values) {
|
||||
if (values.length == 0) return 0;
|
||||
final EntityInfo<T> info = loadEntityInfo(clazz);
|
||||
@@ -1296,10 +1184,9 @@ 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 String column) {
|
||||
public void 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
|
||||
@@ -1308,10 +1195,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends FilterBean> Number getNumberResult(final AsyncHandler<Number, B> handler, final Class entityClass, final FilterFunc func, final String column, final B bean) {
|
||||
public <B extends FilterBean> void 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
|
||||
@@ -1320,10 +1206,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number getNumberResult(final AsyncHandler<Number, FilterNode> handler, final Class entityClass, final FilterFunc func, final String column, final FilterNode node) {
|
||||
public void 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
|
||||
@@ -1332,10 +1217,9 @@ 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) {
|
||||
public void 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
|
||||
@@ -1344,8 +1228,8 @@ 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 FilterBean bean) {
|
||||
return getNumberResult(handler, entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterBean bean) {
|
||||
getNumberResult(handler, entityClass, func, defVal, column, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1354,10 +1238,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterFuncColumn[]> handler, final Class entityClass, final FilterFuncColumn... columns) {
|
||||
public <N extends Number> void 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
|
||||
@@ -1366,10 +1249,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <N extends Number, B extends FilterBean> void 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
|
||||
@@ -1437,10 +1319,9 @@ 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) {
|
||||
public <N extends Number> void 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
|
||||
@@ -1480,10 +1361,9 @@ 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) {
|
||||
public void 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-----------------------------
|
||||
@@ -1493,10 +1373,9 @@ 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) {
|
||||
public <T, K extends Serializable, N extends Number> void 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
|
||||
@@ -1505,8 +1384,8 @@ 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 FilterBean bean) {
|
||||
return queryColumnMap(handler, entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
|
||||
public <T, K extends Serializable, N extends Number> void queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterBean bean) {
|
||||
queryColumnMap(handler, entityClass, keyColumn, func, funcColumn, FilterNodeBean.createFilterNode(bean));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1548,10 +1427,9 @@ 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) {
|
||||
public <T, K extends Serializable, N extends Number> void 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----------------------------
|
||||
@@ -1570,10 +1448,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final Serializable pk) {
|
||||
public <T> void 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
|
||||
@@ -1609,10 +1486,9 @@ 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) {
|
||||
public <T> void 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
|
||||
@@ -1621,10 +1497,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final String column, final Serializable key) {
|
||||
public <T> void 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
|
||||
@@ -1633,10 +1508,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final B bean) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -1645,10 +1519,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final FilterNode node) {
|
||||
public <T> void 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
|
||||
@@ -1657,10 +1530,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -1696,10 +1568,9 @@ 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) {
|
||||
public <T> void 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
|
||||
@@ -1708,10 +1579,9 @@ 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 pk) {
|
||||
public <T> void 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
|
||||
@@ -1720,10 +1590,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> Serializable findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final B bean) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -1732,10 +1601,9 @@ 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 FilterNode node) {
|
||||
public <T> void 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
|
||||
@@ -1779,10 +1647,9 @@ 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) {
|
||||
public <T> void 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
|
||||
@@ -1791,10 +1658,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -1838,10 +1704,9 @@ 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) {
|
||||
public <T> void 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
|
||||
@@ -1879,10 +1744,9 @@ 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) {
|
||||
public <T> void 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
|
||||
@@ -1891,10 +1755,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> boolean exists(final AsyncHandler<Boolean, B> handler, final Class<T> clazz, final B bean) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -1932,10 +1795,9 @@ 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) {
|
||||
public <T> void 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----------------------------
|
||||
@@ -1945,10 +1807,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable> void 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
|
||||
@@ -1957,10 +1818,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable, B extends FilterBean> void 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
|
||||
@@ -1969,10 +1829,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable> void 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
|
||||
@@ -1981,10 +1840,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable> void 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
|
||||
@@ -1993,10 +1851,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable, B extends FilterBean> void 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
|
||||
@@ -2005,10 +1862,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable> void 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
|
||||
@@ -2017,10 +1873,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable, B extends FilterBean> void 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
|
||||
@@ -2029,10 +1884,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable> void 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2053,10 +1907,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable, B extends FilterBean> void 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
|
||||
@@ -2065,10 +1918,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, V extends Serializable> void 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) {
|
||||
@@ -2102,10 +1954,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final String column, final Serializable key) {
|
||||
public <T> void 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2123,10 +1974,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final B bean) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -2135,10 +1985,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final FilterNode node) {
|
||||
public <T> void 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2157,10 +2006,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -2169,10 +2017,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node) {
|
||||
public <T> void 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
|
||||
@@ -2181,10 +2028,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T> void 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
|
||||
@@ -2193,10 +2039,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -2205,10 +2050,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
public <T> void 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
|
||||
@@ -2217,10 +2061,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -2229,10 +2072,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T> void 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----------------------------
|
||||
@@ -2252,10 +2094,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -2264,10 +2105,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node) {
|
||||
public <T> void 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2287,10 +2127,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T, B extends FilterBean> void 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
|
||||
@@ -2299,10 +2138,9 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
@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) {
|
||||
public <T> void 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) {
|
||||
@@ -62,10 +62,9 @@ public interface DataSource {
|
||||
* @param handler 回调函数
|
||||
* @param values Entity对象
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int delete(final AsyncHandler<Integer, T[]> handler, final T... values);
|
||||
public <T> void delete(final AsyncHandler<Integer, T[]> handler, final T... values);
|
||||
|
||||
/**
|
||||
* 删除指定主键值的记录 <br>
|
||||
@@ -88,10 +87,9 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param ids 主键值
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int delete(final AsyncHandler<Integer, Serializable[]> handler, final Class<T> clazz, final Serializable... ids);
|
||||
public <T> void delete(final AsyncHandler<Integer, Serializable[]> handler, final Class<T> clazz, final Serializable... ids);
|
||||
|
||||
/**
|
||||
* 删除符合过滤条件的记录 <br>
|
||||
@@ -114,10 +112,9 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
public <T> void delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 删除符合过滤条件且指定最大影响条数的记录 <br>
|
||||
@@ -144,10 +141,9 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
public <T> void delete(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
|
||||
//------------------------update---------------------------
|
||||
/**
|
||||
@@ -175,10 +171,9 @@ public interface DataSource {
|
||||
* @param handler 回调函数
|
||||
* @param values Entity对象
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int update(final AsyncHandler<Integer, T[]> handler, final T... values);
|
||||
public <T> void update(final AsyncHandler<Integer, T[]> handler, final T... values);
|
||||
|
||||
/**
|
||||
* 更新单个记录的单个字段 <br>
|
||||
@@ -207,10 +202,9 @@ public interface DataSource {
|
||||
* @param column 待更新的字段名
|
||||
* @param value 更新值
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, final Serializable id, final String column, final Serializable value);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, final Serializable id, final String column, final Serializable value);
|
||||
|
||||
/**
|
||||
* 更新符合过滤条件记录的单个字段 <br>
|
||||
@@ -239,10 +233,9 @@ public interface DataSource {
|
||||
* @param value 更新值
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final String column, final Serializable value, final FilterNode node);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final String column, final Serializable value, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 更新指定主键值记录的部分字段 <br>
|
||||
@@ -269,10 +262,9 @@ public interface DataSource {
|
||||
* @param id 主键
|
||||
* @param values 更新字段
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, final Serializable id, final ColumnValue... values);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, Serializable> handler, final Class<T> clazz, final Serializable id, final ColumnValue... values);
|
||||
|
||||
/**
|
||||
* 更新符合过滤条件记录的部分字段 <br>
|
||||
@@ -301,10 +293,9 @@ public interface DataSource {
|
||||
* @param node 过滤条件
|
||||
* @param values 更新字段
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node, final ColumnValue... values);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node, final ColumnValue... values);
|
||||
|
||||
/**
|
||||
* 更新符合过滤条件的记录的指定字段 <br>
|
||||
@@ -335,10 +326,9 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param values 更新字段
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node, final Flipper flipper, final ColumnValue... values);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final Class<T> clazz, final FilterNode node, final Flipper flipper, final ColumnValue... values);
|
||||
|
||||
/**
|
||||
* 更新单个记录的指定字段 <br>
|
||||
@@ -363,9 +353,8 @@ public interface DataSource {
|
||||
* @param bean 待更新的Entity对象
|
||||
* @param columns 需更新的字段名
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final String... columns);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final String... columns);
|
||||
|
||||
/**
|
||||
* 更新符合过滤条件记录的指定字段 <br>
|
||||
@@ -392,10 +381,9 @@ public interface DataSource {
|
||||
* @param node 过滤条件
|
||||
* @param columns 需更新的字段名
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, final FilterNode node, final String... columns);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, final FilterNode node, final String... columns);
|
||||
|
||||
/**
|
||||
* 更新单个记录的指定字段 <br>
|
||||
@@ -420,10 +408,9 @@ public interface DataSource {
|
||||
* @param bean 待更新的Entity对象
|
||||
* @param selects 指定字段
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final SelectColumn selects);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, T> handler, final T bean, final SelectColumn selects);
|
||||
|
||||
/**
|
||||
* 更新符合过滤条件记录的指定字段 <br>
|
||||
@@ -450,10 +437,9 @@ public interface DataSource {
|
||||
* @param node 过滤条件
|
||||
* @param selects 指定字段
|
||||
*
|
||||
* @return 影响的记录条数
|
||||
*
|
||||
*/
|
||||
public <T> int updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, final FilterNode node, final SelectColumn selects);
|
||||
public <T> void updateColumn(final AsyncHandler<Integer, FilterNode> handler, final T bean, final FilterNode node, final SelectColumn selects);
|
||||
|
||||
//############################################# 查询接口 #############################################
|
||||
//-----------------------getXXXXResult-----------------------------
|
||||
@@ -480,10 +466,9 @@ public interface DataSource {
|
||||
* @param func 聚合函数
|
||||
* @param column 指定字段
|
||||
*
|
||||
* @return 聚合结果
|
||||
*
|
||||
*/
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final String column);
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final String column);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果, 无结果返回null <br>
|
||||
@@ -511,10 +496,9 @@ public interface DataSource {
|
||||
* @param column 指定字段
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 聚合结果
|
||||
*
|
||||
*/
|
||||
public <B extends FilterBean> Number getNumberResult(final AsyncHandler<Number, B> handler, final Class entityClass, final FilterFunc func, final String column, final B bean);
|
||||
public <B extends FilterBean> void getNumberResult(final AsyncHandler<Number, B> handler, final Class entityClass, final FilterFunc func, final String column, final B bean);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果, 无结果返回null <br>
|
||||
@@ -541,10 +525,9 @@ public interface DataSource {
|
||||
* @param column 指定字段
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 聚合结果
|
||||
*
|
||||
*/
|
||||
public Number getNumberResult(final AsyncHandler<Number, FilterNode> handler, final Class entityClass, final FilterFunc func, final String column, final FilterNode node);
|
||||
public void getNumberResult(final AsyncHandler<Number, FilterNode> handler, final Class entityClass, final FilterFunc func, final String column, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果, 无结果返回默认值 <br>
|
||||
@@ -571,9 +554,8 @@ public interface DataSource {
|
||||
* @param defVal 默认值
|
||||
* @param column 指定字段
|
||||
*
|
||||
* @return 聚合结果
|
||||
*/
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column);
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果, 无结果返回默认值 <br>
|
||||
@@ -602,9 +584,8 @@ public interface DataSource {
|
||||
* @param column 指定字段
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 聚合结果
|
||||
*/
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterBean bean);
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterBean bean);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果, 无结果返回默认值 <br>
|
||||
@@ -633,10 +614,9 @@ public interface DataSource {
|
||||
* @param column 指定字段
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 聚合结果
|
||||
*
|
||||
*/
|
||||
public Number getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterNode node);
|
||||
public void getNumberResult(final AsyncHandler<Number, String> handler, final Class entityClass, final FilterFunc func, final Number defVal, final String column, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果Map <br>
|
||||
@@ -661,9 +641,8 @@ public interface DataSource {
|
||||
* @param entityClass Entity类
|
||||
* @param columns 聚合字段
|
||||
*
|
||||
* @return 聚合结果Map
|
||||
*/
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterFuncColumn[]> handler, final Class entityClass, final FilterFuncColumn... columns);
|
||||
public <N extends Number> void getNumberMap(final AsyncHandler<Map<String, N>, FilterFuncColumn[]> handler, final Class entityClass, final FilterFuncColumn... columns);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果Map <br>
|
||||
@@ -691,9 +670,8 @@ public interface DataSource {
|
||||
* @param bean 过滤条件
|
||||
* @param columns 聚合字段
|
||||
*
|
||||
* @return 聚合结果Map
|
||||
*/
|
||||
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);
|
||||
public <N extends Number, B extends FilterBean> void getNumberMap(final AsyncHandler<Map<String, N>, B> handler, final Class entityClass, final B bean, final FilterFuncColumn... columns);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件记录的聚合结果Map <br>
|
||||
@@ -720,9 +698,8 @@ public interface DataSource {
|
||||
* @param node 过滤条件
|
||||
* @param columns 聚合字段
|
||||
*
|
||||
* @return 聚合结果Map
|
||||
*/
|
||||
public <N extends Number> Map<String, N> getNumberMap(final AsyncHandler<Map<String, N>, FilterNode> handler, final Class entityClass, final FilterNode node, final FilterFuncColumn... columns);
|
||||
public <N extends Number> void getNumberMap(final AsyncHandler<Map<String, N>, FilterNode> handler, final Class entityClass, final FilterNode node, final FilterFuncColumn... columns);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的GROUP BY聚合结果Map <br>
|
||||
@@ -755,9 +732,8 @@ public interface DataSource {
|
||||
* @param func 聚合函数
|
||||
* @param funcColumn 聚合字段
|
||||
*
|
||||
* @return 聚合结果Map
|
||||
*/
|
||||
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);
|
||||
public <T, K extends Serializable, N extends Number> void queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的GROUP BY聚合结果Map <br>
|
||||
@@ -792,9 +768,8 @@ public interface DataSource {
|
||||
* @param funcColumn 聚合字段
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 聚合结果Map
|
||||
*/
|
||||
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);
|
||||
public <T, K extends Serializable, N extends Number> void queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterBean bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的GROUP BY聚合结果Map <br>
|
||||
@@ -829,9 +804,8 @@ public interface DataSource {
|
||||
* @param funcColumn 聚合字段
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 聚合结果Map
|
||||
*/
|
||||
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);
|
||||
public <T, K extends Serializable, N extends Number> void queryColumnMap(final AsyncHandler<Map<K, N>, String> handler, final Class<T> entityClass, final String keyColumn, final FilterFunc func, final String funcColumn, final FilterNode node);
|
||||
|
||||
//-----------------------find----------------------------
|
||||
/**
|
||||
@@ -855,9 +829,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param pk 主键值
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final Serializable pk);
|
||||
public <T> void find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final Serializable pk);
|
||||
|
||||
/**
|
||||
* 获取指定主键值的单个记录, 返回null表示不存在值 <br>
|
||||
@@ -882,9 +855,8 @@ public interface DataSource {
|
||||
* @param selects 指定字段
|
||||
* @param pk 主键值
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final SelectColumn selects, final Serializable pk);
|
||||
public <T> void find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final SelectColumn selects, final Serializable pk);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录, 返回null表示不存在值 <br>
|
||||
@@ -909,9 +881,8 @@ public interface DataSource {
|
||||
* @param column 过滤字段名
|
||||
* @param key 过滤字段值
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T> T find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final String column, final Serializable key);
|
||||
public <T> void find(final AsyncHandler<T, Serializable> handler, final Class<T> clazz, final String column, final Serializable key);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录, 返回null表示不存在值 <br>
|
||||
@@ -935,9 +906,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final B bean);
|
||||
public <T, B extends FilterBean> void find(final AsyncHandler<T, B> handler, final Class<T> clazz, final B bean);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录, 返回null表示不存在值 <br>
|
||||
@@ -960,9 +930,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
public <T> void find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录, 返回null表示不存在值 <br>
|
||||
@@ -988,9 +957,8 @@ public interface DataSource {
|
||||
* @param selects 指定字段
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T, B extends FilterBean> T find(final AsyncHandler<T, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean);
|
||||
public <T, B extends FilterBean> void find(final AsyncHandler<T, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录, 返回null表示不存在值 <br>
|
||||
@@ -1015,9 +983,8 @@ public interface DataSource {
|
||||
* @param selects 指定字段
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity对象
|
||||
*/
|
||||
public <T> T find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node);
|
||||
public <T> void find(final AsyncHandler<T, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录的单个字段值, 返回null表示不存在值 <br>
|
||||
@@ -1042,9 +1009,8 @@ public interface DataSource {
|
||||
* @param column 字段名
|
||||
* @param pk 主键值
|
||||
*
|
||||
* @return 字段值
|
||||
*/
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable pk);
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable pk);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录的单个字段值, 返回null表示不存在值 <br>
|
||||
@@ -1070,9 +1036,8 @@ public interface DataSource {
|
||||
* @param column 字段名
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 字段值
|
||||
*/
|
||||
public <T, B extends FilterBean> Serializable findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final B bean);
|
||||
public <T, B extends FilterBean> void findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final B bean);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录的单个字段值, 返回null表示不存在值 <br>
|
||||
@@ -1097,9 +1062,8 @@ public interface DataSource {
|
||||
* @param column 字段名
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 字段值
|
||||
*/
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final FilterNode node);
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录的单个字段值, 不存在值则返回默认值 <br>
|
||||
@@ -1126,9 +1090,8 @@ public interface DataSource {
|
||||
* @param defValue 默认值
|
||||
* @param pk 主键值
|
||||
*
|
||||
* @return 字段值
|
||||
*/
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable defValue, final Serializable pk);
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, Serializable> handler, final Class<T> clazz, final String column, final Serializable defValue, final Serializable pk);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录的单个字段值, 不存在值则返回默认值 <br>
|
||||
@@ -1156,9 +1119,8 @@ public interface DataSource {
|
||||
* @param defValue 默认值
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 字段值
|
||||
*/
|
||||
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);
|
||||
public <T, B extends FilterBean> void findColumn(final AsyncHandler<Serializable, B> handler, final Class<T> clazz, final String column, final Serializable defValue, final B bean);
|
||||
|
||||
/**
|
||||
* 获取符合过滤条件单个记录的单个字段值, 不存在值则返回默认值 <br>
|
||||
@@ -1185,9 +1147,8 @@ public interface DataSource {
|
||||
* @param defValue 默认值
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 字段值
|
||||
*/
|
||||
public <T> Serializable findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final Serializable defValue, final FilterNode node);
|
||||
public <T> void findColumn(final AsyncHandler<Serializable, FilterNode> handler, final Class<T> clazz, final String column, final Serializable defValue, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 判断是否存在主键值的记录 <br>
|
||||
@@ -1210,9 +1171,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param pk 主键值
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
public <T> boolean exists(final AsyncHandler<Boolean, Serializable> handler, final Class<T> clazz, final Serializable pk);
|
||||
public <T> void exists(final AsyncHandler<Boolean, Serializable> handler, final Class<T> clazz, final Serializable pk);
|
||||
|
||||
/**
|
||||
* 判断是否存在符合过滤条件的记录 <br>
|
||||
@@ -1236,9 +1196,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
public <T, B extends FilterBean> boolean exists(final AsyncHandler<Boolean, B> handler, final Class<T> clazz, final B bean);
|
||||
public <T, B extends FilterBean> void exists(final AsyncHandler<Boolean, B> handler, final Class<T> clazz, final B bean);
|
||||
|
||||
/**
|
||||
* 判断是否存在符合过滤条件的记录 <br>
|
||||
@@ -1261,9 +1220,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 是否存在
|
||||
*/
|
||||
public <T> boolean exists(final AsyncHandler<Boolean, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
public <T> void exists(final AsyncHandler<Boolean, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
|
||||
//-----------------------list set----------------------------
|
||||
/**
|
||||
@@ -1293,9 +1251,8 @@ public interface DataSource {
|
||||
* @param column 过滤字段名
|
||||
* @param key 过滤字段值
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
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);
|
||||
public <T, V extends Serializable> void queryColumnSet(final AsyncHandler<HashSet<V>, String> handler, final String selectedColumn, final Class<T> clazz, final String column, final Serializable key);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段Set集合 <br>
|
||||
@@ -1323,9 +1280,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
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);
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnSet(final AsyncHandler<HashSet<V>, B> handler, final String selectedColumn, final Class<T> clazz, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段Set集合 <br>
|
||||
@@ -1352,9 +1308,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
public <T, V extends Serializable> HashSet<V> queryColumnSet(final AsyncHandler<HashSet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final FilterNode node);
|
||||
public <T, V extends Serializable> void queryColumnSet(final AsyncHandler<HashSet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段List集合 <br>
|
||||
@@ -1383,9 +1338,8 @@ public interface DataSource {
|
||||
* @param column 过滤字段名
|
||||
* @param key 过滤字段值
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
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);
|
||||
public <T, V extends Serializable> void queryColumnList(final AsyncHandler<List<V>, Serializable> handler, final String selectedColumn, final Class<T> clazz, final String column, final Serializable key);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段List集合 <br>
|
||||
@@ -1413,9 +1367,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
public <T, V extends Serializable, B extends FilterBean> List<V> queryColumnList(final AsyncHandler<List<V>, B> handler, final String selectedColumn, final Class<T> clazz, final B bean);
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnList(final AsyncHandler<List<V>, B> handler, final String selectedColumn, final Class<T> clazz, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段List集合 <br>
|
||||
@@ -1442,9 +1395,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final FilterNode node);
|
||||
public <T, V extends Serializable> void queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段List集合 <br>
|
||||
@@ -1474,9 +1426,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
public <T, V extends Serializable, B extends FilterBean> List<V> queryColumnList(final AsyncHandler<List<V>, B> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnList(final AsyncHandler<List<V>, B> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段List集合 <br>
|
||||
@@ -1505,9 +1456,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
public <T, V extends Serializable> List<V> queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
public <T, V extends Serializable> void queryColumnList(final AsyncHandler<List<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段Sheet集合 <br>
|
||||
@@ -1537,9 +1487,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
public <T, V extends Serializable, B extends FilterBean> Sheet<V> queryColumnSheet(final AsyncHandler<Sheet<V>, B> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
public <T, V extends Serializable, B extends FilterBean> void queryColumnSheet(final AsyncHandler<Sheet<V>, B> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的某个字段Sheet集合 <br>
|
||||
@@ -1568,9 +1517,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return 字段值的集合
|
||||
*/
|
||||
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);
|
||||
public <T, V extends Serializable> void queryColumnSheet(final AsyncHandler<Sheet<V>, FilterNode> handler, final String selectedColumn, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1595,9 +1543,8 @@ public interface DataSource {
|
||||
* @param column 过滤字段名
|
||||
* @param key 过滤字段值
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final String column, final Serializable key);
|
||||
public <T> void queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final String column, final Serializable key);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1621,9 +1568,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final B bean);
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1646,9 +1592,8 @@ public interface DataSource {
|
||||
* @param clazz Entity类
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1674,9 +1619,8 @@ public interface DataSource {
|
||||
* @param selects 指定字段
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean);
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1701,9 +1645,8 @@ public interface DataSource {
|
||||
* @param selects 指定字段
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node);
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1730,9 +1673,8 @@ public interface DataSource {
|
||||
* @param column 过滤字段名
|
||||
* @param key 过滤字段值
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final Flipper flipper, final String column, final Serializable key);
|
||||
public <T> void queryList(final AsyncHandler<List<T>, Serializable> handler, final Class<T> clazz, final Flipper flipper, final String column, final Serializable key);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1758,9 +1700,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T, B extends FilterBean> List<T> queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1787,9 +1728,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1817,9 +1757,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
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);
|
||||
public <T, B extends FilterBean> void queryList(final AsyncHandler<List<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的List集合 <br>
|
||||
@@ -1846,9 +1785,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> List<T> queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||
public <T> void queryList(final AsyncHandler<List<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||
|
||||
//-----------------------sheet----------------------------
|
||||
/**
|
||||
@@ -1875,9 +1813,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T, B extends FilterBean> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
public <T, B extends FilterBean> void querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final Flipper flipper, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的Sheet集合 <br>
|
||||
@@ -1902,9 +1839,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
public <T> void querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final Flipper flipper, final FilterNode node);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的Sheet集合 <br>
|
||||
@@ -1932,9 +1868,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param bean 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
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);
|
||||
public <T, B extends FilterBean> void querySheet(final AsyncHandler<Sheet<T>, B> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final B bean);
|
||||
|
||||
/**
|
||||
* 查询符合过滤条件记录的Sheet集合 <br>
|
||||
@@ -1961,9 +1896,8 @@ public interface DataSource {
|
||||
* @param flipper 翻页对象
|
||||
* @param node 过滤条件
|
||||
*
|
||||
* @return Entity的集合
|
||||
*/
|
||||
public <T> Sheet<T> querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||
public <T> void querySheet(final AsyncHandler<Sheet<T>, FilterNode> handler, final Class<T> clazz, final SelectColumn selects, final Flipper flipper, final FilterNode node);
|
||||
|
||||
//-----------------------direct----------------------------
|
||||
/**
|
||||
|
||||
136
src/org/redkale/source/DataSources.java
Normal file
136
src/org/redkale/source/DataSources.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* 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.source;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import javax.xml.stream.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public final class DataSources {
|
||||
|
||||
public static final String DATASOURCE_CONFPATH = "DATASOURCE_CONFPATH";
|
||||
|
||||
public static final String JDBC_DATASOURCE_CLASS = "javax.persistence.datasource";
|
||||
|
||||
public static final String JDBC_CONNECTIONSMAX = "javax.persistence.connections.limit";
|
||||
|
||||
public static final String JDBC_CONTAIN_SQLTEMPLATE = "javax.persistence.contain.sqltemplate";
|
||||
|
||||
public static final String JDBC_NOTCONTAIN_SQLTEMPLATE = "javax.persistence.notcontain.sqltemplate";
|
||||
|
||||
public static final String JDBC_TABLENOTEXIST_SQLSTATES = "javax.persistence.tablenotexist.sqlstates";
|
||||
|
||||
public static final String JDBC_TABLECOPY_SQLTEMPLATE = "javax.persistence.tablecopy.sqltemplate";
|
||||
|
||||
public static final String JDBC_URL = "javax.persistence.jdbc.url";
|
||||
|
||||
public static final String JDBC_USER = "javax.persistence.jdbc.user";
|
||||
|
||||
public static final String JDBC_PWD = "javax.persistence.jdbc.password";
|
||||
|
||||
public static final String JDBC_DRIVER = "javax.persistence.jdbc.driver";
|
||||
|
||||
public static final String JDBC_SOURCE = "javax.persistence.jdbc.source";
|
||||
|
||||
private DataSources() {
|
||||
}
|
||||
|
||||
public static DataSource createDataSource(final String unitName) throws IOException {
|
||||
return createDataSource(unitName, System.getProperty(DATASOURCE_CONFPATH) == null
|
||||
? DataJdbcSource.class.getResource("/META-INF/persistence.xml")
|
||||
: new File(System.getProperty(DATASOURCE_CONFPATH)).toURI().toURL());
|
||||
}
|
||||
|
||||
public static DataSource createDataSource(final String unitName, URL url) throws IOException {
|
||||
if (url == null) url = DataSources.class.getResource("/persistence.xml");
|
||||
InputStream in = url.openStream();
|
||||
if (in == null) return null;
|
||||
Map<String, Properties> map = loadPersistenceXml(in);
|
||||
Properties readprop = null;
|
||||
Properties writeprop = null;
|
||||
if (unitName != null) {
|
||||
readprop = map.get(unitName);
|
||||
writeprop = readprop;
|
||||
if (readprop == null) {
|
||||
readprop = map.get(unitName + ".read");
|
||||
writeprop = map.get(unitName + ".write");
|
||||
}
|
||||
}
|
||||
if ((unitName == null || unitName.isEmpty()) || readprop == null) {
|
||||
String key = null;
|
||||
for (Map.Entry<String, Properties> en : map.entrySet()) {
|
||||
key = en.getKey();
|
||||
readprop = en.getValue();
|
||||
writeprop = readprop;
|
||||
break;
|
||||
}
|
||||
if (key != null && (key.endsWith(".read") || key.endsWith(".write"))) {
|
||||
if (key.endsWith(".read")) {
|
||||
writeprop = map.get(key.substring(0, key.lastIndexOf('.')) + ".write");
|
||||
} else {
|
||||
readprop = map.get(key.substring(0, key.lastIndexOf('.')) + ".read");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readprop == null) throw new IOException("Cannot find (resource.name = '" + unitName + "') DataSource");
|
||||
String impl = readprop.getProperty(JDBC_DATASOURCE_CLASS, DataJdbcSource.class.getName());
|
||||
if (DataJdbcSource.class.getName().equals(impl)) return new DataJdbcSource(unitName, readprop, writeprop);
|
||||
try {
|
||||
Class ds = Class.forName(impl);
|
||||
for (Constructor d : ds.getConstructors()) {
|
||||
Class<?>[] paramtypes = d.getParameterTypes();
|
||||
if (paramtypes.length == 1 && paramtypes[0] == Properties.class) {
|
||||
return (DataSource) d.newInstance(readprop);
|
||||
} else if (paramtypes.length == 2 && paramtypes[0] == String.class && paramtypes[1] == Properties.class) {
|
||||
return (DataSource) d.newInstance(unitName, readprop);
|
||||
} else if (paramtypes.length == 3 && paramtypes[0] == String.class && paramtypes[1] == Properties.class && paramtypes[2] == Properties.class) {
|
||||
return (DataSource) d.newInstance(unitName, readprop, writeprop);
|
||||
}
|
||||
}
|
||||
throw new IOException("DataSource impl class (" + impl + ") have no Constructor by (Properties prop) or (String name, Properties prop) or (String name, Properties readprop, Propertieswriteprop)");
|
||||
} catch (IOException ex) {
|
||||
throw ex;
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
static Map<String, Properties> loadPersistenceXml(final InputStream in0) {
|
||||
final Map<String, Properties> map = new LinkedHashMap();
|
||||
Properties result = new Properties();
|
||||
boolean flag = false;
|
||||
try (final InputStream in = in0) {
|
||||
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(in);
|
||||
while (reader.hasNext()) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
if ("persistence-unit".equalsIgnoreCase(reader.getLocalName())) {
|
||||
if (!result.isEmpty()) result = new Properties();
|
||||
map.put(reader.getAttributeValue(null, "name"), result);
|
||||
flag = true;
|
||||
} else if (flag && "property".equalsIgnoreCase(reader.getLocalName())) {
|
||||
String name = reader.getAttributeValue(null, "name");
|
||||
String value = reader.getAttributeValue(null, "value");
|
||||
if (name == null) continue;
|
||||
result.put(name, value);
|
||||
} else if (flag && "shared-cache-mode".equalsIgnoreCase(reader.getLocalName())) {
|
||||
result.put(reader.getLocalName(), reader.getElementText());
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -425,14 +425,16 @@ public final class EntityCache<T> {
|
||||
return new Sheet<>(total, rs);
|
||||
}
|
||||
|
||||
public void insert(T value) {
|
||||
if (value == null) return;
|
||||
public int insert(T value) {
|
||||
if (value == null) return 0;
|
||||
final T rs = newReproduce.apply(this.creator.create(), value); //确保同一主键值的map与list中的对象必须共用。
|
||||
T old = this.map.put(this.primary.get(rs), rs);
|
||||
if (old == null) {
|
||||
this.list.add(rs);
|
||||
return 1;
|
||||
} else {
|
||||
logger.log(Level.WARNING, this.type + " cache repeat insert data: " + value);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -304,11 +304,11 @@ public final class EntityInfo<T> {
|
||||
this.cache = null;
|
||||
}
|
||||
if (conf == null) conf = new Properties();
|
||||
this.containSQL = conf.getProperty(JDBCPoolSource.JDBC_CONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) > 0");
|
||||
this.notcontainSQL = conf.getProperty(JDBCPoolSource.JDBC_NOTCONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) = 0");
|
||||
this.containSQL = conf.getProperty(DataSources.JDBC_CONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) > 0");
|
||||
this.notcontainSQL = conf.getProperty(DataSources.JDBC_NOTCONTAIN_SQLTEMPLATE, "LOCATE(${keystr}, ${column}) = 0");
|
||||
|
||||
this.tablenotexistSqlstates = ";" + conf.getProperty(JDBCPoolSource.JDBC_TABLENOTEXIST_SQLSTATES, "42000;42S02") + ";";
|
||||
this.tablecopySQL = conf.getProperty(JDBCPoolSource.JDBC_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} LIKE ${oldtable}");
|
||||
this.tablenotexistSqlstates = ";" + conf.getProperty(DataSources.JDBC_TABLENOTEXIST_SQLSTATES, "42000;42S02") + ";";
|
||||
this.tablecopySQL = conf.getProperty(DataSources.JDBC_TABLECOPY_SQLTEMPLATE, "CREATE TABLE ${newtable} LIKE ${oldtable}");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -659,6 +659,8 @@ public final class EntityInfo<T> {
|
||||
o = ((Number) o).byteValue();
|
||||
} else if (t == char.class) {
|
||||
o = (char) ((Number) o).intValue();
|
||||
} else if (t == boolean.class) {
|
||||
o = (Boolean) o;
|
||||
}
|
||||
} else if (t == int.class) {
|
||||
o = 0;
|
||||
|
||||
@@ -280,6 +280,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
}
|
||||
|
||||
private static boolean needSplit(final FilterExpress express, final Object val0) {
|
||||
if(val0 == null) return false;
|
||||
boolean items = express != IN && express != NOTIN; //是否数组集合的表达式
|
||||
if (!items) {
|
||||
if (val0.getClass().isArray()) {
|
||||
@@ -1709,7 +1710,7 @@ public class FilterNode { //FilterNode 不能实现Serializable接口, 否则
|
||||
protected StringBuilder toString(final String prefix) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringBuilder element = toElementString(prefix);
|
||||
boolean more = element.length() > 0 && this.nodes != null;
|
||||
boolean more = element != null && element.length() > 0 && this.nodes != null;
|
||||
if (more) sb.append('(');
|
||||
sb.append(element);
|
||||
if (this.nodes != null) {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
*/
|
||||
package org.redkale.source;
|
||||
|
||||
import static org.redkale.source.DataDefaultSource.*;
|
||||
import java.io.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -17,6 +16,7 @@ import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.logging.Level;
|
||||
import javax.sql.*;
|
||||
import static org.redkale.source.DataSources.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,29 +25,9 @@ import javax.sql.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class JDBCPoolSource {
|
||||
public class PoolJdbcSource {
|
||||
|
||||
static final String JDBC_CONNECTIONSMAX = "javax.persistence.connections.limit";
|
||||
|
||||
static final String JDBC_CONTAIN_SQLTEMPLATE = "javax.persistence.contain.sqltemplate";
|
||||
|
||||
static final String JDBC_NOTCONTAIN_SQLTEMPLATE = "javax.persistence.notcontain.sqltemplate";
|
||||
|
||||
static final String JDBC_TABLENOTEXIST_SQLSTATES = "javax.persistence.tablenotexist.sqlstates";
|
||||
|
||||
static final String JDBC_TABLECOPY_SQLTEMPLATE = "javax.persistence.tablecopy.sqltemplate";
|
||||
|
||||
static final String JDBC_URL = "javax.persistence.jdbc.url";
|
||||
|
||||
static final String JDBC_USER = "javax.persistence.jdbc.user";
|
||||
|
||||
static final String JDBC_PWD = "javax.persistence.jdbc.password";
|
||||
|
||||
static final String JDBC_DRIVER = "javax.persistence.jdbc.driver";
|
||||
|
||||
static final String JDBC_SOURCE = "javax.persistence.jdbc.source";
|
||||
|
||||
private static final Map<String, AbstractMap.SimpleEntry<WatchService, List<WeakReference<JDBCPoolSource>>>> maps = new HashMap<>();
|
||||
private static final Map<String, AbstractMap.SimpleEntry<WatchService, List<WeakReference<PoolJdbcSource>>>> maps = new HashMap<>();
|
||||
|
||||
private final AtomicLong usingCounter = new AtomicLong();
|
||||
|
||||
@@ -63,7 +43,7 @@ public class JDBCPoolSource {
|
||||
|
||||
private final ConnectionEventListener listener;
|
||||
|
||||
private final DataDefaultSource dataSource;
|
||||
private final DataJdbcSource dataSource;
|
||||
|
||||
private final String stype; // "" 或 "read" 或 "write"
|
||||
|
||||
@@ -77,7 +57,7 @@ public class JDBCPoolSource {
|
||||
|
||||
final Properties props;
|
||||
|
||||
public JDBCPoolSource(DataDefaultSource source, String stype, Properties prop) {
|
||||
public PoolJdbcSource(DataJdbcSource source, String stype, Properties prop) {
|
||||
this.dataSource = source;
|
||||
this.stype = stype;
|
||||
this.props = prop;
|
||||
@@ -151,7 +131,7 @@ public class JDBCPoolSource {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.MysqlConnectionPoolDataSource");
|
||||
source = "com.mysql.cj.jdbc.MysqlConnectionPoolDataSource";
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
source = "com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource";
|
||||
}
|
||||
break;
|
||||
@@ -210,13 +190,13 @@ public class JDBCPoolSource {
|
||||
final File f = new File(file);
|
||||
if (!f.isFile() || !f.canRead()) return;
|
||||
synchronized (maps) {
|
||||
AbstractMap.SimpleEntry<WatchService, List<WeakReference<JDBCPoolSource>>> entry = maps.get(file);
|
||||
AbstractMap.SimpleEntry<WatchService, List<WeakReference<PoolJdbcSource>>> entry = maps.get(file);
|
||||
if (entry != null) {
|
||||
entry.getValue().add(new WeakReference<>(this));
|
||||
return;
|
||||
}
|
||||
final WatchService watcher = f.toPath().getFileSystem().newWatchService();
|
||||
final List<WeakReference<JDBCPoolSource>> list = new CopyOnWriteArrayList<>();
|
||||
final List<WeakReference<PoolJdbcSource>> list = new CopyOnWriteArrayList<>();
|
||||
Thread watchThread = new Thread() {
|
||||
|
||||
@Override
|
||||
@@ -230,12 +210,12 @@ public class JDBCPoolSource {
|
||||
Thread.sleep(2000L);
|
||||
if (d == f.lastModified()) break;
|
||||
}
|
||||
final Map<String, Properties> m = loadProperties(new FileInputStream(file));
|
||||
final Map<String, Properties> m = loadPersistenceXml(new FileInputStream(file));
|
||||
key.pollEvents().stream().forEach((event) -> {
|
||||
if (event.kind() != ENTRY_MODIFY) return;
|
||||
if (!((Path) event.context()).toFile().getName().equals(f.getName())) return;
|
||||
for (WeakReference<JDBCPoolSource> ref : list) {
|
||||
JDBCPoolSource pool = ref.get();
|
||||
for (WeakReference<PoolJdbcSource> ref : list) {
|
||||
PoolJdbcSource pool = ref.get();
|
||||
if (pool == null) continue;
|
||||
try {
|
||||
Properties property = m.get(pool.dataSource.name);
|
||||
@@ -46,33 +46,6 @@ public interface AsyncHandler<V, A> extends CompletionHandler<V, A> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 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 对象
|
||||
*
|
||||
|
||||
@@ -104,6 +104,7 @@ public interface Creator<T> {
|
||||
if (constructorDesc != null && !constructorDesc.equals(desc)) return null;
|
||||
if (this.started) return null;
|
||||
this.started = true;
|
||||
//返回的List中参数列表可能会比方法参数量多,因为方法内的临时变量也会存入list中, 所以需要list的元素集合比方法的参数多
|
||||
return new MethodVisitor(Opcodes.ASM5) {
|
||||
@Override
|
||||
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
|
||||
@@ -113,7 +114,7 @@ public interface Creator<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, String constructorDesc) {
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, int paramcount, String constructorDesc) {
|
||||
String n = clazz.getName();
|
||||
InputStream in = clazz.getResourceAsStream(n.substring(n.lastIndexOf('.') + 1) + ".class");
|
||||
if (in == null) return null;
|
||||
@@ -131,10 +132,18 @@ public interface Creator<T> {
|
||||
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()]));
|
||||
if (paramcount == fieldnames.size()) {
|
||||
return getConstructorField(clazz, paramcount, fieldnames.toArray(new String[fieldnames.size()]));
|
||||
} else {
|
||||
String[] fs = new String[paramcount];
|
||||
for (int i = 0; i < fs.length; i++) {
|
||||
fs[i] = fieldnames.get(i);
|
||||
}
|
||||
return getConstructorField(clazz, paramcount, fs);
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, String[] names) {
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, int paramcount, String[] names) {
|
||||
SimpleEntry<String, Class>[] se = new SimpleEntry[names.length];
|
||||
for (int i = 0; i < names.length; i++) { //查询参数名对应的Field
|
||||
try {
|
||||
@@ -147,7 +156,7 @@ public interface Creator<T> {
|
||||
return se;
|
||||
}
|
||||
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, Parameter[] params) {
|
||||
public static SimpleEntry<String, Class>[] getConstructorField(Class clazz, int paramcount, Parameter[] params) {
|
||||
SimpleEntry<String, Class>[] se = new SimpleEntry[params.length];
|
||||
for (int i = 0; i < params.length; i++) { //查询参数名对应的Field
|
||||
try {
|
||||
@@ -213,7 +222,7 @@ public interface Creator<T> {
|
||||
}
|
||||
try {
|
||||
return (Creator) Class.forName(newDynName.replace('/', '.')).newInstance();
|
||||
} catch (Exception ex) {
|
||||
} catch (Throwable ex) {
|
||||
}
|
||||
|
||||
Constructor<T> constructor0 = null;
|
||||
@@ -232,7 +241,7 @@ public interface Creator<T> {
|
||||
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());
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, c.getParameterCount(), cp.value());
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
@@ -250,7 +259,7 @@ public interface Creator<T> {
|
||||
//优先参数最多的构造函数
|
||||
cs.sort((o1, o2) -> o2.getParameterCount() - o1.getParameterCount());
|
||||
for (Constructor c : cs) {
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, Type.getConstructorDescriptor(c));
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, c.getParameterCount(), Type.getConstructorDescriptor(c));
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
@@ -263,7 +272,7 @@ public interface Creator<T> {
|
||||
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());
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, c.getParameterCount(), cp.value());
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
@@ -282,7 +291,7 @@ public interface Creator<T> {
|
||||
//优先参数最多的构造函数
|
||||
cs.sort((o1, o2) -> o2.getParameterCount() - o1.getParameterCount());
|
||||
for (Constructor c : cs) {
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, Type.getConstructorDescriptor(c));
|
||||
SimpleEntry<String, Class>[] fields = ConstructorParameters.CreatorInner.getConstructorField(clazz, c.getParameterCount(), Type.getConstructorDescriptor(c));
|
||||
if (fields != null) {
|
||||
constructor0 = c;
|
||||
constructorParameters0 = fields;
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface Reproduce<D, S> extends BiFunction<D, S, D> {
|
||||
}
|
||||
try {
|
||||
return (Reproduce) Class.forName(newDynName.replace('/', '.')).newInstance();
|
||||
} catch (Exception ex) {
|
||||
} catch (Throwable ex) {
|
||||
}
|
||||
// ------------------------------------------------------------------------------
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
|
||||
|
||||
19
src/org/redkale/util/Resourcable.java
Normal file
19
src/org/redkale/util/Resourcable.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 对象的类没有标记为@Resource, 可以通过实现Resourcable接口实现动态获取Resource.name
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public interface Resourcable {
|
||||
|
||||
public String resourceName();
|
||||
}
|
||||
@@ -15,10 +15,13 @@ import java.util.regex.Pattern;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 如果Resource(name = "$") 表示资源name采用所属对象的name
|
||||
* 如果@Resource(name = "$") 表示资源name采用所属对象的name <br>
|
||||
* 如果没有@Resource 则会取对象的getResourceName()方法值(若存在)
|
||||
* <blockquote><pre>
|
||||
* name规则:
|
||||
* 1: "$"有特殊含义, 不能表示"$"资源本身
|
||||
* 2: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合
|
||||
* 1: "$"有特殊含义, 不能表示"$"资源本身
|
||||
* 2: 只能是字母、数字、(短横)-、(下划线)_、点(.)的组合
|
||||
* </pre></blockquote>
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
@@ -320,17 +323,17 @@ public final class ResourceFactory {
|
||||
if (consumer != null) consumer.accept(src, field);
|
||||
String tname = rc.name();
|
||||
if (tname.contains(RESOURCE_PARENT_NAME)) {
|
||||
try {
|
||||
Resource res = src.getClass().getAnnotation(Resource.class);
|
||||
if (res == null) {
|
||||
String srcname = (String) src.getClass().getMethod("name").invoke(src);
|
||||
tname = tname.replace(RESOURCE_PARENT_NAME, srcname);
|
||||
Resource res = src.getClass().getAnnotation(Resource.class);
|
||||
if (res == null) {
|
||||
if (src instanceof Resourcable) {
|
||||
tname = tname.replace(RESOURCE_PARENT_NAME, ((Resourcable) src).resourceName());
|
||||
} else {
|
||||
tname = res.name();
|
||||
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or not implements Resourcable");
|
||||
}
|
||||
} catch (Exception e) { // 获取src中的name()方法的值, 异常则忽略
|
||||
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or [public String name()] method", e);
|
||||
} else {
|
||||
tname = res.name();
|
||||
}
|
||||
|
||||
}
|
||||
final String rcname = tname;
|
||||
ResourceEntry re = findEntry(rcname, genctype);
|
||||
|
||||
@@ -14,7 +14,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
* 方法在资源被更新以后调用。
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* public class Record {
|
||||
* public class RecordService implements Service {
|
||||
*
|
||||
* @Resource(name = "record.id")
|
||||
* private int id;
|
||||
|
||||
@@ -183,7 +183,7 @@ public abstract class TypeToken<T> {
|
||||
try {
|
||||
Class.forName(newDynName.replace('/', '.'));
|
||||
newDynName = TypeToken.class.getName().replace('.', '/') + "_Dyn" + Math.abs(System.nanoTime());
|
||||
} catch (Exception ex) { //异常说明类不存在
|
||||
} catch (Throwable ex) { //异常说明类不存在
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public final class Utility {
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, String> ofMap(String... items) {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
HashMap<String, String> map = new LinkedHashMap<>();
|
||||
int len = items.length / 2;
|
||||
for (int i = 0; i < len; i++) {
|
||||
map.put(items[i * 2], items[i * 2 + 1]);
|
||||
@@ -113,7 +113,7 @@ public final class Utility {
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<Object, Object> ofMap(Object... items) {
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
HashMap<Object, Object> map = new LinkedHashMap<>();
|
||||
int len = items.length / 2;
|
||||
for (int i = 0; i < len; i++) {
|
||||
map.put(items[i * 2], items[i * 2 + 1]);
|
||||
@@ -121,6 +121,34 @@ public final class Utility {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将多个元素组合成一个Set
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param items 元素
|
||||
*
|
||||
* @return Set
|
||||
*/
|
||||
public static <T> Set<T> ofSet(T... items) {
|
||||
Set<T> set = new LinkedHashSet<>();
|
||||
for (T item : items) set.add(item);
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将多个元素组合成一个List
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param items 元素
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public static <T> List<T> ofList(T... items) {
|
||||
List<T> list = new ArrayList<>();
|
||||
for (T item : items) list.add(item);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不带"-"的UUID值
|
||||
*
|
||||
@@ -131,7 +159,54 @@ public final class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组上追加数据
|
||||
* 将一个或多个新元素添加到数组开始,数组中的元素自动后移
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param array 原数组
|
||||
* @param objs 待追加数据
|
||||
*
|
||||
* @return 新数组
|
||||
*/
|
||||
public static <T> T[] unshift(final T[] array, final T... objs) {
|
||||
if (array == null || array.length == 0) return objs;
|
||||
final T[] news = (T[]) Array.newInstance(array.getClass().getComponentType(), array.length + objs.length);
|
||||
System.arraycopy(objs, 0, news, 0, objs.length);
|
||||
System.arraycopy(array, 0, news, objs.length, array.length);
|
||||
return news;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个或多个新元素添加到数组开始,数组中的元素自动后移
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param array 原数组
|
||||
* @param objs 待追加数据
|
||||
*
|
||||
* @return 新数组
|
||||
*/
|
||||
public static <T> T[] unshift(final T[] array, final Collection<T> objs) {
|
||||
if (objs == null || objs.isEmpty()) return array;
|
||||
if (array == null) {
|
||||
T one = null;
|
||||
for (T t : objs) {
|
||||
if (t != null) one = t;
|
||||
break;
|
||||
}
|
||||
if (one == null) return array;
|
||||
T[] news = (T[]) Array.newInstance(one.getClass(), objs.size());
|
||||
return objs.toArray(news);
|
||||
}
|
||||
T[] news = (T[]) Array.newInstance(array.getClass().getComponentType(), array.length + objs.size());
|
||||
int index = -1;
|
||||
for (T t : objs) {
|
||||
news[(++index)] = t;
|
||||
}
|
||||
System.arraycopy(array, 0, news, objs.size(), array.length);
|
||||
return news;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个或多个新元素添加到数组结尾
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param array 原数组
|
||||
@@ -148,7 +223,7 @@ public final class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组上追加数据
|
||||
* 将一个或多个新元素添加到数组结尾
|
||||
*
|
||||
* @param <T> 泛型
|
||||
* @param array 原数组
|
||||
|
||||
@@ -34,8 +34,8 @@ public class FilterNodeTest {
|
||||
FilterNode joinNode1 = FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username)
|
||||
.or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GREATERTHAN, bean.createtime));
|
||||
FilterNode joinNode2 = FilterJoinNode.create(CarTypeTestTable.class, "cartype", "typename", LIKE, bean.typename);
|
||||
FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNode.create("carid", GREATERTHAN, bean.carid).and(joinNode1).or(joinNode2);
|
||||
FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
||||
final FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNode.create("carid", GREATERTHAN, bean.carid).and(joinNode1).or(joinNode2);
|
||||
final FilterNode beanNode = FilterNodeBean.createFilterNode(bean);
|
||||
System.out.println("node.string = " + node);
|
||||
System.out.println("bean.string = " + beanNode);
|
||||
Map<Class, String> nodeJoinTabalis = node.getJoinTabalis();
|
||||
@@ -46,8 +46,11 @@ public class FilterNodeTest {
|
||||
CharSequence beanWhere = beanNode.createSQLExpress(carEntity, beanJoinTabalis);
|
||||
System.out.println("node.sql = SELECT a.* FROM " + CarTestTable.class.getSimpleName().toLowerCase() + " a" + (nodeJoinsql == null ? "" : nodeJoinsql) + " WHERE " + nodeWhere);
|
||||
System.out.println("bean.sql = SELECT a.* FROM " + CarTestTable.class.getSimpleName().toLowerCase() + " a" + (beanJoinsql == null ? "" : beanJoinsql) + " WHERE " + beanWhere);
|
||||
assert node.isCacheUseable(func) : "isCacheUseable 应该是true";
|
||||
assert beanNode.isCacheUseable(func) : "isCacheUseable 应该是true";
|
||||
boolean r1 = node.isCacheUseable(func);
|
||||
if(!r1) System.err.println("node.isCacheUseable 应该是true");
|
||||
boolean r2 = beanNode.isCacheUseable(func);
|
||||
if(!r2) System.err.println("beanNode.isCacheUseable 应该是true");
|
||||
|
||||
System.out.println("node.Predicate = " + node.createPredicate(carEntity.getCache()));
|
||||
System.out.println("bean.Predicate = " + beanNode.createPredicate(carEntity.getCache()));
|
||||
System.out.println("node.sheet = " + carEntity.getCache().querySheet(null, new Flipper(), node));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.redkale.test.rest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
@@ -70,6 +70,14 @@ public class HelloService implements Service {
|
||||
return source.queryList(HelloEntity.class, bean);
|
||||
}
|
||||
|
||||
//查询List列表
|
||||
@RestMapping(name = "listmap")
|
||||
public List<HelloEntity> queryHello(HelloBean bean, @RestParam(name = "map") Map<String, String> map) { //通过 /pipes/hello/list?bean={...} 查询List列表
|
||||
System.out.println("map参数: " + map);
|
||||
if (source != null) return source.queryList(HelloEntity.class, bean);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
//查询单个
|
||||
@RestMapping(name = "find")
|
||||
public HelloEntity findHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
@@ -78,11 +86,10 @@ public class HelloService implements Service {
|
||||
|
||||
//异步查询单个
|
||||
@RestMapping(name = "asyncfind")
|
||||
public HelloEntity findHello(AsyncHandler handler, @RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
public void 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import javax.annotation.Resource;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.service.RetResult;
|
||||
|
||||
|
||||
public class SimpleRestServlet extends RestHttpServlet<UserInfo> {
|
||||
|
||||
protected static final RetResult RET_UNLOGIN = RetCodes.retResult(RetCodes.RET_USER_UNLOGIN);
|
||||
@@ -26,16 +25,16 @@ public class SimpleRestServlet extends RestHttpServlet<UserInfo> {
|
||||
|
||||
//普通鉴权
|
||||
@Override
|
||||
public boolean authenticate(int module, int actionid, HttpRequest request, HttpResponse response) throws IOException {
|
||||
public void authenticate(int module, int actionid, HttpRequest request, HttpResponse response, HttpServlet next) throws IOException {
|
||||
UserInfo info = currentUser(request);
|
||||
if (info == null) {
|
||||
response.finishJson(RET_UNLOGIN);
|
||||
return false;
|
||||
return;
|
||||
} else if (!info.checkAuth(module, actionid)) {
|
||||
response.finishJson(RET_AUTHILLEGAL);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
return true;
|
||||
next.execute(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
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));
|
||||
System.out.println("异步查找: " + Utility.postHttpContent(url, headers, null));
|
||||
|
||||
url = "http://127.0.0.1:" + port + "/pipes/hello/listmap?map={'a':5}";
|
||||
System.out.println("listmap: " + Utility.postHttpContent(url, headers, null));
|
||||
|
||||
}
|
||||
|
||||
|
||||
200
test/org/redkale/test/service/ABMainService.java
Normal file
200
test/org/redkale/test/service/ABMainService.java
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* 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.test.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.AsynchronousChannelGroup;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import java.util.logging.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.redkale.convert.bson.BsonConvert;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||
import org.redkale.util.*;
|
||||
import org.redkale.watch.WatchFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@RestService(name = "abmain")
|
||||
public class ABMainService implements Service {
|
||||
|
||||
@Resource
|
||||
private BCService bcService;
|
||||
|
||||
public static void remotemain(String[] args) throws Throwable {
|
||||
System.out.println("------------------- 远程模式调用 -----------------------------------");
|
||||
final int abport = 8888;
|
||||
ResourceFactory factory = ResourceFactory.root();
|
||||
factory.register(JsonConvert.root());
|
||||
factory.register(BsonConvert.root());
|
||||
//------------------------ 初始化 CService ------------------------------------
|
||||
CService cservice = Sncp.createLocalService("", null, ResourceFactory.root(), CService.class, new InetSocketAddress("127.0.0.1", 5577), null, null);
|
||||
SncpServer cserver = new SncpServer();
|
||||
cserver.getLogger().setLevel(Level.WARNING);
|
||||
cserver.addSncpServlet(new ServiceWrapper(cservice, "", "", new HashSet<>(), null));
|
||||
cserver.init(DefaultAnyValue.create("port", 5577));
|
||||
cserver.start();
|
||||
|
||||
//------------------------ 初始化 BCService ------------------------------------
|
||||
final Transport bctransport = new Transport("", WatchFactory.root(), "", newBufferPool(), newChannelGroup(), null, Utility.ofSet(new InetSocketAddress("127.0.0.1", 5577)));
|
||||
BCService bcservice = Sncp.createLocalService("", null, ResourceFactory.root(), BCService.class, new InetSocketAddress("127.0.0.1", 5588), bctransport, null);
|
||||
CService remoteCService = Sncp.createRemoteService("", null, CService.class, new InetSocketAddress("127.0.0.1", 5588), bctransport);
|
||||
factory.inject(remoteCService);
|
||||
factory.register("", remoteCService);
|
||||
SncpServer bcserver = new SncpServer();
|
||||
bcserver.getLogger().setLevel(Level.WARNING);
|
||||
bcserver.addSncpServlet(new ServiceWrapper(bcservice, "", "", new HashSet<>(), null));
|
||||
bcserver.init(DefaultAnyValue.create("port", 5588));
|
||||
bcserver.start();
|
||||
|
||||
//------------------------ 初始化 ABMainService ------------------------------------
|
||||
final Transport abtransport = new Transport("", WatchFactory.root(), "", newBufferPool(), newChannelGroup(), null, Utility.ofSet(new InetSocketAddress("127.0.0.1", 5588)));
|
||||
ABMainService service = Sncp.createLocalService("", null, ResourceFactory.root(), ABMainService.class, new InetSocketAddress("127.0.0.1", 5599), bctransport, null);
|
||||
BCService remoteBCService = Sncp.createRemoteService("", null, BCService.class, new InetSocketAddress("127.0.0.1", 5599), abtransport);
|
||||
factory.inject(remoteBCService);
|
||||
factory.register("", remoteBCService);
|
||||
|
||||
HttpServer server = new HttpServer();
|
||||
server.getLogger().setLevel(Level.WARNING);
|
||||
|
||||
server.addRestServlet("", ABMainService.class, service, DefaultRestServlet.class, "/pipes");
|
||||
|
||||
factory.inject(cservice);
|
||||
factory.inject(bcservice);
|
||||
factory.inject(service);
|
||||
|
||||
server.init(DefaultAnyValue.create("port", abport));
|
||||
server.start();
|
||||
Thread.sleep(100);
|
||||
|
||||
//同步方法
|
||||
String url = "http://127.0.0.1:" + abport + "/pipes/abmain/syncabtime/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
//异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/asyncabtime/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
//异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/asyncabtime2/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
server.shutdown();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
System.out.println("------------------- 本地模式调用 -----------------------------------");
|
||||
final int abport = 8888;
|
||||
ResourceFactory factory = ResourceFactory.root();
|
||||
|
||||
ABMainService service = new ABMainService();
|
||||
|
||||
BCService bcservice = new BCService();
|
||||
factory.register("", bcservice);
|
||||
factory.register("", new CService());
|
||||
factory.inject(bcservice);
|
||||
factory.inject(service);
|
||||
|
||||
HttpServer server = new HttpServer();
|
||||
server.getLogger().setLevel(Level.WARNING);
|
||||
|
||||
server.addRestServlet("", ABMainService.class, service, DefaultRestServlet.class, "/pipes");
|
||||
|
||||
server.init(DefaultAnyValue.create("port", "" + abport));
|
||||
server.start();
|
||||
Thread.sleep(100);
|
||||
|
||||
//同步方法
|
||||
String url = "http://127.0.0.1:" + abport + "/pipes/abmain/syncabtime/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
//异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/asyncabtime/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
//异步方法
|
||||
url = "http://127.0.0.1:" + abport + "/pipes/abmain/asyncabtime2/张先生";
|
||||
System.out.println(Utility.postHttpContent(url));
|
||||
|
||||
server.shutdown();
|
||||
//远程模式
|
||||
remotemain(args);
|
||||
}
|
||||
|
||||
public static AsynchronousChannelGroup newChannelGroup() throws IOException {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
ExecutorService transportExec = Executors.newFixedThreadPool(16, (Runnable r) -> {
|
||||
Thread t = new Thread(r);
|
||||
t.setDaemon(true);
|
||||
t.setName("Transport-Thread-" + counter.incrementAndGet());
|
||||
return t;
|
||||
});
|
||||
return AsynchronousChannelGroup.withCachedThreadPool(transportExec, 1);
|
||||
}
|
||||
|
||||
public static ObjectPool<ByteBuffer> newBufferPool() {
|
||||
return new ObjectPool<>(new AtomicLong(), new AtomicLong(), 16,
|
||||
(Object... params) -> ByteBuffer.allocateDirect(8192), null, (e) -> {
|
||||
if (e == null || e.isReadOnly() || e.capacity() != 8192) return false;
|
||||
e.clear();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@RestMapping(name = "syncabtime")
|
||||
public String abCurrentTime(@RestParam(name = "#") final String name) {
|
||||
String rs = "同步abCurrentTime: " + bcService.bcCurrentTime(name);
|
||||
System.out.println("执行了 ABMainService.abCurrentTime++++同步方法");
|
||||
return rs;
|
||||
}
|
||||
|
||||
@RestMapping(name = "asyncabtime")
|
||||
public void abCurrentTime(final AsyncHandler<String, Void> handler, @RestParam(name = "#") final String name) {
|
||||
bcService.bcCurrentTime(AsyncHandler.create((v, a) -> {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) handler.completed(rs, a);
|
||||
}, (t, a) -> {
|
||||
if (handler != null) handler.failed(t, a);
|
||||
}), name);
|
||||
}
|
||||
|
||||
@RestMapping(name = "asyncabtime2")
|
||||
public void abCurrentTime(final MyAsyncHandler<String, Void> handler, @RestParam(name = "#") final String name) {
|
||||
bcService.bcCurrentTime(new MyAsyncHandler<String, Void>() {
|
||||
@Override
|
||||
public int id() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(String v, Void a) {
|
||||
System.out.println("执行了 ABMainService.abCurrentTime----异步方法2");
|
||||
String rs = "异步abCurrentTime: " + v;
|
||||
if (handler != null) handler.completed(rs, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id2() {
|
||||
return 2;
|
||||
}
|
||||
}, name);
|
||||
}
|
||||
}
|
||||
61
test/org/redkale/test/service/BCService.java
Normal file
61
test/org/redkale/test/service/BCService.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.test.service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.AsyncHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class BCService implements Service {
|
||||
|
||||
@Resource
|
||||
private CService cService;
|
||||
|
||||
public String bcCurrentTime(final String name) {
|
||||
String rs = "同步bcCurrentTime: " + cService.ccCurrentTime(name).getResult();
|
||||
System.out.println("执行了 BCService.bcCurrentTime++++同步方法");
|
||||
return rs;
|
||||
}
|
||||
|
||||
public void bcCurrentTime(final AsyncHandler<String, Void> handler, final String name) {
|
||||
cService.ccCurrentTime(AsyncHandler.create((v, a) -> {
|
||||
System.out.println("执行了 BCService.bcCurrentTime----异步方法");
|
||||
String rs = "异步bcCurrentTime: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) handler.completed(rs, null);
|
||||
}, (t, a) -> {
|
||||
if (handler != null) handler.failed(t, a);
|
||||
}), name);
|
||||
}
|
||||
|
||||
public void bcCurrentTime(final MyAsyncHandler<String, Void> handler, final String name) {
|
||||
cService.mcCurrentTime(new MyAsyncHandler<RetResult<String>, Void>() {
|
||||
@Override
|
||||
public int id() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(RetResult<String> v, Void a) {
|
||||
System.out.println("执行了 BCService.bcCurrentTime----异步方法2");
|
||||
String rs = "异步bcCurrentTime: " + (v == null ? null : v.getResult());
|
||||
if (handler != null) handler.completed(rs, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Void attachment) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int id2() {
|
||||
return 2;
|
||||
}
|
||||
}, name);
|
||||
}
|
||||
}
|
||||
34
test/org/redkale/test/service/CService.java
Normal file
34
test/org/redkale/test/service/CService.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.test.service;
|
||||
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class CService implements Service {
|
||||
|
||||
public RetResult<String> ccCurrentTime(final String name) {
|
||||
String rs = "同步ccCurrentTime: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.ccCurrentTime++++同步方法");
|
||||
return new RetResult(rs);
|
||||
}
|
||||
|
||||
public void ccCurrentTime(final AsyncHandler<RetResult<String>, Void> handler, final String name) {
|
||||
String rs = "异步ccCurrentTime: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.ccCurrentTime----异步方法");
|
||||
if (handler != null) handler.completed(new RetResult(rs), null);
|
||||
}
|
||||
|
||||
public void mcCurrentTime(final MyAsyncHandler<RetResult<String>, Void> handler, final String name) {
|
||||
String rs = "异步mcCurrentTime: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.mcCurrentTime----异步方法2");
|
||||
if (handler != null) handler.completed(new RetResult(rs), null);
|
||||
}
|
||||
}
|
||||
18
test/org/redkale/test/service/MyAsyncHandler.java
Normal file
18
test/org/redkale/test/service/MyAsyncHandler.java
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.test.service;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <V> V
|
||||
* @param <A> A
|
||||
*/
|
||||
public abstract class MyAsyncHandler<V, A> extends MyAsyncInnerHandler<V, A> {
|
||||
|
||||
public abstract int id();
|
||||
|
||||
}
|
||||
18
test/org/redkale/test/service/MyAsyncInnerHandler.java
Normal file
18
test/org/redkale/test/service/MyAsyncInnerHandler.java
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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.test.service;
|
||||
|
||||
import org.redkale.util.AsyncHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public abstract class MyAsyncInnerHandler<V, A> implements AsyncHandler<V, A> {
|
||||
|
||||
protected abstract int id2();
|
||||
|
||||
}
|
||||
32
test/org/redkale/test/service/TestService.java
Normal file
32
test/org/redkale/test/service/TestService.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.test.service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
public class TestService implements Service {
|
||||
|
||||
// public boolean change(TestBean bean, String name, int id) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public void change(AsyncHandler<Boolean, TestBean> handler, TestBean bean, String name, int id) {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
SncpServer cserver = new SncpServer();
|
||||
cserver.addSncpServlet(new ServiceWrapper(new TestService(), "", "", new HashSet<>(), null));
|
||||
cserver.init(AnyValue.DefaultAnyValue.create("port", 5577));
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,7 @@
|
||||
*/
|
||||
package org.redkale.test.source;
|
||||
|
||||
import org.redkale.source.DataDefaultSource;
|
||||
import org.redkale.source.DataSource;
|
||||
import org.redkale.source.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,7 +14,7 @@ import org.redkale.source.DataSource;
|
||||
public class JDBCTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DataSource source = new DataDefaultSource(); //耗时:37415
|
||||
DataSource source = DataSources.createDataSource(""); //耗时:37415
|
||||
int count = 1000;
|
||||
LoginTestRecord last = null;
|
||||
long s = System.currentTimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user