Package com.querydsl.core.group
Class GroupBy
java.lang.Object
com.querydsl.core.group.GroupBy
GroupBy provides factory methods for ResultTransformer and GroupExpression creation
Example: Group employees by department
query.transform(
GroupBy.groupBy(employee.department)
.as(GroupBy.list(Projections.tuple(employee.id, employee.firstName, employee.lastName))))
- Author:
- sasa, tiwe
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Number>
AbstractGroupExpression<E,E> avg(Expression<E> expression) Create a new aggregating avg expression, uses default MathContext.DECIMAL128 for average calculationstatic <E extends Number>
AbstractGroupExpression<E,E> avg(Expression<E> expression, MathContext mathContext) Create a new aggregating avg expression with a user-provided MathContextstatic GroupByBuilder<List<?>>groupBy(Expression<?>... keys) Create a new GroupByBuilder for the given key expressionsstatic <K> GroupByBuilder<K>groupBy(Expression<K> key) Create a new GroupByBuilder for the given key expressionstatic <E,F> AbstractGroupExpression<E, List<F>> list(GroupExpression<E, F> groupExpression) Create a new aggregating list expressionstatic <E> AbstractGroupExpression<E,List<E>> list(Expression<E> expression) Create a new aggregating list expressionstatic <K,V, T, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, Map<T, U>> map(GroupExpression<K, T> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing LinkedHashMapstatic <K,V, T> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, Map<T, V>> map(GroupExpression<K, T> key, Expression<V> value) Create a new aggregating map expression using a backing LinkedHashMapstatic <K,V, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, Map<K, U>> map(Expression<K> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing LinkedHashMapstatic <K,V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, Map<K, V>> map(Expression<K> key, Expression<V> value) Create a new aggregating map expression using a backing LinkedHashMapstatic <E extends Comparable<? super E>>
AbstractGroupExpression<E,E> max(Expression<E> expression) Create a new aggregating max expressionstatic <E extends Comparable<? super E>>
AbstractGroupExpression<E,E> min(Expression<E> expression) Create a new aggregating min expressionstatic <E,F> GroupExpression<E, Set<F>> set(GroupExpression<E, F> groupExpression) Create a new aggregating set expression using a backing LinkedHashSetstatic <E> AbstractGroupExpression<E,Set<E>> set(Expression<E> expression) Create a new aggregating set expression using a backing LinkedHashSetstatic <K,V, T extends Comparable<? super T>, U>
AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, SortedMap<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing TreeMapstatic <K,V, T, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, SortedMap<T, U>> sortedMap(GroupExpression<K, T> key, GroupExpression<V, U> value, Comparator<? super T> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparatorstatic <K,V, T extends Comparable<? super T>>
AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value) Create a new aggregating map expression using a backing TreeMapstatic <K,V, T> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, SortedMap<T, V>> sortedMap(GroupExpression<K, T> key, Expression<V> value, Comparator<? super T> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparatorstatic <K extends Comparable<? super K>,V, U>
AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing TreeMapstatic <K,V, U> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, SortedMap<K, U>> sortedMap(Expression<K> key, GroupExpression<V, U> value, Comparator<? super K> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparatorstatic <K extends Comparable<? super K>,V>
AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, SortedMap<K, V>> sortedMap(Expression<K> key, Expression<V> value) Create a new aggregating map expression using a backing TreeMapstatic <K,V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K, V>, SortedMap<K, V>> sortedMap(Expression<K> key, Expression<V> value, Comparator<? super K> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparatorstatic <E,F extends Comparable<? super F>>
GroupExpression<E,SortedSet<F>> sortedSet(GroupExpression<E, F> groupExpression) Create a new aggregating set expression using a backing TreeSetstatic <E,F> GroupExpression<E, SortedSet<F>> sortedSet(GroupExpression<E, F> groupExpression, Comparator<? super F> comparator) Create a new aggregating set expression using a backing TreeSet using the given comparatorstatic <E extends Comparable<? super E>>
AbstractGroupExpression<E,SortedSet<E>> sortedSet(Expression<E> expression) Create a new aggregating set expression using a backing TreeSetstatic <E> AbstractGroupExpression<E,SortedSet<E>> sortedSet(Expression<E> expression, Comparator<? super E> comparator) Create a new aggregating set expression using a backing TreeSet using the given comparatorstatic <E extends Number>
AbstractGroupExpression<E,E> sum(Expression<E> expression) Create a new aggregating sum expression
-
Constructor Details
-
GroupBy
protected GroupBy()
-
-
Method Details
-
groupBy
Create a new GroupByBuilder for the given key expression- Parameters:
key- key for aggregation- Returns:
- builder for further specification
-
groupBy
Create a new GroupByBuilder for the given key expressions- Parameters:
keys- keys for aggregation- Returns:
- builder for further specification
-
min
public static <E extends Comparable<? super E>> AbstractGroupExpression<E,E> min(Expression<E> expression) Create a new aggregating min expression- Parameters:
expression- expression for which the minimum value will be used in the group by projection- Returns:
- wrapper expression
-
sum
Create a new aggregating sum expression- Parameters:
expression- expression a for which the accumulated sum will be used in the group by projection- Returns:
- wrapper expression
-
avg
Create a new aggregating avg expression, uses default MathContext.DECIMAL128 for average calculation- Parameters:
expression- expression for which the accumulated average value will be used in the group by projection- Returns:
- wrapper expression
-
avg
public static <E extends Number> AbstractGroupExpression<E,E> avg(Expression<E> expression, MathContext mathContext) Create a new aggregating avg expression with a user-provided MathContext- Parameters:
expression- expression for which the accumulated average value will be used in the group by projectionmathContext- mathContext for average calculation- Returns:
- wrapper expression
-
max
public static <E extends Comparable<? super E>> AbstractGroupExpression<E,E> max(Expression<E> expression) Create a new aggregating max expression- Parameters:
expression- expression for which the maximum value will be used in the group by projection- Returns:
- wrapper expression
-
list
Create a new aggregating list expression- Parameters:
expression- values for this expression will be accumulated into a list- Returns:
- wrapper expression
-
list
Create a new aggregating list expression- Type Parameters:
E-F-- Parameters:
groupExpression- values for this expression will be accumulated into a list- Returns:
- wrapper expression
-
set
Create a new aggregating set expression using a backing LinkedHashSet- Parameters:
expression- values for this expression will be accumulated into a set- Returns:
- wrapper expression
-
set
Create a new aggregating set expression using a backing LinkedHashSet- Type Parameters:
E-F-- Parameters:
groupExpression- values for this expression will be accumulated into a set- Returns:
- wrapper expression
-
sortedSet
public static <E extends Comparable<? super E>> AbstractGroupExpression<E,SortedSet<E>> sortedSet(Expression<E> expression) Create a new aggregating set expression using a backing TreeSet- Parameters:
expression- values for this expression will be accumulated into a set- Returns:
- wrapper expression
-
sortedSet
public static <E,F extends Comparable<? super F>> GroupExpression<E,SortedSet<F>> sortedSet(GroupExpression<E, F> groupExpression) Create a new aggregating set expression using a backing TreeSet- Parameters:
groupExpression- values for this expression will be accumulated into a set- Returns:
- wrapper expression
-
sortedSet
public static <E> AbstractGroupExpression<E,SortedSet<E>> sortedSet(Expression<E> expression, Comparator<? super E> comparator) Create a new aggregating set expression using a backing TreeSet using the given comparator- Parameters:
expression- values for this expression will be accumulated into a setcomparator- comparator of the created TreeSet instance- Returns:
- wrapper expression
-
sortedSet
public static <E,F> GroupExpression<E,SortedSet<F>> sortedSet(GroupExpression<E, F> groupExpression, Comparator<? super F> comparator) Create a new aggregating set expression using a backing TreeSet using the given comparator- Parameters:
groupExpression- values for this expression will be accumulated into a setcomparator- comparator of the created TreeSet instance- Returns:
- wrapper expression
-
map
public static <K,V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, mapMap<K, V>> (Expression<K> key, Expression<V> value) Create a new aggregating map expression using a backing LinkedHashMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
map
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,T> V>, mapMap<T, V>> (GroupExpression<K, T> key, Expression<V> value) Create a new aggregating map expression using a backing LinkedHashMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
map
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,U> V>, mapMap<K, U>> (Expression<K> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing LinkedHashMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
map
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,T, U> V>, mapMap<T, U>> (GroupExpression<K, T> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing LinkedHashMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
sortedMap
public static <K extends Comparable<? super K>,V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, sortedMapSortedMap<K, V>> (Expression<K> key, Expression<V> value) Create a new aggregating map expression using a backing TreeMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
sortedMap
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,T extends Comparable<? super T>> V>, sortedMapSortedMap<T, V>> (GroupExpression<K, T> key, Expression<V> value) Create a new aggregating map expression using a backing TreeMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
sortedMap
public static <K extends Comparable<? super K>,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,U> V>, sortedMapSortedMap<K, U>> (Expression<K> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing TreeMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
sortedMap
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,T extends Comparable<? super T>, U> V>, sortedMapSortedMap<T, U>> (GroupExpression<K, T> key, GroupExpression<V, U> value) Create a new aggregating map expression using a backing TreeMap- Parameters:
key- key for the map entriesvalue- value for the map entries- Returns:
- wrapper expression
-
sortedMap
public static <K,V> AbstractGroupExpression<com.mysema.commons.lang.Pair<K,V>, sortedMapSortedMap<K, V>> (Expression<K> key, Expression<V> value, Comparator<? super K> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparator- Parameters:
key- key for the map entriesvalue- value for the map entriescomparator- comparator for the created TreeMap instances- Returns:
- wrapper expression
-
sortedMap
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,T> V>, sortedMapSortedMap<T, V>> (GroupExpression<K, T> key, Expression<V> value, Comparator<? super T> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparator- Parameters:
key- key for the map entriesvalue- value for the map entriescomparator- comparator for the created TreeMap instances- Returns:
- wrapper expression
-
sortedMap
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,U> V>, sortedMapSortedMap<K, U>> (Expression<K> key, GroupExpression<V, U> value, Comparator<? super K> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparator- Parameters:
key- key for the map entriesvalue- value for the map entriescomparator- comparator for the created TreeMap instances- Returns:
- wrapper expression
-
sortedMap
public static <K,V, AbstractGroupExpression<com.mysema.commons.lang.Pair<K,T, U> V>, sortedMapSortedMap<T, U>> (GroupExpression<K, T> key, GroupExpression<V, U> value, Comparator<? super T> comparator) Create a new aggregating map expression using a backing TreeMap using the given comparator- Parameters:
key- key for the map entriesvalue- value for the map entriescomparator- comparator for the created TreeMap instances- Returns:
- wrapper expression
-