Search in sources :

Example 1 with IvOther

use of org.apache.cayenne.testdo.inheritance_vertical.IvOther in project cayenne by apache.

the class VerticalInheritanceMultipleAttributesIT method testUpdateTwoObjects.

/**
 * @link https://issues.apache.org/jira/browse/CAY-2282
 */
@Test
public void testUpdateTwoObjects() throws SQLException {
    // Insert records we want to update
    ivOtherTable.insert(1, "other1");
    ivOtherTable.insert(2, "other2");
    ivBaseTable.insert(1, "Impl 1", "I");
    ivBaseTable.insert(2, "Impl 2", "I");
    ivImplTable.insert(1, "attr1", "attr2", 1, 2);
    ivImplTable.insert(2, "attr1", "attr2", 1, 2);
    // Fetch and update the records
    IvOther other1 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other1")).selectOne(context);
    IvOther other2 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other2")).selectOne(context);
    List<IvImpl> implResult = ObjectSelect.query(IvImpl.class).select(context);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        record.setName(record.getName() + "-Change");
        record.setAttr1(record.getAttr1() + "-Change");
        record.setAttr2(record.getAttr2() + "-Change");
        record.setOther1(other2);
        record.setOther2(other1);
    }
    context.commitChanges();
    // Check result via clean context
    ObjectContext cleanContext = runtime.newContext();
    implResult = ObjectSelect.query(IvImpl.class).select(cleanContext);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        assertTrue(record.getName().endsWith("-Change"));
        assertTrue(record.getAttr1().endsWith("-Change"));
        assertTrue(record.getAttr2().endsWith("-Change"));
        assertEquals(other2.getObjectId(), record.getOther1().getObjectId());
        assertEquals(other1.getObjectId(), record.getOther2().getObjectId());
    }
}
Also used : IvOther(org.apache.cayenne.testdo.inheritance_vertical.IvOther) ObjectContext(org.apache.cayenne.ObjectContext) IvImpl(org.apache.cayenne.testdo.inheritance_vertical.IvImpl) Test(org.junit.Test)

Example 2 with IvOther

use of org.apache.cayenne.testdo.inheritance_vertical.IvOther in project cayenne by apache.

the class VerticalInheritanceMultipleAttributesIT method testCreateObjectsWithData.

@Test
public void testCreateObjectsWithData() throws SQLException {
    ivOtherTable.insert(1, "other1");
    ivOtherTable.insert(2, "other2");
    IvOther other1 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other1")).selectOne(context);
    IvOther other2 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other2")).selectOne(context);
    IvImpl impl1 = context.newObject(IvImpl.class);
    impl1.setName("name");
    impl1.setAttr1("attr1");
    impl1.setAttr2("attr2");
    impl1.setOther1(other1);
    impl1.setOther2(other2);
    IvImpl impl2 = context.newObject(IvImpl.class);
    impl2.setName("name");
    impl2.setAttr1("attr1");
    impl2.setAttr2("attr2");
    impl2.setOther1(other1);
    impl2.setOther2(other2);
    context.commitChanges();
    // Check result via clean context
    ObjectContext cleanContext = runtime.newContext();
    List<IvImpl> implResult = ObjectSelect.query(IvImpl.class).select(cleanContext);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        assertEquals("name", record.getName());
        assertEquals("attr1", record.getAttr1());
        assertEquals("attr2", record.getAttr2());
        assertEquals(other1.getObjectId(), record.getOther1().getObjectId());
        assertEquals(other2.getObjectId(), record.getOther2().getObjectId());
    }
}
Also used : IvOther(org.apache.cayenne.testdo.inheritance_vertical.IvOther) ObjectContext(org.apache.cayenne.ObjectContext) IvImpl(org.apache.cayenne.testdo.inheritance_vertical.IvImpl) Test(org.junit.Test)

Example 3 with IvOther

use of org.apache.cayenne.testdo.inheritance_vertical.IvOther in project cayenne by apache.

the class VerticalInheritanceMultipleAttributesIT method testCreateEmptyObjectsWithUpdate.

