use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextIT method testBeforePropertyReadShouldInflateHollow.
@Test
public void testBeforePropertyReadShouldInflateHollow() {
ObjectId gid = new ObjectId("MtTable1", "a", "b");
final ClientMtTable1 inflated = new ClientMtTable1();
inflated.setPersistenceState(PersistenceState.COMMITTED);
inflated.setObjectId(gid);
inflated.setGlobalAttribute1("abc");
ClientConnection connection = mock(ClientConnection.class);
when(connection.sendMessage((ClientMessage) any())).thenAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
if (arg instanceof BootstrapMessage) {
return new EntityResolver();
} else {
return new GenericResponse(Arrays.asList(inflated));
}
}
});
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
// check that a HOLLOW object is infalted on "beforePropertyRead"
ClientMtTable1 hollow = new ClientMtTable1();
hollow.setPersistenceState(PersistenceState.HOLLOW);
hollow.setObjectId(gid);
final boolean[] selectExecuted = new boolean[1];
CayenneContext context = new CayenneContext(channel) {
@Override
public List<?> performQuery(Query query) {
selectExecuted[0] = true;
return super.performQuery(query);
}
};
context.setEntityResolver(serverContext.getEntityResolver().getClientEntityResolver());
context.graphManager.registerNode(hollow.getObjectId(), hollow);
// testing this...
context.prepareForAccess(hollow, ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, false);
assertTrue(selectExecuted[0]);
assertSame(hollow, context.getGraphManager().getNode(gid));
assertEquals(inflated.getGlobalAttribute1Direct(), hollow.getGlobalAttribute1Direct());
assertEquals(PersistenceState.COMMITTED, hollow.getPersistenceState());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 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.ClientMtTable1 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.ClientMtTable1 in project cayenne by apache.
the class CayenneContextRefreshQueryIT method testRefreshToMany.
@Test
public void testRefreshToMany() throws Exception {
createM1AndTwoM2sDataSet();
ClientMtTable1 a = Cayenne.objectForPK(context, ClientMtTable1.class, 1);
assertEquals(2, a.getTable2Array().size());
delete1M2DataSet();
RefreshQuery refresh = new RefreshQuery(a);
context.performGenericQuery(refresh);
assertEquals(PersistenceState.HOLLOW, a.getPersistenceState());
assertEquals(1, a.getTable2Array().size());
}
use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.
the class CayenneContextSQLTemplateIT method testObjectRoot.
@Test
public void testObjectRoot() throws Exception {
assertNull(Cayenne.objectForPK(context, ClientMtTable1.class, 1));
context.performGenericQuery(new SQLTemplate(ClientMtTable1.class, "insert into MT_TABLE1 " + "(TABLE1_ID, GLOBAL_ATTRIBUTE1, SERVER_ATTRIBUTE1) " + "values (1, 'g1', 's1')"));
assertNotNull(Cayenne.objectForPK(context, ClientMtTable1.class, 1));
}
Aggregations