Search in sources :

Example 31 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class EntityRowReader method readRow.

@Override
public DataRow readRow(ResultSet resultSet) {
    try {
        DataRow row = new DataRow(mapCapacity);
        int len = converters.length;
        for (int i = 0; i < len; i++) {
            // note: jdbc column indexes start from 1, not 0 as in arrays
            Object val = converters[i].materializeObject(resultSet, startIndex + i + 1, types[i]);
            row.put(labels[i], val);
        }
        postprocessRow(resultSet, row);
        return row;
    } catch (CayenneRuntimeException cex) {
        // rethrow unmodified
        throw cex;
    } catch (Exception otherex) {
        throw new CayenneRuntimeException("Exception materializing id column.", Util.unwindException(otherex));
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataRow(org.apache.cayenne.DataRow) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 32 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class IdRowReader method readIdMap.

@SuppressWarnings("unchecked")
private T readIdMap(ResultSet resultSet) throws Exception {
    DataRow idRow = new DataRow(2);
    idRow.setEntityName(entityName);
    for (int index : pkIndices) {
        // dereference column index
        // note: jdbc column indexes start from 1, not 0 as in arrays
        Object val = converters[index].materializeObject(resultSet, index + 1, types[index]);
        idRow.put(labels[index], val);
    }
    if (postProcessor != null) {
        postProcessor.postprocessRow(resultSet, idRow);
    }
    return (T) idRow;
}
Also used : DataRow(org.apache.cayenne.DataRow)

Example 33 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class EmbeddableRowReader method readRow.

@Override
public DataRow readRow(ResultSet resultSet) {
    try {
        DataRow row = new DataRow(mapCapacity);
        int len = converters.length;
        for (int i = 0; i < len; i++) {
            // note: jdbc column indexes start from 1, not 0 as in arrays
            Object val = converters[i].materializeObject(resultSet, startIndex + i + 1, types[i]);
            row.put(labels[i], val);
        }
        return row;
    } catch (CayenneRuntimeException cex) {
        // rethrow unmodified
        throw cex;
    } catch (Exception otherex) {
        throw new CayenneRuntimeException("Exception materializing column.", Util.unwindException(otherex));
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataRow(org.apache.cayenne.DataRow) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 34 with DataRow

use of org.apache.cayenne.DataRow in project cayenne by apache.

the class FullRowReader method readRow.

@Override
public DataRow readRow(ResultSet resultSet) {
    try {
        DataRow dataRow = new DataRow(mapCapacity);
        int resultWidth = labels.length;
        // process result row columns,
        for (int i = 0; i < resultWidth; i++) {
            // note: jdbc column indexes start from 1, not 0 unlike
            // everywhere else
            Object val = converters[i].materializeObject(resultSet, i + 1, types[i]);
            dataRow.put(labels[i], val);
        }
        postprocessRow(resultSet, dataRow);
        return dataRow;
    } catch (CayenneRuntimeException cex) {
        // rethrow unmodified
        throw cex;
    } catch (Exception otherex) {
        throw new CayenneRuntimeException("Exception materializing column.", Util.unwindException(otherex));
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataRow(org.apache.cayenne.DataRow) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 35 with DataRow

use of org.apache.cayenne.DataRow 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)

Aggregations

DataRow (org.apache.cayenne.DataRow)152 Test (org.junit.Test)113 Artist (org.apache.cayenne.testdo.testmap.Artist)31 ObjectId (org.apache.cayenne.ObjectId)25 DataObject (org.apache.cayenne.DataObject)20 ReturnTypesMap1 (org.apache.cayenne.testdo.return_types.ReturnTypesMap1)20 SQLTemplate (org.apache.cayenne.query.SQLTemplate)18 Date (java.util.Date)14 HashMap (java.util.HashMap)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)14 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 Persistent (org.apache.cayenne.Persistent)8 Painting (org.apache.cayenne.testdo.testmap.Painting)8 Connection (java.sql.Connection)6 Calendar (java.util.Calendar)5 Map (java.util.Map)5 QueryResponse (org.apache.cayenne.QueryResponse)5 DataMap (org.apache.cayenne.map.DataMap)5