From 1e14b90894a02a86d4fbff6d97425921f4e5540b Mon Sep 17 00:00:00 2001 From: The Alchemist Date: Thu, 17 May 2018 14:28:59 -0400 Subject: [PATCH] Expose some private methods as public Many APIs only give you access to one entity at a time, even if there is some kind of stream backing it (e.g., JDBC, Kafka). So, I was hoping to inline and modify the `PgBulkInsert::saveAll()` method and call the following directly: ```java CopyManager cpManager = connection.getCopyAPI(); CopyIn copyIn = cpManager.copyIn(getCopyCommand()); try (PgBinaryWriter bw = new PgBinaryWriter()) { // Wrap the CopyOutputStream in our own Writer: bw.open(new PGCopyOutputStream(copyIn)); // Insert Each Column: entities.forEach(entity -> this.saveEntity(bw, entity)); } ``` However, two methods are private and can't be called directly. Exposing them would allow users to control the opening and closing of a `PgBinaryWriter`, allowing usage with other APIs that provide messages one-by-one. --- .../src/main/java/de/bytefish/pgbulkinsert/PgBulkInsert.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PgBulkInsert/src/main/java/de/bytefish/pgbulkinsert/PgBulkInsert.java b/PgBulkInsert/src/main/java/de/bytefish/pgbulkinsert/PgBulkInsert.java index c5389d1..65ef55e 100644 --- a/PgBulkInsert/src/main/java/de/bytefish/pgbulkinsert/PgBulkInsert.java +++ b/PgBulkInsert/src/main/java/de/bytefish/pgbulkinsert/PgBulkInsert.java @@ -67,7 +67,7 @@ public void saveAll(PGConnection connection, Stream entities) throws SQ } } - private void saveEntity(PgBinaryWriter bw, TEntity entity) throws SaveEntityFailedException { + public void saveEntity(PgBinaryWriter bw, TEntity entity) throws SaveEntityFailedException { synchronized (bw) { // Start a New Row: bw.startRow(columns.size()); @@ -269,7 +269,7 @@ private PgBulkInsert addColumn(String columnName, Action2 x.getColumnName())