#210 - ENH: Add Query.setLazyLoadBatch(int size) method ... for per query control

This commit is contained in:
rbygrave committed 2014-11-26 20:13:30 +13:00
1 parent 1cd31e13b9
commit 478053263f
18 files changed
+239 -112

No files matched your search

@@ -69,7 +69,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
return buffer;
}
public void loadSecondaryQuery(OrmQueryRequest<?> parentRequest, int requestedBatchSize, boolean all) {
public void loadSecondaryQuery(OrmQueryRequest<?> parentRequest) {
if (!queryFetch) {
throw new IllegalStateException("Not expecting loadSecondaryQuery() to be called?");
@@ -111,7 +111,11 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
this.batchSize = batchSize;
this.list = new ArrayList<EntityBeanIntercept>(batchSize);
}
public int getBatchSize() {
return batchSize;
}
/**
* Return true if the buffer is full.
*/
@@ -56,7 +56,7 @@ public class DLoadContext implements LoadContext {
this.persistenceContext = request.getPersistenceContext();
this.ebeanServer = request.getServer();
this.defaultBatchSize = ebeanServer.getLazyLoadBatchSize();
this.defaultBatchSize = request.getLazyLoadBatchSize();
this.rootDescriptor = request.getBeanDescriptor();
SpiQuery<?> query = request.getQuery();
@@ -104,18 +104,13 @@ public class DLoadContext implements LoadContext {
/**
* Execute all the secondary queries.
*/
public void executeSecondaryQueries(OrmQueryRequest<?> parentRequest, int defaultQueryBatch) {
public void executeSecondaryQueries(OrmQueryRequest<?> parentRequest) {
if (secQuery != null){
for (int i = 0; i < secQuery.size(); i++) {
OrmQueryProperties properties = secQuery.get(i);
int batchSize = properties.getQueryFetchBatch();
if (batchSize == 0){
batchSize = defaultQueryBatch;
}
LoadSecondaryQuery load = getLoadSecondaryQuery(properties.getPath());
load.loadSecondaryQuery(parentRequest, batchSize, properties.isQueryFetchAll());
load.loadSecondaryQuery(parentRequest);
}
}
}
@@ -201,10 +196,6 @@ public class DLoadContext implements LoadContext {
return useAutofetchManager;
}
public String getRelativePath() {
return relativePath;
}
protected String getFullPath(String path) {
if (relativePath == null) {
return path;
@@ -83,8 +83,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
bc.setLoader(0, currentBuffer);
}
public void loadSecondaryQuery(OrmQueryRequest<?> parentRequest, int requestedBatchSize, boolean all){
public void loadSecondaryQuery(OrmQueryRequest<?> parentRequest) {
if (!queryFetch) {
throw new IllegalStateException("Not expecting loadSecondaryQuery() to be called?");
@@ -93,7 +92,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
if (bufferList != null) {
for (LoadBuffer loadBuffer : bufferList) {
if (!loadBuffer.list.isEmpty()) {
LoadManyRequest req = new LoadManyRequest(loadBuffer, parentRequest, requestedBatchSize, false, false, false);
LoadManyRequest req = new LoadManyRequest(loadBuffer, parentRequest, false, false, false);
parent.getEbeanServer().loadMany(req);
if (!queryProps.isQueryFetchAll()) {
// Stop - only fetch the first batch ... the rest will be lazy loaded
@@ -127,6 +126,10 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
this.batchSize = batchSize;
this.list = new ArrayList<BeanCollection<?>>(batchSize);
}
public int getBatchSize() {
return batchSize;
}
/**
* Return true if the buffer is full.
@@ -188,7 +191,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
boolean useCache = context.hitCache && !onlyIds;
if (useCache) {
EntityBean ownerBean = bc.getOwnerBean();
BeanDescriptor<? extends Object> parentDesc = context.desc.getBeanDescriptor(ownerBean.getClass());
BeanDescriptor<?> parentDesc = context.desc.getBeanDescriptor(ownerBean.getClass());
Object parentId = parentDesc.getId(ownerBean);
if (parentDesc.cacheManyPropLoad(context.property, bc, parentId, context.parent.isReadOnly())) {
// we loaded the bean from cache
@@ -199,7 +202,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
// Should reduce the list by checking each beanCollection in the L2 first before executing the query
LoadManyRequest req = new LoadManyRequest(this, batchSize, true, onlyIds, useCache);
LoadManyRequest req = new LoadManyRequest(this, true, onlyIds, useCache);
context.parent.getEbeanServer().loadMany(req);
}
}