public long endCopy() throws SQLException { if (at > 0) { op.writeToCopy(copyBuffer, 0, at); } op.endCopy(); return getHandledRowCount(); }
public long endCopy() throws SQLException { if(at > 0) { op.writeToCopy(copyBuffer, 0, at); } op.endCopy(); return getHandledRowCount(); }
/** * 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 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 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) { 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(); } } }
public long endCopy() throws SQLException { if(at > 0) { op.writeToCopy(copyBuffer, 0, at); } op.endCopy(); return getHandledRowCount(); }
public long endCopy() throws SQLException { if(at > 0) { op.writeToCopy(copyBuffer, 0, at); } op.endCopy(); return getHandledRowCount(); }
/** * 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) { 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 ) { 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(); } } }
// your code CopyManager copyManager = new CopyManager((BaseConnection) new DataSource().connect()); FileReader from = ... // different name! int bufferSize = 65536; // here starts the copy of the driver's implementation of the copyIn() method. char[] cbuf = new char[bufferSize]; int len; // if you store the instance of the CopyIn interface in an instance variable you // should be able to call cancelCopy() on it CopyIn cp = copyManager.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(); }
protected void endCopy() { if (copyIn != null) { try { flush(); } finally { try { copyIn.endCopy(); } catch (Exception ex) { throw getPlatform().getSqlTemplate().translate(ex); } finally { copyIn = null; } } } }