Search in sources :

Example 1 with IntIdEntity

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

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

the class EmbeddedInheritanceTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            IntIdEntity i1 = new IntIdEntity("i1", 1);
            base1 = new SingleTableSub1("st1");
            base2 = new SingleTableSub2("st2");
            base1.setSub1Value(123);
            base2.setSub2Value(456);
            base2.setRelation2(i1);
            em.persist(i1);
            em.persist(base1);
            em.persist(base2);
            base1.setParent(base2);
            base2.setParent(base1);
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) SingleTableSub1(com.blazebit.persistence.testsuite.treat.entity.SingleTableSub1) SingleTableSub2(com.blazebit.persistence.testsuite.treat.entity.SingleTableSub2)

Example 3 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");
            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");
            // The Java compiler can't up-cast automatically, maybe a bug?
            // persist(em, i1, tpc1, tpc2, tpc1Parent, tpc2Parent);
            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 4 with IntIdEntity

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

the class EntityViewUpdateMutableNestedEmbeddableMapsTest method assertSubviewEquals.

private void assertSubviewEquals(Map<String, IntIdEntity> entities, Map<String, SimpleIntIdEntityView> views) {
    assertEquals(entities.size(), views.size());
    Map<String, SimpleIntIdEntityView> unmatched = new HashMap<>(views);
    for (Map.Entry<String, IntIdEntity> entry : entities.entrySet()) {
        IntIdEntity value = entry.getValue();
        SimpleIntIdEntityView view = unmatched.remove(entry.getKey());
        if (view == null || !value.getId().equals(view.getId())) {
            Assert.fail("Unmatched name object: " + value);
        }
    }
    if (!unmatched.isEmpty()) {
        Assert.fail("Unmatched views: " + unmatched);
    }
}
Also used : IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) SimpleIntIdEntityView(com.blazebit.persistence.view.testsuite.update.embeddable.nested.model.SimpleIntIdEntityView) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with IntIdEntity

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

the class AbstractEntityViewUpdateNestedEmbeddableEntityTest method prepareData.

@Override
protected void prepareData(EntityManager em) {
    entity1 = new EmbeddableTestEntity();
    entity1.getId().setKey("e1");
    entity1.getId().setValue("e1");
    entity1.setVersion(1L);
    entity2 = new EmbeddableTestEntity();
    entity2.getId().setKey("e2");
    entity2.getId().setValue("e2");
    entity2.setVersion(1L);
    intIdEntity1 = new IntIdEntity("i1", 1);
    intIdEntity2 = new IntIdEntity("i2", 2);
    em.persist(entity1);
    em.persist(entity2);
    em.persist(intIdEntity1);
    em.persist(intIdEntity2);
    entity1.getEmbeddable().setManyToOne(entity1);
    entity1.getEmbeddable().getManyToMany().put("a", intIdEntity1);
    entity1.getEmbeddable().getOneToMany2().add(entity1);
    entity1.getEmbeddable().getElementCollection().put("a", new NameObject("a", "b", intIdEntity1));
    entity1.getEmbeddable().getNestedEmbeddable().getNestedOneToMany().add(entity1);
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) IntIdEntity(com.blazebit.persistence.testsuite.entity.IntIdEntity) NameObject(com.blazebit.persistence.testsuite.entity.NameObject)

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