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());
}
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());
}
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);
}
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);
}
Aggregations