Search in sources :

Example 46 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class GroupByListTest method map4.

@Test
public void map4() {
    CloseableIterator<Map<Map<Integer, String>, String>> results = MAP4_RESULTS.transform(groupBy(postId).iterate(map(map(postId, commentText), postName)));
    List<Map<Map<Integer, String>, String>> actual = IteratorAdapter.asList(results);
    Object commentId = null;
    Map<Map<Integer, String>, String> comments = null;
    List<Map<Map<Integer, String>, String>> expected = new LinkedList<Map<Map<Integer, String>, String>>();
    for (Iterator<Tuple> iterator = MAP4_RESULTS.iterate(); iterator.hasNext(); ) {
        Tuple tuple = iterator.next();
        Object[] array = tuple.toArray();
        if (comments == null || !(commentId == array[0] || commentId != null && commentId.equals(array[0]))) {
            comments = new LinkedHashMap<Map<Integer, String>, String>();
            expected.add(comments);
        }
        commentId = array[0];
        @SuppressWarnings("unchecked") Pair<Pair<Integer, String>, String> pair = (Pair<Pair<Integer, String>, String>) array[1];
        Pair<Integer, String> first = pair.getFirst();
        Map<Integer, String> posts = Collections.singletonMap(first.getFirst(), first.getSecond());
        comments.put(posts, pair.getSecond());
    }
    assertEquals(expected.toString(), actual.toString());
}
Also used : Tuple(com.querydsl.core.Tuple) Pair(com.mysema.commons.lang.Pair) Test(org.junit.Test)

Example 47 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class OrderingTest method tabularResults.

@Test
public void tabularResults() {
    List<Tuple> rows = query().from(product).orderBy(product.name.asc()).select(product.name, product.description).fetch();
    assertEquals(30, rows.size());
    for (Tuple row : rows) {
        assertEquals(row.get(0, String.class).substring(1), row.get(1, String.class).substring(1));
    }
}
Also used : Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 48 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class HibernateBase method scrollTuple.

@Test
public void scrollTuple() throws IOException {
    CloseableIterator<Tuple> rows = new ScrollableResultsIterator<Tuple>(query().from(cat).select(cat.name, cat.birthdate).createQuery().scroll());
    assertTrue(rows.hasNext());
    while (rows.hasNext()) {
        Tuple row = rows.next();
        assertEquals(2, row.size());
    }
    rows.close();
}
Also used : Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 49 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class AbstractSQLTest method union3.

@SuppressWarnings("unchecked")
@Test
@ExcludeIn(Target.DERBY)
// FIXME
@Ignore
public void union3() {
    SAnimal cat2 = new SAnimal("cat2");
    List<Tuple> rows = query().union(select(cat.id, cat2.id).from(cat).innerJoin(cat2).on(cat2.id.eq(cat.id)), select(cat.id, null).from(cat)).list();
    assertEquals(12, rows.size());
    int nulls = 0;
    for (Tuple row : rows) {
        System.err.println(Collections.singletonList(row));
        if (row.get(1, Object.class) == null) {
            nulls++;
        }
    }
    assertEquals(6, nulls);
}
Also used : SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Tuple(com.querydsl.core.Tuple) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 50 with Tuple

use of com.querydsl.core.Tuple in project querydsl by querydsl.

the class AbstractSQLTest method union2.

@SuppressWarnings("unchecked")
@Test
@ExcludeIn({ Target.DERBY, Target.POSTGRESQL })
// FIXME
@Ignore
public void union2() {
    List<Tuple> rows = query().union(select(cat.name, cat.id).from(cat).where(cat.name.eq("Beck")).distinct(), select(cat.name, null).from(cat).where(cat.name.eq("Kate")).distinct()).list();
    assertEquals(2, rows.size());
    for (Tuple row : rows) {
        System.err.println(row);
    }
}
Also used : Tuple(com.querydsl.core.Tuple) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

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