long now = System.currentTimeMillis(); LOG.info("Flushing COPY batch for table " + name + " (size = " + baos.size() + ", total time = " + (now - start) + " ms, of which " + (now - beforeFlush) + " for flush)");
    protected void doInserts(String name, TableBatch table) throws SQLException {        String colNames[] = table.getColNames();        if ((colNames != null) && (!table.getIdsToInsert().isEmpty())) {            try {                CopyManager copyManager = null;                if (con instanceof PGConnection) {                    copyManager = ((PGConnection) con).getCopyAPI();                }                if (copyManager == null) {                    LOG.error("Database is incompatible with the PostgreSQL COPY command - falling"                            + " back to prepared statements");                    super.doInserts(name, table);                } else {                    ByteArrayOutputStream baos = new ByteArrayOutputStream();                    DataOutputStream dos = new DataOutputStream(baos);                    dos.writeBytes("PGCOPY\n");                    dos.writeByte(255);                    dos.writeBytes("\r\n");                    dos.writeByte(0); // Signature done                    dos.writeInt(0); // Flags - we aren't supplying OIDS                    dos.writeInt(0); // Length of header extension                    Iterator insertIter = table.getIdsToInsert().entrySet().iterator();                    while (insertIter.hasNext()) {                        Map.Entry insertEntry = (Map.Entry) insertIter.next();                        Object values[] = (Object[]) insertEntry.getValue();                        dos.writeShort(colNames.length);                        for (int i = 0; i < colNames.length; i++) {                            writeObject(dos, values[i]);                        }                    }                    StringBuffer sqlBuffer = new StringBuffer("COPY ").append(name).append(" (");                    for (int i = 0; i < colNames.length; i++) {                        if (i > 0) {                            sqlBuffer.append(", ");                        }                        sqlBuffer.append(colNames[i]);                    }                    sqlBuffer.append(") FROM STDIN BINARY");                    String sql = sqlBuffer.toString();                    dos.writeShort(-1);                    dos.flush();                    LOG.warn("Flushing COPY batch for table " + name + " (size = " + baos.size()                            + ")");                    copyManager.copyInQuery(sql, new ByteArrayInputStream(baos.toByteArray()));                    table.getIdsToInsert().clear();                }            } catch (IOException e) {                throw new SQLException(e.toString());            }        }    }