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

com.bixuebihui.jdbc.RowMapperResultReaderToMap Maven / Gradle / Ivy

Go to download

a fast small database connection pool and a active record flavor mini framework

There is a newer version: 1.15.3.3
Show newest version
package com.bixuebihui.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * 

RowMapperResultReaderToMap class.

* * @author xingwx * @version $Id: $Id */ public class RowMapperResultReaderToMap { private final RowMapper handle; private final String keyName; private Map res; /** *

Constructor for RowMapperResultReaderToMap.

* * @param handle a {@link RowMapper} object. * @param keyName a {@link java.lang.String} object. */ public RowMapperResultReaderToMap(RowMapper handle, String keyName){ this.handle = handle; this.keyName = keyName; } /** *

Constructor for RowMapperResultReaderToMap.

* * @param handle a {@link RowMapper} object. * @param keyName a {@link java.lang.String} object. * @param resultMap a {@link java.util.Map} object. */ public RowMapperResultReaderToMap(RowMapper handle, String keyName, Map resultMap){ this.handle = handle; this.keyName= keyName; this.res = resultMap; } /** *

processResultSet.

* * @param rs a {@link java.sql.ResultSet} object. * @return a {@link java.util.Map} object. * @throws java.sql.SQLException if any. */ @SuppressWarnings("unchecked") public Map processResultSet(ResultSet rs) throws SQLException { if(res ==null) { res = new HashMap<>(); }else{ res.clear(); } int index=1; while (rs.next()) { res.put((K)rs.getObject(keyName), handle.mapRow(rs, index++, null)); } return res; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy