@@ -131,6 +131,9 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
131131 String sslTrustStorePassword ;
132132 long maxBytesBilled ;
133133 Map <String , String > labels ;
134+ Integer httpConnectTimeout ;
135+ Integer httpReadTimeout ;
136+ String requestReason ;
134137
135138 BigQueryConnection (String url ) throws IOException {
136139 this .connectionUrl = url ;
@@ -272,11 +275,25 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
272275 BigQueryJdbcUrlUtility .SSL_TRUST_STORE_PWD_PROPERTY_NAME ,
273276 null ,
274277 this .connectionClassName );
278+ this .httpConnectTimeout =
279+ BigQueryJdbcUrlUtility .parseIntProperty (
280+ url ,
281+ BigQueryJdbcUrlUtility .HTTP_CONNECT_TIMEOUT_PROPERTY_NAME ,
282+ null ,
283+ this .connectionClassName );
284+ this .httpReadTimeout =
285+ BigQueryJdbcUrlUtility .parseIntProperty (
286+ url ,
287+ BigQueryJdbcUrlUtility .HTTP_READ_TIMEOUT_PROPERTY_NAME ,
288+ null ,
289+ this .connectionClassName );
275290 this .httpTransportOptions =
276291 BigQueryJdbcProxyUtility .getHttpTransportOptions (
277292 proxyProperties ,
278293 this .sslTrustStorePath ,
279294 this .sslTrustStorePassword ,
295+ this .httpConnectTimeout ,
296+ this .httpReadTimeout ,
280297 this .connectionClassName );
281298 this .transportChannelProvider =
282299 BigQueryJdbcProxyUtility .getTransportChannelProvider (
@@ -347,6 +364,12 @@ public class BigQueryConnection extends BigQueryNoOpsConnection {
347364 BigQueryJdbcUrlUtility .METADATA_FETCH_THREAD_COUNT_PROPERTY_NAME ,
348365 BigQueryJdbcUrlUtility .DEFAULT_METADATA_FETCH_THREAD_COUNT_VALUE ,
349366 this .connectionClassName );
367+ this .requestReason =
368+ BigQueryJdbcUrlUtility .parseStringProperty (
369+ url ,
370+ BigQueryJdbcUrlUtility .REQUEST_REASON_PROPERTY_NAME ,
371+ null ,
372+ this .connectionClassName );
350373
351374 HEADER_PROVIDER = createHeaderProvider ();
352375 this .bigQuery = getBigQueryConnection ();
@@ -383,11 +406,16 @@ HeaderProvider createHeaderProvider() {
383406 String partnerToken = buildPartnerToken (this .connectionUrl );
384407 String headerToken =
385408 DEFAULT_JDBC_TOKEN_VALUE + "/" + getLibraryVersion (this .getClass ()) + partnerToken ;
386- return FixedHeaderProvider .create ("user-agent" , headerToken );
409+ Map <String , String > headers = new java .util .HashMap <>();
410+ headers .put ("user-agent" , headerToken );
411+ if (this .requestReason != null ) {
412+ headers .put ("x-goog-request-reason" , this .requestReason );
413+ }
414+ return FixedHeaderProvider .create (headers );
387415 }
388416
389417 protected void addOpenStatements (Statement statement ) {
390- LOG .finest (String . format ( "Statement %s added to Connection %s." , statement , this ) );
418+ LOG .finest ("Statement %s added to Connection %s." , statement , this );
391419 this .openStatements .add (statement );
392420 }
393421
@@ -431,7 +459,7 @@ String getConnectionUrl() {
431459 public Statement createStatement () throws SQLException {
432460 checkClosed ();
433461 BigQueryStatement currentStatement = new BigQueryStatement (this );
434- LOG .fine (String . format ( "Statement %s created." , currentStatement ) );
462+ LOG .fine ("Statement %s created." , currentStatement );
435463 addOpenStatements (currentStatement );
436464 return currentStatement ;
437465 }
@@ -490,7 +518,7 @@ public Statement createStatement(
490518 public PreparedStatement prepareStatement (String sql ) throws SQLException {
491519 checkClosed ();
492520 PreparedStatement currentStatement = new BigQueryPreparedStatement (this , sql );
493- LOG .fine (String . format ( "Prepared Statement %s created." , currentStatement ) );
521+ LOG .fine ("Prepared Statement %s created." , currentStatement );
494522 addOpenStatements (currentStatement );
495523 return currentStatement ;
496524 }
@@ -724,6 +752,14 @@ String getSSLTrustStorePassword() {
724752 return sslTrustStorePassword ;
725753 }
726754
755+ Integer getHttpConnectTimeout () {
756+ return httpConnectTimeout ;
757+ }
758+
759+ Integer getHttpReadTimeout () {
760+ return httpReadTimeout ;
761+ }
762+
727763 @ Override
728764 public boolean isValid (int timeout ) throws SQLException {
729765 if (timeout < 0 ) {
@@ -1139,7 +1175,7 @@ private void commitTransaction() {
11391175 public CallableStatement prepareCall (String sql ) throws SQLException {
11401176 checkClosed ();
11411177 CallableStatement currentStatement = new BigQueryCallableStatement (this , sql );
1142- LOG .fine (String . format ( "Callable Statement %s created." , currentStatement ) );
1178+ LOG .fine ("Callable Statement %s created." , currentStatement );
11431179 addOpenStatements (currentStatement );
11441180 return currentStatement ;
11451181 }
0 commit comments