Search in sources :

Example 6 with Tuple

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

the class GroupByMapTest method map4.

@Test
public void map4() {
    Map<Integer, Map<Map<Integer, String>, String>> actual = MAP4_RESULTS.transform(groupBy(postId).as(map(map(postId, commentText), postName)));
    Map<Integer, Map<Map<Integer, String>, String>> expected = new LinkedHashMap<Integer, Map<Map<Integer, String>, String>>();
    for (Iterator<Tuple> iterator = MAP4_RESULTS.iterate(); iterator.hasNext(); ) {
        Tuple tuple = iterator.next();
        Object[] array = tuple.toArray();
        Map<Map<Integer, String>, String> comments = expected.get(array[0]);
        if (comments == null) {
            comments = new LinkedHashMap<Map<Integer, String>, String>();
            expected.put((Integer) array[0], comments);
        }
        @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 7 with Tuple

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

the class GroupByListTest method map3.

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

Example 8 with Tuple

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

the class JPABase method createQuery4.

@Test
@NoHibernate
@ExcludeIn(Target.DERBY)
public void createQuery4() {
    List<Tuple> rows = query().from(cat).select(new Expression<?>[] { Expressions.nullExpression() }).fetch();
    for (Tuple row : rows) {
        assertNotNull(row);
        assertEquals(1, row.size());
        assertNull(row.get(Expressions.nullExpression()));
    }
}
Also used : Expression(com.querydsl.core.types.Expression) BooleanExpression(com.querydsl.core.types.dsl.BooleanExpression) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 9 with Tuple

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

the class AbstractSQLTest method entityQueries5.

@Test
@NoBatooJPA
@NoEclipseLink
public void entityQueries5() {
    QCat catEntity = QCat.cat;
    SAnimal otherCat = new SAnimal("otherCat");
    QCat otherCatEntity = new QCat("otherCat");
    List<Tuple> cats = query().from(cat, otherCat).select(catEntity, otherCatEntity).fetch();
    assertEquals(36, cats.size());
    for (Tuple tuple : cats) {
        assertTrue(tuple.get(catEntity) instanceof Cat);
        assertTrue(tuple.get(otherCatEntity) instanceof Cat);
    }
}
Also used : QCat(com.querydsl.jpa.domain.QCat) SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Cat(com.querydsl.jpa.domain.Cat) QCat(com.querydsl.jpa.domain.QCat) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

Example 10 with Tuple

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

the class AbstractSQLTest method entityQueries4.

@Test
@NoBatooJPA
@NoEclipseLink
public void entityQueries4() {
    QCat catEntity = QCat.cat;
    List<Tuple> cats = query().from(cat).select(catEntity, cat.name, cat.id).fetch();
    assertEquals(6, cats.size());
    for (Tuple tuple : cats) {
        assertTrue(tuple.get(catEntity) instanceof Cat);
        assertTrue(tuple.get(cat.name) instanceof String);
        assertTrue(tuple.get(cat.id) instanceof Integer);
    }
}
Also used : QCat(com.querydsl.jpa.domain.QCat) Cat(com.querydsl.jpa.domain.Cat) QCat(com.querydsl.jpa.domain.QCat) Tuple(com.querydsl.core.Tuple) Test(org.junit.Test)

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