No effective change - format only

This commit is contained in:
Robin Bygrave
2015-07-31 22:52:59 +12:00
parent b1c41a58f2
commit ebc4d9fdc5
4 changed files with 344 additions and 340 deletions
@@ -10,61 +10,61 @@ import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
* Base class for Bean and BeanCollection loading (lazy loading and query join loading).
*/
public abstract class DLoadBaseContext {
protected final DLoadContext parent;
protected final BeanDescriptor<?> desc;
protected final DLoadContext parent;
protected final String fullPath;
protected final BeanDescriptor<?> desc;
protected final String fullPath;
protected final OrmQueryProperties queryProps;
protected final boolean hitCache;
protected final String serverName;
protected final int firstBatchSize;
protected final OrmQueryProperties queryProps;
protected final boolean hitCache;
protected final String serverName;
protected final int firstBatchSize;
protected final int secondaryBatchSize;
protected final ObjectGraphNode objectGraphNode;
protected final boolean queryFetch;
public DLoadBaseContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
this.parent = parent;
this.serverName = parent.getEbeanServer().getName();
this.desc = desc;
this.queryProps = queryProps;
this.fullPath = parent.getFullPath(path);
this.hitCache = !parent.isExcludeBeanCache() && desc.isBeanCaching();
this.hitCache = !parent.isExcludeBeanCache() && desc.isBeanCaching();
this.objectGraphNode = parent.getObjectGraphNode(path);
this.queryFetch = queryProps != null && queryProps.isQueryFetch();
this.queryFetch = queryProps != null && queryProps.isQueryFetch();
this.firstBatchSize = initFirstBatchSize(defaultBatchSize, queryProps);
this.secondaryBatchSize = initSecondaryBatchSize(defaultBatchSize, firstBatchSize, queryProps);
this.secondaryBatchSize = initSecondaryBatchSize(defaultBatchSize, firstBatchSize, queryProps);
}
private int initFirstBatchSize(int batchSize, OrmQueryProperties queryProps) {
if (queryProps == null) {
return batchSize;
}
int queryFetchBatch = queryProps.getQueryFetchBatch();
if (queryFetchBatch > 0) {
// property join was automatically set to a 'query join'
return queryFetchBatch;
}
FetchConfig fetchConfig = queryProps.getFetchConfig();
if (fetchConfig == null) {
return batchSize;
}
int queryBatchSize = fetchConfig.getQueryBatchSize();
if (queryBatchSize == -1) {
// not eager query fetch, just lazy loading
@@ -73,12 +73,12 @@ public abstract class DLoadBaseContext {
} else if (queryBatchSize == 0) {
// default query fetch batch size is 100
return 100;
} else {
return queryBatchSize;
}
}
private int initSecondaryBatchSize(int defaultBatchSize, int firstBatchSize, OrmQueryProperties queryProps) {
if (queryProps == null) {
return defaultBatchSize;
@@ -90,11 +90,11 @@ public abstract class DLoadBaseContext {
if (fetchConfig.isQueryAll()) {
return firstBatchSize;
}
int lazyBatchSize = fetchConfig.getLazyBatchSize();
return (lazyBatchSize > 1) ? lazyBatchSize : defaultBatchSize;
}
protected PersistenceContext getPersistenceContext() {
return parent.getPersistenceContext();
}
@@ -1,9 +1,5 @@
package com.avaje.ebeaninternal.server.loadcontext;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.avaje.ebean.bean.BeanLoader;
import com.avaje.ebean.bean.EntityBeanIntercept;
import com.avaje.ebean.bean.PersistenceContext;
@@ -15,22 +11,26 @@ import com.avaje.ebeaninternal.server.core.OrmQueryRequest;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Default implementation of LoadBeanContext.
*/
public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext{
public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContext {
private List<LoadBuffer> bufferList;
private LoadBuffer currentBuffer;
public DLoadBeanContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
super(parent, desc, path, defaultBatchSize, queryProps);
// bufferList only required when using query joins (queryFetch)
this.bufferList = (!queryFetch) ? null : new ArrayList<DLoadBeanContext.LoadBuffer>();
this.currentBuffer = createBuffer(firstBatchSize);
this.currentBuffer = createBuffer(firstBatchSize);
}
/**
@@ -63,36 +63,36 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
}
}
protected void register(EntityBeanIntercept ebi){
protected void register(EntityBeanIntercept ebi) {
if (currentBuffer.isFull()) {
currentBuffer = createBuffer(secondaryBatchSize);
currentBuffer = createBuffer(secondaryBatchSize);
}
// set the persistenceContext on the bean first
ebi.setBeanLoader(currentBuffer, getPersistenceContext());
currentBuffer.add(ebi);
}
private LoadBuffer createBuffer(int size) {
LoadBuffer buffer = new LoadBuffer(this, size);
if (bufferList != null) {
bufferList.add(buffer);
}
private LoadBuffer createBuffer(int size) {
LoadBuffer buffer = new LoadBuffer(this, size);
if (bufferList != null) {
bufferList.add(buffer);
}
return buffer;
}
}
public void loadSecondaryQuery(OrmQueryRequest<?> parentRequest) {
if (!queryFetch) {
throw new IllegalStateException("Not expecting loadSecondaryQuery() to be called?");
}
synchronized (this) {
if (bufferList != null) {
for (LoadBuffer loadBuffer : bufferList) {
if (!loadBuffer.list.isEmpty()) {
LoadBeanRequest req = new LoadBeanRequest(loadBuffer, parentRequest, false, null, false);
parent.getEbeanServer().loadBean(req);
parent.getEbeanServer().loadBean(req);
if (!queryProps.isQueryFetchAll()) {
// Stop - only fetch the first batch ... the rest will be lazy loaded
break;
@@ -104,18 +104,18 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
}
}
}
/**
* A buffer for batch loading beans on a given path.
*/
public static class LoadBuffer implements BeanLoader, LoadBeanBuffer {
private final DLoadBeanContext context;
private final int batchSize;
private final List<EntityBeanIntercept> list;
private PersistenceContext persistenceContext;
public LoadBuffer(DLoadBeanContext context, int batchSize) {
this.context = context;
this.batchSize = batchSize;
@@ -132,7 +132,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
public boolean isFull() {
return batchSize == list.size();
}
/**
* Return true if the buffer is full.
*/
@@ -143,7 +143,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
}
list.add(ebi);
}
@Override
public List<EntityBeanIntercept> getBatch() {
return list;
@@ -153,12 +153,12 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
public String getName() {
return context.serverName;
}
@Override
public String getFullPath() {
return context.fullPath;
}
@Override
public BeanDescriptor<?> getBeanDescriptor() {
return context.desc;
@@ -173,7 +173,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
public void configureQuery(SpiQuery<?> query, String lazyLoadProperty) {
context.configureQuery(query, lazyLoadProperty);
}
@Override
public void loadBean(EntityBeanIntercept ebi) {
// A synchronized (this) is effectively held by EntityBeanIntercept.loadBean()
@@ -182,7 +182,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
// lazy load property was a Many
return;
}
if (context.hitCache && context.desc.cacheBeanLoad(ebi)) {
// successfully hit the L2 cache so don't invoke DB lazy loading
list.remove(ebi);
@@ -205,5 +205,5 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
}
}
}
@@ -1,6 +1,10 @@
package com.avaje.ebeaninternal.server.loadcontext;
import com.avaje.ebean.bean.*;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.EntityBeanIntercept;
import com.avaje.ebean.bean.ObjectGraphNode;
import com.avaje.ebean.bean.ObjectGraphOrigin;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebeaninternal.api.LoadContext;
import com.avaje.ebeaninternal.api.LoadSecondaryQuery;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
@@ -23,60 +27,60 @@ import java.util.Map;
*/
public class DLoadContext implements LoadContext {
private final SpiEbeanServer ebeanServer;
private final BeanDescriptor<?> rootDescriptor;
private final Map<String, DLoadBeanContext> beanMap = new HashMap<String, DLoadBeanContext>();
private final Map<String, DLoadManyContext> manyMap = new HashMap<String, DLoadManyContext>();
private final DLoadBeanContext rootBeanContext;
private final SpiEbeanServer ebeanServer;
private final BeanDescriptor<?> rootDescriptor;
private final Map<String, DLoadBeanContext> beanMap = new HashMap<String, DLoadBeanContext>();
private final Map<String, DLoadManyContext> manyMap = new HashMap<String, DLoadManyContext>();
private final DLoadBeanContext rootBeanContext;
private final Timestamp asOf;
private final Boolean readOnly;
private final boolean excludeBeanCache;
private final int defaultBatchSize;
private final Boolean readOnly;
private final boolean excludeBeanCache;
private final int defaultBatchSize;
private final boolean disableLazyLoading;
/**
* The path relative to the root of the object graph.
*/
private final String relativePath;
private final ObjectGraphOrigin origin;
private final boolean useAutofetchManager;
private final Map<String,ObjectGraphNode> nodePathMap = new HashMap<String, ObjectGraphNode>();
private PersistenceContext persistenceContext;
private List<OrmQueryProperties> secQuery;
* The path relative to the root of the object graph.
*/
private final String relativePath;
private final ObjectGraphOrigin origin;
private final boolean useAutofetchManager;
public DLoadContext(OrmQueryRequest<?> request) {
private final Map<String, ObjectGraphNode> nodePathMap = new HashMap<String, ObjectGraphNode>();
this.persistenceContext = request.getPersistenceContext();
private PersistenceContext persistenceContext;
private List<OrmQueryProperties> secQuery;
public DLoadContext(OrmQueryRequest<?> request) {
this.persistenceContext = request.getPersistenceContext();
this.ebeanServer = request.getServer();
this.defaultBatchSize = request.getLazyLoadBatchSize();
this.rootDescriptor = request.getBeanDescriptor();
SpiQuery<?> query = request.getQuery();
this.asOf = query.getAsOf();
this.readOnly = query.isReadOnly();
this.disableLazyLoading = query.isDisableLazyLoading();
this.excludeBeanCache = Boolean.FALSE.equals(query.isUseBeanCache());
this.useAutofetchManager = query.getAutoFetchManager() != null;
ObjectGraphNode parentNode = query.getParentNode();
if (parentNode != null){
this.origin = parentNode.getOriginQueryPoint();
this.relativePath = parentNode.getPath();
} else {
this.origin = null;
this.relativePath = null;
}
// initialise rootBeanContext after origin and relativePath have been set
this.excludeBeanCache = Boolean.FALSE.equals(query.isUseBeanCache());
this.useAutofetchManager = query.getAutoFetchManager() != null;
ObjectGraphNode parentNode = query.getParentNode();
if (parentNode != null) {
this.origin = parentNode.getOriginQueryPoint();
this.relativePath = parentNode.getPath();
} else {
this.origin = null;
this.relativePath = null;
}
// initialise rootBeanContext after origin and relativePath have been set
this.rootBeanContext = new DLoadBeanContext(this, rootDescriptor, null, defaultBatchSize, null);
}
}
protected boolean isExcludeBeanCache() {
return excludeBeanCache;
@@ -101,121 +105,121 @@ public class DLoadContext implements LoadContext {
}
return maxBatch;
}
/**
* Execute all the secondary queries.
*/
public void executeSecondaryQueries(OrmQueryRequest<?> parentRequest) {
if (secQuery != null){
for (int i = 0; i < secQuery.size(); i++) {
OrmQueryProperties properties = secQuery.get(i);
LoadSecondaryQuery load = getLoadSecondaryQuery(properties.getPath());
load.loadSecondaryQuery(parentRequest);
}
}
}
/**
* Return the LoadBeanContext or LoadManyContext for the given path.
*/
private LoadSecondaryQuery getLoadSecondaryQuery(String path){
LoadSecondaryQuery beanLoad = beanMap.get(path);
if (beanLoad == null){
beanLoad = manyMap.get(path);
}
return beanLoad;
}
/**
* Remove the +query and +lazy secondary queries and
* register them with their appropriate LoadBeanContext
* or LoadManyContext.
* <p>
* The parts of the secondary queries are removed and used
* by LoadBeanContext/LoadManyContext to build the appropriate
* queries.
* </p>
*/
public void registerSecondaryQueries(SpiQuery<?> query) {
secQuery = query.removeQueryJoins();
if (secQuery != null){
for (int i = 0; i < secQuery.size(); i++) {
OrmQueryProperties props = secQuery.get(i);
registerSecondaryQuery(props);
}
}
List<OrmQueryProperties> lazyQueries = query.removeLazyJoins();
if (lazyQueries != null){
for (int i = 0; i < lazyQueries.size(); i++) {
OrmQueryProperties lazyProps = lazyQueries.get(i);
registerSecondaryQuery(lazyProps);
}
}
}
/**
* 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) {
String propName = props.getPath();
ElPropertyValue elGetValue = rootDescriptor.getElGetValue(propName);
/**
* Execute all the secondary queries.
*/
public void executeSecondaryQueries(OrmQueryRequest<?> parentRequest) {
boolean many = elGetValue.getBeanProperty().containsMany();
registerSecondaryNode(many, props);
}
if (secQuery != null) {
for (int i = 0; i < secQuery.size(); i++) {
OrmQueryProperties properties = secQuery.get(i);
LoadSecondaryQuery load = getLoadSecondaryQuery(properties.getPath());
load.loadSecondaryQuery(parentRequest);
}
}
}
/**
* Return the LoadBeanContext or LoadManyContext for the given path.
*/
private LoadSecondaryQuery getLoadSecondaryQuery(String path) {
LoadSecondaryQuery beanLoad = beanMap.get(path);
if (beanLoad == null) {
beanLoad = manyMap.get(path);
}
return beanLoad;
}
/**
* Remove the +query and +lazy secondary queries and
* register them with their appropriate LoadBeanContext
* or LoadManyContext.
* <p>
* The parts of the secondary queries are removed and used
* by LoadBeanContext/LoadManyContext to build the appropriate
* queries.
* </p>
*/
public void registerSecondaryQueries(SpiQuery<?> query) {
secQuery = query.removeQueryJoins();
if (secQuery != null) {
for (int i = 0; i < secQuery.size(); i++) {
OrmQueryProperties props = secQuery.get(i);
registerSecondaryQuery(props);
}
}
List<OrmQueryProperties> lazyQueries = query.removeLazyJoins();
if (lazyQueries != null) {
for (int i = 0; i < lazyQueries.size(); i++) {
OrmQueryProperties lazyProps = lazyQueries.get(i);
registerSecondaryQuery(lazyProps);
}
}
}
/**
* 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) {
String propName = props.getPath();
ElPropertyValue elGetValue = rootDescriptor.getElGetValue(propName);
boolean many = elGetValue.getBeanProperty().containsMany();
registerSecondaryNode(many, props);
}
public ObjectGraphNode getObjectGraphNode(String path) {
ObjectGraphNode node = nodePathMap.get(path);
if (node == null){
node = createObjectGraphNode(path);
nodePathMap.put(path, node);
}
return node;
}
private ObjectGraphNode createObjectGraphNode(String path) {
if (relativePath != null){
if (path == null){
path = relativePath;
} else {
path = relativePath+"."+path;
}
}
return new ObjectGraphNode(origin, path);
}
public ObjectGraphNode getObjectGraphNode(String path) {
public boolean isUseAutofetchManager() {
return useAutofetchManager;
}
protected String getFullPath(String path) {
ObjectGraphNode node = nodePathMap.get(path);
if (node == null) {
node = createObjectGraphNode(path);
nodePathMap.put(path, node);
}
return node;
}
private ObjectGraphNode createObjectGraphNode(String path) {
if (relativePath != null) {
if (path == null) {
path = relativePath;
} else {
path = relativePath + "." + path;
}
}
return new ObjectGraphNode(origin, path);
}
public boolean isUseAutofetchManager() {
return useAutofetchManager;
}
protected String getFullPath(String path) {
if (relativePath == null) {
return path;
} else {
return relativePath + "." + path;
}
}
}
protected SpiEbeanServer getEbeanServer() {
return ebeanServer;
}
/**
* Return the parent state which defines the sharedInstance and readOnly status
* which needs to be propagated to other beans and collections.
*/
protected Boolean isReadOnly() {
return readOnly;
}
protected SpiEbeanServer getEbeanServer() {
return ebeanServer;
}
/**
* Return the parent state which defines the sharedInstance and readOnly status
* which needs to be propagated to other beans and collections.
*/
protected Boolean isReadOnly() {
return readOnly;
}
protected Timestamp getAsOf() {
return asOf;
@@ -226,85 +230,85 @@ public class DLoadContext implements LoadContext {
}
public PersistenceContext getPersistenceContext() {
return persistenceContext;
}
return persistenceContext;
}
public void resetPersistenceContext(PersistenceContext persistenceContext) {
this.persistenceContext = persistenceContext;
// clear the load contexts for beans and beanCollections
for (DLoadBeanContext beanContext : beanMap.values()) {
beanContext.clear();
}
for (DLoadManyContext manyContext : manyMap.values()) {
manyContext.clear();
}
this.rootBeanContext.clear();
}
public void resetPersistenceContext(PersistenceContext persistenceContext) {
this.persistenceContext = persistenceContext;
// clear the load contexts for beans and beanCollections
for (DLoadBeanContext beanContext : beanMap.values()) {
beanContext.clear();
}
for (DLoadManyContext manyContext : manyMap.values()) {
manyContext.clear();
}
this.rootBeanContext.clear();
}
public void register(String path, EntityBeanIntercept ebi){
getBeanContext(path).register(ebi);
}
public void register(String path, EntityBeanIntercept ebi) {
getBeanContext(path).register(ebi);
}
public void register(String path, BeanCollection<?> bc){
getManyContext(path).register(bc);
}
private DLoadBeanContext getBeanContext(String path) {
if (path == null){
return rootBeanContext;
}
DLoadBeanContext beanContext = beanMap.get(path);
if (beanContext == null){
beanContext = createBeanContext(path, defaultBatchSize, null);
beanMap.put(path, beanContext);
}
return beanContext;
}
private void registerSecondaryNode(boolean many, OrmQueryProperties props) {
String path = props.getPath();
int lazyJoinBatch = props.getLazyFetchBatch();
int batchSize = lazyJoinBatch > 0 ? lazyJoinBatch : defaultBatchSize;
if (many){
DLoadManyContext manyContext = createManyContext(path, batchSize, props);
manyMap.put(path, manyContext);
} else {
DLoadBeanContext beanContext = createBeanContext(path, batchSize, props);
beanMap.put(path, beanContext);
}
}
public void register(String path, BeanCollection<?> bc) {
getManyContext(path).register(bc);
}
private DLoadManyContext getManyContext(String path) {
if (path == null){
throw new RuntimeException("path is null?");
}
DLoadManyContext ctx = manyMap.get(path);
if (ctx == null){
ctx = createManyContext(path, defaultBatchSize, null);
manyMap.put(path, ctx);
}
return ctx;
}
private DLoadManyContext createManyContext(String path, int batchSize, OrmQueryProperties queryProps) {
private DLoadBeanContext getBeanContext(String path) {
if (path == null) {
return rootBeanContext;
}
DLoadBeanContext beanContext = beanMap.get(path);
if (beanContext == null) {
beanContext = createBeanContext(path, defaultBatchSize, null);
beanMap.put(path, beanContext);
}
return beanContext;
}
BeanPropertyAssocMany<?> p = (BeanPropertyAssocMany<?>)getBeanProperty(rootDescriptor, path);
private void registerSecondaryNode(boolean many, OrmQueryProperties props) {
return new DLoadManyContext(this, p, path, batchSize, queryProps);
}
String path = props.getPath();
int lazyJoinBatch = props.getLazyFetchBatch();
int batchSize = lazyJoinBatch > 0 ? lazyJoinBatch : defaultBatchSize;
private DLoadBeanContext createBeanContext(String path, int batchSize, OrmQueryProperties queryProps) {
if (many) {
DLoadManyContext manyContext = createManyContext(path, batchSize, props);
manyMap.put(path, manyContext);
} else {
DLoadBeanContext beanContext = createBeanContext(path, batchSize, props);
beanMap.put(path, beanContext);
}
}
BeanPropertyAssoc<?> p = (BeanPropertyAssoc<?>)getBeanProperty(rootDescriptor, path);
BeanDescriptor<?> targetDescriptor = p.getTargetDescriptor();
private DLoadManyContext getManyContext(String path) {
if (path == null) {
throw new RuntimeException("path is null?");
}
DLoadManyContext ctx = manyMap.get(path);
if (ctx == null) {
ctx = createManyContext(path, defaultBatchSize, null);
manyMap.put(path, ctx);
}
return ctx;
}
private DLoadManyContext createManyContext(String path, int batchSize, OrmQueryProperties queryProps) {
BeanPropertyAssocMany<?> p = (BeanPropertyAssocMany<?>) getBeanProperty(rootDescriptor, path);
return new DLoadManyContext(this, p, path, batchSize, queryProps);
}
private DLoadBeanContext createBeanContext(String path, int batchSize, OrmQueryProperties queryProps) {
BeanPropertyAssoc<?> p = (BeanPropertyAssoc<?>) getBeanProperty(rootDescriptor, path);
BeanDescriptor<?> targetDescriptor = p.getTargetDescriptor();
return new DLoadBeanContext(this, targetDescriptor, path, batchSize, queryProps);
}
private BeanProperty getBeanProperty(BeanDescriptor<?> desc, String path) {
return desc.getBeanPropertyFromPath(path);
}
return new DLoadBeanContext(this, targetDescriptor, path, batchSize, queryProps);
}
private BeanProperty getBeanProperty(BeanDescriptor<?> desc, String path){
return desc.getBeanPropertyFromPath(path);
}
}
@@ -1,8 +1,5 @@
package com.avaje.ebeaninternal.server.loadcontext;
import java.util.ArrayList;
import java.util.List;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollectionLoader;
import com.avaje.ebean.bean.EntityBean;
@@ -17,25 +14,28 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
import java.util.ArrayList;
import java.util.List;
public class DLoadManyContext extends DLoadBaseContext implements LoadManyContext {
protected final BeanPropertyAssocMany<?> property;
private List<LoadBuffer> bufferList;
private LoadBuffer currentBuffer;
public DLoadManyContext(DLoadContext parent, BeanPropertyAssocMany<?> property,
String path, int defaultBatchSize, OrmQueryProperties queryProps) {
super(parent, property.getBeanDescriptor(), path, defaultBatchSize, queryProps);
public DLoadManyContext(DLoadContext parent, BeanPropertyAssocMany<?> property,
String path, int defaultBatchSize, OrmQueryProperties queryProps) {
this.property = property;
super(parent, property.getBeanDescriptor(), path, defaultBatchSize, queryProps);
this.property = property;
// bufferList only required when using query joins (queryFetch)
this.bufferList = (!queryFetch) ? null : new ArrayList<DLoadManyContext.LoadBuffer>();
this.bufferList = (!queryFetch) ? null : new ArrayList<DLoadManyContext.LoadBuffer>();
this.currentBuffer = createBuffer(firstBatchSize);
}
}
private LoadBuffer createBuffer(int size) {
LoadBuffer buffer = new LoadBuffer(this, size);
if (bufferList != null) {
@@ -54,48 +54,48 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
currentBuffer = createBuffer(secondaryBatchSize);
}
public void configureQuery(SpiQuery<?> query){
// propagate the readOnly state
if (parent.isReadOnly() != null){
query.setReadOnly(parent.isReadOnly());
}
public void configureQuery(SpiQuery<?> query) {
// propagate the readOnly state
if (parent.isReadOnly() != null) {
query.setReadOnly(parent.isReadOnly());
}
// propagate the asOf and lazy loading mode
query.setDisableLazyLoading(parent.isDisableLazyLoading());
query.asOf(parent.getAsOf());
query.setParentNode(objectGraphNode);
if (queryProps != null){
queryProps.configureBeanQuery(query);
}
if (parent.isUseAutofetchManager()){
query.setAutofetch(true);
}
}
query.setParentNode(objectGraphNode);
public BeanPropertyAssocMany<?> getBeanProperty() {
return property;
}
if (queryProps != null) {
queryProps.configureBeanQuery(query);
}
public BeanDescriptor<?> getBeanDescriptor() {
return desc;
}
if (parent.isUseAutofetchManager()) {
query.setAutofetch(true);
}
}
public String getName() {
return parent.getEbeanServer().getName();
}
public BeanPropertyAssocMany<?> getBeanProperty() {
return property;
}
public void register(BeanCollection<?> bc){
if (currentBuffer.isFull()) {
public BeanDescriptor<?> getBeanDescriptor() {
return desc;
}
public String getName() {
return parent.getEbeanServer().getName();
}
public void register(BeanCollection<?> bc) {
if (currentBuffer.isFull()) {
currentBuffer = createBuffer(secondaryBatchSize);
}
currentBuffer.add(bc);
}
currentBuffer.add(bc);
bc.setLoader(currentBuffer);
}
}
public void loadSecondaryQuery(OrmQueryRequest<?> parentRequest) {
@@ -107,31 +107,31 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
for (LoadBuffer loadBuffer : bufferList) {
if (!loadBuffer.list.isEmpty()) {
LoadManyRequest req = new LoadManyRequest(loadBuffer, parentRequest, false, false, false);
parent.getEbeanServer().loadMany(req);
parent.getEbeanServer().loadMany(req);
if (!queryProps.isQueryFetchAll()) {
// Stop - only fetch the first batch ... the rest will be lazy loaded
break;
}
}
}
// this is only run once - secondary query is a one shot deal
this.bufferList = null;
}
}
}
}
/**
* A buffer for batch loading bean collections on a given path.
* Supports batch lazy loading and secondary query loading.
*/
public static class LoadBuffer implements BeanCollectionLoader, LoadManyBuffer {
private final PersistenceContext persistenceContext;
private final DLoadManyContext context;
private final int batchSize;
private final List<BeanCollection<?>> list;
public LoadBuffer(DLoadManyContext context, int batchSize) {
this.context = context;
// set the persistence context as at this moment in
@@ -144,21 +144,21 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
public int getBatchSize() {
return batchSize;
}
/**
* Return true if the buffer is full.
*/
public boolean isFull() {
return batchSize == list.size();
return batchSize == list.size();
}
/**
* Return true if the buffer is full.
*/
public void add(BeanCollection<?> bc) {
list.add(bc);
}
@Override
public List<BeanCollection<?>> getBatch() {
return list;
@@ -168,22 +168,22 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
public BeanPropertyAssocMany<?> getBeanProperty() {
return context.property;
}
@Override
public ObjectGraphNode getObjectGraphNode() {
return context.objectGraphNode;
}
@Override
public void configureQuery(SpiQuery<?> query){
public void configureQuery(SpiQuery<?> query) {
context.configureQuery(query);
}
@Override
public String getName() {
return context.serverName;
}
@Override
public BeanDescriptor<?> getBeanDescriptor() {
return context.desc;
@@ -193,7 +193,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
public PersistenceContext getPersistenceContext() {
return persistenceContext;
}
@Override
public String getFullPath() {
return context.fullPath;
@@ -213,9 +213,9 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
return;
}
}
// Should reduce the list by checking each beanCollection in the L2 first before executing the query
LoadManyRequest req = new LoadManyRequest(this, true, onlyIds, useCache);
context.parent.getEbeanServer().loadMany(req);
}