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());
}
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());
}
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()));
}
}
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);
}
}
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);
}
}
Aggregations