Search in sources :

Example 1 with CharPkTestEntity

use of org.apache.cayenne.testdo.compound.CharPkTestEntity in project cayenne by apache.

the class DataContextPrefetchExtrasIT method testPrefetchToManyOnCharKey.

@Test
public void testPrefetchToManyOnCharKey() throws Exception {
    createPrefetchToManyOnCharKeyDataSet();
    SelectQuery q = new SelectQuery(CharPkTestEntity.class);
    q.addPrefetch("charFKs");
    q.addOrdering(CharPkTestEntity.OTHER_COL.asc());
    List<?> pks = context.performQuery(q);
    assertEquals(2, pks.size());
    CharPkTestEntity pk1 = (CharPkTestEntity) pks.get(0);
    assertEquals("n1", pk1.getOtherCol());
    List<?> toMany = (List<?>) pk1.readPropertyDirectly("charFKs");
    assertNotNull(toMany);
    assertFalse(((ValueHolder) toMany).isFault());
    assertEquals(3, toMany.size());
    CharFkTestEntity fk1 = (CharFkTestEntity) toMany.get(0);
    assertEquals(PersistenceState.COMMITTED, fk1.getPersistenceState());
    assertSame(pk1, fk1.getToCharPK());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) CharFkTestEntity(org.apache.cayenne.testdo.compound.CharFkTestEntity) CharPkTestEntity(org.apache.cayenne.testdo.compound.CharPkTestEntity) List(java.util.List) Test(org.junit.Test)

Example 2 with CharPkTestEntity

use of org.apache.cayenne.testdo.compound.CharPkTestEntity in project cayenne by apache.

the class DataContextCharPKIT method testDelete.

@Test
public void testDelete() throws Exception {
    CharPkTestEntity object = context.newObject(CharPkTestEntity.class);
    object.setOtherCol("object-XYZ");
    object.setPkCol("PK1");
    context.commitChanges();
    context.deleteObjects(object);
    context.commitChanges();
    SQLTemplate q = new SQLTemplate(CharPkTestEntity.class, "SELECT * FROM CHAR_PK_TEST");
    q.setFetchingDataRows(true);
    List<?> rows = context.performQuery(q);
    assertNotNull(rows);
    assertEquals(0, rows.size());
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) CharPkTestEntity(org.apache.cayenne.testdo.compound.CharPkTestEntity) Test(org.junit.Test)

Example 3 with CharPkTestEntity

use of org.apache.cayenne.testdo.compound.CharPkTestEntity in project cayenne by apache.

the class DataContextCharPKIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    CharPkTestEntity object = context.newObject(CharPkTestEntity.class);
    object.setOtherCol("object-XYZ");
    object.setPkCol("PK1");
    context.commitChanges();
    object.setOtherCol("UPDATED");
    context.commitChanges();
    SQLTemplate q = new SQLTemplate(CharPkTestEntity.class, "SELECT * FROM CHAR_PK_TEST");
    q.setFetchingDataRows(true);
    List<?> rows = context.performQuery(q);
    assertNotNull(rows);
    assertEquals(1, rows.size());
    DataRow row = (DataRow) rows.get(0);
    Object val = row.get("OTHER_COL");
    if (val == null) {
        val = row.get("other_col");
    }
    assertEquals("UPDATED", val);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) CharPkTestEntity(org.apache.cayenne.testdo.compound.CharPkTestEntity) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 4 with CharPkTestEntity

use of org.apache.cayenne.testdo.compound.CharPkTestEntity in project cayenne by apache.

the class DataContextCharPKIT method testInsert.

@Test
public void testInsert() throws Exception {
    CharPkTestEntity object = context.newObject(CharPkTestEntity.class);
    object.setOtherCol("object-XYZ");
    object.setPkCol("PK1");
    context.commitChanges();
    SQLTemplate q = new SQLTemplate(CharPkTestEntity.class, "SELECT * FROM CHAR_PK_TEST");
    q.setFetchingDataRows(true);
    List<?> rows = context.performQuery(q);
    assertNotNull(rows);
    assertEquals(1, rows.size());
    DataRow row = (DataRow) rows.get(0);
    Object val = row.get("OTHER_COL");
    if (val == null) {
        val = row.get("other_col");
    }
    assertEquals("object-XYZ", val);
    val = row.get("PK_COL");
    if (val == null) {
        val = row.get("pk_col");
    }
    assertEquals("PK1", val);
}
Also used : SQLTemplate(org.apache.cayenne.query.SQLTemplate) CharPkTestEntity(org.apache.cayenne.testdo.compound.CharPkTestEntity) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Aggregations

CharPkTestEntity (org.apache.cayenne.testdo.compound.CharPkTestEntity)4 Test (org.junit.Test)4 SQLTemplate (org.apache.cayenne.query.SQLTemplate)3 DataRow (org.apache.cayenne.DataRow)2 List (java.util.List)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 CharFkTestEntity (org.apache.cayenne.testdo.compound.CharFkTestEntity)1