格式化

This commit is contained in:
redkale
2024-09-11 09:56:01 +08:00
parent 352dc9038f
commit eced5e522e
4 changed files with 83 additions and 61 deletions

View File

@@ -330,7 +330,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
*/ */
@Override @Override
public <T> void localSet(String key, Type type, T value, Duration expire) { public <T> 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 @Override
public <T> void remoteSet(final String key, final Type type, final T value, Duration expire) { public <T> 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 @Override
public <T> CompletableFuture<Void> remoteSetAsync(String key, Type type, T value, Duration expire) { public <T> CompletableFuture<Void> 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) { final String key, final Type type, final T value, Duration localExpire, Duration remoteExpire) {
checkEnable(); checkEnable();
if (localExpire != null) { if (localExpire != null) {
setCache(localSource, key, type, value, localExpire); localSetCache(key, type, value, localExpire);
} }
if (remoteExpire != null && remoteSource != null) { if (remoteExpire != null && remoteSource != null) {
setCache(remoteSource, key, type, value, remoteExpire); remoteSetCache(key, type, value, remoteExpire);
} }
if (remoteSource != null && broadcastable) { if (remoteSource != null && broadcastable) {
remoteSource.publish(getChannelTopic(), new CachedEventMessage(node, key)); 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) { String key, Type type, T value, Duration localExpire, Duration remoteExpire) {
checkEnable(); checkEnable();
if (localExpire != null) { if (localExpire != null) {
setCache(localSource, key, type, value, localExpire); localSetCache(key, type, value, localExpire);
} }
CompletableFuture<Void> future = CompletableFuture.completedFuture(null); CompletableFuture<Void> future = CompletableFuture.completedFuture(null);
if (remoteSource != null && remoteExpire != null) { if (remoteSource != null && remoteExpire != null) {
future = setCacheAsync(remoteSource, key, type, value, remoteExpire); future = remoteSetCacheAsync(key, type, value, remoteExpire);
} }
if (remoteSource != null && broadcastable) { if (remoteSource != null && broadcastable) {
future = future.thenCompose(r -> remoteSource future = future.thenCompose(r -> remoteSource
@@ -824,69 +824,88 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
}); });
} }
protected <T> void localSetCache(String key, Type type, T value, Duration expire) {
localSetCache(key, expire, loadCacheType(type, value), CachedValue.create(value));
}
protected <T> void localSetCache(String key, Duration expire, Type cacheType, CachedValue<T> 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 <T> void remoteSetCache(String key, Type type, T value, Duration expire) {
remoteSetCache(key, expire, loadCacheType(type, value), CachedValue.create(value));
}
protected <T> void remoteSetCache(String key, Duration expire, Type cacheType, CachedValue<T> 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 <T> CompletableFuture<Void> localSetCacheAsync(String key, Type type, T value, Duration expire) {
return localSetCacheAsync(key, expire, loadCacheType(type, value), CachedValue.create(value));
}
protected <T> CompletableFuture<Void> localSetCacheAsync( protected <T> CompletableFuture<Void> localSetCacheAsync(
String key, Duration expire, Type cacheType, CachedValue<T> cacheVal) { String key, Duration expire, Type cacheType, CachedValue<T> 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 <T> CompletableFuture<Void> remoteSetCacheAsync(String key, Type type, T value, Duration expire) {
return remoteSetCacheAsync(key, expire, loadCacheType(type, value), CachedValue.create(value));
} }
protected <T> CompletableFuture<Void> remoteSetCacheAsync( protected <T> CompletableFuture<Void> remoteSetCacheAsync(
String key, Duration expire, Type cacheType, CachedValue<T> cacheVal) { String key, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
return setCacheAsync(remoteSource, key, expire, cacheType, cacheVal);
}
protected <T> void localSetCache(String key, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
setCache(localSource, key, expire, cacheType, cacheVal);
}
protected <T> void remoteSetCache(String key, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
setCache(remoteSource, key, expire, cacheType, cacheVal);
}
protected <T> void setCache(
CacheSource source, String key, Duration expire, Type cacheType, CachedValue<T> 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 <T> CompletableFuture<Void> setCacheAsync(
CacheSource source, String key, Duration expire, Type cacheType, CachedValue<T> cacheVal) {
checkEnable(); checkEnable();
boolean logable = logger.isLoggable(logLevel); boolean logable = logger.isLoggable(logLevel);
Objects.requireNonNull(expire); Objects.requireNonNull(expire);
String id = idFor(key); String id = idFor(key);
long millis = expire.toMillis(); long millis = expire.toMillis();
if (logable) { if (logable) {
String s = source == localSource ? "localSource" : "remoteSource"; logger.log(logLevel, "Cached set id(" + id + ") value to remoteSource expire " + millis + " ms");
logger.log(logLevel, "Cached set id(" + id + ") value to " + s + " expire " + millis + " ms");
} }
if (millis > 0) { if (millis > 0) {
return source.psetexAsync(id, millis, cacheType, cacheVal); return remoteSource.psetexAsync(id, millis, cacheType, cacheVal);
} else { } else {
return source.setAsync(id, cacheType, cacheVal); return remoteSource.setAsync(id, cacheType, cacheVal);
} }
} }
protected <T> void setCache(CacheSource source, String key, Type type, T value, Duration expire) {
setCache(source, key, expire, loadCacheType(type, value), CachedValue.create(value));
}
protected <T> CompletableFuture<Void> setCacheAsync(
CacheSource source, String key, Type type, T value, Duration expire) {
return setCacheAsync(source, key, expire, loadCacheType(type, value), CachedValue.create(value));
}
protected <T> CachedValue<T> bothGetCache(final String key, final Duration expire, final Type cacheType) { protected <T> CachedValue<T> bothGetCache(final String key, final Duration expire, final Type cacheType) {
checkEnable(); checkEnable();
boolean logable = logger.isLoggable(logLevel); boolean logable = logger.isLoggable(logLevel);
@@ -905,7 +924,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
if (logable) { if (logable) {
logger.log(logLevel, "Cached set id(" + id + ") value to localSource from remoteSource"); 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) { if (logable) {
logger.log(logLevel, "Cached got id(" + id + ") value from remoteSource"); logger.log(logLevel, "Cached got id(" + id + ") value from remoteSource");
@@ -945,7 +964,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
if (logable) { if (logable) {
logger.log(logLevel, "Cached set id(" + id + ") value to localSource from remoteSource"); 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) { if (logable) {
logger.log(logLevel, "Cached got id(" + id + ") value from remoteSource"); logger.log(logLevel, "Cached got id(" + id + ") value from remoteSource");

View File

@@ -5,10 +5,9 @@
*/ */
package org.redkale.source; package org.redkale.source;
import static org.redkale.source.ColumnExpress.*;
import java.io.Serializable; import java.io.Serializable;
import org.redkale.convert.ConvertColumn; import org.redkale.convert.ConvertColumn;
import static org.redkale.source.ColumnExpress.*;
/** /**
* 作为ColumnValue的value字段值用于复杂的字段表达式 。 <br> * 作为ColumnValue的value字段值用于复杂的字段表达式 。 <br>
@@ -27,14 +26,17 @@ import org.redkale.convert.ConvertColumn;
*/ */
public class ColumnExpNode implements ColumnNode { public class ColumnExpNode implements ColumnNode {
// 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode
@ConvertColumn(index = 1) @ConvertColumn(index = 1)
protected ColumnNode left; // 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode protected ColumnNode left;
// SET时left必须是ColumnNameNode, right必须是null
@ConvertColumn(index = 2) @ConvertColumn(index = 2)
protected ColumnExpress express; // SET时left必须是ColumnNameNode, right必须是null protected ColumnExpress express;
// 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode
@ConvertColumn(index = 3) @ConvertColumn(index = 3)
protected ColumnNode right; // 类型只能是ColumnNameNode、ColumnNumberNode、ColumnExpNode protected ColumnNode right;
public ColumnExpNode() {} public ColumnExpNode() {}

View File

@@ -21,8 +21,9 @@ public class ColumnFuncNode implements ColumnNode {
@ConvertColumn(index = 1) @ConvertColumn(index = 1)
protected FilterFunc func; protected FilterFunc func;
// 类型只能是ColumnNameNode、ColumnExpNode、ColumnFuncNode
@ConvertColumn(index = 2) @ConvertColumn(index = 2)
protected ColumnNode value; // 类型只能是ColumnNameNode、ColumnExpNode、ColumnFuncNode protected ColumnNode value;
public ColumnFuncNode() {} public ColumnFuncNode() {}

View File

@@ -187,7 +187,7 @@ public final class EntityCache<T> {
List<T> all = l; List<T> all = l;
ConcurrentHashMap newmap = new ConcurrentHashMap(); ConcurrentHashMap newmap = new ConcurrentHashMap();
if (all != null) { 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); newmap.put(this.primary.get(x), x);
}); });
} }