/** * Use COPY FROM STDIN for very fast copying from a Reader into a database table. * * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon reader or database connection failure */ public long copyIn(final String sql, Reader from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Use COPY FROM STDIN for very fast copying from an InputStream into a database table. * * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon input stream or database connection failure */ public long copyIn(final String sql, InputStream from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Use COPY FROM STDIN for very fast copying from an InputStream into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon input stream or database connection failure */ public long copyIn(final String sql, InputStream from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Use COPY FROM STDIN for very fast copying from a Reader into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon reader or database connection failure */ public long copyIn(final String sql, Reader from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Uses given connection for specified COPY FROM STDIN operation. * * @param connection database connection to use for copying (protocol version 3 required) * @param sql COPY FROM STDIN statement * @param bufferSize try to send this many bytes at a time * @throws SQLException if initializing the operation fails */ public PGCopyOutputStream(PGConnection connection, String sql, int bufferSize) throws SQLException { this(connection.getCopyAPI().copyIn(sql), bufferSize); }
/** * Uses given connection for specified COPY FROM STDIN operation * @param connection database connection to use for copying (protocol version 3 required) * @param sql COPY FROM STDIN statement * @param bufferSize try to send this many bytes at a time * @throws SQLException if initializing the operation fails */ public PGCopyOutputStream(PGConnection connection, String sql, int bufferSize) throws SQLException { this(connection.getCopyAPI().copyIn(sql), bufferSize); }
copyManager.copyIn("COPY t FROM STDIN", fileReader );
/** * Use COPY FROM STDIN for very fast copying from an InputStream into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @param bufferSize number of bytes to buffer and push over network to server at once * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon input stream or database connection failure */ public long copyIn(final String sql, InputStream from, int bufferSize) throws SQLException, IOException { byte[] buf = new byte[bufferSize]; int len; CopyIn cp = copyIn(sql); try { while( (len = from.read(buf)) > 0 ) { cp.writeToCopy(buf, 0, len); } return cp.endCopy(); } finally { // see to it that we do not leave the connection locked if(cp.isActive()) cp.cancelCopy(); } } }
/** * Use COPY FROM STDIN for very fast copying from a Reader into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @param bufferSize number of characters to buffer and push over network to server at once * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon reader or database connection failure */ public long copyIn(final String sql, Reader from, int bufferSize) throws SQLException, IOException { char[] cbuf = new char[bufferSize]; int len; CopyIn cp = copyIn(sql); try { while ( (len = from.read(cbuf)) > 0) { byte[] buf = encoding.encode(new String(cbuf, 0, len)); cp.writeToCopy(buf, 0, buf.length); } return cp.endCopy(); } finally { // see to it that we do not leave the connection locked if(cp.isActive()) cp.cancelCopy(); } }
/** * Use COPY FROM STDIN for very fast copying from a Reader into a database table. * * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @param bufferSize number of characters to buffer and push over network to server at once * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon reader or database connection failure */ public long copyIn(final String sql, Reader from, int bufferSize) throws SQLException, IOException { char[] cbuf = new char[bufferSize]; int len; CopyIn cp = copyIn(sql); try { while ((len = from.read(cbuf)) >= 0) { if (len > 0) { byte[] buf = encoding.encode(new String(cbuf, 0, len)); cp.writeToCopy(buf, 0, buf.length); } } return cp.endCopy(); } finally { // see to it that we do not leave the connection locked if (cp.isActive()) { cp.cancelCopy(); } } }
/** * Use COPY FROM STDIN for very fast copying from an InputStream into a database table. * * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @param bufferSize number of bytes to buffer and push over network to server at once * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon input stream or database connection failure */ public long copyIn(final String sql, InputStream from, int bufferSize) throws SQLException, IOException { byte[] buf = new byte[bufferSize]; int len; CopyIn cp = copyIn(sql); try { while ((len = from.read(buf)) >= 0) { if (len > 0) { cp.writeToCopy(buf, 0, len); } } return cp.endCopy(); } finally { // see to it that we do not leave the connection locked if (cp.isActive()) { cp.cancelCopy(); } } } }
/** * Use COPY FROM STDIN for very fast copying from an InputStream into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon input stream or database connection failure */ public long copyIn(final String sql, InputStream from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Use COPY FROM STDIN for very fast copying from a Reader into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon reader or database connection failure */ public long copyIn(final String sql, Reader from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Use COPY FROM STDIN for very fast copying from an InputStream into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon input stream or database connection failure */ public long copyIn(final String sql, InputStream from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Use COPY FROM STDIN for very fast copying from a Reader into a database table. * @param sql COPY FROM STDIN statement * @param from a CSV file or such * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage issues * @throws IOException upon reader or database connection failure */ public long copyIn(final String sql, Reader from) throws SQLException, IOException { return copyIn(sql, from, DEFAULT_BUFFER_SIZE); }
/** * Uses given connection for specified COPY FROM STDIN operation * @param connection database connection to use for copying (protocol version 3 required) * @param sql COPY FROM STDIN statement * @param bufferSize try to send this many bytes at a time * @throws SQLException if initializing the operation fails */ public PGCopyOutputStream(PGConnection connection, String sql, int bufferSize) throws SQLException { this(connection.getCopyAPI().copyIn(sql), bufferSize); }
/** * Uses given connection for specified COPY FROM STDIN operation * @param connection database connection to use for copying (protocol version 3 required) * @param sql COPY FROM STDIN statement * @param bufferSize try to send this many bytes at a time * @throws SQLException if initializing the operation fails */ public PGCopyOutputStream(PGConnection connection, String sql, int bufferSize) throws SQLException { this(connection.getCopyAPI().copyIn(sql), bufferSize); }
private void executeCopy(CopyManager copyManager, String copyStatement, final StringBuilder sb) throws SQLException, IOException { Reader reader = new StringBuilderReader(sb); copyManager.copyIn(copyStatement, reader); sb.delete(0, sb.length()); }
SessionFactory factory = HibernateUtil.getSessionFactory(); Session session = factory.openSession(); SessionImplementor sessImpl = (SessionImplementor) session; Connection conn = null; conn = sessImpl.getJdbcConnectionAccess().obtainConnection(); CopyManager copyManager = new CopyManager((BaseConnection) conn); File tf =File.createTempFile("temp-file", "tmp"); String tempPath =tf.getParent(); File tempFile = new File(tempPath + File.separator + filename); FileReader fileReader = new FileReader(tempFile); copyManager.copyIn("copy testdata (col1, col2, col3) from STDIN with csv", fileReader );
public synchronized long copyFromReader(TableSchema tableSchema, Reader reader) { try { String query = tableSchema.copyFromStdin(); CopyManager copyManager = new CopyManager((BaseConnection) currentConnection); long numRows = copyManager.copyIn(query, reader); return numRows; } catch (Exception e) { throw new EmissionException(e); } }