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

org.simpleflatmapper.jdbc.spring.PreparedStatementCallbackImpl 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.util.CheckedConsumer;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.ResultSetExtractor;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;


public final class PreparedStatementCallbackImpl implements PreparedStatementCallback> {
	private final ResultSetExtractorImpl resultSetExtractor;

	public PreparedStatementCallbackImpl(JdbcMapper mapper) {
		this.resultSetExtractor = new ResultSetExtractorImpl(mapper);
	}

	@Override
	public List doInPreparedStatement(PreparedStatement ps) throws SQLException,
			DataAccessException {
		ResultSet rs = ps.executeQuery();
		try {
			return resultSetExtractor.extractData(rs);
		} finally {
			rs.close();
		}
	}


	public > PreparedStatementCallback newPreparedStatementCallback(final H handler) {
		return new PreparedStatementCallback() {
			@Override
			public H doInPreparedStatement(
					PreparedStatement ps)
					throws SQLException, DataAccessException {
				ResultSet rs = ps.executeQuery();
				ResultSetExtractor extractor = resultSetExtractor.newResultSetExtractor(handler);
				try {
					return extractor.extractData(rs);
				} finally {
					rs.close();
				}
			}
		};
	}



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy