Change *ToMany lazy loading to not use the parent entity/table

This commit is contained in:
Rob Bygrave committed 2014-01-30 22:27:52 +13:00
1 parent 87a948223c
commit 749f8d0d45
36 files changed
+542 -190

No files matched your search

@@ -51,23 +51,17 @@ public class DLoadContext implements LoadContext {
private PersistenceContext persistenceContext;
private List<OrmQueryProperties> secQuery;
public DLoadContext(SpiEbeanServer ebeanServer, BeanDescriptor<?> rootDescriptor, Boolean readOnly, SpiQuery<?> query) {
this(ebeanServer, rootDescriptor, readOnly,
Boolean.FALSE.equals(query.isUseBeanCache()),
query.getParentNode(),
query.getAutoFetchManager() != null);
}
public DLoadContext(SpiEbeanServer ebeanServer, BeanDescriptor<?> rootDescriptor, Boolean readOnly,
boolean excludeBeanCache, ObjectGraphNode parentNode, boolean useAutofetchManager) {
this.ebeanServer = ebeanServer;
this.defaultBatchSize = ebeanServer.getLazyLoadBatchSize();
this.rootDescriptor = rootDescriptor;
this.readOnly = readOnly;
this.excludeBeanCache = excludeBeanCache;
this.useAutofetchManager = useAutofetchManager;
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();
@@ -80,29 +74,29 @@ public class DLoadContext implements LoadContext {
this.rootBeanContext = new DLoadBeanContext(this, rootDescriptor, null, defaultBatchSize, null);
}
protected boolean isExcludeBeanCache() {
return excludeBeanCache;
protected boolean isExcludeBeanCache() {
return excludeBeanCache;
}
/**
* Return the minimum batch size when using QueryIterator with query joins.
*/
public int getSecondaryQueriesMinBatchSize(OrmQueryRequest<?> parentRequest, int defaultQueryBatch) {
if (secQuery == null) {
return -1;
}
/**
* Return the minimum batch size when using QueryIterator with query joins.
*/
public int getSecondaryQueriesMinBatchSize(OrmQueryRequest<?> parentRequest, int defaultQueryBatch) {
if (secQuery == null){
return -1;
}
int maxBatch = 0;
for (int i = 0; i < secQuery.size(); i++) {
int batchSize = secQuery.get(i).getQueryFetchBatch();
if (batchSize == 0){
batchSize = defaultQueryBatch;
}
maxBatch = Math.max(maxBatch, batchSize);
}
return maxBatch;
int maxBatch = 0;
for (int i = 0; i < secQuery.size(); i++) {
int batchSize = secQuery.get(i).getQueryFetchBatch();
if (batchSize == 0) {
batchSize = defaultQueryBatch;
}
maxBatch = Math.max(maxBatch, batchSize);
}
return maxBatch;
}
/**
* Execute all the secondary queries.
@@ -30,15 +30,13 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
super(parent, property.getBeanDescriptor(), path, defaultBatchSize, queryProps);
this.property = property;
this.currentBuffer = createBuffer(firstBatchSize);
this.bufferList = queryFetch ? new ArrayList<DLoadManyContext.LoadBuffer>() : null;
this.bufferList = new ArrayList<DLoadManyContext.LoadBuffer>();
this.currentBuffer = createBuffer(firstBatchSize);
}
private LoadBuffer createBuffer(int size) {
LoadBuffer buffer = new LoadBuffer(this, size);
if (bufferList != null) {
bufferList.add(buffer);
}
bufferList.add(buffer);
return buffer;
}
@@ -48,10 +46,10 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
if (parent.isReadOnly() != null){
query.setReadOnly(parent.isReadOnly());
}
query.setParentNode(getObjectGraphNode());
query.setParentNode(objectGraphNode);
if (queryProps != null){
queryProps.configureManyQuery(query);
queryProps.configureBeanQuery(query);
}
if (parent.isUseAutofetchManager()){
@@ -59,20 +57,6 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
}
}
public ObjectGraphNode getObjectGraphNode() {
// we return the parent node ... as we actually
// query on the parent selecting just it's id
int pos = path.lastIndexOf('.');
if (pos == -1){
return parent.getObjectGraphNode(null);
} else {
String parentPath = path.substring(0, pos);
return parent.getObjectGraphNode(parentPath);
}
}
public BeanPropertyAssocMany<?> getBeanProperty() {
return property;
}
@@ -156,7 +140,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
@Override
public ObjectGraphNode getObjectGraphNode() {
return context.getObjectGraphNode();
return context.objectGraphNode;
}
@Override