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 8b9fb7f34..a44652a04 100644 --- a/datavines-connector/datavines-connector-plugins/datavines-connector-all/pom.xml +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-all/pom.xml @@ -146,6 +146,12 @@ ${project.version} + + io.datavines + datavines-connector-dm + ${project.version} + + \ No newline at end of file diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/pom.xml b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/pom.xml new file mode 100644 index 000000000..6103f8e46 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/pom.xml @@ -0,0 +1,45 @@ + + + + + + datavines-connector-plugins + io.datavines + 1.0.0-SNAPSHOT + + 4.0.0 + + datavines-connector-dm + + + + io.datavines + datavines-connector-jdbc + ${project.version} + + + com.dameng + DmJdbcDriver18 + + + + \ No newline at end of file diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConfigBuilder.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConfigBuilder.java new file mode 100644 index 000000000..499be7598 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConfigBuilder.java @@ -0,0 +1,36 @@ +/* + * 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.Validate; +import io.datavines.common.param.form.type.InputParam; + +public class DmConfigBuilder extends JdbcConfigBuilder{ + + @Override + protected InputParam getDatabaseInput(boolean isEn) { + // DM only need schema. + // To avoid affecting the original code structure, the schema will be stored in the database here + return getInputParam("database", + isEn ? "schema" : "模式", + isEn ? "please enter schema, which is usually the same as the username" : "请填入模式, 一般和用户名相同", 1, + Validate.newBuilder().setRequired(true).setMessage(isEn ? "please enter schema" : "请填入模式").build(), + null); + } + + +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnector.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnector.java new file mode 100644 index 000000000..12887cfa8 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnector.java @@ -0,0 +1,55 @@ +/* + * 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 java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class DmConnector extends JdbcConnector { + @Override + public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { + return new DmDataSourceInfo(jdbcConnectionInfo); + } + + @Override + protected ResultSet getMetadataDatabases(Connection connection) throws SQLException { + DatabaseMetaData metaData = connection.getMetaData(); + // DM only need schema + return metaData.getSchemas(); + } + + protected ResultSet getMetadataTables(DatabaseMetaData metaData, String catalog, String schema) throws SQLException { + // DM only need schema + return metaData.getTables(null, schema, null, TABLE_TYPES); + } + + protected ResultSet getMetadataColumns(DatabaseMetaData metaData, + String catalog, String schema, + String tableName, String columnName) throws SQLException { + // DM only need schema + return metaData.getColumns(null, schema, tableName, columnName); + } + + protected ResultSet getPrimaryKeys(DatabaseMetaData metaData,String catalog, String schema, String tableName) throws SQLException { + // DM only need schema + return metaData.getPrimaryKeys(null, schema, tableName); + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorFactory.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorFactory.java new file mode 100644 index 000000000..a688db82c --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorFactory.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 io.datavines.connector.api.*; + +public class DmConnectorFactory extends AbstractJdbcConnectorFactory { + @Override + public Connector getConnector() { + return new DmConnector(); + } + + @Override + public Dialect getDialect() { + return new DmDialect(); + } + + @Override + public ConnectorParameterConverter getConnectorParameterConverter() { + return new DmConnectorParameterConverter(); + } + + @Override + public Executor getExecutor() { + return new DmExecutor(); + } + + @Override + public ConfigBuilder getConfigBuilder() { + return new DmConfigBuilder(); + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorParameterConverter.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorParameterConverter.java new file mode 100644 index 000000000..b093456e3 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorParameterConverter.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.utils.StringUtils; +import java.util.Map; +import static io.datavines.common.ConfigConstants.*; +import static io.datavines.common.ConfigConstants.PROPERTIES; + +public class DmConnectorParameterConverter extends JdbcConnectorParameterConverter { + @Override + protected String getUrl(Map parameter) { + // in dm jdbc url, the database is not need. + String url = String.format("jdbc:dm://%s:%s?schema=%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-dm/src/main/java/io/datavines/connector/plugin/DmDataSourceInfo.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDataSourceInfo.java new file mode 100644 index 000000000..080724aca --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDataSourceInfo.java @@ -0,0 +1,50 @@ +/* + * 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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DmDataSourceInfo extends BaseJdbcDataSourceInfo { + private final Logger logger = LoggerFactory.getLogger(DmDataSourceInfo.class); + + public DmDataSourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { + super(jdbcConnectionInfo); + } + + @Override + public String getAddress() { + return "jdbc:dm://"+getHost()+":"+getPort(); + } + + @Override + public String getDriverClass() { + return "dm.jdbc.driver.DmDriver"; + } + + @Override + public String getType() { + return "dameng"; + } + + @Override + protected String getSeparator() { + return "?"; + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDialect.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDialect.java new file mode 100644 index 000000000..3680c1467 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDialect.java @@ -0,0 +1,29 @@ +/* + * 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; + +public class DmDialect extends JdbcDialect{ + @Override + public String getDriver() { + return "dm.jdbc.driver.DmDriver"; + } + + @Override + public boolean invalidateItemCanOutput() { + return false; + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmExecutor.java b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmExecutor.java new file mode 100644 index 000000000..1e43b92eb --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmExecutor.java @@ -0,0 +1,28 @@ +/* + * 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 DmExecutor extends BaseJdbcExecutor{ + + @Override + public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { + return new DmDataSourceInfo(jdbcConnectionInfo); + } +} diff --git a/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory new file mode 100644 index 000000000..8ae1a6816 --- /dev/null +++ b/datavines-connector/datavines-connector-plugins/datavines-connector-dm/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory @@ -0,0 +1 @@ +dm=io.datavines.connector.plugin.DmConnectorFactory \ 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 24dc8964d..d230b38b0 100644 --- a/datavines-connector/datavines-connector-plugins/pom.xml +++ b/datavines-connector/datavines-connector-plugins/pom.xml @@ -46,6 +46,7 @@ datavines-connector-databend datavines-connector-mongodb datavines-connector-sqlserver + datavines-connector-dm diff --git a/datavines-dist/src/main/assembly/datavines-bin.xml b/datavines-dist/src/main/assembly/datavines-bin.xml index 8cc70729b..29aa076a9 100644 --- a/datavines-dist/src/main/assembly/datavines-bin.xml +++ b/datavines-dist/src/main/assembly/datavines-bin.xml @@ -106,6 +106,7 @@ org.postgresql:postgresql com.facebook.presto:presto-jdbc io.trino:trino-jdbc + com.dameng:DmJdbcDriver18 diff --git a/pom.xml b/pom.xml index 1dc2ed43c..5be0818b3 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,7 @@ 1.8 2.1.0 6.1.0.jre8 + 8.1.2.141 4.0.3 5.3.12 1.0.1.RELEASE @@ -568,6 +569,11 @@ mssql-jdbc ${sqlserver.version} + + com.dameng + DmJdbcDriver18 + ${dameng.version} + com.zaxxer HikariCP