shangeyao commented on code in PR #4419:
URL: https://github.com/apache/streampark/pull/4419#discussion_r3540609526


##########
streampark-common/src/main/java/org/apache/streampark/common/util/JdbcUtils.java:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.streampark.common.util;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+
+/**
+ * Based on the hikari connection pool implementation. Support multiple data 
sources, note that all
+ * modifications and additions are automatically committed transactions.
+ */
+public final class JdbcUtils {
+
+    private static final ConcurrentHashMap<String, ReentrantLock> LOCK_MAP = 
new ConcurrentHashMap<>();
+
+    private static final ConcurrentHashMap<String, HikariDataSource> 
DATA_SOURCE_HOLDER =
+            new ConcurrentHashMap<>();
+
+    private JdbcUtils() {}
+
+    public static List<Map<String, Object>> select(String sql, Properties 
jdbcConfig) {
+        return select(sql, null, jdbcConfig);
+    }
+
+    public static List<Map<String, Object>> select(
+            String sql, Consumer<ResultSet> func, Properties jdbcConfig) {
+        if (sql == null || sql.isEmpty()) {
+            return Collections.emptyList();
+        }
+        Connection conn = getConnection(jdbcConfig);
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            if (func != null) {
+                func.accept(result);
+            }
+            int count = result.getMetaData().getColumnCount();
+            List<Map<String, Object>> array = new ArrayList<>();
+            while (result.next()) {
+                Map<String, Object> map = new HashMap<>();
+                for (int x = 1; x <= count; x++) {
+                    String key = result.getMetaData().getColumnLabel(x);
+                    Object value = result.getObject(x);
+                    map.put(key, value);
+                }
+                array.add(map);
+            }
+            return array.isEmpty() ? Collections.emptyList() : array;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return Collections.emptyList();
+        } finally {
+            close(result, stmt, conn);
+        }
+    }
+
+    public static long count(String sql, Properties jdbcConfig) {
+        Map<String, Object> row = unique(sql, jdbcConfig);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static long count(Connection conn, String sql) {
+        Map<String, Object> row = unique(conn, sql);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static int batch(Iterable<String> sql, Properties jdbcConfig) {
+        int size = 0;
+        for (String ignored : sql) {
+            size++;
+        }
+        if (size == 0) {
+            return 0;
+        }
+        if (size == 1) {
+            for (String s : sql) {
+                return update(s, jdbcConfig);
+            }
+        }
+        Connection conn = getConnection(jdbcConfig);
+        try {
+            Statement prepStat = conn.createStatement();
+            try {
+                int index = 0;
+                int batchSize = 1000;
+                int total = 0;
+                for (String x : sql) {
+                    prepStat.addBatch(x);
+                    index++;
+                    if (index > 0 && index % batchSize == 0) {
+                        int count = 0;
+                        for (int c : prepStat.executeBatch()) {
+                            count += c;
+                        }
+                        conn.commit();
+                        prepStat.clearBatch();
+                        total += count;
+                    }
+                }
+                for (int c : prepStat.executeBatch()) {
+                    total += c;
+                }
+                return total;
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                return 0;
+            } finally {
+                conn.commit();
+                close(conn);
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return 0;
+        }
+    }
+
+    public static int update(String sql, Properties jdbcConfig) {
+        return update(getConnection(jdbcConfig), sql);
+    }
+
+    public static int update(Connection conn, String sql) {
+        Statement statement = null;
+        try {
+            statement = conn.createStatement();
+            return statement.executeUpdate(sql);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return -1;
+        } finally {
+            close(statement, conn);
+        }
+    }
+
+    public static Map<String, Object> unique(String sql, Properties 
jdbcConfig) {
+        return unique(getConnection(jdbcConfig), sql);
+    }
+
+    public static Map<String, Object> unique(Connection conn, String sql) {
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            int count = result.getMetaData().getColumnCount();
+            if (!result.next()) {
+                return Collections.emptyMap();
+            }
+            Map<String, Object> map = new HashMap<>();
+            for (int x = 1; x <= count; x++) {
+                String key = result.getMetaData().getColumnLabel(x);
+                Object value = result.getObject(x);
+                map.put(key, value);
+            }
+            return map;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return Collections.emptyMap();
+        } finally {
+            close(result, stmt, conn);
+        }
+    }
+
+    public static boolean execute(String sql, Properties jdbcConfig) {
+        return execute(getConnection(jdbcConfig), sql);
+    }
+
+    public static boolean execute(Connection conn, String sql) {
+        Statement stmt = null;
+        try {
+            stmt = conn.createStatement();
+            return stmt.execute(sql);
+        } catch (Exception ex) {
+            ex.printStackTrace();

Review Comment:
   Fixed in `752fa8a68`: replaced `printStackTrace()` with `LOG.warn(...)`.



##########
streampark-common/src/main/java/org/apache/streampark/common/util/JdbcUtils.java:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.streampark.common.util;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+
+/**
+ * Based on the hikari connection pool implementation. Support multiple data 
sources, note that all
+ * modifications and additions are automatically committed transactions.
+ */
+public final class JdbcUtils {
+
+    private static final ConcurrentHashMap<String, ReentrantLock> LOCK_MAP = 
new ConcurrentHashMap<>();
+
+    private static final ConcurrentHashMap<String, HikariDataSource> 
DATA_SOURCE_HOLDER =
+            new ConcurrentHashMap<>();
+
+    private JdbcUtils() {}
+
+    public static List<Map<String, Object>> select(String sql, Properties 
jdbcConfig) {
+        return select(sql, null, jdbcConfig);
+    }
+
+    public static List<Map<String, Object>> select(
+            String sql, Consumer<ResultSet> func, Properties jdbcConfig) {
+        if (sql == null || sql.isEmpty()) {
+            return Collections.emptyList();
+        }
+        Connection conn = getConnection(jdbcConfig);
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            if (func != null) {
+                func.accept(result);
+            }
+            int count = result.getMetaData().getColumnCount();
+            List<Map<String, Object>> array = new ArrayList<>();
+            while (result.next()) {
+                Map<String, Object> map = new HashMap<>();
+                for (int x = 1; x <= count; x++) {
+                    String key = result.getMetaData().getColumnLabel(x);
+                    Object value = result.getObject(x);
+                    map.put(key, value);
+                }
+                array.add(map);
+            }
+            return array.isEmpty() ? Collections.emptyList() : array;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return Collections.emptyList();
+        } finally {
+            close(result, stmt, conn);
+        }
+    }
+
+    public static long count(String sql, Properties jdbcConfig) {
+        Map<String, Object> row = unique(sql, jdbcConfig);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static long count(Connection conn, String sql) {
+        Map<String, Object> row = unique(conn, sql);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static int batch(Iterable<String> sql, Properties jdbcConfig) {
+        int size = 0;
+        for (String ignored : sql) {
+            size++;
+        }
+        if (size == 0) {
+            return 0;
+        }
+        if (size == 1) {
+            for (String s : sql) {
+                return update(s, jdbcConfig);
+            }
+        }
+        Connection conn = getConnection(jdbcConfig);
+        try {
+            Statement prepStat = conn.createStatement();
+            try {
+                int index = 0;
+                int batchSize = 1000;
+                int total = 0;
+                for (String x : sql) {
+                    prepStat.addBatch(x);
+                    index++;
+                    if (index > 0 && index % batchSize == 0) {
+                        int count = 0;
+                        for (int c : prepStat.executeBatch()) {
+                            count += c;
+                        }
+                        conn.commit();
+                        prepStat.clearBatch();
+                        total += count;
+                    }
+                }
+                for (int c : prepStat.executeBatch()) {
+                    total += c;
+                }
+                return total;
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                return 0;
+            } finally {
+                conn.commit();
+                close(conn);
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return 0;
+        }
+    }
+
+    public static int update(String sql, Properties jdbcConfig) {
+        return update(getConnection(jdbcConfig), sql);
+    }
+
+    public static int update(Connection conn, String sql) {
+        Statement statement = null;
+        try {
+            statement = conn.createStatement();
+            return statement.executeUpdate(sql);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return -1;
+        } finally {
+            close(statement, conn);
+        }
+    }
+
+    public static Map<String, Object> unique(String sql, Properties 
jdbcConfig) {
+        return unique(getConnection(jdbcConfig), sql);
+    }
+
+    public static Map<String, Object> unique(Connection conn, String sql) {
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            int count = result.getMetaData().getColumnCount();
+            if (!result.next()) {
+                return Collections.emptyMap();
+            }
+            Map<String, Object> map = new HashMap<>();
+            for (int x = 1; x <= count; x++) {
+                String key = result.getMetaData().getColumnLabel(x);
+                Object value = result.getObject(x);
+                map.put(key, value);
+            }
+            return map;
+        } catch (Exception ex) {
+            ex.printStackTrace();

Review Comment:
   Fixed in `752fa8a68`: replaced `printStackTrace()` with `LOG.warn(...)`.



##########
streampark-common/src/main/java/org/apache/streampark/common/util/JdbcUtils.java:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.streampark.common.util;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+
+/**
+ * Based on the hikari connection pool implementation. Support multiple data 
sources, note that all
+ * modifications and additions are automatically committed transactions.
+ */
+public final class JdbcUtils {
+
+    private static final ConcurrentHashMap<String, ReentrantLock> LOCK_MAP = 
new ConcurrentHashMap<>();
+
+    private static final ConcurrentHashMap<String, HikariDataSource> 
DATA_SOURCE_HOLDER =
+            new ConcurrentHashMap<>();
+
+    private JdbcUtils() {}
+
+    public static List<Map<String, Object>> select(String sql, Properties 
jdbcConfig) {
+        return select(sql, null, jdbcConfig);
+    }
+
+    public static List<Map<String, Object>> select(
+            String sql, Consumer<ResultSet> func, Properties jdbcConfig) {
+        if (sql == null || sql.isEmpty()) {
+            return Collections.emptyList();
+        }
+        Connection conn = getConnection(jdbcConfig);
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            if (func != null) {
+                func.accept(result);
+            }
+            int count = result.getMetaData().getColumnCount();
+            List<Map<String, Object>> array = new ArrayList<>();
+            while (result.next()) {
+                Map<String, Object> map = new HashMap<>();
+                for (int x = 1; x <= count; x++) {
+                    String key = result.getMetaData().getColumnLabel(x);
+                    Object value = result.getObject(x);
+                    map.put(key, value);
+                }
+                array.add(map);
+            }
+            return array.isEmpty() ? Collections.emptyList() : array;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return Collections.emptyList();
+        } finally {
+            close(result, stmt, conn);
+        }
+    }
+
+    public static long count(String sql, Properties jdbcConfig) {
+        Map<String, Object> row = unique(sql, jdbcConfig);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static long count(Connection conn, String sql) {
+        Map<String, Object> row = unique(conn, sql);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static int batch(Iterable<String> sql, Properties jdbcConfig) {
+        int size = 0;
+        for (String ignored : sql) {
+            size++;
+        }
+        if (size == 0) {
+            return 0;
+        }
+        if (size == 1) {
+            for (String s : sql) {
+                return update(s, jdbcConfig);
+            }
+        }
+        Connection conn = getConnection(jdbcConfig);
+        try {
+            Statement prepStat = conn.createStatement();
+            try {
+                int index = 0;
+                int batchSize = 1000;
+                int total = 0;
+                for (String x : sql) {
+                    prepStat.addBatch(x);
+                    index++;
+                    if (index > 0 && index % batchSize == 0) {
+                        int count = 0;
+                        for (int c : prepStat.executeBatch()) {
+                            count += c;
+                        }
+                        conn.commit();
+                        prepStat.clearBatch();
+                        total += count;
+                    }
+                }
+                for (int c : prepStat.executeBatch()) {
+                    total += c;
+                }
+                return total;
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                return 0;
+            } finally {
+                conn.commit();
+                close(conn);
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return 0;
+        }
+    }
+
+    public static int update(String sql, Properties jdbcConfig) {
+        return update(getConnection(jdbcConfig), sql);
+    }
+
+    public static int update(Connection conn, String sql) {
+        Statement statement = null;
+        try {
+            statement = conn.createStatement();
+            return statement.executeUpdate(sql);
+        } catch (Exception ex) {
+            ex.printStackTrace();

Review Comment:
   Fixed in `752fa8a68`: replaced `printStackTrace()` with `LOG.warn(...)`.



##########
streampark-common/src/main/java/org/apache/streampark/common/util/JdbcUtils.java:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.streampark.common.util;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+
+/**
+ * Based on the hikari connection pool implementation. Support multiple data 
sources, note that all
+ * modifications and additions are automatically committed transactions.
+ */
+public final class JdbcUtils {
+
+    private static final ConcurrentHashMap<String, ReentrantLock> LOCK_MAP = 
new ConcurrentHashMap<>();
+
+    private static final ConcurrentHashMap<String, HikariDataSource> 
DATA_SOURCE_HOLDER =
+            new ConcurrentHashMap<>();
+
+    private JdbcUtils() {}
+
+    public static List<Map<String, Object>> select(String sql, Properties 
jdbcConfig) {
+        return select(sql, null, jdbcConfig);
+    }
+
+    public static List<Map<String, Object>> select(
+            String sql, Consumer<ResultSet> func, Properties jdbcConfig) {
+        if (sql == null || sql.isEmpty()) {
+            return Collections.emptyList();
+        }
+        Connection conn = getConnection(jdbcConfig);
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            if (func != null) {
+                func.accept(result);
+            }
+            int count = result.getMetaData().getColumnCount();
+            List<Map<String, Object>> array = new ArrayList<>();
+            while (result.next()) {
+                Map<String, Object> map = new HashMap<>();
+                for (int x = 1; x <= count; x++) {
+                    String key = result.getMetaData().getColumnLabel(x);
+                    Object value = result.getObject(x);
+                    map.put(key, value);
+                }
+                array.add(map);
+            }
+            return array.isEmpty() ? Collections.emptyList() : array;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return Collections.emptyList();
+        } finally {
+            close(result, stmt, conn);
+        }
+    }
+
+    public static long count(String sql, Properties jdbcConfig) {
+        Map<String, Object> row = unique(sql, jdbcConfig);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static long count(Connection conn, String sql) {
+        Map<String, Object> row = unique(conn, sql);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static int batch(Iterable<String> sql, Properties jdbcConfig) {
+        int size = 0;
+        for (String ignored : sql) {
+            size++;
+        }
+        if (size == 0) {
+            return 0;
+        }
+        if (size == 1) {
+            for (String s : sql) {
+                return update(s, jdbcConfig);
+            }
+        }
+        Connection conn = getConnection(jdbcConfig);
+        try {
+            Statement prepStat = conn.createStatement();
+            try {
+                int index = 0;
+                int batchSize = 1000;
+                int total = 0;
+                for (String x : sql) {
+                    prepStat.addBatch(x);
+                    index++;
+                    if (index > 0 && index % batchSize == 0) {
+                        int count = 0;
+                        for (int c : prepStat.executeBatch()) {
+                            count += c;
+                        }
+                        conn.commit();
+                        prepStat.clearBatch();
+                        total += count;
+                    }
+                }
+                for (int c : prepStat.executeBatch()) {
+                    total += c;
+                }
+                return total;
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                return 0;
+            } finally {
+                conn.commit();
+                close(conn);
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();

Review Comment:
   Fixed in `752fa8a68`: replaced `printStackTrace()` with `LOG.warn(...)`.



##########
streampark-common/src/main/java/org/apache/streampark/common/util/JdbcUtils.java:
##########
@@ -0,0 +1,329 @@
+/*
+ * 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.streampark.common.util;
+
+import org.apache.streampark.common.conf.ConfigKeys;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+
+/**
+ * Based on the hikari connection pool implementation. Support multiple data 
sources, note that all
+ * modifications and additions are automatically committed transactions.
+ */
+public final class JdbcUtils {
+
+    private static final ConcurrentHashMap<String, ReentrantLock> LOCK_MAP = 
new ConcurrentHashMap<>();
+
+    private static final ConcurrentHashMap<String, HikariDataSource> 
DATA_SOURCE_HOLDER =
+            new ConcurrentHashMap<>();
+
+    private JdbcUtils() {}
+
+    public static List<Map<String, Object>> select(String sql, Properties 
jdbcConfig) {
+        return select(sql, null, jdbcConfig);
+    }
+
+    public static List<Map<String, Object>> select(
+            String sql, Consumer<ResultSet> func, Properties jdbcConfig) {
+        if (sql == null || sql.isEmpty()) {
+            return Collections.emptyList();
+        }
+        Connection conn = getConnection(jdbcConfig);
+        Statement stmt = null;
+        ResultSet result = null;
+        try {
+            stmt = createStatement(conn);
+            result = stmt.executeQuery(sql);
+            if (func != null) {
+                func.accept(result);
+            }
+            int count = result.getMetaData().getColumnCount();
+            List<Map<String, Object>> array = new ArrayList<>();
+            while (result.next()) {
+                Map<String, Object> map = new HashMap<>();
+                for (int x = 1; x <= count; x++) {
+                    String key = result.getMetaData().getColumnLabel(x);
+                    Object value = result.getObject(x);
+                    map.put(key, value);
+                }
+                array.add(map);
+            }
+            return array.isEmpty() ? Collections.emptyList() : array;
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            return Collections.emptyList();
+        } finally {
+            close(result, stmt, conn);
+        }
+    }
+
+    public static long count(String sql, Properties jdbcConfig) {
+        Map<String, Object> row = unique(sql, jdbcConfig);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static long count(Connection conn, String sql) {
+        Map<String, Object> row = unique(conn, sql);
+        if (row.isEmpty()) {
+            return 0L;
+        }
+        return Long.parseLong(row.values().iterator().next().toString());
+    }
+
+    public static int batch(Iterable<String> sql, Properties jdbcConfig) {
+        int size = 0;
+        for (String ignored : sql) {
+            size++;
+        }
+        if (size == 0) {
+            return 0;
+        }
+        if (size == 1) {
+            for (String s : sql) {
+                return update(s, jdbcConfig);
+            }
+        }
+        Connection conn = getConnection(jdbcConfig);
+        try {
+            Statement prepStat = conn.createStatement();
+            try {
+                int index = 0;
+                int batchSize = 1000;
+                int total = 0;
+                for (String x : sql) {
+                    prepStat.addBatch(x);
+                    index++;
+                    if (index > 0 && index % batchSize == 0) {
+                        int count = 0;
+                        for (int c : prepStat.executeBatch()) {
+                            count += c;
+                        }
+                        conn.commit();
+                        prepStat.clearBatch();
+                        total += count;
+                    }
+                }
+                for (int c : prepStat.executeBatch()) {
+                    total += c;
+                }
+                return total;
+            } catch (Exception ex) {
+                ex.printStackTrace();

Review Comment:
   Fixed in `752fa8a68`: replaced `printStackTrace()` with `LOG.warn(...)`.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to