NEW: FetchCountDistinct - query can return distinct values with their counts (#1300)

* NEW: FetchCountDistinct - query can return distinct values with their counts

* Have to disable asserts, because of #1298
This commit is contained in:
Roland Praml
2018-03-02 11:46:41 +13:00
committed by Rob Bygrave
parent 021d57f4b2
commit c1b022c123
11 changed files with 329 additions and 83 deletions
@@ -1,6 +1,7 @@
package io.ebeaninternal.server.querydefn;
import io.ebean.CacheMode;
import io.ebean.CountDistinctOrder;
import io.ebean.Expression;
import io.ebean.ExpressionFactory;
import io.ebean.ExpressionList;
@@ -217,6 +218,8 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
private boolean singleAttribute;
private CountDistinctOrder countDistinctOrder;
/**
* Set to true if this query has been tuned by autoTune.
*/
@@ -655,6 +658,11 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return singleAttribute;
}
@Override
public CountDistinctOrder getCountDistinctOrder() {
return countDistinctOrder;
}
/**
* Return true if the Id should be included in the query.
*/
@@ -1021,7 +1029,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
queryPlanKey = new OrmQueryPlanKey(beanDescriptor.getDiscValue(), m2mIncludeJoin, type, detail, maxRows, firstRow,
disableLazyLoading, orderBy,
distinct, sqlDistinct, mapKey, id, bindParams, whereExpressions, havingExpressions,
temporalMode, forUpdate, rootTableAlias, rawSql, updateProperties);
temporalMode, forUpdate, rootTableAlias, rawSql, updateProperties, countDistinctOrder);
}
return queryPlanKey;
}
@@ -1484,6 +1492,17 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return this;
}
@Override
public DefaultOrmQuery<T> setCountDistinct(CountDistinctOrder countDistinctOrder) {
this.countDistinctOrder = countDistinctOrder;
return this;
}
@Override
public boolean isCountDistinct() {
return countDistinctOrder != null;
}
/**
* Return true if this query uses SQL DISTINCT either explicitly by the user or internally defined
* by ebean.