Search in sources :

Example 1 with EmbedEntity1

use of org.apache.cayenne.testdo.embeddable.EmbedEntity1 in project cayenne by apache.

the class EmbeddingIT method testUpdateEmbedded.

@Test
public void testUpdateEmbedded() throws Exception {
    createUpdateDataSet();
    List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
    EmbedEntity1 o1 = results.get(0);
    Embeddable1 e11 = new Embeddable1();
    e11.setEmbedded10("x1");
    e11.setEmbedded20("x2");
    o1.setEmbedded1(e11);
    assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
    context.commitChanges();
    DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
    assertNotNull(row);
    assertEquals("x1", row.get("EMBEDDED10"));
}
Also used : Embeddable1(org.apache.cayenne.testdo.embeddable.Embeddable1) DataRow(org.apache.cayenne.DataRow) EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 2 with EmbedEntity1

use of org.apache.cayenne.testdo.embeddable.EmbedEntity1 in project cayenne by apache.

the class EmbeddingIT method testUpdateEmbeddedProperties.

@Test
public void testUpdateEmbeddedProperties() throws Exception {
    createUpdateDataSet();
    List<EmbedEntity1> results = ObjectSelect.query(EmbedEntity1.class).orderBy(EmbedEntity1.NAME.asc()).select(context);
    EmbedEntity1 o1 = results.get(0);
    Embeddable1 e11 = o1.getEmbedded1();
    e11.setEmbedded10("x1");
    assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
    context.commitChanges();
    DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
    assertNotNull(row);
    assertEquals("x1", row.get("EMBEDDED10"));
}
Also used : Embeddable1(org.apache.cayenne.testdo.embeddable.Embeddable1) DataRow(org.apache.cayenne.DataRow) EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 3 with EmbedEntity1

use of org.apache.cayenne.testdo.embeddable.EmbedEntity1 in project cayenne by apache.

the class EmbeddingSerializeIT method testSerializationEntityWithEmbeddableCommited.

@Test
public void testSerializationEntityWithEmbeddableCommited() throws Exception {
    createSelectDataSet();
    ObjectSelect<EmbedEntity1> query = ObjectSelect.query(EmbedEntity1.class);
    List<EmbedEntity1> results = query.select(context);
    assertEquals(1, results.size());
    EmbedEntity1 o1 = results.get(0);
    assertNotNull(o1);
    EmbedEntity1 o2 = Util.cloneViaSerialization(o1);
    assertNotNull(o2);
    assertEquals(o1.getPersistenceState(), PersistenceState.COMMITTED);
    assertEquals(o2.getPersistenceState(), PersistenceState.HOLLOW);
    assertEquals("e1", o1.getEmbedded1().getEmbedded10());
    assertEquals("e3", o1.getEmbedded2().getEmbedded10());
    assertNull(o2.getEmbedded1());
    assertNull(o2.getEmbedded2());
}
Also used : EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 4 with EmbedEntity1

use of org.apache.cayenne.testdo.embeddable.EmbedEntity1 in project cayenne by apache.

the class EmbeddingSerializeIT method testSerializationEmbeddable.

@Test
public void testSerializationEmbeddable() throws Exception {
    createSelectDataSet();
    ObjectSelect<EmbedEntity1> query = ObjectSelect.query(EmbedEntity1.class);
    List<EmbedEntity1> results = query.select(context);
    assertEquals(1, results.size());
    EmbedEntity1 o1 = results.get(0);
    assertNotNull(o1);
    Embeddable1 e1 = o1.getEmbedded1();
    Embeddable1 e2 = Util.cloneViaSerialization(e1);
    assertEquals(e1.getEmbedded10(), e2.getEmbedded10());
}
Also used : Embeddable1(org.apache.cayenne.testdo.embeddable.Embeddable1) EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 5 with EmbedEntity1

use of org.apache.cayenne.testdo.embeddable.EmbedEntity1 in project cayenne by apache.

the class EmbeddingSerializeIT method testSerializationEntityWithEmbeddableModified.

@Test
public void testSerializationEntityWithEmbeddableModified() throws Exception {
    createSelectDataSet();
    ObjectSelect<EmbedEntity1> query = ObjectSelect.query(EmbedEntity1.class);
    List<EmbedEntity1> results = query.select(context);
    assertEquals(1, results.size());
    EmbedEntity1 o1 = results.get(0);
    assertNotNull(o1);
    o1.setPersistenceState(PersistenceState.MODIFIED);
    EmbedEntity1 o2 = Util.cloneViaSerialization(o1);
    assertNotNull(o2);
    assertEquals(o1.getPersistenceState(), PersistenceState.MODIFIED);
    assertEquals(o2.getPersistenceState(), PersistenceState.MODIFIED);
    assertEquals("e1", o1.getEmbedded1().getEmbedded10());
    assertEquals("e1", o2.getEmbedded1().getEmbedded10());
    assertEquals("e3", o1.getEmbedded2().getEmbedded10());
    assertEquals("e3", o2.getEmbedded2().getEmbedded10());
}
Also used : EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Aggregations

EmbedEntity1 (org.apache.cayenne.testdo.embeddable.EmbedEntity1)8 Test (org.junit.Test)8 Embeddable1 (org.apache.cayenne.testdo.embeddable.Embeddable1)6 DataRow (org.apache.cayenne.DataRow)3