com.github.davidmoten.rx.jdbc.ResultSetCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxjava-jdbc Show documentation
Show all versions of rxjava-jdbc Show documentation
rx-java Observables for jdbc
The newest version!
package com.github.davidmoten.rx.jdbc;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import com.github.davidmoten.rx.jdbc.exceptions.SQLRuntimeException;
class ResultSetCache {
final ResultSet rs;
final Map colIndexes;
ResultSetCache(ResultSet rs) {
this.rs = rs;
this.colIndexes = collectColIndexes(rs);
}
private static Map collectColIndexes(ResultSet rs) {
HashMap map = new HashMap();
try {
ResultSetMetaData metadata = rs.getMetaData();
for (int i = 1; i <= metadata.getColumnCount(); i++) {
map.put(metadata.getColumnLabel(i).toUpperCase(), i);
}
return map;
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
}
}