Uploading works now with Envers.
parent
f022a9540d
commit
36c9ec8a61
|
|
@ -86,7 +86,7 @@ public class BinaryAsset extends Asset implements Serializable {
|
||||||
@Column(name = "ASSET_DATA")
|
@Column(name = "ASSET_DATA")
|
||||||
@Lob
|
@Lob
|
||||||
@Basic(fetch = FetchType.LAZY)
|
@Basic(fetch = FetchType.LAZY)
|
||||||
@NotAudited
|
// @NotAudited
|
||||||
// private byte[] data;
|
// private byte[] data;
|
||||||
private Blob data;
|
private Blob data;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ public class BinaryAssetBlobDataProvider implements BinaryAssetDataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
final Blob data = BlobProxy.generateProxy(
|
final Blob data = BlobProxy.generateProxy(
|
||||||
Files.newInputStream(tmpFilePath), -1
|
new UploadInputStream(tmpFilePath), -1
|
||||||
);
|
);
|
||||||
asset.setFileName(fileName);
|
asset.setFileName(fileName);
|
||||||
asset.setData(data);
|
asset.setData(data);
|
||||||
|
|
@ -143,9 +143,9 @@ public class BinaryAssetBlobDataProvider implements BinaryAssetDataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
assetRepo.save(asset);
|
assetRepo.save(asset);
|
||||||
entityManager.flush();
|
// entityManager.flush();
|
||||||
|
//
|
||||||
updateAudTable(asset.getObjectId());
|
// updateAudTable(asset.getObjectId());
|
||||||
|
|
||||||
// try ( Connection connection = dataSource.getConnection()) {
|
// try ( Connection connection = dataSource.getConnection()) {
|
||||||
// final PreparedStatement stmt = connection
|
// final PreparedStatement stmt = connection
|
||||||
|
|
@ -165,7 +165,7 @@ public class BinaryAssetBlobDataProvider implements BinaryAssetDataProvider {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
||||||
private void updateAudTable(final long assetId) {
|
private void updateAudTable(final long assetId) {
|
||||||
try ( Connection connection = dataSource.getConnection()) {
|
try ( Connection connection = dataSource.getConnection()) {
|
||||||
final PreparedStatement findRevStmt = connection
|
final PreparedStatement findRevStmt = connection
|
||||||
|
|
@ -194,4 +194,90 @@ public class BinaryAssetBlobDataProvider implements BinaryAssetDataProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class UploadInputStream extends InputStream {
|
||||||
|
|
||||||
|
private final Path tmpFilePath;
|
||||||
|
|
||||||
|
private InputStream inputStream;
|
||||||
|
|
||||||
|
public UploadInputStream(final Path tmpFilePath) {
|
||||||
|
this.tmpFilePath = tmpFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int available() throws IOException {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
return inputStream.available();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
inputStream = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mark(final int readLimit) {
|
||||||
|
try {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
inputStream.mark(readLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean markSupported() {
|
||||||
|
try {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
return inputStream.markSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
return inputStream.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(final byte[] data) throws IOException {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
return inputStream.read(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(final byte[] data, final int offset, final int length)
|
||||||
|
throws IOException {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
return inputStream.read(data, offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() throws IOException {
|
||||||
|
if (inputStream == null) {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
} else {
|
||||||
|
inputStream.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long skip(long nBytes) throws IOException {
|
||||||
|
openNewInputStreamIfNecessary();
|
||||||
|
return inputStream.skip(nBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openNewInputStreamIfNecessary() throws IOException {
|
||||||
|
if (inputStream == null) {
|
||||||
|
inputStream = Files.newInputStream(tmpFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue