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:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user