use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class AbstractSQLTest method union5.
@SuppressWarnings("unchecked")
@Test
@ExcludeIn({ Target.DERBY, Target.ORACLE })
public void union5() {
SAnimal cat2 = new SAnimal("cat2");
List<Tuple> rows = query().union(select(cat.id, cat2.id).from(cat).join(cat2).on(cat2.id.eq(cat.id.add(1))), select(cat.id, cat2.id).from(cat).join(cat2).on(cat2.id.eq(cat.id.add(1)))).list();
assertEquals(5, rows.size());
for (Tuple row : rows) {
int first = row.get(cat.id);
int second = row.get(cat2.id);
assertEquals(first + 1, second);
}
}
use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class SpatialBase method geometryType.
// FIXME, maybe use enum as the type ?!?
@Test
@ExcludeIn(H2)
public void geometryType() {
List<Tuple> results = query().from(shapes).select(shapes.geometry, shapes.geometry.geometryType()).fetch();
assertFalse(results.isEmpty());
for (Tuple row : results) {
assertEquals(normalize(row.get(shapes.geometry).getGeometryType().name()), normalize(row.get(shapes.geometry.geometryType())));
}
}
use of com.querydsl.core.Tuple in project querydsl by querydsl.
the class SpatialBase method point_x_y.
@Test
@ExcludeIn(H2)
public void point_x_y() {
PointPath<Point> point = shapes.geometry.asPoint();
List<Tuple> results = withPoints().select(point, point.x(), point.y()).fetch();
assertFalse(results.isEmpty());
for (Tuple row : results) {
assertEquals(Double.valueOf(row.get(point).getPosition().getCoordinate(0)), row.get(point.x()));
assertEquals(Double.valueOf(row.get(point).getPosition().getCoordinate(1)), row.get(point.y()));
}
}
use of com.querydsl.core.Tuple 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.Tuple 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