From f8b97ff397f5bfe305a56bdcb1f738399293ac8f Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Wed, 27 Mar 2019 12:57:36 +1300 Subject: [PATCH] #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). --- .../server/loadcontext/DLoadBaseContext.java | 15 +++++++++++ .../server/loadcontext/DLoadBeanContext.java | 1 + .../server/loadcontext/DLoadContext.java | 25 ++++++++++++++++--- .../server/loadcontext/DLoadManyContext.java | 1 + 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBaseContext.java b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBaseContext.java index 21e6c35d3..3eda74298 100644 --- a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBaseContext.java +++ b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBaseContext.java @@ -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(); } diff --git a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java index 4c820c71c..f5207c7bf 100644 --- a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java +++ b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java @@ -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); diff --git a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java index 7a04f3bb7..1b86a169a 100644 --- a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java +++ b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadContext.java @@ -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 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) { diff --git a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java index d98a62039..07123109e 100644 --- a/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java +++ b/src/main/java/io/ebeaninternal/server/loadcontext/DLoadManyContext.java @@ -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) {