private void doWriteStandard(Handle h, String path, InputStream file) { doDelete(h, path); h.insert("INSERT INTO filestore(path, data) values (?,?)", path, file); }
private void doWriteDerby(Handle h, String path, InputStream file) { doDelete(h, path); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, blob); } catch (IOException | SQLException ex) { throw DaoException.launderThrowable(ex); } }
public boolean delete(String path) { FileStoreSupport.checkValidPath(path); try { return dbi.inTransaction((h, status) -> doDelete(h, path)); } catch (CallbackFailedException ex) { throw new DaoException("Unable to delete path " + path, ex); } }
public boolean move(String fromPath, String toPath) { FileStoreSupport.checkValidPath(fromPath); FileStoreSupport.checkValidPath(toPath); try { return dbi.inTransaction((h, status) -> { boolean existed = h.select("SELECT 1 from filestore WHERE path=?", fromPath).size() > 0; if (existed) { doDelete(h, toPath); h.update("UPDATE filestore SET path=? WHERE path=?", toPath, fromPath); } return existed; }); } catch (CallbackFailedException ex) { throw new DaoException("Unable to move file from path " + fromPath + " to path " + toPath, ex); } }
private void doWritePostgres(Handle h, String path, InputStream file) { doDelete(h, path); try { LargeObjectManager lobj = getPostgresConnection(h.getConnection()).getLargeObjectAPI(); long oid = lobj.createLO(); LargeObject obj = lobj.open(oid, LargeObjectManager.WRITE); try (OutputStream lob = obj.getOutputStream()) { IOUtils.copy(file, lob); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, oid); } catch (IOException | SQLException ex) { throw DaoException.launderThrowable(ex); } }