-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARTEMIS-1813 DB2 should avoid Blob to append data
DB2 10.5 doesn't allow to append Blob data to an existing Blob, producing unexpected errors: a custom DB2 sequential file can perfom the append by using a customized UPDATE statement. max-blob-size.db2 and create-file-table.db2 are changed to match the 2 GB max blob size limit allowed by DB2.
- Loading branch information
1 parent
9247eaa
commit 998be38
Showing
5 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...re/src/main/java/org/apache/activemq/artemis/jdbc/store/file/Db2SequentialFileDriver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.activemq.artemis.jdbc.store.file; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider; | ||
|
||
@SuppressWarnings("SynchronizeOnNonFinalField") | ||
public final class Db2SequentialFileDriver extends JDBCSequentialFileFactoryDriver { | ||
|
||
public Db2SequentialFileDriver() { | ||
super(); | ||
} | ||
|
||
public Db2SequentialFileDriver(DataSource dataSource, SQLProvider provider) { | ||
super(dataSource, provider); | ||
} | ||
|
||
public Db2SequentialFileDriver(Connection connection, SQLProvider provider) { | ||
super(connection, provider); | ||
} | ||
|
||
@Override | ||
protected void prepareStatements() throws SQLException { | ||
this.deleteFile = connection.prepareStatement(sqlProvider.getDeleteFileSQL()); | ||
this.createFile = connection.prepareStatement(sqlProvider.getInsertFileSQL(), new String[]{"ID"}); | ||
this.selectFileByFileName = connection.prepareStatement(sqlProvider.getSelectFileByFileName()); | ||
this.copyFileRecord = connection.prepareStatement(sqlProvider.getCopyFileRecordByIdSQL()); | ||
this.renameFile = connection.prepareStatement(sqlProvider.getUpdateFileNameByIdSQL()); | ||
this.readLargeObject = connection.prepareStatement(sqlProvider.getReadLargeObjectSQL()); | ||
this.appendToLargeObject = connection.prepareStatement(sqlProvider.getAppendToLargeObjectSQL()); | ||
this.selectFileNamesByExtension = connection.prepareStatement(sqlProvider.getSelectFileNamesByExtensionSQL()); | ||
} | ||
|
||
@Override | ||
public int writeToFile(JDBCSequentialFile file, byte[] data) throws SQLException { | ||
if (data == null || data.length == 0) { | ||
return 0; | ||
} | ||
synchronized (connection) { | ||
try { | ||
connection.setAutoCommit(false); | ||
int bytesWritten; | ||
appendToLargeObject.setBytes(1, data); | ||
appendToLargeObject.setLong(2, file.getId()); | ||
final int updatesFiles = appendToLargeObject.executeUpdate(); | ||
assert updatesFiles <= 1; | ||
connection.commit(); | ||
if (updatesFiles == 0) { | ||
bytesWritten = 0; | ||
} else { | ||
bytesWritten = data.length; | ||
} | ||
return bytesWritten; | ||
} catch (SQLException e) { | ||
connection.rollback(); | ||
throw e; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters