mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
FIX: Subsequent findEach / findList does not work reliable (Regression of #2411)
This commit is contained in:
1 parent
0bb7d79015
commit
fd1b5f58bc
2 files changed
+45
-3
No files matched your search
+19
-3
@@ -276,11 +276,20 @@ public final class DefaultPersistenceContext implements SpiPersistenceContext {
|
||||
}
|
||||
|
||||
private void put(Object id, Object b) {
|
||||
Object existing;
|
||||
if (useReferences) {
|
||||
weakCount++;
|
||||
map.put(id, new BeanRef(this, id, b, queue));
|
||||
existing = map.put(id, new BeanRef(this, id, b, queue));
|
||||
} else {
|
||||
map.put(id, b);
|
||||
existing = map.put(id, b);
|
||||
}
|
||||
// when existing BeanRef is replaced, it must not be processed by the queue.
|
||||
// Removing from queue is not possible, so we set it to "dead" and skip
|
||||
// this reference in expunge. This prevents us from removing wrong keys.
|
||||
|
||||
if (existing instanceof BeanRef) {
|
||||
((BeanRef) existing).setDead();
|
||||
weakCount--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,6 +339,7 @@ public final class DefaultPersistenceContext implements SpiPersistenceContext {
|
||||
|
||||
private final ClassContext classContext;
|
||||
private final Object key;
|
||||
private boolean alive = true;
|
||||
|
||||
private BeanRef(ClassContext classContext, Object key, Object referent, ReferenceQueue<? super Object> q) {
|
||||
super(referent, q);
|
||||
@@ -337,8 +347,14 @@ public final class DefaultPersistenceContext implements SpiPersistenceContext {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
private void setDead() {
|
||||
alive = false;
|
||||
}
|
||||
|
||||
private void expunge() {
|
||||
classContext.remove(key);
|
||||
if (alive) {
|
||||
classContext.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user