Skip to content

Commit 91899f0

Browse files
committed
Resolved a few lint warnings
1 parent fe6ca21 commit 91899f0

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ protected ResultSetImpl executeQueryImpl(String sql, QuerySettings settings) thr
155155
}
156156
ClickHouseBinaryFormatReader reader = connection.getClient().newBinaryFormatReader(response);
157157
if (reader.getSchema() == null) {
158+
reader.close();
158159
throw new SQLException("Called method expects empty or filled result set but query has returned none. Consider using `java.sql.Statement.execute(java.lang.String)`", ExceptionUtils.SQL_STATE_CLIENT_ERROR);
159160
}
160161
return new ResultSetImpl(this, response, reader);

jdbc-v2/src/test/java/com/clickhouse/jdbc/ConnectionTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void createAndCloseStatementTest() throws SQLException {
4444
pStmt.setString(1, "test string");
4545
conn.close();
4646
conn.close(); // check second attempt doesn't throw anything
47-
assertThrows(SQLException.class, () ->conn.createStatement());
47+
assertThrows(SQLException.class, conn::createStatement);
4848

4949
try {
5050
stmt.executeQuery("SELECT 1");
@@ -84,20 +84,17 @@ public void testCreateUnsupportedStatements() throws Throwable {
8484
() -> conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE),
8585
() -> conn.prepareStatement("SELECT 1", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY),
8686
() -> conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT),
87-
() -> conn.setSavepoint(),
87+
conn::setSavepoint,
8888
() -> conn.setSavepoint("save point"),
8989
() -> conn.createStruct("simple", null),
9090
};
9191

92-
int i = 0;
9392
for (Assert.ThrowingRunnable createStatement : createStatements) {
94-
System.out.println("Failed at pos " + (i));
9593
if (!flag) {
9694
Assert.assertThrows(SQLFeatureNotSupportedException.class, createStatement );
9795
} else {
9896
createStatement.run();
9997
}
100-
i++;
10198
}
10299
}
103100
}
@@ -145,8 +142,8 @@ public void setAutoCommitTest() throws SQLException {
145142
@Test(groups = { "integration" })
146143
public void testCommitRollback() throws SQLException {
147144
try (Connection localConnection = this.getJdbcConnection()) {
148-
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.commit());
149-
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.rollback());
145+
assertThrows(SQLFeatureNotSupportedException.class, localConnection::commit);
146+
assertThrows(SQLFeatureNotSupportedException.class, localConnection::rollback);
150147
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.rollback(null));
151148
}
152149

@@ -231,7 +228,7 @@ public void clearWarningsTest() throws SQLException {
231228
@Test(groups = { "integration" })
232229
public void getTypeMapTest() throws SQLException {
233230
Connection localConnection = this.getJdbcConnection();
234-
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.getTypeMap());
231+
assertThrows(SQLFeatureNotSupportedException.class, localConnection::getTypeMap);
235232
}
236233

237234
@Test(groups = { "integration" })
@@ -255,7 +252,7 @@ public void getHoldabilityTest() throws SQLException {
255252
@Test(groups = { "integration" })
256253
public void setSavepointTest() throws SQLException {
257254
Connection localConnection = this.getJdbcConnection();
258-
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.setSavepoint());
255+
assertThrows(SQLFeatureNotSupportedException.class, localConnection::setSavepoint);
259256
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.setSavepoint("savepoint-name"));
260257
}
261258

