Examples of PGCopyOutputStream


Examples of org.postgresql.copy.PGCopyOutputStream

    @Test
    public void testWriteNodes() throws IOException, SQLException {
        KiWiConnection con = store.getPersistence().getConnection();

        PGCopyOutputStream out = new PGCopyOutputStream(PGCopyUtil.getWrappedConnection(con.getJDBCConnection()), "COPY nodes FROM STDIN (FORMAT csv)");

        long start = System.currentTimeMillis();

        List<KiWiNode> nodes = new ArrayList<>(10000);

        nodes.add(TYPE_INT);
        nodes.add(TYPE_DBL);
        nodes.add(TYPE_BOOL);
        nodes.add(TYPE_DATE);
        nodes.add(EMPTY);

        // randomly create 10000 nodes
        for(int i=0; i<10000; i++) {
            nodes.add(randomObject());
        }

        // flush out nodes
        PGCopyUtil.flushNodes(nodes, out);

        out.close();

        long imported = System.currentTimeMillis();

        log.info("imported {} nodes in {} ms", nodes.size(), imported-start);
View Full Code Here

Examples of org.postgresql.copy.PGCopyOutputStream

    @Override
    protected void flushBacklogInternal() throws SQLException {
        try {
            // flush out nodes
            PGCopyOutputStream nodesOut = new PGCopyOutputStream(PGCopyUtil.getWrappedConnection(connection.getJDBCConnection()), "COPY nodes FROM STDIN (FORMAT csv)");
            PGCopyUtil.flushNodes(nodeBacklog, nodesOut);
            nodesOut.close();

            // flush out triples
            PGCopyOutputStream triplesOut = new PGCopyOutputStream(PGCopyUtil.getWrappedConnection(connection.getJDBCConnection()), "COPY triples FROM STDIN (FORMAT csv)");
            PGCopyUtil.flushTriples(tripleBacklog, triplesOut);
            triplesOut.close();
        } catch (IOException ex) {
            throw new SQLException("error while flushing out data",ex);
        }
    }
View Full Code Here

Examples of org.postgresql.copy.PGCopyOutputStream

  }
 
  @Override
  public void write(ILineReceiver receiver) {
    logger.info(writerID + ": insert SQL - " + sql);
    PGCopyOutputStream outputStream = null;
    try {
      outputStream = new PGCopyOutputStream((PGConnection) ((DelegatingConnection) conn).getInnermostDelegate(), sql);
      while(true){
        if(fetchLine(receiver, outputStream) == -1){
          break;
        }
      }
      outputStream.flushCopy();
      getMonitor().increaseSuccessLine(sucLineCounter);
      getMonitor().increaseFailedLines(failedLineCounter);
    } catch (Exception e) {
      logger.error(writerID + ": write to greenplum failed.");
      throw throwException(e)
    }
    finally{
      if(outputStream != null) {
        try {
          outputStream.close();
        } catch (IOException e) {
          throw throwException(e)
        }
      }
      this.logger.info(writerID + ": write to greenplum ends .");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.