#1658 - ENH: Add label to ProfileLocation and use as default query label

- Extend/propagate the label from the origin query to secondary queries
(appending the relative path).
This commit is contained in:
rob bygrave
2019-03-27 12:57:36 +13:00
parent fc032c632b
commit f8b97ff397
4 changed files with 38 additions and 4 deletions
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.loadcontext;
import io.ebean.FetchConfig;
import io.ebean.bean.ObjectGraphNode;
import io.ebean.bean.PersistenceContext;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.querydefn.OrmQueryProperties;
@@ -77,6 +78,20 @@ public abstract class DLoadBaseContext {
return (lazyBatchSize > 1) ? lazyBatchSize : defaultBatchSize;
}
/**
* If the parent has a query plan label then extend it with the path and
* set onto the secondary query.
*/
void setLabel(SpiQuery<?> query) {
String label = parent.getPlanLabel();
if (label != null) {
label += "_" + fullPath;
query.setLabel(label);
query.setProfileLocation(parent.getProfileLocation());
}
}
protected PersistenceContext getPersistenceContext() {
return parent.getPersistenceContext();
}
@@ -43,6 +43,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
protected void configureQuery(SpiQuery<?> query, String lazyLoadProperty) {
setLabel(query);
parent.propagateQueryState(query, desc.isDocStoreMapped());
query.setParentNode(objectGraphNode);
query.setLazyLoadProperty(lazyLoadProperty);
@@ -1,6 +1,7 @@
package io.ebeaninternal.server.loadcontext;
import io.ebean.CacheMode;
import io.ebean.ProfileLocation;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.CallStack;
import io.ebean.bean.EntityBeanIntercept;
@@ -55,6 +56,8 @@ public class DLoadContext implements LoadContext {
private final String relativePath;
private final ObjectGraphOrigin origin;
private final boolean useProfiling;
private final String planLabel;
private final ProfileLocation profileLocation;
private final Map<String, ObjectGraphNode> nodePathMap = new HashMap<>();
@@ -83,6 +86,8 @@ public class DLoadContext implements LoadContext {
this.disableReadAudit = false;
this.includeSoftDeletes = false;
this.relativePath = null;
this.planLabel = null;
this.profileLocation = null;
this.useProfiling = false;
this.rootBeanContext = new DLoadBeanContext(this, rootDescriptor, null, defaultBatchSize, null);
}
@@ -110,6 +115,8 @@ public class DLoadContext implements LoadContext {
this.disableLazyLoading = query.isDisableLazyLoading();
this.useBeanCache = query.getUseBeanCache();
this.useProfiling = query.getProfilingListener() != null;
this.planLabel = query.getPlanLabel();
this.profileLocation = query.getProfileLocation();
ObjectGraphNode parentNode = query.getParentNode();
if (parentNode != null) {
@@ -126,6 +133,19 @@ public class DLoadContext implements LoadContext {
registerSecondaryQueries(secondaryQueries);
}
/**
* Return the query plan label of the origin query.
*/
public String getPlanLabel() {
return planLabel;
}
/**
* Return the profile location of the origin query.
*/
public ProfileLocation getProfileLocation() {
return profileLocation;
}
/**
* Register the +query and +lazy secondary queries with their appropriate LoadBeanContext or LoadManyContext.
@@ -211,10 +231,7 @@ public class DLoadContext implements LoadContext {
@Override
public ObjectGraphNode getObjectGraphNode(String path) {
ObjectGraphNode node = nodePathMap.computeIfAbsent(path, this::createObjectGraphNode);
return node;
return nodePathMap.computeIfAbsent(path, this::createObjectGraphNode);
}
private ObjectGraphNode createObjectGraphNode(String path) {
@@ -59,6 +59,7 @@ public class DLoadManyContext extends DLoadBaseContext implements LoadManyContex
public void configureQuery(SpiQuery<?> query) {
setLabel(query);
parent.propagateQueryState(query, docStoreMapped);
query.setParentNode(objectGraphNode);
if (queryProps != null) {