Skip to content

Commit 70b69cd

Browse files
committed
make statement instance variable
1 parent 985801b commit 70b69cd

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class BigQueryDatabaseMetaData implements DatabaseMetaData {
139139

140140
String URL;
141141
BigQueryConnection connection;
142+
Statement statement = null;
142143
private final BigQuery bigquery;
143144
private final int metadataFetchThreadCount;
144145
private static final AtomicReference<String> parsedDriverVersion = new AtomicReference<>(null);
@@ -147,7 +148,7 @@ class BigQueryDatabaseMetaData implements DatabaseMetaData {
147148
private static final AtomicReference<Integer> parsedDriverMinorVersion =
148149
new AtomicReference<>(null);
149150

150-
BigQueryDatabaseMetaData(BigQueryConnection connection) throws SQLException {
151+
BigQueryDatabaseMetaData(BigQueryConnection connection) {
151152
this.URL = connection.getConnectionUrl();
152153
this.connection = connection;
153154
this.bigquery = connection.getBigQuery();
@@ -2632,10 +2633,11 @@ Schema defineGetVersionColumnsSchema() {
26322633
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
26332634
String sql = readSqlFromFile(GET_PRIMARY_KEYS_SQL);
26342635
try {
2635-
Statement stmt = this.connection.createStatement();
2636-
stmt.closeOnCompletion();
2636+
if (this.statement == null) {
2637+
this.statement = this.connection.createStatement();
2638+
}
26372639
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
2638-
return stmt.executeQuery(formattedSql);
2640+
return this.statement.executeQuery(formattedSql);
26392641
} catch (SQLException e) {
26402642
throw new BigQueryJdbcException(e);
26412643
}
@@ -2646,10 +2648,11 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
26462648
throws SQLException {
26472649
String sql = readSqlFromFile(GET_IMPORTED_KEYS_SQL);
26482650
try {
2649-
Statement stmt = this.connection.createStatement();
2650-
stmt.closeOnCompletion();
2651+
if (this.statement == null) {
2652+
this.statement = this.connection.createStatement();
2653+
}
26512654
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
2652-
return stmt.executeQuery(formattedSql);
2655+
return this.statement.executeQuery(formattedSql);
26532656
} catch (SQLException e) {
26542657
throw new BigQueryJdbcException(e);
26552658
}
@@ -2660,10 +2663,11 @@ public ResultSet getExportedKeys(String catalog, String schema, String table)
26602663
throws SQLException {
26612664
String sql = readSqlFromFile(GET_EXPORTED_KEYS_SQL);
26622665
try {
2663-
Statement stmt = this.connection.createStatement();
2664-
stmt.closeOnCompletion();
2666+
if (this.statement == null) {
2667+
this.statement = this.connection.createStatement();
2668+
}
26652669
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
2666-
return stmt.executeQuery(formattedSql);
2670+
return this.statement.executeQuery(formattedSql);
26672671
} catch (SQLException e) {
26682672
throw new BigQueryJdbcException(e);
26692673
}
@@ -2680,8 +2684,9 @@ public ResultSet getCrossReference(
26802684
throws SQLException {
26812685
String sql = readSqlFromFile(GET_CROSS_REFERENCE_SQL);
26822686
try {
2683-
Statement stmt = this.connection.createStatement();
2684-
stmt.closeOnCompletion();
2687+
if (this.statement == null) {
2688+
this.statement = this.connection.createStatement();
2689+
}
26852690
String formattedSql =
26862691
replaceSqlParameters(
26872692
sql,
@@ -2691,7 +2696,7 @@ public ResultSet getCrossReference(
26912696
foreignCatalog,
26922697
foreignSchema,
26932698
foreignTable);
2694-
return stmt.executeQuery(formattedSql);
2699+
return this.statement.executeQuery(formattedSql);
26952700
} catch (SQLException e) {
26962701
throw new BigQueryJdbcException(e);
26972702
}

0 commit comments

Comments
 (0)