Search in sources :

Example 6 with IntIdEntity

use of com.blazebit.persistence.testsuite.entity.IntIdEntity in project blaze-persistence by Blazebit.

the class AbstractTreatVariationsTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            IntIdEntity i1 = new IntIdEntity("i1", 1);
            em.persist(i1);
            persist(em, new IntIdEntity("s1", 1));
            persist(em, new IntIdEntity("s2", 2));
            persist(em, new IntIdEntity("s1.parent", 101));
            persist(em, new IntIdEntity("s2.parent", 102));
            persist(em, new IntIdEntity("st1", 1));
            persist(em, new IntIdEntity("st2", 2));
            persist(em, new IntIdEntity("st1.parent", 101));
            persist(em, new IntIdEntity("st2.parent", 102));
            persist(em, new IntIdEntity("tpc1", 1));
            persist(em, new IntIdEntity("tpc2", 2));
            persist(em, new IntIdEntity("tpc1.parent", 101));
            persist(em, new IntIdEntity("tpc2.parent", 102));
            /**
             **************
             * Joined
             **************
             */
            JoinedSub1 s1 = new JoinedSub1("s1");
            JoinedSub2 s2 = new JoinedSub2("s2");
            JoinedSub1 s1Parent = new JoinedSub1("s1.parent");
            JoinedSub2 s2Parent = new JoinedSub2("s2.parent");
            if (supportsJoinedInheritance()) {
                persist(em, i1, s1, s2, s1Parent, s2Parent);
            }
            /**
             **************
             * Single Table
             **************
             */
            SingleTableSub1 st1 = new SingleTableSub1("st1");
            SingleTableSub2 st2 = new SingleTableSub2("st2");
            SingleTableSub1 st1Parent = new SingleTableSub1("st1.parent");
            SingleTableSub2 st2Parent = new SingleTableSub2("st2.parent");
            persist(em, i1, st1, st2, st1Parent, st2Parent);
            /**
             **************
             * Table per Class
             **************
             */
            TablePerClassSub1 tpc1 = new TablePerClassSub1(1L, "tpc1");
            TablePerClassSub2 tpc2 = new TablePerClassSub2(2L, "tpc2");
            TablePerClassSub1 tpc1Parent = new TablePerClassSub1(3L, "tpc1.parent");
            TablePerClassSub2 tpc2Parent = new TablePerClassSub2(4L, "tpc2.parent");
            // persist(em, i1, tpc1, tpc2, tpc1Parent, tpc2Parent);
            if (supportsTablePerClassInheritance()) {
                persist(em, i1, (Sub1) tpc1, (Sub2) tpc2, (Sub1) tpc1Parent, (Sub2) tpc2Parent);
            }
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) JoinedSub2(com.blazebit.persistence.testsuite.treat.entity.JoinedSub2) TablePerClassSub2(com.blazebit.persistence.testsuite.treat.entity.TablePerClassSub2) Sub2(com.blazebit.persistence.testsuite.treat.entity.Sub2) SingleTableSub2(com.blazebit.persistence.testsuite.treat.entity.SingleTableSub2) SingleTableSub1(com.blazebit.persistence.testsuite.treat.entity.SingleTableSub1) JoinedSub1(com.blazebit.persistence.testsuite.treat.entity.JoinedSub1) TablePerClassSub1(com.blazebit.persistence.testsuite.treat.entity.TablePerClassSub1) Sub1(com.blazebit.persistence.testsuite.treat.entity.Sub1) SingleTableSub1(com.blazebit.persistence.testsuite.treat.entity.SingleTableSub1) TablePerClassSub2(com.blazebit.persistence.testsuite.treat.entity.TablePerClassSub2) SingleTableSub2(com.blazebit.persistence.testsuite.treat.entity.SingleTableSub2) TablePerClassSub1(com.blazebit.persistence.testsuite.treat.entity.TablePerClassSub1) JoinedSub2(com.blazebit.persistence.testsuite.treat.entity.JoinedSub2) JoinedSub1(com.blazebit.persistence.testsuite.treat.entity.JoinedSub1)

