本文整理汇总了Java中org.postgresql.largeobject.LargeObjectManager类的典型用法代码示例。如果您正苦于以下问题:Java LargeObjectManager类的具体用法?Java LargeObjectManager怎么用?Java LargeObjectManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LargeObjectManager类属于org.postgresql.largeobject包,在下文中一共展示了LargeObjectManager类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getPostgreSqlnputStream
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
/**
* Extract the Large Object Input Stream from PostgreSQL
*
* @param resultSet
* the Result Set to extract the blob from
* @param columnIndex
* the index of column
* @return the Large Object Input Stream from PostgreSQL
* @throws SQLException
*/
public static InputStream getPostgreSqlnputStream(ResultSet resultSet,
int columnIndex) throws SQLException {
InputStream in;
Statement statement = resultSet.getStatement();
Connection conn = statement.getConnection();
// Get the Large Object Manager to perform operations with
LargeObjectManager lobj = ((org.postgresql.PGConnection) conn)
.getLargeObjectAPI();
long oid = resultSet.getLong(columnIndex);
if (oid < 1) {
return null;
}
LargeObject obj = lobj.open(oid, LargeObjectManager.READ);
in = obj.getInputStream();
return in;
}
开发者ID:kawansoft,项目名称:aceql-http,代码行数:31,代码来源:PostgreSqlUtil.java
示例2: setPostgreSqlParameterWithLargeObject
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
/**
* Create a Large Object to set the PostgreSQL OID with
*
* @param preparedStatement
* the Prepared Statement
* @param parameterIndex
* the parameter index
* @param in
* The Input Stream to use
* @param connection
* the JDBC Connection
* @throws SQLException
* @throws IOException
*/
public static void setPostgreSqlParameterWithLargeObject(
PreparedStatement preparedStatement, int parameterIndex,
InputStream in, Connection connection) throws SQLException,
IOException {
// Get the Large Object Manager to perform operations with
LargeObjectManager lobj = ((org.postgresql.PGConnection) connection)
.getLargeObjectAPI();
// Create a new large object
long oid = lobj.createLO(LargeObjectManager.READ
| LargeObjectManager.WRITE);
// Open the large object for writing
LargeObject obj = lobj.open(oid, LargeObjectManager.WRITE);
try (OutputStream out = obj.getOutputStream();){
IOUtils.copy(in, out);
} finally {
//IOUtils.closeQuietly(out);
// Close the large object
obj.close();
}
preparedStatement.setLong(parameterIndex, oid);
}
开发者ID:kawansoft,项目名称:aceql-http,代码行数:40,代码来源:PostgreSqlUtil.java
示例3: createFile
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
@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;
}
}
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:26,代码来源:PostgresSequentialSequentialFileDriver.java
示例4: writeToFile
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
@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;
}
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:PostgresSequentialSequentialFileDriver.java
示例5: getPostGresLargeObjectSize
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
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;
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:22,代码来源:PostgresSequentialSequentialFileDriver.java
示例6: doWritePostgres
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
private void doWritePostgres(Handle h, String id, InputStream file) {
doDelete(h, id);
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 icon_filestore(id, data) values (?,?)", id, oid);
} catch (IOException | SQLException ex) {
throw IconDataAccessException.launderThrowable(ex);
}
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:16,代码来源:SqlIconFileStore.java
示例7: doReadPostgres
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
/**
* Postgres does not allow to read from the large object after the connection has been closed.
*/
private InputStream doReadPostgres(String id) {
Handle h = dbi.open();
try {
h.getConnection().setAutoCommit(false);
List<Map<String, Object>> res = h.select("SELECT data FROM icon_filestore WHERE id=?", id);
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 IconDataAccessException.launderThrowable(e);
}
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:30,代码来源:SqlIconFileStore.java
示例8: doWritePostgres
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
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 ExtensionDataAccessException.launderThrowable(ex);
}
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:16,代码来源:SqlExtensionFileStore.java
示例9: doReadPostgres
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
/**
* 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 ExtensionDataAccessException.launderThrowable(e);
}
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:30,代码来源:SqlExtensionFileStore.java
示例10: doWritePostgres
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
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 FileStoreException.launderThrowable(ex);
}
}
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:16,代码来源:SqlFileStore.java
示例11: doReadPostgres
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
/**
* 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 FileStoreException.launderThrowable(e);
}
}
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:30,代码来源:SqlFileStore.java
示例12: readFromFile
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
@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;
}
}
}
开发者ID:apache,项目名称:activemq-artemis,代码行数:29,代码来源:PostgresSequentialSequentialFileDriver.java
示例13: AbstractJdbc2BlobClob
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
public AbstractJdbc2BlobClob(BaseConnection conn, long oid) throws SQLException
{
this.conn = conn;
LargeObjectManager lom = conn.getLargeObjectAPI();
this.lo = lom.open(oid);
subLOs = new ArrayList();
}
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:8,代码来源:AbstractJdbc2BlobClob.java
示例14: getLargeObjectAPI
import org.postgresql.largeobject.LargeObjectManager; //导入依赖的package包/类
/**
* This returns the LargeObject API for the current connection.
* @since 7.3
*/
public LargeObjectManager getLargeObjectAPI() throws SQLException;
开发者ID:health-and-care-developer-network,项目名称:health-and-care-developer-network,代码行数:6,代码来源:PGConnection.java
注:本文中的org.postgresql.largeobject.LargeObjectManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论