#1238 - Refactor MetaInfoManager - collect query plan stats, fix collection of stats on UpdateQuery

This commit is contained in:
Rob Bygrave
2018-01-19 01:07:37 +13:00
parent b9ae76d465
commit 07cdf64ece
27 changed files with 355 additions and 108 deletions
@@ -10,8 +10,24 @@ public class BasicProfileLocationTest {
public void obtain() {
DProfileLocation loc = new DProfileLocation(12);
String obtain = loc.obtain();
assertThat(obtain).endsWith(":12)");
assertThat(loc.obtain()).endsWith(":12)");
assertThat(loc.shortDescription()).isEqualTo("NativeMethodAccessorImpl.invoke0(Native Method:12)");
}
@Test
public void basic_trimPackage() {
BasicProfileLocation loc = new BasicProfileLocation("com.foo.Bar.all");
assertThat(loc.obtain()).isEqualTo("com.foo.Bar.all");
assertThat(loc.shortDescription()).isEqualTo("Bar.all");
}
@Test
public void basic_trimSinglePackage() {
BasicProfileLocation loc = new BasicProfileLocation("foo.Bar.all");
assertThat(loc.obtain()).isEqualTo("foo.Bar.all");
assertThat(loc.shortDescription()).isEqualTo("Bar.all");
}
}
@@ -30,7 +30,7 @@ public class DefaultOrmQueryTest extends BaseTestCase {
assertThat(q1.getWhereExpressions()).isNotNull();
assertThat(q1.getId()).isNull();
q1.checkIdEqualTo();
assertThat(q1.isFindById()).isTrue();
assertThat(q1.getId()).isEqualTo(42);
assertThat(q1.getWhereExpressions()).isNull();
@@ -41,7 +41,16 @@ public class DefaultOrmQueryTest extends BaseTestCase {
DefaultOrmQuery<Order> q1 = (DefaultOrmQuery<Order>) Ebean.find(Order.class).where().idEq(42).query();
assertThat(q1.getId()).isEqualTo(42);
q1.checkIdEqualTo();
assertThat(q1.isFindById()).isTrue();
assertThat(q1.getId()).isEqualTo(42);
}
@Test
public void checkForId_when_setId_ok() {
DefaultOrmQuery<Order> q1 = (DefaultOrmQuery<Order>) Ebean.find(Order.class).setId(42);
assertThat(q1.getId()).isEqualTo(42);
assertThat(q1.isFindById()).isTrue();
assertThat(q1.getId()).isEqualTo(42);
}
@@ -54,4 +54,19 @@ public class CustomerFinder extends Finder<Integer, Customer> {
.setParameter(1, name+"%")
.findSingleAttributeList();
}
/**
* Bulk update names (not a good example here).
*/
public int updateNames(String newName, long minId) {
return update()
.set("name", newName)
.setRaw("version = version + 1")
.where().gt("id", minId)
.update();
}
public int totalCount() {
return query().findCount();
}
}
@@ -3,6 +3,8 @@ package org.tests.query.finder;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import io.ebean.meta.MetaInfoManager;
import io.ebean.meta.MetaQueryPlanStatistic;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.model.basic.Customer;
@@ -127,4 +129,34 @@ public class TestCustomerFinder extends BaseTestCase {
List<String> names = Customer.find.namesStartingWith("F");
assertThat(names).isNotEmpty();
}
@Test
public void test_finders_queryPlans() {
ResetBasicData.reset();
MetaInfoManager metaInfoManager = Ebean.getDefaultServer().getMetaInfoManager();
metaInfoManager.collectQueryPlanStatistics(true);
List<Customer> customers = Customer.find.all();
assertThat(customers).isNotEmpty();
Customer customer = Customer.find.byId(1);
assertThat(customer).isNotNull();
Customer.find.byId(2);
Customer.find.namesStartingWith("F");
Customer.find.byNameStatus("Rob", Customer.Status.ACTIVE);
Customer.find.totalCount();
Customer.find.updateNames("Junk", 2000);
Customer.find.byId(3);
List<MetaQueryPlanStatistic> planStats = metaInfoManager.collectQueryPlanStatistics(true);
assertThat(planStats).hasSize(6);
for (MetaQueryPlanStatistic planStat : planStats) {
System.out.println(planStat);
}
}
}