mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1922 - Performance - Too pessimistic synchronized block for lazy loading on reference bean or l2 cache bean
This commit is contained in:
@@ -323,10 +323,6 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
public void loadMany(BeanCollection<?> collection, boolean onlyIds) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBean(EntityBeanIntercept ebi) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(boolean shutdownDataSource, boolean deregisterDriver) {
|
||||
}
|
||||
|
||||
+10
-6
@@ -3,13 +3,17 @@ package io.ebeaninternal.server.deploy;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.Ebean;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestReferenceWithConstructorProperties extends BaseTestCase {
|
||||
|
||||
/**
|
||||
@@ -24,14 +28,14 @@ public class TestReferenceWithConstructorProperties extends BaseTestCase {
|
||||
BeanState beanState = Ebean.getBeanState(order);
|
||||
Set<String> loadedProps = beanState.getLoadedProps();
|
||||
|
||||
Assert.assertEquals(1, loadedProps.size());
|
||||
Assert.assertTrue(beanState.isReference());
|
||||
assertEquals(1, loadedProps.size());
|
||||
assertTrue(beanState.isReference());
|
||||
|
||||
// read the status invokes lazy loading
|
||||
order.getStatus();
|
||||
|
||||
Assert.assertFalse(beanState.isReference());
|
||||
|
||||
assertFalse(beanState.isReference());
|
||||
assertNotNull(order.getCustomer());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-4
@@ -9,16 +9,24 @@ import io.ebean.Update;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import io.ebean.cache.ServerCacheManager;
|
||||
import io.ebeaninternal.server.cache.CachedManyIds;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.*;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Country;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.OBeanChild;
|
||||
import org.tests.model.basic.OCachedBean;
|
||||
import org.tests.model.basic.OCachedBeanChild;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.OrderDetail;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestCacheCollectionIds extends BaseTestCase {
|
||||
@@ -88,7 +96,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
||||
List<Contact> contacts2 = customer2.getContacts();
|
||||
|
||||
for (Contact contact : contacts2) {
|
||||
contact.getFirstName();
|
||||
assertNotNull(contact.getFirstName());
|
||||
contact.getEmail();
|
||||
}
|
||||
return contacts2.size();
|
||||
@@ -297,7 +305,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
||||
// assert that the cache contains the expected entry
|
||||
assertEquals("countries cache now loaded with 1 entry", 1, cachedBeanCountriesCache.size());
|
||||
CachedManyIds dummyEntry = (CachedManyIds) cachedBeanCountriesCache.get(dummyLoad.getId());
|
||||
Assert.assertNotNull(dummyEntry);
|
||||
assertNotNull(dummyEntry);
|
||||
assertEquals("2 ids in the entry", 2, dummyEntry.getIdList().size());
|
||||
assertTrue(dummyEntry.getIdList().contains("NZ"));
|
||||
assertTrue(dummyEntry.getIdList().contains("AU"));
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.tests.model.basic.FeatureDescription;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestL2CacheWithSharedBean extends BaseTestCase {
|
||||
|
||||
private TunedQueryInfo createTunedQueryInfo(OrmQueryDetail tunedDetail) {
|
||||
@@ -25,7 +27,7 @@ public class TestL2CacheWithSharedBean extends BaseTestCase {
|
||||
|
||||
FeatureDescription f1 = new FeatureDescription();
|
||||
f1.setName("one");
|
||||
f1.setDescription(null);
|
||||
f1.setDescription("helloOne");
|
||||
|
||||
Ebean.save(f1);
|
||||
|
||||
@@ -44,19 +46,20 @@ public class TestL2CacheWithSharedBean extends BaseTestCase {
|
||||
|
||||
FeatureDescription fd2 = query.findOne(); // LOAD cache
|
||||
|
||||
fd2.getDescription(); // invoke lazy load (this fails)
|
||||
String description0 = fd2.getDescription(); // invoke lazy load
|
||||
assertEquals("helloOne", description0);
|
||||
|
||||
// load the cache
|
||||
FeatureDescription fetchOne = Ebean.find(FeatureDescription.class, f1.getId());
|
||||
Assert.assertNotNull(fetchOne);
|
||||
Assert.assertEquals(1, beanCache.getStatistics(false).getSize());
|
||||
assertEquals(1, beanCache.getStatistics(false).getSize());
|
||||
|
||||
FeatureDescription fetchTwo = Ebean.find(FeatureDescription.class, f1.getId());
|
||||
FeatureDescription fetchThree = Ebean.find(FeatureDescription.class, f1.getId());
|
||||
Assert.assertSame(fetchTwo, fetchThree);
|
||||
|
||||
String description = fetchThree.getDescription();
|
||||
Assert.assertNull(description);
|
||||
String description1 = fetchThree.getDescription();
|
||||
assertEquals("helloOne", description1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user