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 authored and Rob Bygrave committed 2018-03-02 11:46:41 +13:00
1 parent 021d57f4b2
commit c1b022c123
11 files changed
+329 -83

No files matched your search

@@ -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.
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.querydefn;
import io.ebean.CountDistinctOrder;
import io.ebean.OrderBy;
import io.ebean.Query;
import io.ebeaninternal.api.BindParams;
@@ -23,7 +24,7 @@ class OrmQueryPlanKey implements CQueryPlanKey {
OrmQueryPlanKey(String discValue, TableJoin m2mIncludeTable, SpiQuery.Type type, OrmQueryDetail detail, int maxRows, int firstRow, boolean disableLazyLoading,
OrderBy<?> orderBy, boolean distinct, boolean sqlDistinct, String mapKey, Object id, BindParams bindParams,
SpiExpression whereExpressions, SpiExpression havingExpressions, SpiQuery.TemporalMode temporalMode,
Query.ForUpdate forUpdate, String rootTableAlias, SpiRawSql rawSql, OrmUpdateProperties updateProperties) {
Query.ForUpdate forUpdate, String rootTableAlias, SpiRawSql rawSql, OrmUpdateProperties updateProperties, CountDistinctOrder countDistinctOrder) {
StringBuilder sb = new StringBuilder(300);
if (type != null) {
@@ -62,6 +63,9 @@ class OrmQueryPlanKey implements CQueryPlanKey {
if (mapKey != null) {
sb.append(",mapKey:").append(mapKey);
}
if (countDistinctOrder != null) {
sb.append(",countdistinctoder:").append(countDistinctOrder.name());
}
this.maxRows = maxRows;
this.firstRow = firstRow;
this.rawSqlKey = (rawSql == null) ? null : rawSql.getKey();