mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
#2931 - Fix for Ebean Redis - Failed to decode cache data for UUID as Id
This commit is contained in:
1 parent
dce6a3e9e1
commit
130e9451f4
8 files changed
+71
-76
No files matched your search
@@ -120,7 +120,7 @@ public final class LoadManyRequest extends LoadRequest {
|
|||||||
log.log(DEBUG, "BeanCollection after lazy load was empty. type:{0} id:{1} owner:{2}", ownerBean.getClass().getName(), parentId, ownerBean);
|
log.log(DEBUG, "BeanCollection after lazy load was empty. type:{0} id:{1} owner:{2}", ownerBean.getClass().getName(), parentId, ownerBean);
|
||||||
}
|
}
|
||||||
} else if (loadCache && many.isUseCache()) {
|
} else if (loadCache && many.isUseCache()) {
|
||||||
desc.cacheManyPropPut(many, bc, desc.getId(bc.getOwnerBean()));
|
desc.cacheManyPropPut(many, bc, desc.cacheKeyForBean(bc.getOwnerBean()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -91,15 +91,15 @@ public final class CacheChangeSet {
|
|||||||
/**
|
/**
|
||||||
* Add many property remove.
|
* Add many property remove.
|
||||||
*/
|
*/
|
||||||
public <T> void addManyRemove(BeanDescriptor<T> desc, String manyProperty, Object parentId) {
|
public <T> void addManyRemove(BeanDescriptor<T> desc, String manyProperty, String parentKey) {
|
||||||
many(desc, manyProperty).addRemove(parentId);
|
many(desc, manyProperty).addRemove(parentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add many property put.
|
* Add many property put.
|
||||||
*/
|
*/
|
||||||
public <T> void addManyPut(BeanDescriptor<T> desc, String manyProperty, Object parentId, CachedManyIds entry) {
|
public <T> void addManyPut(BeanDescriptor<T> desc, String manyProperty, String parentKey, CachedManyIds entry) {
|
||||||
many(desc, manyProperty).addPut(parentId, entry);
|
many(desc, manyProperty).addPut(parentKey, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,8 +164,8 @@ public final class CacheChangeSet {
|
|||||||
private static final class ManyChange implements CacheChange {
|
private static final class ManyChange implements CacheChange {
|
||||||
|
|
||||||
final ManyKey key;
|
final ManyKey key;
|
||||||
final Set<Object> removes = new HashSet<>();
|
final Set<String> removes = new HashSet<>();
|
||||||
final Map<Object, CachedManyIds> puts = new LinkedHashMap<>();
|
final Map<String, CachedManyIds> puts = new LinkedHashMap<>();
|
||||||
boolean clear;
|
boolean clear;
|
||||||
|
|
||||||
ManyChange(ManyKey key) {
|
ManyChange(ManyKey key) {
|
||||||
@@ -183,17 +183,17 @@ public final class CacheChangeSet {
|
|||||||
/**
|
/**
|
||||||
* Remove entry for the given parentId.
|
* Remove entry for the given parentId.
|
||||||
*/
|
*/
|
||||||
void addRemove(Object parentId) {
|
void addRemove(String parentKey) {
|
||||||
if (!clear) {
|
if (!clear) {
|
||||||
removes.add(parentId);
|
removes.add(parentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put entry for the given parentId.
|
* Put entry for the given parentId.
|
||||||
*/
|
*/
|
||||||
void addPut(Object parentId, CachedManyIds entry) {
|
void addPut(String parentKey, CachedManyIds entry) {
|
||||||
puts.put(parentId, entry);
|
puts.put(parentKey, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,11 +201,11 @@ public final class CacheChangeSet {
|
|||||||
if (clear) {
|
if (clear) {
|
||||||
key.cacheClear();
|
key.cacheClear();
|
||||||
} else {
|
} else {
|
||||||
for (Map.Entry<Object, CachedManyIds> entry : puts.entrySet()) {
|
for (Map.Entry<String, CachedManyIds> entry : puts.entrySet()) {
|
||||||
key.cachePut(entry.getKey(), entry.getValue());
|
key.cachePut(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
for (Object parentId : removes) {
|
for (String parentKey : removes) {
|
||||||
key.cacheRemove(parentId);
|
key.cacheRemove(parentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,12 +241,12 @@ public final class CacheChangeSet {
|
|||||||
desc.cacheManyPropClear(manyProperty);
|
desc.cacheManyPropClear(manyProperty);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cachePut(Object parentId, CachedManyIds entry) {
|
void cachePut(String parentKey, CachedManyIds entry) {
|
||||||
desc.cacheManyPropPut(manyProperty, parentId, entry);
|
desc.cacheManyPropPut(manyProperty, parentKey, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cacheRemove(Object parentId) {
|
void cacheRemove(String parentKey) {
|
||||||
desc.cacheManyPropRemove(manyProperty, parentId);
|
desc.cacheManyPropRemove(manyProperty, parentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,8 @@ final class DefaultBeanLoader {
|
|||||||
if (ebi.isReadOnly()) {
|
if (ebi.isReadOnly()) {
|
||||||
readOnly = Boolean.TRUE;
|
readOnly = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
if (parentDesc.cacheManyPropLoad(many, beanCollection, parentId, readOnly)) {
|
final String parentKey = parentDesc.cacheKey(parentId);
|
||||||
|
if (parentDesc.cacheManyPropLoad(many, beanCollection, parentKey, readOnly)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,7 +114,8 @@ final class DefaultBeanLoader {
|
|||||||
log.log(DEBUG, "BeanCollection after load was empty. Owner:{0}", beanCollection.getOwnerBean());
|
log.log(DEBUG, "BeanCollection after load was empty. Owner:{0}", beanCollection.getOwnerBean());
|
||||||
}
|
}
|
||||||
} else if (useManyIdCache) {
|
} else if (useManyIdCache) {
|
||||||
parentDesc.cacheManyPropPut(many, beanCollection, parentId);
|
final String parentKey = parentDesc.cacheKey(parentId);
|
||||||
|
parentDesc.cacheManyPropPut(many, beanCollection, parentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1202,26 +1202,26 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
|||||||
/**
|
/**
|
||||||
* Try to load the beanCollection from cache return true if successful.
|
* Try to load the beanCollection from cache return true if successful.
|
||||||
*/
|
*/
|
||||||
public boolean cacheManyPropLoad(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId, Boolean readOnly) {
|
public boolean cacheManyPropLoad(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, String parentKey, Boolean readOnly) {
|
||||||
return cacheHelp.manyPropLoad(many, bc, parentId, readOnly);
|
return cacheHelp.manyPropLoad(many, bc, parentKey, readOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put the beanCollection into the cache.
|
* Put the beanCollection into the cache.
|
||||||
*/
|
*/
|
||||||
public void cacheManyPropPut(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId) {
|
public void cacheManyPropPut(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, String parentKey) {
|
||||||
cacheHelp.manyPropPut(many, bc, parentId);
|
cacheHelp.manyPropPut(many, bc, parentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the bean collection entry in the cache.
|
* Update the bean collection entry in the cache.
|
||||||
*/
|
*/
|
||||||
public void cacheManyPropPut(String name, Object parentId, CachedManyIds entry) {
|
public void cacheManyPropPut(String name, String parentKey, CachedManyIds entry) {
|
||||||
cacheHelp.cachePutManyIds(parentId, name, entry);
|
cacheHelp.cachePutManyIds(name, parentKey, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cacheManyPropRemove(String propertyName, Object parentId) {
|
public void cacheManyPropRemove(String propertyName, String parentKey) {
|
||||||
cacheHelp.manyPropRemove(propertyName, parentId);
|
cacheHelp.manyPropRemove(propertyName, parentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cacheManyPropClear(String propertyName) {
|
public void cacheManyPropClear(String propertyName) {
|
||||||
@@ -2096,7 +2096,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
|||||||
/**
|
/**
|
||||||
* Return the cache key for the given bean (based on id value).
|
* Return the cache key for the given bean (based on id value).
|
||||||
*/
|
*/
|
||||||
String cacheKeyForBean(EntityBean bean) {
|
public String cacheKeyForBean(EntityBean bean) {
|
||||||
return cacheKey(idProperty.getValue(bean));
|
return cacheKey(idProperty.getValue(bean));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2112,11 +2112,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
|
|||||||
return getId((EntityBean) bean);
|
return getId((EntityBean) bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public Object beanId(T bean) {
|
|
||||||
// return getId((EntityBean) bean);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Id value for the bean with embeddedId beans converted into maps.
|
* Return the Id value for the bean with embeddedId beans converted into maps.
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
+19
-19
@@ -226,13 +226,12 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
queryCache.put(id, entry);
|
queryCache.put(id, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void manyPropRemove(String propertyName, String parentKey) {
|
||||||
void manyPropRemove(String propertyName, Object parentId) {
|
|
||||||
ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
|
ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
|
||||||
if (manyLog.isLoggable(TRACE)) {
|
if (manyLog.isLoggable(TRACE)) {
|
||||||
manyLog.log(TRACE, " REMOVE {0}({1}).{2}", cacheName, parentId, propertyName);
|
manyLog.log(TRACE, " REMOVE {0}({1}).{2}", cacheName, parentKey, propertyName);
|
||||||
}
|
}
|
||||||
collectionIdsCache.remove(parentId);
|
collectionIdsCache.remove(parentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manyPropClear(String propertyName) {
|
void manyPropClear(String propertyName) {
|
||||||
@@ -246,15 +245,15 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
/**
|
/**
|
||||||
* Return the CachedManyIds for a given bean many property. Returns null if not in the cache.
|
* Return the CachedManyIds for a given bean many property. Returns null if not in the cache.
|
||||||
*/
|
*/
|
||||||
private CachedManyIds manyPropGet(Object parentId, String propertyName) {
|
private CachedManyIds manyPropGet(String propertyName, String parentKey) {
|
||||||
ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
|
ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName);
|
||||||
CachedManyIds entry = (CachedManyIds) collectionIdsCache.get(parentId);
|
CachedManyIds entry = (CachedManyIds) collectionIdsCache.get(parentKey);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
if (manyLog.isLoggable(TRACE)) {
|
if (manyLog.isLoggable(TRACE)) {
|
||||||
manyLog.log(TRACE, " GET {0}({1}).{2} - cache miss", cacheName, parentId, propertyName);
|
manyLog.log(TRACE, " GET {0}({1}).{2} - cache miss", cacheName, parentKey, propertyName);
|
||||||
}
|
}
|
||||||
} else if (manyLog.isLoggable(DEBUG)) {
|
} else if (manyLog.isLoggable(DEBUG)) {
|
||||||
manyLog.log(DEBUG, " GET {0}({1}).{2} - hit", cacheName, parentId, propertyName);
|
manyLog.log(DEBUG, " GET {0}({1}).{2} - hit", cacheName, parentKey, propertyName);
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@@ -262,12 +261,12 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
/**
|
/**
|
||||||
* Try to load the bean collection from cache return true if successful.
|
* Try to load the bean collection from cache return true if successful.
|
||||||
*/
|
*/
|
||||||
boolean manyPropLoad(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, Object parentId, Boolean readOnly) {
|
boolean manyPropLoad(BeanPropertyAssocMany<?> many, BeanCollection<?> bc, String parentKey, Boolean readOnly) {
|
||||||
if (many.isElementCollection()) {
|
if (many.isElementCollection()) {
|
||||||
// held as part of the bean cache so skip
|
// held as part of the bean cache so skip
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CachedManyIds entry = manyPropGet(parentId, many.name());
|
CachedManyIds entry = manyPropGet(many.name(), parentKey);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
// not in cache so return unsuccessful
|
// not in cache so return unsuccessful
|
||||||
return false;
|
return false;
|
||||||
@@ -293,9 +292,9 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
/**
|
/**
|
||||||
* Put the beanCollection into the cache.
|
* Put the beanCollection into the cache.
|
||||||
*/
|
*/
|
||||||
void manyPropPut(BeanPropertyAssocMany<?> many, Object details, Object parentId) {
|
void manyPropPut(BeanPropertyAssocMany<?> many, Object details, String parentKey) {
|
||||||
if (many.isElementCollection()) {
|
if (many.isElementCollection()) {
|
||||||
CachedBeanData data = (CachedBeanData) beanCache.get(parentId);
|
CachedBeanData data = (CachedBeanData) beanCache.get(parentKey);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
try {
|
try {
|
||||||
// add as JSON to bean cache
|
// add as JSON to bean cache
|
||||||
@@ -305,9 +304,9 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
|
|
||||||
CachedBeanData newData = data.update(changes, data.getVersion());
|
CachedBeanData newData = data.update(changes, data.getVersion());
|
||||||
if (beanLog.isLoggable(DEBUG)) {
|
if (beanLog.isLoggable(DEBUG)) {
|
||||||
beanLog.log(DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, parentId, changes);
|
beanLog.log(DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, parentKey, changes);
|
||||||
}
|
}
|
||||||
beanCache.put(parentId, newData);
|
beanCache.put(parentKey, newData);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.log(ERROR, "Error updating L2 cache", e);
|
log.log(ERROR, "Error updating L2 cache", e);
|
||||||
}
|
}
|
||||||
@@ -315,17 +314,17 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
} else {
|
} else {
|
||||||
CachedManyIds entry = createManyIds(many, details);
|
CachedManyIds entry = createManyIds(many, details);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
cachePutManyIds(parentId, many.name(), entry);
|
cachePutManyIds(many.name(), parentKey, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cachePutManyIds(Object parentId, String manyName, CachedManyIds entry) {
|
void cachePutManyIds(String manyName, String parentKey, CachedManyIds entry) {
|
||||||
ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, manyName);
|
ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, manyName);
|
||||||
if (manyLog.isLoggable(DEBUG)) {
|
if (manyLog.isLoggable(DEBUG)) {
|
||||||
manyLog.log(DEBUG, " PUT {0}({1}).{2} - ids:{3}", cacheName, parentId, manyName, entry);
|
manyLog.log(DEBUG, " PUT {0}({1}).{2} - ids:{3}", cacheName, parentKey, manyName, entry);
|
||||||
}
|
}
|
||||||
collectionIdsCache.put(parentId, entry);
|
collectionIdsCache.put(parentKey, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CachedManyIds createManyIds(BeanPropertyAssocMany<?> many, Object details) {
|
private CachedManyIds createManyIds(BeanPropertyAssocMany<?> many, Object details) {
|
||||||
@@ -828,7 +827,8 @@ final class BeanDescriptorCacheHelp<T> {
|
|||||||
Object details = many.getValue(updateRequest.entityBean());
|
Object details = many.getValue(updateRequest.entityBean());
|
||||||
CachedManyIds entry = createManyIds(many, details);
|
CachedManyIds entry = createManyIds(many, details);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
changeSet.addManyPut(desc, many.name(), id, entry);
|
final String parentKey = desc.cacheKey(id);
|
||||||
|
changeSet.addManyPut(desc, many.name(), parentKey, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,8 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
|||||||
if (assocBean != null) {
|
if (assocBean != null) {
|
||||||
Object parentId = targetDescriptor.id(assocBean);
|
Object parentId = targetDescriptor.id(assocBean);
|
||||||
if (parentId != null) {
|
if (parentId != null) {
|
||||||
changeSet.addManyRemove(targetDescriptor, relationshipProperty.name(), parentId);
|
final String parentKey = targetDescriptor.cacheKey(parentId);
|
||||||
|
changeSet.addManyRemove(targetDescriptor, relationshipProperty.name(), parentKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,8 @@ final class DLoadManyContext extends DLoadBaseContext implements LoadManyContext
|
|||||||
EntityBean ownerBean = bc.getOwnerBean();
|
EntityBean ownerBean = bc.getOwnerBean();
|
||||||
BeanDescriptor<?> parentDesc = context.desc.descriptor(ownerBean.getClass());
|
BeanDescriptor<?> parentDesc = context.desc.descriptor(ownerBean.getClass());
|
||||||
Object parentId = parentDesc.getId(ownerBean);
|
Object parentId = parentDesc.getId(ownerBean);
|
||||||
if (parentDesc.cacheManyPropLoad(context.property, bc, parentId, context.parent.isReadOnly())) {
|
final String parentKey = parentDesc.cacheKey(parentId);
|
||||||
|
if (parentDesc.cacheManyPropLoad(context.property, bc, parentKey, context.parent.isReadOnly())) {
|
||||||
// we loaded the bean collection from cache so remove it from the buffer
|
// we loaded the bean collection from cache so remove it from the buffer
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
// find it using instance equality - avoiding equals() and potential deadlock issue
|
// find it using instance equality - avoiding equals() and potential deadlock issue
|
||||||
|
|||||||
@@ -14,13 +14,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class TestCacheCollectionIds extends BaseTestCase {
|
class TestCacheCollectionIds extends BaseTestCase {
|
||||||
|
|
||||||
private ServerCacheManager cacheManager = DB.cacheManager();
|
private final ServerCacheManager cacheManager = DB.cacheManager();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
void test() {
|
||||||
|
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
awaitL2Cache();
|
awaitL2Cache();
|
||||||
|
|
||||||
@@ -75,7 +74,6 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int fetchCustomer(Integer id) {
|
private int fetchCustomer(Integer id) {
|
||||||
|
|
||||||
Customer customer2 = DB.find(Customer.class, id);
|
Customer customer2 = DB.find(Customer.class, id);
|
||||||
|
|
||||||
List<Contact> contacts2 = customer2.getContacts();
|
List<Contact> contacts2 = customer2.getContacts();
|
||||||
@@ -91,7 +89,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
* When updating a ManyToMany relations also the collection cache must be updated.
|
* When updating a ManyToMany relations also the collection cache must be updated.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdatingCollectionCacheForManyToManyRelations() {
|
void testUpdatingCollectionCacheForManyToManyRelations() {
|
||||||
// arrange
|
// arrange
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
@@ -107,7 +105,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
dummyToLoad.getCountries().size();
|
dummyToLoad.getCountries().size();
|
||||||
|
|
||||||
ServerCache cachedBeanCountriesCache = cacheManager.collectionIdsCache(OCachedBean.class, "countries");
|
ServerCache cachedBeanCountriesCache = cacheManager.collectionIdsCache(OCachedBean.class, "countries");
|
||||||
CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(cachedBean.getId());
|
CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(String.valueOf(cachedBean.getId()));
|
||||||
|
|
||||||
// confirm the starting data and cache entry
|
// confirm the starting data and cache entry
|
||||||
assertEquals(2, dummyToLoad.getCountries().size());
|
assertEquals(2, dummyToLoad.getCountries().size());
|
||||||
@@ -124,7 +122,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
|
|
||||||
// Get the data to assert/check against
|
// Get the data to assert/check against
|
||||||
OCachedBean result = DB.find(OCachedBean.class, cachedBean.getId());
|
OCachedBean result = DB.find(OCachedBean.class, cachedBean.getId());
|
||||||
cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(result.getId());
|
cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(String.valueOf(result.getId()));
|
||||||
|
|
||||||
// assert that data and cache both show correct data
|
// assert that data and cache both show correct data
|
||||||
assertEquals(1, result.getCountries().size());
|
assertEquals(1, result.getCountries().size());
|
||||||
@@ -134,7 +132,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChangingCollectionByEditingConnectedCachedBean() {
|
void testChangingCollectionByEditingConnectedCachedBean() {
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
OCachedBean cachedBean = new OCachedBean();
|
OCachedBean cachedBean = new OCachedBean();
|
||||||
@@ -174,7 +172,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChangingCollectionByEditingConnectedNotCachedBean() {
|
void testChangingCollectionByEditingConnectedNotCachedBean() {
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
OCachedBean cachedBean = new OCachedBean();
|
OCachedBean cachedBean = new OCachedBean();
|
||||||
@@ -213,13 +211,12 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
DB.delete(cachedBean);
|
DB.delete(cachedBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When updating a ManyToMany relations also the collection cache must be updated.
|
* When updating a ManyToMany relations also the collection cache must be updated.
|
||||||
* Alternate to above test where in this case the bean is dirty - loadedBean.setName("goodbye");.
|
* Alternate to above test where in this case the bean is dirty - loadedBean.setName("goodbye");.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdatingCollectionCacheForManyToManyRelationsWithUpdatedBean() {
|
void testUpdatingCollectionCacheForManyToManyRelationsWithUpdatedBean() {
|
||||||
// arrange
|
// arrange
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
@@ -235,7 +232,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
dummyToLoad.getCountries().size();
|
dummyToLoad.getCountries().size();
|
||||||
|
|
||||||
ServerCache cachedBeanCountriesCache = cacheManager.collectionIdsCache(OCachedBean.class, "countries");
|
ServerCache cachedBeanCountriesCache = cacheManager.collectionIdsCache(OCachedBean.class, "countries");
|
||||||
CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(cachedBean.getId());
|
CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(String.valueOf(cachedBean.getId()));
|
||||||
|
|
||||||
// confirm the starting data and cache entry
|
// confirm the starting data and cache entry
|
||||||
assertEquals(2, dummyToLoad.getCountries().size());
|
assertEquals(2, dummyToLoad.getCountries().size());
|
||||||
@@ -253,7 +250,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
|
|
||||||
// Get the data to assert/check against
|
// Get the data to assert/check against
|
||||||
OCachedBean result = DB.find(OCachedBean.class, cachedBean.getId());
|
OCachedBean result = DB.find(OCachedBean.class, cachedBean.getId());
|
||||||
cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(result.getId());
|
cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(String.valueOf(result.getId()));
|
||||||
|
|
||||||
// assert that data and cache both show correct data
|
// assert that data and cache both show correct data
|
||||||
assertEquals(1, result.getCountries().size());
|
assertEquals(1, result.getCountries().size());
|
||||||
@@ -266,7 +263,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
* When updating a ManyToMany relations also the collection cache must be updated.
|
* When updating a ManyToMany relations also the collection cache must be updated.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdatingCollectionCacheForManyToManyRelationsWithinStatelessUpdate() {
|
void testUpdatingCollectionCacheForManyToManyRelationsWithinStatelessUpdate() {
|
||||||
// arrange
|
// arrange
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
@@ -289,7 +286,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
|
|
||||||
// assert that the cache contains the expected entry
|
// assert that the cache contains the expected entry
|
||||||
assertEquals(1, cachedBeanCountriesCache.size());
|
assertEquals(1, cachedBeanCountriesCache.size());
|
||||||
CachedManyIds dummyEntry = (CachedManyIds) cachedBeanCountriesCache.get(dummyLoad.getId());
|
CachedManyIds dummyEntry = (CachedManyIds) cachedBeanCountriesCache.get(String.valueOf(dummyLoad.getId()));
|
||||||
assertNotNull(dummyEntry);
|
assertNotNull(dummyEntry);
|
||||||
assertEquals(2, dummyEntry.getIdList().size());
|
assertEquals(2, dummyEntry.getIdList().size());
|
||||||
assertTrue(dummyEntry.getIdList().contains("NZ"));
|
assertTrue(dummyEntry.getIdList().contains("NZ"));
|
||||||
@@ -307,7 +304,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
|
|
||||||
assertEquals(1, cachedBeanCountriesCache.size());
|
assertEquals(1, cachedBeanCountriesCache.size());
|
||||||
|
|
||||||
CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(update.getId());
|
CachedManyIds cachedManyIds = (CachedManyIds) cachedBeanCountriesCache.get(String.valueOf(update.getId()));
|
||||||
|
|
||||||
// assert cache updated
|
// assert cache updated
|
||||||
assertEquals(1, cachedManyIds.getIdList().size());
|
assertEquals(1, cachedManyIds.getIdList().size());
|
||||||
@@ -321,8 +318,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdating_noChange() throws InterruptedException {
|
void testUpdating_noChange() throws InterruptedException {
|
||||||
|
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
try (Transaction txn = DB.beginTransaction()) {
|
try (Transaction txn = DB.beginTransaction()) {
|
||||||
@@ -355,7 +351,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testClearingCollectionCacheOnORMUpdate() {
|
void testClearingCollectionCacheOnORMUpdate() {
|
||||||
// arrange
|
// arrange
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
@@ -390,7 +386,7 @@ public class TestCacheCollectionIds extends BaseTestCase {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Disabled
|
@Disabled
|
||||||
public void testClearingCollectionCacheOnExternalModification() {
|
void testClearingCollectionCacheOnExternalModification() {
|
||||||
// arrange
|
// arrange
|
||||||
ResetBasicData.reset();
|
ResetBasicData.reset();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user