Search in sources :

Example 31 with QCat

use of com.querydsl.jpa.domain.QCat in project querydsl by querydsl.

the class JPAQueryMixinTest method orderBy_where.

@Test
public void orderBy_where() {
    QCat cat = QCat.cat;
    mixin.from(cat);
    mixin.where(cat.mate.name.isNotNull());
    mixin.orderBy(cat.mate.name.asc());
    QueryMetadata md = mixin.getMetadata();
    assertEquals(Arrays.asList(new JoinExpression(JoinType.DEFAULT, cat)), md.getJoins());
    assertEquals(Arrays.asList(cat.mate.name.asc()), md.getOrderBy());
}
Also used : QCat(com.querydsl.jpa.domain.QCat) QueryMetadata(com.querydsl.core.QueryMetadata) JoinExpression(com.querydsl.core.JoinExpression) Test(org.junit.Test)

Example 32 with QCat

use of com.querydsl.jpa.domain.QCat in project querydsl by querydsl.

the class JPAQueryMixinTest method orderBy_any.

@Test
public void orderBy_any() {
    QCat cat = QCat.cat;
    QCat catKittens = new QCat("cat_kittens");
    mixin.from(cat);
    mixin.orderBy(cat.kittens.any().name.asc());
    QueryMetadata md = mixin.getMetadata();
    assertEquals(Arrays.asList(new JoinExpression(JoinType.DEFAULT, cat), new JoinExpression(JoinType.LEFTJOIN, cat.kittens.as(catKittens))), md.getJoins());
    assertEquals(Arrays.asList(catKittens.name.asc()), md.getOrderBy());
}
Also used : QCat(com.querydsl.jpa.domain.QCat) QueryMetadata(com.querydsl.core.QueryMetadata) JoinExpression(com.querydsl.core.JoinExpression) Test(org.junit.Test)

Example 33 with QCat

use of com.querydsl.jpa.domain.QCat in project querydsl by querydsl.

the class JPAQueryMutability2Test method clone_.

@Test
public void clone_() {
    QCat cat = QCat.cat;
    JPAQuery<?> query = query().from(cat).where(cat.name.isNotNull());
    JPAQuery<?> query2 = query.clone(entityManager);
    assertEquals(query.getMetadata().getJoins(), query2.getMetadata().getJoins());
    assertEquals(query.getMetadata().getWhere(), query2.getMetadata().getWhere());
    query2.select(cat).fetch();
}
Also used : QCat(com.querydsl.jpa.domain.QCat) Test(org.junit.Test)

Example 34 with QCat

use of com.querydsl.jpa.domain.QCat in project querydsl by querydsl.

the class JPAQueryMutability2Test method test.

@Test
public void test() {
    QCat cat = QCat.cat;
    JPAQuery<?> query = query().from(cat);
    query.fetchCount();
    query.distinct().fetchCount();
    query.select(cat).iterate();
    query.select(cat, cat).iterate();
    query.distinct().select(cat).iterate();
    query.distinct().select(cat, cat).iterate();
    query.select(cat).fetch();
    query.select(cat, cat).fetch();
    query.distinct().select(cat).fetch();
    query.distinct().select(cat, cat).fetch();
    query.select(cat).fetchResults();
    query.distinct().select(cat).fetchResults();
}
Also used : QCat(com.querydsl.jpa.domain.QCat) Test(org.junit.Test)

Example 35 with QCat

use of com.querydsl.jpa.domain.QCat in project querydsl by querydsl.

the class TupleTest method test.

@Test
// FIXME
@Ignore
public void test() {
    QCat cat = QCat.cat;
    SubQueryExpression<?> subQuery = select(cat.birthdate, cat.name, cat.mate).from(cat).where(select(cat.mate, cat.birthdate.max()).from(cat).groupBy(cat.mate).contains(Projections.tuple(cat.mate, cat.birthdate)));
    assertToString("(select cat.birthdate, cat.name, cat.mate from Cat cat " + "where (cat.mate, cat.birthdate) in " + "(select cat.mate, max(cat.birthdate) from Cat cat group by cat.mate))", subQuery);
}
Also used : QCat(com.querydsl.jpa.domain.QCat) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

QCat (com.querydsl.jpa.domain.QCat)35 Test (org.junit.Test)33 Cat (com.querydsl.jpa.domain.Cat)10 JoinExpression (com.querydsl.core.JoinExpression)8 QueryMetadata (com.querydsl.core.QueryMetadata)8 SAnimal (com.querydsl.jpa.domain.sql.SAnimal)6 Tuple (com.querydsl.core.Tuple)3 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)2 HibernateQuery (com.querydsl.jpa.hibernate.HibernateQuery)2 HibernateSQLQuery (com.querydsl.jpa.hibernate.sql.HibernateSQLQuery)2 JPASQLQuery (com.querydsl.jpa.sql.JPASQLQuery)2 Query (javax.persistence.Query)2 Query (org.hibernate.Query)2 BooleanBuilder (com.querydsl.core.BooleanBuilder)1 QueryMutability (com.querydsl.core.QueryMutability)1 ScrollableResults (org.hibernate.ScrollableResults)1 Ignore (org.junit.Ignore)1