From bd050eb7ba3d066c7a22b6ee098e3942862cd6a4 Mon Sep 17 00:00:00 2001 From: wangzhan10 Date: Thu, 11 Jan 2024 15:02:27 +0800 Subject: [PATCH 1/2] feature-add MariaDB Connector --- .../datavines-connector-all/pom.xml | 6 +++ .../datavines-connector-mariadb/pom.xml | 42 +++++++++++++++ .../plugin/MariadbConfigBuilder.java | 38 ++++++++++++++ .../connector/plugin/MariadbConnector.java | 44 ++++++++++++++++ .../plugin/MariadbConnectorFactory.java | 47 +++++++++++++++++ .../MariadbConnectorParameterConverter.java | 40 ++++++++++++++ .../plugin/MariadbDataSourceInfo.java | 52 +++++++++++++++++++ .../connector/plugin/MariadbDialect.java | 46 ++++++++++++++++ .../connector/plugin/MariadbExecutor.java | 33 ++++++++++++ ...o.datavines.connector.api.ConnectorFactory | 1 + .../datavines-connector-plugins/pom.xml | 1 + pom.xml | 8 +++ 12 files changed, 358 insertions(+) create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/pom.xml create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConfigBuilder.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnector.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorFactory.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorParameterConverter.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbExecutor.java create mode 100644 datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-all/pom.xml b/datavines-connector/datavines-connector-plugins/datavines-connector-all/pom.xml index d3ba62d2..1f0bb806 100644 --- a/datavines-connector/datavines-connector-plugins/datavines-connector-all/pom.xml +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-all/pom.xml @@ -36,6 +36,12 @@ ${project.version} + + io.datavines + datavines-connector-mariadb + ${project.version} + + io.datavines datavines-connector-hive diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/pom.xml b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/pom.xml new file mode 100644 index 00000000..a5b104c1 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/pom.xml @@ -0,0 +1,42 @@ + + + + + + datavines-connector-plugins + io.datavines + 1.0.0-SNAPSHOT + + 4.0.0 + + datavines-connector-mariadb + + + + io.datavines + datavines-connector-jdbc + ${project.version} + + + + + \ No newline at end of file diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConfigBuilder.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConfigBuilder.java new file mode 100644 index 00000000..355290de --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConfigBuilder.java @@ -0,0 +1,38 @@ +/* + * 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 io.datavines.connector.plugin; + +import io.datavines.common.param.form.type.InputParam; + +public class MariadbConfigBuilder extends JdbcConfigBuilder { + + @Override + protected InputParam getPropertiesInput(boolean isEn) { + return getInputParam("properties", + isEn ? "properties" : "参数", + isEn ? "please enter properties,like key=value&key1=value1" : "请填入参数,格式为key=value&key1=value1", 2, null, + "useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&useInformationSchema=true"); + } + + @Override + protected InputParam getDatabaseInput(boolean isEn) { + return getInputParam("database", + isEn ? "database" : "数据库", + isEn ? "please enter database" : "请填入数据库", 1, null, + null); + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnector.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnector.java new file mode 100644 index 00000000..bc58961c --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnector.java @@ -0,0 +1,44 @@ +/* + * 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 io.datavines.connector.plugin; + +import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo; +import io.datavines.common.datasource.jdbc.JdbcConnectionInfo; +import io.datavines.connector.api.DataSourceClient; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MariadbConnector extends JdbcConnector { + + public MariadbConnector(DataSourceClient dataSourceClient) { + super(dataSourceClient); + } + @Override + public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { + return new MariadbDataSourceInfo(jdbcConnectionInfo); + } + + @Override + public ResultSet getMetadataDatabases(Connection connection) throws SQLException { + DatabaseMetaData metaData = connection.getMetaData(); + return metaData.getCatalogs(); + } + +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorFactory.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorFactory.java new file mode 100644 index 00000000..0c893e84 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorFactory.java @@ -0,0 +1,47 @@ +/* + * 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 io.datavines.connector.plugin; + +import io.datavines.connector.api.*; + +public class MariadbConnectorFactory extends AbstractJdbcConnectorFactory { + + @Override + public ConnectorParameterConverter getConnectorParameterConverter() { + return new MariadbConnectorParameterConverter(); + } + + @Override + public Dialect getDialect() { + return new MariadbDialect(); + } + + @Override + public Connector getConnector() { + return new MariadbConnector(getDataSourceClient()); + } + + @Override + public Executor getExecutor() { + return new MariadbExecutor(getDataSourceClient()); + } + + @Override + public ConfigBuilder getConfigBuilder() { + return new MariadbConfigBuilder(); + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorParameterConverter.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorParameterConverter.java new file mode 100644 index 00000000..68c84725 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbConnectorParameterConverter.java @@ -0,0 +1,40 @@ +/* + * 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 io.datavines.connector.plugin; + +import java.util.Map; + +import io.datavines.common.utils.StringUtils; +import static io.datavines.common.ConfigConstants.*; + +public class MariadbConnectorParameterConverter extends JdbcConnectorParameterConverter { + + @Override + protected String getUrl(Map parameter) { + String url = String.format("jdbc:mariadb://%s:%s/%s", + parameter.get(HOST), + parameter.get(PORT), + parameter.get(DATABASE)); + String properties = (String)parameter.get(PROPERTIES); + if (StringUtils.isNotEmpty(properties)) { + url += "?" + properties; + } + + return url; + } + +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java new file mode 100644 index 00000000..19bae9f3 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java @@ -0,0 +1,52 @@ +/* + * 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 io.datavines.connector.plugin; + +import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo; +import io.datavines.common.datasource.jdbc.JdbcConnectionInfo; + +public class MariadbDataSourceInfo extends BaseJdbcDataSourceInfo { + + public MariadbDataSourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { + super(jdbcConnectionInfo); + } + + @Override + public String getAddress() { + return "jdbc:mariadb://"+getHost()+":"+getPort(); + } + + @Override + public String getDriverClass() { + return "com.mariadb.cj.jdbc.Driver"; + } + + @Override + public String getType() { + return "mariadb"; + } + + @Override + protected String getSeparator() { + return "?"; + } + + @Override + protected String filterProperties(String other){ + return other; + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java new file mode 100644 index 00000000..6a4b21d8 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java @@ -0,0 +1,46 @@ +/* + * 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 io.datavines.connector.plugin; + +import java.util.Map; + +import static io.datavines.common.ConfigConstants.STRING_TYPE; + +public class MariadbDialect extends JdbcDialect { + + @Override + public Map getDialectKeyMap() { + super.getDialectKeyMap(); + dialectKeyMap.put(STRING_TYPE, "char"); + return dialectKeyMap; + } + + @Override + public String getDriver() { + return "com.mariadb.cj.jdbc.Driver"; + } + + @Override + public boolean invalidateItemCanOutputToSelf() { + return true; + } + + @Override + public boolean supportToBeErrorDataStorage() { + return true; + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbExecutor.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbExecutor.java new file mode 100644 index 00000000..0f6f04d0 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbExecutor.java @@ -0,0 +1,33 @@ +/* + * 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 io.datavines.connector.plugin; + +import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo; +import io.datavines.common.datasource.jdbc.JdbcConnectionInfo; +import io.datavines.connector.api.DataSourceClient; + +public class MariadbExecutor extends BaseJdbcExecutor { + + public MariadbExecutor(DataSourceClient dataSourceClient) { + super(dataSourceClient); + } + + @Override + public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { + return new MariadbDataSourceInfo(jdbcConnectionInfo); + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory new file mode 100644 index 00000000..f8a7dd6d --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory @@ -0,0 +1 @@ +mariadb=io.datavines.connector.plugin.MariadbConnectorFactory \ No newline at end of file diff --git a/datavines-connector/datavines-connector-plugins/pom.xml b/datavines-connector/datavines-connector-plugins/pom.xml index 2b2ec91f..0c4cbb4c 100644 --- a/datavines-connector/datavines-connector-plugins/pom.xml +++ b/datavines-connector/datavines-connector-plugins/pom.xml @@ -33,6 +33,7 @@ datavines-connector-jdbc datavines-connector-mysql + datavines-connector-mariadb datavines-connector-hive datavines-connector-impala datavines-connector-clickhouse diff --git a/pom.xml b/pom.xml index 973de1d7..4929867f 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,7 @@ 1.3.0 1.8 2.1.0 + 3.1.4 6.1.0.jre8 8.1.2.141 4.0.3 @@ -571,6 +572,13 @@ mssql-jdbc ${sqlserver.version} + + + org.mariadb.jdbc + mariadb-java-client + ${mariadb.version} + + com.dameng DmJdbcDriver18 -- Gitee From 9ad3b07ceadfe21ef6660fe747e02154afd9d299 Mon Sep 17 00:00:00 2001 From: wangzhan10 Date: Thu, 11 Jan 2024 16:25:39 +0800 Subject: [PATCH 2/2] fix MariaDB Connector class load driver --- .../io/datavines/connector/plugin/MariadbDataSourceInfo.java | 2 +- .../main/java/io/datavines/connector/plugin/MariadbDialect.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java index 19bae9f3..1de6187a 100644 --- a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDataSourceInfo.java @@ -32,7 +32,7 @@ public class MariadbDataSourceInfo extends BaseJdbcDataSourceInfo { @Override public String getDriverClass() { - return "com.mariadb.cj.jdbc.Driver"; + return "org.mariadb.jdbc.Driver"; } @Override diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java index 6a4b21d8..96644072 100644 --- a/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-mariadb/src/main/java/io/datavines/connector/plugin/MariadbDialect.java @@ -31,7 +31,7 @@ public class MariadbDialect extends JdbcDialect { @Override public String getDriver() { - return "com.mariadb.cj.jdbc.Driver"; + return "org.mariadb.jdbc.Driver"; } @Override -- Gitee