@@ -316,7 +313,6 @@ public void setAndGetClientInfoTest(String clientName) throws SQLException {
316313
try (ResultSet rs = stmt.executeQuery(logQuery)) {
317314
Assert.assertTrue(rs.next());
318315
String userAgent = rs.getString("http_user_agent");
319-
System.out.println(userAgent);
320316
if (clientName != null && !clientName.isEmpty()) {
321317
Assert.assertTrue(userAgent.startsWith(clientName), "Expected to start with '" + clientName + "' but value was '" + userAgent + "'");
322318
}
@@ -401,7 +397,7 @@ public void setNetworkTimeoutTest() throws SQLException {
401397
@Test(groups = { "integration" })
402398
public void getNetworkTimeoutTest() throws SQLException {
403399
Connection localConnection = this.getJdbcConnection();
404-
assertThrows(SQLFeatureNotSupportedException.class, () -> localConnection.getNetworkTimeout());
400+
assertThrows(SQLFeatureNotSupportedException.class, localConnection::getNetworkTimeout);
405401
}
406402

407403
@Test(groups = { "integration" })

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import com.clickhouse.client.api.ClientConfigProperties;
44
import com.clickhouse.client.api.internal.ServerSettings;
55
import com.clickhouse.client.api.query.GenericRecord;
6+
import com.clickhouse.data.ClickHouseVersion;
7+
import org.apache.commons.lang3.RandomStringUtils;
68
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
810
import org.testng.Assert;
9-
import com.clickhouse.data.ClickHouseVersion;
10-
import org.apache.commons.lang3.RandomStringUtils;
1111
import org.testng.annotations.DataProvider;
1212
import org.testng.annotations.Test;
1313

@@ -383,50 +383,50 @@ public void testSettingRole() throws SQLException {
383383
info.setProperty("password", userPass);
384384

385385
try (ConnectionImpl conn = new ConnectionImpl(getEndpointString(), info)) {
386-
GenericRecord record = conn.getClient().queryAll("SELECT currentRoles()").get(0);
387-
assertEquals(record.getList(1).size(), 0);
386+
GenericRecord dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
387+
assertEquals(dataRecord.getList(1).size(), 0);
388388

389389
try (Statement stmt = conn.createStatement()) {
390390
stmt.execute("SET ROLE role1");
391391
}
392392

393-
record = conn.getClient().queryAll("SELECT currentRoles()").get(0);
394-
assertEquals(record.getList(1).size(), 1);
395-
assertEquals(record.getList(1).get(0), "role1");
393+
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
394+
assertEquals(dataRecord.getList(1).size(), 1);
395+
assertEquals(dataRecord.getList(1).get(0), "role1");
396396

397397
try (Statement stmt = conn.createStatement()) {
398398
stmt.execute("SET ROLE role2");
399399
}
400400

401-
record = conn.getClient().queryAll("SELECT currentRoles()").get(0);
402-
assertEquals(record.getList(1).size(), 1);
403-
assertEquals(record.getList(1).get(0), "role2");
401+
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
402+
assertEquals(dataRecord.getList(1).size(), 1);
403+
assertEquals(dataRecord.getList(1).get(0), "role2");
404404

405405
try (Statement stmt = conn.createStatement()) {
406406
stmt.execute("SET ROLE NONE");
407407
}
408408

409-
record = conn.getClient().queryAll("SELECT currentRoles()").get(0);
410-
assertEquals(record.getList(1).size(), 0);
409+
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
410+
assertEquals(dataRecord.getList(1).size(), 0);
411411

412412
try (Statement stmt = conn.createStatement()) {
413413
stmt.execute("SET ROLE \"role1\",\"role2\"");
414414
}
415415

416-
record = conn.getClient().queryAll("SELECT currentRoles()").get(0);
417-
assertEquals(record.getList(1).size(), 2);
418-
assertEquals(record.getList(1).get(0), "role1");
419-
assertEquals(record.getList(1).get(1), "role2");
416+
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
417+
assertEquals(dataRecord.getList(1).size(), 2);
418+
assertEquals(dataRecord.getList(1).get(0), "role1");
419+
assertEquals(dataRecord.getList(1).get(1), "role2");
420420

421421
try (Statement stmt = conn.createStatement()) {
422422
stmt.execute("SET ROLE \"role1\",\"role2\",\"role3\"");
423423
}
424424

425-
record = conn.getClient().queryAll("SELECT currentRoles()").get(0);
426-
assertEquals(record.getList(1).size(), 3);
427-
assertEquals(record.getList(1).get(0), "role1");
428-
assertEquals(record.getList(1).get(1), "role2");
429-
assertEquals(record.getList(1).get(2), "role3");
425+
dataRecord = conn.getClient().queryAll("SELECT currentRoles()").get(0);
426+
assertEquals(dataRecord.getList(1).size(), 3);
427+
assertEquals(dataRecord.getList(1).get(0), "role1");
428+
assertEquals(dataRecord.getList(1).get(1), "role2");
429+
assertEquals(dataRecord.getList(1).get(2), "role3");
430430
}
431431
}
432432

0 commit comments

Comments
 (0)