Example 7 with IntIdEntity

use of com.blazebit.persistence.testsuite.entity.IntIdEntity in project blaze-persistence by Blazebit.

the class EmbeddableTestEntityViewTest method assertEqualViewEquals.

private void assertEqualViewEquals(EmbeddableTestEntity2 entity, EmbeddableTestEntityViewWithSubview view) {
    assertEquals(entity.getId(), view.getId());
    if (entity.getId().getIntIdEntity() == null) {
        assertNull(view.getIdIntIdEntity());
    } else {
        assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntity().getId());
    }
    assertEquals(entity.getId().getIntIdEntity().getId(), view.getIdIntIdEntityId());
    assertEquals(entity.getId().getIntIdEntity().getName(), view.getIdIntIdEntityName());
    assertEquals(entity.getId().getKey(), view.getIdKey());
    assertEquals(entity.getEmbeddable().getName(), view.getEmbeddable().getName());
    if (entity.getEmbeddable().getManyToOne() == null) {
        assertNull(view.getEmbeddableManyToOneView());
    } else {
        assertEquals(entity.getEmbeddable().getManyToOne().getId(), view.getEmbeddableManyToOneView().getId());
    }
    assertEquals(entity.getEmbeddable().getOneToMany().size(), view.getEmbeddableOneToManyView().size());
    OUTER: for (EmbeddableTestEntity2 child : entity.getEmbeddable().getOneToMany()) {
        for (EmbeddableTestEntitySubView childView : view.getEmbeddableOneToManyView()) {
            if (child.getId().equals(childView.getId())) {
                continue OUTER;
            }
        }
        fail("Couldn't find child view with id: " + child.getId());
    }
    assertEquals(entity.getEmbeddable().getElementCollection().size(), view.getEmbeddableElementCollectionView().size());
    for (Map.Entry<String, IntIdEntity> childEntry : entity.getEmbeddable().getElementCollection().entrySet()) {
        IntIdEntityView childView = view.getEmbeddableElementCollectionView().get(childEntry.getKey());
        assertEquals(childEntry.getValue().getId(), childView.getId());
    }
    Set<String> set1 = new HashSet<String>();
    for (EmbeddableTestEntitySimpleEmbeddable2 elem : entity.getEmbeddableSet()) {
        set1.add(elem.getName());
    }
    Set<String> set2 = new HashSet<String>();
    for (EmbeddableTestEntitySimpleEmbeddableSubView elem : view.getEmbeddableSet()) {
        set2.add(elem.getName());
    }
    assertEquals(set1, set2);
    Map<String, String> map1 = new HashMap<String, String>();
    for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddable2> entry : entity.getEmbeddableMap().entrySet()) {
        map1.put(entry.getKey(), entry.getValue().getName());
    }
    Map<String, String> map2 = new HashMap<String, String>();
    for (Map.Entry<String, EmbeddableTestEntitySimpleEmbeddableSubView> entry : view.getEmbeddableMap().entrySet()) {
        map2.put(entry.getKey(), entry.getValue().getName());
    }
    assertEquals(map1, map2);
}
Also used : IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) EmbeddableTestEntitySimpleEmbeddableSubView(com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySimpleEmbeddableSubView) HashMap(java.util.HashMap) EmbeddableTestEntity2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2) EmbeddableTestEntitySimpleEmbeddable2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2) EmbeddableTestEntitySubView(com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySubView) IntIdEntityView(com.blazebit.persistence.view.testsuite.basic.model.IntIdEntityView) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 8 with IntIdEntity

use of com.blazebit.persistence.testsuite.entity.IntIdEntity in project blaze-persistence by Blazebit.

the class EmbeddedFetchTest method setUpOnce.

