mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Added SQL command "EXISTS" and "NOT EXISTS" to Ebean (ExpressionFactory,
ExpressionList).
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
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 TestQueryExists extends BaseTestCase {
|
||||
@Test
|
||||
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<Customer> query=Ebean.find(Customer.class).alias("qt").where().exists(subQuery).query();
|
||||
|
||||
query.findList();
|
||||
String sql=query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.indexOf("exists (")>0);
|
||||
}
|
||||
|
||||
@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.findList();
|
||||
String sql=query.getGeneratedSql();
|
||||
|
||||
Assert.assertTrue(sql.indexOf("not exists (")>0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user