Skip to content

Commit 9eeed5f

Browse files
committed
chore: refactor spans
1 parent 122c14e commit 9eeed5f

1 file changed

Lines changed: 16 additions & 30 deletions

File tree

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

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -252,25 +252,19 @@ public ResultSet executeQuery(String sql) throws SQLException {
252252
setDestinationDatasetAndTableInJobConfig(getJobConfig(sql).build());
253253
runQuery(sql, jobConfiguration);
254254
} catch (InterruptedException ex) {
255-
span.recordException(ex);
256-
span.setStatus(StatusCode.ERROR, ex.getMessage());
257255
throw new BigQueryJdbcException(ex);
258-
} catch (Exception ex) {
259-
span.recordException(ex);
260-
span.setStatus(StatusCode.ERROR, ex.getMessage());
261-
throw ex;
262256
}
263257

264258
if (!isSingularResultSet()) {
265-
BigQueryJdbcException ex =
266-
new BigQueryJdbcException(
267-
"Query returned more than one or didn't return any ResultSet.");
268-
span.recordException(ex);
269-
span.setStatus(StatusCode.ERROR, ex.getMessage());
270-
throw ex;
259+
throw new BigQueryJdbcException(
260+
"Query returned more than one or didn't return any ResultSet.");
271261
}
272262
// This contains all the other assertions spec required on this method
273263
return getCurrentResultSet();
264+
} catch (Exception ex) {
265+
span.recordException(ex);
266+
span.setStatus(StatusCode.ERROR, ex.getMessage());
267+
throw ex;
274268
} finally {
275269
span.end();
276270
}
@@ -289,23 +283,17 @@ public long executeLargeUpdate(String sql) throws SQLException {
289283
QueryJobConfiguration.Builder jobConfiguration = getJobConfig(sql);
290284
runQuery(sql, jobConfiguration.build());
291285
} catch (InterruptedException ex) {
292-
span.recordException(ex);
293-
span.setStatus(StatusCode.ERROR, ex.getMessage());
294286
throw new BigQueryJdbcRuntimeException(ex);
295-
} catch (Exception ex) {
296-
span.recordException(ex);
297-
span.setStatus(StatusCode.ERROR, ex.getMessage());
298-
throw ex;
299287
}
300288
if (this.currentUpdateCount == -1) {
301-
BigQueryJdbcException ex =
302-
new BigQueryJdbcException(
303-
"Update query expected to return affected row count. Double check query type.");
304-
span.recordException(ex);
305-
span.setStatus(StatusCode.ERROR, ex.getMessage());
306-
throw ex;
289+
throw new BigQueryJdbcException(
290+
"Update query expected to return affected row count. Double check query type.");
307291
}
308292
return this.currentUpdateCount;
293+
} catch (Exception ex) {
294+
span.recordException(ex);
295+
span.setStatus(StatusCode.ERROR, ex.getMessage());
296+
throw ex;
309297
} finally {
310298
span.end();
311299
}
@@ -344,15 +332,13 @@ public boolean execute(String sql) throws SQLException {
344332
}
345333
runQuery(sql, jobConfiguration);
346334
} catch (InterruptedException ex) {
347-
span.recordException(ex);
348-
span.setStatus(StatusCode.ERROR, ex.getMessage());
349335
throw new BigQueryJdbcRuntimeException(ex);
350-
} catch (Exception ex) {
351-
span.recordException(ex);
352-
span.setStatus(StatusCode.ERROR, ex.getMessage());
353-
throw ex;
354336
}
355337
return getCurrentResultSet() != null;
338+
} catch (Exception ex) {
339+
span.recordException(ex);
340+
span.setStatus(StatusCode.ERROR, ex.getMessage());
341+
throw ex;
356342
} finally {
357343
span.end();
358344
}

0 commit comments

Comments
 (0)