Search in sources :

Example 1 with Embeddable1

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

the class EmbeddingIT method testUpdateEmbeddedProperties.

@Test
public void testUpdateEmbeddedProperties() throws Exception {
    createUpdateDataSet();
    SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
    query.addOrdering(EmbedEntity1.NAME.asc());
    List<?> results = context.performQuery(query);
    EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
    Embeddable1 e11 = o1.getEmbedded1();
    e11.setEmbedded10("x1");
    assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
    context.commitChanges();
    SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class);
    DataRow row = (DataRow) Cayenne.objectForQuery(context, query1);
    assertNotNull(row);
    assertEquals("x1", row.get("EMBEDDED10"));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) 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 Embeddable1

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

the class EmbeddingIT method testUpdateEmbedded.

@Test
public void testUpdateEmbedded() throws Exception {
    createUpdateDataSet();
    SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
    query.addOrdering(EmbedEntity1.NAME.asc());
    List<?> results = context.performQuery(query);
    EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
    Embeddable1 e11 = new Embeddable1();
    e11.setEmbedded10("x1");
    e11.setEmbedded20("x2");
    o1.setEmbedded1(e11);
    assertEquals(PersistenceState.MODIFIED, o1.getPersistenceState());
    context.commitChanges();
    SelectQuery<DataRow> query1 = SelectQuery.dataRowQuery(EmbedEntity1.class);
    DataRow row = query1.selectOne(context);
    assertNotNull(row);
    assertEquals("x1", row.get("EMBEDDED10"));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) 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 Embeddable1

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

the class EmbeddingIT method testSelect.

@Test
public void testSelect() throws Exception {
    createSelectDataSet();
    SelectQuery query = new SelectQuery<>(EmbedEntity1.class);
    query.addOrdering(EmbedEntity1.NAME.asc());
    List<?> results = context.performQuery(query);
    assertEquals(2, results.size());
    EmbedEntity1 o1 = (EmbedEntity1) results.get(0);
    assertEquals("n1", o1.getName());
    Embeddable1 e11 = o1.getEmbedded1();
    Embeddable1 e12 = o1.getEmbedded2();
    assertNotNull(e11);
    assertNotNull(e12);
    assertEquals("e1", e11.getEmbedded10());
    assertEquals("e2", e11.getEmbedded20());
    assertEquals("e3", e12.getEmbedded10());
    assertEquals("e4", e12.getEmbedded20());
    EmbedEntity1 o2 = (EmbedEntity1) results.get(1);
    assertEquals("n2", o2.getName());
    Embeddable1 e21 = o2.getEmbedded1();
    Embeddable1 e22 = o2.getEmbedded2();
    assertNotNull(e21);
    assertNotNull(e22);
    assertEquals("ex1", e21.getEmbedded10());
    assertEquals("ex2", e21.getEmbedded20());
    assertEquals("ex3", e22.getEmbedded10());
    assertEquals("ex4", e22.getEmbedded20());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Embeddable1(org.apache.cayenne.testdo.embeddable.Embeddable1) EmbedEntity1(org.apache.cayenne.testdo.embeddable.EmbedEntity1) Test(org.junit.Test)

Example 4 with Embeddable1

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

the class EmbeddingIT method testInsert.

@Test
public void testInsert() throws Exception {
    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();
    SelectQuery<DataRow> query = SelectQuery.dataRowQuery(EmbedEntity1.class);
    DataRow row = query.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)4 Embeddable1 (org.apache.cayenne.testdo.embeddable.Embeddable1)4 Test (org.junit.Test)4 DataRow (org.apache.cayenne.DataRow)3 SelectQuery (org.apache.cayenne.query.SelectQuery)3