use of jakarta.persistence.Tuple in project jOOQ by jOOQ.
the class CriteriaQueryOrJOOQ method numberOfActorsPerLanguage.
private static void numberOfActorsPerLanguage(EntityManager em, DSLContext ctx) {
// Using criteria query
// --------------------
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> q = qb.createTupleQuery();
Root<Film> filmRoot = q.from(Film.class);
Join<Film, Language> filmJoin = filmRoot.join(Film_.language);
Path<String> languagePath = filmJoin.get(Language_.name);
SetJoin<Film, Actor> actorJoin = filmRoot.join(Film_.actors);
Path<Integer> actorPath = actorJoin.get(Actor_.actorId);
Expression<Long> count = qb.countDistinct(actorPath);
q = q.multiselect(languagePath, count);
q = q.groupBy(languagePath);
TypedQuery<Tuple> typed = em.createQuery(q);
for (Tuple tuple : typed.getResultList()) System.out.println(tuple.get(languagePath) + " (" + tuple.get(count) + " actors)");
for (Record rec : ctx.select(LANGUAGE.NAME, countDistinct(FILM_ACTOR.ACTORS_ACTORID).as("c")).from(LANGUAGE).join(FILM).on(FILM.LANGUAGE_LANGUAGEID.eq(LANGUAGE.LANGUAGEID)).join(FILM_ACTOR).on(FILM.FILMID.eq(FILM_ACTOR.FILMS_FILMID)).groupBy(LANGUAGE.NAME)) System.out.println(rec.get(LANGUAGE.NAME) + " (" + rec.get("c") + " actors)");
}
use of jakarta.persistence.Tuple in project jOOQ by jOOQ.
the class CriteriaQueryOrJOOQ method numberOfFilmsPerLanguage.
private static void numberOfFilmsPerLanguage(EntityManager em, DSLContext ctx) {
// Using criteria query
// --------------------
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Tuple> q = qb.createTupleQuery();
Root<Film> filmRoot = q.from(Film.class);
Join<Film, Language> filmJoin = filmRoot.join(Film_.language);
Path<String> languagePath = filmJoin.get(Language_.name);
Path<Integer> filmPath = filmRoot.get(Film_.filmId);
Expression<Long> count = qb.count(filmPath);
q = q.multiselect(languagePath, count);
q = q.groupBy(languagePath);
TypedQuery<Tuple> typed = em.createQuery(q);
for (Tuple tuple : typed.getResultList()) System.out.println(tuple.get(languagePath) + " (" + tuple.get(count) + " films)");
for (Record rec : ctx.select(LANGUAGE.NAME, count()).from(LANGUAGE).join(FILM).on(FILM.LANGUAGE_LANGUAGEID.eq(LANGUAGE.LANGUAGEID)).groupBy(LANGUAGE.NAME)) System.out.println(rec.get(LANGUAGE.NAME) + " (" + rec.get(count()) + " films)");
}