Skip to content

Commit

Permalink
Try with buffered outputstream and add java opts to docker
Browse files Browse the repository at this point in the history
  • Loading branch information
samleeflang committed Jan 29, 2024
1 parent 20bd9f6 commit d73389f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ RUN true
COPY --chown=java:java --from=builder application/application/ ./
USER 1000

ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
ENTRYPOINT ["java", "$JAVA_OPTS", "org.springframework.boot.loader.launch.JarLauncher"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.fasterxml.jackson.databind.JsonNode;
import eu.dissco.core.translator.exception.DisscoRepositoryException;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.List;
Expand Down Expand Up @@ -41,23 +41,16 @@ private static String cleanString(JsonNode jsonNode) {

public void batchCopy(String tableName, List<Pair<String, JsonNode>> dbRecords)
throws DisscoRepositoryException {
try (var outputStream = new ByteArrayOutputStream();
var in = new PipedInputStream();
var out = new PipedOutputStream(in)) {
byte[] buffer = new byte[2048];
try (var baos = new ByteArrayOutputStream();
var bos = new BufferedOutputStream(baos, buffer.length)) {
for (var dbRecord : dbRecords) {
outputStream.write(getCsvRow(dbRecord));
bos.write(getCsvRow(dbRecord));
}
try (in) {
new Thread(() -> {
try (out) {
outputStream.writeTo(out);
} catch (IOException e) {
log.error("Error writing to pipe", e);
}
}).start();

try (ByteArrayInputStream bais =
new ByteArrayInputStream(baos.toByteArray())) {
copyManager.copyIn("COPY " + tableName
+ " FROM stdin DELIMITER ','", in);
+ " FROM stdin DELIMITER ','", bais);
}
} catch (IOException | SQLException e) {
throw new DisscoRepositoryException(
Expand All @@ -66,4 +59,5 @@ public void batchCopy(String tableName, List<Pair<String, JsonNode>> dbRecords)
}
}


}

0 comments on commit d73389f

Please sign in to comment.