
de.zalando.sprocwrapper.proxy.executors.SingleRowCustomMapperExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zalando-sprocwrapper Show documentation
Show all versions of zalando-sprocwrapper Show documentation
Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces
including automatic object serialization and deserialization (using typemapper and
convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types
such as enums and hstore.
package de.zalando.sprocwrapper.proxy.executors;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import de.zalando.sprocwrapper.proxy.InvocationContext;
/**
* @author hjacobs
*/
public class SingleRowCustomMapperExecutor implements Executor {
private final RowMapper> resultMapper;
public SingleRowCustomMapperExecutor(final RowMapper> resultMapper) {
this.resultMapper = resultMapper;
}
@Override
public Object executeSProc(final DataSource ds, final String sql, final Object[] args, final int[] types,
final InvocationContext invocationContext, final Class> returnType) {
final List> list = (new JdbcTemplate(ds)).query(sql, args, types, resultMapper);
if (!list.isEmpty()) {
return list.iterator().next();
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy