Search in sources :

Example 1 with MockQueryMetadata

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"));
}
Also used : MockStatement(com.mockrunner.mock.jdbc.MockStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) MockConnection(com.mockrunner.mock.jdbc.MockConnection) MockResultSet(com.mockrunner.mock.jdbc.MockResultSet) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DataRow(org.apache.cayenne.DataRow) ExtendedTypeMap(org.apache.cayenne.access.types.ExtendedTypeMap) DefaultRowReaderFactory(org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory) MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) DbAdapter(org.apache.cayenne.dba.DbAdapter) MockStatement(com.mockrunner.mock.jdbc.MockStatement) Test(org.junit.Test)

Example 2 with MockQueryMetadata

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());
}
Also used : MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) QueryMetadata(org.apache.cayenne.query.QueryMetadata) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjEntity(org.apache.cayenne.map.ObjEntity) MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) PrefetchTreeNode(org.apache.cayenne.query.PrefetchTreeNode) Test(org.junit.Test)

Example 3 with MockQueryMetadata

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());
}
Also used : MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) Test(org.junit.Test)

Example 4 with MockQueryMetadata

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());
}
Also used : MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) QueryMetadata(org.apache.cayenne.query.QueryMetadata) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) MockQueryMetadata(org.apache.cayenne.query.MockQueryMetadata) PrefetchTreeNode(org.apache.cayenne.query.PrefetchTreeNode) ArrayList(java.util.ArrayList) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Aggregations

MockQueryMetadata (org.apache.cayenne.query.MockQueryMetadata)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 DataRow (org.apache.cayenne.DataRow)2 PrefetchTreeNode (org.apache.cayenne.query.PrefetchTreeNode)2 QueryMetadata (org.apache.cayenne.query.QueryMetadata)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2 MockConnection (com.mockrunner.mock.jdbc.MockConnection)1 MockResultSet (com.mockrunner.mock.jdbc.MockResultSet)1 MockStatement (com.mockrunner.mock.jdbc.MockStatement)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 DefaultRowReaderFactory (org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory)1 ExtendedTypeMap (org.apache.cayenne.access.types.ExtendedTypeMap)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1