You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/03/04 00:57:18 UTC

[GitHub] [incubator-seatunnel] yx91490 commented on a change in pull request #1390: [Feature][spark-connector-jdbc] add pre sql and post sql #1386

yx91490 commented on a change in pull request #1390:
URL: https://github.com/apache/incubator-seatunnel/pull/1390#discussion_r819181327



##########
File path: seatunnel-connectors/seatunnel-connector-spark-jdbc/src/main/scala/org/apache/seatunnel/spark/JdbcConfigs.scala
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.seatunnel.spark

Review comment:
       is JdbcConfigs.scala will be shared by source and sink? if not, maybe can move to org.apache.seatunnel.spark.sink package.

##########
File path: seatunnel-connectors/seatunnel-connector-spark-jdbc/src/main/scala/org/apache/seatunnel/spark/sink/Jdbc.scala
##########
@@ -16,47 +16,98 @@
  */
 package org.apache.seatunnel.spark.sink
 
-import scala.collection.JavaConversions._
-
+import org.apache.commons.collections.CollectionUtils
 import org.apache.seatunnel.common.config.CheckConfigUtil.checkAllExists
 import org.apache.seatunnel.common.config.CheckResult
 import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory
-import org.apache.seatunnel.spark.SparkEnvironment
+import org.apache.seatunnel.spark.{JdbcConfigs, SparkEnvironment}
 import org.apache.seatunnel.spark.batch.SparkBatchSink
-import org.apache.spark.sql.{Dataset, Row}
 import org.apache.spark.sql.execution.datasources.jdbc2.JDBCSaveMode
+import org.apache.spark.sql.{Dataset, Row}
+import org.slf4j.{Logger, LoggerFactory}
+
+import java.sql.{Connection, DriverManager, Statement}
+import scala.collection.JavaConversions._
 
 class Jdbc extends SparkBatchSink {
 
+  private val LOG: Logger = LoggerFactory.getLogger(classOf[Jdbc])
+
+  private var jdbcConfigs: JdbcConfigs = _
+
+  private def getConnection(): Connection = {
+    Class.forName(jdbcConfigs.driver)
+    val connection = DriverManager.getConnection(jdbcConfigs.url, jdbcConfigs.user, jdbcConfigs.password)

Review comment:
       It seems that connection will be created about 3 times at worst, can connection be reused in the same job?




-- 
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: commits-unsubscribe@seatunnel.apache.org

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