activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nigrofr...@apache.org
Subject [activemq-artemis] branch master updated: ARTEMIS-2911 DB2 isn't replacing Blob data
Date Thu, 24 Sep 2020 10:31:18 GMT
This is an automated email from the ASF dual-hosted git repository.

nigrofranz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new fddb210  ARTEMIS-2911 DB2 isn't replacing Blob data
     new f5dfe68  This closes #3271
fddb210 is described below

commit fddb2102776b69fbbf8222302cb94279f86bd421
Author: franz1981 <nigro.fra@gmail.com>
AuthorDate: Wed Sep 23 18:29:35 2020 +0200

    ARTEMIS-2911 DB2 isn't replacing Blob data
---
 .../artemis/jdbc/store/file/Db2SequentialFileDriver.java    | 13 +++++++++----
 .../artemis/jdbc/store/sql/PropertySQLProvider.java         |  5 +++++
 .../apache/activemq/artemis/jdbc/store/sql/SQLProvider.java |  2 ++
 .../src/main/resources/journal-sql.properties               |  1 +
 4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/Db2SequentialFileDriver.java
b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/Db2SequentialFileDriver.java
index 1043002..c0066ab 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/Db2SequentialFileDriver.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/file/Db2SequentialFileDriver.java
@@ -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) {
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProvider.java
b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProvider.java
index 118725a..7d46184 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProvider.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/PropertySQLProvider.java
@@ -137,6 +137,11 @@ public class PropertySQLProvider implements SQLProvider {
    }
 
    @Override
+   public String getReplaceLargeObjectSQL() {
+      return format(sql("replace-file"), tableName);
+   }
+
+   @Override
    public String getAppendToLargeObjectSQL() {
       return format(sql("append-to-file"), tableName);
    }
diff --git a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java
b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java
index 66af24b..5f2f26f 100644
--- a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java
+++ b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/sql/SQLProvider.java
@@ -44,6 +44,8 @@ public interface SQLProvider {
 
    String getSelectFileByFileName();
 
+   String getReplaceLargeObjectSQL();
+
    String getAppendToLargeObjectSQL();
 
    String getReadLargeObjectSQL();
diff --git a/artemis-jdbc-store/src/main/resources/journal-sql.properties b/artemis-jdbc-store/src/main/resources/journal-sql.properties
index 831d4bd..4312379 100644
--- a/artemis-jdbc-store/src/main/resources/journal-sql.properties
+++ b/artemis-jdbc-store/src/main/resources/journal-sql.properties
@@ -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
 


Mime
View raw message