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

com.github.davidmoten.rx.jdbc.ResultSetCache Maven / Gradle / Ivy

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);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy