mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
AutoTune update - rename and profiling against original query
This commit is contained in:
@@ -216,7 +216,7 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdminAutofetch getAdminAutofetch() {
|
||||
public AutoTune getAutoTune() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,4 +77,43 @@ public class OrmQueryDetailParserTest extends BaseTestCase {
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("sku","description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWithPlusQuery() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name) fetch customer (+query,id,name,email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("id", "name", "email");
|
||||
assertThat(chunk.isQueryFetch()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTuneApply() {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (status) fetch customer (email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
OrmQueryDetailParser p2 = new OrmQueryDetailParser("select (id,name) fetch customer (+query,id,name,email)");
|
||||
OrmQueryDetail tune = p2.parse();
|
||||
|
||||
|
||||
detail.tuneFetchProperties(tune);
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("id", "name", "email");
|
||||
assertThat(chunk.isQueryFetch()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +1,41 @@
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.AdminAutofetch;
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestBatchLazy extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class);
|
||||
List<Order> list = query.findList();
|
||||
|
||||
|
||||
for (Order order : list) {
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
|
||||
List<OrderDetail> details = order.getDetails();
|
||||
for (OrderDetail orderDetail : details) {
|
||||
orderDetail.getProduct().getSku();
|
||||
}
|
||||
}
|
||||
|
||||
AdminAutofetch adminAutofetch = Ebean.getServer(null).getAdminAutofetch();
|
||||
adminAutofetch.collectUsageViaGC();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
package com.avaje.tests.basic;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestBatchLazy extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class);
|
||||
List<Order> list = query.findList();
|
||||
|
||||
|
||||
for (Order order : list) {
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
|
||||
List<OrderDetail> details = order.getDetails();
|
||||
for (OrderDetail orderDetail : details) {
|
||||
orderDetail.getProduct().getSku();
|
||||
}
|
||||
}
|
||||
|
||||
Ebean.getDefaultServer().getAutoTune().collectProfiling();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class TestByteOnly extends BaseTestCase {
|
||||
|
||||
Ebean.save(e2);
|
||||
|
||||
// Ebean.getServer(null).getAdminAutofetch().collectUsageViaGC();
|
||||
// Ebean.getServer(null).getAdminAutofetch().updateTunedQueryInfo();
|
||||
// Ebean.getServer(null).getAutoTune().collectProfiling();
|
||||
// Ebean.getServer(null).getAutoTune().updateTunedQueryInfo();
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,82 +1,78 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.AdminAutofetch;
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebean.bean.ObjectGraphOrigin;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestAutofetchTuneWithJoin extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
runQuery();
|
||||
collectUsage();
|
||||
}
|
||||
|
||||
private void runQuery() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.setAutofetch(true)
|
||||
//.fetch("customer")
|
||||
//.fetch("customer.contacts")
|
||||
.where().lt("id", 3).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Order order = list.get(i);
|
||||
order.getOrderDate();
|
||||
order.getShipDate();
|
||||
// order.setShipDate(new Date(System.currentTimeMillis()));
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
Address shippingAddress = customer.getShippingAddress();
|
||||
if (shippingAddress != null) {
|
||||
shippingAddress.getLine1();
|
||||
shippingAddress.getCity();
|
||||
}
|
||||
// customer.getContacts()
|
||||
}
|
||||
|
||||
SpiQuery<?> sq = (SpiQuery<?>) q;
|
||||
ObjectGraphNode parentNode = sq.getParentNode();
|
||||
ObjectGraphOrigin origin = parentNode.getOriginQueryPoint();
|
||||
|
||||
System.out.println("Origin:" + origin.getKey());
|
||||
|
||||
// MetaAutoFetchStatistic metaAutoFetchStatistic =
|
||||
// ((DefaultOrmQuery<?>)q).getMetaAutoFetchStatistic();
|
||||
// if (metaAutoFetchStatistic != null) {
|
||||
// List<NodeUsageStats> nodeUsageStats =
|
||||
// metaAutoFetchStatistic.getNodeUsageStats();
|
||||
// System.out.println(nodeUsageStats);
|
||||
// List<QueryStats> queryStats = metaAutoFetchStatistic.getQueryStats();
|
||||
// System.out.println(queryStats);
|
||||
// }
|
||||
|
||||
if (q.isAutofetchTuned()) {
|
||||
System.out.println("TUNED...");
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectUsage() {
|
||||
|
||||
AdminAutofetch adminAutofetch = Ebean.getServer(null).getAdminAutofetch();
|
||||
adminAutofetch.collectUsageViaGC();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebean.bean.ObjectGraphOrigin;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestAutofetchTuneWithJoin extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
runQuery();
|
||||
collectUsage();
|
||||
}
|
||||
|
||||
private void runQuery() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.setAutofetch(true)
|
||||
//.fetch("customer")
|
||||
//.fetch("customer.contacts")
|
||||
.where().lt("id", 3).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Order order = list.get(i);
|
||||
order.getOrderDate();
|
||||
order.getShipDate();
|
||||
// order.setShipDate(new Date(System.currentTimeMillis()));
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
Address shippingAddress = customer.getShippingAddress();
|
||||
if (shippingAddress != null) {
|
||||
shippingAddress.getLine1();
|
||||
shippingAddress.getCity();
|
||||
}
|
||||
// customer.getContacts()
|
||||
}
|
||||
|
||||
SpiQuery<?> sq = (SpiQuery<?>) q;
|
||||
ObjectGraphNode parentNode = sq.getParentNode();
|
||||
ObjectGraphOrigin origin = parentNode.getOriginQueryPoint();
|
||||
|
||||
System.out.println("Origin:" + origin.getKey());
|
||||
|
||||
// MetaAutoFetchStatistic metaAutoFetchStatistic =
|
||||
// ((DefaultOrmQuery<?>)q).getMetaAutoFetchStatistic();
|
||||
// if (metaAutoFetchStatistic != null) {
|
||||
// List<NodeUsageStats> nodeUsageStats =
|
||||
// metaAutoFetchStatistic.getNodeUsageStats();
|
||||
// System.out.println(nodeUsageStats);
|
||||
// List<QueryStats> queryStats = metaAutoFetchStatistic.getQueryStats();
|
||||
// System.out.println(queryStats);
|
||||
// }
|
||||
|
||||
if (q.isAutofetchTuned()) {
|
||||
System.out.println("TUNED...");
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectUsage() {
|
||||
|
||||
Ebean.getDefaultServer().getAutoTune().collectProfiling();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,82 +1,96 @@
|
||||
package com.avaje.tests.query.autotune;
|
||||
|
||||
import com.avaje.ebean.AdminAutofetch;
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebean.bean.ObjectGraphOrigin;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestAutoTuneProfiling extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
for (int i = 0; i < 1; i++) {
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
collectUsage();
|
||||
}
|
||||
|
||||
|
||||
private void execute() {
|
||||
useOrderDate();
|
||||
useOrderDateCustomerName();
|
||||
useLots();
|
||||
}
|
||||
|
||||
|
||||
private Order findById(long id) {
|
||||
return Ebean.find(Order.class)
|
||||
.setAutofetch(true)
|
||||
.setId(id)
|
||||
.findUnique();
|
||||
}
|
||||
|
||||
private void useOrderDate() {
|
||||
Order order = findById(3);
|
||||
order.getStatus();
|
||||
order.getShipDate();
|
||||
}
|
||||
|
||||
private void useOrderDateCustomerName() {
|
||||
Order order = findById(3);
|
||||
order.getOrderDate();
|
||||
order.getCustomer().getName();
|
||||
}
|
||||
|
||||
private void useLots() {
|
||||
|
||||
Order order = findById(3);
|
||||
order.getOrderDate();
|
||||
order.getShipDate();
|
||||
// order.setShipDate(new Date(System.currentTimeMillis()));
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
Address shippingAddress = customer.getShippingAddress();
|
||||
if (shippingAddress != null) {
|
||||
shippingAddress.getLine1();
|
||||
shippingAddress.getCity();
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectUsage() {
|
||||
|
||||
AdminAutofetch adminAutofetch = Ebean.getServer(null).getAdminAutofetch();
|
||||
adminAutofetch.collectUsageViaGC();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.tests.query.autotune;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestAutoTuneProfiling extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
for (int i = 0; i < 1; i++) {
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
collectUsage();
|
||||
}
|
||||
|
||||
|
||||
private void execute() {
|
||||
useOrderDate();
|
||||
useOrderDateCustomerName();
|
||||
useLots();
|
||||
useLotUntuned();
|
||||
}
|
||||
|
||||
private Order findById(long id) {
|
||||
return Ebean.find(Order.class)
|
||||
.select("status, orderDate, shipDate")
|
||||
.setId(id)
|
||||
.findUnique();
|
||||
}
|
||||
|
||||
private void useOrderDate() {
|
||||
Order order = findById(3);
|
||||
order.getStatus();
|
||||
order.getShipDate();
|
||||
}
|
||||
|
||||
private void useOrderDateCustomerName() {
|
||||
Order order = findById(3);
|
||||
order.getOrderDate();
|
||||
order.getCustomer().getName();
|
||||
}
|
||||
|
||||
private void useLots() {
|
||||
|
||||
Order order = findById(3);
|
||||
order.getOrderDate();
|
||||
order.getShipDate();
|
||||
// order.setShipDate(new Date(System.currentTimeMillis()));
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
Address shippingAddress = customer.getShippingAddress();
|
||||
if (shippingAddress != null) {
|
||||
shippingAddress.getLine1();
|
||||
shippingAddress.getCity();
|
||||
}
|
||||
}
|
||||
|
||||
private void useLotUntuned() {
|
||||
Order order = findById(3);
|
||||
List<OrderDetail> details = order.getDetails();
|
||||
for (OrderDetail detail : details) {
|
||||
detail.getProduct().getName();
|
||||
detail.getOrderQty();
|
||||
detail.getShipQty();
|
||||
detail.getUnitPrice();
|
||||
}
|
||||
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
if (billingAddress != null) {
|
||||
billingAddress.getCity();
|
||||
billingAddress.getLine1();
|
||||
billingAddress.getLine2();
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectUsage() {
|
||||
|
||||
Ebean.getDefaultServer().getAutoTune().collectProfiling();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user