Search in sources :

Example 1 with LegacyOrderPosition

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testUpdateReferenceEmbeddable.

@Test
public void testUpdateReferenceEmbeddable() {
    Assume.assumeFalse("Partial reference updates don't work in full mode", isFullMode());
    // Given
    UpdatableLegacyOrderView order1 = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    position.getEmbeddable().setName("123");
    order1.getPositions().add(position);
    update(order1);
    UpdatableLegacyOrderView order2 = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position1 = evm.create(UpdatableLegacyOrderPositionView.class);
    position1.getId().setPositionId(0);
    position1.setArticleNumber("123");
    position1.getEmbeddable().setName("123");
    order2.getPositions().add(position1);
    UpdatableLegacyOrderPositionView position2 = evm.create(UpdatableLegacyOrderPositionView.class);
    position2.getId().setPositionId(1);
    position2.setArticleNumber("456");
    position2.getEmbeddable().setName("456");
    order2.getPositions().add(position2);
    update(order2);
    // When
    UpdatableLegacyOrderView order = evm.getReference(UpdatableLegacyOrderView.class, order2.getId());
    position = evm.getReference(UpdatableLegacyOrderPositionView.class, position2.getId());
    position.setEmbeddable(evm.create(UpdatableLegacyOrderPositionEmbeddableView.class));
    position.getEmbeddable().setName("test");
    order.getPositions().add(position);
    update(order);
    // Then
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, order2.getId());
    Assert.assertEquals(1, legacyOrder.getPositions().size());
    LegacyOrderPosition orderPosition = legacyOrder.getPositions().iterator().next();
    Assert.assertEquals(new LegacyOrderPositionId(order2.getId(), position2.getId().getPositionId()), orderPosition.getId());
    assertEquals("456", orderPosition.getArticleNumber());
    assertEquals("test", orderPosition.getEmbeddable().getName());
}
Also used : LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) UpdatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView) UpdatableLegacyOrderPositionEmbeddableView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionEmbeddableView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 2 with LegacyOrderPosition

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testLoadMultipleUpdatableWithUpdatableFlatViewIds.

@Test
public void testLoadMultipleUpdatableWithUpdatableFlatViewIds() {
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            LegacyOrder o = new LegacyOrder();
            em.persist(o);
            LegacyOrderPosition p = new LegacyOrderPosition(new LegacyOrderPositionId(o.getId(), 0));
            p.setArticleNumber("123");
            p.setOrder(o);
            em.persist(p);
            o.getPositions().add(p);
            LegacyOrderPositionDefault d1 = new LegacyOrderPositionDefault(new LegacyOrderPositionDefaultId(p.getId(), 1));
            d1.setValue("1");
            em.persist(d1);
            LegacyOrderPositionDefault d2 = new LegacyOrderPositionDefault(new LegacyOrderPositionDefaultId(p.getId(), 2));
            d2.setValue("1");
            em.persist(d2);
            p.getDefaults().add(d1);
            p.getDefaults().add(d2);
        }
    });
    em.clear();
    List<UpdatableLegacyOrderPositionDefaultView> resultList = evm.applySetting(EntityViewSetting.create(UpdatableLegacyOrderPositionDefaultView.class), cbf.create(em, LegacyOrderPositionDefault.class)).getResultList();
    // Making the id view updatable at some point caused just a part of the id to be considered when de-duplicating updatable views
    assertEquals(2, resultList.size());
    assertNotEquals(resultList.get(0).getId(), resultList.get(1).getId());
}
Also used : LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) EntityManager(javax.persistence.EntityManager) UpdatableLegacyOrderPositionDefaultView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionDefaultView) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) LegacyOrderPositionDefault(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefault) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) LegacyOrderPositionDefaultId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefaultId) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 3 with LegacyOrderPosition

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

the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testAddElementCreateViewToCollection.

@Test
public void testAddElementCreateViewToCollection() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    CreatableLegacyOrderPositionView position = evm.create(CreatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    update(newOrder);
    // When
    CreatableLegacyOrderPositionElementView elementView = evm.create(CreatableLegacyOrderPositionElementView.class);
    elementView.setText("test");
    newOrder.getPositions().iterator().next().getElems().add(elementView);
    update(newOrder);
    // Then
    em.clear();
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals(1, legacyOrder.getPositions().size());
    LegacyOrderPosition orderPosition = legacyOrder.getPositions().iterator().next();
    Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 0), orderPosition.getId());
    Assert.assertEquals(1, orderPosition.getElems().size());
    Assert.assertEquals("test", orderPosition.getElems().iterator().next().getText());
}
Also used : CreatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView) LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) CreatableLegacyOrderPositionElementView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionElementView) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 4 with LegacyOrderPosition

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

