@@ -592,7 +592,7 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
592592 return prepareStatement (sql );
593593 }
594594
595- public DatasetId getDefaultDataset () {
595+ public DatasetId getDefaultDataset () throws BigQueryJdbcException {
596596 checkClosed ();
597597 return this .defaultDataset ;
598598 }
@@ -613,12 +613,12 @@ String getKmsKeyName() {
613613 return this .kmsKeyName ;
614614 }
615615
616- public String getLocation () {
616+ public String getLocation () throws BigQueryJdbcException {
617617 checkClosed ();
618618 return this .location ;
619619 }
620620
621- public Map <String , String > getAuthProperties () {
621+ public Map <String , String > getAuthProperties () throws BigQueryJdbcException {
622622 checkClosed ();
623623 return this .authProperties ;
624624 }
@@ -678,7 +678,7 @@ SessionState getSessionStateSnapshot() {
678678 * For more information about transactions in BigQuery, see <a
679679 * href="https://cloud.google.com/bigquery/docs/transactions">Multi-statement transactions</a>.
680680 */
681- private void beginTransaction () {
681+ private void beginTransaction () throws BigQueryJdbcException {
682682 LOG .finer ("++enter++" );
683683 SessionState snapshot = this .sessionState .get ();
684684 QueryJobConfiguration .Builder transactionBeginJobConfig =
@@ -696,7 +696,8 @@ private void beginTransaction() {
696696 initSessionInfo (transactionResult .getSessionInfo ().getSessionId ());
697697 this .transactionStarted = true ;
698698 } catch (InterruptedException ex ) {
699- throw new BigQueryJdbcRuntimeException ("Failed to begin transaction" , ex );
699+ Thread .currentThread ().interrupt ();
700+ throw new BigQueryJdbcException ("Failed to begin transaction" , ex );
700701 }
701702 }
702703
@@ -930,7 +931,7 @@ public void clearWarnings() {
930931 }
931932
932933 @ Override
933- public boolean getAutoCommit () {
934+ public boolean getAutoCommit () throws SQLException {
934935 checkClosed ();
935936 return this .autoCommit ;
936937 }
@@ -954,16 +955,13 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
954955 }
955956
956957 @ Override
957- public void commit () {
958+ public void commit () throws SQLException {
958959 checkClosed ();
959960 checkIfEnabledSession ("commit" );
960961 if (!isTransactionStarted ()) {
961- IllegalStateException ex =
962- new IllegalStateException (
963- "Cannot commit without an active transaction. Please set setAutoCommit to false to start"
964- + " a transaction." );
965- LOG .severe (ex .getMessage (), ex );
966- throw ex ;
962+ throw new BigQueryJdbcException (
963+ "Cannot commit without an active transaction. Please set setAutoCommit to false to start"
964+ + " a transaction." );
967965 }
968966 commitTransaction ();
969967 if (!getAutoCommit ()) {
@@ -976,12 +974,9 @@ public void rollback() throws SQLException {
976974 checkClosed ();
977975 checkIfEnabledSession ("rollback" );
978976 if (!isTransactionStarted ()) {
979- IllegalStateException ex =
980- new IllegalStateException (
981- "Cannot rollback without an active transaction. Please set setAutoCommit to false to"
982- + " start a transaction." );
983- LOG .severe (ex .getMessage (), ex );
984- throw ex ;
977+ throw new BigQueryJdbcException (
978+ "Cannot rollback without an active transaction. Please set setAutoCommit to false to"
979+ + " start a transaction." );
985980 }
986981 rollbackImpl ();
987982 }
@@ -999,8 +994,11 @@ private void rollbackImpl() throws SQLException {
999994 if (!getAutoCommit ()) {
1000995 beginTransaction ();
1001996 }
1002- } catch (InterruptedException | BigQueryException ex ) {
997+ } catch (BigQueryException ex ) {
1003998 throw new BigQueryJdbcException ("Failed to rollback transaction" , ex );
999+ } catch (InterruptedException ex ) {
1000+ Thread .currentThread ().interrupt ();
1001+ throw new BigQueryJdbcException ("Interrupted during rollback transaction" , ex );
10041002 }
10051003 }
10061004
@@ -1103,10 +1101,19 @@ private void closeImpl() throws SQLException {
11031101
11041102 SessionState snapshot = this .sessionState .get ();
11051103 if (snapshot .sessionInfo != null && snapshot .createdByDriver ) {
1106- abortSession (snapshot );
1104+ try {
1105+ abortSession (snapshot );
1106+ } catch (SQLException e ) {
1107+ if (exceptionToThrow == null ) {
1108+ exceptionToThrow = e ;
1109+ } else {
1110+ exceptionToThrow .addSuppressed (e );
1111+ }
1112+ }
11071113 }
11081114
11091115 boolean interrupted = Thread .currentThread ().isInterrupted ();
1116+ InterruptedException terminationInterruptedException = null ;
11101117
11111118 try {
11121119 if (this .bigQueryReadClient != null ) {
@@ -1135,6 +1142,7 @@ private void closeImpl() throws SQLException {
11351142 }
11361143 } catch (InterruptedException e ) {
11371144 interrupted = true ;
1145+ terminationInterruptedException = e ;
11381146 if (this .bigQueryReadClient != null ) {
11391147 this .bigQueryReadClient .shutdownNow ();
11401148 }
@@ -1161,23 +1169,31 @@ private void closeImpl() throws SQLException {
11611169
11621170 if (interrupted ) {
11631171 Thread .currentThread ().interrupt ();
1164- throw new InterruptedException ("Interrupted awaiting executor termination" );
1172+ }
1173+ if (terminationInterruptedException != null ) {
1174+ BigQueryJdbcException interruptedException =
1175+ new BigQueryJdbcException ("Interrupted during close" , terminationInterruptedException );
1176+ if (exceptionToThrow == null ) {
1177+ exceptionToThrow = interruptedException ;
1178+ } else {
1179+ exceptionToThrow .addSuppressed (interruptedException );
1180+ }
11651181 }
11661182 } catch (ConcurrentModificationException ex ) {
11671183 throw new BigQueryJdbcException ("Concurrent modification during close" , ex );
1168- } catch (InterruptedException e ) {
1169- throw new BigQueryJdbcRuntimeException ("Interrupted during close" , e );
11701184 } finally {
11711185 BigQueryJdbcMdc .clear ();
11721186 BigQueryJdbcRootLogger .closeConnectionHandler (this .connectionId );
11731187 BigQueryJdbcOpenTelemetry .unregisterConnection (this .connectionId );
11741188 BigQueryJdbcOpenTelemetry .releaseSdk (this .openTelemetry );
11751189 this .openTelemetry = null ;
11761190 }
1191+
1192+ this .isClosed = true ;
1193+
11771194 if (exceptionToThrow != null ) {
11781195 throw exceptionToThrow ;
11791196 }
1180- this .isClosed = true ;
11811197 }
11821198
11831199 ExecutorService getExecutorService () {
@@ -1193,22 +1209,16 @@ public boolean isClosed() {
11931209 return this .isClosed ;
11941210 }
11951211
1196- private void checkClosed () {
1212+ private void checkClosed () throws BigQueryJdbcException {
11971213 if (isClosed ()) {
1198- IllegalStateException ex =
1199- new IllegalStateException ("This " + getClass ().getName () + " has been closed" );
1200- LOG .severe (ex .getMessage (), ex );
1201- throw ex ;
1214+ throw new BigQueryJdbcException ("This " + getClass ().getName () + " has been closed" );
12021215 }
12031216 }
12041217
1205- private void checkIfEnabledSession (String methodName ) {
1218+ private void checkIfEnabledSession (String methodName ) throws BigQueryJdbcException {
12061219 if (!this .enableSession ) {
1207- IllegalStateException ex =
1208- new IllegalStateException (
1209- String .format ("Session needs to be enabled to use %s method." , methodName ));
1210- LOG .severe (ex .getMessage (), ex );
1211- throw ex ;
1220+ throw new BigQueryJdbcException (
1221+ String .format ("Session needs to be enabled to use %s method." , methodName ));
12121222 }
12131223 }
12141224
@@ -1519,7 +1529,7 @@ RetrySettings getRetrySettings() {
15191529 return retrySettingsBuilder == null ? null : retrySettingsBuilder .build ();
15201530 }
15211531
1522- private void commitTransaction () {
1532+ private void commitTransaction () throws BigQueryJdbcException {
15231533 try {
15241534 QueryJobConfiguration transactionCommitJobConfig =
15251535 QueryJobConfiguration .newBuilder ("COMMIT TRANSACTION;" )
@@ -1530,11 +1540,12 @@ private void commitTransaction() {
15301540 commitJob .waitFor ();
15311541 this .transactionStarted = false ;
15321542 } catch (InterruptedException ex ) {
1533- throw new BigQueryJdbcRuntimeException ("Interrupted during commitTransaction" , ex );
1543+ Thread .currentThread ().interrupt ();
1544+ throw new BigQueryJdbcException ("Interrupted during commitTransaction" , ex );
15341545 }
15351546 }
15361547
1537- private void abortSession (SessionState snapshot ) {
1548+ private void abortSession (SessionState snapshot ) throws BigQueryJdbcException {
15381549 try {
15391550 LOG .fine ("Aborting session on connection close: %s" , snapshot .sessionInfo .getValue ());
15401551 QueryJobConfiguration abortSessionJobConfig =
@@ -1544,7 +1555,7 @@ private void abortSession(SessionState snapshot) {
15441555 this .bigQuery .query (abortSessionJobConfig );
15451556 } catch (InterruptedException ex ) {
15461557 Thread .currentThread ().interrupt ();
1547- throw new BigQueryJdbcRuntimeException ("Interrupted during session abort" , ex );
1558+ throw new BigQueryJdbcException ("Interrupted during session abort" , ex );
15481559 } catch (BigQueryException ex ) {
15491560 LOG .warning (
15501561 "Failed to abort session during session abort (session may have already ended): "
0 commit comments