#566 - Refactor internals - SpiQuerySecondary and DLoadContext

This commit is contained in:
Robin Bygrave
2016-02-17 19:44:30 +13:00
parent 439858b259
commit c83606c1da
13 changed files with 248 additions and 101 deletions
@@ -9,6 +9,7 @@ import com.avaje.ebeaninternal.api.LoadContext;
import com.avaje.ebeaninternal.api.LoadSecondaryQuery;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.api.SpiQuerySecondary;
import com.avaje.ebeaninternal.server.core.OrmQueryRequest;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
@@ -58,7 +59,7 @@ public class DLoadContext implements LoadContext {
private List<OrmQueryProperties> secQuery;
public DLoadContext(OrmQueryRequest<?> request) {
public DLoadContext(OrmQueryRequest<?> request, SpiQuerySecondary secondaryQueries) {
this.persistenceContext = request.getPersistenceContext();
this.ebeanServer = request.getServer();
@@ -86,6 +87,41 @@ public class DLoadContext implements LoadContext {
// initialise rootBeanContext after origin and relativePath have been set
this.rootBeanContext = new DLoadBeanContext(this, rootDescriptor, null, defaultBatchSize, null);
registerSecondaryQueries(secondaryQueries);
}
/**
* Register the +query and +lazy secondary queries with their appropriate LoadBeanContext or LoadManyContext.
*/
private void registerSecondaryQueries(SpiQuerySecondary secondaryQueries) {
this.secQuery = secondaryQueries.getQueryJoins();
if (secQuery != null) {
for (OrmQueryProperties pathProperties : secQuery) {
registerSecondaryQuery(pathProperties);
}
}
List<OrmQueryProperties> lazyJoins = secondaryQueries.getLazyJoins();
if (lazyJoins != null) {
for (OrmQueryProperties lazyJoin : lazyJoins) {
registerSecondaryQuery(lazyJoin);
}
}
}
/**
* Setup the load context at this path with OrmQueryProperties which is
* used to build the appropriate query for +query or +lazy loading.
*/
private void registerSecondaryQuery(OrmQueryProperties props) {
ElPropertyValue elGetValue = rootDescriptor.getElGetValue(props.getPath());
boolean many = elGetValue.getBeanProperty().containsMany();
registerSecondaryNode(many, props);
}
protected boolean isExcludeBeanCache() {
@@ -136,36 +172,6 @@ public class DLoadContext implements LoadContext {
return beanLoad;
}
/**
* Register the +query and +lazy secondary queries with their appropriate LoadBeanContext or LoadManyContext.
*/
public void registerSecondaryQueries(List<OrmQueryProperties> queryJoins, List<OrmQueryProperties> lazyJoins) {
this.secQuery = queryJoins;
if (secQuery != null) {
for (int i = 0; i < secQuery.size(); i++) {
registerSecondaryQuery(secQuery.get(i));
}
}
if (lazyJoins != null) {
for (int i = 0; i < lazyJoins.size(); i++) {
registerSecondaryQuery(lazyJoins.get(i));
}
}
}
/**
* Setup the load context at this path with OrmQueryProperties which is
* used to build the appropriate query for +query or +lazy loading.
*/
private void registerSecondaryQuery(OrmQueryProperties props) {
ElPropertyValue elGetValue = rootDescriptor.getElGetValue(props.getPath());
boolean many = elGetValue.getBeanProperty().containsMany();
registerSecondaryNode(many, props);
}
public ObjectGraphNode getObjectGraphNode(String path) {
ObjectGraphNode node = nodePathMap.get(path);
@@ -233,7 +239,7 @@ public class DLoadContext implements LoadContext {
getManyContext(path).register(bc);
}
private DLoadBeanContext getBeanContext(String path) {
protected DLoadBeanContext getBeanContext(String path) {
if (path == null) {
return rootBeanContext;
}