Search in sources :

Example 1 with DaoException

use of io.syndesis.server.dao.DaoException in project syndesis by syndesisio.

the class SqlFileStore method move.

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);
    }
}
Also used : DaoException(io.syndesis.server.dao.DaoException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException)

Example 2 with DaoException

use of io.syndesis.server.dao.DaoException in project syndesis by syndesisio.

the class SqlFileStore method write.

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);
    }
}
Also used : DaoException(io.syndesis.server.dao.DaoException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException)

Example 3 with DaoException

use of io.syndesis.server.dao.DaoException in project syndesis by syndesisio.

the class SqlFileStore method writeTemporaryFile.

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);
    }
}
Also used : DaoException(io.syndesis.server.dao.DaoException) CallbackFailedException(org.skife.jdbi.v2.exceptions.CallbackFailedException)

Example 4 with DaoException

use of io.syndesis.server.dao.DaoException in project syndesis by syndesisio.

the class SqlFileStore method doReadStandard.

private InputStream doReadStandard(Handle h, String path) {
    List<Map<String, Object>> res = h.select("SELECT data FROM filestore WHERE path=?", path);
    Optional<Blob> blob = res.stream().map(row -> row.get("data")).map(Blob.class::cast).findFirst();
    if (blob.isPresent()) {
        try {
            return blob.get().getBinaryStream();
        } catch (SQLException ex) {
            throw new DaoException("Unable to read from BLOB", ex);
        }
    }
    return null;
}
Also used : Blob(java.sql.Blob) SQLException(java.sql.SQLException) DaoException(io.syndesis.server.dao.DaoException) Map(java.util.Map)

Aggregations

DaoException (io.syndesis.server.dao.DaoException)4 CallbackFailedException (org.skife.jdbi.v2.exceptions.CallbackFailedException)3 Blob (java.sql.Blob)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1