Search in sources :

Example 1 with UseRowMapper

use of org.jdbi.v3.sqlobject.statement.UseRowMapper in project jdbi by jdbi.

the class SqlQueryHandler method configureReturner.

@Override
void configureReturner(Query q, SqlObjectStatementConfiguration cfg) {
    UseRowMapper useRowMapper = getMethod().getAnnotation(UseRowMapper.class);
    UseRowReducer useRowReducer = getMethod().getAnnotation(UseRowReducer.class);
    if (useRowReducer != null && useRowMapper != null) {
        throw new IllegalStateException("Cannot declare @UseRowMapper and @UseRowReducer on the same method.");
    }
    cfg.setReturner(() -> {
        StatementContext ctx = q.getContext();
        Type elementType = magic.elementType(ctx);
        if (useRowReducer != null) {
            return magic.reducedResult(q.reduceRows(rowReducerFor(useRowReducer)), ctx);
        }
        ResultIterable<?> iterable = useRowMapper == null ? q.mapTo(elementType) : q.map(rowMapperFor(useRowMapper));
        return magic.mappedResult(iterable, ctx);
    });
}
Also used : UseRowMapper(org.jdbi.v3.sqlobject.statement.UseRowMapper) Type(java.lang.reflect.Type) UseRowReducer(org.jdbi.v3.sqlobject.statement.UseRowReducer) StatementContext(org.jdbi.v3.core.statement.StatementContext)

Aggregations

Type (java.lang.reflect.Type)1 StatementContext (org.jdbi.v3.core.statement.StatementContext)1 UseRowMapper (org.jdbi.v3.sqlobject.statement.UseRowMapper)1 UseRowReducer (org.jdbi.v3.sqlobject.statement.UseRowReducer)1