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

cool.scx.jdbc.result_handler.MapListHandler Maven / Gradle / Ivy

There is a newer version: 2.7.4
Show newest version
package cool.scx.jdbc.result_handler;

import cool.scx.jdbc.dialect.Dialect;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

/**
 * a
 *
 * @author scx567888
 * @version 0.0.1
 */
record MapListHandler(Supplier> mapSupplier) implements ResultHandler>> {

    static final MapListHandler INSTANCE = new MapListHandler();

    public MapListHandler() {
        this(HashMap::new);
    }

    /**
     * {@inheritDoc}
     * 

* a */ @Override public List> apply(ResultSet rs, Dialect dialect) throws SQLException { var list = new ArrayList>(); var rsm = rs.getMetaData(); var count = rsm.getColumnCount(); while (rs.next()) { var map = mapSupplier.get(); for (int i = 1; i <= count; i = i + 1) { map.put(rsm.getColumnLabel(i), rs.getObject(i)); } list.add(map); } return list; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy