mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add MetaObjectGraphNodeStats and MetaQueryPlanOriginCount etc
This commit is contained in:
@@ -21,6 +21,7 @@ public class TestLoadOnDirty extends BaseTestCase {
|
||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
||||
|
||||
Customer customer = Ebean.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
||||
.setUseCache(false)
|
||||
.findUnique();
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(customer);
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.avaje.tests.query.other;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.meta.MetaInfoManager;
|
||||
import com.avaje.ebean.meta.MetaObjectGraphNodeStats;
|
||||
import com.avaje.ebean.meta.MetaQueryPlanStatistic;
|
||||
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;
|
||||
|
||||
public class TestObjectGraphNodeStatsCollection extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
MetaInfoManager infoManager = server.getMetaInfoManager();
|
||||
|
||||
|
||||
server.find(Order.class).findRowCount();
|
||||
|
||||
infoManager.collectNodeStatistics(true);
|
||||
infoManager.collectQueryPlanStatistics(true);
|
||||
|
||||
runFindOrderQuery(server);
|
||||
runFindCustomerQuery(server);
|
||||
|
||||
System.out.println("============================================================");
|
||||
|
||||
List<MetaObjectGraphNodeStats> nodeStatistics = infoManager.collectNodeStatistics(true);
|
||||
for (MetaObjectGraphNodeStats stat : nodeStatistics) {
|
||||
System.out.println("-----------");
|
||||
System.out.println(stat);
|
||||
}
|
||||
|
||||
System.out.println("============================================================");
|
||||
|
||||
List<MetaQueryPlanStatistic> planStatistics = infoManager.collectQueryPlanStatistics(true);
|
||||
for (MetaQueryPlanStatistic planStatistic : planStatistics) {
|
||||
System.out.println("------------");
|
||||
System.out.println(planStatistic);
|
||||
System.out.println(planStatistic.getSql());
|
||||
}
|
||||
|
||||
System.out.println("============================================================");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void runFindCustomerQuery(EbeanServer server) {
|
||||
|
||||
List<Customer> customers = server.find(Customer.class)
|
||||
.select("name")
|
||||
.fetch("contacts")
|
||||
.findList();
|
||||
|
||||
Assert.assertTrue(!customers.isEmpty());
|
||||
|
||||
List<Customer> custs = server.find(Customer.class).select("name").findList();
|
||||
for (Customer customer : custs) {
|
||||
customer.getShippingAddress();
|
||||
}
|
||||
}
|
||||
|
||||
private void runFindOrderQuery(EbeanServer server) {
|
||||
List<Order> orders = server.find(Order.class)
|
||||
.where().gt("id", 0)
|
||||
.order().asc("orderDate")
|
||||
.setMaxRows(40)
|
||||
.findList();
|
||||
|
||||
for (Order order : orders) {
|
||||
Customer customer = order.getCustomer();
|
||||
Address billingAddress = customer.getBillingAddress();
|
||||
if (billingAddress != null) {
|
||||
billingAddress.getCity();
|
||||
}
|
||||
Address shippingAddress = customer.getShippingAddress();
|
||||
if (shippingAddress != null) {
|
||||
shippingAddress.getCity();
|
||||
}
|
||||
List<OrderDetail> details = order.getDetails();
|
||||
for (OrderDetail orderDetail : details) {
|
||||
orderDetail.getUnitPrice();
|
||||
orderDetail.getProduct().getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindByIds() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> ids = Ebean.find(Order.class).findIds();
|
||||
Assert.assertTrue(!ids.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -61,5 +61,10 @@ public class TestRawSqlOrmQuery extends BaseTestCase {
|
||||
|
||||
System.out.println(page);
|
||||
System.out.println(list);
|
||||
|
||||
for (Customer customer : list) {
|
||||
customer.getCretime();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user