Skip to content

Commit

Permalink
[Feature][Connector] Add oracle connector (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
anan0120 authored Dec 9, 2023
1 parent 56aae12 commit 58d65ba
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.datavines</groupId>
<artifactId>datavines-connector-oracle</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

</project>
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>
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);
}

}
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");
}
}
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();
}
}
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);
}
}
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";
}
}
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;
}
}
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);
}
}
Loading

0 comments on commit 58d65ba

Please sign in to comment.