Search in sources :

Example 1 with EmbeddableTestEntity

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

the class UpdateEmbeddableComplexTest method testUpdateWithReturningExplicitId.

@Test
// TODO: report that datanucleus doesn't support element collection in an embeddable
@Category({ NoH2.class, NoOracle.class, NoSQLite.class, NoFirebird.class, NoMySQL.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testUpdateWithReturningExplicitId() {
    final String intIdEntity1Key = "1";
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable2Id = new EmbeddableTestEntityId("1", "2");
            EmbeddableTestEntity embeddable2 = new EmbeddableTestEntity();
            embeddable2.setId(embeddable2Id);
            em.persist(embeddable2);
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", intIdEntity1Key);
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            EmbeddableTestEntityEmbeddable embeddable1Embeddable = new EmbeddableTestEntityEmbeddable();
            embeddable1Embeddable.setManyToOne(embeddable2);
            embeddable1.setEmbeddable(embeddable1Embeddable);
            em.persist(embeddable1);
            em.flush();
            EmbeddableTestEntityId manyToOneId = cbf.update(em, EmbeddableTestEntity.class, "e").set("id.key", "newKey").where("e.id.key").eq(intIdEntity1Key).executeWithReturning("embeddable.manyToOne.id", EmbeddableTestEntityId.class).getLastResult();
            assertEquals(embeddable2Id, manyToOneId);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityEmbeddable(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityEmbeddable) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with EmbeddableTestEntity

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

Example 3 with EmbeddableTestEntity

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

the class UpdateEmbeddableComplexTest method testUpdateWithReturningEmbeddable.

@Test
// TODO: report that datanucleus doesn't support element collection in an embeddable
@Category({ NoH2.class, NoOracle.class, NoSQLite.class, NoFirebird.class, NoMySQL.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testUpdateWithReturningEmbeddable() {
    final String newEmbeddableTestEntityIdKey = "newKey";
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", "oldKey");
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            em.persist(embeddable1);
            em.flush();
            String key = cbf.update(em, EmbeddableTestEntity.class, "e").set("id.key", newEmbeddableTestEntityIdKey).executeWithReturning("id.key", String.class).getLastResult();
            assertEquals(newEmbeddableTestEntityIdKey, key);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 4 with EmbeddableTestEntity

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

the class EmbeddedCorrelationTest method setUpOnce.

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

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", "oldKey");
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            em.persist(embeddable1);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId)

Example 5 with EmbeddableTestEntity

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

the class EmbeddedCorrelationTest method testEmbeddedCorrelation.

// For #556
@Test
// NOTE: Eclipselink and Datanucleus don't support the single valued id access optimization which causes a cyclic join dependency
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoDatanucleus.class, NoOpenJPA.class, NoEclipselink.class })
public void testEmbeddedCorrelation() {
    EntityViewManager evm = build(EmbeddableTestEntityCorrelationView.class, EmbeddableTestEntityCorrelationView.Id.class, EmbeddableTestEntityCorrelationView.SimpleEmbeddableTestEntityCorrelationView.class);
    CriteriaBuilder<EmbeddableTestEntity> criteria = cbf.create(em, EmbeddableTestEntity.class, "d");
    EntityViewSetting<EmbeddableTestEntityCorrelationView, CriteriaBuilder<EmbeddableTestEntityCorrelationView>> setting = EntityViewSetting.create(EmbeddableTestEntityCorrelationView.class);
    CriteriaBuilder<EmbeddableTestEntityCorrelationView> cb = evm.applySetting(setting, criteria);
    cb.getResultList();
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityViewManager(com.blazebit.persistence.view.EntityViewManager) EmbeddableTestEntityCorrelationView(com.blazebit.persistence.view.testsuite.correlation.embedded.model.EmbeddableTestEntityCorrelationView) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) AbstractEntityViewTest(com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)

Aggregations

EmbeddableTestEntity (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity)5 EmbeddableTestEntityId (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId)3 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)3 EntityManager (javax.persistence.EntityManager)3 Test (org.junit.Test)3 Category (org.junit.experimental.categories.Category)3 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 EmbeddableTestEntityEmbeddable (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityEmbeddable)1 IntIdEntity (com.blazebit.persistence.testsuite.entity.IntIdEntity)1 NameObject (com.blazebit.persistence.testsuite.entity.NameObject)1 EntityViewManager (com.blazebit.persistence.view.EntityViewManager)1 AbstractEntityViewTest (com.blazebit.persistence.view.testsuite.AbstractEntityViewTest)1 EmbeddableTestEntityCorrelationView (com.blazebit.persistence.view.testsuite.correlation.embedded.model.EmbeddableTestEntityCorrelationView)1