org.postgresql.copy.PGCopyOutputStream Java Examples

The following examples show how to use org.postgresql.copy.PGCopyOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PGBulkLoader.java    From hop with Apache License 2.0 6 votes vote down vote up
private void do_copy( PGBulkLoaderMeta meta, boolean wait ) throws HopException {
  data.db = getDatabase( this, meta );
  String copyCmd = getCopyCommand();
  try {
    connect();

    checkClientEncoding();

    processTruncate();

    logBasic( "Launching command: " + copyCmd );
    pgCopyOut = new PGCopyOutputStream( (PGConnection) data.db.getConnection(), copyCmd );

  } catch ( Exception ex ) {
    throw new HopException( "Error while preparing the COPY " + copyCmd, ex );
  }
}
 
Example #2
Source File: SimpleRowWriter.java    From PgBulkInsert with MIT License 6 votes vote down vote up
public SimpleRowWriter(final Table table, final PGConnection connection, final boolean usePostgresQuoting) throws SQLException {
    this.table = table;
    this.isClosed = false;
    this.isOpened = false;
    this.nullCharacterHandler = (val) -> val;

    this.provider = new ValueHandlerProvider();
    this.lookup = new HashMap<>();

    for (int ordinal = 0; ordinal < table.columns.length; ordinal++) {
        lookup.put(table.columns[ordinal], ordinal);
    }

    this.writer = new PgBinaryWriter(new PGCopyOutputStream(connection, table.getCopyCommand(usePostgresQuoting), 1));

    isClosed = false;
    isOpened = true;
}
 
Example #3
Source File: PGBulkLoader.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void do_copy( PGBulkLoaderMeta meta, boolean wait ) throws KettleException {
  data.db = getDatabase( this, meta );
  String copyCmd = getCopyCommand();
  try {
    connect();

    checkClientEncoding();

    processTruncate();

    logBasic( "Launching command: " + copyCmd );
    pgCopyOut = new PGCopyOutputStream( (PGConnection) data.db.getConnection(), copyCmd );

  } catch ( Exception ex ) {
    throw new KettleException( "Error while preparing the COPY " + copyCmd, ex );
  }
}
 
Example #4
Source File: PgBulkInsert.java    From PgBulkInsert with MIT License 5 votes vote down vote up
@Override
public void saveAll(PGConnection connection, Stream<TEntity> entities) throws SQLException {
    // Wrap the CopyOutputStream in our own Writer:
    try (PgBinaryWriter bw = new PgBinaryWriter(new PGCopyOutputStream(connection, mapping.getCopyCommand(), 1), configuration.getBufferSize())) {
        // Insert Each Column:
        entities.forEach(entity -> saveEntitySynchonized(bw, entity));
    }
}
 
Example #5
Source File: PGBulkLoaderTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private ByteArrayOutputStream initPGCopyOutputStream() throws IOException, NoSuchFieldException, IllegalAccessException {
  final ByteArrayOutputStream out = new ByteArrayOutputStream();
  final PGCopyOutputStream pgCopy = mock( PGCopyOutputStream.class );
  doAnswer( invocation -> {
    out.write( (byte[]) invocation.getArguments()[0] );
    return null;
  } ).when( pgCopy ).write( any() );
  final Field pgCopyOut = pgBulkLoader.getClass().getDeclaredField( "pgCopyOut" );
  pgCopyOut.setAccessible( true );
  pgCopyOut.set( pgBulkLoader, pgCopy );
  return out;
}