mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1673 - ENH: Support ProfileLocation on DtoQuery including via orm query.asDto()
This commit is contained in:
1 parent
46c66b7169
commit
2639e799c5
14 files changed
+117
-35
No files matched your search
@@ -37,6 +37,7 @@ public final class DtoQueryRequest<T> extends AbstractSqlQueryRequest {
|
||||
super(server, query, null);
|
||||
this.queryEngine = engine;
|
||||
this.query = query;
|
||||
query.obtainLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -110,22 +110,12 @@ class DumpMetrics {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("query:").append(padName(metric.getName())).append(" ");
|
||||
addCounters(metric, sb);
|
||||
|
||||
appendQueryName(metric, sb);
|
||||
appendCounters(metric, sb);
|
||||
if (dumpHash) {
|
||||
sb.append("\n hash:").append(metric.getQueryPlanHash());
|
||||
}
|
||||
|
||||
ProfileLocation profileLocation = metric.getProfileLocation();
|
||||
if (dumpLoc && profileLocation != null) {
|
||||
sb.append("\n loc:").append(profileLocation.shortDescription());
|
||||
}
|
||||
|
||||
if (dumpSql) {
|
||||
sb.append("\n\n sql:").append(metric.getSql()).append("\n\n");
|
||||
}
|
||||
|
||||
appendProfileAndSql(metric, sb);
|
||||
out(sb.toString());
|
||||
}
|
||||
|
||||
@@ -134,24 +124,36 @@ class DumpMetrics {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
appendQueryName(metric, sb);
|
||||
appendCounters(metric, sb);
|
||||
appendProfileAndSql(metric, sb);
|
||||
out(sb.toString());
|
||||
}
|
||||
|
||||
private void appendQueryName(MetaQueryMetric metric, StringBuilder sb) {
|
||||
sb.append("query:").append(padName(metric.getName())).append(" ");
|
||||
addCounters(metric, sb);
|
||||
}
|
||||
|
||||
private void appendProfileAndSql(MetaQueryMetric metric, StringBuilder sb) {
|
||||
ProfileLocation profileLocation = metric.getProfileLocation();
|
||||
if (dumpLoc && profileLocation != null) {
|
||||
sb.append("\n loc:").append(profileLocation.shortDescription());
|
||||
}
|
||||
|
||||
if (dumpSql) {
|
||||
sb.append(" \n\n sql:").append(metric.getSql()).append("\n\n");
|
||||
}
|
||||
out(sb.toString());
|
||||
}
|
||||
|
||||
private void log(MetaTimedMetric metric) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(padNameTimed(metric.getName())).append(" ");
|
||||
addCounters(metric, sb);
|
||||
appendCounters(metric, sb);
|
||||
out(sb.toString());
|
||||
}
|
||||
|
||||
private void addCounters(MetaTimedMetric timedMetric, StringBuilder sb) {
|
||||
private void appendCounters(MetaTimedMetric timedMetric, StringBuilder sb) {
|
||||
sb.append(" count:").append(pad(timedMetric.getCount()))
|
||||
.append(" total:").append(pad(timedMetric.getTotal()))
|
||||
.append(" mean:").append(pad(timedMetric.getMean()))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.ebeaninternal.server.dto;
|
||||
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebean.meta.MetricType;
|
||||
import io.ebean.metric.MetricFactory;
|
||||
import io.ebean.metric.QueryPlanMetric;
|
||||
@@ -14,6 +15,8 @@ public class DtoMappingRequest {
|
||||
|
||||
private final String label;
|
||||
|
||||
private final ProfileLocation profileLocation;
|
||||
|
||||
private final String sql;
|
||||
|
||||
private final boolean relaxedMode;
|
||||
@@ -22,7 +25,8 @@ public class DtoMappingRequest {
|
||||
|
||||
public DtoMappingRequest(SpiDtoQuery query, String sql, DtoColumn[] columnMeta) {
|
||||
this.type = query.getType();
|
||||
this.label = query.getLabel();
|
||||
this.label = query.getPlanLabel();
|
||||
this.profileLocation = query.getProfileLocation();
|
||||
this.sql = sql;
|
||||
this.relaxedMode = query.isRelaxedMode();
|
||||
this.columnMeta = columnMeta;
|
||||
@@ -45,6 +49,6 @@ public class DtoMappingRequest {
|
||||
}
|
||||
|
||||
public QueryPlanMetric createMetric() {
|
||||
return MetricFactory.get().createQueryPlanMetric(MetricType.DTO, type, label, sql);
|
||||
return MetricFactory.get().createQueryPlanMetric(MetricType.DTO, type, label, profileLocation, sql);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import io.ebean.DtoQuery;
|
||||
import io.ebean.ProfileLocation;
|
||||
import io.ebeaninternal.api.BindParams;
|
||||
import io.ebeaninternal.api.SpiDtoQuery;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -39,6 +40,8 @@ public class DefaultDtoQuery<T> implements SpiDtoQuery<T> {
|
||||
|
||||
private String label;
|
||||
|
||||
private ProfileLocation profileLocation;
|
||||
|
||||
/**
|
||||
* Bind parameters when using the query language.
|
||||
*/
|
||||
@@ -52,6 +55,7 @@ public class DefaultDtoQuery<T> implements SpiDtoQuery<T> {
|
||||
this.descriptor = descriptor;
|
||||
this.ormQuery = ormQuery;
|
||||
this.label = ormQuery.getLabel();
|
||||
this.profileLocation = ormQuery.getProfileLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,6 +170,35 @@ public class DefaultDtoQuery<T> implements SpiDtoQuery<T> {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlanLabel() {
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
if (profileLocation != null) {
|
||||
return profileLocation.label();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void obtainLocation() {
|
||||
if (profileLocation != null) {
|
||||
profileLocation.obtain();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DtoQuery<T> setProfileLocation(ProfileLocation profileLocation) {
|
||||
this.profileLocation = profileLocation;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileLocation getProfileLocation() {
|
||||
return profileLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFirstRow() {
|
||||
return firstRow;
|
||||
|
||||
Reference in new issue
Block a user