Search in sources :

Example 11 with Tuple

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);
    }
}
Also used : SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 12 with Tuple

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())));
    }
}
Also used : Tuple(com.querydsl.core.Tuple) AbstractBaseTest(com.querydsl.sql.AbstractBaseTest) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 13 with Tuple

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()));
    }
}
Also used : Tuple(com.querydsl.core.Tuple) AbstractBaseTest(com.querydsl.sql.AbstractBaseTest) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 14 with Tuple

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);
}
Also used : Group(com.querydsl.core.group.Group) GroupImpl(com.querydsl.core.group.GroupImpl) GroupExpression(com.querydsl.core.group.GroupExpression) Tuple(com.querydsl.core.Tuple)

Example 15 with Tuple

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);
}
Also used : Group(com.querydsl.core.group.Group) GroupExpression(com.querydsl.core.group.GroupExpression) GroupImpl(com.querydsl.core.group.GroupImpl) Tuple(com.querydsl.core.Tuple)

Aggregations

Tuple (com.querydsl.core.Tuple)55 Test (org.junit.Test)41 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)10 Pair (com.mysema.commons.lang.Pair)7 QTuple (com.querydsl.core.types.QTuple)6 Expression (com.querydsl.core.types.Expression)4 StringPath (com.querydsl.core.types.dsl.StringPath)4 AbstractBaseTest (com.querydsl.sql.AbstractBaseTest)4 QCat (com.querydsl.jpa.domain.QCat)3 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)3 QEmployee (com.querydsl.sql.domain.QEmployee)3 ArrayList (java.util.ArrayList)3 Ignore (org.junit.Ignore)3 QObject (com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)2 ResultListRowTransformer (com.evolveum.midpoint.repo.sqlbase.mapping.ResultListRowTransformer)2 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 QueryMetadata (com.querydsl.core.QueryMetadata)2 Group (com.querydsl.core.group.Group)2