#2035 - lazy-loading soft-deleted list from lazy-loaded bean doesn't remember includeSoftDeletes

This commit is contained in:
rob bygrave
2020-07-14 09:32:52 +12:00
parent ff0274f72c
commit dac0a97a3f
4 changed files with 28 additions and 9 deletions
@@ -1,9 +1,15 @@
package io.ebeaninternal.api;
import io.ebean.bean.BeanCollection;
/**
* Controls the loading of ManyToOne and OneToOne relationships.
*/
public interface LoadBeanContext extends LoadSecondaryQuery {
/**
* Register a BeanCollection into the load context.
*/
void register(String manyProperty, BeanCollection<?> collection);
}
@@ -39,6 +39,7 @@ import io.ebean.util.SplitName;
import io.ebeaninternal.api.BeanCacheResult;
import io.ebeaninternal.api.CQueryPlanKey;
import io.ebeaninternal.api.ConcurrencyMode;
import io.ebeaninternal.api.LoadBeanContext;
import io.ebeaninternal.api.LoadContext;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
@@ -2276,14 +2277,18 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
* define a Reference for the collection and not invoke a query.
*/
public boolean lazyLoadMany(EntityBeanIntercept ebi) {
return lazyLoadMany(ebi, null);
}
public boolean lazyLoadMany(EntityBeanIntercept ebi, LoadBeanContext parent) {
int lazyLoadProperty = ebi.getLazyLoadPropertyIndex();
if (lazyLoadProperty == -1) {
return false;
}
if (inheritInfo != null) {
return descOf(ebi.getOwner().getClass()).lazyLoadMany(ebi, lazyLoadProperty);
return descOf(ebi.getOwner().getClass()).lazyLoadMany(ebi, lazyLoadProperty, parent);
}
return lazyLoadMany(ebi, lazyLoadProperty);
return lazyLoadMany(ebi, lazyLoadProperty, parent);
}
/**
@@ -2296,12 +2301,15 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
/**
* Check for lazy loading of many property.
*/
private boolean lazyLoadMany(EntityBeanIntercept ebi, int lazyLoadProperty) {
private boolean lazyLoadMany(EntityBeanIntercept ebi, int lazyLoadProperty, LoadBeanContext loadBeanContext) {
BeanProperty lazyLoadBeanProp = propertiesIndex[lazyLoadProperty];
if (lazyLoadBeanProp instanceof BeanPropertyAssocMany<?>) {
BeanPropertyAssocMany<?> manyProp = (BeanPropertyAssocMany<?>) lazyLoadBeanProp;
manyProp.createReference(ebi.getOwner());
final BeanCollection<?> collection = manyProp.createReference(ebi.getOwner());
ebi.setLoadedLazy();
if (loadBeanContext != null) {
loadBeanContext.register(manyProp.getName(), collection);
}
return true;
}
return false;
@@ -1,6 +1,7 @@
package io.ebeaninternal.server.loadcontext;
import io.ebean.CacheMode;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanLoader;
import io.ebean.bean.EntityBeanIntercept;
import io.ebean.bean.PersistenceContext;
@@ -32,7 +33,13 @@ class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
// bufferList only required when using query joins (queryFetch)
this.bufferList = (!queryFetch) ? null : new ArrayList<>();
this.currentBuffer = createBuffer(firstBatchSize);
this.cache = (queryProps == null) ? false : queryProps.isCache();
this.cache = (queryProps != null) && queryProps.isCache();
}
@Override
public void register(String manyProperty, BeanCollection<?> collection) {
String path = fullPath + "." + manyProperty;
parent.register(path, collection);
}
/**
@@ -175,7 +182,7 @@ class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
@Override
public void loadBean(EntityBeanIntercept ebi) {
// A synchronized (this) is effectively held by EntityBeanIntercept.loadBean()
if (context.desc.lazyLoadMany(ebi)) {
if (context.desc.lazyLoadMany(ebi, context)) {
// lazy load property was a Many
return;
}