Search in sources :

Example 6 with SAnimal

use of com.querydsl.jpa.domain.sql.SAnimal in project querydsl by querydsl.

the class NativeSQLSerializerTest method in.

@Test
public void in() {
    Configuration conf = new Configuration(new MySQLTemplates());
    NativeSQLSerializer serializer = new NativeSQLSerializer(conf, true);
    DefaultQueryMetadata md = new DefaultQueryMetadata();
    SAnimal cat = SAnimal.animal_;
    md.addJoin(JoinType.DEFAULT, cat);
    md.addWhere(cat.name.in("X", "Y"));
    md.setProjection(cat.id);
    serializer.serialize(md, false);
    assertEquals("select animal_.id\n" + "from animal_ animal_\n" + "where animal_.name in (?1, ?2)", serializer.toString());
}
Also used : MySQLTemplates(com.querydsl.sql.MySQLTemplates) SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Configuration(com.querydsl.sql.Configuration) DefaultQueryMetadata(com.querydsl.core.DefaultQueryMetadata) Test(org.junit.Test)

Example 7 with SAnimal

use of com.querydsl.jpa.domain.sql.SAnimal in project querydsl by querydsl.

the class QueryMutabilityTest method clone_.

@Test
public void clone_() {
    SAnimal cat = new SAnimal("cat");
    HibernateSQLQuery<?> query = query().from(cat).where(cat.name.isNotNull());
    HibernateSQLQuery<?> query2 = query.clone(session);
    assertEquals(query.getMetadata().getJoins(), query2.getMetadata().getJoins());
    assertEquals(query.getMetadata().getWhere(), query2.getMetadata().getWhere());
// query2.fetch(cat.id);
}
Also used : SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Test(org.junit.Test)

Example 8 with SAnimal

use of com.querydsl.jpa.domain.sql.SAnimal in project querydsl by querydsl.

the class AbstractSQLTest method entityQueries2.

@Test
public void entityQueries2() {
    SAnimal mate = new SAnimal("mate");
    QCat catEntity = QCat.cat;
    List<Cat> cats = query().from(cat).innerJoin(mate).on(cat.mateId.eq(mate.id)).where(cat.dtype.eq("C"), mate.dtype.eq("C")).select(catEntity).fetch();
    assertTrue(cats.isEmpty());
}
Also used : SAnimal(com.querydsl.jpa.domain.sql.SAnimal) QCat(com.querydsl.jpa.domain.QCat) Cat(com.querydsl.jpa.domain.Cat) QCat(com.querydsl.jpa.domain.QCat) Test(org.junit.Test)

Example 9 with SAnimal

use of com.querydsl.jpa.domain.sql.SAnimal 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);
}
Also used : SAnimal(com.querydsl.jpa.domain.sql.SAnimal) Tuple(com.querydsl.core.Tuple) Ignore(org.junit.Ignore) Test(org.junit.Test) ExcludeIn(com.querydsl.core.testutil.ExcludeIn)

Example 10 with SAnimal

use of com.querydsl.jpa.domain.sql.SAnimal in project querydsl by querydsl.

the class JPAQueryMutabilityTest method clone_.

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

Aggregations

SAnimal (com.querydsl.jpa.domain.sql.SAnimal)13 Test (org.junit.Test)13 ExcludeIn (com.querydsl.core.testutil.ExcludeIn)4 QCat (com.querydsl.jpa.domain.QCat)4 Tuple (com.querydsl.core.Tuple)3 Cat (com.querydsl.jpa.domain.Cat)3 QueryMutability (com.querydsl.core.QueryMutability)2 HibernateSQLQuery (com.querydsl.jpa.hibernate.sql.HibernateSQLQuery)2 Query (org.hibernate.query.Query)2 Ignore (org.junit.Ignore)2 DefaultQueryMetadata (com.querydsl.core.DefaultQueryMetadata)1 JPASQLQuery (com.querydsl.jpa.sql.JPASQLQuery)1 Configuration (com.querydsl.sql.Configuration)1 MySQLTemplates (com.querydsl.sql.MySQLTemplates)1 Query (javax.persistence.Query)1