This commit is contained in:
RedKale
2016-04-15 14:14:21 +08:00
parent 75e8767676
commit d54070c229
3 changed files with 18 additions and 12 deletions

View File

@@ -301,7 +301,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
EntityInfo<T> info = loadEntityInfo(clazz);
EntityCache<T> cache = info.getCache();
if (cache == null) return;
cache.fullLoad(queryList(clazz, (FilterNode) null));
cache.fullLoad();
}
//----------------------insertCache-----------------------------

View File

@@ -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<T> {
});
}
public void fullLoad(List<T> all) {
if (all == null) return;
public void fullLoad() {
if (info.fullloader == null) return;
clear();
List<T> 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<T> {
collector = (Collector<T, Map, ?>) Collectors.averagingLong((T t) -> ((Number) funcAttr.get(t)).longValue());
}
break;
case COUNT: collector = (Collector<T, Map, ?>) Collectors.counting();
case COUNT:
collector = (Collector<T, Map, ?>) Collectors.counting();
break;
case DISTINCTCOUNT:
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);
}
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) {

View File

@@ -94,6 +94,8 @@ public final class EntityInfo<T> {
final AtomicLong primaryValue = new AtomicLong(0);
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,
@@ -104,11 +106,11 @@ public final class EntityInfo<T> {
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<T> {
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.fullloader = fullloader;
//---------------------------------------------
this.nodeid = nodeid >= 0 ? nodeid : 0;
DistributeTables dt = type.getAnnotation(DistributeTables.class);