DatabaseBlobBinaryStorage service will only store blob up to Integer.MAX_VALUE (#4167)

* Modification of entity to support long.

* Adding Changelog.

Co-authored-by: peartree <etienne.poirier@smilecdr.com>
This commit is contained in:
Etienne Poirier 2022-10-19 17:06:51 -04:00 committed by GitHub
parent 0798ab35db
commit 4200ccf756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 4166
title: "When storing a blob, the database blob binary storage service may store the blob size as being much smaller than the actual blob size. This issue has been fixed."

View File

@ -28,6 +28,7 @@ import ca.uhn.fhir.jpa.dao.data.IBinaryStorageEntityDao;
import ca.uhn.fhir.jpa.model.entity.BinaryStorageEntity; import ca.uhn.fhir.jpa.model.entity.BinaryStorageEntity;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import com.google.common.hash.HashingInputStream; import com.google.common.hash.HashingInputStream;
import com.google.common.io.ByteStreams;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CountingInputStream; import org.apache.commons.io.input.CountingInputStream;
import org.hibernate.LobHelper; import org.hibernate.LobHelper;
@ -94,7 +95,7 @@ public class DatabaseBlobBinaryStorageSvcImpl extends BaseBinaryStorageSvcImpl {
// Update the entity with the final byte count and hash // Update the entity with the final byte count and hash
long bytes = countingInputStream.getByteCount(); long bytes = countingInputStream.getByteCount();
String hash = hashingInputStream.hash().toString(); String hash = hashingInputStream.hash().toString();
entity.setSize((int) bytes); entity.setSize(bytes);
entity.setHash(hash); entity.setHash(hash);
// Save the entity // Save the entity
@ -161,9 +162,8 @@ public class DatabaseBlobBinaryStorageSvcImpl extends BaseBinaryStorageSvcImpl {
} }
byte[] copyBlobToByteArray(BinaryStorageEntity theEntity) throws IOException { byte[] copyBlobToByteArray(BinaryStorageEntity theEntity) throws IOException {
int size = theEntity.getSize();
try { try {
return IOUtils.toByteArray(theEntity.getBlob().getBinaryStream(), size); return ByteStreams.toByteArray(theEntity.getBlob().getBinaryStream());
} catch (SQLException e) { } catch (SQLException e) {
throw new IOException(Msg.code(1342) + e); throw new IOException(Msg.code(1342) + e);
} }

View File

@ -41,7 +41,7 @@ public class BinaryStorageEntity {
@Column(name = "RESOURCE_ID", length = 100, nullable = false) @Column(name = "RESOURCE_ID", length = 100, nullable = false)
private String myResourceId; private String myResourceId;
@Column(name = "BLOB_SIZE", nullable = true) @Column(name = "BLOB_SIZE", nullable = true)
private int mySize; private long mySize;
@Column(name = "CONTENT_TYPE", nullable = false, length = 100) @Column(name = "CONTENT_TYPE", nullable = false, length = 100)
private String myBlobContentType; private String myBlobContentType;
@Lob @Lob
@ -73,7 +73,7 @@ public class BinaryStorageEntity {
myResourceId = theResourceId; myResourceId = theResourceId;
} }
public int getSize() { public long getSize() {
return mySize; return mySize;
} }
@ -97,7 +97,7 @@ public class BinaryStorageEntity {
return myBlobId; return myBlobId;
} }
public void setSize(int theSize) { public void setSize(long theSize) {
mySize = theSize; mySize = theSize;
} }