use of com.querydsl.core.group.GroupImpl in project querydsl by querydsl.
the class GroupByMultimap method transform.
@Override
public R transform(FetchableQuery<?, ?> query) {
Multimap<K, Group> groups = LinkedHashMultimap.create();
// create groups
FactoryExpression<Tuple> expr = FactoryExpressionUtils.wrap(Projections.tuple(expressions));
boolean hasGroups = false;
for (Expression<?> e : expr.getArgs()) {
hasGroups |= e instanceof GroupExpression;
}
if (hasGroups) {
expr = withoutGroupExpressions(expr);
}
CloseableIterator<Tuple> iter = query.select(expr).iterate();
try {
while (iter.hasNext()) {
// This type is mandated by the key type
@SuppressWarnings("unchecked") K[] row = (K[]) iter.next().toArray();
K groupId = row[0];
GroupImpl group = new GroupImpl(groupExpressions, maps);
groups.put(groupId, group);
group.add(row);
}
} finally {
iter.close();
}
// transform groups
return transform(groups);
}
use of com.querydsl.core.group.GroupImpl in project querydsl by querydsl.
the class GroupByTable method transform.
@Override
public RES transform(FetchableQuery<?, ?> query) {
// TODO Table<Object, Object, Group> after support for it in https://github.com/querydsl/querydsl/issues/2644
Table<R, Object, Group> groups = HashBasedTable.create();
// create groups
FactoryExpression<Tuple> expr = FactoryExpressionUtils.wrap(Projections.tuple(expressions));
boolean hasGroups = false;
for (Expression<?> e : expr.getArgs()) {
hasGroups |= e instanceof GroupExpression;
}
if (hasGroups) {
expr = withoutGroupExpressions(expr);
}
CloseableIterator<Tuple> iter = query.select(expr).iterate();
try {
while (iter.hasNext()) {
// This type is mandated by the key type
@SuppressWarnings("unchecked") Object[] row = iter.next().toArray();
R groupId = (R) row[0];
Object rowId = row[1];
GroupImpl group = (GroupImpl) groups.get(groupId, rowId);
if (group == null) {
group = new GroupImpl(groupExpressions, maps);
groups.put(groupId, rowId, group);
}
group.add(row);
}
} finally {
iter.close();
}
// transform groups
return transform(groups);
}
Aggregations