@Test void throwsParserException() throws SQLException, IOException { CopyManager copyManager = mock(CopyManager.class); doThrow(SQLException.class).when(copyManager).copyIn(any(), (Reader) any(), anyInt()); PGConnection pgConnection = mock(PGConnection.class); doReturn(copyManager).when(pgConnection).getCopyAPI(); DataSource dataSource = mock(DataSource.class); Connection conn = mock(Connection.class); doReturn(conn).when(dataSource).getConnection(); doReturn(pgConnection).when(conn).unwrap(any()); var cryptoTransferPgCopy2 = new PgCopy<>(CryptoTransfer.class, meterRegistry, sqlProperties); var cryptoTransfers = new HashSet<CryptoTransfer>(); cryptoTransfers.add(cryptoTransfer(1)); assertThatThrownBy(() -> cryptoTransferPgCopy2.copy(cryptoTransfers, dataSource.getConnection())) .isInstanceOf(ParserException.class); }
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);  }