Skip to content

Commit bf72a69

Browse files
committed
fix checkClosed usage
1 parent 5de61a8 commit bf72a69

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,16 +927,14 @@ public void setHoldability(int holdability) throws SQLException {
927927
@Override
928928
public void close() throws SQLException {
929929
try {
930-
BigQueryJdbcMdc.registerInstance(this, this.connectionId);
931-
LOG.finest("++enter++");
932-
LOG.fine("Closing Connection " + this);
933-
// TODO(neenu-postMVP): Release all connection state objects
934-
// check for and close all existing transactions
935-
936930
if (isClosed()) {
937931
return;
938932
}
939933

934+
BigQueryJdbcMdc.registerInstance(this, this.connectionId);
935+
LOG.finest("++enter++");
936+
LOG.fine("Closing Connection " + this);
937+
940938
try {
941939
if (this.bigQueryReadClient != null) {
942940
this.bigQueryReadClient.shutdown();
@@ -977,6 +975,7 @@ public boolean isClosed() {
977975

978976
private void checkClosed() {
979977
if (isClosed()) {
978+
LOG.severe("This " + getClass().getName() + " has been closed");
980979
throw new IllegalStateException("This " + getClass().getName() + " has been closed");
981980
}
982981
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ private BigQuerySettings generateBigQuerySettings() {
235235
*/
236236
@Override
237237
public ResultSet executeQuery(String sql) throws SQLException {
238+
checkClosed();
238239
try {
239240
BigQueryJdbcMdc.registerInstance(this.connection, this.connectionId);
240241
// TODO: write method to return state variables to original state.
@@ -262,6 +263,7 @@ public ResultSet executeQuery(String sql) throws SQLException {
262263

263264
@Override
264265
public long executeLargeUpdate(String sql) throws SQLException {
266+
checkClosed();
265267
try {
266268
BigQueryJdbcMdc.registerInstance(this.connection, this.connectionId);
267269
LOG.finest("++enter++");
@@ -306,6 +308,7 @@ int checkUpdateCount(long updateCount) {
306308

307309
@Override
308310
public boolean execute(String sql) throws SQLException {
311+
checkClosed();
309312
try {
310313
BigQueryJdbcMdc.registerInstance(this.connection, this.connectionId);
311314
LOG.finest("++enter++");
@@ -385,12 +388,12 @@ QueryStatistics getQueryStatistics(QueryJobConfiguration queryJobConfiguration)
385388
*/
386389
@Override
387390
public void close() throws SQLException {
391+
if (isClosed()) {
392+
return;
393+
}
388394
try {
389395
BigQueryJdbcMdc.registerInstance(this.connection, this.connectionId);
390396
LOG.fine("Closing Statement %s.", this);
391-
if (isClosed()) {
392-
return;
393-
}
394397

395398
boolean cancelSucceeded = false;
396399
try {
@@ -1571,6 +1574,7 @@ protected void logQueryExecutionStart(String sql) {
15711574
/** Throws a {@link BigQueryJdbcException} if this object is closed */
15721575
void checkClosed() throws SQLException {
15731576
if (isClosed()) {
1577+
LOG.severe("This " + getClass().getName() + " has been closed");
15741578
throw new BigQueryJdbcException("This " + getClass().getName() + " has been closed");
15751579
}
15761580
}

0 commit comments

Comments
 (0)