mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1404 - Query.findCount() with query.setDistinct(true) ... doesn't give count distinct SQL query
This commit is contained in:
@@ -3,13 +3,16 @@ package org.tests.query;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestRowCount extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@@ -17,8 +20,12 @@ public class TestRowCount extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Order> query = Ebean.find(Order.class).fetch("details").where().gt("id", 1)
|
||||
.gt("details.id", 1).order("id desc");
|
||||
Query<Order> query = Ebean.find(Order.class)
|
||||
.fetch("details")
|
||||
.where()
|
||||
.gt("id", 1)
|
||||
.gt("details.id", 1)
|
||||
.order("id desc");
|
||||
|
||||
int rc = query.findCount();
|
||||
|
||||
@@ -30,8 +37,40 @@ public class TestRowCount extends BaseTestCase {
|
||||
order.getStatus();
|
||||
}
|
||||
|
||||
Assert.assertEquals("same rc to ids.size() ", rc, ids.size());
|
||||
Assert.assertEquals("same rc to list.size()", rc, list.size());
|
||||
assertEquals("same rc to ids.size() ", rc, ids.size());
|
||||
assertEquals("same rc to list.size()", rc, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void find_count_distinct_singleProperty() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.setDistinct(true)
|
||||
.select("anniversary")
|
||||
.where().eq("status", Customer.Status.NEW)
|
||||
.query();
|
||||
|
||||
int count = query.findCount();
|
||||
|
||||
assertThat(sqlOf(query)).contains("select count(distinct t0.anniversary) from o_customer t0 where t0.status = ?");
|
||||
assertThat(count).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void find_count_distinct_multipleProperties() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.setDistinct(true)
|
||||
.select("anniversary, status");
|
||||
|
||||
int count = query.findCount();
|
||||
|
||||
assertThat(sqlOf(query)).contains("select count(*) from ( select distinct t0.anniversary, t0.status from o_customer t0)");
|
||||
assertThat(count).isGreaterThan(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user