Search in sources :

Example 1 with EmbeddableTestEntitySimpleEmbeddable2

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

the class EmbeddableTestEntityViewTest method setUp.

@Before
public void setUp() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            IntIdEntity intIdEntity1 = new IntIdEntity("1");
            entity1 = new EmbeddableTestEntity2();
            entity1.setId(new EmbeddableTestEntityId2(intIdEntity1, "1"));
            entity1.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("1"));
            entity1.getEmbeddableMap().put("key1", new EmbeddableTestEntitySimpleEmbeddable2("1"));
            entity1.getEmbeddable().setName("1");
            entity1.getEmbeddable().setManyToOne(null);
            entity1.getEmbeddable().getElementCollection().put("1", intIdEntity1);
            IntIdEntity intIdEntity2 = new IntIdEntity("2");
            entity2 = new EmbeddableTestEntity2();
            entity2.setId(new EmbeddableTestEntityId2(intIdEntity2, "2"));
            entity2.getEmbeddableSet().add(new EmbeddableTestEntitySimpleEmbeddable2("2"));
            entity2.getEmbeddableMap().put("key2", new EmbeddableTestEntitySimpleEmbeddable2("2"));
            entity2.getEmbeddable().setName("2");
            entity2.getEmbeddable().setManyToOne(entity1);
            entity2.getEmbeddable().getElementCollection().put("2", intIdEntity2);
            em.persist(intIdEntity1);
            em.persist(intIdEntity2);
            em.persist(entity1);
            em.persist(entity2);
        }
    });
    entity1 = cbf.create(em, EmbeddableTestEntity2.class).fetch("id.intIdEntity", "embeddableSet", "embeddableMap", "embeddable.manyToOne", "embeddable.oneToMany", "embeddable.elementCollection").where("id").eq(entity1.getId()).getSingleResult();
    entity2 = cbf.create(em, EmbeddableTestEntity2.class).fetch("id.intIdEntity", "embeddableSet", "embeddableMap", "embeddable.manyToOne", "embeddable.oneToMany", "embeddable.elementCollection").where("id").eq(entity2.getId()).getSingleResult();
}
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) EmbeddableTestEntityId2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntityId2) Before(org.junit.Before)

Example 2 with EmbeddableTestEntitySimpleEmbeddable2

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

the class EmbeddableTestEntityViewTest method assertEqualViewEquals.

private void assertEqualViewEquals(EmbeddableTestEntity2 entity, EmbeddableTestEntityView view) {
    assertEquals(entity.getId(), view.getId());
    assertEquals(entity.getId().getIntIdEntity(), view.getIdIntIdEntity());
    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());
    assertEquals(entity.getEmbeddable().getManyToOne(), view.getEmbeddableManyToOne());
    assertEquals(entity.getEmbeddable().getOneToMany(), view.getEmbeddableOneToMany());
    assertEquals(entity.getEmbeddable().getElementCollection(), view.getEmbeddableElementCollection());
    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 : EmbeddableTestEntitySimpleEmbeddable2(com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2) EmbeddableTestEntitySimpleEmbeddableSubView(com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySimpleEmbeddableSubView) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with EmbeddableTestEntitySimpleEmbeddable2

use of com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2 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 4 with EmbeddableTestEntitySimpleEmbeddable2

use of com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2 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

EmbeddableTestEntitySimpleEmbeddable2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntitySimpleEmbeddable2)4 IntIdEntity (com.blazebit.persistence.testsuite.entity.IntIdEntity)3 EmbeddableTestEntity2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntity2)3 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)2 EmbeddableTestEntitySimpleEmbeddableSubView (com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySimpleEmbeddableSubView)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 EntityManager (javax.persistence.EntityManager)2 EmbeddableTestEntitySubView (com.blazebit.persistence.view.testsuite.basic.model.EmbeddableTestEntitySubView)1 IntIdEntityView (com.blazebit.persistence.view.testsuite.basic.model.IntIdEntityView)1 EmbeddableTestEntityId2 (com.blazebit.persistence.view.testsuite.entity.EmbeddableTestEntityId2)1 Before (org.junit.Before)1