the class EntityViewUpdateSubviewInverseEmbeddedComplexTest method testAddNewElementToCollectionAndUpdate.

@Test
public void testAddNewElementToCollectionAndUpdate() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    CreatableLegacyOrderPositionView position = evm.create(CreatableLegacyOrderPositionView.class);
    position.setCreationDate(Calendar.getInstance());
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    UpdatableLegacyOrderPositionDefaultView positionDefault = evm.create(UpdatableLegacyOrderPositionDefaultView.class);
    positionDefault.getId().setSupplierId(1);
    position.getDefaults().add(positionDefault);
    update(newOrder);
    // Then 1
    Assert.assertNotNull(newOrder.getPositions().iterator().next().getDefaults().iterator().next().getId().getOrderId());
    // When
    newOrder.getPositions().iterator().next().getDefaults().iterator().next().setValue("NEW");
    position = evm.create(CreatableLegacyOrderPositionView.class);
    position.getId().setPositionId(1);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    positionDefault = evm.create(UpdatableLegacyOrderPositionDefaultView.class);
    positionDefault.getId().setSupplierId(2);
    position.getDefaults().add(positionDefault);
    update(newOrder);
    // Then 2
    em.clear();
    LegacyOrder legacyOrder = em.find(LegacyOrder.class, newOrder.getId());
    Assert.assertEquals(2, legacyOrder.getPositions().size());
    Iterator<LegacyOrderPosition> iterator = legacyOrder.getPositions().iterator();
    LegacyOrderPosition actualPosition = iterator.next();
    if (actualPosition.getId().getPositionId().equals(0)) {
        actualPosition = iterator.next();
    }
    Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 1), actualPosition.getId());
}
Also used : CreatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView) LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) UpdatableLegacyOrderPositionDefaultView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionDefaultView) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) LegacyOrder(com.blazebit.persistence.view.testsuite.entity.LegacyOrder) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Example 5 with LegacyOrderPosition

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

the class EntityViewUpdateSubviewInverseEmbeddedSimpleTest method testConvertEmbeddedIdEntityViewToEntityReference.

@Test
public void testConvertEmbeddedIdEntityViewToEntityReference() {
    // Given
    UpdatableLegacyOrderView newOrder = evm.create(UpdatableLegacyOrderView.class);
    UpdatableLegacyOrderPositionView position = evm.create(UpdatableLegacyOrderPositionView.class);
    position.getId().setPositionId(0);
    position.setArticleNumber("123");
    newOrder.getPositions().add(position);
    update(newOrder);
    // When
    LegacyOrderPosition legacyOrderPosition = evm.getEntityReference(em, position);
    // Then
    Assert.assertEquals(new LegacyOrderPositionId(newOrder.getId(), 0), legacyOrderPosition.getId());
}
Also used : LegacyOrderPosition(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition) LegacyOrderPositionId(com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId) UpdatableLegacyOrderPositionView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView) UpdatableLegacyOrderView(com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView) AbstractEntityViewUpdateTest(com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest) Test(org.junit.Test)

Aggregations

LegacyOrderPosition (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPosition)5 LegacyOrderPositionId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionId)5 AbstractEntityViewUpdateTest (com.blazebit.persistence.view.testsuite.update.AbstractEntityViewUpdateTest)5 Test (org.junit.Test)5 LegacyOrder (com.blazebit.persistence.view.testsuite.entity.LegacyOrder)4 CreatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionView)2 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderView)2 UpdatableLegacyOrderPositionView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionView)2 UpdatableLegacyOrderView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderView)2 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)1 LegacyOrderPositionDefault (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefault)1 LegacyOrderPositionDefaultId (com.blazebit.persistence.view.testsuite.entity.LegacyOrderPositionDefaultId)1 CreatableLegacyOrderPositionElementView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.CreatableLegacyOrderPositionElementView)1 UpdatableLegacyOrderPositionDefaultView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.complex.model.UpdatableLegacyOrderPositionDefaultView)1 UpdatableLegacyOrderPositionDefaultView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionDefaultView)1 UpdatableLegacyOrderPositionEmbeddableView (com.blazebit.persistence.view.testsuite.update.subview.inverse.embedded.simple.model.UpdatableLegacyOrderPositionEmbeddableView)1 EntityManager (javax.persistence.EntityManager)1