Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1381725] Avoid bloating pg_largeobject with content updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Burman committed Jan 13, 2017
1 parent 012b4f4 commit d1cb335
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -32,6 +32,7 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -2038,6 +2039,15 @@ public void updateBlobStream(InputStream stream, PackageBits bits, Map<String, S
try {
while (rs.next()) {

if(DatabaseTypeFactory.isPostgres(DatabaseTypeFactory.getDefaultDatabaseType())) {
// Unlink the current blob
int unlinkedBlob = rs.getInt(1);
Statement unlinkStatement = conn.createStatement();
String unlinkSQLProto = "SELECT lo_unlink(%s)";
String sqlUnlink = String.format(unlinkSQLProto, unlinkedBlob);
unlinkStatement.execute(sqlUnlink);
}

//We can not create a blob directly because BlobImpl from Hibernate is not acceptable
//for oracle and Connection.createBlob is not working on postgres.
//This blob will be not empty because we saved there PackageBits.EMPTY_BLOB
Expand Down

0 comments on commit d1cb335

Please sign in to comment.