#919 - io.ebean package initial

This commit is contained in:
Rob Bygrave
2016-12-11 23:23:22 +13:00
parent 5821dc96b9
commit 971e2dc91b
2134 changed files with 10721 additions and 8652 deletions
@@ -0,0 +1,114 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import org.tests.model.basic.Contact;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class IsEmptyExpressionQueryTest extends BaseTestCase {
@Test
public void isEmpty() {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.select("id")
.where().isEmpty("contacts")
.query();
query.findList();
assertThat(sqlOf(query)).contains("select t0.id from o_customer t0 where not exists (select 1 from contact where customer_id = t0.id");
}
@Test
public void isNotEmpty() {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.select("id")
.where().isNotEmpty("contacts")
.query();
query.findList();
assertThat(sqlOf(query)).contains("select t0.id from o_customer t0 where exists (select 1 from contact where customer_id = t0.id");
}
@Test
public void isEmpty_contacts() {
ResetBasicData.reset();
Query<Contact> query = Ebean.find(Contact.class)
.select("id")
.where().isEmpty("notes")
.query();
query.findList();
assertThat(sqlOf(query)).contains("select t0.id from contact t0 where not exists (select 1 from contact_note where contact_id = t0.id");
}
@Test
public void isNotEmpty_contacts() {
ResetBasicData.reset();
Query<Contact> query = Ebean.find(Contact.class)
.select("id")
.where().isNotEmpty("notes")
.query();
query.findList();
assertThat(sqlOf(query)).contains("select t0.id from contact t0 where exists (select 1 from contact_note where contact_id = t0.id");
}
@Test
public void isEmpty_manyToMany() {
ResetBasicData.reset();
Query<Contact> query = Ebean.find(Contact.class)
.select("id")
.where().isEmpty("notes")
.query();
query.findList();
}
@Test
public void isEmpty_nested() {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.select("id")
.where().isEmpty("contacts.notes")
.query();
query.findList();
assertThat(sqlOf(query)).contains("select distinct t0.id from o_customer t0 join contact u1 on u1.customer_id = t0.id where not exists (select 1 from contact_note where contact_id = u1.id)");
}
@Test
public void isNotEmpty_nested() {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.select("id")
.where().isNotEmpty("contacts.notes")
.query();
query.findList();
assertThat(sqlOf(query)).contains("select distinct t0.id from o_customer t0 join contact u1 on u1.customer_id = t0.id where exists (select 1 from contact_note where contact_id = u1.id)");
}
}