mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Remove unused ServerConfig debugSql options, Update Tests to use agentloader
This commit is contained in:
@@ -2,9 +2,10 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
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;
|
||||
@@ -15,65 +16,64 @@ 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 TestCase {
|
||||
public class TestAutofetchTuneWithJoin extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
runQuery();
|
||||
collectUsage();
|
||||
@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()
|
||||
}
|
||||
|
||||
private void runQuery() {
|
||||
SpiQuery<?> sq = (SpiQuery<?>) q;
|
||||
ObjectGraphNode parentNode = sq.getParentNode();
|
||||
ObjectGraphOrigin origin = parentNode.getOriginQueryPoint();
|
||||
|
||||
ResetBasicData.reset();
|
||||
System.out.println("Origin:" + origin.getKey());
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.setAutofetch(true)
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts")
|
||||
.where().lt("id", 3)
|
||||
.query();
|
||||
// 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);
|
||||
// }
|
||||
|
||||
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...");
|
||||
}
|
||||
if (q.isAutofetchTuned()) {
|
||||
System.out.println("TUNED...");
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectUsage() {
|
||||
private static void collectUsage() {
|
||||
|
||||
AdminAutofetch adminAutofetch = Ebean.getServer(null).getAdminAutofetch();
|
||||
adminAutofetch.collectUsageViaGC();
|
||||
AdminAutofetch adminAutofetch = Ebean.getServer(null).getAdminAutofetch();
|
||||
adminAutofetch.collectUsageViaGC();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
|
||||
public class TestConnectionCloseOnSqlerr extends TestCase {
|
||||
public class TestConnectionCloseOnSqlerr extends BaseTestCase {
|
||||
|
||||
static boolean runManuallyNow = true;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
if (runManuallyNow) {
|
||||
@@ -19,12 +22,13 @@ public class TestConnectionCloseOnSqlerr extends TestCase {
|
||||
try {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
try {
|
||||
Query<Customer> q0 = Ebean.find(Customer.class).where().icontains("namexxx", "Rob").query();
|
||||
Query<Customer> q0 = Ebean.find(Customer.class).where().icontains("namexxx", "Rob")
|
||||
.query();
|
||||
|
||||
q0.findList();
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage().contains("Unsuccessfully waited")) {
|
||||
fail("No connections found while only one thread is running. (after " + i + " queries)");
|
||||
Assert.fail("No connections found while only one thread is running. (after " + i + " queries)");
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -37,6 +41,7 @@ public class TestConnectionCloseOnSqlerr extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactional() {
|
||||
|
||||
if (runManuallyNow) {
|
||||
@@ -47,13 +52,14 @@ public class TestConnectionCloseOnSqlerr extends TestCase {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
try {
|
||||
Ebean.beginTransaction();
|
||||
Query<Customer> q0 = Ebean.find(Customer.class).where().icontains("namexxx", "Rob").query();
|
||||
Query<Customer> q0 = Ebean.find(Customer.class).where().icontains("namexxx", "Rob")
|
||||
.query();
|
||||
|
||||
q0.findList();
|
||||
Ebean.commitTransaction();
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage().contains("Unsuccessfully waited")) {
|
||||
fail("No connections found while only one thread is running. (after " + i + " queries)");
|
||||
Assert.fail("No connections found while only one thread is running. (after " + i + " queries)");
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -3,50 +3,51 @@ package com.avaje.tests.query;
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.BeanState;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.MyLobSize;
|
||||
|
||||
public class TestDefaultFetchLazy extends TestCase {
|
||||
public class TestDefaultFetchLazy extends BaseTestCase {
|
||||
|
||||
public void testFetchTypeLazy(){
|
||||
|
||||
MyLobSize m = new MyLobSize();
|
||||
m.setName("aname");
|
||||
m.setMyCount(10);
|
||||
m.setMyLob("A big lob of data");
|
||||
|
||||
Ebean.save(m);
|
||||
@Test
|
||||
public void testFetchTypeLazy() {
|
||||
|
||||
Assert.assertNotNull(m.getId());
|
||||
MyLobSize m = new MyLobSize();
|
||||
m.setName("aname");
|
||||
m.setMyCount(10);
|
||||
m.setMyLob("A big lob of data");
|
||||
|
||||
MyLobSize myLobSize = Ebean.find(MyLobSize.class, m.getId());
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(myLobSize);
|
||||
Set<String> loadedProps = beanState.getLoadedProps();
|
||||
|
||||
Assert.assertNotNull(loadedProps);
|
||||
Assert.assertTrue(loadedProps.contains("id"));
|
||||
Assert.assertTrue(loadedProps.contains("name"));
|
||||
|
||||
// FetchType.LAZY properties excluded
|
||||
Assert.assertFalse(loadedProps.contains("myLob"));
|
||||
Assert.assertFalse(loadedProps.contains("myCount"));
|
||||
|
||||
Ebean.save(m);
|
||||
|
||||
// the details is also tuned
|
||||
Query<MyLobSize> queryMany = Ebean.find(MyLobSize.class)
|
||||
.fetch("details")// ,"+query")
|
||||
.where().gt("id", 0).query();
|
||||
Assert.assertNotNull(m.getId());
|
||||
|
||||
queryMany.findList();
|
||||
MyLobSize myLobSize = Ebean.find(MyLobSize.class, m.getId());
|
||||
|
||||
BeanState beanState = Ebean.getBeanState(myLobSize);
|
||||
Set<String> loadedProps = beanState.getLoadedProps();
|
||||
|
||||
Assert.assertNotNull(loadedProps);
|
||||
Assert.assertTrue(loadedProps.contains("id"));
|
||||
Assert.assertTrue(loadedProps.contains("name"));
|
||||
|
||||
// FetchType.LAZY properties excluded
|
||||
Assert.assertFalse(loadedProps.contains("myLob"));
|
||||
Assert.assertFalse(loadedProps.contains("myCount"));
|
||||
|
||||
// the details is also tuned
|
||||
Query<MyLobSize> queryMany = Ebean.find(MyLobSize.class).fetch("details")// ,"+query")
|
||||
.where().gt("id", 0).query();
|
||||
|
||||
queryMany.findList();
|
||||
|
||||
String generatedSql = queryMany.getGeneratedSql();
|
||||
Assert.assertTrue(generatedSql.contains("t1.other "));
|
||||
Assert.assertFalse(generatedSql.contains("t1.something "));
|
||||
}
|
||||
|
||||
String generatedSql = queryMany.getGeneratedSql();
|
||||
Assert.assertTrue(generatedSql.contains("t1.other "));
|
||||
Assert.assertFalse(generatedSql.contains("t1.something "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,41 +1,36 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.Query.UseIndex;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestExprNestedDisjunction extends TestCase {
|
||||
public class TestExprNestedDisjunction extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// java.sql.Date dateAfter = java.sql.Date.valueOf("2010-01-01");
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
java.sql.Date onAfter = java.sql.Date.valueOf("2009-08-31");
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> q = Ebean.find(Customer.class)
|
||||
.setUseIndex(UseIndex.NO)
|
||||
.where()
|
||||
.disjunction()
|
||||
.conjunction()
|
||||
.startsWith("name", "r")
|
||||
.eq("anniversary", onAfter)
|
||||
.endJunction()
|
||||
.conjunction()
|
||||
.eq("status", Customer.Status.ACTIVE)
|
||||
.gt("id", 0)
|
||||
.endJunction()
|
||||
.orderBy().asc("name");
|
||||
|
||||
q.findList();
|
||||
String s = q.getGeneratedSql();
|
||||
// java.sql.Date dateAfter = java.sql.Date.valueOf("2010-01-01");
|
||||
|
||||
java.sql.Date onAfter = java.sql.Date.valueOf("2009-08-31");
|
||||
|
||||
Query<Customer> q = Ebean.find(Customer.class).setUseIndex(UseIndex.NO).where().disjunction()
|
||||
.conjunction().startsWith("name", "r").eq("anniversary", onAfter).endJunction()
|
||||
.conjunction().eq("status", Customer.Status.ACTIVE).gt("id", 0).endJunction().orderBy()
|
||||
.asc("name");
|
||||
|
||||
q.findList();
|
||||
String s = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(s
|
||||
.contains("(t0.name like ? and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )"));
|
||||
}
|
||||
|
||||
assertTrue(s.contains("(t0.name like ? and t0.anniversary = ? ) or (t0.status = ? and t0.id > ? )"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
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.ResetBasicData;
|
||||
|
||||
public class TestIContains extends TestCase {
|
||||
public class TestIContains extends BaseTestCase {
|
||||
|
||||
public void testIContains() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// case insensitive
|
||||
Query<Customer> q0 = Ebean.find(Customer.class)
|
||||
.where().icontains("name", "Rob")
|
||||
.query();
|
||||
|
||||
|
||||
q0.findList();
|
||||
String generatedSql = q0.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(generatedSql.contains("lower(t0.name)"));
|
||||
|
||||
@Test
|
||||
public void testIContains() {
|
||||
|
||||
// not case insensitive
|
||||
q0 = Ebean.find(Customer.class)
|
||||
.where().contains("name", "Rob")
|
||||
.query();
|
||||
|
||||
|
||||
q0.findList();
|
||||
generatedSql = q0.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(generatedSql.contains(" t0.name "));
|
||||
ResetBasicData.reset();
|
||||
|
||||
// case insensitive
|
||||
Query<Customer> q0 = Ebean.find(Customer.class).where().icontains("name", "Rob").query();
|
||||
|
||||
q0.findList();
|
||||
String generatedSql = q0.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(generatedSql.contains("lower(t0.name)"));
|
||||
|
||||
// not case insensitive
|
||||
q0 = Ebean.find(Customer.class).where().contains("name", "Rob").query();
|
||||
|
||||
q0.findList();
|
||||
generatedSql = q0.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(generatedSql.contains(" t0.name "));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,34 +3,31 @@ package com.avaje.tests.query;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestInCollectionQueryPlan extends TestCase {
|
||||
public class TestInCollectionQueryPlan extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> idList1 = new ArrayList<Object>();
|
||||
idList1.add(1);
|
||||
|
||||
String oq = "find customer where id in (:idList)";
|
||||
Ebean.createQuery(Customer.class, oq)
|
||||
.setParameter("idList", idList1)
|
||||
.findList();
|
||||
|
||||
List<Object> idList2 = new ArrayList<Object>();
|
||||
idList2.add(1);
|
||||
idList2.add(2);
|
||||
|
||||
Ebean.createQuery(Customer.class, oq)
|
||||
.setParameter("idList", idList2)
|
||||
.findList();
|
||||
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> idList1 = new ArrayList<Object>();
|
||||
idList1.add(1);
|
||||
|
||||
String oq = "find customer where id in (:idList)";
|
||||
Ebean.createQuery(Customer.class, oq).setParameter("idList", idList1).findList();
|
||||
|
||||
List<Object> idList2 = new ArrayList<Object>();
|
||||
idList2.add(1);
|
||||
idList2.add(2);
|
||||
|
||||
Ebean.createQuery(Customer.class, oq).setParameter("idList", idList2).findList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.EOptOneA;
|
||||
|
||||
public class TestJoinOptOneCascade extends TestCase {
|
||||
public class TestJoinOptOneCascade extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
// the left outer join cascades to the join for c
|
||||
Query<EOptOneA> query = Ebean.find(EOptOneA.class).fetch("b").fetch("b.c");
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.contains("left outer join eopt_one_b "));
|
||||
Assert.assertTrue(sql.contains("left outer join eopt_one_c "));
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
// the left outer join cascades to the join for c
|
||||
Query<EOptOneA> query = Ebean.find(EOptOneA.class)
|
||||
.fetch("b")
|
||||
.fetch("b.c");
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.contains("left outer join eopt_one_b "));
|
||||
Assert.assertTrue(sql.contains("left outer join eopt_one_c "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,38 +3,36 @@ package com.avaje.tests.query;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
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.OrderShipment;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestJoinQuery extends TestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// test that join to order.details is not included
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.setAutofetch(false)
|
||||
.fetch("orders")
|
||||
.fetch("orders.details");
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
Assert.assertTrue("has rows", list.size() > 0);
|
||||
|
||||
// test that join to order.details is not included
|
||||
Query<OrderShipment> shipQuery = Ebean.find(OrderShipment.class)
|
||||
.setAutofetch(false)
|
||||
.fetch("order")
|
||||
.fetch("order.details");
|
||||
|
||||
|
||||
List<OrderShipment> shipList = shipQuery.findList();
|
||||
Assert.assertTrue("has rows", shipList.size() > 0);
|
||||
}
|
||||
|
||||
public class TestJoinQuery extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// test that join to order.details is not included
|
||||
Query<Customer> query = Ebean.find(Customer.class).setAutofetch(false).fetch("orders")
|
||||
.fetch("orders.details");
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
Assert.assertTrue("has rows", list.size() > 0);
|
||||
|
||||
// test that join to order.details is not included
|
||||
Query<OrderShipment> shipQuery = Ebean.find(OrderShipment.class).setAutofetch(false)
|
||||
.fetch("order").fetch("order.details");
|
||||
|
||||
List<OrderShipment> shipList = shipQuery.findList();
|
||||
Assert.assertTrue("has rows", shipList.size() > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,34 +2,35 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
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.ResetBasicData;
|
||||
|
||||
public class TestLimitAlterFetchMany extends TestCase {
|
||||
public class TestLimitAlterFetchMany extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// Due to the use of maxRows... we will convert
|
||||
// the fetch join to contacts over to a query join
|
||||
// ... otherwise we wouldn't be able to use the
|
||||
// limit offset clause
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
// this will automatically get converted to a
|
||||
// query join ... due to the maxRows
|
||||
.fetch("contacts").setMaxRows(5);
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
|
||||
System.out.println(list);
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// Due to the use of maxRows... we will convert
|
||||
// the fetch join to contacts over to a query join
|
||||
// ... otherwise we wouldn't be able to use the
|
||||
// limit offset clause
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
// this will automatically get converted to a
|
||||
// query join ... due to the maxRows
|
||||
.fetch("contacts")
|
||||
.setMaxRows(5);
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
|
||||
System.out.println(list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Expr;
|
||||
import com.avaje.ebean.Junction;
|
||||
@@ -11,22 +13,23 @@ import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestLimitQuery extends TestCase {
|
||||
public class TestLimitQuery extends BaseTestCase {
|
||||
|
||||
public void testHasManyWithLimit()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
@Test
|
||||
public void testHasManyWithLimit() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class);
|
||||
query.setAutofetch(false);
|
||||
query.setFirstRow(0);
|
||||
query.setMaxRows(10);
|
||||
Query<Customer> query = Ebean.find(Customer.class);
|
||||
query.setAutofetch(false);
|
||||
query.setFirstRow(0);
|
||||
query.setMaxRows(10);
|
||||
|
||||
Junction<Customer> junc = Expr.disjunction(query);
|
||||
junc.add(Expr.like("name", "%A%"));
|
||||
query.where(junc);
|
||||
Junction<Customer> junc = Expr.disjunction(query);
|
||||
junc.add(Expr.like("name", "%A%"));
|
||||
query.where(junc);
|
||||
|
||||
List<Customer> customer = query.findList();
|
||||
assertTrue(customer.size() > 0); // should at least find the "Cust NoAddress" customer
|
||||
}
|
||||
List<Customer> customer = query.findList();
|
||||
Assert.assertTrue(customer.size() > 0); // should at least find the
|
||||
// "Cust NoAddress" customer
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,36 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
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.ResetBasicData;
|
||||
|
||||
public class TestManyWhereJoin extends TestCase {
|
||||
public class TestManyWhereJoin extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.select("id,status")
|
||||
//.join("orders")
|
||||
// the where on a 'many' (like orders) requires an
|
||||
// additional join and distinct which is independent
|
||||
// of a fetch join (if there is a fetch join)
|
||||
.where().eq("orders.status", Order.Status.NEW)
|
||||
//.where().eq("orders.details.product.name", "Desk")
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.indexOf("select distinct ") > -1);
|
||||
Assert.assertTrue(sql.indexOf("join o_order ") > -1);
|
||||
Assert.assertTrue(sql.indexOf(".status = ?") > -1);
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class).select("id,status")
|
||||
// .join("orders")
|
||||
// the where on a 'many' (like orders) requires an
|
||||
// additional join and distinct which is independent
|
||||
// of a fetch join (if there is a fetch join)
|
||||
.where().eq("orders.status", Order.Status.NEW)
|
||||
// .where().eq("orders.details.product.name", "Desk")
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.indexOf("select distinct ") > -1);
|
||||
Assert.assertTrue(sql.indexOf("join o_order ") > -1);
|
||||
Assert.assertTrue(sql.indexOf(".status = ?") > -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,66 +2,63 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.MRole;
|
||||
import com.avaje.tests.model.basic.MUser;
|
||||
|
||||
public class TestManyWhereJoinM2M extends TestCase {
|
||||
public class TestManyWhereJoinM2M extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
Ebean.beginTransaction();
|
||||
|
||||
MRole r1 = new MRole();
|
||||
r1.setRoleName("role1");
|
||||
Ebean.save(r1);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
MRole r2 = new MRole();
|
||||
r2.setRoleName("role2special");
|
||||
Ebean.save(r2);
|
||||
Ebean.beginTransaction();
|
||||
|
||||
MRole r3 = new MRole();
|
||||
r3.setRoleName("role3");
|
||||
Ebean.save(r3);
|
||||
MRole r1 = new MRole();
|
||||
r1.setRoleName("role1");
|
||||
Ebean.save(r1);
|
||||
|
||||
MUser u0 = new MUser();
|
||||
u0.setUserName("user0");
|
||||
u0.addRole(r1);
|
||||
u0.addRole(r2);
|
||||
MRole r2 = new MRole();
|
||||
r2.setRoleName("role2special");
|
||||
Ebean.save(r2);
|
||||
|
||||
Ebean.save(u0);
|
||||
MRole r3 = new MRole();
|
||||
r3.setRoleName("role3");
|
||||
Ebean.save(r3);
|
||||
|
||||
MUser u1 = new MUser();
|
||||
u1.setUserName("user1");
|
||||
u1.addRole(r1);
|
||||
MUser u0 = new MUser();
|
||||
u0.setUserName("user0");
|
||||
u0.addRole(r1);
|
||||
u0.addRole(r2);
|
||||
|
||||
Ebean.save(u1);
|
||||
|
||||
Ebean.commitTransaction();
|
||||
|
||||
|
||||
|
||||
Query<MUser> query = Ebean.find(MUser.class)
|
||||
.fetch("roles")
|
||||
// the where on a 'many' (like orders) requires an
|
||||
// additional join and distinct which is independent
|
||||
// of a fetch join (if there is a fetch join)
|
||||
.where().eq("roles.roleName", "role2special")
|
||||
.query();
|
||||
|
||||
List<MUser> list = query.findList();
|
||||
System.out.println(list);
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.indexOf("select distinct") > -1);
|
||||
Assert.assertTrue(sql.indexOf("left outer join mrole ") > -1);
|
||||
Assert.assertTrue(sql.indexOf("join mrole ") > -1);
|
||||
Assert.assertTrue(sql.indexOf(".role_name = ?") > -1);
|
||||
|
||||
}
|
||||
Ebean.save(u0);
|
||||
|
||||
MUser u1 = new MUser();
|
||||
u1.setUserName("user1");
|
||||
u1.addRole(r1);
|
||||
|
||||
Ebean.save(u1);
|
||||
|
||||
Ebean.commitTransaction();
|
||||
|
||||
Query<MUser> query = Ebean.find(MUser.class).fetch("roles")
|
||||
// the where on a 'many' (like orders) requires an
|
||||
// additional join and distinct which is independent
|
||||
// of a fetch join (if there is a fetch join)
|
||||
.where().eq("roles.roleName", "role2special").query();
|
||||
|
||||
List<MUser> list = query.findList();
|
||||
System.out.println(list);
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.indexOf("select distinct") > -1);
|
||||
Assert.assertTrue(sql.indexOf("left outer join mrole ") > -1);
|
||||
Assert.assertTrue(sql.indexOf("join mrole ") > -1);
|
||||
Assert.assertTrue(sql.indexOf(".role_name = ?") > -1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,26 +2,25 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.MyAdHoc;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestMyAdHocSqlSelect extends TestCase {
|
||||
public class TestMyAdHocSqlSelect extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<MyAdHoc> list = Ebean.find(MyAdHoc.class).where().gt("order_id", 0).having()
|
||||
.gt("detailCount", 0).findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<MyAdHoc> list = Ebean.find(MyAdHoc.class)
|
||||
.where().gt("order_id", 0)
|
||||
.having().gt("detailCount", 0)
|
||||
.findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
public class TestNoSpaceBracket extends TestCase {
|
||||
public class TestNoSpaceBracket extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Query<Order> query = Ebean.createQuery(Order.class, "find order join customer(id,name) ");
|
||||
|
||||
query.findList();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
Query<Order> query = Ebean.createQuery(Order.class, "find order join customer(id,name) ");
|
||||
|
||||
query.findList();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,45 +2,47 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.PagingList;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestPagingListLoop extends TestCase {
|
||||
public class TestPagingListLoop extends BaseTestCase {
|
||||
|
||||
public void test() throws InterruptedException, ExecutionException {
|
||||
|
||||
// boolean autoRunTest = false;
|
||||
// if (!autoRunTest){
|
||||
// // we only want to run this test manually.
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
ResetBasicData.reset();
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
PagingList<Customer> pagingList = Ebean.find(Customer.class).findPagingList(10);
|
||||
pagingList.getFutureRowCount();//.get();
|
||||
|
||||
//createLeak();
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws InterruptedException, ExecutionException {
|
||||
|
||||
// boolean autoRunTest = false;
|
||||
// if (!autoRunTest){
|
||||
// // we only want to run this test manually.
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
ResetBasicData.reset();
|
||||
|
||||
for (int i = 0; i < 50; i++) {
|
||||
PagingList<Customer> pagingList = Ebean.find(Customer.class).findPagingList(10);
|
||||
pagingList.getFutureRowCount();// .get();
|
||||
|
||||
// createLeak();
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// private void createLeak() {
|
||||
//
|
||||
// // create a transaction we never close ...
|
||||
// // ... a connection pool leak
|
||||
// Ebean.getServer(null).createTransaction();
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
// private void createLeak() {
|
||||
//
|
||||
// // create a transaction we never close ...
|
||||
// // ... a connection pool leak
|
||||
// Ebean.getServer(null).createTransaction();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,45 +2,38 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFetchJoinWithOrder extends TestCase {
|
||||
public class TestQueryFetchJoinWithOrder extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.fetch("details", new FetchConfig().query())
|
||||
.order().asc("id")
|
||||
.order().desc("details.id")
|
||||
.findList();
|
||||
|
||||
assertNotNull(list);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
List<Order> list2 = Ebean.find(Order.class)
|
||||
.fetch("customer", new FetchConfig().query())
|
||||
.fetch("customer.contacts")
|
||||
.order().asc("id")
|
||||
.order().asc("customer.contacts.lastName")
|
||||
.findList();
|
||||
ResetBasicData.reset();
|
||||
|
||||
assertNotNull(list2);
|
||||
List<Order> list = Ebean.find(Order.class).fetch("details", new FetchConfig().query()).order()
|
||||
.asc("id").order().desc("details.id").findList();
|
||||
|
||||
|
||||
List<Customer> list3 = Ebean.find(Customer.class)
|
||||
.fetch("orders")
|
||||
.filterMany("orders").eq("status", Order.Status.NEW)
|
||||
.order().desc("orders.id")
|
||||
.findList();
|
||||
|
||||
assertNotNull(list3);
|
||||
Assert.assertNotNull(list);
|
||||
|
||||
}
|
||||
List<Order> list2 = Ebean.find(Order.class).fetch("customer", new FetchConfig().query())
|
||||
.fetch("customer.contacts").order().asc("id").order().asc("customer.contacts.lastName")
|
||||
.findList();
|
||||
|
||||
Assert.assertNotNull(list2);
|
||||
|
||||
List<Customer> list3 = Ebean.find(Customer.class).fetch("orders").filterMany("orders")
|
||||
.eq("status", Order.Status.NEW).order().desc("orders.id").findList();
|
||||
|
||||
Assert.assertNotNull(list3);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.ContactNote;
|
||||
@@ -11,36 +12,34 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFetchSkipPath extends TestCase {
|
||||
public class TestQueryFetchSkipPath extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
|
||||
//.setAutofetch(true)
|
||||
.setAutofetch(false)
|
||||
.select("status")
|
||||
// .fetch("customer","id")
|
||||
// .fetch("customer.contacts","id")
|
||||
.fetch("customer.contacts.notes","title")
|
||||
.findList();
|
||||
|
||||
for (Order order : list) {
|
||||
order.getStatus();
|
||||
Customer customer = order.getCustomer();
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
for (Contact contact : contacts) {
|
||||
System.out.println("contact:"+contact);
|
||||
List<ContactNote> notes = contact.getNotes();
|
||||
for (ContactNote contactNote : notes) {
|
||||
System.out.println("note:"+contactNote.getTitle());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
|
||||
// .setAutofetch(true)
|
||||
.setAutofetch(false).select("status")
|
||||
// .fetch("customer","id")
|
||||
// .fetch("customer.contacts","id")
|
||||
.fetch("customer.contacts.notes", "title").findList();
|
||||
|
||||
for (Order order : list) {
|
||||
order.getStatus();
|
||||
Customer customer = order.getCustomer();
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
for (Contact contact : contacts) {
|
||||
System.out.println("contact:" + contact);
|
||||
List<ContactNote> notes = contact.getNotes();
|
||||
for (ContactNote contactNote : notes) {
|
||||
System.out.println("note:" + contactNote.getTitle());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.ebean.Query;
|
||||
@@ -11,29 +12,27 @@ import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFilterMany extends TestCase {
|
||||
public class TestQueryFilterMany extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.fetch("orders", new FetchConfig().lazy())
|
||||
.where().ilike("name","Rob%")
|
||||
.filterMany("orders").eq("status", Order.Status.NEW)
|
||||
.where().gt("id", 0)
|
||||
.query();
|
||||
|
||||
//query.filterMany("orders").eq("status", Order.Status.NEW);
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
for (Customer customer : list) {
|
||||
customer.getOrders().size();
|
||||
}
|
||||
|
||||
Customer c0 = list.get(0);
|
||||
System.out.println("......... refreshMany ...");
|
||||
Ebean.refreshMany(c0, "orders");
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class).fetch("orders", new FetchConfig().lazy())
|
||||
.where().ilike("name", "Rob%").filterMany("orders").eq("status", Order.Status.NEW).where()
|
||||
.gt("id", 0).query();
|
||||
|
||||
// query.filterMany("orders").eq("status", Order.Status.NEW);
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
for (Customer customer : list) {
|
||||
customer.getOrders().size();
|
||||
}
|
||||
|
||||
Customer c0 = list.get(0);
|
||||
System.out.println("......... refreshMany ...");
|
||||
Ebean.refreshMany(c0, "orders");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.MUser;
|
||||
|
||||
public class TestQueryFilterManyOnM2M extends TestCase {
|
||||
public class TestQueryFilterManyOnM2M extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Ebean.find(MUser.class).fetch("roles").filterMany("roles").ilike("roleName", "Jim%").findList();
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
Ebean.find(MUser.class)
|
||||
.fetch("roles")
|
||||
.filterMany("roles").ilike("roleName","Jim%")
|
||||
.findList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,38 +3,36 @@ package com.avaje.tests.query;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFilterManySimple extends TestCase {
|
||||
public class TestQueryFilterManySimple extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// not really last week :)
|
||||
Date lastWeek = Date.valueOf("2010-01-01");
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
// .join("orders", new JoinConfig().lazy())
|
||||
// .join("orders", new JoinConfig().query())
|
||||
.fetch("orders")
|
||||
.fetch("contacts", new FetchConfig().query())
|
||||
.where().ilike("name","rob%")
|
||||
.filterMany("orders")
|
||||
.eq("status", Order.Status.NEW)
|
||||
.gt("orderDate", lastWeek)
|
||||
.filterMany("contacts").isNotNull("firstName")
|
||||
.findList();
|
||||
|
||||
System.out.println(list);
|
||||
// invoke lazy loading
|
||||
list.get(0).getOrders().size();
|
||||
System.out.println(list.get(0).getOrders());
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
// not really last week :)
|
||||
Date lastWeek = Date.valueOf("2010-01-01");
|
||||
|
||||
List<Customer> list = Ebean
|
||||
.find(Customer.class)
|
||||
// .join("orders", new JoinConfig().lazy())
|
||||
// .join("orders", new JoinConfig().query())
|
||||
.fetch("orders").fetch("contacts", new FetchConfig().query()).where().ilike("name", "rob%")
|
||||
.filterMany("orders").eq("status", Order.Status.NEW).gt("orderDate", lastWeek)
|
||||
.filterMany("contacts").isNotNull("firstName").findList();
|
||||
|
||||
System.out.println(list);
|
||||
// invoke lazy loading
|
||||
list.get(0).getOrders().size();
|
||||
System.out.println(list.get(0).getOrders());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
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.FetchConfig;
|
||||
@@ -12,34 +12,32 @@ import com.avaje.ebean.QueryIterator;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFindIterate extends TestCase {
|
||||
public class TestQueryFindIterate extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
Query<Customer> query = server.find(Customer.class)
|
||||
.setAutofetch(false)
|
||||
.fetch("contacts",new FetchConfig().query(2))
|
||||
.where().gt("id", 0)
|
||||
.orderBy("id")
|
||||
.setMaxRows(2);
|
||||
|
||||
int count = 0;
|
||||
|
||||
QueryIterator<Customer> it = query.findIterate();
|
||||
try {
|
||||
while (it.hasNext()) {
|
||||
Customer customer = it.next();
|
||||
customer.hashCode();
|
||||
count++;
|
||||
}
|
||||
} finally {
|
||||
it.close();
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Assert.assertEquals(2, count);
|
||||
ResetBasicData.reset();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
Query<Customer> query = server.find(Customer.class).setAutofetch(false)
|
||||
.fetch("contacts", new FetchConfig().query(2)).where().gt("id", 0).orderBy("id")
|
||||
.setMaxRows(2);
|
||||
|
||||
int count = 0;
|
||||
|
||||
QueryIterator<Customer> it = query.findIterate();
|
||||
try {
|
||||
while (it.hasNext()) {
|
||||
Customer customer = it.next();
|
||||
customer.hashCode();
|
||||
count++;
|
||||
}
|
||||
} finally {
|
||||
it.close();
|
||||
}
|
||||
|
||||
Assert.assertEquals(2, count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,25 +2,24 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFindMapTypedKey extends TestCase {
|
||||
public class TestQueryFindMapTypedKey extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Map<String, Customer> map =
|
||||
Ebean.find(Customer.class)
|
||||
.select("id, name")
|
||||
.findMap("name", String.class);
|
||||
|
||||
Assert.assertNotNull(map);
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Map<String, Customer> map = Ebean.find(Customer.class).select("id, name")
|
||||
.findMap("name", String.class);
|
||||
|
||||
Assert.assertNotNull(map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,50 +2,47 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Article;
|
||||
import com.avaje.tests.model.basic.Section;
|
||||
|
||||
public class TestQueryFindReadOnly extends TestCase {
|
||||
public class TestQueryFindReadOnly extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
Section s0 = new Section("some content");
|
||||
Article a0 = new Article("art1","auth1");
|
||||
a0.addSection(s0);
|
||||
|
||||
Ebean.save(a0);
|
||||
|
||||
Article ar1 = Ebean.find(Article.class)
|
||||
.setReadOnly(true)
|
||||
.setId(a0.getId())
|
||||
.findUnique();
|
||||
|
||||
Assert.assertNotNull(ar1);
|
||||
Assert.assertTrue("readonly",Ebean.getBeanState(ar1).isReadOnly());
|
||||
|
||||
List<Section> ar1sections = ar1.getSections();
|
||||
Assert.assertEquals(1, ar1sections.size());
|
||||
|
||||
Section s2 = ar1sections.get(0);
|
||||
Assert.assertTrue("readonly cascading",Ebean.getBeanState(s2).isReadOnly());
|
||||
|
||||
|
||||
Ebean.runCacheWarming(Article.class);
|
||||
|
||||
Article ar0 = Ebean.find(Article.class, a0.getId());
|
||||
|
||||
Assert.assertNotNull(ar0);
|
||||
Assert.assertFalse(Ebean.getBeanState(ar0).isReadOnly());
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Section s0 = new Section("some content");
|
||||
Article a0 = new Article("art1", "auth1");
|
||||
a0.addSection(s0);
|
||||
|
||||
Ebean.save(a0);
|
||||
|
||||
Article ar1 = Ebean.find(Article.class).setReadOnly(true).setId(a0.getId()).findUnique();
|
||||
|
||||
Assert.assertNotNull(ar1);
|
||||
Assert.assertTrue("readonly", Ebean.getBeanState(ar1).isReadOnly());
|
||||
|
||||
List<Section> ar1sections = ar1.getSections();
|
||||
Assert.assertEquals(1, ar1sections.size());
|
||||
|
||||
Section s2 = ar1sections.get(0);
|
||||
Assert.assertTrue("readonly cascading", Ebean.getBeanState(s2).isReadOnly());
|
||||
|
||||
Ebean.runCacheWarming(Article.class);
|
||||
|
||||
Article ar0 = Ebean.find(Article.class, a0.getId());
|
||||
|
||||
Assert.assertNotNull(ar0);
|
||||
Assert.assertFalse(Ebean.getBeanState(ar0).isReadOnly());
|
||||
|
||||
List<Section> ar0sections = ar0.getSections();
|
||||
Section s1 = ar0sections.get(0);
|
||||
Assert.assertFalse(Ebean.getBeanState(s1).isReadOnly());
|
||||
|
||||
}
|
||||
|
||||
List<Section> ar0sections = ar0.getSections();
|
||||
Section s1 = ar0sections.get(0);
|
||||
Assert.assertFalse(Ebean.getBeanState(s1).isReadOnly());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
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.FetchConfig;
|
||||
@@ -14,31 +14,29 @@ import com.avaje.ebean.QueryResultVisitor;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryFindVisit extends TestCase {
|
||||
public class TestQueryFindVisit extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
Query<Customer> query = server.find(Customer.class)
|
||||
.setAutofetch(false)
|
||||
.fetch("contacts",new FetchConfig().query(2))
|
||||
.where().gt("id", 0)
|
||||
.orderBy("id")
|
||||
.setMaxRows(2);
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
query.findVisit(new QueryResultVisitor<Customer>() {
|
||||
|
||||
public boolean accept(Customer bean) {
|
||||
counter.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(2, counter.get());
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
Query<Customer> query = server.find(Customer.class).setAutofetch(false)
|
||||
.fetch("contacts", new FetchConfig().query(2)).where().gt("id", 0).orderBy("id")
|
||||
.setMaxRows(2);
|
||||
|
||||
final AtomicInteger counter = new AtomicInteger(0);
|
||||
|
||||
query.findVisit(new QueryResultVisitor<Customer>() {
|
||||
|
||||
public boolean accept(Customer bean) {
|
||||
counter.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(2, counter.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,36 +2,32 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
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.ResetBasicData;
|
||||
|
||||
public class TestQueryInAssocOne extends TestCase {
|
||||
public class TestQueryInAssocOne extends BaseTestCase {
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.where().lt("id",200)
|
||||
.findList();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.where().in("customer", list)
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql, sql.indexOf("join o_customer t1 on t1.id = t0.kcustomer_id") > -1);
|
||||
Assert.assertTrue(sql, sql.indexOf("t0.kcustomer_id in (?") > -1);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).where().lt("id", 200).findList();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).where().in("customer", list).query();
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql, sql.indexOf("join o_customer t1 on t1.id = t0.kcustomer_id") > -1);
|
||||
Assert.assertTrue(sql, sql.indexOf("t0.kcustomer_id in (?") > -1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,28 @@ package com.avaje.tests.query;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryInIdTypeConversion extends TestCase {
|
||||
public class TestQueryInIdTypeConversion extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<String> idList = new ArrayList<String>();
|
||||
idList.add("1");
|
||||
idList.add("2");
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.where().idIn(idList)
|
||||
.findList();
|
||||
|
||||
assertNotNull(list);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<String> idList = new ArrayList<String>();
|
||||
idList.add("1");
|
||||
idList.add("2");
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).where().idIn(idList).findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,84 +2,72 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryJoinManyNonRoot extends TestCase {
|
||||
public class TestQueryJoinManyNonRoot extends BaseTestCase {
|
||||
|
||||
public void test_manyNonRoot() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts")
|
||||
.where().gt("id", 0)
|
||||
.query();
|
||||
@Test
|
||||
public void test_manyNonRoot() {
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer t1 on t1.id "));
|
||||
Assert.assertTrue(sql.contains("left outer join contact t2 on"));
|
||||
|
||||
}
|
||||
ResetBasicData.reset();
|
||||
|
||||
public void test_manyRootQueryJoinOrderDetailsFirst() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.fetch("details")
|
||||
.fetch("details.product")
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts")
|
||||
.where().gt("id", 0)
|
||||
.query();
|
||||
Query<Order> q = Ebean.find(Order.class).fetch("customer").fetch("customer.contacts").where()
|
||||
.gt("id", 0).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer t1 on t1.id "));
|
||||
Assert.assertTrue(sql.contains("left outer join o_order_detail "));
|
||||
Assert.assertTrue(sql.contains("left outer join o_product "));
|
||||
|
||||
Assert.assertFalse(sql.contains("left outer join contact"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void test_manyRootQueryJoinCustomerContactsFirst() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts")
|
||||
.fetch("details")
|
||||
.fetch("details.product")
|
||||
.where().gt("id", 0)
|
||||
.query();
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer t1 on t1.id "));
|
||||
Assert.assertTrue(sql.contains("left outer join contact "));
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer t1 on t1.id "));
|
||||
Assert.assertTrue(sql.contains("left outer join contact t2 on"));
|
||||
|
||||
Assert.assertFalse(sql.contains("left outer join o_order_detail "));
|
||||
Assert.assertFalse(sql.contains("left outer join o_product "));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_manyRootQueryJoinOrderDetailsFirst() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class).fetch("details").fetch("details.product")
|
||||
.fetch("customer").fetch("customer.contacts").where().gt("id", 0).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer t1 on t1.id "));
|
||||
Assert.assertTrue(sql.contains("left outer join o_order_detail "));
|
||||
Assert.assertTrue(sql.contains("left outer join o_product "));
|
||||
|
||||
Assert.assertFalse(sql.contains("left outer join contact"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_manyRootQueryJoinCustomerContactsFirst() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class).fetch("customer").fetch("customer.contacts")
|
||||
.fetch("details").fetch("details.product").where().gt("id", 0).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer t1 on t1.id "));
|
||||
Assert.assertTrue(sql.contains("left outer join contact "));
|
||||
|
||||
Assert.assertFalse(sql.contains("left outer join o_order_detail "));
|
||||
Assert.assertFalse(sql.contains("left outer join o_product "));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,35 +2,32 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryJoinMulipleMany extends TestCase {
|
||||
public class TestQueryJoinMulipleMany extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts")
|
||||
.where().gt("id", 0)
|
||||
.findList();
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
System.out.println(list);
|
||||
|
||||
for (Order order : list) {
|
||||
List<Contact> contacts = order.getCustomer().getContacts();
|
||||
contacts.size();
|
||||
}
|
||||
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).fetch("customer").fetch("customer.contacts").where()
|
||||
.gt("id", 0).findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
System.out.println(list);
|
||||
|
||||
for (Order order : list) {
|
||||
List<Contact> contacts = order.getCustomer().getContacts();
|
||||
contacts.size();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
@@ -15,44 +15,40 @@ import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryJoinQueryNonRoot extends TestCase {
|
||||
public class TestQueryJoinQueryNonRoot extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer)Ebean.getServer(null);
|
||||
BeanDescriptor<Order> d = server.getBeanDescriptor(Order.class);
|
||||
ElPropertyValue elGetValue = d.getElGetValue("customer.contacts");
|
||||
|
||||
Assert.assertTrue(elGetValue.containsMany());
|
||||
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts", "firstName", new FetchConfig().query().lazy(10))
|
||||
.fetch("customer.contacts.group")
|
||||
.where().lt("id", 3)
|
||||
.findList();
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
|
||||
for (Order order : list) {
|
||||
List<Contact> contacts = order.getCustomer().getContacts();
|
||||
for (Contact contact : contacts) {
|
||||
contact.getFirstName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// String oq = "find order join customer join customer.contacts join details (+query(4),+lazy(5))";
|
||||
// Query<Order> q = Ebean.createQuery(Order.class, oq);
|
||||
// q.setAutofetch(false);
|
||||
// List<Order> list2 = q.findList();
|
||||
//
|
||||
// Assert.assertTrue(list2.size() > 0);
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) Ebean.getServer(null);
|
||||
BeanDescriptor<Order> d = server.getBeanDescriptor(Order.class);
|
||||
ElPropertyValue elGetValue = d.getElGetValue("customer.contacts");
|
||||
|
||||
Assert.assertTrue(elGetValue.containsMany());
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).fetch("customer")
|
||||
.fetch("customer.contacts", "firstName", new FetchConfig().query().lazy(10))
|
||||
.fetch("customer.contacts.group").where().lt("id", 3).findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
|
||||
for (Order order : list) {
|
||||
List<Contact> contacts = order.getCustomer().getContacts();
|
||||
for (Contact contact : contacts) {
|
||||
contact.getFirstName();
|
||||
}
|
||||
}
|
||||
|
||||
// String oq =
|
||||
// "find order join customer join customer.contacts join details (+query(4),+lazy(5))";
|
||||
// Query<Order> q = Ebean.createQuery(Order.class, oq);
|
||||
// q.setAutofetch(false);
|
||||
// List<Order> list2 = q.findList();
|
||||
//
|
||||
// Assert.assertTrue(list2.size() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryLimitOffsetSimple extends TestCase {
|
||||
public class TestQueryLimitOffsetSimple extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Test the syntax of the limit offset clause.
|
||||
*/
|
||||
@Test
|
||||
public void testMe() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
@@ -2,39 +2,34 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryMultiManyOrder extends TestCase {
|
||||
public class TestQueryMultiManyOrder extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.fetch("shipments")
|
||||
.fetch("details")
|
||||
.fetch("details.product")
|
||||
.fetch("customer")
|
||||
.where().gt("id", 0)
|
||||
.query();
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer "));
|
||||
|
||||
Assert.assertFalse(sql.contains("left outer join contact "));
|
||||
Assert.assertFalse(sql.contains("left outer join o_order_detail "));
|
||||
Assert.assertFalse(sql.contains("left outer join o_product "));
|
||||
|
||||
|
||||
}
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class).fetch("shipments").fetch("details")
|
||||
.fetch("details.product").fetch("customer").where().gt("id", 0).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
String sql = q.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(list.size() > 0);
|
||||
Assert.assertTrue(sql.contains("join o_customer "));
|
||||
|
||||
Assert.assertFalse(sql.contains("left outer join contact "));
|
||||
Assert.assertFalse(sql.contains("left outer join o_order_detail "));
|
||||
Assert.assertFalse(sql.contains("left outer join o_product "));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,49 +2,45 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryNullAssocOne extends TestCase {
|
||||
public class TestQueryNullAssocOne extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
Query<Order> q0 = Ebean.find(Order.class)
|
||||
.where().eq("customer", null).query();
|
||||
|
||||
List<Order> orders = q0.findList();
|
||||
assertNotNull(orders);
|
||||
assertTrue(q0.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Query<Order> q1 = Ebean.find(Order.class)
|
||||
.where().eq("customer.id", null).query();
|
||||
|
||||
List<Order> o1 = q1.findList();
|
||||
assertTrue(o1.size() == orders.size());
|
||||
assertTrue(q1.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> q0 = Ebean.find(Order.class).where().eq("customer", null).query();
|
||||
|
||||
Query<Order> q2 = Ebean.find(Order.class)
|
||||
.where().isNull("customer").query();
|
||||
|
||||
List<Order> o2 = q2.findList();
|
||||
assertTrue(o2.size() == orders.size());
|
||||
assertTrue(q2.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
List<Order> orders = q0.findList();
|
||||
Assert.assertNotNull(orders);
|
||||
Assert.assertTrue(q0.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
|
||||
Query<Order> q1 = Ebean.find(Order.class).where().eq("customer.id", null).query();
|
||||
|
||||
Query<Order> q3 = Ebean.find(Order.class)
|
||||
.where().isNull("customer").query();
|
||||
|
||||
List<Order> o3 = q3.findList();
|
||||
assertTrue(o3.size() == orders.size());
|
||||
assertTrue(q3.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
List<Order> o1 = q1.findList();
|
||||
Assert.assertTrue(o1.size() == orders.size());
|
||||
Assert.assertTrue(q1.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
|
||||
}
|
||||
Query<Order> q2 = Ebean.find(Order.class).where().isNull("customer").query();
|
||||
|
||||
List<Order> o2 = q2.findList();
|
||||
Assert.assertTrue(o2.size() == orders.size());
|
||||
Assert.assertTrue(q2.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
|
||||
Query<Order> q3 = Ebean.find(Order.class).where().isNull("customer").query();
|
||||
|
||||
List<Order> o3 = q3.findList();
|
||||
Assert.assertTrue(o3.size() == orders.size());
|
||||
Assert.assertTrue(q3.getGeneratedSql().contains("where t0.kcustomer_id is null"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
|
||||
public class TestQueryParsing extends TestCase {
|
||||
public class TestQueryParsing extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
String oq = "find order join customer join customer.contacts join details (+query(4),+lazy(5))";
|
||||
Query<Order> q = Ebean.createQuery(Order.class, oq);
|
||||
checkQuery(q);
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
String oq1 = "find order join customer join customer.contacts join details ( +query(4), +lazy(5) )";
|
||||
SpiQuery<?> q1 = (SpiQuery<?>)Ebean.createQuery(Order.class, oq1);
|
||||
checkQuery(q1);
|
||||
String oq = "find order join customer join customer.contacts join details (+query(4),+lazy(5))";
|
||||
Query<Order> q = Ebean.createQuery(Order.class, oq);
|
||||
checkQuery(q);
|
||||
|
||||
String oq2 = "find order join customer join customer.contacts join details ( +query(4), +lazy(5) , *)";
|
||||
SpiQuery<?> q2 = (SpiQuery<?>)Ebean.createQuery(Order.class, oq2);
|
||||
checkQuery(q2);
|
||||
|
||||
String oq3 = "find order join customer join customer.contacts join details (+query(4),+lazy(5),*)";
|
||||
SpiQuery<?> q3 = (SpiQuery<?>)Ebean.createQuery(Order.class, oq3);
|
||||
checkQuery(q3);
|
||||
String oq1 = "find order join customer join customer.contacts join details ( +query(4), +lazy(5) )";
|
||||
SpiQuery<?> q1 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq1);
|
||||
checkQuery(q1);
|
||||
|
||||
String oq4 = "find order join customer join customer.contacts join details (+query(4) +lazy(5) *)";
|
||||
SpiQuery<?> q4 = (SpiQuery<?>)Ebean.createQuery(Order.class, oq4);
|
||||
checkQuery(q4);
|
||||
String oq2 = "find order join customer join customer.contacts join details ( +query(4), +lazy(5) , *)";
|
||||
SpiQuery<?> q2 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq2);
|
||||
checkQuery(q2);
|
||||
|
||||
}
|
||||
|
||||
private void checkQuery(Query<?> q){
|
||||
|
||||
|
||||
SpiQuery<?> sq = (SpiQuery<?>)q;
|
||||
OrmQueryDetail detail = sq.getDetail();
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("customer", false));
|
||||
Assert.assertFalse(detail.getChunk("customer", false).isQueryFetch());
|
||||
Assert.assertFalse(detail.getChunk("customer", false).isLazyFetch());
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("customer.contacts", false));
|
||||
Assert.assertFalse(detail.getChunk("customer.contacts", false).isQueryFetch());
|
||||
Assert.assertFalse(detail.getChunk("customer.contacts", false).isLazyFetch());
|
||||
String oq3 = "find order join customer join customer.contacts join details (+query(4),+lazy(5),*)";
|
||||
SpiQuery<?> q3 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq3);
|
||||
checkQuery(q3);
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("details", false));
|
||||
Assert.assertTrue(detail.getChunk("details", false).isQueryFetch());
|
||||
Assert.assertTrue(detail.getChunk("details", false).isLazyFetch());
|
||||
String oq4 = "find order join customer join customer.contacts join details (+query(4) +lazy(5) *)";
|
||||
SpiQuery<?> q4 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq4);
|
||||
checkQuery(q4);
|
||||
|
||||
Assert.assertEquals(4, detail.getChunk("details", false).getQueryFetchBatch());
|
||||
Assert.assertEquals(5, detail.getChunk("details", false).getLazyFetchBatch());
|
||||
}
|
||||
|
||||
private void checkQuery(Query<?> q) {
|
||||
|
||||
SpiQuery<?> sq = (SpiQuery<?>) q;
|
||||
OrmQueryDetail detail = sq.getDetail();
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("customer", false));
|
||||
Assert.assertFalse(detail.getChunk("customer", false).isQueryFetch());
|
||||
Assert.assertFalse(detail.getChunk("customer", false).isLazyFetch());
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("customer.contacts", false));
|
||||
Assert.assertFalse(detail.getChunk("customer.contacts", false).isQueryFetch());
|
||||
Assert.assertFalse(detail.getChunk("customer.contacts", false).isLazyFetch());
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("details", false));
|
||||
Assert.assertTrue(detail.getChunk("details", false).isQueryFetch());
|
||||
Assert.assertTrue(detail.getChunk("details", false).isLazyFetch());
|
||||
|
||||
Assert.assertEquals(4, detail.getChunk("details", false).getQueryFetchBatch());
|
||||
Assert.assertEquals(5, detail.getChunk("details", false).getLazyFetchBatch());
|
||||
|
||||
Assert.assertTrue(detail.getChunk("details", false).allProperties());
|
||||
|
||||
}
|
||||
|
||||
Assert.assertTrue(detail.getChunk("details", false).allProperties());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,30 +2,28 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryPathJoinAndOrder extends TestCase {
|
||||
public class TestQueryPathJoinAndOrder extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class)
|
||||
.select("id,name, status")
|
||||
.fetch("contacts")
|
||||
.order().asc("id")
|
||||
.order().desc("contacts.firstName")
|
||||
.setMaxRows(3)
|
||||
.findList();
|
||||
|
||||
assertNotNull(list);
|
||||
|
||||
// can't really assert that the contacts are batch loaded
|
||||
// via a secondary query join
|
||||
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).select("id,name, status").fetch("contacts")
|
||||
.order().asc("id").order().desc("contacts.firstName").setMaxRows(3).findList();
|
||||
|
||||
Assert.assertNotNull(list);
|
||||
|
||||
// can't really assert that the contacts are batch loaded
|
||||
// via a secondary query join
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,68 +2,63 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryPlanCacheRowCount extends TestCase {
|
||||
public class TestQueryPlanCacheRowCount extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.where()
|
||||
.eq("status", Order.Status.NEW)
|
||||
.ge("id", 1)
|
||||
.order().desc("id");
|
||||
|
||||
int rc0 = query.findRowCount();
|
||||
|
||||
List<Object> ids = query.findIds();
|
||||
Assert.assertEquals(rc0,ids.size());
|
||||
|
||||
List<Order> list0 = query.findList();
|
||||
Assert.assertEquals(rc0,list0.size());
|
||||
|
||||
int rc1 = query.findRowCount();
|
||||
Assert.assertEquals(rc0,rc1);
|
||||
|
||||
List<Object> ids1 = query.findIds();
|
||||
Assert.assertEquals(rc0,ids1.size());
|
||||
|
||||
List<Order> list1 = query.findList();
|
||||
Assert.assertEquals(rc0,list1.size());
|
||||
|
||||
int idGt = 5;
|
||||
if (ids1.size() > 0){
|
||||
Object id = ids.get(0);
|
||||
idGt = Integer.valueOf(""+id);
|
||||
}
|
||||
|
||||
// should still hit query plan cache
|
||||
Query<Order> query2 = Ebean.find(Order.class)
|
||||
.where()
|
||||
.eq("status", Order.Status.NEW)
|
||||
.ge("id", idGt)
|
||||
.order().desc("id");
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
int rc2 = query2.findRowCount();
|
||||
|
||||
System.out.println("Expection Not same "+rc0+" != "+rc2);
|
||||
Assert.assertNotSame(rc0, rc2);
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> ids2 = query2.findIds();
|
||||
Assert.assertEquals(rc2,ids2.size());
|
||||
|
||||
List<Order> list2 = query2.findList();
|
||||
Assert.assertEquals(rc2,list2.size());
|
||||
Query<Order> query = Ebean.find(Order.class).where().eq("status", Order.Status.NEW).ge("id", 1)
|
||||
.order().desc("id");
|
||||
|
||||
int rc0 = query.findRowCount();
|
||||
|
||||
List<Object> ids = query.findIds();
|
||||
Assert.assertEquals(rc0, ids.size());
|
||||
|
||||
List<Order> list0 = query.findList();
|
||||
Assert.assertEquals(rc0, list0.size());
|
||||
|
||||
int rc1 = query.findRowCount();
|
||||
Assert.assertEquals(rc0, rc1);
|
||||
|
||||
List<Object> ids1 = query.findIds();
|
||||
Assert.assertEquals(rc0, ids1.size());
|
||||
|
||||
List<Order> list1 = query.findList();
|
||||
Assert.assertEquals(rc0, list1.size());
|
||||
|
||||
int idGt = 5;
|
||||
if (ids1.size() > 0) {
|
||||
Object id = ids.get(0);
|
||||
idGt = Integer.valueOf("" + id);
|
||||
}
|
||||
|
||||
|
||||
// should still hit query plan cache
|
||||
Query<Order> query2 = Ebean.find(Order.class).where().eq("status", Order.Status.NEW)
|
||||
.ge("id", idGt).order().desc("id");
|
||||
|
||||
int rc2 = query2.findRowCount();
|
||||
|
||||
System.out.println("Expection Not same " + rc0 + " != " + rc2);
|
||||
Assert.assertNotSame(rc0, rc2);
|
||||
|
||||
List<Object> ids2 = query2.findIds();
|
||||
Assert.assertEquals(rc2, ids2.size());
|
||||
|
||||
List<Order> list2 = query2.findList();
|
||||
Assert.assertEquals(rc2, list2.size());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,41 +2,41 @@ package com.avaje.tests.query;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestRefToLazyLoadMany extends TestCase {
|
||||
public class TestRefToLazyLoadMany extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
List<Customer> custList = Ebean.find(Customer.class)
|
||||
.select("id")
|
||||
.findList();
|
||||
|
||||
Customer c = custList.get(0);
|
||||
|
||||
List<Contact> contacts2 = c.getContacts();
|
||||
assertEquals(3, Ebean.getBeanState(c).getLoadedProps().size());
|
||||
ResetBasicData.reset();
|
||||
|
||||
// now lazy load the contacts
|
||||
contacts2.size();
|
||||
|
||||
|
||||
Customer c2 = Ebean.getReference(Customer.class, c.getId());
|
||||
|
||||
// we only "loaded" the contacts BeanList and not all of c2
|
||||
List<Contact> contacts = c2.getContacts();
|
||||
//Set<String> loadedProps = Ebean.getBeanState(c2).getLoadedProps();
|
||||
//assertEquals(1, loadedProps.size());
|
||||
|
||||
// now lazy load the contacts
|
||||
contacts.size();
|
||||
|
||||
}
|
||||
List<Customer> custList = Ebean.find(Customer.class).select("id").findList();
|
||||
|
||||
Customer c = custList.get(0);
|
||||
|
||||
List<Contact> contacts2 = c.getContacts();
|
||||
Assert.assertEquals(3, Ebean.getBeanState(c).getLoadedProps().size());
|
||||
|
||||
// now lazy load the contacts
|
||||
contacts2.size();
|
||||
|
||||
Customer c2 = Ebean.getReference(Customer.class, c.getId());
|
||||
|
||||
// we only "loaded" the contacts BeanList and not all of c2
|
||||
List<Contact> contacts = c2.getContacts();
|
||||
// Set<String> loadedProps = Ebean.getBeanState(c2).getLoadedProps();
|
||||
// assertEquals(1, loadedProps.size());
|
||||
|
||||
// now lazy load the contacts
|
||||
contacts.size();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,37 +3,36 @@ package com.avaje.tests.query;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestRowCount extends TestCase {
|
||||
public class TestRowCount extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("details").where().gt("id", 1)
|
||||
.gt("details.id", 1).order("id desc");
|
||||
|
||||
int rc = query.findRowCount();
|
||||
System.out.println("rc:" + rc);
|
||||
|
||||
List<Object> ids = query.findIds();
|
||||
System.out.println("ids:" + ids);
|
||||
|
||||
List<Order> list = query.findList();
|
||||
System.out.println(list);
|
||||
|
||||
Assert.assertEquals("same rc to ids.size() ", rc, ids.size());
|
||||
Assert.assertEquals("same rc to list.size()", rc, list.size());
|
||||
}
|
||||
|
||||
public void test(){
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("details")
|
||||
.where().gt("id", 1)
|
||||
.gt("details.id", 1)
|
||||
.order("id desc");
|
||||
|
||||
|
||||
int rc = query.findRowCount();
|
||||
System.out.println("rc:"+rc);
|
||||
|
||||
List<Object> ids = query.findIds();
|
||||
System.out.println("ids:"+ids);
|
||||
|
||||
List<Order> list = query.findList();
|
||||
System.out.println(list);
|
||||
|
||||
Assert.assertEquals("same rc to ids.size() ", rc, ids.size());
|
||||
Assert.assertEquals("same rc to list.size()", rc, list.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package com.avaje.tests.query;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.CKeyParent;
|
||||
@@ -13,195 +15,157 @@ import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import com.avaje.tests.model.basic.Vehicle;
|
||||
import com.avaje.tests.model.basic.VehicleDriver;
|
||||
|
||||
public class TestSubQuery extends TestCase {
|
||||
public class TestSubQuery extends BaseTestCase {
|
||||
|
||||
public void testId() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
@Test
|
||||
public void testId() {
|
||||
|
||||
List<Integer> productIds = new ArrayList<Integer>();
|
||||
productIds.add(3);
|
||||
|
||||
Query<Order> sq = Ebean.createQuery(Order.class)
|
||||
.select("id")
|
||||
.where().in("details.product.id", productIds)
|
||||
.query();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class)
|
||||
.where().in("id", sq)
|
||||
.findList();
|
||||
|
||||
System.out.println(list);
|
||||
// FIXME: need to clear out old orders..
|
||||
//Assert.assertEquals(2,list.size());
|
||||
|
||||
String oq = " find order (id, status) where id in "
|
||||
+"(select a.id from o_order a join o_order_detail ad on ad.order_id = a.id where ad.product_id in (:prods)) ";
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Order> list2 = Ebean.createQuery(Order.class, oq)
|
||||
.setParameter("prods", productIds)
|
||||
.findList();
|
||||
List<Integer> productIds = new ArrayList<Integer>();
|
||||
productIds.add(3);
|
||||
|
||||
System.out.println(list2);
|
||||
//Assert.assertEquals(2,list2.size());
|
||||
Query<Order> sq = Ebean.createQuery(Order.class).select("id").where()
|
||||
.in("details.product.id", productIds).query();
|
||||
|
||||
List<Order> list = Ebean.find(Order.class).where().in("id", sq).findList();
|
||||
|
||||
System.out.println(list);
|
||||
// FIXME: need to clear out old orders..
|
||||
// Assert.assertEquals(2,list.size());
|
||||
|
||||
String oq = " find order (id, status) where id in "
|
||||
+ "(select a.id from o_order a join o_order_detail ad on ad.order_id = a.id where ad.product_id in (:prods)) ";
|
||||
|
||||
List<Order> list2 = Ebean.createQuery(Order.class, oq).setParameter("prods", productIds)
|
||||
.findList();
|
||||
|
||||
System.out.println(list2);
|
||||
// Assert.assertEquals(2,list2.size());
|
||||
|
||||
}
|
||||
|
||||
public void testCompositeKey() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<CKeyParent> sq = Ebean.createQuery(CKeyParent.class).select("id.oneKey")
|
||||
.setAutofetch(false).where().query();
|
||||
|
||||
Query<CKeyParent> pq = Ebean.find(CKeyParent.class).where().in("id.oneKey", sq).query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
|
||||
String golden = "(t0.one_key) in (select t0.one_key from ckey_parent t0) ";
|
||||
|
||||
if (sql.indexOf(golden) < 0) {
|
||||
System.out.println("failed sql:" + sql);
|
||||
Assert.fail("golden string not found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* show that ebean is not using the correct table name in the subquery (sq)
|
||||
*
|
||||
* public void testInheritance1() { ResetBasicData.reset();
|
||||
*
|
||||
* Query<Vehicle> sq = Ebean.createQuery(Vehicle.class) .select("id")
|
||||
* .setAutofetch(false) .where() .query();
|
||||
*
|
||||
* Query<VehicleDriver> pq = Ebean.find(VehicleDriver.class)
|
||||
* .where().in("vehicle.id", sq) .query();
|
||||
*
|
||||
* pq.findList();
|
||||
*
|
||||
* String sql = pq.getGeneratedSql(); System.err.println(sql);
|
||||
*
|
||||
* String golden = "(t0.vehicle_id) in (select t0.id from t0.vehicle t0)"; if
|
||||
* (sql.indexOf(golden) < 0) { System.out.println("failed sql:"+sql);
|
||||
* fail("golden string not found"); }
|
||||
*
|
||||
* }
|
||||
*/
|
||||
|
||||
/**
|
||||
* show that ebean is adding the discriminator to the list of columns in the
|
||||
* subquery
|
||||
*/
|
||||
public void testInheritance2() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<VehicleDriver> sq = Ebean.createQuery(VehicleDriver.class).select("vehicle")
|
||||
.setAutofetch(false).where().query();
|
||||
|
||||
Query<Vehicle> pq = Ebean.find(Vehicle.class).where().in("id", sq).query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
|
||||
// TODO: If, after bugfixing, the system still join against vehicle I do not
|
||||
// know now, in our case, it is not necessary if not
|
||||
// using it in the where clause
|
||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left outer join vehicle t1 on t1.id = t0.vehicle_id )";
|
||||
if (sql.indexOf(golden) < 0) {
|
||||
System.out.println("failed sql:" + sql);
|
||||
Assert.fail("golden string not found");
|
||||
}
|
||||
|
||||
|
||||
public void testCompositeKey()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
}
|
||||
|
||||
Query<CKeyParent> sq = Ebean.createQuery(CKeyParent.class)
|
||||
.select("id.oneKey")
|
||||
.setAutofetch(false)
|
||||
.where()
|
||||
.query();
|
||||
/**
|
||||
* show that ebean is adding the discriminator to the list of columns in the
|
||||
* subquery. Second test to make sure that joining is still possible after
|
||||
* bugfixing testInheritance2.
|
||||
*/
|
||||
public void testInheritance3() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<CKeyParent> pq = Ebean.find(CKeyParent.class)
|
||||
.where().in("id.oneKey", sq)
|
||||
.query();
|
||||
Query<VehicleDriver> sq = Ebean.createQuery(VehicleDriver.class).select("vehicle")
|
||||
.setAutofetch(false).where().eq("vehicle.licenseNumber", "abc").query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
Query<Vehicle> pq = Ebean.find(Vehicle.class).where().in("id", sq).query();
|
||||
|
||||
String golden = "(t0.one_key) in (select t0.one_key from ckey_parent t0) ";
|
||||
|
||||
if (sql.indexOf(golden) < 0)
|
||||
{
|
||||
System.out.println("failed sql:"+sql);
|
||||
fail("golden string not found");
|
||||
}
|
||||
}
|
||||
pq.findList();
|
||||
|
||||
/**
|
||||
* show that ebean is not using the correct table name in the subquery (sq)
|
||||
*
|
||||
public void testInheritance1()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
|
||||
Query<Vehicle> sq = Ebean.createQuery(Vehicle.class)
|
||||
.select("id")
|
||||
.setAutofetch(false)
|
||||
.where()
|
||||
.query();
|
||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left outer join vehicle t1 on t1.id = t0.vehicle_id where t1.license_number = ? )";
|
||||
if (sql.indexOf(golden) < 0) {
|
||||
System.out.println("failed sql:" + sql);
|
||||
Assert.fail("golden string not found");
|
||||
}
|
||||
}
|
||||
|
||||
Query<VehicleDriver> pq = Ebean.find(VehicleDriver.class)
|
||||
.where().in("vehicle.id", sq)
|
||||
.query();
|
||||
/**
|
||||
* show that ebean is using the wrong column (from the vehicle_driver table
|
||||
* instead of vehicle) for the selected column in the subquery. In contrast to
|
||||
* testInheritance2+3 this test forces ebean to "drill down" to the key of the
|
||||
* relation.
|
||||
*/
|
||||
public void testInheritance4() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
pq.findList();
|
||||
Query<VehicleDriver> sq = Ebean.createQuery(VehicleDriver.class).select("vehicle.id")
|
||||
.setAutofetch(false).where().query();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
Query<Vehicle> pq = Ebean.find(Vehicle.class).where().in("id", sq).query();
|
||||
|
||||
String golden = "(t0.vehicle_id) in (select t0.id from t0.vehicle t0)";
|
||||
if (sql.indexOf(golden) < 0)
|
||||
{
|
||||
System.out.println("failed sql:"+sql);
|
||||
fail("golden string not found");
|
||||
}
|
||||
pq.findList();
|
||||
|
||||
}
|
||||
*/
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
|
||||
/**
|
||||
* show that ebean is adding the discriminator to the list of columns in the subquery
|
||||
*/
|
||||
public void testInheritance2()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<VehicleDriver> sq = Ebean.createQuery(VehicleDriver.class)
|
||||
.select("vehicle")
|
||||
.setAutofetch(false)
|
||||
.where()
|
||||
.query();
|
||||
|
||||
Query<Vehicle> pq = Ebean.find(Vehicle.class)
|
||||
.where().in("id", sq)
|
||||
.query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
|
||||
// TODO: If, after bugfixing, the system still join against vehicle I do not know now, in our case, it is not necessary if not
|
||||
// using it in the where clause
|
||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left outer join vehicle t1 on t1.id = t0.vehicle_id )";
|
||||
if (sql.indexOf(golden) < 0)
|
||||
{
|
||||
System.out.println("failed sql:"+sql);
|
||||
fail("golden string not found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* show that ebean is adding the discriminator to the list of columns in the subquery.
|
||||
* Second test to make sure that joining is still possible after bugfixing testInheritance2.
|
||||
*/
|
||||
public void testInheritance3()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<VehicleDriver> sq = Ebean.createQuery(VehicleDriver.class)
|
||||
.select("vehicle")
|
||||
.setAutofetch(false)
|
||||
.where()
|
||||
.eq("vehicle.licenseNumber", "abc")
|
||||
.query();
|
||||
|
||||
Query<Vehicle> pq = Ebean.find(Vehicle.class)
|
||||
.where().in("id", sq)
|
||||
.query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
|
||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left outer join vehicle t1 on t1.id = t0.vehicle_id where t1.license_number = ? )";
|
||||
if (sql.indexOf(golden) < 0)
|
||||
{
|
||||
System.out.println("failed sql:"+sql);
|
||||
fail("golden string not found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* show that ebean is using the wrong column (from the vehicle_driver table instead of vehicle) for the selected column in the subquery.
|
||||
* In contrast to testInheritance2+3 this test forces ebean to "drill down" to the key of the relation.
|
||||
*/
|
||||
public void testInheritance4()
|
||||
{
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<VehicleDriver> sq = Ebean.createQuery(VehicleDriver.class)
|
||||
.select("vehicle.id")
|
||||
.setAutofetch(false)
|
||||
.where()
|
||||
.query();
|
||||
|
||||
Query<Vehicle> pq = Ebean.find(Vehicle.class)
|
||||
.where().in("id", sq)
|
||||
.query();
|
||||
|
||||
pq.findList();
|
||||
|
||||
String sql = pq.getGeneratedSql();
|
||||
System.err.println(sql);
|
||||
|
||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left outer join vehicle t1 on t1.id = t0.vehicle_id )";
|
||||
// OR without join
|
||||
// String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0)";
|
||||
if (sql.indexOf(golden) < 0)
|
||||
{
|
||||
System.out.println("failed sql:"+sql);
|
||||
fail("golden string not found");
|
||||
}
|
||||
}
|
||||
String golden = "(t0.id) in (select t0.vehicle_id from vehicle_driver t0 left outer join vehicle t1 on t1.id = t0.vehicle_id )";
|
||||
// OR without join
|
||||
// String golden =
|
||||
// "(t0.id) in (select t0.vehicle_id from vehicle_driver t0)";
|
||||
if (sql.indexOf(golden) < 0) {
|
||||
System.out.println("failed sql:" + sql);
|
||||
Assert.fail("golden string not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestThreeLevelQueryJoin extends TestCase {
|
||||
public class TestThreeLevelQueryJoin extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Ebean.find(Customer.class).fetch("orders", new FetchConfig().query())
|
||||
.fetch("orders.details", new FetchConfig().query())
|
||||
.fetch("orders.shipments", new FetchConfig().query())
|
||||
.fetch("shippingAddress", new FetchConfig().query())
|
||||
.fetch("billingAddress", new FetchConfig().query()).findList();
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Ebean.find(Customer.class)
|
||||
.fetch("orders", new FetchConfig().query())
|
||||
.fetch("orders.details", new FetchConfig().query())
|
||||
.fetch("orders.shipments", new FetchConfig().query())
|
||||
.fetch("shippingAddress", new FetchConfig().query())
|
||||
.fetch("billingAddress", new FetchConfig().query())
|
||||
.findList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Expr;
|
||||
import com.avaje.tests.model.basic.OrderDetail;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestWhereRawClause extends TestCase {
|
||||
public class TestWhereRawClause extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testRawClause() {
|
||||
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
|
||||
Ebean.find(OrderDetail.class)
|
||||
.where()
|
||||
.not(Expr.eq("id", 1))
|
||||
.raw("orderQty < shipQty")
|
||||
|
||||
Ebean.find(OrderDetail.class).where().not(Expr.eq("id", 1)).raw("orderQty < shipQty")
|
||||
.findList();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
package com.avaje.tests.query.orderby;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestOrderByOnComplex extends TestCase {
|
||||
public class TestOrderByOnComplex extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).order().desc("customer");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.contains("order by t0.kcustomer_id desc"));
|
||||
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.order().desc("customer");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
assertTrue(sql.contains("order by t0.kcustomer_id desc"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
package com.avaje.tests.query.orderby;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
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.ResetBasicData;
|
||||
|
||||
public class TestOrderByWithFunction extends TestCase {
|
||||
public class TestOrderByWithFunction extends BaseTestCase {
|
||||
|
||||
public void testWithFunction() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.order("length(name),name");
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.indexOf("order by length(t0.name)") > -1);
|
||||
|
||||
|
||||
String oq = "find customer ORDER BY LENGTH(name),name";
|
||||
query = Ebean.createQuery(Customer.class, oq);
|
||||
query.findList();
|
||||
|
||||
sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.indexOf("order by LENGTH(t0.name)") > -1);
|
||||
}
|
||||
@Test
|
||||
public void testWithFunction() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class).order("length(name),name");
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.indexOf("order by length(t0.name)") > -1);
|
||||
|
||||
String oq = "find customer ORDER BY LENGTH(name),name";
|
||||
query = Ebean.createQuery(Customer.class, oq);
|
||||
query.findList();
|
||||
|
||||
sql = query.getGeneratedSql();
|
||||
Assert.assertTrue(sql.indexOf("order by LENGTH(t0.name)") > -1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,119 +1,113 @@
|
||||
package com.avaje.tests.query.orderby;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestOrderByWithMany extends TestCase {
|
||||
public class TestOrderByWithMany extends BaseTestCase {
|
||||
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
checkWithBuiltInMany();
|
||||
checkAppendId();
|
||||
checkNone();
|
||||
checkBoth();
|
||||
checkPrepend();
|
||||
checkAlreadyIncluded();
|
||||
checkAlreadyIncluded2();
|
||||
}
|
||||
|
||||
private void checkWithBuiltInMany() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("details")
|
||||
.order().desc("customer.name");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
// t0.id inserted into the middle of the order by
|
||||
assertTrue(sql.contains("order by t1.name desc, t0.id, t2.id asc"));
|
||||
}
|
||||
|
||||
private void checkAppendId() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("shipments")
|
||||
.order().desc("customer.name");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
// append the id to ensure ordering of root level objects
|
||||
assertTrue(sql.contains("order by t1.name desc, t0.id"));
|
||||
}
|
||||
|
||||
private void checkNone() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.order().desc("customer.name");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
// no need to append id to order by as there is no 'many' included in the query
|
||||
assertTrue(sql.contains("order by t1.name desc"));
|
||||
assertTrue(!sql.contains("order by t1.name desc,"));
|
||||
}
|
||||
|
||||
private void checkBoth() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("shipments")
|
||||
.order().desc("customer.name, shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// insert id into the middle of the order by
|
||||
assertTrue(sql.contains("order by t1.name, t0.id, t2.ship_time desc"));
|
||||
}
|
||||
|
||||
private void checkPrepend() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("shipments")
|
||||
.order().desc("shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// prepend id in order by
|
||||
assertTrue(sql.contains("order by t0.id, t1.ship_time desc"));
|
||||
}
|
||||
|
||||
private void checkAlreadyIncluded() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("shipments")
|
||||
.order().desc("id, shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// prepend id in order by
|
||||
assertTrue(sql.contains("order by t0.id, t1.ship_time desc"));
|
||||
}
|
||||
|
||||
|
||||
private void checkAlreadyIncluded2() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("shipments")
|
||||
.order().desc("orderDate, id, shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// prepend id in order by
|
||||
assertTrue(sql.contains("order by t0.order_date, t0.id, t1.ship_time desc"));
|
||||
}
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
checkWithBuiltInMany();
|
||||
checkAppendId();
|
||||
checkNone();
|
||||
checkBoth();
|
||||
checkPrepend();
|
||||
checkAlreadyIncluded();
|
||||
checkAlreadyIncluded2();
|
||||
}
|
||||
|
||||
private void checkWithBuiltInMany() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("details").order().desc("customer.name");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
// t0.id inserted into the middle of the order by
|
||||
Assert.assertTrue(sql.contains("order by t1.name desc, t0.id, t2.id asc"));
|
||||
}
|
||||
|
||||
private void checkAppendId() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("shipments").order().desc("customer.name");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
// append the id to ensure ordering of root level objects
|
||||
Assert.assertTrue(sql.contains("order by t1.name desc, t0.id"));
|
||||
}
|
||||
|
||||
private void checkNone() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).order().desc("customer.name");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
// no need to append id to order by as there is no 'many' included in the
|
||||
// query
|
||||
Assert.assertTrue(sql.contains("order by t1.name desc"));
|
||||
Assert.assertTrue(!sql.contains("order by t1.name desc,"));
|
||||
}
|
||||
|
||||
private void checkBoth() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("shipments").order()
|
||||
.desc("customer.name, shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// insert id into the middle of the order by
|
||||
Assert.assertTrue(sql.contains("order by t1.name, t0.id, t2.ship_time desc"));
|
||||
}
|
||||
|
||||
private void checkPrepend() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("shipments").order()
|
||||
.desc("shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// prepend id in order by
|
||||
Assert.assertTrue(sql.contains("order by t0.id, t1.ship_time desc"));
|
||||
}
|
||||
|
||||
private void checkAlreadyIncluded() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("shipments").order()
|
||||
.desc("id, shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// prepend id in order by
|
||||
Assert.assertTrue(sql.contains("order by t0.id, t1.ship_time desc"));
|
||||
}
|
||||
|
||||
private void checkAlreadyIncluded2() {
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("shipments").order()
|
||||
.desc("orderDate, id, shipments.shipTime");
|
||||
|
||||
query.findList();
|
||||
|
||||
String sql = query.getGeneratedSql();
|
||||
// prepend id in order by
|
||||
Assert.assertTrue(sql.contains("order by t0.order_date, t0.id, t1.ship_time desc"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.tests.model.basic.NoIdEntityType;
|
||||
|
||||
public class TestNoIdEntityType {
|
||||
public class TestNoIdEntityType extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testFindById() {
|
||||
|
||||
Reference in New Issue
Block a user