use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class UpdatableFlatViewTest method setUp.
@Before
public void setUp() {
cleanDatabase();
transactional(new TxVoidWork() {
@Override
public void work(EntityManager em) {
doc1 = new Document("doc1");
Person o1 = new Person("pers1");
doc1.setOwner(o1);
doc1.getNameMap().put("doc1", new NameObject("doc1", "doc1"));
doc1.getNameMap().put("doc2", new NameObject("doc1", "doc1"));
em.persist(o1);
em.persist(doc1);
}
});
doc1 = cbf.create(em, Document.class).where("id").eq(doc1.getId()).fetch("owner").getSingleResult();
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableSubtypeFlatViewCollectionsTest method assertSubviewEquals.
public static void assertSubviewEquals(Collection<NameObject> persons, Collection<? extends ReadonlyNameObjectView> personSubviews) {
if (persons == null) {
assertNull(personSubviews);
return;
}
assertNotNull(personSubviews);
assertEquals(persons.size(), personSubviews.size());
for (NameObject p : persons) {
boolean found = false;
for (ReadonlyNameObjectView pSub : personSubviews) {
if (p.getPrimaryName().equals(pSub.getPrimaryName())) {
found = true;
break;
}
}
if (!found) {
Assert.fail("Could not find a UpdatableNameObjectView with the name: " + p.getPrimaryName());
}
}
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class EntityViewUpdateSimpleMutableFlatViewMapsTest method assertSubviewEquals.
public static void assertSubviewEquals(Map<String, NameObject> persons, Map<String, ? extends UpdatableNameObjectView> personSubviews) {
if (persons == null) {
assertNull(personSubviews);
return;
}
assertNotNull(personSubviews);
assertEquals(persons.size(), personSubviews.size());
for (Map.Entry<String, NameObject> entry : persons.entrySet()) {
NameObject p = entry.getValue();
boolean found = false;
UpdatableNameObjectView pSub = personSubviews.get(entry.getKey());
if (pSub != null) {
if (p.getPrimaryName().equals(pSub.getPrimaryName())) {
found = true;
break;
}
}
if (!found) {
Assert.fail("Could not find a UpdatableNameObjectView with the name: " + p.getPrimaryName());
}
}
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class ValuesClauseTest method testValuesEntityFunctionLikeEmbeddable.
@Test
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testValuesEntityFunctionLikeEmbeddable() {
CriteriaBuilder<Tuple> cb = cbf.create(em, Tuple.class);
cb.fromValues(Document.class, "nameObject", "t", Collections.singleton(new NameObject("123", "abc")));
cb.select("t");
String expected = "SELECT t FROM NameObject(1 VALUES LIKE Document.nameObject) t";
assertEquals(expected, cb.getQueryString());
List<Tuple> resultList = cb.getResultList();
assertEquals(1, resultList.size());
assertEquals(new NameObject("123", "abc"), resultList.get(0).get(0));
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class ValuesClauseTest method testValuesEntityFunctionWithEmbeddable.
@Test
@Category({ NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testValuesEntityFunctionWithEmbeddable() {
CriteriaBuilder<Tuple> cb = cbf.create(em, Tuple.class);
cb.fromValues(NameObject.class, "embeddable", Collections.singleton(new NameObject("abc", "123")));
cb.from(Document.class, "doc");
cb.where("doc.nameObject.primaryName").eqExpression("embeddable.secondaryName");
cb.where("doc.nameObject.secondaryName").eqExpression("embeddable.primaryName");
cb.select("doc.name");
cb.select("embeddable");
String expected = "" + "SELECT doc.name, embeddable FROM NameObject(1 VALUES) embeddable, Document doc" + " WHERE doc.nameObject.primaryName = embeddable.secondaryName AND doc.nameObject.secondaryName = embeddable.primaryName";
assertEquals(expected, cb.getQueryString());
List<Tuple> resultList = cb.getResultList();
assertEquals(1, resultList.size());
assertEquals("doc1", resultList.get(0).get(0));
assertEquals(new NameObject("abc", "123"), resultList.get(0).get(1));
}
Aggregations