org.onetwo.dbm.jdbc.SetRowMapperResultSetExtractor Maven / Gradle / Ivy
The newest version!
package org.onetwo.dbm.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;
public class SetRowMapperResultSetExtractor extends AbstractResultSetExtractor implements ResultSetExtractor>{
private final int rowsExpected;
public SetRowMapperResultSetExtractor(RowMapper rowMapper) {
this(rowMapper, 0);
}
public SetRowMapperResultSetExtractor(RowMapper rowMapper, int rowsExpected) {
super(rowMapper);
this.rowsExpected = rowsExpected;
}
public Set extractData(ResultSet rs) throws SQLException {
Set results = (this.rowsExpected > 0 ? new HashSet(this.rowsExpected) : new HashSet());
int rowNum = 0;
while (rs.next()) {
T row = this.rowMapper.mapRow(rs, rowNum++);
if(row!=null){
results.add(row);
}
}
return results;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy