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;
}
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);
}
}
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);
}
}
Aggregations