use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class ValuesClauseTest method testValuesEntityFunctionWithPluralOnlyEmbeddable.
@Test
// NOTE: Only the latest Hibernate 5.2 properly implements support for selecting element collections
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoHibernate51.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testValuesEntityFunctionWithPluralOnlyEmbeddable() {
CriteriaBuilder<Tuple> cb = cbf.create(em, Tuple.class);
cb.fromValues(NameObjectContainer.class, "embeddable", Collections.singleton(new NameObjectContainer("test", new NameObject("abc", "123"))));
cb.from(Document.class, "doc");
cb.where("doc.nameContainers.name").eqExpression("embeddable.name");
cb.where("doc.nameContainers.nameObject.primaryName").eqExpression("embeddable.nameObject.secondaryName");
cb.where("doc.nameContainers.nameObject.secondaryName").eqExpression("embeddable.nameObject.primaryName");
cb.select("doc.name");
cb.select("embeddable");
String expected = "" + "SELECT doc.name, embeddable FROM NameObjectContainer(1 VALUES) embeddable, Document doc LEFT JOIN doc.nameContainers nameContainers_1" + " WHERE nameContainers_1.name = embeddable.name AND nameContainers_1.nameObject.primaryName = embeddable.nameObject.secondaryName AND nameContainers_1.nameObject.secondaryName = embeddable.nameObject.primaryName";
assertEquals(expected, cb.getQueryString());
List<Tuple> resultList = cb.getResultList();
assertEquals(1, resultList.size());
assertEquals("doc1", resultList.get(0).get(0));
assertEquals(new NameObjectContainer("test", new NameObject("abc", "123")), resultList.get(0).get(1));
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class AbstractEntityViewOrphanRemoveDocumentTest method prepareData.
@Override
protected void prepareData(EntityManager em) {
doc1 = new Document("doc1", null, new Version());
doc1.setVersion(1L);
doc1.setLastModified(new Date(EPOCH_2K));
doc1.getNameObject().setPrimaryName("doc1");
doc1.getNames().add(new NameObject("doc1", "doc1"));
doc1.getNameMap().put("doc1", new NameObject("doc1", "doc1"));
doc1.getNameContainers().add(new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
doc1.getNameContainerMap().put("doc1", new NameObjectContainer("doc1", new NameObject("doc1", "doc1")));
p1 = new Person("pers1");
p1.getNameObject().setPrimaryName("pers1");
p1.getLocalized().put(1, "localized1");
p2 = new Person("pers2");
p2.getNameObject().setPrimaryName("pers2");
p2.getLocalized().put(1, "localized2");
p3 = new Person("pers3");
p3.getNameObject().setPrimaryName("pers3");
p3.getLocalized().put(1, "localized3");
p4 = new Person("pers4");
p4.getNameObject().setPrimaryName("pers4");
p4.getLocalized().put(1, "localized4");
p5 = new Person("pers5");
p5.getNameObject().setPrimaryName("pers5");
p5.getLocalized().put(1, "localized5");
p6 = new Person("pers6");
p6.getNameObject().setPrimaryName("pers6");
p6.getLocalized().put(1, "localized6");
p7 = new Person("pers7");
p7.getNameObject().setPrimaryName("pers7");
p7.getLocalized().put(1, "localized7");
p8 = new Person("pers8");
p8.getNameObject().setPrimaryName("pers8");
p8.getLocalized().put(1, "localized8");
p9 = new Person("pers9");
p9.getNameObject().setPrimaryName("pers9");
p9.getLocalized().put(1, "localized9");
doc1.setOwner(p1);
doc1.setResponsiblePerson(p2);
doc1.getPeople().add(p3);
doc1.getPeople().add(p4);
doc1.getContacts().put(1, p5);
doc1.getContacts().put(2, p6);
doc1.getStrings().add("asd");
doc1.getStringMap().put("doc1", "doc1");
em.persist(p1);
em.persist(p2);
em.persist(p3);
em.persist(p4);
em.persist(p5);
em.persist(p6);
em.persist(p7);
em.persist(p8);
em.persist(p9);
em.persist(doc1);
p2.setFriend(p7);
p4.setFriend(p8);
p6.setFriend(p9);
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class AbstractEntityViewUpdateEmbeddableCollectionsTest method updateAddToNewCollection.
public T updateAddToNewCollection() {
// Given
final T docView = getDoc1View();
clearQueries();
// When
docView.setNames(new ArrayList<>(docView.getNames()));
docView.getNames().add(new NameObject("newPrimaryName", "newSecondaryName"));
return docView;
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class AbstractEntityViewUpdateEmbeddableCollectionsTest method updateAddToCollection.
public T updateAddToCollection() {
// Given
final T docView = getDoc1View();
clearQueries();
// When
docView.getNames().add(new NameObject("newPrimaryName", "newSecondaryName"));
return docView;
}
use of com.blazebit.persistence.testsuite.entity.NameObject in project blaze-persistence by Blazebit.
the class AbstractEntityViewUpdateEmbeddableCollectionsTest method updateRemoveNonExisting.
public T updateRemoveNonExisting() {
// Given
final T docView = getDoc1View();
clearQueries();
// When
docView.getNames().remove(new NameObject());
return docView;
}
Aggregations