Search in sources :

Example 11 with Mappers

use of org.jdbi.v3.core.mapper.Mappers in project jdbi by jdbi.

the class JoinRowMapper method specialize.

@Override
public RowMapper<JoinRow> specialize(ResultSet r, StatementContext ctx) throws SQLException {
    RowMapper<?>[] mappers = new RowMapper[types.length];
    for (int i = 0; i < types.length; i++) {
        Type type = types[i];
        mappers[i] = ctx.findRowMapperFor(type).orElseThrow(() -> new IllegalArgumentException("No row mapper registered for " + type)).specialize(r, ctx);
    }
    return (rs, context) -> {
        final Map<Type, Object> entries = new HashMap<>(types.length);
        for (int i = 0; i < types.length; i++) {
            Type type = types[i];
            RowMapper<?> mapper = mappers[i];
            entries.put(type, mapper.map(r, ctx));
        }
        return new JoinRow(entries);
    };
}
Also used : SQLException(java.sql.SQLException) Arrays(java.util.Arrays) Type(java.lang.reflect.Type) ResultSet(java.sql.ResultSet) Map(java.util.Map) HashMap(java.util.HashMap) StatementContext(org.jdbi.v3.core.statement.StatementContext) Type(java.lang.reflect.Type) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 Map (java.util.Map)5 StatementContext (org.jdbi.v3.core.statement.StatementContext)5 Type (java.lang.reflect.Type)4 RowMappers (org.jdbi.v3.core.mapper.RowMappers)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ColumnMapper (org.jdbi.v3.core.mapper.ColumnMapper)3 ColumnMappers (org.jdbi.v3.core.mapper.ColumnMappers)3 Nested (org.jdbi.v3.core.mapper.Nested)3 RowMapper (org.jdbi.v3.core.mapper.RowMapper)3 RowMapperFactory (org.jdbi.v3.core.mapper.RowMapperFactory)3 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)2 Jdbi (org.jdbi.v3.core.Jdbi)2 SingleColumnMapper (org.jdbi.v3.core.mapper.SingleColumnMapper)2