@Test void testCopy() throws SQLException { var cryptoTransfers = new HashSet<CryptoTransfer>(); cryptoTransfers.add(cryptoTransfer(1)); cryptoTransfers.add(cryptoTransfer(2)); cryptoTransfers.add(cryptoTransfer(3)); var tokenTransfers = new HashSet<TokenTransfer>(); tokenTransfers.add(tokenTransfer(1)); tokenTransfers.add(tokenTransfer(2)); tokenTransfers.add(tokenTransfer(3)); cryptoTransferPgCopy.copy(cryptoTransfers, dataSource.getConnection()); tokenTransferPgCopy.copy(tokenTransfers, dataSource.getConnection()); assertThat(cryptoTransferRepository.findAll()).containsExactlyInAnyOrderElementsOf(cryptoTransfers); assertThat(tokenTransferRepository.findAll()).containsExactlyInAnyOrderElementsOf(tokenTransfers); }
public void copy(Collection<T> items, Connection connection) { if (items == null || items.isEmpty()) { return; } try { var reader = buildCsv(items); Stopwatch stopwatch = Stopwatch.createStarted(); CopyManager copyManager = connection.unwrap(PGConnection.class).getCopyAPI(); long rowsCount = copyManager.copyIn(sql, reader, properties.getBufferSize()); insertDurationMetric.record(stopwatch.elapsed()); log.info("Copied {} rows to {} table in {}", rowsCount, tableName, stopwatch); } catch (Exception e) { throw new ParserException(String.format("Error copying %d items to table %s", items.size(), tableName), e); } }
PgCopy { public void copy(Collection<T> items, Connection connection) { if (items == null || items.isEmpty()) { return; } try { var reader = buildCsv(items); Stopwatch stopwatch = Stopwatch.createStarted(); CopyManager copyManager = connection.unwrap(PGConnection.class).getCopyAPI(); long rowsCount = copyManager.copyIn(sql, reader, properties.getBufferSize()); insertDurationMetric.record(stopwatch.elapsed()); log.info("Copied {} rows to {} table in {}", rowsCount, tableName, stopwatch); } catch (Exception e) { throw new ParserException(String.format("Error copying %d items to table %s", items.size(), tableName), e); } } }
PgCopy { public void copy(Collection<T> items, Connection connection) { if (items == null || items.isEmpty()) { return; } try { var reader = buildCsv(items); Stopwatch stopwatch = Stopwatch.createStarted(); CopyManager copyManager = connection.unwrap(PGConnection.class).getCopyAPI(); long rowsCount = copyManager.copyIn(sql, reader, properties.getBufferSize()); insertDurationMetric.record(stopwatch.elapsed()); log.info("Copied {} rows to {} table in {}", rowsCount, tableName, stopwatch); } catch (Exception e) { throw new ParserException(String.format("Error copying %d items to table %s", items.size(), tableName), e); } } PgCopy(Class<T> entityClass, MeterRegistry meterRegistry, SqlProperties properties); }
PgCopy { public void copy(Collection<T> items, Connection connection) { if (items == null || items.isEmpty()) { return; } try { var reader = buildCsv(items); Stopwatch stopwatch = Stopwatch.createStarted(); CopyManager copyManager = connection.unwrap(PGConnection.class).getCopyAPI(); long rowsCount = copyManager.copyIn(sql, reader, properties.getBufferSize()); insertDurationMetric.record(stopwatch.elapsed()); log.info("Copied {} rows to {} table in {}", rowsCount, tableName, stopwatch); } catch (Exception e) { throw new ParserException(String.format("Error copying %d items to table %s", items.size(), tableName), e); } } PgCopy(Class<T> entityClass, MeterRegistry meterRegistry, SqlProperties properties); void copy(Collection<T> items, Connection connection); }
PgCopy { public void copy(Collection<T> items, Connection connection) { if (items == null || items.isEmpty()) { return; } try { var reader = buildCsv(items); Stopwatch stopwatch = Stopwatch.createStarted(); CopyManager copyManager = connection.unwrap(PGConnection.class).getCopyAPI(); long rowsCount = copyManager.copyIn(sql, reader, properties.getBufferSize()); insertDurationMetric.record(stopwatch.elapsed()); log.info("Copied {} rows to {} table in {}", rowsCount, tableName, stopwatch); } catch (Exception e) { throw new ParserException(String.format("Error copying %d items to table %s", items.size(), tableName), e); } } PgCopy(Class<T> entityClass, MeterRegistry meterRegistry, SqlProperties properties); void copy(Collection<T> items, Connection connection);  }