View Javadoc
1   package com.github.davidmoten.rx.jdbc;
2   
3   import java.sql.ResultSet;
4   import java.sql.ResultSetMetaData;
5   import java.sql.SQLException;
6   import java.util.HashMap;
7   import java.util.Map;
8   
9   import com.github.davidmoten.rx.jdbc.exceptions.SQLRuntimeException;
10  
11  class ResultSetCache {
12  
13      final ResultSet rs;
14      final Map<String, Integer> colIndexes;
15      
16      ResultSetCache(ResultSet rs) {
17          this.rs = rs;
18          
19          this.colIndexes = collectColIndexes(rs);
20      }
21  
22      private static Map<String, Integer> collectColIndexes(ResultSet rs) {
23          HashMap<String, Integer> map = new HashMap<String, Integer>();
24          try {
25              ResultSetMetaData metadata = rs.getMetaData();
26              for (int i=1;i<=metadata.getColumnCount();i++) {
27                  map.put(metadata.getColumnName(i),i);
28              }
29              return map;
30          } catch (SQLException e) {
31              throw new SQLRuntimeException(e);
32          }
33      }
34  
35  }