Search in sources :

Example 21 with NameObject

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));
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) NameObjectContainer(com.blazebit.persistence.testsuite.entity.NameObjectContainer) Tuple(javax.persistence.Tuple) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 22 with NameObject

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);
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) Version(com.blazebit.persistence.testsuite.entity.Version) NameObjectContainer(com.blazebit.persistence.testsuite.entity.NameObjectContainer) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Date(java.util.Date)

Example 23 with NameObject

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;
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 24 with NameObject

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;
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Example 25 with NameObject

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;
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

Aggregations

NameObject (com.blazebit.persistence.testsuite.entity.NameObject)30 Test (org.junit.Test)7 Document (com.blazebit.persistence.testsuite.entity.Document)6 NameObjectContainer (com.blazebit.persistence.testsuite.entity.NameObjectContainer)5 Person (com.blazebit.persistence.testsuite.entity.Person)5 Category (org.junit.experimental.categories.Category)5 UpdatableDocumentEmbeddableView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableView)4 Tuple (javax.persistence.Tuple)4 Date (java.util.Date)3 Map (java.util.Map)3 Version (com.blazebit.persistence.testsuite.entity.Version)2 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)2 MapChangeModel (com.blazebit.persistence.view.change.MapChangeModel)2 PluralChangeModel (com.blazebit.persistence.view.change.PluralChangeModel)2 AbstractEntityViewUpdateEmbeddableTest (com.blazebit.persistence.view.testsuite.update.embeddable.simple.AbstractEntityViewUpdateEmbeddableTest)2 UpdatableDocumentEmbeddableWithCollectionsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithCollectionsView)2 UpdatableDocumentEmbeddableWithMapsView (com.blazebit.persistence.view.testsuite.update.embeddable.simple.mutable.model.UpdatableDocumentEmbeddableWithMapsView)2 UpdatableNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)2 ReadonlyNameObjectView (com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.ReadonlyNameObjectView)2 HashMap (java.util.HashMap)2