org.simpleflatmapper.jdbc.ConnectedSelectQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-jdbc Show documentation
Show all versions of sfm-jdbc Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
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;
}
}