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