JBoss Community

Re: How get completed/release time for a task?

created by Nick Tan in jBPM - View the full discussion

Thanks, Jose

 

finally, i use jdbc directly since i want to have as less dependency as possible, but obviously the limition is it tightly couple with postgresql driver classes

 

/**
* get the content bytearray with PostgreSQL JDBC driver
*
* @param contentId
* @return the content byte array, or <code>null</code> if not found
* @see http://snipplr.com/view/53917/postgres-how-to-read-oid-value-using-jdbc-api/
http://virgo47.wordpress.com/2008/06/13/jpa-postgresql-and-bytea-vs-oid-type/
*/
public byte[] getContentWithPg(long contentId) {
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = getConnection();
conn.setAutoCommit(false);

 

// Get the Large Object Manager to perform operations with
LargeObjectManager lobj = ((org.postgresql.PGConnection) conn).getLargeObjectAPI();

 

stmt = conn.prepareStatement("SELECT content FROM content WHERE id = ?");
stmt.setLong(1, contentId);
ResultSet rs = stmt.executeQuery();
if (rs != null) {
if (rs.next()) {
// Open the large object for reading
long oid = rs.getLong(1);
LargeObject obj = lobj.open(oid, LargeObjectManager.READ);

 

// Read the data
byte buf[] = new byte[obj.size()];
obj.read(buf, 0, obj.size());
// Do something with the data read here

 

// Close the object
obj.close();
return buf;
}
rs.close();
}
conn.commit();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
if (conn != null)
conn.close();
if (stmt != null)
stmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}

Reply to this message by going to Community

Start a new discussion in jBPM at Community