mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Change *ToMany lazy loading to not use the parent entity/table
This commit is contained in:
1 parent
87a948223c
commit
749f8d0d45
36 files changed
+542
-190
No files matched your search
@@ -42,6 +42,7 @@ import com.avaje.ebeaninternal.api.SpiExpressionList;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.ebeaninternal.server.autofetch.AutoFetchManager;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import com.avaje.ebeaninternal.server.deploy.DRawSqlSelect;
|
||||
import com.avaje.ebeaninternal.server.deploy.DeployNamedQuery;
|
||||
import com.avaje.ebeaninternal.server.deploy.TableJoin;
|
||||
@@ -207,6 +208,10 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
*/
|
||||
private ObjectGraphNode parentNode;
|
||||
|
||||
private BeanPropertyAssocMany<?> lazyLoadForParentsProperty;
|
||||
|
||||
private List<Object> lazyLoadForParentsIds;
|
||||
|
||||
/**
|
||||
* Hash of final query after AutoFetch tuning.
|
||||
*/
|
||||
@@ -530,9 +535,25 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
*/
|
||||
public void setPersistenceContext(PersistenceContext persistenceContext) {
|
||||
this.persistenceContext = persistenceContext;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@Override
|
||||
public void setLazyLoadForParents(List<Object> parentIds, BeanPropertyAssocMany<?> many) {
|
||||
this.lazyLoadForParentsIds = parentIds;
|
||||
this.lazyLoadForParentsProperty = many;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getLazyLoadForParentIds() {
|
||||
return lazyLoadForParentsIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeanPropertyAssocMany<?> getLazyLoadForParentsProperty() {
|
||||
return lazyLoadForParentsProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the query detail has neither select or joins specified.
|
||||
*/
|
||||
public boolean isDetailEmpty() {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.avaje.ebean.OrderBy;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.event.BeanQueryRequest;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionFactory;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionList;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
@@ -170,7 +171,7 @@ public class OrmQueryProperties implements Serializable {
|
||||
if (filterMany == null){
|
||||
FilterExprPath exprPath = new FilterExprPath(path);
|
||||
SpiExpressionFactory queryEf = (SpiExpressionFactory)rootQuery.getExpressionFactory();
|
||||
ExpressionFactory filterEf = queryEf.createExpressionFactory(exprPath);
|
||||
ExpressionFactory filterEf = queryEf.createExpressionFactory();//exprPath);
|
||||
filterMany = new FilterExpressionList(exprPath, filterEf, rootQuery);
|
||||
// by default we need to make this a 'query join' now
|
||||
queryFetchAll = true;
|
||||
@@ -229,12 +230,17 @@ public class OrmQueryProperties implements Serializable {
|
||||
public void configureBeanQuery(SpiQuery<?> query) {
|
||||
|
||||
if (trimmedProperties != null && trimmedProperties.length() > 0) {
|
||||
query.select(trimmedProperties);
|
||||
if (filterMany != null){
|
||||
query.setFilterMany(path, filterMany);
|
||||
}
|
||||
query.select(trimmedProperties);
|
||||
}
|
||||
|
||||
|
||||
if (filterMany != null){
|
||||
SpiExpressionList<?> trimPath = filterMany.trimPath(path.length()+1);
|
||||
List<SpiExpression> underlyingList = trimPath.getUnderlyingList();
|
||||
for (SpiExpression spiExpression : underlyingList) {
|
||||
query.where().add(spiExpression);
|
||||
}
|
||||
}
|
||||
|
||||
if (secondaryChildren != null) {
|
||||
int trimPath = path.length() + 1;
|
||||
for (int i = 0; i < secondaryChildren.size(); i++) {
|
||||
@@ -251,36 +257,6 @@ public class OrmQueryProperties implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the select and joins for this query.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void configureManyQuery(SpiQuery<?> query) {
|
||||
|
||||
if (trimmedProperties != null && trimmedProperties.length() > 0) {
|
||||
query.fetch(query.getLazyLoadManyPath(), trimmedProperties);
|
||||
}
|
||||
if (filterMany != null){
|
||||
query.setFilterMany(path, filterMany);
|
||||
}
|
||||
if (secondaryChildren != null) {
|
||||
|
||||
int trimlen = path.length() - query.getLazyLoadManyPath().length();
|
||||
|
||||
for (int i = 0; i < secondaryChildren.size(); i++) {
|
||||
OrmQueryProperties p = secondaryChildren.get(i);
|
||||
String path = p.getPath();
|
||||
path = path.substring(trimlen);
|
||||
query.fetch(path, p.getProperties(), p.getFetchConfig());
|
||||
query.setFilterMany(path, p.getFilterManyTrimPath(trimlen));
|
||||
}
|
||||
}
|
||||
|
||||
if (orderBy != null){
|
||||
query.setOrder(orderBy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a copy of the OrmQueryProperties.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user