ARTEMIS-2911 DB2 isn't replacing Blob data
This commit is contained in:
parent
622acf1da1
commit
fddb210277
|
@ -19,6 +19,7 @@ package org.apache.activemq.artemis.jdbc.store.file;
|
|||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
|
||||
|
@ -26,6 +27,8 @@ import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider;
|
|||
@SuppressWarnings("SynchronizeOnNonFinalField")
|
||||
public final class Db2SequentialFileDriver extends JDBCSequentialFileFactoryDriver {
|
||||
|
||||
private PreparedStatement replaceLargeObject;
|
||||
|
||||
public Db2SequentialFileDriver() {
|
||||
super();
|
||||
}
|
||||
|
@ -46,22 +49,24 @@ public final class Db2SequentialFileDriver extends JDBCSequentialFileFactoryDriv
|
|||
this.copyFileRecord = connection.prepareStatement(sqlProvider.getCopyFileRecordByIdSQL());
|
||||
this.renameFile = connection.prepareStatement(sqlProvider.getUpdateFileNameByIdSQL());
|
||||
this.readLargeObject = connection.prepareStatement(sqlProvider.getReadLargeObjectSQL());
|
||||
this.replaceLargeObject = connection.prepareStatement(sqlProvider.getReplaceLargeObjectSQL());
|
||||
this.appendToLargeObject = connection.prepareStatement(sqlProvider.getAppendToLargeObjectSQL());
|
||||
this.selectFileNamesByExtension = connection.prepareStatement(sqlProvider.getSelectFileNamesByExtensionSQL());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int writeToFile(JDBCSequentialFile file, byte[] data) throws SQLException {
|
||||
public int writeToFile(JDBCSequentialFile file, byte[] data, boolean append) throws SQLException {
|
||||
if (data == null || data.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
final PreparedStatement largeObjectStatement = append ? appendToLargeObject : replaceLargeObject;
|
||||
synchronized (connection) {
|
||||
try {
|
||||
connection.setAutoCommit(false);
|
||||
int bytesWritten;
|
||||
appendToLargeObject.setBytes(1, data);
|
||||
appendToLargeObject.setLong(2, file.getId());
|
||||
final int updatesFiles = appendToLargeObject.executeUpdate();
|
||||
largeObjectStatement.setBytes(1, data);
|
||||
largeObjectStatement.setLong(2, file.getId());
|
||||
final int updatesFiles = largeObjectStatement.executeUpdate();
|
||||
assert updatesFiles <= 1;
|
||||
connection.commit();
|
||||
if (updatesFiles == 0) {
|
||||
|
|
|
@ -136,6 +136,11 @@ public class PropertySQLProvider implements SQLProvider {
|
|||
return format(sql("select-file-by-filename"), tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReplaceLargeObjectSQL() {
|
||||
return format(sql("replace-file"), tableName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAppendToLargeObjectSQL() {
|
||||
return format(sql("append-to-file"), tableName);
|
||||
|
|
|
@ -44,6 +44,8 @@ public interface SQLProvider {
|
|||
|
||||
String getSelectFileByFileName();
|
||||
|
||||
String getReplaceLargeObjectSQL();
|
||||
|
||||
String getAppendToLargeObjectSQL();
|
||||
|
||||
String getReadLargeObjectSQL();
|
||||
|
|
|
@ -91,6 +91,7 @@ table-names-case.oracle=upper
|
|||
create-journal-table.db2=CREATE TABLE %s(id BIGINT,recordType SMALLINT,compactCount SMALLINT,txId BIGINT,userRecordType SMALLINT,variableSize INTEGER,record BLOB(2G),txDataSize INTEGER,txData BLOB(2G),txCheckNoRecords INTEGER,seq BIGINT NOT NULL, PRIMARY KEY(seq))
|
||||
max-blob-size.db2=2147483647
|
||||
create-file-table.db2=CREATE TABLE %s (ID BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1), FILENAME VARCHAR(255), EXTENSION VARCHAR(10), DATA BLOB(2G), PRIMARY KEY(ID))
|
||||
replace-file.db2=UPDATE %s SET DATA=? WHERE ID=?
|
||||
append-to-file.db2=UPDATE %s SET DATA = (DATA || ?) WHERE ID=?
|
||||
table-names-case.db2=upper
|
||||
|
||||
|
|
Loading…
Reference in New Issue