Search in sources :

Example 1 with QDocument

use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.

the class BasicQueryTest method testNestedSubQuery.

// NOTE: No advanced sql support for Datanucleus, Eclipselink and OpenJPA yet
@Test
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testNestedSubQuery() {
    doInJPA(entityManager -> {
        QDocument sub = new QDocument("sub");
        QDocument sub2 = new QDocument("sub2");
        BlazeJPAQuery<Tuple> query = new BlazeJPAQuery<Document>(entityManager, cbf).from(document).select(document.name.as("documentName"), document.name.substring(0, 2)).where(document.id.in(select(sub.id).from(sub).where(sub.id.in(select(sub2.id).from(sub2).where(sub2.id.eq(sub.id)))).orderBy(sub.id.asc()).limit(5)));
        List<Tuple> fetch = query.fetch();
        assertFalse(fetch.isEmpty());
    });
}
Also used : QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Document(com.blazebit.persistence.testsuite.entity.Document) QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Tuple(com.querydsl.core.Tuple) Category(org.junit.experimental.categories.Category) AbstractCoreTest(com.blazebit.persistence.testsuite.AbstractCoreTest) Test(org.junit.Test)

Example 2 with QDocument

use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.

the class BasicQueryTest method testEntityJoin.

// NOTE: Entity joins are only supported on Hibernate 5.1+
@Test
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class, NoHibernate42.class, NoHibernate43.class, NoHibernate50.class })
public void testEntityJoin() {
    Assume.assumeTrue(jpaProvider.supportsEntityJoin());
    doInJPA(entityManager -> {
        QPerson otherAuthor = new QPerson("otherAuthor");
        QDocument otherBook = new QDocument("otherBook");
        Map<Person, List<Document>> booksByAuthor = new BlazeJPAQuery<Document>(entityManager, cbf).from(otherAuthor).innerJoin(otherBook).on(otherBook.owner.eq(otherAuthor)).transform(GroupBy.groupBy(otherAuthor).as(GroupBy.list(otherBook)));
        assertNotNull(booksByAuthor);
    });
}
Also used : QDocument(com.blazebit.persistence.testsuite.entity.QDocument) QPerson(com.blazebit.persistence.testsuite.entity.QPerson) List(java.util.List) PagedList(com.blazebit.persistence.PagedList) Person(com.blazebit.persistence.testsuite.entity.Person) QPerson(com.blazebit.persistence.testsuite.entity.QPerson) Category(org.junit.experimental.categories.Category) AbstractCoreTest(com.blazebit.persistence.testsuite.AbstractCoreTest) Test(org.junit.Test)

Example 3 with QDocument

use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.

the class BasicQueryTest method testComplexSubqueryUnion.

// NOTE: No advanced sql support for Datanucleus, Eclipselink and OpenJPA yet
// NOTE: MySQL only supports the UNION set operation
@Test
@Category({ NoMySQL.class, NoFirebird.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testComplexSubqueryUnion() {
    doInJPA(entityManager -> {
        Person person = new Person();
        person.setName("Person");
        entityManager.persist(person);
        Document theBook = new Document();
        theBook.setId(1337L);
        theBook.setName("test");
        theBook.setOwner(person);
        entityManager.merge(theBook);
        Document theSequel = new Document();
        theSequel.setId(42L);
        theSequel.setName("test2");
        theSequel.setOwner(person);
        entityManager.merge(theSequel);
    });
    doInJPA(entityManager -> {
        SetExpression<Long> union = new BlazeJPAQuery<Long>(entityManager, cbf).union(select(document.id).from(document).where(document.id.eq(1337L)), new BlazeJPAQuery<Long>().intersect(select(document.id).from(document).where(document.id.eq(41L)), new BlazeJPAQuery<Long>().except(select(document.id).from(document).where(document.id.eq(42L)), select(document.id).from(document).where(document.id.eq(43L)))), select(document.id).from(document).where(document.id.eq(46L)));
        QDocument book2 = new QDocument("secondBook");
        List<Document> fetch = new BlazeJPAQuery<Document>(entityManager, cbf).select(book2).from(book2).where(book2.id.in(union)).fetch();
        assertNotNull(fetch);
    });
}
Also used : QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Document(com.blazebit.persistence.testsuite.entity.Document) QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Person(com.blazebit.persistence.testsuite.entity.Person) QPerson(com.blazebit.persistence.testsuite.entity.QPerson) Category(org.junit.experimental.categories.Category) AbstractCoreTest(com.blazebit.persistence.testsuite.AbstractCoreTest) Test(org.junit.Test)

Example 4 with QDocument

use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.

the class BasicQueryTest method testWindowFunction.

// NOTE: Window functions were only introduced in MySQL8
@Test
@Category({ NoMySQLOld.class })
public void testWindowFunction() {
    Assume.assumeTrue(dbmsDialect.supportsWindowFunctions());
    doInJPA(entityManager -> {
        QDocument sub = new QDocument("sub");
        BlazeJPAQuery<Tuple> query = new BlazeJPAQuery<Document>(entityManager, cbf).from(document).select(document.name.as("documentName"), rowNumber().over().orderBy(document.id), lastValue(document.name).over().partitionBy(document.id).orderBy(document.id)).where(document.id.in(select(sub.id).from(sub)));
        List<Tuple> fetch = query.fetch();
        assertFalse(fetch.isEmpty());
    });
}
Also used : QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Document(com.blazebit.persistence.testsuite.entity.Document) QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Tuple(com.querydsl.core.Tuple) Category(org.junit.experimental.categories.Category) AbstractCoreTest(com.blazebit.persistence.testsuite.AbstractCoreTest) Test(org.junit.Test)

Example 5 with QDocument

use of com.blazebit.persistence.testsuite.entity.QDocument in project blaze-persistence by Blazebit.

the class BasicQueryTest method testSubQuery.

@Test
public void testSubQuery() {
    doInJPA(entityManager -> {
        QDocument sub = new QDocument("sub");
        BlazeJPAQuery<Tuple> query = new BlazeJPAQuery<Document>(entityManager, cbf).from(document).select(document.name.as("blep"), document.name.substring(0, 2)).where(document.id.in(select(sub.id).from(sub)));
        List<Tuple> fetch = query.fetch();
        assertFalse(fetch.isEmpty());
    });
}
Also used : QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Document(com.blazebit.persistence.testsuite.entity.Document) QDocument(com.blazebit.persistence.testsuite.entity.QDocument) Tuple(com.querydsl.core.Tuple) AbstractCoreTest(com.blazebit.persistence.testsuite.AbstractCoreTest) Test(org.junit.Test)

Aggregations

AbstractCoreTest (com.blazebit.persistence.testsuite.AbstractCoreTest)6 QDocument (com.blazebit.persistence.testsuite.entity.QDocument)6 Test (org.junit.Test)6 Category (org.junit.experimental.categories.Category)5 Document (com.blazebit.persistence.testsuite.entity.Document)4 Tuple (com.querydsl.core.Tuple)4 Person (com.blazebit.persistence.testsuite.entity.Person)2 QPerson (com.blazebit.persistence.testsuite.entity.QPerson)2 PagedList (com.blazebit.persistence.PagedList)1 List (java.util.List)1