org.simpleflatmapper.jdbi.DynamicSfmResultSetMapper Maven / Gradle / Ivy
package org.simpleflatmapper.jdbi;
import org.simpleflatmapper.jdbc.DynamicJdbcMapper;
import org.simpleflatmapper.map.Mapper;
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 {
Mapper mapper = (Mapper) statementContext.getAttribute(STATEMENT_MAPPER);
if (mapper == null) {
mapper = dynamicMapper.getMapper(resultSet.getMetaData());
statementContext.setAttribute(STATEMENT_MAPPER, mapper);
}
return mapper.map(resultSet);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy