mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2122 - Metrics for ElementCollection query not included in reporting (via MetaInfoManager)
This commit is contained in:
1 parent
ed2455f460
commit
365b7c4600
6 files changed
+60
-8
No files matched your search
@@ -2087,6 +2087,13 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the simple name of the entity bean.
|
||||
*/
|
||||
public String getSimpleName() {
|
||||
return beanType.getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary description.
|
||||
*/
|
||||
|
||||
@@ -14,13 +14,32 @@ import java.util.Arrays;
|
||||
*/
|
||||
abstract class BeanDescriptorElement<T> extends BeanDescriptor<T> {
|
||||
|
||||
private final String simpleName;
|
||||
|
||||
final ElementHelp elementHelp;
|
||||
|
||||
BeanDescriptorElement(BeanDescriptorMap owner, DeployBeanDescriptor<T> deploy, ElementHelp elementHelp) {
|
||||
super(owner, deploy);
|
||||
this.simpleName = shortName(deploy.getName());
|
||||
this.elementHelp = elementHelp;
|
||||
}
|
||||
|
||||
private String shortName(String name) {
|
||||
int pos = name.lastIndexOf('.');
|
||||
if (pos > 1) {
|
||||
pos = name.lastIndexOf('.', pos - 1);
|
||||
if (pos > 1) {
|
||||
return name.substring(pos + 1);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSimpleName() {
|
||||
return simpleName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJsonReadCollection() {
|
||||
return true;
|
||||
|
||||
@@ -117,6 +117,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
private final TypeManager typeManager;
|
||||
private final BootupClasses bootupClasses;
|
||||
private final String serverName;
|
||||
private final List<BeanDescriptor> elementDescriptors = new ArrayList<>();
|
||||
private final Map<Class<?>, BeanTable> beanTableMap = new HashMap<>();
|
||||
private final Map<String, BeanDescriptor<?>> descMap = new HashMap<>();
|
||||
private final Map<String, BeanDescriptor<?>> descQueueMap = new HashMap<>();
|
||||
@@ -644,6 +645,11 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
if (desc.isDocStoreMapped()) {
|
||||
descQueueMap.put(desc.getDocStoreQueueId(), desc);
|
||||
}
|
||||
for (BeanPropertyAssocMany many : desc.propertiesMany()) {
|
||||
if (many.isElementCollection()) {
|
||||
elementDescriptors.add(many.getElementDescriptor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1619,6 +1625,9 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
for (BeanDescriptor<?> desc : immutableDescriptorList) {
|
||||
desc.visitMetrics(visitor);
|
||||
}
|
||||
for (BeanDescriptor desc : elementDescriptors) {
|
||||
desc.visitMetrics(visitor);
|
||||
}
|
||||
}
|
||||
|
||||
public List<MetaQueryPlan> queryPlanInit(QueryPlanInit request) {
|
||||
|
||||
@@ -569,6 +569,13 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
return elementCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the element bean descriptor (for an element collection only).
|
||||
*/
|
||||
public BeanDescriptor<T> getElementDescriptor() {
|
||||
return elementDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* ManyToMany only, join from local table to intersection table.
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.ebeaninternal.api.SpiQueryBindCapture;
|
||||
import io.ebeaninternal.api.SpiQueryPlan;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import io.ebeaninternal.server.core.timezone.DataTimeZone;
|
||||
import io.ebeaninternal.server.lib.Str;
|
||||
import io.ebeaninternal.server.query.CQueryPlanStats.Snapshot;
|
||||
import io.ebeaninternal.server.type.DataBind;
|
||||
import io.ebeaninternal.server.type.DataBindCapture;
|
||||
@@ -106,7 +107,7 @@ public class CQueryPlan implements SpiQueryPlan {
|
||||
SpiQuery<?> query = request.getQuery();
|
||||
this.profileLocation = query.getProfileLocation();
|
||||
this.label = query.getPlanLabel();
|
||||
this.name = deriveName(label, query.getType());
|
||||
this.name = deriveName(label, query.getType(), request.getBeanDescriptor().getSimpleName());
|
||||
this.location = location();
|
||||
this.asOfTableCount = query.getAsOfTableCount();
|
||||
this.sql = sqlRes.getSql();
|
||||
@@ -130,7 +131,7 @@ public class CQueryPlan implements SpiQueryPlan {
|
||||
SpiQuery<?> query = request.getQuery();
|
||||
this.profileLocation = query.getProfileLocation();
|
||||
this.label = query.getPlanLabel();
|
||||
this.name = deriveName(label, query.getType());
|
||||
this.name = deriveName(label, query.getType(), request.getBeanDescriptor().getSimpleName());
|
||||
this.location = location();
|
||||
this.planKey = buildPlanKey(sql, logWhereSql);
|
||||
this.asOfTableCount = 0;
|
||||
@@ -145,14 +146,19 @@ public class CQueryPlan implements SpiQueryPlan {
|
||||
this.hash = md5Hash();
|
||||
}
|
||||
|
||||
private String deriveName(String label, SpiQuery.Type type) {
|
||||
private String deriveName(String label, SpiQuery.Type type, String simpleName) {
|
||||
if (label == null) {
|
||||
return "orm." + beanType.getSimpleName() + "." + type.label();
|
||||
return Str.add("orm.", simpleName, ".", type.label());
|
||||
}
|
||||
if (label.startsWith(beanType.getSimpleName())) {
|
||||
return "orm." + label;
|
||||
int pos = simpleName.indexOf('.');
|
||||
if (pos > 1) {
|
||||
// element collection and label
|
||||
return Str.add("orm.", simpleName.substring(0, pos), "_", label);
|
||||
}
|
||||
return "orm." + beanType.getSimpleName() + "_" + label;
|
||||
if (label.startsWith(simpleName)) {
|
||||
return Str.add("orm.", label);
|
||||
}
|
||||
return Str.add("orm.", simpleName, "_", label);
|
||||
}
|
||||
|
||||
private SpiQueryBindCapture initBindCapture(SpiQuery<?> query) {
|
||||
|
||||
+5
-1
@@ -30,7 +30,11 @@ public class TestElementCollectionBasic extends BaseTestCase {
|
||||
assertThat(eventLog()).containsOnly("preInsert", "postInsert");
|
||||
assertThat(sql).hasSize(4);
|
||||
|
||||
final EcPerson found = Ebean.find(EcPerson.class, person.getId());
|
||||
final EcPerson found = Ebean.find(EcPerson.class)
|
||||
.setId(person.getId())
|
||||
//.setLabel("findById")
|
||||
.findOne();
|
||||
|
||||
found.getPhoneNumbers().size();
|
||||
|
||||
sql = LoggedSqlCollector.current();
|
||||
|
||||
Reference in new issue
Block a user