use of org.apache.cayenne.query.MockQueryMetadata in project cayenne by apache.
the class JDBCResultIteratorTest method testNextDataRow.
@Test
public void testNextDataRow() throws Exception {
Connection c = new MockConnection();
Statement s = new MockStatement(c);
MockResultSet rs = new MockResultSet("rs");
rs.addColumn("a", new Object[] { "1", "2", "3" });
RowDescriptor descriptor = new RowDescriptorBuilder().setResultSet(rs).getDescriptor(new ExtendedTypeMap());
RowReader<?> rowReader = new DefaultRowReaderFactory().rowReader(descriptor, new MockQueryMetadata(), mock(DbAdapter.class), Collections.<ObjAttribute, ColumnDescriptor>emptyMap());
JDBCResultIterator it = new JDBCResultIterator(s, rs, rowReader);
DataRow row = (DataRow) it.nextRow();
assertNotNull(row);
assertEquals(1, row.size());
assertEquals("1", row.get("a"));
}
use of org.apache.cayenne.query.MockQueryMetadata in project cayenne by apache.
the class PrefetchProcessorTreeBuilderIT method testBuildTreeWithPrefetches.
@Test
public void testBuildTreeWithPrefetches() {
final ClassDescriptor descriptor = resolver.getClassDescriptor("Artist");
ObjEntity e2 = resolver.getObjEntity("Painting");
ObjEntity e3 = resolver.getObjEntity("Gallery");
ObjEntity e4 = resolver.getObjEntity("Exhibit");
ObjEntity e5 = resolver.getObjEntity("ArtistExhibit");
List<Object> mainRows = new ArrayList<Object>();
Map<Object, Object> extraRows = new HashMap<Object, Object>();
PrefetchTreeNode tree = new PrefetchTreeNode();
tree.addPath(Artist.PAINTING_ARRAY.getName()).setPhantom(false);
tree.addPath(Artist.PAINTING_ARRAY.dot(Painting.TO_GALLERY).dot(Gallery.EXHIBIT_ARRAY).getName()).setPhantom(false);
tree.addPath(Artist.ARTIST_EXHIBIT_ARRAY.getName()).setPhantom(false);
QueryMetadata metadata = new MockQueryMetadata() {
@Override
public ClassDescriptor getClassDescriptor() {
return descriptor;
}
@Override
public ObjEntity getObjEntity() {
return descriptor.getEntity();
}
@Override
public DbEntity getDbEntity() {
return getObjEntity().getDbEntity();
}
@Override
public DataMap getDataMap() {
return getObjEntity().getDataMap();
}
@Override
public boolean isRefreshingObjects() {
return true;
}
@Override
public boolean isResolvingInherited() {
return true;
}
};
HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(context, metadata);
PrefetchProcessorTreeBuilder builder = new PrefetchProcessorTreeBuilder(resolver, mainRows, extraRows);
PrefetchProcessorNode n1 = builder.buildTree(tree);
assertSame(mainRows, n1.getDataRows());
assertSame(descriptor.getEntity(), n1.getResolver().getEntity());
PrefetchProcessorNode n2 = (PrefetchProcessorNode) n1.getNode("paintingArray");
assertNotNull(n2);
assertSame(e2, n2.getResolver().getEntity());
assertFalse(n2.isPhantom());
assertTrue(n2.isPartitionedByParent());
PrefetchProcessorNode n3 = (PrefetchProcessorNode) n1.getNode("paintingArray.toGallery");
assertNotNull(n3);
assertSame(e3, n3.getResolver().getEntity());
assertTrue(n3.isPhantom());
assertTrue(n3.isPartitionedByParent());
PrefetchProcessorNode n4 = (PrefetchProcessorNode) n1.getNode("paintingArray.toGallery.exhibitArray");
assertNotNull(n4);
assertSame(e4, n4.getResolver().getEntity());
assertFalse(n4.isPhantom());
assertTrue(n4.isPartitionedByParent());
PrefetchProcessorNode n5 = (PrefetchProcessorNode) n1.getNode("artistExhibitArray");
assertNotNull(n5);
assertSame(e5, n5.getResolver().getEntity());
assertFalse(n5.isPhantom());
assertTrue(n5.isPartitionedByParent());
}
use of org.apache.cayenne.query.MockQueryMetadata in project cayenne by apache.
the class MapQueryCacheTest method testSerializability.
@Test
public void testSerializability() throws Exception {
MapQueryCache cache = new MapQueryCache(5);
cache.put(new MockQueryMetadata() {
@Override
public String getCacheKey() {
return "key";
}
}, new ArrayList<Object>());
assertEquals(1, cache.size());
MapQueryCache deserialized = (MapQueryCache) Util.cloneViaSerialization(cache);
assertNotNull(deserialized);
assertEquals(1, deserialized.size());
}
use of org.apache.cayenne.query.MockQueryMetadata in project cayenne by apache.
the class PrefetchProcessorTreeBuilderIT method testBuildTreeNoPrefetches.
@Test
public void testBuildTreeNoPrefetches() {
final ClassDescriptor descriptor = resolver.getClassDescriptor("Artist");
List<Object> dataRows = new ArrayList<Object>();
dataRows.add(new DataRow(4));
dataRows.add(new DataRow(4));
QueryMetadata metadata = new MockQueryMetadata() {
@Override
public ClassDescriptor getClassDescriptor() {
return descriptor;
}
@Override
public ObjEntity getObjEntity() {
return descriptor.getEntity();
}
@Override
public DbEntity getDbEntity() {
return getObjEntity().getDbEntity();
}
@Override
public DataMap getDataMap() {
return getObjEntity().getDataMap();
}
@Override
public boolean isRefreshingObjects() {
return true;
}
@Override
public boolean isResolvingInherited() {
return true;
}
};
PrefetchTreeNode tree = new PrefetchTreeNode();
HierarchicalObjectResolver resolver = new HierarchicalObjectResolver(context, metadata);
PrefetchProcessorTreeBuilder builder = new PrefetchProcessorTreeBuilder(resolver, dataRows, new HashMap<Object, Object>());
PrefetchProcessorNode processingTree = builder.buildTree(tree);
assertTrue(processingTree.getChildren().isEmpty());
assertFalse(processingTree.isPhantom());
assertFalse(processingTree.isPartitionedByParent());
assertTrue(processingTree.isDisjointPrefetch());
assertSame(dataRows, processingTree.getDataRows());
assertSame(descriptor.getEntity(), processingTree.getResolver().getEntity());
assertNull(processingTree.getIncoming());
}
Aggregations