-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature-293][Connector] Add dameng connector (#298)
- Loading branch information
Showing
13 changed files
with
342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
datavines-connector/datavines-connector-plugins/datavines-connector-dm/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>datavines-connector-plugins</artifactId> | ||
<groupId>io.datavines</groupId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>datavines-connector-dm</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.datavines</groupId> | ||
<artifactId>datavines-connector-jdbc</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.dameng</groupId> | ||
<artifactId>DmJdbcDriver18</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
36 changes: 36 additions & 0 deletions
36
...s/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...atavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...nnector-dm/src/main/java/io/datavines/connector/plugin/DmConnectorParameterConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, Object> 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; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDataSourceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "?"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...plugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...lugins/datavines-connector-dm/src/main/java/io/datavines/connector/plugin/DmExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...nector-dm/src/main/resources/META-INF/plugins/io.datavines.connector.api.ConnectorFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dm=io.datavines.connector.plugin.DmConnectorFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters