From 2237d94e6669e76dc619378e189034d583f8ead5 Mon Sep 17 00:00:00 2001 From: Kate Date: Sat, 23 Mar 2013 19:25:37 -0400 Subject: [PATCH] SQOOP-909: Sqoop2 integration: Create Oracle and Microsoft SQL Server database providers (Jarek Jarcec Cecho via Kathleen Ting) --- pom.xml | 12 +++ test/pom.xml | 47 +++++++++++ .../apache/sqoop/test/db/OracleProvider.java | 83 +++++++++++++++++++ .../sqoop/test/db/SqlServerProvider.java | 83 +++++++++++++++++++ .../minicluster/TomcatSqoopMiniCluster.java | 2 + 5 files changed, 227 insertions(+) create mode 100644 test/src/main/java/org/apache/sqoop/test/db/OracleProvider.java create mode 100644 test/src/main/java/org/apache/sqoop/test/db/SqlServerProvider.java diff --git a/pom.xml b/pom.xml index 0620d086..25dfba6c 100644 --- a/pom.xml +++ b/pom.xml @@ -108,6 +108,8 @@ limitations under the License. ${tomcat.major.version}.${tomcat.minor.version} 5.1.23 9.1-901.jdbc4 + 11.2.0.3 + 4.0 @@ -362,6 +364,16 @@ limitations under the License. postgresql ${jdbc.postgresql.version} + + com.oracle + ojdbc14 + ${jdbc.oracle.version} + + + com.microsoft + sqljdbc4 + ${jdbc.sqlserver.version} + diff --git a/test/pom.xml b/test/pom.xml index 26aa556c..58f1c498 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -228,6 +228,53 @@ limitations under the License. + + + + + + jdbc-oracle + + + + jdbc.oracle + + + + + + com.oracle + ojdbc14 + + + + + + + jdbc-sqlserver + + + + jdbc.sqlserver + + + + + + com.microsoft + sqljdbc4 + + + + diff --git a/test/src/main/java/org/apache/sqoop/test/db/OracleProvider.java b/test/src/main/java/org/apache/sqoop/test/db/OracleProvider.java new file mode 100644 index 00000000..5a55c851 --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/db/OracleProvider.java @@ -0,0 +1,83 @@ +/** + * 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 org.apache.sqoop.test.db; + +/** + * Oracle Provider that will connect to remote Oracle server. + * + * JDBC can be configured via system properties. Default value is server running + * on the same box (localhost) that is access via sqoop/sqoop credentials. + */ +public class OracleProvider extends DatabaseProvider { + + public static final String DRIVER = "oracle.jdbc.OracleDriver"; + + private static final String CONNECTION = System.getProperties().getProperty( + "sqoop.provider.oracle.jdbc", + "jdbc:oracle:thin:@//localhost/xe" + ); + + private static final String USERNAME = System.getProperties().getProperty( + "sqoop.provider.oracle.username", + "sqoop" + ); + + private static final String PASSWORD = System.getProperties().getProperty( + "sqoop.provider.oracle.password", + "sqoop" + ); + + @Override + public String getConnectionUrl() { + return CONNECTION; + } + + @Override + public String getConnectionUsername() { + return USERNAME; + } + + @Override + public String getConnectionPassword() { + return PASSWORD; + } + + @Override + public String escapeColumnName(String columnName) { + return escape(columnName); + } + + @Override + public String escapeTableName(String tableName) { + return escape(tableName); + } + + @Override + public String escapeValueString(String value) { + return "'" + value + "'"; + } + + @Override + public String getJdbcDriver() { + return DRIVER; + } + + public String escape(String entity) { + return "\"" + entity + "\""; + } +} diff --git a/test/src/main/java/org/apache/sqoop/test/db/SqlServerProvider.java b/test/src/main/java/org/apache/sqoop/test/db/SqlServerProvider.java new file mode 100644 index 00000000..35b6ef39 --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/db/SqlServerProvider.java @@ -0,0 +1,83 @@ +/** + * 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 org.apache.sqoop.test.db; + +/** + * Oracle Provider that will connect to remote Oracle server. + * + * JDBC can be configured via system properties. Default value is server running + * on the same box (localhost) that is access via sqoop/sqoop credentials. + */ +public class SqlServerProvider extends DatabaseProvider { + + public static final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; + + private static final String CONNECTION = System.getProperties().getProperty( + "sqoop.provider.sqlserver.jdbc", + "jdbc:sqlserver://localhost" + ); + + private static final String USERNAME = System.getProperties().getProperty( + "sqoop.provider.sqlserver.username", + "sqoop" + ); + + private static final String PASSWORD = System.getProperties().getProperty( + "sqoop.provider.sqlserver.password", + "sqoop" + ); + + @Override + public String getConnectionUrl() { + return CONNECTION; + } + + @Override + public String getConnectionUsername() { + return USERNAME; + } + + @Override + public String getConnectionPassword() { + return PASSWORD; + } + + @Override + public String escapeColumnName(String columnName) { + return escape(columnName); + } + + @Override + public String escapeTableName(String tableName) { + return escape(tableName); + } + + @Override + public String escapeValueString(String value) { + return "'" + value + "'"; + } + + @Override + public String getJdbcDriver() { + return DRIVER; + } + + public String escape(String entity) { + return "[" + entity + "]"; + } +} diff --git a/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java b/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java index 567ddbcf..c7998a17 100644 --- a/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java +++ b/test/src/main/java/org/apache/sqoop/test/minicluster/TomcatSqoopMiniCluster.java @@ -95,6 +95,8 @@ public void start() throws Exception { jar.contains("avro-") || // Avro jar.contains("mysql") || // MySQL JDBC driver jar.contains("postgre") || // PostgreSQL JDBC driver + jar.contains("oracle") || // Oracle driver + jar.contains("sqljdbc") || // Microsoft SQL Server driver jar.contains("google") // Google libraries (guava, ...) ) { extraClassPath.add(jar);