Search in sources :

Example 1 with PrimitiveDocument

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

the class AttributeFilterTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new PrimitiveDocument("doc1");
            doc2 = new PrimitiveDocument("doc2");
            PrimitivePerson o1 = new PrimitivePerson("James");
            PrimitivePerson o2 = new PrimitivePerson("Jack");
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc1.getContacts().put(1, o1);
            doc2.getContacts().put(1, o2);
            em.persist(o1);
            em.persist(o2);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
}
Also used : PrimitiveDocument(com.blazebit.persistence.testsuite.entity.PrimitiveDocument) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) PrimitivePerson(com.blazebit.persistence.testsuite.entity.PrimitivePerson)

Example 2 with PrimitiveDocument

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

the class AttributeFilterTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new PrimitiveDocument("doc1");
            doc2 = new PrimitiveDocument("doc2");
            PrimitivePerson o1 = new PrimitivePerson("James");
            PrimitivePerson o2 = new PrimitivePerson("Jack");
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc1.getContacts().put(1, o1);
            doc2.getContacts().put(1, o2);
            em.persist(o1);
            em.persist(o2);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
}
Also used : PrimitiveDocument(com.blazebit.persistence.testsuite.entity.PrimitiveDocument) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) PrimitivePerson(com.blazebit.persistence.testsuite.entity.PrimitivePerson)

Example 3 with PrimitiveDocument

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

the class PrimitiveViewTest method setUp.

@Before
public void setUp() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            doc1 = new PrimitiveDocument("doc1");
            doc2 = new PrimitiveDocument("doc2");
            o1 = new PrimitivePerson("pers1");
            o2 = new PrimitivePerson("pers2");
            o1.setPartnerDocument(doc1);
            o2.setPartnerDocument(doc2);
            doc1.setOwner(o1);
            doc2.setOwner(o2);
            doc1.getContacts().put(1, o1);
            doc2.getContacts().put(1, o2);
            em.persist(o1);
            em.persist(o2);
            em.persist(doc1);
            em.persist(doc2);
        }
    });
    doc1 = em.find(PrimitiveDocument.class, doc1.getId());
    doc2 = em.find(PrimitiveDocument.class, doc2.getId());
}
Also used : PrimitiveDocument(com.blazebit.persistence.testsuite.entity.PrimitiveDocument) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) PrimitivePerson(com.blazebit.persistence.testsuite.entity.PrimitivePerson) Before(org.junit.Before)

Example 4 with PrimitiveDocument

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

the class AttributeFilterTest method testAttributeFilterWithInheritance.

@Test
// DataNucleus apparently thinks NULL has a specific type which isn't the one of other result arms of a CASE WHEN clause
@Category({ NoDatanucleus.class })
public void testAttributeFilterWithInheritance() {
    EntityViewManager evm = build(AttributeFilterInheritancePrimitiveDocumentView.class, AttributeFilterInheritancePrimitiveDocumentViewSub1.class, AttributeFilterInheritancePrimitiveDocumentViewSub2.class);
    EntityViewSetting<AttributeFilterInheritancePrimitiveDocumentView, CriteriaBuilder<AttributeFilterInheritancePrimitiveDocumentView>> setting = EntityViewSetting.create(AttributeFilterInheritancePrimitiveDocumentView.class);
    setting.addAttributeFilter("name", "JACK");
    CriteriaBuilder<AttributeFilterInheritancePrimitiveDocumentView> cb = evm.applySetting(setting, cbf.create(em, PrimitiveDocument.class));
    String caseExpression = "CASE WHEN primitiveDocument.name = 'doc1' THEN owner_1.name WHEN primitiveDocument.name = 'doc2' THEN UPPER(owner_1.name) ELSE NULL END";
    assertEquals("SELECT CASE WHEN primitiveDocument.name = 'doc1' THEN 1 WHEN primitiveDocument.name = 'doc2' THEN 2 ELSE 0 END AS AttributeFilterInheritancePrimitiveDocumentView_class," + " primitiveDocument.id AS AttributeFilterInheritancePrimitiveDocumentView_id, " + caseExpression + " AS AttributeFilterInheritancePrimitiveDocumentView_name" + " FROM PrimitiveDocument primitiveDocument" + " LEFT JOIN primitiveDocument.owner owner_1" + " WHERE " + caseExpression + " = :param_0", cb.getQueryString());
    List<AttributeFilterInheritancePrimitiveDocumentView> list = cb.getResultList();
    assertEquals(1, list.size());
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PrimitiveDocument(com.blazebit.persistence.testsuite.entity.PrimitiveDocument) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) AttributeFilterInheritancePrimitiveDocumentView(com.blazebit.persistence.view.testsuite.filter.inheritance.model.AttributeFilterInheritancePrimitiveDocumentView) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

PrimitiveDocument (com.blazebit.persistence.testsuite.entity.PrimitiveDocument)4 PrimitivePerson (com.blazebit.persistence.testsuite.entity.PrimitivePerson)3 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)3 EntityManager (javax.persistence.EntityManager)3 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)1 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)1 AttributeFilterInheritancePrimitiveDocumentView (com.blazebit.persistence.view.testsuite.filter.inheritance.model.AttributeFilterInheritancePrimitiveDocumentView)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1