diff --git a/src/org/redkale/source/DataDefaultSource.java b/src/org/redkale/source/DataDefaultSource.java index 710a9f570..3ad5c9419 100644 --- a/src/org/redkale/source/DataDefaultSource.java +++ b/src/org/redkale/source/DataDefaultSource.java @@ -301,7 +301,7 @@ public final class DataDefaultSource implements DataSource, Function info = loadEntityInfo(clazz); EntityCache cache = info.getCache(); if (cache == null) return; - cache.fullLoad(queryList(clazz, (FilterNode) null)); + cache.fullLoad(); } //----------------------insertCache----------------------------- diff --git a/src/org/redkale/source/EntityCache.java b/src/org/redkale/source/EntityCache.java index c04cca3d8..a00e75e14 100644 --- a/src/org/redkale/source/EntityCache.java +++ b/src/org/redkale/source/EntityCache.java @@ -5,15 +5,14 @@ */ package org.redkale.source; -import java.io.*; +import java.io.Serializable; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.logging.*; -import java.util.stream.Stream; +import java.util.stream.*; import javax.persistence.Transient; import static org.redkale.source.FilterFunc.*; -import java.util.stream.*; import org.redkale.util.*; /** @@ -64,9 +63,10 @@ public final class EntityCache { }); } - public void fullLoad(List all) { - if (all == null) return; + public void fullLoad() { + if (info.fullloader == null) return; clear(); + List all = info.fullloader.apply(type); all.stream().filter(x -> x != null).forEach(x -> { this.map.put(this.primary.get(x), x); }); @@ -169,7 +169,8 @@ public final class EntityCache { collector = (Collector) Collectors.averagingLong((T t) -> ((Number) funcAttr.get(t)).longValue()); } break; - case COUNT: collector = (Collector) Collectors.counting(); + case COUNT: + collector = (Collector) Collectors.counting(); break; case DISTINCTCOUNT: collector = (Collector) Collectors.mapping((t) -> funcAttr.get(t), Collectors.toSet()); @@ -221,8 +222,10 @@ public final class EntityCache { return stream.mapToDouble(x -> (Double) attr.get(x)).average().orElse(0); } throw new RuntimeException("getNumberResult error(type:" + type + ", attr.declaringClass: " + attr.declaringClass() + ", attr.field: " + attr.field() + ", attr.type: " + attr.type()); - case COUNT: return stream.count(); - case DISTINCTCOUNT: return stream.map(x -> attr.get(x)).distinct().count(); + case COUNT: + return stream.count(); + case DISTINCTCOUNT: + return stream.map(x -> attr.get(x)).distinct().count(); case MAX: if (attr.type() == int.class || attr.type() == Integer.class) { diff --git a/src/org/redkale/source/EntityInfo.java b/src/org/redkale/source/EntityInfo.java index f5e8370ac..4e45ef0ba 100644 --- a/src/org/redkale/source/EntityInfo.java +++ b/src/org/redkale/source/EntityInfo.java @@ -94,6 +94,8 @@ public final class EntityInfo { final AtomicLong primaryValue = new AtomicLong(0); final int allocationSize; + + final Function fullloader; //------------------------------------------------------------ public static EntityInfo load(Class clazz, final int nodeid, final boolean cacheForbidden, final Properties conf, @@ -104,11 +106,11 @@ public final class EntityInfo { rs = entityInfos.get(clazz); if (rs == null) { if (nodeid < 0) throw new IllegalArgumentException("nodeid(" + nodeid + ") is illegal"); - rs = new EntityInfo(clazz, nodeid, cacheForbidden, conf); + rs = new EntityInfo(clazz, nodeid, cacheForbidden, conf, fullloader); entityInfos.put(clazz, rs); if (rs.cache != null) { if (fullloader == null) throw new IllegalArgumentException(clazz.getName() + " auto loader is illegal"); - rs.cache.fullLoad(fullloader.apply(clazz)); + rs.cache.fullLoad(); } } return rs; @@ -119,8 +121,9 @@ public final class EntityInfo { return entityInfos.get(clazz); } - private EntityInfo(Class type, int nodeid, final boolean cacheForbidden, Properties conf) { + private EntityInfo(Class type, int nodeid, final boolean cacheForbidden, Properties conf, Function fullloader) { this.type = type; + this.fullloader = fullloader; //--------------------------------------------- this.nodeid = nodeid >= 0 ? nodeid : 0; DistributeTables dt = type.getAnnotation(DistributeTables.class);