Search in sources :

Example 1 with RosettaMapper

use of com.hubspot.rosetta.RosettaMapper in project Rosetta by HubSpot.

the class RosettaMapperFactory method mapperFor.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public ResultSetMapper mapperFor(Class rawType, StatementContext ctx) {
    ObjectMapper objectMapper = RosettaObjectMapperOverride.resolve(ctx);
    final Type genericType;
    if (ctx.getSqlObjectMethod() == null) {
        genericType = rawType;
    } else {
        genericType = determineGenericReturnType(rawType, ctx.getSqlObjectMethod().getGenericReturnType());
    }
    final RosettaMapper mapper = new RosettaMapper(genericType, objectMapper, extractTableName(ctx.getRewrittenSql()));
    return new ResultSetMapper() {

        @Override
        public Object map(int index, ResultSet r, StatementContext ctx) throws SQLException {
            return mapper.mapRow(r);
        }
    };
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ResultSetMapper(org.skife.jdbi.v2.tweak.ResultSetMapper) ResultSet(java.sql.ResultSet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RosettaMapper(com.hubspot.rosetta.RosettaMapper) StatementContext(org.skife.jdbi.v2.StatementContext)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RosettaMapper (com.hubspot.rosetta.RosettaMapper)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ResultSet (java.sql.ResultSet)1 StatementContext (org.skife.jdbi.v2.StatementContext)1 ResultSetMapper (org.skife.jdbi.v2.tweak.ResultSetMapper)1