alexvanboxel commented on a change in pull request #11258: [BEAM-9571] Add 
withMongoClientProvider to MongoDbIO
URL: https://github.com/apache/beam/pull/11258#discussion_r410057736
 
 

 ##########
 File path: 
sdks/java/io/mongodb/src/main/java/org/apache/beam/sdk/io/mongodb/MongoDbIO.java
 ##########
 @@ -843,22 +843,39 @@ private MongoClient createClient(Read spec) {
      */
     public Write withUri(String uri) {
       checkArgument(uri != null, "uri can not be null");
-      return builder().setUri(uri).build();
+      Write spec = toBuilder().setUri(uri).build();
+      return withMongoClientProvider(
+              DefaultMongoClientProvider.of(
+                  spec.uri(),
+                  spec.maxConnectionIdleTime(),
+                  spec.sslEnabled(),
+                  spec.sslInvalidHostNameAllowed(),
+                  spec.ignoreSSLCertificate()))
+          .toBuilder()
+          .setUri(uri)
+          .build();
     }
 
     /** Sets the maximum idle time for a pooled connection. */
     public Write withMaxConnectionIdleTime(int maxConnectionIdleTime) {
-      return builder().setMaxConnectionIdleTime(maxConnectionIdleTime).build();
+      return 
toBuilder().setMaxConnectionIdleTime(maxConnectionIdleTime).build();
     }
 
     /** Enable ssl for connection. */
     public Write withSSLEnabled(boolean sslEnabled) {
-      return builder().setSslEnabled(sslEnabled).build();
+      return toBuilder().setSslEnabled(sslEnabled).build();
     }
 
     /** Enable invalidHostNameAllowed for ssl for connection. */
     public Write withSSLInvalidHostNameAllowed(boolean invalidHostNameAllowed) 
{
-      return 
builder().setSslInvalidHostNameAllowed(invalidHostNameAllowed).build();
+      return 
toBuilder().setSslInvalidHostNameAllowed(invalidHostNameAllowed).build();
+    }
+
+    /** Sets a MongoClient provider. */
+    public Write withMongoClientProvider(
 
 Review comment:
   Maybe we should rename this to withClientProvider, the we can use this 
pattern in other IO's and make it as part of a IO style guide to make them more 
consistent. WDYT?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to