Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import de.bytefish.pgbulkinsert.mapping.AbstractMapping;
import de.bytefish.pgbulkinsert.pgsql.PgBinaryWriter;
import org.postgresql.PGConnection;
import org.postgresql.copy.CopyIn;
import org.postgresql.copy.CopyManager;
import org.postgresql.copy.PGCopyOutputStream;

import java.sql.SQLException;
Expand Down Expand Up @@ -45,13 +43,10 @@ public PgBulkInsert(IConfiguration configuration, AbstractMapping<TEntity> mappi
*/
public void saveAll(PGConnection connection, Stream<TEntity> entities) throws SQLException {

CopyManager cpManager = connection.getCopyAPI();
CopyIn copyIn = cpManager.copyIn(mapping.getCopyCommand());

try (PgBinaryWriter bw = new PgBinaryWriter(configuration.getBufferSize())) {

// Wrap the CopyOutputStream in our own Writer:
bw.open(new PGCopyOutputStream(copyIn, 1));
bw.open(new PGCopyOutputStream(connection, mapping.getCopyCommand(), 1));

// Insert Each Column:
entities.forEach(entity -> saveEntitySynchonized(bw, entity));
Expand All @@ -67,13 +62,10 @@ public void saveAll(PGConnection connection, Stream<TEntity> entities) throws SQ
*/
public void saveAll(PGConnection connection, Collection<TEntity> entities) throws SQLException {

CopyManager cpManager = connection.getCopyAPI();
CopyIn copyIn = cpManager.copyIn(mapping.getCopyCommand());

try (PgBinaryWriter bw = new PgBinaryWriter(configuration.getBufferSize())) {

// Wrap the CopyOutputStream in our own Writer:
bw.open(new PGCopyOutputStream(copyIn, 1));
bw.open(new PGCopyOutputStream(connection, mapping.getCopyCommand(), 1));

// Insert Each Column:
entities.forEach(entity -> saveEntity(bw, entity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

public class ByteArrayValueHandler extends BaseValueHandler<byte[]> {

@Override
protected void internalHandle(DataOutputStream buffer, final byte[] value) throws Exception {
buffer.writeInt(value.length);
for(byte b : value) {
buffer.writeByte(b);
}
}
@Override
protected void internalHandle(DataOutputStream buffer, final byte[] value) throws Exception {
buffer.writeInt(value.length);
buffer.write(value, 0, value.length);
}
}