mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Follow up to #2437 - Rename internal "dead/alive" to "replaced"
This commit is contained in:
+9
-12
@@ -275,20 +275,17 @@ public final class DefaultPersistenceContext implements SpiPersistenceContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void put(Object id, Object b) {
|
||||
private void put(Object id, Object bean) {
|
||||
Object existing;
|
||||
if (useReferences) {
|
||||
weakCount++;
|
||||
existing = map.put(id, new BeanRef(this, id, b, queue));
|
||||
existing = map.put(id, new BeanRef(this, id, bean, queue));
|
||||
} else {
|
||||
existing = map.put(id, b);
|
||||
existing = map.put(id, bean);
|
||||
}
|
||||
// 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();
|
||||
// when a BeanRef is replaced, its expunge() must NOT remove an entry
|
||||
((BeanRef) existing).setReplaced();
|
||||
weakCount--;
|
||||
}
|
||||
}
|
||||
@@ -339,7 +336,7 @@ public final class DefaultPersistenceContext implements SpiPersistenceContext {
|
||||
|
||||
private final ClassContext classContext;
|
||||
private final Object key;
|
||||
private boolean alive = true;
|
||||
private boolean replaced;
|
||||
|
||||
private BeanRef(ClassContext classContext, Object key, Object referent, ReferenceQueue<? super Object> q) {
|
||||
super(referent, q);
|
||||
@@ -347,12 +344,12 @@ public final class DefaultPersistenceContext implements SpiPersistenceContext {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
private void setDead() {
|
||||
alive = false;
|
||||
private void setReplaced() {
|
||||
replaced = true;
|
||||
}
|
||||
|
||||
private void expunge() {
|
||||
if (alive) {
|
||||
if (!replaced) {
|
||||
classContext.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TestPersistenceContext extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
void testReload() {
|
||||
ResetBasicData.reset();
|
||||
@@ -34,7 +33,7 @@ class TestPersistenceContext extends BaseTestCase {
|
||||
assertThat(notes.get(0).getTitle()).isEqualTo("FooBar");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
ResetBasicData.reset();
|
||||
@@ -191,10 +190,10 @@ class TestPersistenceContext extends BaseTestCase {
|
||||
assertThat(pc.toString()).contains("Customer=size:200 (0 weak)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Disabled // run manually
|
||||
@Test
|
||||
void testPcScopes_with_findEachFindList() throws InterruptedException {
|
||||
void testPcScopes_with_findEachFindList() {
|
||||
for (int i = 0; i < 5000; i++) {
|
||||
Customer c = new Customer();
|
||||
c.setName("Customer #" + i);
|
||||
@@ -203,7 +202,7 @@ class TestPersistenceContext extends BaseTestCase {
|
||||
o.setCustomer(c);
|
||||
DB.save(o);
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
try (Transaction txn = DB.beginTransaction()) {
|
||||
List<Customer> customers = new ArrayList<>();
|
||||
@@ -212,7 +211,7 @@ class TestPersistenceContext extends BaseTestCase {
|
||||
assertThat(pc.toString()).contains("Customer=size:5000 (5000 weak)");
|
||||
customers.clear();
|
||||
customers = DB.find(Customer.class).select("id").findList();
|
||||
|
||||
|
||||
assertThat(pc.toString()).contains("Customer=size:5000"); // We expect ALWAYS 5000 entries in the PC
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user