This commit is contained in:
@@ -72,7 +72,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
@Resource(name = "$")
|
||||
private DataCacheListener cacheListener;
|
||||
|
||||
private final Function<Class, List> fullloader = (t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||
private final BiFunction<DataSource, Class, List> fullloader = (s, t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true);
|
||||
|
||||
public DataDefaultSource() throws IOException {
|
||||
this("");
|
||||
@@ -287,7 +287,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
}
|
||||
|
||||
private <T> EntityInfo<T> loadEntityInfo(Class<T> clazz) {
|
||||
return EntityInfo.load(clazz, this.nodeid, this.cacheForbidden, this.readPool.props, fullloader);
|
||||
return EntityInfo.load(clazz, this.nodeid, this.cacheForbidden, this.readPool.props, this, fullloader);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -990,7 +990,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
* 更新对象指定的一些字段, 必须是Entity对象
|
||||
*
|
||||
* @param <T> Entity类的泛型
|
||||
* @param bean Entity对象
|
||||
* @param bean Entity对象
|
||||
* @param columns 需要更新的字段
|
||||
*/
|
||||
@Override
|
||||
@@ -1053,7 +1053,7 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
* 更新对象指定的一些字段, 必须是Entity对象
|
||||
*
|
||||
* @param <T> Entity类的泛型
|
||||
* @param bean Entity对象
|
||||
* @param bean Entity对象
|
||||
* @param node 过滤node 不能为null
|
||||
* @param columns 需要更新的字段
|
||||
*/
|
||||
|
||||
@@ -82,7 +82,7 @@ public final class EntityCache<T> {
|
||||
public void fullLoad() {
|
||||
if (info.fullloader == null) return;
|
||||
clear();
|
||||
List<T> all = info.fullloader.apply(type);
|
||||
List<T> all = info.fullloader.apply(info.source, type);
|
||||
if (all != null) {
|
||||
all.stream().filter(x -> x != null).forEach(x -> {
|
||||
this.map.put(this.primary.get(x), x);
|
||||
|
||||
@@ -95,18 +95,20 @@ public final class EntityInfo<T> {
|
||||
|
||||
final int allocationSize;
|
||||
|
||||
final Function<Class, List> fullloader;
|
||||
final DataSource source;
|
||||
|
||||
final BiFunction<DataSource, Class, List> fullloader;
|
||||
//------------------------------------------------------------
|
||||
|
||||
public static <T> EntityInfo<T> load(Class<T> clazz, final int nodeid, final boolean cacheForbidden, final Properties conf,
|
||||
Function<Class, List> fullloader) {
|
||||
DataSource source, BiFunction<DataSource, Class, List> fullloader) {
|
||||
EntityInfo rs = entityInfos.get(clazz);
|
||||
if (rs != null) return rs;
|
||||
synchronized (entityInfos) {
|
||||
rs = entityInfos.get(clazz);
|
||||
if (rs == null) {
|
||||
if (nodeid < 0) throw new IllegalArgumentException("nodeid(" + nodeid + ") is illegal");
|
||||
rs = new EntityInfo(clazz, nodeid, cacheForbidden, conf, fullloader);
|
||||
rs = new EntityInfo(clazz, nodeid, cacheForbidden, conf, source, fullloader);
|
||||
entityInfos.put(clazz, rs);
|
||||
if (rs.cache != null) {
|
||||
if (fullloader == null) throw new IllegalArgumentException(clazz.getName() + " auto loader is illegal");
|
||||
@@ -121,8 +123,10 @@ public final class EntityInfo<T> {
|
||||
return entityInfos.get(clazz);
|
||||
}
|
||||
|
||||
private EntityInfo(Class<T> type, int nodeid, final boolean cacheForbidden, Properties conf, Function<Class, List> fullloader) {
|
||||
private EntityInfo(Class<T> type, int nodeid, final boolean cacheForbidden,
|
||||
Properties conf, DataSource source, BiFunction<DataSource, Class, List> fullloader) {
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
//---------------------------------------------
|
||||
this.nodeid = nodeid >= 0 ? nodeid : 0;
|
||||
DistributeTables dt = type.getAnnotation(DistributeTables.class);
|
||||
@@ -134,7 +138,7 @@ public final class EntityInfo<T> {
|
||||
Table t = type.getAnnotation(Table.class);
|
||||
if (type.getAnnotation(VirtualEntity.class) != null) {
|
||||
this.table = null;
|
||||
Function<Class, List> loader = null;
|
||||
BiFunction<DataSource, Class, List> loader = null;
|
||||
try {
|
||||
loader = type.getAnnotation(VirtualEntity.class).loader().newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -28,12 +28,12 @@ public @interface VirtualEntity {
|
||||
boolean direct() default false;
|
||||
|
||||
//初始化时数据的加载器
|
||||
Class<? extends Function< Class, List>> loader() default DefaultFunctionLoader.class;
|
||||
Class<? extends BiFunction<DataSource, Class, List>> loader() default DefaultFunctionLoader.class;
|
||||
|
||||
public static class DefaultFunctionLoader implements Function< Class, List> {
|
||||
public static class DefaultFunctionLoader implements BiFunction<DataSource, Class, List> {
|
||||
|
||||
@Override
|
||||
public List apply(Class u) {
|
||||
public List apply(DataSource source, Class type) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user