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);
}
});
}
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);
}
});
}
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());
}
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());
}
Aggregations