Search in sources :

Example 1 with NameObject

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();
}
Also used : EntityManager(javax.persistence.EntityManager) NameObject(com.blazebit.persistence.testsuite.entity.NameObject) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) Document(com.blazebit.persistence.testsuite.entity.Document) Person(com.blazebit.persistence.testsuite.entity.Person) Before(org.junit.Before)

Example 2 with NameObject

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());
        }
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) ReadonlyNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutablesubtype.model.ReadonlyNameObjectView)

Example 3 with NameObject

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());
        }
    }
}
Also used : NameObject(com.blazebit.persistence.testsuite.entity.NameObject) HashMap(java.util.HashMap) Map(java.util.Map) UpdatableNameObjectView(com.blazebit.persistence.view.testsuite.update.flatview.simple.mutable.model.UpdatableNameObjectView)

Example 4 with NameObject

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

Example 5 with NameObject

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

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