From 81da17ddd45bb493e3bfcb3aa3ab4117498b536b Mon Sep 17 00:00:00 2001 From: redkale Date: Thu, 21 Dec 2023 13:25:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DEntityCache=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=8F=8D=E4=BA=86=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/redkale/source/EntityCache.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/redkale/source/EntityCache.java b/src/main/java/org/redkale/source/EntityCache.java index 0110772d1..b5724ee7d 100644 --- a/src/main/java/org/redkale/source/EntityCache.java +++ b/src/main/java/org/redkale/source/EntityCache.java @@ -169,7 +169,7 @@ public final class EntityCache { ConcurrentHashMap newmap2 = new ConcurrentHashMap(); List all2 = info.fullLoader.apply(info.source, info).join(); if (all2 != null) { - all2.stream().filter(x -> x != null).forEach(x -> { + all2.stream().filter(Objects::nonNull).forEach(x -> { newmap2.put(this.primary.get(x), x); }); } @@ -228,7 +228,7 @@ public final class EntityCache { return null; } T rs = map.get(pk); - return rs == null ? null : (needCopy ? newCopier.apply(this.creator.create(), rs) : rs); + return rs == null ? null : (needCopy ? newCopier.apply(rs, this.creator.create()) : rs); } public T[] finds(Serializable... pks) { @@ -242,7 +242,7 @@ public final class EntityCache { T[] result = arrayer.apply(ids.length); for (int i = 0; i < result.length; i++) { T rs = map.get(ids[i]); - result[i] = rs == null ? null : (needCopy ? newCopier.apply(this.creator.create(), rs) : rs); + result[i] = rs == null ? null : (needCopy ? newCopier.apply(rs, this.creator.create()) : rs); } return result; } else if (t == long[].class) { @@ -250,7 +250,7 @@ public final class EntityCache { T[] result = arrayer.apply(ids.length); for (int i = 0; i < result.length; i++) { T rs = map.get(ids[i]); - result[i] = rs == null ? null : (needCopy ? newCopier.apply(this.creator.create(), rs) : rs); + result[i] = rs == null ? null : (needCopy ? newCopier.apply(rs, this.creator.create()) : rs); } return result; } @@ -259,7 +259,7 @@ public final class EntityCache { if (needCopy) { for (int i = 0; i < result.length; i++) { T rs = map.get(pks[i]); - result[i] = rs == null ? null : newCopier.apply(this.creator.create(), rs); + result[i] = rs == null ? null : newCopier.apply(rs, this.creator.create()); } } else { for (int i = 0; i < result.length; i++) { @@ -278,7 +278,7 @@ public final class EntityCache { return null; } if (selects == null) { - return needCopy ? newCopier.apply(this.creator.create(), rs) : rs; + return needCopy ? newCopier.apply(rs, this.creator.create()) : rs; } T t = this.creator.create(); for (Attribute attr : this.info.attributes) { @@ -317,7 +317,7 @@ public final class EntityCache { } if (selects == null) { if (needCopy) { - rs = newCopier.apply(ctr.create(), rs); + rs = newCopier.apply(rs, ctr.create()); } } else { T t = ctr.create(); @@ -344,7 +344,7 @@ public final class EntityCache { return null; } if (selects == null) { - return (needCopy ? newCopier.apply(this.creator.create(), opt.get()) : opt.get()); + return needCopy ? newCopier.apply(opt.get(), this.creator.create()) : opt.get(); } T rs = opt.get(); T t = this.creator.create(); @@ -650,7 +650,7 @@ public final class EntityCache { return defResult; } - public Number getNumberResult(final FilterFunc func, final Number defResult, final String column, final FilterNode node) { + public Number getNumberResult(final FilterFunc func, final Number defResult, final String column, final FilterNode node) { final Attribute attr = column == null ? null : info.getAttribute(column); //COUNT的column=null final Function attrFunc = attr == null ? null : x -> (Number) attr.get(x); return getNumberResult(this.list, func, defResult, attr == null ? null : attr.type(), attrFunc, node); @@ -725,7 +725,7 @@ public final class EntityCache { } final List rs = new ArrayList<>(); if (selects == null) { - Consumer action = x -> rs.add(needCopy ? newCopier.apply(creator.create(), x) : x); + Consumer action = x -> rs.add(needCopy ? newCopier.apply(x, creator.create()) : x); if (comparator != null) { stream.forEachOrdered(action); } else { @@ -761,7 +761,7 @@ public final class EntityCache { if (entity == null) { return 0; } - final T rs = newCopier.apply(this.creator.create(), entity); //确保同一主键值的map与list中的对象必须共用。 + final T rs = newCopier.apply(entity, this.creator.create()); //确保同一主键值的map与list中的对象必须共用。 T old = this.map.putIfAbsent(this.primary.get(rs), rs); if (old == null) { this.list.add(rs); @@ -825,7 +825,7 @@ public final class EntityCache { } tableLock.lock(); //表锁, 可优化成行锁 try { - this.uptCopier.apply(rs, entity); + this.uptCopier.apply(entity, rs); } finally { tableLock.unlock(); }