diff --git a/Dockerfile b/Dockerfile index f0e77a9..4b41849 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/src/main/java/eu/dissco/core/translator/repository/BatchInserter.java b/src/main/java/eu/dissco/core/translator/repository/BatchInserter.java index d7c2eae..2c4a1cf 100644 --- a/src/main/java/eu/dissco/core/translator/repository/BatchInserter.java +++ b/src/main/java/eu/dissco/core/translator/repository/BatchInserter.java @@ -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; @@ -41,23 +41,16 @@ private static String cleanString(JsonNode jsonNode) { public void batchCopy(String tableName, List> 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( @@ -66,4 +59,5 @@ public void batchCopy(String tableName, List> dbRecords) } } + }