use of org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1 in project cayenne by apache.
the class CayenneContextInheritanceIT method testInsertSubclass.
@Test
public void testInsertSubclass() throws Exception {
ClientMtTable1Subclass1 object = context.newObject(ClientMtTable1Subclass1.class);
object.setGlobalAttribute1("sub1");
object.setServerAttribute1("sa1");
object.setSubclass1Attribute1("suba1");
context.commitChanges();
assertEquals(1, tMtTable1.getRowCount());
assertEquals("sub1", tMtTable1.getString("GLOBAL_ATTRIBUTE1"));
assertEquals("sa1", tMtTable1.getString("SERVER_ATTRIBUTE1"));
assertEquals("suba1", tMtTable1.getString("SUBCLASS_ATTRIBUTE1"));
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1 in project cayenne by apache.
the class CayenneContextInheritanceIT method testPerformQueryInheritanceSuper.
@Test
public void testPerformQueryInheritanceSuper() throws Exception {
tMtTable1.insert(1, "a", "yyy", null);
tMtTable1.insert(2, "sub1", "zzz", "sa1");
tMtTable1.insert(3, "z", "aaa", null);
SelectQuery query = new SelectQuery(ClientMtTable1.class);
List<ClientMtTable1> objects = context.performQuery(query);
assertEquals(3, objects.size());
int checkedFields = 0;
for (int i = 0; i < objects.size(); i++) {
Integer id = (Integer) objects.get(i).getObjectId().getIdSnapshot().get("TABLE1_ID");
if (id == 1) {
assertEquals("a", objects.get(i).getGlobalAttribute1());
checkedFields++;
} else if (id == 2) {
assertEquals("sa1", ((ClientMtTable1Subclass1) objects.get(i)).getSubclass1Attribute1());
checkedFields++;
}
}
assertEquals(2, checkedFields);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1 in project cayenne by apache.
the class CayenneContextInheritanceIT method testPerformQueryInheritanceLeaf.
@Test
public void testPerformQueryInheritanceLeaf() throws Exception {
tMtTable1.insert(1, "xxx", "yyy", null);
tMtTable1.insert(2, "sub1", "zzz", "sa1");
tMtTable1.insert(3, "1111", "aaa", null);
SelectQuery query = new SelectQuery(ClientMtTable1Subclass1.class);
List<ClientMtTable1Subclass1> objects = context.performQuery(query);
assertEquals(1, objects.size());
assertEquals("sa1", objects.get(0).getSubclass1Attribute1());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1 in project cayenne by apache.
the class CayenneContextInheritanceIT method testPerformQueryWithQualifierInheritanceSuper.
@Test
public void testPerformQueryWithQualifierInheritanceSuper() throws Exception {
tMtTable1.insert(1, "a", "XX", null);
tMtTable1.insert(2, "sub1", "XXA", "sa1");
tMtTable1.insert(3, "z", "MM", null);
SelectQuery query = new SelectQuery(ClientMtTable1.class);
query.andQualifier(ExpressionFactory.likeExp(ClientMtTable1.SERVER_ATTRIBUTE1_PROPERTY, "X%"));
List<ClientMtTable1> objects = context.performQuery(query);
assertEquals(2, objects.size());
int checkedFields = 0;
for (int i = 0; i < objects.size(); i++) {
Integer id = (Integer) objects.get(i).getObjectId().getIdSnapshot().get("TABLE1_ID");
if (id == 1) {
assertEquals("a", objects.get(i).getGlobalAttribute1());
checkedFields++;
} else if (id == 2) {
assertEquals("sa1", ((ClientMtTable1Subclass1) objects.get(i)).getSubclass1Attribute1());
checkedFields++;
}
}
assertEquals(2, checkedFields);
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1Subclass1 in project cayenne by apache.
the class ClientServerChannelIT method testPerformQueryPropagationInheritance.
@Test
public void testPerformQueryPropagationInheritance() throws Exception {
tMtTable1.insert(65, "sub1", "xyz");
SelectQuery query = new SelectQuery(ClientMtTable1.class);
QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
Object result = results.get(0);
assertTrue("Result is of wrong type: " + result, result instanceof ClientMtTable1Subclass1);
ClientMtTable1Subclass1 clientObject = (ClientMtTable1Subclass1) result;
assertEquals("sub1", clientObject.getGlobalAttribute1());
}
Aggregations