|
| 1 | +package com.clickhouse.benchmark.clients; |
| 2 | + |
| 3 | +import org.openjdk.jmh.annotations.Benchmark; |
| 4 | +import org.openjdk.jmh.infra.Blackhole; |
| 5 | +import org.slf4j.Logger; |
| 6 | +import org.slf4j.LoggerFactory; |
| 7 | + |
| 8 | +import java.sql.Connection; |
| 9 | +import java.sql.ResultSet; |
| 10 | +import java.sql.SQLException; |
| 11 | +import java.sql.Statement; |
| 12 | + |
| 13 | +import static com.clickhouse.benchmark.BenchmarkRunner.getSelectQuery; |
| 14 | + |
| 15 | +public class JDBCQuery extends BenchmarkBase { |
| 16 | + private static final Logger LOGGER = LoggerFactory.getLogger(JDBCQuery.class); |
| 17 | + void selectData(Connection connection, DataState dataState, Blackhole blackhole) throws SQLException { |
| 18 | + String sql = getSelectQuery(dataState.tableNameFilled); |
| 19 | + try (Statement stmt = connection.createStatement()) { |
| 20 | + try (ResultSet rs = stmt.executeQuery(sql)) { |
| 21 | + while (rs.next()) { |
| 22 | + for (int i = 1; i <= dataState.dataSet.getSchema().getColumns().size(); i++) { |
| 23 | + blackhole.consume(rs.getObject(i)); |
| 24 | + } |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + @Benchmark |
| 31 | + public void selectJDBCV1(DataState dataState, Blackhole blackhole) throws SQLException { |
| 32 | + selectData(jdbcV1, dataState, blackhole); |
| 33 | + } |
| 34 | + |
| 35 | + @Benchmark |
| 36 | + public void selectJDBCV2(DataState dataState, Blackhole blackhole) throws SQLException { |
| 37 | + selectData(jdbcV2, dataState, blackhole); |
| 38 | + } |
| 39 | + |
| 40 | +} |
0 commit comments