diff --git a/src/main/java/org/redkale/cached/spi/CachedManagerService.java b/src/main/java/org/redkale/cached/spi/CachedManagerService.java index b6712bc97..85591d05d 100644 --- a/src/main/java/org/redkale/cached/spi/CachedManagerService.java +++ b/src/main/java/org/redkale/cached/spi/CachedManagerService.java @@ -330,7 +330,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se */ @Override public void localSet(String key, Type type, T value, Duration expire) { - setCache(localSource, key, type, value, expire); + localSetCache(key, type, value, expire); } /** @@ -434,7 +434,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se */ @Override public void remoteSet(final String key, final Type type, final T value, Duration expire) { - setCache(remoteSource, key, type, value, expire); + remoteSetCache(key, type, value, expire); } /** @@ -448,7 +448,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se */ @Override public CompletableFuture remoteSetAsync(String key, Type type, T value, Duration expire) { - return setCacheAsync(remoteSource, key, type, value, expire); + return remoteSetCacheAsync(key, type, value, expire); } /** @@ -621,10 +621,10 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se final String key, final Type type, final T value, Duration localExpire, Duration remoteExpire) { checkEnable(); if (localExpire != null) { - setCache(localSource, key, type, value, localExpire); + localSetCache(key, type, value, localExpire); } if (remoteExpire != null && remoteSource != null) { - setCache(remoteSource, key, type, value, remoteExpire); + remoteSetCache(key, type, value, remoteExpire); } if (remoteSource != null && broadcastable) { remoteSource.publish(getChannelTopic(), new CachedEventMessage(node, key)); @@ -647,11 +647,11 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se String key, Type type, T value, Duration localExpire, Duration remoteExpire) { checkEnable(); if (localExpire != null) { - setCache(localSource, key, type, value, localExpire); + localSetCache(key, type, value, localExpire); } CompletableFuture future = CompletableFuture.completedFuture(null); if (remoteSource != null && remoteExpire != null) { - future = setCacheAsync(remoteSource, key, type, value, remoteExpire); + future = remoteSetCacheAsync(key, type, value, remoteExpire); } if (remoteSource != null && broadcastable) { future = future.thenCompose(r -> remoteSource @@ -824,69 +824,88 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se }); } + protected void localSetCache(String key, Type type, T value, Duration expire) { + localSetCache(key, expire, loadCacheType(type, value), CachedValue.create(value)); + } + + protected void localSetCache(String key, Duration expire, Type cacheType, CachedValue cacheVal) { + checkEnable(); + boolean logable = logger.isLoggable(logLevel); + Objects.requireNonNull(expire); + long millis = expire.toMillis(); + String id = idFor(key); + if (logable) { + logger.log(logLevel, "Cached set id(" + id + ") value to localSource expire " + millis + " ms"); + } + if (millis > 0) { + localSource.psetex(id, millis, cacheType, cacheVal); + } else { + localSource.set(id, cacheType, cacheVal); + } + } + + protected void remoteSetCache(String key, Type type, T value, Duration expire) { + remoteSetCache(key, expire, loadCacheType(type, value), CachedValue.create(value)); + } + + protected void remoteSetCache(String key, Duration expire, Type cacheType, CachedValue cacheVal) { + checkEnable(); + boolean logable = logger.isLoggable(logLevel); + Objects.requireNonNull(expire); + long millis = expire.toMillis(); + String id = idFor(key); + if (logable) { + logger.log(logLevel, "Cached set id(" + id + ") value to remoteSource expire " + millis + " ms"); + } + if (millis > 0) { + remoteSource.psetex(id, millis, cacheType, cacheVal); + } else { + remoteSource.set(id, cacheType, cacheVal); + } + } + + protected CompletableFuture localSetCacheAsync(String key, Type type, T value, Duration expire) { + return localSetCacheAsync(key, expire, loadCacheType(type, value), CachedValue.create(value)); + } + protected CompletableFuture localSetCacheAsync( String key, Duration expire, Type cacheType, CachedValue cacheVal) { - return setCacheAsync(localSource, key, expire, cacheType, cacheVal); + checkEnable(); + boolean logable = logger.isLoggable(logLevel); + Objects.requireNonNull(expire); + String id = idFor(key); + long millis = expire.toMillis(); + if (logable) { + logger.log(logLevel, "Cached set id(" + id + ") value to localSource expire " + millis + " ms"); + } + if (millis > 0) { + return localSource.psetexAsync(id, millis, cacheType, cacheVal); + } else { + return localSource.setAsync(id, cacheType, cacheVal); + } + } + + protected CompletableFuture remoteSetCacheAsync(String key, Type type, T value, Duration expire) { + return remoteSetCacheAsync(key, expire, loadCacheType(type, value), CachedValue.create(value)); } protected CompletableFuture remoteSetCacheAsync( String key, Duration expire, Type cacheType, CachedValue cacheVal) { - return setCacheAsync(remoteSource, key, expire, cacheType, cacheVal); - } - - protected void localSetCache(String key, Duration expire, Type cacheType, CachedValue cacheVal) { - setCache(localSource, key, expire, cacheType, cacheVal); - } - - protected void remoteSetCache(String key, Duration expire, Type cacheType, CachedValue cacheVal) { - setCache(remoteSource, key, expire, cacheType, cacheVal); - } - - protected void setCache( - CacheSource source, String key, Duration expire, Type cacheType, CachedValue cacheVal) { - checkEnable(); - boolean logable = logger.isLoggable(logLevel); - Objects.requireNonNull(expire); - long millis = expire.toMillis(); - String id = idFor(key); - if (logable) { - String s = source == localSource ? "localSource" : "remoteSource"; - logger.log(logLevel, "Cached set id(" + id + ") value to " + s + " expire " + millis + " ms"); - } - if (millis > 0) { - source.psetex(id, millis, cacheType, cacheVal); - } else { - source.set(id, cacheType, cacheVal); - } - } - - protected CompletableFuture setCacheAsync( - CacheSource source, String key, Duration expire, Type cacheType, CachedValue cacheVal) { checkEnable(); boolean logable = logger.isLoggable(logLevel); Objects.requireNonNull(expire); String id = idFor(key); long millis = expire.toMillis(); if (logable) { - String s = source == localSource ? "localSource" : "remoteSource"; - logger.log(logLevel, "Cached set id(" + id + ") value to " + s + " expire " + millis + " ms"); + logger.log(logLevel, "Cached set id(" + id + ") value to remoteSource expire " + millis + " ms"); } if (millis > 0) { - return source.psetexAsync(id, millis, cacheType, cacheVal); + return remoteSource.psetexAsync(id, millis, cacheType, cacheVal); } else { - return source.setAsync(id, cacheType, cacheVal); + return remoteSource.setAsync(id, cacheType, cacheVal); } } - protected void setCache(CacheSource source, String key, Type type, T value, Duration expire) { - setCache(source, key, expire, loadCacheType(type, value), CachedValue.create(value)); - } - - protected CompletableFuture setCacheAsync( - CacheSource source, String key, Type type, T value, Duration expire) { - return setCacheAsync(source, key, expire, loadCacheType(type, value), CachedValue.create(value)); - } - protected CachedValue bothGetCache(final String key, final Duration expire, final Type cacheType) { checkEnable(); boolean logable = logger.isLoggable(logLevel); @@ -905,7 +924,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se if (logable) { logger.log(logLevel, "Cached set id(" + id + ") value to localSource from remoteSource"); } - setCache(localSource, key, expire, cacheType, cacheVal); + localSetCache(key, expire, cacheType, cacheVal); } if (logable) { logger.log(logLevel, "Cached got id(" + id + ") value from remoteSource"); @@ -945,7 +964,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se if (logable) { logger.log(logLevel, "Cached set id(" + id + ") value to localSource from remoteSource"); } - setCache(localSource, id, expire, cacheType, v); + localSetCache(id, expire, cacheType, v); } if (logable) { logger.log(logLevel, "Cached got id(" + id + ") value from remoteSource"); diff --git a/src/main/java/org/redkale/source/ColumnExpNode.java b/src/main/java/org/redkale/source/ColumnExpNode.java index 009b51a05..e5a2a9715 100644 --- a/src/main/java/org/redkale/source/ColumnExpNode.java +++ b/src/main/java/org/redkale/source/ColumnExpNode.java @@ -5,10 +5,9 @@ */ package org.redkale.source; -import static org.redkale.source.ColumnExpress.*; - import java.io.Serializable; import org.redkale.convert.ConvertColumn; +import static org.redkale.source.ColumnExpress.*; /** * 作为ColumnValue的value字段值,用于复杂的字段表达式 。
@@ -27,14 +26,17 @@ import org.redkale.convert.ConvertColumn; */ public class ColumnExpNode implements ColumnNode { + // 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode @ConvertColumn(index = 1) - protected ColumnNode left; // 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode + protected ColumnNode left; + // SET时,left必须是ColumnNameNode, right必须是null @ConvertColumn(index = 2) - protected ColumnExpress express; // SET时,left必须是ColumnNameNode, right必须是null + protected ColumnExpress express; + // 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode @ConvertColumn(index = 3) - protected ColumnNode right; // 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode + protected ColumnNode right; public ColumnExpNode() {} diff --git a/src/main/java/org/redkale/source/ColumnFuncNode.java b/src/main/java/org/redkale/source/ColumnFuncNode.java index 4a4475e03..4e6e7cc2e 100644 --- a/src/main/java/org/redkale/source/ColumnFuncNode.java +++ b/src/main/java/org/redkale/source/ColumnFuncNode.java @@ -21,8 +21,9 @@ public class ColumnFuncNode implements ColumnNode { @ConvertColumn(index = 1) protected FilterFunc func; + // 类型只能是ColumnNameNode、ColumnExpNode、ColumnFuncNode @ConvertColumn(index = 2) - protected ColumnNode value; // 类型只能是ColumnNameNode、ColumnExpNode、ColumnFuncNode + protected ColumnNode value; public ColumnFuncNode() {} diff --git a/src/main/java/org/redkale/source/EntityCache.java b/src/main/java/org/redkale/source/EntityCache.java index e037048b2..ef447976b 100644 --- a/src/main/java/org/redkale/source/EntityCache.java +++ b/src/main/java/org/redkale/source/EntityCache.java @@ -187,7 +187,7 @@ public final class EntityCache { List all = l; ConcurrentHashMap newmap = new ConcurrentHashMap(); if (all != null) { - all.stream().filter(x -> x != null).forEach(x -> { + all.stream().filter(Objects::nonNull).forEach(x -> { newmap.put(this.primary.get(x), x); }); }