This is an automated email from the ASF dual-hosted git repository.

libenchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 420b5e319e1 [FLINK-31548][jdbc-driver] Introduce FlinkDataSource for 
flink jdbc driver
420b5e319e1 is described below

commit 420b5e319e1f8e917c099530360f51f73a070575
Author: Shammon FY <zjur...@gmail.com>
AuthorDate: Sat May 6 09:00:38 2023 +0800

    [FLINK-31548][jdbc-driver] Introduce FlinkDataSource for flink jdbc driver
    
    Close apache/flink#22532
---
 .../apache/flink/table/jdbc/FlinkDataSource.java   | 88 ++++++++++++++++++++++
 .../flink/table/jdbc/FlinkDataSourceTest.java      | 39 ++++++++++
 2 files changed, 127 insertions(+)

diff --git 
a/flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkDataSource.java
 
b/flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkDataSource.java
new file mode 100644
index 00000000000..d8a84e19742
--- /dev/null
+++ 
b/flink-table/flink-sql-jdbc-driver/src/main/java/org/apache/flink/table/jdbc/FlinkDataSource.java
@@ -0,0 +1,88 @@
+/*
+ * 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.table.jdbc;
+
+import javax.sql.DataSource;
+
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+/** Basic flink data source which create {@link FlinkConnection}. */
+public class FlinkDataSource implements DataSource {
+    private final String url;
+    private final Properties properties;
+
+    public FlinkDataSource(String url, Properties properties) {
+        this.url = url;
+        this.properties = properties;
+    }
+
+    @Override
+    public Connection getConnection() throws SQLException {
+        return new FlinkConnection(DriverUri.create(url, properties));
+    }
+
+    @Override
+    public Connection getConnection(String username, String password) throws 
SQLException {
+        throw new SQLFeatureNotSupportedException(
+                "FlinkDataSource#getConnection with username and password is 
not supported");
+    }
+
+    @Override
+    public <T> T unwrap(Class<T> iface) throws SQLException {
+        throw new SQLFeatureNotSupportedException("FlinkDataSource#unwrap is 
not supported");
+    }
+
+    @Override
+    public boolean isWrapperFor(Class<?> iface) throws SQLException {
+        throw new 
SQLFeatureNotSupportedException("FlinkDataSource#isWrapperFor is not 
supported");
+    }
+
+    @Override
+    public PrintWriter getLogWriter() throws SQLException {
+        throw new 
SQLFeatureNotSupportedException("FlinkDataSource#getLogWriter is not 
supported");
+    }
+
+    @Override
+    public void setLogWriter(PrintWriter out) throws SQLException {
+        throw new 
SQLFeatureNotSupportedException("FlinkDataSource#setLogWriter is not 
supported");
+    }
+
+    @Override
+    public void setLoginTimeout(int seconds) throws SQLException {
+        throw new SQLFeatureNotSupportedException(
+                "FlinkDataSource#setLoginTimeout is not supported");
+    }
+
+    @Override
+    public int getLoginTimeout() throws SQLException {
+        throw new SQLFeatureNotSupportedException(
+                "FlinkDataSource#getLoginTimeout is not supported");
+    }
+
+    @Override
+    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+        throw new SQLFeatureNotSupportedException(
+                "FlinkDataSource#getParentLogger is not supported");
+    }
+}
diff --git 
a/flink-table/flink-sql-jdbc-driver/src/test/java/org/apache/flink/table/jdbc/FlinkDataSourceTest.java
 
b/flink-table/flink-sql-jdbc-driver/src/test/java/org/apache/flink/table/jdbc/FlinkDataSourceTest.java
new file mode 100644
index 00000000000..9d00c37d24d
--- /dev/null
+++ 
b/flink-table/flink-sql-jdbc-driver/src/test/java/org/apache/flink/table/jdbc/FlinkDataSourceTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.table.jdbc;
+
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/** Tests for flink data source. */
+public class FlinkDataSourceTest extends FlinkJdbcDriverTestBase {
+
+    @Test
+    public void testDataSource() throws Exception {
+        FlinkDataSource dataSource = new 
FlinkDataSource(getDriverUri().getURL(), new Properties());
+        try (Connection connection = dataSource.getConnection()) {
+            assertEquals("default_catalog", connection.getCatalog());
+            assertEquals("default_database", connection.getSchema());
+        }
+    }
+}

Reply via email to