#1673 - ENH: Support ProfileLocation on DtoQuery including via orm query.asDto()

This commit is contained in:
rob bygrave committed 2019-04-12 02:01:01 +12:00
1 parent 46c66b7169
commit 2639e799c5
14 files changed
+117 -35

No files matched your search

@@ -1,5 +1,6 @@
package io.ebeaninternal.server.profile;
import io.ebean.ProfileLocation;
import io.ebean.meta.MetricType;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.QueryPlanMetric;
@@ -22,8 +23,8 @@ public class DMetricFactory implements MetricFactory {
}
@Override
public QueryPlanMetric createQueryPlanMetric(MetricType metricType, Class<?> type, String label, String sql) {
return new DQueryPlanMetric(new DQueryPlanMeta(type, label, sql), new DTimedMetric(metricType, label));
public QueryPlanMetric createQueryPlanMetric(MetricType metricType, Class<?> type, String label, ProfileLocation profileLocation, String sql) {
return new DQueryPlanMetric(new DQueryPlanMeta(type, label, profileLocation, sql), new DTimedMetric(metricType, label));
}
}
@@ -42,11 +42,12 @@ class DProfileLocation implements ProfileLocation {
@Override
public String obtain() {
// atomic assignment so happy with this
// atomic assignments so happy enough with this (racing but atomic)
if (location == null) {
final String loc = create();
shortDescription = shortDesc(loc);
label = UtilLocation.label(shortDescription);
final String shortDesc = shortDesc(loc);
label = UtilLocation.label(shortDesc);
shortDescription = shortDesc;
location = loc;
}
return location;
@@ -63,6 +64,7 @@ class DProfileLocation implements ProfileLocation {
}
private String create() {
// relatively expensive but we only do it once per profile location
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
for (int i = 3; i < trace.length; i++) {
if (!trace[i].getClassName().startsWith(IO_EBEAN)) {
@@ -1,15 +1,19 @@
package io.ebeaninternal.server.profile;
import io.ebean.ProfileLocation;
class DQueryPlanMeta {
private final Class<?> type;
private final String label;
private final ProfileLocation profileLocation;
private final String name;
private final String sql;
DQueryPlanMeta(Class<?> type, String label, String sql) {
DQueryPlanMeta(Class<?> type, String label, ProfileLocation profileLocation, String sql) {
this.type = type;
this.label = label;
this.profileLocation = profileLocation;
this.sql = sql;
String name = type.getSimpleName();
if (label != null) {
@@ -30,6 +34,10 @@ class DQueryPlanMeta {
return label;
}
public ProfileLocation getProfileLocation() {
return profileLocation;
}
public String getSql() {
return sql;
}
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.profile;
import io.ebean.ProfileLocation;
import io.ebean.meta.MetaQueryMetric;
import io.ebean.meta.MetricType;
import io.ebean.meta.MetricVisitor;
@@ -60,6 +61,11 @@ class DQueryPlanMetric implements QueryPlanMetric {
return meta.getLabel();
}
@Override
public ProfileLocation getProfileLocation() {
return meta.getProfileLocation();
}
@Override
public String getSql() {
return meta.getSql();