Skip to content

Commit

Permalink
chore: rename methods to avoid name clash
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Oct 12, 2024
1 parent 5c54696 commit 09b9524
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 85 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>sdk-platform-java-config</artifactId>
<version>3.36.1</version>
<version>3.37.0</version>
</parent>
<developers>
<developer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ private String createUrl() {
getPort(), "proj", "inst", "db" + (dialect == Dialect.POSTGRESQL ? "pg" : ""));
}

private Connection createConnection() throws SQLException {
@Override
protected Connection createJdbcConnection() throws SQLException {
return DriverManager.getConnection(createUrl());
}

@Test
public void testStatementTagInHint() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
try (ResultSet resultSet =
connection
.createStatement()
Expand All @@ -94,7 +95,7 @@ public void testStatementTagInHint() throws SQLException {

@Test
public void testRpcPriorityInHint() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
try (ResultSet resultSet =
connection
.createStatement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@ private String createUrl() {
getPort(), "proj", "inst", "db");
}

private Connection createConnection() throws SQLException {
@Override
protected Connection createJdbcConnection() throws SQLException {
return DriverManager.getConnection(createUrl());
}

@Test
public void testStatementExecuteQuery() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
try (ResultSet resultSet = statement.executeQuery(query)) {
verifyResultSet(resultSet);
Expand All @@ -231,7 +232,7 @@ public void testStatementExecuteQuery() throws SQLException {

@Test
public void testStatementExecuteUpdate() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
assertEquals(1, statement.executeUpdate(dml));
assertEquals(0, statement.executeUpdate(DDL));
Expand All @@ -249,7 +250,7 @@ public void testStatementExecuteUpdate() throws SQLException {

@Test
public void testStatementExecuteUpdateReturnGeneratedKeys() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
// TODO: Add tests for RETURN_GENERATED_KEYS when that is supported.
assertEquals(1, statement.executeUpdate(dml, Statement.NO_GENERATED_KEYS));
Expand All @@ -265,7 +266,7 @@ public void testStatementExecuteUpdateReturnGeneratedKeys() throws SQLException

@Test
public void testStatementExecuteUpdateReturnColumnNames() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
assertEquals(1, statement.executeUpdate(dml, new String[] {"id"}));
assertEquals(0, statement.executeUpdate(DDL, new String[] {"id"}));
Expand All @@ -283,7 +284,7 @@ public void testStatementExecuteUpdateReturnColumnNames() throws SQLException {

@Test
public void testStatementExecuteUpdateReturnColumnIndexes() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
assertEquals(1, statement.executeUpdate(dml, new int[] {1}));
assertEquals(0, statement.executeUpdate(DDL, new int[] {1}));
Expand All @@ -297,7 +298,7 @@ public void testStatementExecuteUpdateReturnColumnIndexes() throws SQLException

@Test
public void testStatementLargeExecuteUpdate() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
assertEquals(1L, statement.executeLargeUpdate(dml));
assertEquals(0L, statement.executeLargeUpdate(DDL));
Expand All @@ -311,7 +312,7 @@ public void testStatementLargeExecuteUpdate() throws SQLException {

@Test
public void testStatementExecuteLargeUpdateReturnGeneratedKeys() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
// TODO: Add tests for RETURN_GENERATED_KEYS when that is supported.
assertEquals(1, statement.executeLargeUpdate(dml, Statement.NO_GENERATED_KEYS));
Expand All @@ -329,7 +330,7 @@ public void testStatementExecuteLargeUpdateReturnGeneratedKeys() throws SQLExcep

@Test
public void testStatementExecuteLargeUpdateReturnColumnNames() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
assertEquals(1, statement.executeLargeUpdate(dml, new String[] {"id"}));
assertEquals(0, statement.executeLargeUpdate(DDL, new String[] {"id"}));
Expand All @@ -346,7 +347,7 @@ public void testStatementExecuteLargeUpdateReturnColumnNames() throws SQLExcepti

@Test
public void testStatementExecuteLargeUpdateReturnColumnIndexes() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
assertEquals(1, statement.executeLargeUpdate(dml, new int[] {1}));
assertEquals(0, statement.executeLargeUpdate(DDL, new int[] {1}));
Expand All @@ -360,7 +361,7 @@ public void testStatementExecuteLargeUpdateReturnColumnIndexes() throws SQLExcep

@Test
public void testStatementExecute() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
verifyUpdateCount(statement, () -> statement.execute(dml), 1L);
verifyUpdateCount(statement, () -> statement.execute(largeDml), LARGE_UPDATE_COUNT);
Expand All @@ -375,7 +376,7 @@ public void testStatementExecute() throws SQLException {

@Test
public void testStatementExecuteReturnGeneratedKeys() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
// TODO: Add tests for RETURN_GENERATED_KEYS when that is supported.
verifyUpdateCount(statement, () -> statement.execute(dml, Statement.NO_GENERATED_KEYS), 1L);
Expand All @@ -401,7 +402,7 @@ public void testStatementExecuteReturnGeneratedKeys() throws SQLException {

@Test
public void testStatementExecuteReturnColumnNames() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
verifyUpdateCount(statement, () -> statement.execute(dml, new String[] {"id"}), 1L);
verifyUpdateCount(
Expand All @@ -420,7 +421,7 @@ public void testStatementExecuteReturnColumnNames() throws SQLException {

@Test
public void testStatementExecuteReturnColumnIndexes() throws SQLException {
try (Connection connection = createConnection();
try (Connection connection = createJdbcConnection();
Statement statement = connection.createStatement()) {
verifyUpdateCount(statement, () -> statement.execute(dml, new int[] {1}), 1L);
verifyUpdateCount(
Expand All @@ -439,7 +440,7 @@ public void testStatementExecuteReturnColumnIndexes() throws SQLException {

@Test
public void testPreparedStatementExecuteQuery() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
try (ResultSet resultSet = connection.prepareStatement(query).executeQuery()) {
verifyResultSet(resultSet);
}
Expand All @@ -458,7 +459,7 @@ public void testPreparedStatementExecuteQuery() throws SQLException {

@Test
public void testPreparedStatementExecuteUpdate() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertEquals(1, connection.prepareStatement(dml).executeUpdate());
assertEquals(0, connection.prepareStatement(DDL).executeUpdate());
assertEquals(0, connection.prepareStatement(clientSideUpdate).executeUpdate());
Expand All @@ -472,7 +473,7 @@ public void testPreparedStatementExecuteUpdate() throws SQLException {

@Test
public void testPreparedStatementExecuteUpdateReturnGeneratedKeys() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
// TODO: Add tests for RETURN_GENERATED_KEYS when that is supported.
assertEquals(
1, connection.prepareStatement(dml, Statement.NO_GENERATED_KEYS).executeUpdate());
Expand Down Expand Up @@ -503,7 +504,7 @@ public void testPreparedStatementExecuteUpdateReturnGeneratedKeys() throws SQLEx

@Test
public void testPreparedStatementExecuteUpdateReturnColumnNames() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertEquals(1, connection.prepareStatement(dml, new String[] {"id"}).executeUpdate());
assertEquals(0, connection.prepareStatement(DDL, new String[] {"id"}).executeUpdate());
assertEquals(
Expand All @@ -523,7 +524,7 @@ public void testPreparedStatementExecuteUpdateReturnColumnNames() throws SQLExce

@Test
public void testPreparedStatementExecuteUpdateReturnColumnIndexes() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertEquals(1, connection.prepareStatement(dml, new int[] {1}).executeUpdate());
assertEquals(0, connection.prepareStatement(DDL, new int[] {1}).executeUpdate());
assertEquals(0, connection.prepareStatement(clientSideUpdate, new int[] {1}).executeUpdate());
Expand All @@ -539,7 +540,7 @@ public void testPreparedStatementExecuteUpdateReturnColumnIndexes() throws SQLEx

@Test
public void testPreparedStatementLargeExecuteUpdate() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertEquals(1L, connection.prepareStatement(dml).executeLargeUpdate());
assertEquals(0L, connection.prepareStatement(DDL).executeLargeUpdate());
assertEquals(0L, connection.prepareStatement(clientSideUpdate).executeLargeUpdate());
Expand All @@ -554,7 +555,7 @@ public void testPreparedStatementLargeExecuteUpdate() throws SQLException {

@Test
public void testPreparedStatementExecuteLargeUpdateReturnGeneratedKeys() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
// TODO: Add tests for RETURN_GENERATED_KEYS when that is supported.
assertEquals(
1, connection.prepareStatement(dml, Statement.NO_GENERATED_KEYS).executeLargeUpdate());
Expand Down Expand Up @@ -587,7 +588,7 @@ public void testPreparedStatementExecuteLargeUpdateReturnGeneratedKeys() throws

@Test
public void testPreparedStatementExecuteLargeUpdateReturnColumnNames() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertEquals(1, connection.prepareStatement(dml, new String[] {"id"}).executeLargeUpdate());
assertEquals(0, connection.prepareStatement(DDL, new String[] {"id"}).executeLargeUpdate());
assertEquals(
Expand All @@ -612,7 +613,7 @@ public void testPreparedStatementExecuteLargeUpdateReturnColumnNames() throws SQ

@Test
public void testPreparedStatementExecuteLargeUpdateReturnColumnIndexes() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertEquals(1, connection.prepareStatement(dml, new int[] {1}).executeLargeUpdate());
assertEquals(0, connection.prepareStatement(DDL, new int[] {1}).executeLargeUpdate());
assertEquals(
Expand All @@ -631,7 +632,7 @@ public void testPreparedStatementExecuteLargeUpdateReturnColumnIndexes() throws

@Test
public void testPreparedStatementExecute() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
verifyPreparedUpdateCount(connection.prepareStatement(dml), PreparedStatement::execute, 1L);
verifyPreparedUpdateCount(
connection.prepareStatement(largeDml), PreparedStatement::execute, LARGE_UPDATE_COUNT);
Expand All @@ -651,7 +652,7 @@ public void testPreparedStatementExecute() throws SQLException {

@Test
public void testPreparedStatementExecuteReturnGeneratedKeys() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
// TODO: Add tests for RETURN_GENERATED_KEYS when that is supported.
verifyPreparedUpdateCount(
connection.prepareStatement(dml, Statement.NO_GENERATED_KEYS),
Expand Down Expand Up @@ -683,7 +684,7 @@ public void testPreparedStatementExecuteReturnGeneratedKeys() throws SQLExceptio

@Test
public void testPreparedStatementExecuteReturnColumnNames() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
verifyPreparedUpdateCount(
connection.prepareStatement(dml, new String[] {"id"}), PreparedStatement::execute, 1L);
verifyPreparedUpdateCount(
Expand Down Expand Up @@ -711,7 +712,7 @@ public void testPreparedStatementExecuteReturnColumnNames() throws SQLException

@Test
public void testPreparedStatementExecuteReturnColumnIndexes() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
verifyPreparedUpdateCount(
connection.prepareStatement(dml, new int[] {1}), PreparedStatement::execute, 1L);
verifyPreparedUpdateCount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ private String createUrl() {
getPort(), "proj", "inst", "db" + (dialect == Dialect.POSTGRESQL ? "pg" : ""));
}

private Connection createConnection() throws SQLException {
@Override
protected Connection createJdbcConnection() throws SQLException {
return DriverManager.getConnection(createUrl());
}

@Test
public void testUsesMultiplexedSessionForQueryInAutoCommit() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertTrue(connection.getAutoCommit());
try (ResultSet resultSet = connection.createStatement().executeQuery(SELECT_RANDOM_SQL)) {
//noinspection StatementWithEmptyBody
Expand All @@ -106,7 +107,7 @@ public void testUsesMultiplexedSessionForQueryInAutoCommit() throws SQLException
@Test
public void testUsesMultiplexedSessionForQueryInReadOnlyTransaction() throws SQLException {
int numQueries = 2;
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
connection.setReadOnly(true);
connection.setAutoCommit(false);

Expand Down Expand Up @@ -137,7 +138,7 @@ public void testUsesMultiplexedSessionForQueryInReadOnlyTransaction() throws SQL

@Test
public void testUsesRegularSessionForDmlInAutoCommit() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
assertTrue(connection.getAutoCommit());
assertEquals(1, connection.createStatement().executeUpdate(INSERT_SQL));
}
Expand All @@ -158,7 +159,7 @@ public void testUsesRegularSessionForDmlInAutoCommit() throws SQLException {

@Test
public void testUsesRegularSessionForQueryInTransaction() throws SQLException {
try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
connection.setAutoCommit(false);
assertFalse(connection.getAutoCommit());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ private String createUrl() {
getPort(), "proj", "inst", "db");
}

private Connection createConnection() throws SQLException {
@Override
protected Connection createJdbcConnection() throws SQLException {
return DriverManager.getConnection(createUrl());
}

Expand All @@ -103,7 +104,7 @@ public void testPartitionedQueryUsingSql() throws SQLException {
mockSpanner.putStatementResult(StatementResult.query(statement, generator.generate()));
String prefix = dialect == Dialect.POSTGRESQL ? "spanner." : "";

try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
// This will automatically enable Data Boost for any partitioned query that is executed on
// this connection. The property is ignored for any query that is not a partitioned query.
connection.createStatement().execute(String.format("set %sdata_boost_enabled=true", prefix));
Expand Down Expand Up @@ -199,7 +200,7 @@ public void testPartitionedQueryStatement() throws SQLException {
Statement statement = Statement.of("select * from my_table where active=true");
mockSpanner.putStatementResult(StatementResult.query(statement, generator.generate()));

try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
CloudSpannerJdbcConnection cloudSpannerJdbcConnection =
connection.unwrap(CloudSpannerJdbcConnection.class);
// This will automatically enable Data Boost for any partitioned query that is executed on
Expand Down Expand Up @@ -288,7 +289,7 @@ public void testPartitionedQueryPreparedStatement() throws SQLException {
.build();
mockSpanner.putStatementResult(StatementResult.query(statement, generator.generate()));

try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
CloudSpannerJdbcConnection cloudSpannerJdbcConnection =
connection.unwrap(CloudSpannerJdbcConnection.class);
// This will automatically enable Data Boost for any partitioned query that is executed on
Expand Down Expand Up @@ -372,7 +373,7 @@ public void testAutoPartitionMode() throws SQLException {
Statement statement = Statement.of("select * from my_table where active=true");
mockSpanner.putStatementResult(StatementResult.query(statement, generator.generate()));

try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
CloudSpannerJdbcConnection cloudSpannerJdbcConnection =
connection.unwrap(CloudSpannerJdbcConnection.class);
// This will automatically enable Data Boost for any partitioned query that is executed on
Expand Down Expand Up @@ -478,7 +479,7 @@ public void testAutoPartitionModeEmptyResult() throws SQLException {
Statement statement = Statement.of("select * from my_table where active=true");
mockSpanner.putStatementResult(StatementResult.query(statement, generator.generate()));

try (Connection connection = createConnection()) {
try (Connection connection = createJdbcConnection()) {
CloudSpannerJdbcConnection cloudSpannerJdbcConnection =
connection.unwrap(CloudSpannerJdbcConnection.class);
// This will automatically enable Data Boost for any partitioned query that is executed on
Expand Down
Loading

0 comments on commit 09b9524

Please sign in to comment.