diff --git a/src/org/redkale/source/DataDefaultSource.java b/src/org/redkale/source/DataDefaultSource.java index 62e11e30f..cce8215ab 100644 --- a/src/org/redkale/source/DataDefaultSource.java +++ b/src/org/redkale/source/DataDefaultSource.java @@ -72,7 +72,7 @@ public final class DataDefaultSource implements DataSource, Function fullloader = (t) -> querySheet(false, false, t, null, null, (FilterNode) null).list(true); + private final BiFunction 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 EntityInfo loadEntityInfo(Class 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 Entity类的泛型 - * @param bean Entity对象 + * @param bean Entity对象 * @param columns 需要更新的字段 */ @Override @@ -1053,7 +1053,7 @@ public final class DataDefaultSource implements DataSource, Function Entity类的泛型 - * @param bean Entity对象 + * @param bean Entity对象 * @param node 过滤node 不能为null * @param columns 需要更新的字段 */ diff --git a/src/org/redkale/source/EntityCache.java b/src/org/redkale/source/EntityCache.java index 1ef00559c..846903979 100644 --- a/src/org/redkale/source/EntityCache.java +++ b/src/org/redkale/source/EntityCache.java @@ -82,7 +82,7 @@ public final class EntityCache { public void fullLoad() { if (info.fullloader == null) return; clear(); - List all = info.fullloader.apply(type); + List 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); diff --git a/src/org/redkale/source/EntityInfo.java b/src/org/redkale/source/EntityInfo.java index 04bf86e8e..7e706b9c0 100644 --- a/src/org/redkale/source/EntityInfo.java +++ b/src/org/redkale/source/EntityInfo.java @@ -95,18 +95,20 @@ public final class EntityInfo { final int allocationSize; - final Function fullloader; + final DataSource source; + + final BiFunction fullloader; //------------------------------------------------------------ public static EntityInfo load(Class clazz, final int nodeid, final boolean cacheForbidden, final Properties conf, - Function fullloader) { + DataSource source, BiFunction 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 { return entityInfos.get(clazz); } - private EntityInfo(Class type, int nodeid, final boolean cacheForbidden, Properties conf, Function fullloader) { + private EntityInfo(Class type, int nodeid, final boolean cacheForbidden, + Properties conf, DataSource source, BiFunction 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 { Table t = type.getAnnotation(Table.class); if (type.getAnnotation(VirtualEntity.class) != null) { this.table = null; - Function loader = null; + BiFunction loader = null; try { loader = type.getAnnotation(VirtualEntity.class).loader().newInstance(); } catch (Exception e) { diff --git a/src/org/redkale/source/VirtualEntity.java b/src/org/redkale/source/VirtualEntity.java index f9ded25cf..b1d95f2f6 100644 --- a/src/org/redkale/source/VirtualEntity.java +++ b/src/org/redkale/source/VirtualEntity.java @@ -28,12 +28,12 @@ public @interface VirtualEntity { boolean direct() default false; //初始化时数据的加载器 - Class> loader() default DefaultFunctionLoader.class; + Class> loader() default DefaultFunctionLoader.class; - public static class DefaultFunctionLoader implements Function< Class, List> { + public static class DefaultFunctionLoader implements BiFunction { @Override - public List apply(Class u) { + public List apply(DataSource source, Class type) { return null; } } diff --git a/test/org/redkale/source/FilterNodeTest.java b/test/org/redkale/source/FilterNodeTest.java index 02b524aef..d8435ce9e 100644 --- a/test/org/redkale/source/FilterNodeTest.java +++ b/test/org/redkale/source/FilterNodeTest.java @@ -20,11 +20,11 @@ public class FilterNodeTest { public static void main(String[] args) throws Exception { final Properties props = new Properties(); - final Function fullloader = (Class t) -> new ArrayList(); - final Function func = (Class t) -> EntityInfo.load(t, 0, false, props, fullloader); - final EntityInfo carEntity = EntityInfo.load(CarTestTable.class, 0, false, props, (t) -> CarTestTable.createList()); - final EntityInfo userEntity = EntityInfo.load(UserTestTable.class, 0, false, props, (t) -> UserTestTable.createList()); - final EntityInfo typeEntity = EntityInfo.load(CarTypeTestTable.class, 0, false, props, (t) -> CarTypeTestTable.createList()); + final BiFunction fullloader = (s, t) -> new ArrayList(); + final Function func = (Class t) -> EntityInfo.load(t, 0, false, props, null, fullloader); + final EntityInfo carEntity = EntityInfo.load(CarTestTable.class, 0, false, props, null, (s, t) -> CarTestTable.createList()); + final EntityInfo userEntity = EntityInfo.load(UserTestTable.class, 0, false, props, null, (s, t) -> UserTestTable.createList()); + final EntityInfo typeEntity = EntityInfo.load(CarTypeTestTable.class, 0, false, props, null, (s, t) -> CarTypeTestTable.createList()); final CarTestBean bean = new CarTestBean(); bean.carid = 70002; @@ -32,7 +32,7 @@ public class FilterNodeTest { bean.createtime = 500; bean.typename = "法拉利"; FilterNode joinNode1 = FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "username", LIKE, bean.username) - .or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GREATERTHAN, bean.createtime)); + .or(FilterJoinNode.create(UserTestTable.class, new String[]{"userid", "username"}, "createtime", GREATERTHAN, bean.createtime)); FilterNode joinNode2 = FilterJoinNode.create(CarTypeTestTable.class, "cartype", "typename", LIKE, bean.typename); FilterNode node = CarTestBean.caridTransient() ? (joinNode2.or(joinNode1)) : FilterNode.create("carid", GREATERTHAN, bean.carid).and(joinNode1).or(joinNode2); FilterNode beanNode = FilterNodeBean.createFilterNode(bean); diff --git a/test/org/redkale/test/source/CacheTestBean.java b/test/org/redkale/test/source/CacheTestBean.java index ec99734f3..6bb45eb03 100644 --- a/test/org/redkale/test/source/CacheTestBean.java +++ b/test/org/redkale/test/source/CacheTestBean.java @@ -6,7 +6,7 @@ package org.redkale.test.source; import java.util.*; -import java.util.function.Function; +import java.util.function.BiFunction; import javax.persistence.Id; import org.redkale.source.*; import org.redkale.util.Attribute; @@ -33,8 +33,8 @@ public class CacheTestBean { Attribute idattr = Attribute.create(CacheTestBean.class, "pkgid"); Attribute nameattr = Attribute.create(CacheTestBean.class, "name"); Attribute priceattr = Attribute.create(CacheTestBean.class, "price"); - Function fullloader = (z) -> list; - EntityCache cache = new EntityCache(EntityInfo.load(CacheTestBean.class, 0, true,new Properties(), fullloader)); + BiFunction fullloader = (s, z) -> list; + EntityCache cache = new EntityCache(EntityInfo.load(CacheTestBean.class, 0, true, new Properties(), null, fullloader)); cache.fullLoad(); System.out.println(cache.queryColumnMap("pkgid", FilterFunc.COUNT, "name", null)); diff --git a/test/org/redkale/test/source/TestSourceCache.java b/test/org/redkale/test/source/TestSourceCache.java index cf7f6e2dd..00ec9053d 100644 --- a/test/org/redkale/test/source/TestSourceCache.java +++ b/test/org/redkale/test/source/TestSourceCache.java @@ -40,7 +40,7 @@ public class TestSourceCache { } public static void main(String[] args) throws Exception { - final EntityInfo info = EntityInfo.load(TestEntity.class, 0, false,new Properties(), null); + final EntityInfo info = EntityInfo.load(TestEntity.class, 0, false, new Properties(), null, null); TestEntity[] entitys = new TestEntity[10_0000]; for (int i = 0; i < entitys.length; i++) { entitys[i] = new TestEntity(i + 1, "用户_" + (i + 1));