Search in sources :

Example 6 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 7 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)

Example 8 with EmbedEntity1

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

the class EmbeddingIT method testInsert.

@Test
public void testInsert() {
    EmbedEntity1 o1 = context.newObject(EmbedEntity1.class);
    o1.setName("NAME");
    Embeddable1 e1 = new Embeddable1();
    // init before the embeddable was set on an owning object
    e1.setEmbedded10("E11");
    e1.setEmbedded20("E12");
    o1.setEmbedded1(e1);
    Embeddable1 e2 = new Embeddable1();
    o1.setEmbedded2(e2);
    // init after it was set on the owning object
    e2.setEmbedded10("E21");
    e2.setEmbedded20("E22");
    context.commitChanges();
    DataRow row = ObjectSelect.dataRowQuery(EmbedEntity1.class).selectOne(context);
    assertNotNull(row);
    assertEquals("E11", row.get("EMBEDDED10"));
    assertEquals("E12", row.get("EMBEDDED20"));
    assertEquals("E21", row.get("EMBEDDED30"));
    assertEquals("E22", row.get("EMBEDDED40"));
}
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)

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