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

org.simpleflatmapper.jdbc.spring.RowMapperImpl Maven / Gradle / Ivy

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

import org.simpleflatmapper.jdbc.JdbcMapper;
import org.simpleflatmapper.jdbc.JdbcMapperFactory;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Provide integration point with Spring JdbcTemplate.
 * 

* It implements {@link RowMapper}, {@link PreparedStatementCallback} and {@link ResultSetExtractor}. * Because some JdbcTemplate template signature match against a few of those type you might need to downcast, declare the variable with a specific type or use the type specific method in {@link JdbcTemplateMapperFactory}. * *

* * * class MyDao {
*     private final JdbcTemplateMapper<DbObject> jdbcMapper =
*         JdbcTemplateMapperFactory.newInstance().newMapper(DbObject.class);
*     private final RowMapper<DbObject> rowMapper = jdbcMapper;
*
*     public void doSomething() {
*         List<DbObject> results = template.query(DbHelper.TEST_DB_OBJECT_QUERY, rowMapper);
*     }
*
*     public void doSomethingElse() {
*         template
*             .query(TEST_DB_OBJECT_QUERY,
*             jdbcMapper.newResultSetExtractor((o) -> System.out.println(o.toString())));
*     }
* }
*
* * @param the mapped type * @see JdbcMapperFactory * @see JdbcMapper * @see JdbcTemplateMapperFactory#newPreparedStatementCallback(Class) * @see JdbcTemplateMapperFactory#newResultSetExtractor(Class) * @see JdbcTemplateMapperFactory#newRowMapper(Class) * */ public final class RowMapperImpl implements RowMapper { private final JdbcMapper mapper; public RowMapperImpl(JdbcMapper mapper) { this.mapper = mapper; } @Override public T mapRow(ResultSet rs, int rowNum) throws SQLException { return mapper.map(rs); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy