mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Added / enhanced test case
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package org.tests.query;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Query;
|
||||
import io.ebeantest.LoggedSql;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TestQueryExists extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
Query<Order> query = DB.find(Order.class)
|
||||
.where().gt("id", 1)
|
||||
.query();
|
||||
|
||||
@@ -34,8 +34,8 @@ public class TestQueryExists extends BaseTestCase {
|
||||
assertThat(sql).contains("select t0.id from o_order t0 where t0.id > ? limit 1");
|
||||
}
|
||||
|
||||
assertThat(Ebean.find(Order.class).where().gt("id", 1).exists()).isTrue();
|
||||
assertThat(Ebean.find(Order.class).where().or().gt("id", 1).isNull("shipDate").exists()).isTrue();
|
||||
assertThat(DB.find(Order.class).where().gt("id", 1).exists()).isTrue();
|
||||
assertThat(DB.find(Order.class).where().or().gt("id", 1).isNull("shipDate").exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,13 +43,13 @@ public class TestQueryExists extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
Query<Order> query = DB.find(Order.class)
|
||||
.where().raw("exists (select 1 from o_order_detail where order_id = t0.id)")
|
||||
.query();
|
||||
|
||||
List<Order> ordersThatHave = query.findList();
|
||||
|
||||
Query<Order> query2 = Ebean.find(Order.class)
|
||||
Query<Order> query2 = DB.find(Order.class)
|
||||
.where().raw("not exists (select 1 from o_order_detail where order_id = t0.id)")
|
||||
.query();
|
||||
|
||||
@@ -67,13 +67,13 @@ public class TestQueryExists extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
Query<Customer> query = DB.find(Customer.class)
|
||||
.where().raw("exists (select 1 from contact where customer_id = t0.id)")
|
||||
.query();
|
||||
|
||||
List<Customer> customersWithContacts = query.findList();
|
||||
|
||||
Query<Customer> query2 = Ebean.find(Customer.class)
|
||||
Query<Customer> query2 = DB.find(Customer.class)
|
||||
.where().raw("not exists (select 1 FROM contact where customer_id = t0.id)")
|
||||
.query();
|
||||
|
||||
@@ -89,26 +89,26 @@ public class TestQueryExists extends BaseTestCase {
|
||||
public void testExists() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> subQuery = Ebean.find(Order.class).alias("sq").select("id").where().raw("sq.kcustomer_id = qt.id").query();
|
||||
Query<Order> subQuery = DB.find(Order.class).alias("sq").select("id").where().raw("sq.kcustomer_id = qt.id").query();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class).alias("qt").where().exists(subQuery).query();
|
||||
Query<Customer> query = DB.find(Customer.class).alias("qt").where().exists(subQuery).query();
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
assertThat(sql).contains("exists (");
|
||||
assertThat(sql).contains("exists (select 1 from");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExists() {
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> subQuery = Ebean.find(Order.class).alias("sq").select("id").where().raw("sq.kcustomer_id = qt.id").query();
|
||||
Query<Customer> query = Ebean.find(Customer.class).alias("qt").where().notExists(subQuery).query();
|
||||
Query<Order> subQuery = DB.find(Order.class).alias("sq").where().raw("sq.kcustomer_id = qt.id").query();
|
||||
Query<Customer> query = DB.find(Customer.class).alias("qt").where().notExists(subQuery).query();
|
||||
|
||||
query.findList();
|
||||
String sql = query.getGeneratedSql();
|
||||
|
||||
assertThat(sql).contains("not exists (");
|
||||
assertThat(sql).contains("not exists (select 1 from");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user