修改logger的finest方式
This commit is contained in:
@@ -83,8 +83,6 @@ public class HttpResourceServlet extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
protected final boolean finest = logger.isLoggable(Level.FINEST);
|
||||
|
||||
protected final LongAdder cachedLength = new LongAdder();
|
||||
|
||||
//缓存总大小, 默认0
|
||||
@@ -193,7 +191,7 @@ public class HttpResourceServlet extends HttpServlet {
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.contains("../")) {
|
||||
if (finest) logger.log(Level.FINEST, "Not found resource (404) be " + uri + ", request = " + request);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, "Not found resource (404) be " + uri + ", request = " + request);
|
||||
response.finish404();
|
||||
return;
|
||||
}
|
||||
@@ -220,7 +218,7 @@ public class HttpResourceServlet extends HttpServlet {
|
||||
entry = files.computeIfAbsent(uri, x -> createFileEntry(x));
|
||||
}
|
||||
if (entry == null) {
|
||||
if (finest) logger.log(Level.FINEST, "Not found resource (404), request = " + request);
|
||||
if (logger.isLoggable(Level.FINER)) logger.log(Level.FINER, "Not found resource (404), request = " + request);
|
||||
response.finish404();
|
||||
} else {
|
||||
//file = null 表示资源内容在内存而不是在File中
|
||||
|
||||
@@ -226,7 +226,7 @@ public abstract class WebSocket<G extends Serializable, T> {
|
||||
*/
|
||||
CompletableFuture<Integer> sendPacket(WebSocketPacket packet) {
|
||||
CompletableFuture<Integer> rs = this._runner.sendMessage(packet);
|
||||
if (_engine.finest && packet != WebSocketPacket.DEFAULT_PING_PACKET) {
|
||||
if (_engine.logger.isLoggable(Level.FINEST) && packet != WebSocketPacket.DEFAULT_PING_PACKET) {
|
||||
_engine.logger.finest("userid:" + getUserid() + " send websocket message(" + packet + ")" + " on " + this);
|
||||
}
|
||||
return rs == null ? CompletableFuture.completedFuture(RETCODE_WSOCKET_CLOSED) : rs;
|
||||
@@ -344,7 +344,7 @@ public abstract class WebSocket<G extends Serializable, T> {
|
||||
return ((CompletableFuture) message).thenCompose((json) -> _engine.node.sendMessage(convert, json, last, userids));
|
||||
}
|
||||
CompletableFuture<Integer> rs = _engine.node.sendMessage(convert, message, last, userids);
|
||||
if (_engine.finest) _engine.logger.finest("userids:" + Arrays.toString(userids) + " send websocket message(" + message + ")");
|
||||
if (_engine.logger.isLoggable(Level.FINEST)) _engine.logger.finest("userids:" + Arrays.toString(userids) + " send websocket message(" + message + ")");
|
||||
return rs;
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ public abstract class WebSocket<G extends Serializable, T> {
|
||||
return ((CompletableFuture) message).thenCompose((json) -> _engine.node.broadcastMessage(convert, json, last));
|
||||
}
|
||||
CompletableFuture<Integer> rs = _engine.node.broadcastMessage(convert, message, last);
|
||||
if (_engine.finest) _engine.logger.finest("broadcast send websocket message(" + message + ")");
|
||||
if (_engine.logger.isLoggable(Level.FINEST)) _engine.logger.finest("broadcast send websocket message(" + message + ")");
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,6 @@ public class WebSocketEngine {
|
||||
@Comment("日志")
|
||||
protected final Logger logger;
|
||||
|
||||
@Comment("日志级别")
|
||||
protected final boolean finest;
|
||||
|
||||
@Comment("PING的间隔秒数")
|
||||
private int liveinterval;
|
||||
|
||||
@@ -81,7 +78,6 @@ public class WebSocketEngine {
|
||||
this.liveinterval = liveinterval;
|
||||
this.maxconns = maxconns;
|
||||
this.logger = logger;
|
||||
this.finest = logger.isLoggable(Level.FINEST);
|
||||
this.index = sequence.getAndIncrement();
|
||||
}
|
||||
|
||||
@@ -103,7 +99,7 @@ public class WebSocketEngine {
|
||||
long now = System.currentTimeMillis();
|
||||
getLocalWebSockets().stream().filter(x -> (now - x.getLastSendTime()) > intervalms).forEach(x -> x.sendPing());
|
||||
}, delay, liveinterval, TimeUnit.SECONDS);
|
||||
logger.finest(this.getClass().getSimpleName() + "(" + engineid + ")" + " start keeplive(delay:" + delay + ", maxconns:" + maxconns + ", interval:" + liveinterval + "s) scheduler executor");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(this.getClass().getSimpleName() + "(" + engineid + ")" + " start keeplive(delay:" + delay + ", maxconns:" + maxconns + ", interval:" + liveinterval + "s) scheduler executor");
|
||||
}
|
||||
|
||||
void destroy(AnyValue conf) {
|
||||
|
||||
@@ -36,10 +36,6 @@ public abstract class WebSocketNode {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
|
||||
protected final boolean finest = logger.isLoggable(Level.FINEST);
|
||||
|
||||
protected final boolean finer = logger.isLoggable(Level.FINER);
|
||||
|
||||
//"SNCP_ADDR" 如果不是分布式(没有SNCP) 值为null
|
||||
@Resource(name = Application.RESNAME_SNCP_ADDR)
|
||||
protected InetSocketAddress localSncpAddress; //为SncpServer的服务address
|
||||
@@ -86,12 +82,12 @@ public abstract class WebSocketNode {
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
final CompletableFuture<Void> connect(final Serializable userid) {
|
||||
if (finest) logger.finest(localSncpAddress + " receive websocket connect event (" + userid + " on " + this.localEngine.getEngineid() + ").");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(localSncpAddress + " receive websocket connect event (" + userid + " on " + this.localEngine.getEngineid() + ").");
|
||||
return connect(userid, localSncpAddress);
|
||||
}
|
||||
|
||||
final CompletableFuture<Void> disconnect(final Serializable userid) {
|
||||
if (finest) logger.finest(localSncpAddress + " receive websocket disconnect event (" + userid + " on " + this.localEngine.getEngineid() + ").");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(localSncpAddress + " receive websocket disconnect event (" + userid + " on " + this.localEngine.getEngineid() + ").");
|
||||
return disconnect(userid, localSncpAddress);
|
||||
}
|
||||
|
||||
@@ -142,7 +138,7 @@ public abstract class WebSocketNode {
|
||||
public CompletableFuture<Map<InetSocketAddress, List<String>>> getRpcNodeWebSocketAddresses(final Serializable userid) {
|
||||
CompletableFuture<Collection<InetSocketAddress>> sncpFuture = getRpcNodeAddresses(userid);
|
||||
return sncpFuture.thenCompose((Collection<InetSocketAddress> addrs) -> {
|
||||
if (finest) logger.finest("websocket found userid:" + userid + " on " + addrs);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket found userid:" + userid + " on " + addrs);
|
||||
if (addrs == null || addrs.isEmpty()) return CompletableFuture.completedFuture(new HashMap<>());
|
||||
CompletableFuture<Map<InetSocketAddress, List<String>>> future = null;
|
||||
for (final InetSocketAddress nodeAddress : addrs) {
|
||||
@@ -194,14 +190,14 @@ public abstract class WebSocketNode {
|
||||
CompletableFuture<Integer> localFuture = null;
|
||||
if (this.localEngine != null) localFuture = CompletableFuture.completedFuture(localEngine.forceCloseLocalWebSocket(userid));
|
||||
if (this.sncpNodeAddresses == null || this.remoteNode == null) {
|
||||
if (finest) logger.finest("websocket remote node is null");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket remote node is null");
|
||||
//没有CacheSource就不会有分布式节点
|
||||
return localFuture;
|
||||
}
|
||||
//远程节点关闭
|
||||
CompletableFuture<Collection<InetSocketAddress>> addrsFuture = sncpNodeAddresses.getCollectionAsync(SOURCE_SNCP_USERID_PREFIX + userid);
|
||||
CompletableFuture<Integer> remoteFuture = addrsFuture.thenCompose((Collection<InetSocketAddress> addrs) -> {
|
||||
if (finest) logger.finest("websocket found userid:" + userid + " on " + addrs);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket found userid:" + userid + " on " + addrs);
|
||||
if (addrs == null || addrs.isEmpty()) return CompletableFuture.completedFuture(0);
|
||||
CompletableFuture<Integer> future = null;
|
||||
for (InetSocketAddress addr : addrs) {
|
||||
@@ -404,7 +400,7 @@ public abstract class WebSocketNode {
|
||||
CompletableFuture<Integer> localFuture = this.localEngine == null ? null : this.localEngine.broadcastMessage(message, last);
|
||||
CompletableFuture<Collection<InetSocketAddress>> addrsFuture = sncpNodeAddresses.getCollectionAsync(SOURCE_SNCP_NODES_KEY);
|
||||
CompletableFuture<Integer> remoteFuture = addrsFuture.thenCompose((Collection<InetSocketAddress> addrs) -> {
|
||||
if (finest) logger.finest("websocket broadcast message on " + addrs);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket broadcast message on " + addrs);
|
||||
if (addrs == null || addrs.isEmpty()) return CompletableFuture.completedFuture(0);
|
||||
CompletableFuture<Integer> future = null;
|
||||
for (InetSocketAddress addr : addrs) {
|
||||
@@ -418,11 +414,11 @@ public abstract class WebSocketNode {
|
||||
}
|
||||
|
||||
private CompletableFuture<Integer> sendOneMessage(final Object message, final boolean last, final Serializable userid) {
|
||||
if (finest) logger.finest("websocket want send message {userid:" + userid + ", content:'" + message + "'} from locale node to locale engine");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket want send message {userid:" + userid + ", content:'" + message + "'} from locale node to locale engine");
|
||||
CompletableFuture<Integer> localFuture = null;
|
||||
if (this.localEngine != null) localFuture = localEngine.sendMessage(message, last, userid);
|
||||
if (this.sncpNodeAddresses == null || this.remoteNode == null) {
|
||||
if (finest) logger.finest("websocket remote node is null");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket remote node is null");
|
||||
//没有CacheSource就不会有分布式节点
|
||||
return localFuture == null ? CompletableFuture.completedFuture(RETCODE_GROUP_EMPTY) : localFuture;
|
||||
}
|
||||
@@ -430,10 +426,10 @@ public abstract class WebSocketNode {
|
||||
CompletableFuture<Collection<InetSocketAddress>> addrsFuture = sncpNodeAddresses.getCollectionAsync(SOURCE_SNCP_USERID_PREFIX + userid);
|
||||
CompletableFuture<Integer> remoteFuture = addrsFuture.thenCompose((Collection<InetSocketAddress> addrs) -> {
|
||||
if (addrs == null || addrs.isEmpty()) {
|
||||
if (finer) logger.finer("websocket not found userid:" + userid + " on any node ");
|
||||
if (logger.isLoggable(Level.FINER)) logger.finer("websocket not found userid:" + userid + " on any node ");
|
||||
return CompletableFuture.completedFuture(0);
|
||||
}
|
||||
if (finest) logger.finest("websocket found userid:" + userid + " on " + addrs);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("websocket found userid:" + userid + " on " + addrs);
|
||||
CompletableFuture<Integer> future = null;
|
||||
for (InetSocketAddress addr : addrs) {
|
||||
if (addr == null || addr.equals(localSncpAddress)) continue;
|
||||
|
||||
@@ -33,8 +33,6 @@ public final class SncpClient {
|
||||
|
||||
protected static final Logger logger = Logger.getLogger(SncpClient.class.getSimpleName());
|
||||
|
||||
protected final boolean finest = logger.isLoggable(Level.FINEST);
|
||||
|
||||
protected final JsonConvert convert = JsonFactory.root().getConvert();
|
||||
|
||||
protected final String name;
|
||||
|
||||
@@ -40,8 +40,6 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SncpDynServlet.class.getSimpleName());
|
||||
|
||||
private final boolean finest = logger.isLoggable(Level.FINEST);
|
||||
|
||||
private final DLong serviceid;
|
||||
|
||||
private final HashMap<DLong, SncpServletAction> actions = new HashMap<>();
|
||||
@@ -110,7 +108,7 @@ public final class SncpDynServlet extends SncpServlet {
|
||||
bufferSupplier = request.getContext().getBufferSupplier();
|
||||
}
|
||||
final SncpServletAction action = actions.get(request.getActionid());
|
||||
//if (finest) logger.log(Level.FINEST, "sncpdyn.execute: " + request + ", " + (action == null ? "null" : action.method));
|
||||
//logger.log(Level.FINEST, "sncpdyn.execute: " + request + ", " + (action == null ? "null" : action.method));
|
||||
if (action == null) {
|
||||
response.finish(SncpResponse.RETCODE_ILLACTIONID, null); //无效actionid
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.redkale.net.sncp;
|
||||
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.util.logging.Level;
|
||||
import org.redkale.convert.bson.*;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.util.*;
|
||||
@@ -58,7 +59,7 @@ public final class SncpRequest extends Request<SncpContext> {
|
||||
//---------------------head----------------------------------
|
||||
this.seqid = buffer.getLong();
|
||||
if (buffer.getChar() != HEADER_SIZE) {
|
||||
context.getLogger().finest("sncp buffer header.length not " + HEADER_SIZE);
|
||||
if (context.getLogger().isLoggable(Level.FINEST)) context.getLogger().finest("sncp buffer header.length not " + HEADER_SIZE);
|
||||
return -1;
|
||||
}
|
||||
this.serviceid = DLong.read(buffer);
|
||||
@@ -68,7 +69,7 @@ public final class SncpRequest extends Request<SncpContext> {
|
||||
this.bodylength = buffer.getInt();
|
||||
|
||||
if (buffer.getInt() != 0) {
|
||||
context.getLogger().finest("sncp buffer header.retcode not 0");
|
||||
if (context.getLogger().isLoggable(Level.FINEST)) context.getLogger().finest("sncp buffer header.retcode not 0");
|
||||
return -1;
|
||||
}
|
||||
//---------------------body----------------------------------
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.util.*;
|
||||
|
||||
@@ -69,7 +70,7 @@ public class WebSocketNodeService extends WebSocketNode implements Service {
|
||||
public CompletableFuture<Void> connect(Serializable userid, InetSocketAddress sncpAddr) {
|
||||
CompletableFuture<Void> future = sncpNodeAddresses.appendSetItemAsync(SOURCE_SNCP_USERID_PREFIX + userid, sncpAddr);
|
||||
future = future.thenAccept((a) -> sncpNodeAddresses.appendSetItemAsync(SOURCE_SNCP_NODES_KEY, sncpAddr));
|
||||
if (finest) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " connect from " + sncpAddr);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " connect from " + sncpAddr);
|
||||
return future;
|
||||
}
|
||||
|
||||
@@ -84,7 +85,7 @@ public class WebSocketNodeService extends WebSocketNode implements Service {
|
||||
@Override
|
||||
public CompletableFuture<Void> disconnect(Serializable userid, InetSocketAddress sncpAddr) {
|
||||
CompletableFuture<Void> future = sncpNodeAddresses.removeSetItemAsync(SOURCE_SNCP_USERID_PREFIX + userid, sncpAddr);
|
||||
if (finest) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " disconnect from " + sncpAddr);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " disconnect from " + sncpAddr);
|
||||
return future;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ public class WebSocketNodeService extends WebSocketNode implements Service {
|
||||
@Override
|
||||
public CompletableFuture<Integer> forceCloseWebSocket(Serializable userid, InetSocketAddress sncpAddr) {
|
||||
//不能从sncpNodeAddresses中移除,因为engine.forceCloseWebSocket 会调用到disconnect
|
||||
if (finest) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " forceCloseWebSocket from " + sncpAddr);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(WebSocketNodeService.class.getSimpleName() + ".event: " + userid + " forceCloseWebSocket from " + sncpAddr);
|
||||
if (localEngine == null) return CompletableFuture.completedFuture(0);
|
||||
return CompletableFuture.completedFuture(localEngine.forceCloseLocalWebSocket(userid));
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
|
||||
if (expireHandler != null && entry != null) expireHandler.accept(entry);
|
||||
}
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
logger.finest(self.getClass().getSimpleName() + ":" + self.resourceName() + " start schedule expire executor");
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest(self.getClass().getSimpleName() + ":" + self.resourceName() + " start schedule expire executor");
|
||||
}
|
||||
if (Sncp.isRemote(self)) return;
|
||||
|
||||
@@ -166,7 +166,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
|
||||
CompletableFuture<List<CacheEntry<Object>>> listFuture = remoteSource.queryListAsync();
|
||||
listFuture.whenComplete((list, exp) -> {
|
||||
if (exp != null) {
|
||||
logger.log(Level.FINEST, CacheSource.class.getSimpleName() + "(" + resourceName() + ") queryListAsync error", exp);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, CacheSource.class.getSimpleName() + "(" + resourceName() + ") queryListAsync error", exp);
|
||||
} else {
|
||||
for (CacheEntry<Object> entry : list) {
|
||||
container.put(entry.key, entry);
|
||||
@@ -174,7 +174,7 @@ public class CacheMemorySource<V extends Object> extends AbstractService impleme
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.FINEST, CacheSource.class.getSimpleName() + "(" + resourceName() + ") queryListAsync error, maybe remote node connot connect ", e);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.log(Level.FINEST, CacheSource.class.getSimpleName() + "(" + resourceName() + ") queryListAsync error, maybe remote node connot connect ", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.net.URL;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.*;
|
||||
import java.util.logging.*;
|
||||
import java.util.stream.Stream;
|
||||
@@ -37,8 +36,6 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
|
||||
protected final Logger logger = Logger.getLogger(DataJdbcSource.class.getSimpleName());
|
||||
|
||||
protected final AtomicBoolean debug = new AtomicBoolean(logger.isLoggable(Level.FINEST));
|
||||
|
||||
protected final String name;
|
||||
|
||||
protected final URL conf;
|
||||
@@ -219,7 +216,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
}
|
||||
prestmt.close();
|
||||
//------------------------------------------------------------
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) { //打印调试信息
|
||||
if (info.isLoggable(logger, Level.FINEST)) { //打印调试信息
|
||||
char[] sqlchars = sql.toCharArray();
|
||||
for (final T value : values) {
|
||||
//-----------------------------
|
||||
@@ -370,7 +367,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final Statement stmt = conn.createStatement();
|
||||
for (Serializable key : keys) {
|
||||
String sql = "DELETE FROM " + info.getTable(key) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(key);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||
stmt.addBatch(sql);
|
||||
}
|
||||
int[] pc = stmt.executeBatch();
|
||||
@@ -451,7 +448,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2)))) + info.createSQLOrderby(flipper)
|
||||
+ ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit()));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " delete sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
final Statement stmt = conn.createStatement();
|
||||
c = stmt.executeUpdate(sql);
|
||||
@@ -533,7 +530,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
conn.setReadOnly(false);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(updateSQL);
|
||||
Attribute<T, Serializable>[] attrs = info.updateAttributes;
|
||||
final boolean debugfinest = debug.get() && info.isLoggable(Level.FINEST);
|
||||
final boolean debugfinest = info.isLoggable(logger, Level.FINEST);
|
||||
char[] sqlchars = debugfinest ? updateSQL.toCharArray() : null;
|
||||
for (final T value : values) {
|
||||
int k = 0;
|
||||
@@ -625,7 +622,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
if (!info.isVirtualEntity()) {
|
||||
if (value instanceof byte[]) {
|
||||
String sql = "UPDATE " + info.getTable(id) + " SET " + info.getSQLColumn(null, column) + " = ? WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(id);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
final PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
Blob blob = conn.createBlob();
|
||||
@@ -636,7 +633,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
} else {
|
||||
String sql = "UPDATE " + info.getTable(id) + " SET " + info.getSQLColumn(null, column) + " = "
|
||||
+ info.formatToString(value) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(id);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
final Statement stmt = conn.createStatement();
|
||||
c = stmt.executeUpdate(sql);
|
||||
@@ -706,7 +703,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
+ " SET " + info.getSQLColumn("a", column) + " = ?"
|
||||
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
Blob blob = conn.createBlob();
|
||||
blob.setBytes(1, (byte[]) value);
|
||||
@@ -719,7 +716,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
+ " SET " + info.getSQLColumn("a", column) + " = " + info.formatToString(value)
|
||||
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
final Statement stmt = conn.createStatement();
|
||||
c = stmt.executeUpdate(sql);
|
||||
@@ -796,7 +793,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
int c = -1;
|
||||
if (!virtual) {
|
||||
String sql = "UPDATE " + info.getTable(id) + " SET " + setsql + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(id);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + ": " + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + ": " + sql);
|
||||
conn.setReadOnly(false);
|
||||
if (blobs != null) {
|
||||
final PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
@@ -926,7 +923,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
|
||||
//注:LIMIT 仅支持MySQL 且在多表关联式会异常, 该BUG尚未解决
|
||||
sql += info.createSQLOrderby(flipper) + ((flipper == null || flipper.getLimit() < 1) ? "" : (" LIMIT " + flipper.getLimit()));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
if (blobs != null) {
|
||||
final PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
@@ -1022,7 +1019,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
int c = -1;
|
||||
if (!virtual) {
|
||||
String sql = "UPDATE " + info.getTable(id) + " SET " + setsql + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(id);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(bean.getClass().getSimpleName() + ": " + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(bean.getClass().getSimpleName() + ": " + sql);
|
||||
conn.setReadOnly(false);
|
||||
if (blobs != null) {
|
||||
final PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
@@ -1110,7 +1107,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
String sql = "UPDATE " + info.getTable(node) + " a " + (join1 == null ? "" : (", " + join1)) + " SET " + setsql
|
||||
+ ((where == null || where.length() == 0) ? (join2 == null ? "" : (" WHERE " + join2))
|
||||
: (" WHERE " + where + (join2 == null ? "" : (" AND " + join2))));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(info.getType().getSimpleName() + " update sql=" + sql);
|
||||
conn.setReadOnly(false);
|
||||
if (blobs != null) {
|
||||
final PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
@@ -1273,7 +1270,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
}
|
||||
final String sql = "SELECT " + sb + " FROM " + info.getTable(node) + " a"
|
||||
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
||||
|
||||
@@ -1329,7 +1326,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||
final String sql = "SELECT " + func.getColumn((column == null || column.isEmpty() ? "*" : info.getSQLColumn("a", column))) + " FROM " + info.getTable(node) + " a"
|
||||
+ (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
||||
Number rs = defVal;
|
||||
@@ -1388,7 +1385,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||
final String sql = "SELECT a." + sqlkey + ", " + func.getColumn((funcColumn == null || funcColumn.isEmpty() ? "*" : info.getSQLColumn("a", funcColumn)))
|
||||
+ " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + " GROUP BY a." + sqlkey;
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(entityClass.getSimpleName() + " single sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement prestmt = conn.prepareStatement(sql);
|
||||
Map<K, N> rs = new LinkedHashMap<>();
|
||||
@@ -1447,7 +1444,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
try {
|
||||
final SelectColumn sels = selects;
|
||||
final String sql = "SELECT * FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ps.setFetchSize(1);
|
||||
@@ -1524,7 +1521,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||
final String sql = "SELECT a.* FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ps.setFetchSize(1);
|
||||
@@ -1591,7 +1588,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
try {
|
||||
final Attribute<T, Serializable> attr = info.getAttribute(column);
|
||||
final String sql = "SELECT " + info.getSQLColumn(null, column) + " FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ps.setFetchSize(1);
|
||||
@@ -1646,7 +1643,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final CharSequence join = node == null ? null : node.createSQLJoin(this, false, joinTabalis, new HashSet<>(), info);
|
||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||
final String sql = "SELECT " + info.getSQLColumn("a", column) + " FROM " + info.getTable(node) + " a" + (join == null ? "" : join) + ((where == null || where.length() == 0) ? "" : (" WHERE " + where));
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(clazz.getSimpleName() + " find sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
ps.setFetchSize(1);
|
||||
@@ -1688,7 +1685,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
}
|
||||
|
||||
final Connection conn = createReadSQLConnection();
|
||||
final boolean log = debug.get() && info.isLoggable(Level.FINEST);
|
||||
final boolean log = info.isLoggable(logger, Level.FINEST);
|
||||
String logstr = null;
|
||||
try {
|
||||
final String sql = "SELECT COUNT(*) FROM " + info.getTable(pk) + " WHERE " + info.getPrimarySQLColumn() + " = " + FilterNode.formatToString(pk);
|
||||
@@ -1734,7 +1731,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
if (cache != null && cache.isFullLoaded() && (node == null || node.isCacheUseable(this))) return cache.exists(node);
|
||||
|
||||
final Connection conn = createReadSQLConnection();
|
||||
final boolean log = debug.get() && info.isLoggable(Level.FINEST);
|
||||
final boolean log = info.isLoggable(logger, Level.FINEST);
|
||||
String logstr = null;
|
||||
try {
|
||||
final Map<Class, String> joinTabalis = node == null ? null : node.getJoinTabalis();
|
||||
@@ -2238,7 +2235,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final EntityCache<T> cache = info.getCache();
|
||||
if (readcache && cache != null && cache.isFullLoaded()) {
|
||||
if (node == null || node.isCacheUseable(this)) {
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) logger.finest(clazz.getSimpleName() + " cache query predicate = " + (node == null ? null : node.createPredicate(cache)));
|
||||
if (info.isLoggable(logger, Level.FINEST)) logger.finest(clazz.getSimpleName() + " cache query predicate = " + (node == null ? null : node.createPredicate(cache)));
|
||||
return cache.querySheet(needtotal, selects, flipper, node);
|
||||
}
|
||||
}
|
||||
@@ -2251,7 +2248,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
final CharSequence where = node == null ? null : node.createSQLExpress(info, joinTabalis);
|
||||
final String sql = "SELECT a.* FROM " + info.getTable(node) + " a" + (join == null ? "" : join)
|
||||
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + info.createSQLOrderby(flipper);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST)) {
|
||||
if (info.isLoggable(logger, Level.FINEST)) {
|
||||
logger.finest(clazz.getSimpleName() + " query sql=" + sql + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getOffset() + "," + flipper.getLimit())));
|
||||
}
|
||||
conn.setReadOnly(true);
|
||||
@@ -2339,7 +2336,7 @@ public class DataJdbcSource extends AbstractService implements DataSource, DataC
|
||||
public final void directQuery(String sql, Consumer<ResultSet> consumer) {
|
||||
final Connection conn = createReadSQLConnection();
|
||||
try {
|
||||
if (debug.get()) logger.finest("direct query sql=" + sql);
|
||||
if (logger.isLoggable(Level.FINEST)) logger.finest("direct query sql=" + sql);
|
||||
conn.setReadOnly(true);
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
final ResultSet set = ps.executeQuery();
|
||||
|
||||
@@ -629,12 +629,13 @@ public final class EntityInfo<T> {
|
||||
/**
|
||||
* 判断日志级别
|
||||
*
|
||||
* @param l Level
|
||||
* @param logger Logger
|
||||
* @param l Level
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isLoggable(Level l) {
|
||||
return l.intValue() >= this.logLevel;
|
||||
public boolean isLoggable(Logger logger, Level l) {
|
||||
return logger.isLoggable(l) && l.intValue() >= this.logLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user