@Test
public void testCreateEmptyObjectsWithUpdate() throws SQLException {
    ivOtherTable.insert(1, "other1");
    ivOtherTable.insert(2, "other2");
    IvOther other1 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other1")).selectOne(context);
    IvOther other2 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other2")).selectOne(context);
    IvImpl impl1 = context.newObject(IvImpl.class);
    impl1.setName("name");
    IvImpl impl2 = context.newObject(IvImpl.class);
    impl2.setName("name");
    context.commitChanges();
    ObjectContext cleanContext = runtime.newContext();
    List<IvImpl> implResult = ObjectSelect.query(IvImpl.class).select(cleanContext);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        assertEquals("name", record.getName());
        assertNull(record.getAttr1());
        assertNull(record.getAttr2());
        assertNull(record.getOther1());
        assertNull(record.getOther2());
    }
    impl1.setAttr1("attr1");
    impl1.setAttr2("attr2");
    impl1.setOther1(other1);
    impl1.setOther2(other2);
    impl2.setAttr1("attr1");
    impl2.setAttr2("attr2");
    impl2.setOther1(other1);
    impl2.setOther2(other2);
    context.commitChanges();
    cleanContext = runtime.newContext();
    implResult = ObjectSelect.query(IvImpl.class).select(cleanContext);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        assertEquals("name", record.getName());
        assertEquals("attr1", record.getAttr1());
        assertEquals("attr2", record.getAttr2());
        assertEquals(other1.getObjectId(), record.getOther1().getObjectId());
        assertEquals(other2.getObjectId(), record.getOther2().getObjectId());
    }
}
Also used : IvOther(org.apache.cayenne.testdo.inheritance_vertical.IvOther) ObjectContext(org.apache.cayenne.ObjectContext) IvImpl(org.apache.cayenne.testdo.inheritance_vertical.IvImpl) Test(org.junit.Test)

Example 4 with IvOther

use of org.apache.cayenne.testdo.inheritance_vertical.IvOther in project cayenne by apache.

the class VerticalInheritanceMultipleAttributesIT method testPartialCreateObjectsWithUpdate.

@Test
public void testPartialCreateObjectsWithUpdate() throws SQLException {
    ivOtherTable.insert(1, "other1");
    ivOtherTable.insert(2, "other2");
    IvOther other1 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other1")).selectOne(context);
    IvOther other2 = ObjectSelect.query(IvOther.class).where(IvOther.NAME.eq("other2")).selectOne(context);
    IvImpl impl1 = context.newObject(IvImpl.class);
    impl1.setName("name");
    impl1.setAttr1("attr1");
    IvImpl impl2 = context.newObject(IvImpl.class);
    impl2.setName("name");
    impl2.setAttr1("attr1");
    context.commitChanges();
    ObjectContext cleanContext = runtime.newContext();
    List<IvImpl> implResult = ObjectSelect.query(IvImpl.class).select(cleanContext);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        assertEquals("name", record.getName());
        assertEquals("attr1", record.getAttr1());
        assertNull(record.getAttr2());
        assertNull(record.getOther1());
        assertNull(record.getOther2());
    }
    impl1.setAttr1("attr1");
    impl1.setAttr2("attr2");
    impl1.setOther1(other1);
    impl1.setOther2(other2);
    impl2.setAttr1("attr1");
    impl2.setAttr2("attr2");
    impl2.setOther1(other1);
    impl2.setOther2(other2);
    context.commitChanges();
    cleanContext = runtime.newContext();
    implResult = ObjectSelect.query(IvImpl.class).select(cleanContext);
    assertEquals(2, implResult.size());
    for (IvImpl record : implResult) {
        assertEquals("name", record.getName());
        assertEquals("attr1", record.getAttr1());
        assertEquals("attr2", record.getAttr2());
        assertEquals(other1.getObjectId(), record.getOther1().getObjectId());
        assertEquals(other2.getObjectId(), record.getOther2().getObjectId());
    }
}
Also used : IvOther(org.apache.cayenne.testdo.inheritance_vertical.IvOther) ObjectContext(org.apache.cayenne.ObjectContext) IvImpl(org.apache.cayenne.testdo.inheritance_vertical.IvImpl) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)4 IvImpl (org.apache.cayenne.testdo.inheritance_vertical.IvImpl)4 IvOther (org.apache.cayenne.testdo.inheritance_vertical.IvOther)4 Test (org.junit.Test)4