All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.jdbi.DynamicSfmResultSetMapper Maven / Gradle / Ivy

There is a newer version: 8.2.3
Show newest version
package org.simpleflatmapper.jdbi;

import org.simpleflatmapper.jdbc.DynamicJdbcMapper;
import org.simpleflatmapper.jdbc.JdbcMapper;
import org.simpleflatmapper.map.SourceMapper;
import org.skife.jdbi.v2.StatementContext;
import org.skife.jdbi.v2.tweak.ResultSetMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class DynamicSfmResultSetMapper implements ResultSetMapper {

    private static final String STATEMENT_MAPPER = DynamicSfmResultSetMapper.class.getName() + ".dynamicMapper";
    private final DynamicJdbcMapper dynamicMapper;

    public DynamicSfmResultSetMapper(DynamicJdbcMapper dynamicMapper) {
        this.dynamicMapper = dynamicMapper;
    }

    @SuppressWarnings("unchecked")
    @Override
    public T map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException {
        JdbcMapper mapper = (JdbcMapper) statementContext.getAttribute(STATEMENT_MAPPER);

        if (mapper == null) {
            mapper = dynamicMapper.getMapper(resultSet.getMetaData());
            statementContext.setAttribute(STATEMENT_MAPPER, mapper);
        }

        return mapper.map(resultSet, mapper.newMappingContext(resultSet));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy