mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2035 - lazy-loading soft-deleted list from lazy-loaded bean doesn't remember includeSoftDeletes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.tests.softdelete;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.SqlQuery;
|
||||
import io.ebean.SqlRow;
|
||||
@@ -17,7 +16,6 @@ import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestSoftDeleteBasic extends BaseTestCase {
|
||||
|
||||
@@ -152,7 +150,7 @@ public class TestSoftDeleteBasic extends BaseTestCase {
|
||||
.find(EBasicSDChild.class)
|
||||
.setIncludeSoftDeletes()
|
||||
.where()
|
||||
.idEq(bean.getId())
|
||||
.idEq(bean2.getId())
|
||||
.findOne();
|
||||
assertThat(child).isNotNull();
|
||||
assertThat(child.getOwner().getChildren().size()).isEqualTo(1);
|
||||
|
||||
Reference in New Issue
Block a user