use of org.postgresql.largeobject.LargeObject in project syndesis by syndesisio.
the class SqlFileStore method doReadPostgres.
/**
* Postgres does not allow to read from the large object after the connection has been closed.
*/
private InputStream doReadPostgres(String path) {
Handle h = dbi.open();
try {
h.getConnection().setAutoCommit(false);
List<Map<String, Object>> res = h.select("SELECT data FROM filestore WHERE path=?", path);
Optional<Long> oid = res.stream().map(row -> row.get("data")).map(Long.class::cast).findFirst();
if (oid.isPresent()) {
LargeObjectManager lobj = getPostgresConnection(h.getConnection()).getLargeObjectAPI();
LargeObject obj = lobj.open(oid.get(), LargeObjectManager.READ);
return new HandleCloserInputStream(h, obj.getInputStream());
} else {
h.close();
return null;
}
} catch (SQLException e) {
IOUtils.closeQuietly(h);
throw DaoException.launderThrowable(e);
}
}
Aggregations