eskabetxe commented on code in PR #2:
URL: 
https://github.com/apache/flink-connector-jdbc/pull/2#discussion_r1441520106


##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/sink/JdbcSinkBuilder.java:
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.sink;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.connector.base.DeliveryGuarantee;
+import org.apache.flink.connector.jdbc.JdbcConnectionOptions;
+import org.apache.flink.connector.jdbc.JdbcExactlyOnceOptions;
+import org.apache.flink.connector.jdbc.JdbcExecutionOptions;
+import org.apache.flink.connector.jdbc.JdbcStatementBuilder;
+import 
org.apache.flink.connector.jdbc.datasource.connections.JdbcConnectionProvider;
+import 
org.apache.flink.connector.jdbc.datasource.connections.SimpleJdbcConnectionProvider;
+import 
org.apache.flink.connector.jdbc.datasource.connections.xa.PoolingXaConnectionProvider;
+import 
org.apache.flink.connector.jdbc.datasource.connections.xa.SimpleXaConnectionProvider;
+import 
org.apache.flink.connector.jdbc.datasource.connections.xa.XaConnectionProvider;
+import 
org.apache.flink.connector.jdbc.datasource.statements.JdbcQueryStatement;
+import 
org.apache.flink.connector.jdbc.datasource.statements.SimpleJdbcQueryStatement;
+import org.apache.flink.util.function.SerializableSupplier;
+
+import javax.sql.XADataSource;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Builder to construct {@link JdbcSink}. */
+@PublicEvolving
+public class JdbcSinkBuilder<IN> {
+
+    private JdbcExecutionOptions executionOptions;
+    private JdbcQueryStatement<IN> queryStatement;
+
+    public JdbcSinkBuilder() {
+        this.executionOptions = JdbcExecutionOptions.defaults();
+    }
+
+    public JdbcSinkBuilder<IN> withExecutionOptions(JdbcExecutionOptions 
executionOptions) {
+        this.executionOptions = checkNotNull(executionOptions, 
"executionOptions cannot be empty");
+        return this;
+    }
+
+    public JdbcSinkBuilder<IN> withQueryStatement(JdbcQueryStatement<IN> 
queryStatement) {
+        this.queryStatement = queryStatement;
+        return this;
+    }
+
+    public JdbcSinkBuilder<IN> withQueryStatement(
+            String query, JdbcStatementBuilder<IN> statement) {
+        this.queryStatement = new SimpleJdbcQueryStatement<>(query, statement);
+        return this;
+    }
+
+    public JdbcSink<IN> buildAtLeastOnce(JdbcConnectionOptions 
connectionOptions) {
+        checkNotNull(connectionOptions, "connectionOptions cannot be empty");
+
+        return buildAtLeastOnce(new 
SimpleJdbcConnectionProvider(connectionOptions));
+    }
+
+    public JdbcSink<IN> buildAtLeastOnce(JdbcConnectionProvider 
connectionProvider) {
+        checkNotNull(connectionProvider, "connectionProvider cannot be empty");
+
+        return build(
+                DeliveryGuarantee.AT_LEAST_ONCE,
+                JdbcExactlyOnceOptions.defaults(),
+                checkNotNull(connectionProvider, "connectionProvider cannot be 
empty"));
+    }
+
+    public JdbcSink<IN> buildExactlyOnce(
+            JdbcExactlyOnceOptions exactlyOnceOptions,
+            SerializableSupplier<XADataSource> dataSourceSupplier) {
+
+        checkNotNull(exactlyOnceOptions, "exactlyOnceOptions cannot be empty");
+        checkNotNull(dataSourceSupplier, "dataSourceSupplier cannot be empty");
+        XaConnectionProvider connectionProvider =
+                exactlyOnceOptions.isTransactionPerConnection()
+                        ? PoolingXaConnectionProvider.from(
+                                dataSourceSupplier, 
exactlyOnceOptions.getTimeoutSec())
+                        : SimpleXaConnectionProvider.from(
+                                dataSourceSupplier, 
exactlyOnceOptions.getTimeoutSec());
+        return buildExactlyOnce(exactlyOnceOptions, connectionProvider);
+    }
+
+    public JdbcSink<IN> buildExactlyOnce(
+            JdbcExactlyOnceOptions exactlyOnceOptions, XaConnectionProvider 
connectionProvider) {
+
+        return build(
+                DeliveryGuarantee.EXACTLY_ONCE,
+                checkNotNull(exactlyOnceOptions, "exactlyOnceOptions cannot be 
empty"),
+                checkNotNull(connectionProvider, "connectionProvider cannot be 
empty"));
+    }
+
+    private JdbcSink<IN> build(
+            DeliveryGuarantee deliveryGuarantee,
+            JdbcExactlyOnceOptions exactlyOnceOptions,
+            JdbcConnectionProvider connectionProvider) {
+
+        return new JdbcSink<>(
+                checkNotNull(deliveryGuarantee, "deliveryGuarantee cannot be 
empty"),
+                checkNotNull(connectionProvider, "connectionProvider cannot be 
empty"),
+                checkNotNull(executionOptions, "executionOptions cannot be 
empty"),
+                checkNotNull(exactlyOnceOptions, "exactlyOnceOptions cannot be 
empty"),
+                checkNotNull(queryStatement, "queryStatement cannot be 
empty"));

Review Comment:
   done



##########
flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/sink/JdbcSinkBuilder.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.jdbc.sink;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.connector.jdbc.JdbcConnectionOptions;
+import org.apache.flink.connector.jdbc.JdbcExecutionOptions;
+import org.apache.flink.connector.jdbc.JdbcStatementBuilder;
+import 
org.apache.flink.connector.jdbc.internal.connection.JdbcConnectionProvider;
+import 
org.apache.flink.connector.jdbc.internal.connection.SimpleJdbcConnectionProvider;
+import org.apache.flink.connector.jdbc.sink.statement.JdbcQueryStatement;
+import org.apache.flink.connector.jdbc.sink.statement.SimpleJdbcQueryStatement;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Builder to construct {@link JdbcSink}. */
+@PublicEvolving
+public class JdbcSinkBuilder<IN> {
+
+    private JdbcConnectionProvider connectionProvider;
+    private JdbcExecutionOptions executionOptions;
+    private JdbcQueryStatement<IN> queryStatement;
+
+    public JdbcSinkBuilder() {
+        executionOptions = JdbcExecutionOptions.defaults();
+    }
+
+    public JdbcSinkBuilder<IN> withExecutionOptions(JdbcExecutionOptions 
executionOptions) {
+        this.executionOptions = checkNotNull(executionOptions, 
"executionOptions cannot be empty");
+        return this;
+    }
+
+    private JdbcSinkBuilder<IN> withConnectionProvider(JdbcConnectionProvider 
connectionProvider) {
+        this.connectionProvider =
+                checkNotNull(connectionProvider, "connectionProvider cannot be 
empty");
+        return this;
+    }
+
+    public JdbcSinkBuilder<IN> withConnectionProvider(JdbcConnectionOptions 
connectionOptions) {
+        return withConnectionProvider(new 
SimpleJdbcConnectionProvider(connectionOptions));
+    }
+
+    public JdbcSinkBuilder<IN> withQueryStatement(JdbcQueryStatement<IN> 
queryStatement) {
+        this.queryStatement = queryStatement;
+        return this;
+    }
+
+    public JdbcSinkBuilder<IN> withQueryStatement(
+            String query, JdbcStatementBuilder<IN> statement) {
+        this.queryStatement = new SimpleJdbcQueryStatement<>(query, statement);
+        return this;
+    }
+
+    public JdbcSink<IN> build() {
+        checkNotNull(connectionProvider, "connectionProvider cannot be empty");
+        checkNotNull(executionOptions, "executionOptions cannot be empty");
+        checkNotNull(queryStatement, "queryStatement cannot be empty");

Review Comment:
   done



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to