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

org.simpleflatmapper.jdbc.JdbcMapper Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.jdbc;

import org.simpleflatmapper.map.MappingException;
import org.simpleflatmapper.map.SetRowMapper;
import org.simpleflatmapper.map.context.MappingContextFactoryFromRows;
import org.simpleflatmapper.util.CheckedConsumer;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
//IFJAVA8_START
import java.util.stream.Stream;
//IFJAVA8_END


/**
 * JdbcMapper will map from a {@link java.sql.ResultSet} to an object of the specified type T
 * 

* JdbcMapper are instantiable via {@link JdbcMapperFactory}. *

* * JdbcMapper<MyClass> jdbcMapper = JdbcMapperFactory.newInstance().newMapper(MyClass.class);
*
* ...
*
* try (ResultSet rs : ps.executeQuery()){
*     jdbcMapper.stream(rs).forEach(System.out::println);
* }
*
* * @param the type that the jdbcMapper is mapping to * @see JdbcMapperFactory */ public interface JdbcMapper extends SetRowMapper, MappingContextFactoryFromRows { /** * map the current row of the ResultSet to a new newInstance of T. * This method does not manage the iteration of the ResultSet and will only map the current row. No join aggregation will be performed. * @param rs the resultSet * @return a new mapped newInstance of T * @throws MappingException if an exception occurs */ T map(ResultSet rs) throws MappingException; /** * Loop over the resultSet, map each row to a new newInstance of T and call back the handler. *

* The method will return the handler passed as an argument so you can easily chain the calls like
* * List<T> list = jdbcMapper.forEach(rs, new ListHandler<T>()).getList(); * *
* * @param rs the resultSet * @param handler the handler that will get the callback * @param the row handler type * @return the handler passed in * @throws SQLException if sql error occurs * @throws MappingException if an error occurs during the mapping * */ > H forEach(final ResultSet rs, final H handler) throws SQLException, MappingException; /** * * @param rs the result set * @return an iterator that will return a map object for each row of the result set. * @throws SQLException if sql error occurs * @throws MappingException if an error occurs during the mapping */ Iterator iterator(ResultSet rs) throws SQLException, MappingException; /** * * @param rs the result set * @return a stream that will contain a map object for each row of the result set. * @throws SQLException if sql error occurs * @throws MappingException if an error occurs during the mapping */ //IFJAVA8_START Stream stream(ResultSet rs) throws SQLException, MappingException; //IFJAVA8_END }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy