use of org.postgresql.largeobject.LargeObjectManager in project activemq-artemis by apache.
the class PostgresSequentialSequentialFileDriver method createFile.
@Override
public void createFile(JDBCSequentialFile file) throws SQLException {
synchronized (connection) {
try {
connection.setAutoCommit(false);
LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();
long oid = lobjManager.createLO();
createFile.setString(1, file.getFileName());
createFile.setString(2, file.getExtension());
createFile.setLong(3, oid);
createFile.executeUpdate();
try (ResultSet keys = createFile.getGeneratedKeys()) {
keys.next();
file.setId(keys.getLong(1));
}
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw e;
}
}
}
use of org.postgresql.largeobject.LargeObjectManager in project syndesis by syndesisio.
the class SqlFileStore method doWritePostgres.
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);
}
}
use of org.postgresql.largeobject.LargeObjectManager in project activemq-artemis by apache.
the class PostgresSequentialSequentialFileDriver method getPostGresLargeObjectSize.
private int getPostGresLargeObjectSize(JDBCSequentialFile file) throws SQLException {
LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();
int size = 0;
Long oid = getOID(file);
if (oid != null) {
synchronized (connection) {
try {
connection.setAutoCommit(false);
LargeObject largeObject = lobjManager.open(oid, LargeObjectManager.READ);
size = largeObject.size();
largeObject.close();
connection.commit();
} catch (SQLException e) {
connection.rollback();
throw e;
}
}
}
return size;
}
use of org.postgresql.largeobject.LargeObjectManager in project activemq-artemis by apache.
the class PostgresSequentialSequentialFileDriver method writeToFile.
@Override
public int writeToFile(JDBCSequentialFile file, byte[] data) throws SQLException {
synchronized (connection) {
LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();
LargeObject largeObject = null;
Long oid = getOID(file);
try {
connection.setAutoCommit(false);
largeObject = lobjManager.open(oid, LargeObjectManager.WRITE);
largeObject.seek(largeObject.size());
largeObject.write(data);
largeObject.close();
connection.commit();
} catch (Exception e) {
connection.rollback();
throw e;
}
return data.length;
}
}
use of org.postgresql.largeobject.LargeObjectManager in project activemq-artemis by apache.
the class PostgresSequentialSequentialFileDriver method readFromFile.
@Override
public int readFromFile(JDBCSequentialFile file, ByteBuffer bytes) throws SQLException {
LargeObjectManager lobjManager = ((PGConnection) connection).getLargeObjectAPI();
LargeObject largeObject = null;
long oid = getOID(file);
synchronized (connection) {
try {
connection.setAutoCommit(false);
largeObject = lobjManager.open(oid, LargeObjectManager.READ);
int readLength = (int) calculateReadLength(largeObject.size(), bytes.remaining(), file.position());
if (readLength > 0) {
if (file.position() > 0)
largeObject.seek((int) file.position());
byte[] data = largeObject.read(readLength);
bytes.put(data);
}
largeObject.close();
connection.commit();
return readLength;
} catch (SQLException e) {
connection.rollback();
throw e;
}
}
}
Aggregations