@Override
public void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            IntIdEntity id1 = new IntIdEntity("i1");
            IntIdEntity id2 = new IntIdEntity("i2");
            IntIdEntity id3 = new IntIdEntity("i3");
            IntIdEntity id4 = new IntIdEntity("i4");
            em.persist(id1);
            em.persist(id2);
            em.persist(id3);
            em.persist(id4);
            doc1 = new EmbeddableTestEntity2(id1, "doc1");
            doc2 = new EmbeddableTestEntity2(id2, "doc2");
            doc3 = new EmbeddableTestEntity2(id3, "doc3");
            doc4 = new EmbeddableTestEntity2(id4, "doc4");
            doc1.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc1"));
            doc2.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc2"));
            doc3.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc3"));
            doc4.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("doc4"));
            doc1.getEmbeddableMap().put("doc1", new EmbeddableTestEntitySimpleEmbeddable2("doc1"));
            doc2.getEmbeddableMap().put("doc2", new EmbeddableTestEntitySimpleEmbeddable2("doc2"));
            doc3.getEmbeddableMap().put("doc3", new EmbeddableTestEntitySimpleEmbeddable2("doc3"));
            doc4.getEmbeddableMap().put("doc4", new EmbeddableTestEntitySimpleEmbeddable2("doc4"));
            em.persist(doc1);
            em.persist(doc2);
            em.persist(doc3);
            em.persist(doc4);
            doc1.getEmbeddable().setManyToOne(doc2);
            doc2.getEmbeddable().setManyToOne(doc2);
            doc3.getEmbeddable().setManyToOne(doc2);
            doc4.getEmbeddable().setManyToOne(doc2);
            doc1.getEmbeddable().getOneToMany().add(doc3);
            doc2.getEmbeddable().getOneToMany().add(doc3);
            doc3.getEmbeddable().getOneToMany().add(doc3);
            doc4.getEmbeddable().getOneToMany().add(doc3);
            doc1.getEmbeddable().getElementCollection().put("doc1", id1);
            doc2.getEmbeddable().getElementCollection().put("doc2", id2);
            doc3.getEmbeddable().getElementCollection().put("doc3", id3);
            doc4.getEmbeddable().getElementCollection().put("doc4", id4);
        }
    });
}
Also used : EmbeddableTestEntity2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2) EmbeddableTestEntitySimpleEmbeddable2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2) EntityManager(javax.persistence.EntityManager) IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork)

Aggregations

IntIdEntity (com.blazebit.persistence.testsuite.entity.IntIdEntity)8 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)5 EntityManager (javax.persistence.EntityManager)5 SingleTableSub1 (com.blazebit.persistence.testsuite.treat.entity.SingleTableSub1)3 SingleTableSub2 (com.blazebit.persistence.testsuite.treat.entity.SingleTableSub2)3 EmbeddableTestEntity2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2)3 EmbeddableTestEntitySimpleEmbeddable2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2)3 JoinedSub1 (com.blazebit.persistence.testsuite.treat.entity.JoinedSub1)2 JoinedSub2 (com.blazebit.persistence.testsuite.treat.entity.JoinedSub2)2 Sub1 (com.blazebit.persistence.testsuite.treat.entity.Sub1)2 Sub2 (com.blazebit.persistence.testsuite.treat.entity.Sub2)2 TablePerClassSub1 (com.blazebit.persistence.testsuite.treat.entity.TablePerClassSub1)2 TablePerClassSub2 (com.blazebit.persistence.testsuite.treat.entity.TablePerClassSub2)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EmbeddableTestEntity (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity)1 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)1 EmbeddableTestEntitySimpleEmbeddableSubView (com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySimpleEmbeddableSubView)1 EmbeddableTestEntitySubView (com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySubView)1 IntIdEntityView (com.blazebit.persistence.view.testsuite.basic.model.IntIdEntityView)1