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

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

Go to download

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

The newest version!
package org.simpleflatmapper.jdbc;

import org.simpleflatmapper.util.CheckedConsumer;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectedSelectQuery {

    private final SelectQuery delegate;
    private final TransactionTemplate txFactory;

    public ConnectedSelectQuery(SelectQuery delegate, TransactionTemplate txFactory) {
        this.delegate = delegate;
        this.txFactory = txFactory;
    }

    public T readFirst(final P p) throws SQLException {
        return txFactory.doInTransaction(
                new SQLFunction() {
                    @Override
                    public T apply(Connection connection) throws SQLException {
                        return delegate.readFirst(connection, p);
                    }
                }
        );
    }

    public > C read(final P p, final C consumer) throws SQLException {
        txFactory.doInTransaction(new SQLFunction() {
            @Override
            public Object apply(Connection connection) throws SQLException {
                delegate.read(connection, p, consumer);
                return null;
            }
        });
        return consumer;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy