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

This commit is contained in:
rob bygrave
2019-03-27 09:37:35 +13:00
parent 54534ea7f3
commit fc032c632b
10 changed files with 65 additions and 8 deletions
@@ -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);
}
}
}