use of org.apache.cayenne.access.types.ExtendedTypeMap 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.access.types.ExtendedTypeMap in project cayenne by apache.
the class SQLTemplateAction method processSelectResult.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void processSelectResult(SQLStatement compiled, Connection connection, Statement statement, ResultSet resultSet, OperationObserver callback, final long startTime) throws Exception {
boolean iteratedResult = callback.isIteratedResult();
ExtendedTypeMap types = dataNode.getAdapter().getExtendedTypes();
RowDescriptorBuilder builder = configureRowDescriptorBuilder(compiled, resultSet);
RowReader<?> rowReader = dataNode.rowReader(builder.getDescriptor(types), queryMetadata);
ResultIterator it = new JDBCResultIterator(statement, resultSet, rowReader);
if (iteratedResult) {
it = new ConnectionAwareResultIterator(it, connection) {
@Override
protected void doClose() {
dataNode.getJdbcEventLogger().logSelectCount(rowCounter, System.currentTimeMillis() - startTime);
super.doClose();
}
};
}
it = new LimitResultIterator(it, getFetchOffset(), query.getFetchLimit());
if (iteratedResult) {
try {
callback.nextRows(query, it);
} catch (Exception ex) {
it.close();
throw ex;
}
} else {
// note that we are not closing the iterator here, relying on caller
// to close the underlying ResultSet on its own... this is a hack,
// maybe a cleaner flow is due here.
List<DataRow> resultRows = (List<DataRow>) it.allRows();
dataNode.getJdbcEventLogger().logSelectCount(resultRows.size(), System.currentTimeMillis() - startTime);
callback.nextRows(query, resultRows);
}
}
Aggregations