Skip to content

Commit

Permalink
ISPN-5737 Cannot use both 'where' and 'having' filtering in the same …
Browse files Browse the repository at this point in the history
…query
  • Loading branch information
anistor committed Sep 10, 2015
1 parent f8a1014 commit 80ce4bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Expand Up @@ -280,7 +280,7 @@ public void testEqHybridQuery() throws Exception {

Query q = qf.from(getModelFactory().getUserImplClass())
.having("notes").eq("Lorem ipsum dolor sit amet")
.and().having("surname").eq("Doe")
.and().having("surname").eq("Doe")
.toBuilder().build();

List<User> list = q.list();
Expand Down Expand Up @@ -1570,8 +1570,8 @@ public void testSampleDomainQuery26() throws Exception {
QueryFactory qf = getQueryFactory();

Query q = qf.from(getModelFactory().getAccountImplClass())
.having("creationDate").eq(makeDate("2013-01-20"))
.toBuilder().build();
.having("creationDate").eq(makeDate("2013-01-20"))
.toBuilder().build();

List<Account> list = q.list();
assertEquals(1, list.size());
Expand Down Expand Up @@ -2052,6 +2052,21 @@ public void testOrderBySum() {
assertEquals(22, list.get(0)[0]);
}

@Test
public void testGroupingWithFilter() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.select("name")
.having("name").eq("John").toBuilder()
.groupBy("name")
.having("name").eq("John").toBuilder()
.build();
List<Object[]> list = q.list();
assertEquals(1, list.size());
assertEquals(1, list.get(0).length);
assertEquals("John", list.get(0)[0]);
}

@Test
public void testCountNull() {
QueryFactory qf = getQueryFactory();
Expand Down
Expand Up @@ -139,6 +139,8 @@ public QueryBuilder groupBy(String... groupBy) {
throw new IllegalStateException("Grouping can be specified only once");
}
this.groupBy = groupBy;
// reset this so we can start a new filter for havingFilterCondition
filterCondition = null;
return this;
}

Expand Down
Expand Up @@ -1331,7 +1331,7 @@ public void testSampleDomainQuery18() throws Exception {
.orderBy("description", SortOrder.ASC)
.having("accountId").eq(1)
.and(qf.having("amount").gt(1600)
.or().having("description").like("%rent%")).toBuilder().build();
.or().having("description").like("%rent%")).toBuilder().build();

List<Transaction> list = q.list();
assertEquals(2, list.size());
Expand Down Expand Up @@ -1932,6 +1932,20 @@ public void testOrderBySum() {
assertEquals(22, list.get(0)[0]);
}

public void testGroupingWithFilter() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
.select("name")
.having("name").eq("John").toBuilder()
.groupBy("name")
.having("name").eq("John").toBuilder()
.build();
List<Object[]> list = q.list();
assertEquals(1, list.size());
assertEquals(1, list.get(0).length);
assertEquals("John", list.get(0)[0]);
}

public void testCountNull() {
QueryFactory qf = getQueryFactory();
Query q = qf.from(getModelFactory().getUserImplClass())
Expand Down

0 comments on commit 80ce4bf

Please sign in to comment.