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