* Tests that lazy loads don't cause heterogeneous joins.
*/
public void testLazyRelationalJoiningRelational()
{
Metaclass clazz = getMetadata().getMetaclass("ExternalVisit");
ReadCountHook readHook = (ReadCountHook)((SQLAdapter)getMetadata().getDataSource("DefaultRelationalDatabase").getComponent().getInstance(m_context)).getSQLHook();
ReadCountHook extHook = (ReadCountHook)((SQLAdapter)getMetadata().getDataSource("ExternalRelationalDatabase").getComponent().getInstance(m_context)).getSQLHook();
InstanceArrayList list;
Instance inst;
int nStartReadCount = readHook.getReadCount();
int nExtReadCount = extHook.getReadCount();
list = (InstanceArrayList)Query.createRead(clazz,
parse("(version startDate endDate)"),
null,
null,
-1, 0, false, Query.SEC_NODE, m_context).read();
assertEquals(6, list.getCount());
inst = list.getInstance(0);
assertEquals(nStartReadCount, readHook.getReadCount());
assertEquals(nExtReadCount + 1, extHook.getReadCount());
nExtReadCount = extHook.getReadCount();
// This causes a lazy load of ExternalVisit, and will instantiate a lazy Patient instance
assertEquals("Broken foot", inst.getValue("reason"));
assertEquals(nExtReadCount + 1, extHook.getReadCount());
assertEquals(nStartReadCount, readHook.getReadCount());
inst = (Instance)inst.getValue("patient");
assertEquals(nStartReadCount, readHook.getReadCount());
// This will cause the read of Patient
assertEquals("Sarah", inst.getValue("firstName"));
assertEquals("Johnson", inst.getValue("lastName"));
assertEquals(nStartReadCount + 1, readHook.getReadCount());
assertEquals(nExtReadCount + 1, extHook.getReadCount());
}