mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
#1658 - ENH: Add label to ProfileLocation and use as default query label
This commit is contained in:
1 parent
54534ea7f3
commit
fc032c632b
10 files changed
+65
-8
No files matched your search
@@ -5,14 +5,16 @@ import io.ebean.ProfileLocation;
|
||||
/**
|
||||
* Fixed / given location. Used internally for find by id and find all.
|
||||
*/
|
||||
class BasicProfileLocation implements ProfileLocation {
|
||||
final class BasicProfileLocation implements ProfileLocation {
|
||||
|
||||
private final String location;
|
||||
private final String shortDescription;
|
||||
private final String label;
|
||||
|
||||
BasicProfileLocation(String location) {
|
||||
this.location = location;
|
||||
this.shortDescription = shortDesc(location);
|
||||
this.label = UtilLocation.label(shortDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,6 +32,11 @@ class BasicProfileLocation implements ProfileLocation {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortDescription() {
|
||||
return shortDescription;
|
||||
@@ -38,9 +45,9 @@ class BasicProfileLocation implements ProfileLocation {
|
||||
private String shortDesc(String location) {
|
||||
int lastPer = location.lastIndexOf('.');
|
||||
if (lastPer > -1) {
|
||||
lastPer = location.lastIndexOf('.', lastPer-1);
|
||||
lastPer = location.lastIndexOf('.', lastPer - 1);
|
||||
if (lastPer > -1) {
|
||||
return location.substring(lastPer+1);
|
||||
return location.substring(lastPer + 1);
|
||||
}
|
||||
}
|
||||
return location;
|
||||
|
||||
@@ -15,6 +15,8 @@ class DProfileLocation implements ProfileLocation {
|
||||
|
||||
private String shortDescription;
|
||||
|
||||
private String label;
|
||||
|
||||
private final int lineNumber;
|
||||
|
||||
DProfileLocation() {
|
||||
@@ -42,12 +44,19 @@ class DProfileLocation implements ProfileLocation {
|
||||
public String obtain() {
|
||||
// atomic assignment so happy with this
|
||||
if (location == null) {
|
||||
location = create();
|
||||
shortDescription = shortDesc(location);
|
||||
final String loc = create();
|
||||
shortDescription = shortDesc(loc);
|
||||
label = UtilLocation.label(shortDescription);
|
||||
location = loc;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String label() {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortDescription() {
|
||||
return shortDescription;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
final class UtilLocation {
|
||||
|
||||
static String label(String shortDescription) {
|
||||
int pos = shortDescription.indexOf("(");
|
||||
if (pos == -1) {
|
||||
return shortDescription;
|
||||
} else {
|
||||
return shortDescription.substring(0, pos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class CQueryPlan {
|
||||
this.planKey = request.getQueryPlanKey();
|
||||
SpiQuery<?> query = request.getQuery();
|
||||
this.profileLocation = query.getProfileLocation();
|
||||
this.label = query.getLabel();
|
||||
this.label = query.getPlanLabel();
|
||||
this.location = location();
|
||||
this.autoTuned = query.isAutoTuned();
|
||||
this.asOfTableCount = query.getAsOfTableCount();
|
||||
@@ -135,7 +135,7 @@ public class CQueryPlan {
|
||||
this.beanType = request.getBeanDescriptor().getBeanType();
|
||||
SpiQuery<?> query = request.getQuery();
|
||||
this.profileLocation = query.getProfileLocation();
|
||||
this.label = query.getLabel();
|
||||
this.label = query.getPlanLabel();
|
||||
this.location = location();
|
||||
this.planKey = buildPlanKey(sql, rawSql, rowNumberIncluded, logWhereSql);
|
||||
this.autoTuned = false;
|
||||
|
||||
@@ -164,7 +164,7 @@ public final class CQueryPlanStats {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "location:" + getLocation() + " metrics:" + metrics + " sql:" + getSql();
|
||||
return "label:" + getLabel() + " location:" + getLocation() + " metrics:" + metrics + " sql:" + getSql();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -361,6 +361,17 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlanLabel() {
|
||||
if (label != null) {
|
||||
return label;
|
||||
}
|
||||
if (profileLocation != null) {
|
||||
return profileLocation.label();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> setLabel(String label) {
|
||||
this.label = label;
|
||||
|
||||
Reference in new issue
Block a user