Search in sources :

Example 1 with PGCopyOutputStream

use of org.postgresql.copy.PGCopyOutputStream in project pentaho-kettle by pentaho.

the class PGBulkLoaderTest method initPGCopyOutputStream.

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;
}
Also used : Field(java.lang.reflect.Field) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 2 with PGCopyOutputStream

use of org.postgresql.copy.PGCopyOutputStream in project sqlg by pietermartin.

the class PostgresDialect method streamSql.

@Override
public Writer streamSql(SqlgGraph sqlgGraph, String sql) {
    Connection conn = sqlgGraph.tx().getConnection();
    PGConnection pgConnection;
    try {
        pgConnection = conn.unwrap(PGConnection.class);
        OutputStream out = new PGCopyOutputStream(pgConnection, sql);
        return new OutputStreamWriter(out, "UTF-8");
    } catch (SQLException | UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : PGConnection(org.postgresql.PGConnection) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) PGConnection(org.postgresql.PGConnection)

Example 3 with PGCopyOutputStream

use of org.postgresql.copy.PGCopyOutputStream in project pentaho-kettle by pentaho.

the class PGBulkLoader method do_copy.

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PGCopyOutputStream(org.postgresql.copy.PGCopyOutputStream) PGConnection(org.postgresql.PGConnection) KettleException(org.pentaho.di.core.exception.KettleException) SQLException(java.sql.SQLException)

Aggregations

PGCopyOutputStream (org.postgresql.copy.PGCopyOutputStream)3 PGConnection (org.postgresql.PGConnection)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Field (java.lang.reflect.Field)1 SQLException (java.sql.SQLException)1 KettleException (org.pentaho.di.core.exception.KettleException)1