ARTEMIS-998 Fix NPE in JDBC FileDriver when BLOB is null

This commit is contained in:
Martyn Taylor 2017-02-25 11:36:16 +00:00
parent 739b8e75b5
commit a1012884cc
1 changed files with 11 additions and 4 deletions

View File

@ -155,7 +155,9 @@ public class JDBCSequentialFileFactoryDriver extends AbstractJDBCDriver {
try (ResultSet rs = readLargeObject.executeQuery()) { try (ResultSet rs = readLargeObject.executeQuery()) {
if (rs.next()) { if (rs.next()) {
Blob blob = rs.getBlob(1); Blob blob = rs.getBlob(1);
file.setWritePosition((int) blob.length()); if (blob != null) {
file.setWritePosition((int) blob.length());
}
} }
connection.commit(); connection.commit();
} catch (SQLException e) { } catch (SQLException e) {
@ -250,6 +252,9 @@ public class JDBCSequentialFileFactoryDriver extends AbstractJDBCDriver {
try (ResultSet rs = appendToLargeObject.executeQuery()) { try (ResultSet rs = appendToLargeObject.executeQuery()) {
if (rs.next()) { if (rs.next()) {
Blob blob = rs.getBlob(1); Blob blob = rs.getBlob(1);
if (blob == null) {
blob = connection.createBlob();
}
bytesWritten = blob.setBytes(blob.length() + 1, data); bytesWritten = blob.setBytes(blob.length() + 1, data);
rs.updateBlob(1, blob); rs.updateBlob(1, blob);
rs.updateRow(); rs.updateRow();
@ -279,9 +284,11 @@ public class JDBCSequentialFileFactoryDriver extends AbstractJDBCDriver {
try (ResultSet rs = readLargeObject.executeQuery()) { try (ResultSet rs = readLargeObject.executeQuery()) {
if (rs.next()) { if (rs.next()) {
final Blob blob = rs.getBlob(1); final Blob blob = rs.getBlob(1);
readLength = (int) calculateReadLength(blob.length(), bytes.remaining(), file.position()); if (blob != null) {
byte[] data = blob.getBytes(file.position() + 1, readLength); readLength = (int) calculateReadLength(blob.length(), bytes.remaining(), file.position());
bytes.put(data); byte[] data = blob.getBytes(file.position() + 1, readLength);
bytes.put(data);
}
} }
connection.commit(); connection.commit();
return readLength; return readLength;