private void doWrite(Handle h, String id, InputStream file) { if (databaseKind == DatabaseKind.PostgreSQL) { doWritePostgres(h, id, file); } else if (databaseKind == DatabaseKind.Apache_Derby) { doWriteDerby(h, id, file); } else { doWriteStandard(h, id, file); } }
private void doWrite(Handle h, String path, InputStream file) { if (databaseKind == DatabaseKind.PostgreSQL) { doWritePostgres(h, path, file); } else if (databaseKind == DatabaseKind.Apache_Derby) { doWriteDerby(h, path, file); } else { doWriteStandard(h, path, file); } }
private void doWrite(Handle h, String path, InputStream file) { if (databaseKind == DatabaseKind.PostgreSQL) { doWritePostgres(h, path, file); } else if (databaseKind == DatabaseKind.Apache_Derby) { doWriteDerby(h, path, file); } else { doWriteStandard(h, path, file); } }
@Override public InputStream read(String path) { FileStoreSupport.checkValidPath(path); try { if (databaseKind == DatabaseKind.PostgreSQL) { return doReadPostgres(path); } else if (databaseKind == DatabaseKind.Apache_Derby) { return doReadDerby(path); } else { return dbi.inTransaction((h, status) -> doReadStandard(h, path)); } } catch (CallbackFailedException ex) { throw new ExtensionDataAccessException("Unable to read data from path " + path, ex); } }
public InputStream read(String path) { FileStoreSupport.checkValidPath(path); try { if (databaseKind == DatabaseKind.PostgreSQL) { return doReadPostgres(path); } else if (databaseKind == DatabaseKind.Apache_Derby) { return doReadDerby(path); } else { return dbi.inTransaction((h, status) -> doReadStandard(h, path)); } } catch (CallbackFailedException ex) { throw new DaoException("Unable to read data from path " + path, 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); } }
@Override public boolean delete(String path) { FileStoreSupport.checkValidPath(path); try { return dbi.inTransaction((h, status) -> doDelete(h, path)); } catch (CallbackFailedException ex) { throw new ExtensionDataAccessException("Unable to delete path " + path, ex); } }
public void write(String path, InputStream file) { FileStoreSupport.checkValidPath(path); Objects.requireNonNull(file, "file cannot be null"); try { dbi.inTransaction((h, status) -> { doWrite(h, path, file); return true; }); } catch (CallbackFailedException ex) { throw new DaoException("Unable to write on path " + path, ex); } }
@Override public InputStream read(String id) { try { if (databaseKind == DatabaseKind.PostgreSQL) { return doReadPostgres(id); } else if (databaseKind == DatabaseKind.Apache_Derby) { return doReadDerby(id); } else { return dbi.inTransaction((h, status) -> doReadStandard(h, id)); } } catch (CallbackFailedException ex) { throw new IconDataAccessException("Unable to read data from id " + id, ex); } }
@Override public void write(String path, InputStream file) { FileStoreSupport.checkValidPath(path); Objects.requireNonNull(file, "file cannot be null"); try { dbi.inTransaction((h, status) -> { doWrite(h, path, file); return true; }); } catch (CallbackFailedException ex) { throw new ExtensionDataAccessException("Unable to write on path " + path, ex); } }
/** * Checks if the path is valid and throws an exception if it's not. * @param path the path to check * @throws ExtensionDataAccessException if the path is not valid */ public static void checkValidPath(String path) throws ExtensionDataAccessException { if (!isValidPath(path)) { throw new ExtensionDataAccessException("Invalid path: " + path); } }
public String writeTemporaryFile(InputStream file) { Objects.requireNonNull(file, "file cannot be null"); try { return dbi.inTransaction((h, status) -> { String path = newRandomTempFilePath(); doWrite(h, path, file); return path; }); } catch (CallbackFailedException ex) { throw new DaoException("Unable to write on temporary path", ex); } }
@Override public String writeTemporaryFile(InputStream file) { Objects.requireNonNull(file, "file cannot be null"); try { return dbi.inTransaction((h, status) -> { String path = newRandomTempFilePath(); doWrite(h, path, file); return path; }); } catch (CallbackFailedException ex) { throw new ExtensionDataAccessException("Unable to write on temporary path", ex); } }
private void doWriteStandard(Handle h, String id, InputStream file) { doDelete(h, id); h.insert("INSERT INTO icon_filestore(id, data) values (?,?)", id, file); }
private void doWriteStandard(Handle h, String path, InputStream file) { doDelete(h, path); h.insert("INSERT INTO filestore(path, data) values (?,?)", path, file); }
private void doWriteStandard(Handle h, String path, InputStream file) { doDelete(h, path); h.insert("INSERT INTO filestore(path, data) values (?,?)", path, file); }
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); } }
@Override 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 ExtensionDataAccessException("Unable to move file from path " + fromPath + " to path " + toPath, ex); } }
/** * Checks if the path is valid and throws an exception if it's not. * @param path the path to check * @throws DaoException if the path is not valid */ public static void checkValidPath(String path) throws DaoException { if (!isValidPath(path)) { throw new DaoException("Invalid path: " + path); } }
@Override public boolean delete(String id) { try { return dbi.inTransaction((h, status) -> doDelete(h, id)); } catch (CallbackFailedException ex) { throw new IconDataAccessException("Unable to delete id " + id, ex); } }