-
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][Connector] Add oracle connector (#309)
- Loading branch information
Showing
16 changed files
with
455 additions
and
3 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
22 changes: 22 additions & 0 deletions
22
datavines-connector/datavines-connector-plugins/datavines-connector-oracle/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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.datavines</groupId> | ||
<artifactId>datavines-connector-plugins</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>datavines-connector-oracle</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.datavines</groupId> | ||
<artifactId>datavines-connector-jdbc</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
31 changes: 31 additions & 0 deletions
31
...nes-connector-oracle/src/main/java/io/datavines/connector/plugin/OracleConfigBuilder.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,31 @@ | ||
/* | ||
* 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 OracleConfigBuilder extends JdbcConfigBuilder{ | ||
@Override | ||
protected InputParam getSchemaInput(boolean isEn) { | ||
return getInputParam("schema", | ||
isEn ? "schema" : "模式", | ||
isEn ? "please enter schema" : "请填入模式", 1, | ||
Validate.newBuilder().setRequired(true).setMessage(isEn ? "please enter schema" : "请填入模式").build(), null); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...tavines-connector-oracle/src/main/java/io/datavines/connector/plugin/OracleConnector.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,49 @@ | ||
/* | ||
* 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 OracleConnector extends JdbcConnector{ | ||
|
||
@Override | ||
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { | ||
return new OracleDataSourceInfo(jdbcConnectionInfo); | ||
} | ||
|
||
@Override | ||
public ResultSet getMetadataColumns(DatabaseMetaData metaData, String catalog, String schema, String tableName, String columnName) throws SQLException { | ||
return metaData.getColumns(null,schema.toUpperCase(), tableName, columnName); | ||
} | ||
|
||
@Override | ||
public ResultSet getMetadataTables(DatabaseMetaData metaData, String catalog, String schema) throws SQLException { | ||
return metaData.getTables(null,schema.toUpperCase(), null, TABLE_TYPES); | ||
} | ||
|
||
@Override | ||
public ResultSet getMetadataDatabases(Connection connection) throws SQLException { | ||
java.sql.Statement stmt = connection.createStatement(); | ||
return stmt.executeQuery("select NAME AS Database FROM V$database"); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...-connector-oracle/src/main/java/io/datavines/connector/plugin/OracleConnectorFactory.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.connector.api.ConnectorParameterConverter; | ||
import io.datavines.connector.api.Dialect; | ||
import io.datavines.connector.api.Connector; | ||
import io.datavines.connector.api.Executor; | ||
import io.datavines.connector.api.ConfigBuilder; | ||
import io.datavines.connector.api.TypeConverter; | ||
public class OracleConnectorFactory extends AbstractJdbcConnectorFactory{ | ||
@Override | ||
public ConnectorParameterConverter getConnectorParameterConverter() { | ||
return new OracleConnectorParameterConverter(); | ||
} | ||
|
||
@Override | ||
public Dialect getDialect() { | ||
return new OracleDialect(); | ||
} | ||
|
||
@Override | ||
public Connector getConnector() { | ||
return new OracleConnector(); | ||
} | ||
|
||
@Override | ||
public Executor getExecutor() { | ||
return new OracleExecutor(new JdbcDataSourceClient()); | ||
} | ||
|
||
@Override | ||
public ConfigBuilder getConfigBuilder() { | ||
return new OracleConfigBuilder(); | ||
} | ||
|
||
@Override | ||
public TypeConverter getTypeConverter() { | ||
return new OracleTypeConverter(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...oracle/src/main/java/io/datavines/connector/plugin/OracleConnectorParameterConverter.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,48 @@ | ||
/* | ||
* 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.HOST; | ||
import static io.datavines.common.ConfigConstants.PORT; | ||
import static io.datavines.common.ConfigConstants.DATABASE; | ||
import static io.datavines.common.ConfigConstants.PROPERTIES; | ||
|
||
public class OracleConnectorParameterConverter extends JdbcConnectorParameterConverter{ | ||
|
||
@Override | ||
protected String getUrl(Map<String, Object> parameter) { | ||
String url = String.format("jdbc:oracle:thin:@%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; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> converter(Map<String, Object> parameter) { | ||
return super.converter(parameter); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...es-connector-oracle/src/main/java/io/datavines/connector/plugin/OracleDataSourceInfo.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,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 OracleDataSourceInfo extends BaseJdbcDataSourceInfo { | ||
|
||
public OracleDataSourceInfo(JdbcConnectionInfo jdbcConnectionInfo){ | ||
super(jdbcConnectionInfo); | ||
} | ||
|
||
@Override | ||
public String getAddress() { | ||
return "jdbc:oracle:thin:@" + getHost() + ":" + getPort(); | ||
} | ||
|
||
@Override | ||
public String getDriverClass() { | ||
return "oracle.jdbc.driver.OracleDriver"; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return "oracle"; | ||
} | ||
|
||
@Override | ||
protected String getSeparator() { | ||
return "?"; | ||
} | ||
|
||
@Override | ||
public String getValidationQuery() { | ||
return "Select 1 FROM DUAL"; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...datavines-connector-oracle/src/main/java/io/datavines/connector/plugin/OracleDialect.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,70 @@ | ||
/* | ||
* 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.*; | ||
|
||
public class OracleDialect extends JdbcDialect{ | ||
@Override | ||
public Map<String, String> getDialectKeyMap() { | ||
super.getDialectKeyMap(); | ||
dialectKeyMap.put(STRING_TYPE, "VARCHAR2"); | ||
dialectKeyMap.put(LIMIT_TOP_50_KEY, " rownum <= 50"); | ||
dialectKeyMap.put(IF_CASE_KEY, "case when ${column} is null then 'NULL' else ${column}||'' end "); | ||
return dialectKeyMap; | ||
} | ||
|
||
@Override | ||
public String getDriver() { | ||
return "oracle.jdbc.driver.OracleDriver"; | ||
} | ||
|
||
@Override | ||
public boolean invalidateItemCanOutputToSelf() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean supportToBeErrorDataStorage() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getCreateTableAsSelectStatement(String srcTable, String targetDatabase, String targetTable) { | ||
return String.format("CREATE TABLE %s.%s AS SELECT * FROM %s", quoteIdentifier(targetDatabase), quoteIdentifier(targetTable), quoteIdentifier(srcTable)); | ||
} | ||
|
||
@Override | ||
public String quoteIdentifier(String column) { | ||
return column; | ||
} | ||
|
||
@Override | ||
public String getFullQualifiedTableName(String database, String schema, String table,boolean needQuote) { | ||
table = quoteIdentifier(table); | ||
|
||
if (!StringUtils.isEmptyOrNullStr(schema)) { | ||
table = quoteIdentifier(schema) + "." + table; | ||
} | ||
|
||
return table; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...atavines-connector-oracle/src/main/java/io/datavines/connector/plugin/OracleExecutor.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,32 @@ | ||
/* | ||
* 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 OracleExecutor extends BaseJdbcExecutor{ | ||
|
||
public OracleExecutor(JdbcDataSourceClient jdbcDataSourceClient) { | ||
super(jdbcDataSourceClient); | ||
} | ||
|
||
@Override | ||
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) { | ||
return new OracleDataSourceInfo(jdbcConnectionInfo); | ||
} | ||
} |
Oops, something went wrong.