Repository: sqoop
Updated Branches:
refs/heads/sqoop2 eda085895 -> 8b51236c2
SQOOP-1640: Sqoop2: Add the rest of the patch
Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/8b51236c
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/8b51236c
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/8b51236c
Branch: refs/heads/sqoop2
Commit: 8b51236c2157dc5444150dee94a166301a60f001
Parents: eda0858
Author: Abraham Elmahrek <abraham@elmahrek.com>
Authored: Sun Nov 2 12:38:44 2014 -0800
Committer: Abraham Elmahrek <abraham@elmahrek.com>
Committed: Sun Nov 2 12:39:28 2014 -0800
----------------------------------------------------------------------
common-test/pom.xml | 164 ++++++++
.../common/test/asserts/ProviderAsserts.java | 74 ++++
.../sqoop/common/test/db/DatabaseProvider.java | 406 +++++++++++++++++++
.../common/test/db/DatabaseProviderFactory.java | 39 ++
.../sqoop/common/test/db/DerbyProvider.java | 107 +++++
.../sqoop/common/test/db/MySQLProvider.java | 83 ++++
.../sqoop/common/test/db/NetezzaProvider.java | 83 ++++
.../sqoop/common/test/db/OracleProvider.java | 83 ++++
.../common/test/db/PostgreSQLProvider.java | 88 ++++
.../sqoop/common/test/db/SqlServerProvider.java | 88 ++++
.../sqoop/common/test/db/TeradataProvider.java | 79 ++++
11 files changed, 1294 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/pom.xml
----------------------------------------------------------------------
diff --git a/common-test/pom.xml b/common-test/pom.xml
new file mode 100644
index 0000000..9fd671c
--- /dev/null
+++ b/common-test/pom.xml
@@ -0,0 +1,164 @@
+<?xml version="1.0"?>
+<!--
+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 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>sqoop</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-common-test</artifactId>
+ <name>Sqoop Common Test Libraries</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derbynet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derbyclient</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+
+ </dependencies>
+
+ <profiles>
+ <!-- Special JDBC Drivers -->
+
+ <!--
+ Oracle JDBC Driver
+ Install: mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=11.2.0.3
-Dpackaging=jar -Dfile=/path/to/the/jar/ojdbc6.jar
+ Usage: mvn integration-test -Djdbc.oracle
+ -->
+ <profile>
+ <id>jdbc-oracle</id>
+
+ <activation>
+ <property>
+ <name>jdbc.oracle</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc14</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <!--
+ Microsoft SQL Server JDBC Driver
+ Install: mvn install:install-file -DgroupId=com.microsoft -DartifactId=sqljdbc4 -Dversion=4.0
-Dpackaging=jar -Dfile=/path/to/the/jar/sqljdbc4.jar
+ Usage: mvn integration-test -Djdbc.sqlserver
+ -->
+ <profile>
+ <id>jdbc-sqlserver</id>
+
+ <activation>
+ <property>
+ <name>jdbc.sqlserver</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.microsoft</groupId>
+ <artifactId>sqljdbc4</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <!--
+ Teradata JDBC Driver
+ Install: mvn install:install-file -DgroupId=com.teradata -DartifactId=tdgssconfig
-Dversion=14.00.00.21 -Dpackaging=jar -Dfile=/path/to/the/jar/tdgssconfig.jar
+ mvn install:install-file -DgroupId=com.teradata -DartifactId=terajdbc4 -Dversion=14.00.00.21
-Dpackaging=jar -Dfile=/path/to/the/jar/terajdbc4.jar
+ Usage: mvn integration-test -Djdbc.teradata
+ -->
+ <profile>
+ <id>jdbc-teradata</id>
+
+ <activation>
+ <property>
+ <name>jdbc.teradata</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.teradata</groupId>
+ <artifactId>tdgssconfig</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.teradata</groupId>
+ <artifactId>terajdbc4</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <!--
+ Netezza JDBC Driver
+ Install: mvn install:install-file -DgroupId=com.ibm.netezza -DartifactId=nzjdbc3 -Dversion=6.0
-Dpackaging=jar -Dfile=/path/to/the/jar/nzjdbc3.jar
+ Usage: mvn integration-test -Djdbc.netezza
+ -->
+ <profile>
+ <id>jdbc-netezza</id>
+
+ <activation>
+ <property>
+ <name>jdbc.netezza</name>
+ </property>
+ </activation>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.ibm.netezza</groupId>
+ <artifactId>nzjdbc3</artifactId>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/asserts/ProviderAsserts.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/asserts/ProviderAsserts.java
b/common-test/src/main/java/org/apache/sqoop/common/test/asserts/ProviderAsserts.java
new file mode 100644
index 0000000..8196fe2
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/asserts/ProviderAsserts.java
@@ -0,0 +1,74 @@
+/**
+ * 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.common.test.asserts;
+
+import org.apache.sqoop.common.test.db.DatabaseProvider;
+import org.apache.log4j.Logger;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Database provider related asserts.
+ */
+public class ProviderAsserts {
+
+ private static final Logger LOG = Logger.getLogger(ProviderAsserts.class);
+
+ /**
+ * Assert row in the table.
+ *
+ * @param provider Provider that should be used to query the database
+ * @param tableName Table name
+ * @param conditions Conditions for identifying the row
+ * @param values Values that should be present in the table
+ */
+ public static void assertRow(DatabaseProvider provider, String tableName, Object []conditions,
Object ...values) {
+ ResultSet rs = null;
+ try {
+ rs = provider.getRows(tableName, conditions);
+
+ if(! rs.next()) {
+ fail("No rows found.");
+ }
+
+ int i = 1;
+ for(Object expectedValue : values) {
+ Object actualValue = rs.getObject(i);
+ assertEquals("Columns do not match on position: " + i, expectedValue, actualValue);
+ i++;
+ }
+
+ if(rs.next()) {
+ fail("Found more than one row.");
+ }
+ } catch (SQLException e) {
+ LOG.error("Unexpected SQLException", e);
+ fail("Unexpected SQLException: " + e);
+ } finally {
+ provider.closeResultSetWithStatement(rs);
+ }
+ }
+
+ private ProviderAsserts() {
+ // Instantiation is prohibited
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
new file mode 100644
index 0000000..0a12d7b
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProvider.java
@@ -0,0 +1,406 @@
+/**
+ * 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.common.test.db;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Database provider for testing purpose.
+ *
+ * Provider contains all methods needed to bootstrap and run the tests on remote
+ * databases. This is abstract implementation that is database agnostic. Each
+ * supported database server have it's own concrete implementation that fills
+ * the gaps in database differences.
+ */
+abstract public class DatabaseProvider {
+
+ private static final Logger LOG = Logger.getLogger(DatabaseProvider.class);
+
+ /**
+ * Internal connection to the database.
+ */
+ private Connection databaseConnection;
+
+ /**
+ * JDBC Url to the remote database system.
+ *
+ * This will be passed to the Sqoop2 server during tests.
+ *
+ * @return String
+ */
+ abstract public String getConnectionUrl();
+
+ /**
+ * Connection username.
+ *
+ * This will be passed to the Sqoop2 server during tests.
+ *
+ * @return String
+ */
+ abstract public String getConnectionUsername();
+
+ /**
+ * Connection password.
+ *
+ * This will be passed to the Sqoop2 server during tests.
+ *
+ * @return String
+ */
+ abstract public String getConnectionPassword();
+
+ /**
+ * Escape column name based on specific database requirements.
+ *
+ * @param columnName Column name
+ * @return Escaped column name
+ */
+ abstract public String escapeColumnName(String columnName);
+
+ /**
+ * Escape table name based on specific database requirements.
+ *
+ * @param tableName Table name
+ * @return Escaped table name
+ */
+ abstract public String escapeTableName(String tableName);
+
+ /**
+ * Escape string value that can be safely used in the queries.
+ *
+ * @param value String value
+ * @return Escaped string value
+ */
+ abstract public String escapeValueString(String value);
+
+ /**
+ * String constant that can be used to denote null (unknown) value.
+ *
+ * @return String encoding null value
+ */
+ public String nullConstant() {
+ return "NULL";
+ }
+
+ /**
+ * True if the underlying database supports custom schemes (namespaces).
+ *
+ * @return
+ */
+ public boolean isSupportingScheme() {
+ return false;
+ }
+
+ public String getJdbcDriver() {
+ return null;
+ }
+
+ /**
+ * Start the handler.
+ */
+ public void start() {
+ if(getJdbcDriver() != null) {
+ loadClass(getJdbcDriver());
+ }
+
+ // Create connection to the database server
+ try {
+ setConnection(DriverManager.getConnection(getConnectionUrl(), getConnectionUsername(),
getConnectionPassword()));
+ } catch (SQLException e) {
+ LOG.error("Can't create connection", e);
+ throw new RuntimeException("Can't create connection", e);
+ }
+ }
+
+ /**
+ * Stop the handler.
+ */
+ public void stop() {
+ // Close connection to the database server
+ if(databaseConnection != null) {
+ try {
+ databaseConnection.close();
+ } catch (SQLException e) {
+ LOG.info("Ignored exception on closing connection", e);
+ }
+ }
+ }
+
+ /**
+ * Return connection to the database.
+ *
+ * @return
+ */
+ public Connection getConnection() {
+ return databaseConnection;
+ }
+
+ /**
+ * Set connection to a new object.
+ *
+ * @param connection New connection object
+ */
+ protected void setConnection(Connection connection) {
+ databaseConnection = connection;
+ }
+
+ /**
+ * Execute DDL or DML query.
+ *
+ * This method will throw RuntimeException on failure.
+ *
+ * @param query DDL or DML query.
+ */
+ public void executeUpdate(String query) {
+ LOG.info("Executing query: " + query);
+ Statement stmt = null;
+
+ try {
+ stmt = databaseConnection.createStatement();
+ stmt.executeUpdate(query);
+ } catch (SQLException e) {
+ LOG.error("Error in executing query", e);
+ throw new RuntimeException("Error in executing query", e);
+ } finally {
+ try {
+ if(stmt != null) {
+ stmt.close();
+ }
+ } catch (SQLException e) {
+ LOG.info("Cant' close statement", e);
+ }
+ }
+ }
+
+ /**
+ * Execute given query in a new statement object and return corresponding
+ * result set. Caller is responsible for closing both ResultSet and Statement
+ * object!
+ *
+ * @param query Query to execute
+ * @return Generated ResultSet
+ */
+ public ResultSet executeQuery(String query) {
+ LOG.info("Executing query: " + query);
+ Statement stmt = null;
+
+ try {
+ stmt = databaseConnection.createStatement();
+ return stmt.executeQuery(query);
+ } catch (SQLException e) {
+ LOG.error("Error in executing query", e);
+ throw new RuntimeException("Error in executing query", e);
+ }
+ }
+
+ /**
+ * Create new table.
+ *
+ * @param name Table name
+ * @param primaryKey Primary key column(0) or null if table should not have any
+ * @param columns List of double values column name and value for example ... "id", "varchar(50)"...
+ */
+ public void createTable(String name, String primaryKey, String ...columns) {
+ // Columns are in form of two strings - name and type
+ if(columns.length == 0 || columns.length % 2 != 0) {
+ throw new RuntimeException("Incorrect number of parameters.");
+ }
+
+ // Drop the table in case that it already exists
+ dropTable(name);
+
+ StringBuilder sb = new StringBuilder("CREATE TABLE ");
+ sb.append(escapeTableName(name)).append("(");
+
+ // Column list
+ List<String> columnList = new LinkedList<String>();
+ for(int i = 0; i < columns.length; i += 2) {
+ String column = escapeColumnName(columns[i]) + " " + columns[i + 1];
+ columnList.add(column);
+ }
+ sb.append(StringUtils.join(columnList, ", "));
+
+ if(primaryKey != null) {
+ sb.append(", PRIMARY KEY(").append(escapeColumnName(primaryKey)).append(")");
+ }
+
+ sb.append(")");
+
+ executeUpdate(sb.toString());
+ }
+
+ /**
+ * Insert new row into the table.
+ *
+ * @param tableName Table name
+ * @param values List of objects that should be inserted
+ */
+ public void insertRow(String tableName, Object ...values) {
+ StringBuilder sb = new StringBuilder("INSERT INTO ");
+ sb.append(escapeTableName(tableName));
+ sb.append(" VALUES (");
+
+ List<String> valueList = new LinkedList<String>();
+ for(Object value : values) {
+ valueList.add(convertObjectToQueryString(value));
+ }
+
+ sb.append(StringUtils.join(valueList, ", "));
+ sb.append(")");
+
+ executeUpdate(sb.toString());
+ }
+
+ /**
+ * Return rows that match given conditions.
+ *
+ * @param tableName Table name
+ * @param conditions Conditions in form of double values - column name and value, for example:
"id", 1 or "last_update_date", null
+ * @return ResultSet with given criteria
+ */
+ public ResultSet getRows(String tableName, Object []conditions) {
+ // Columns are in form of two strings - name and value
+ if(conditions.length % 2 != 0) {
+ throw new RuntimeException("Incorrect number of parameters.");
+ }
+
+ StringBuilder sb = new StringBuilder("SELECT * FROM ");
+ sb.append(escapeTableName(tableName));
+
+ List<String> conditionList = new LinkedList<String>();
+ for(int i = 0; i < conditions.length; i += 2) {
+ Object columnName = conditions[i];
+ Object value = conditions[i + 1];
+
+ if( !(columnName instanceof String)) {
+ throw new RuntimeException("Each odd item should be a string with column name.");
+ }
+
+ if(value == null) {
+ conditionList.add(escapeColumnName((String) columnName) + " IS NULL");
+ } else {
+ conditionList.add(escapeColumnName((String) columnName) + " = " + convertObjectToQueryString(value));
+ }
+ }
+
+ if(conditionList.size() != 0) {
+ sb.append(" WHERE ").append(StringUtils.join(conditionList, " AND "));
+ }
+
+ return executeQuery(sb.toString());
+ }
+
+ /**
+ * Convert given object to it's representation that can be safely used inside
+ * query.
+ *
+ * @param value Value to convert
+ * @return Query safe string representation
+ */
+ public String convertObjectToQueryString(Object value) {
+ if(value == null) {
+ return nullConstant();
+ } else if(value.getClass() == String.class) {
+ return escapeValueString((String)value);
+ } else {
+ return value.toString();
+ }
+ }
+
+ /**
+ * Drop table.
+ *
+ * Any exceptions will be ignored.
+ *
+ * @param tableName
+ */
+ public void dropTable(String tableName) {
+ StringBuilder sb = new StringBuilder("DROP TABLE ");
+ sb.append(escapeTableName(tableName));
+
+ try {
+ executeUpdate(sb.toString());
+ } catch(RuntimeException e) {
+ LOG.info("Ignoring exception: " + e);
+ }
+ }
+
+ /**
+ * Return number of rows from given table.
+ *
+ * @param tableName Table name
+ * @return Number of rows
+ */
+ public long rowCount(String tableName) {
+ StringBuilder sb = new StringBuilder("SELECT COUNT(*) FROM ");
+ sb.append(escapeTableName(tableName));
+
+ ResultSet rs = null;
+ try {
+ rs = executeQuery(sb.toString());
+ if(!rs.next()) {
+ throw new RuntimeException("Row count query did not returned any rows.");
+ }
+
+ return rs.getLong(1);
+ } catch (SQLException e) {
+ LOG.error("Can't get number of rows: ", e);
+ throw new RuntimeException("Can't get number of rows: ", e);
+ } finally {
+ closeResultSetWithStatement(rs);
+ }
+ }
+
+ /**
+ * Close given result set (if not null) and associated statement.
+ *
+ * @param rs ResultSet to close.
+ */
+ public void closeResultSetWithStatement(ResultSet rs) {
+ if(rs != null) {
+ try {
+ Statement stmt = rs.getStatement();
+ rs.close();
+ stmt.close();
+ } catch (SQLException e) {
+ LOG.info("Ignoring exception: ", e);
+ }
+ }
+ }
+
+ /**
+ * Load class.
+ *
+ * @param className Class name
+ */
+ public void loadClass(String className) {
+ try {
+ Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException("Class not found: " + className, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProviderFactory.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProviderFactory.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProviderFactory.java
new file mode 100644
index 0000000..5a01841
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/DatabaseProviderFactory.java
@@ -0,0 +1,39 @@
+/**
+ * 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.common.test.db;
+
+import java.util.Properties;
+
+/**
+ * Create database provider.
+ */
+public class DatabaseProviderFactory {
+
+ public static final String PROVIDER_PROPERTY = "sqoop.provider.class";
+
+ public static DatabaseProvider getProvider(Properties properties) throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
+ String className = properties.getProperty(PROVIDER_PROPERTY);
+ if(className == null) {
+ return new DerbyProvider();
+ }
+
+ Class<?> klass = Class.forName(className);
+ return (DatabaseProvider)klass.newInstance();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/DerbyProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/DerbyProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/DerbyProvider.java
new file mode 100644
index 0000000..f7b91bb
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/DerbyProvider.java
@@ -0,0 +1,107 @@
+/**
+ * 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.common.test.db;
+
+import org.apache.log4j.Logger;
+import org.apache.derby.drda.NetworkServerControl;
+
+import java.net.InetAddress;
+
+/**
+ * Implementation of database provider that is based on embedded derby server.
+ *
+ * This provider will work out of the box without any extra configuration.
+ */
+public class DerbyProvider extends DatabaseProvider {
+
+ private static final Logger LOG = Logger.getLogger(DerbyProvider.class);
+
+ public static final String DRIVER = "org.apache.derby.jdbc.ClientDriver";
+
+ NetworkServerControl server = null;
+
+ @Override
+ public void start() {
+ // Start embedded server
+ try {
+ server = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
+ server.start(null);
+ } catch (Exception e) {
+ LOG.error("Can't start Derby network server", e);
+ throw new RuntimeException("Can't derby server", e);
+ }
+
+ super.start();
+ }
+
+ @Override
+ public void stop() {
+ super.stop();
+
+ // Shutdown embedded server
+ try {
+ server.shutdown();
+ } catch (Exception e) {
+ LOG.info("Can't shut down embedded server", e);
+ }
+ }
+
+ @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 boolean isSupportingScheme() {
+ return true;
+ }
+
+ public String escape(String entity) {
+ return "\"" + entity + "\"";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return DRIVER;
+ }
+
+ @Override
+ public String getConnectionUrl() {
+ return "jdbc:derby://localhost:1527/memory:sqoop;create=true";
+ }
+
+ @Override
+ public String getConnectionUsername() {
+ return null;
+ }
+
+ @Override
+ public String getConnectionPassword() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/MySQLProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/MySQLProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/MySQLProvider.java
new file mode 100644
index 0000000..9814ac8
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/MySQLProvider.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.common.test.db;
+
+/**
+ * MySQL Provider that will connect to remote MySQL 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 MySQLProvider extends DatabaseProvider {
+
+ public static final String DRIVER = "com.mysql.jdbc.Driver";
+
+ private static final String CONNECTION = System.getProperties().getProperty(
+ "sqoop.provider.mysql.jdbc",
+ "jdbc:mysql://localhost/test"
+ );
+
+ private static final String USERNAME = System.getProperties().getProperty(
+ "sqoop.provider.mysql.username",
+ "sqoop"
+ );
+
+ private static final String PASSWORD = System.getProperties().getProperty(
+ "sqoop.provider.mysql.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 + "`";
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/NetezzaProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/NetezzaProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/NetezzaProvider.java
new file mode 100644
index 0000000..d31bf28
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/NetezzaProvider.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.common.test.db;
+
+/**
+ * Netezza Provider that will connect to remote Netezza 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 NetezzaProvider extends DatabaseProvider {
+
+ public static final String DRIVER = "org.netezza.Driver";
+
+ private static final String CONNECTION = System.getProperties().getProperty(
+ "sqoop.provider.netezza.jdbc",
+ "jdbc:netezza://localhost/test"
+ );
+
+ private static final String USERNAME = System.getProperties().getProperty(
+ "sqoop.provider.netezza.username",
+ "sqoop"
+ );
+
+ private static final String PASSWORD = System.getProperties().getProperty(
+ "sqoop.provider.netezza.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 escapeObjectName(columnName);
+ }
+
+ @Override
+ public String escapeTableName(String tableName) {
+ return escapeObjectName(tableName);
+ }
+
+ public String escapeObjectName(String name) {
+ return '"' + name + '"';
+ }
+
+ @Override
+ public String escapeValueString(String value) {
+ return "'" + value + "'";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return DRIVER;
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/OracleProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/OracleProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/OracleProvider.java
new file mode 100644
index 0000000..ed29a23
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/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.common.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 + "\"";
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/PostgreSQLProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/PostgreSQLProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/PostgreSQLProvider.java
new file mode 100644
index 0000000..d46e01d
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/PostgreSQLProvider.java
@@ -0,0 +1,88 @@
+/**
+ * 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.common.test.db;
+
+/**
+ * PostgreSQL Provider that will connect to remote PostgreSQL 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 PostgreSQLProvider extends DatabaseProvider {
+
+ public static final String DRIVER = "org.postgresql.Driver";
+
+ private static final String CONNECTION = System.getProperties().getProperty(
+ "sqoop.provider.postgresql.jdbc",
+ "jdbc:postgresql://localhost/test"
+ );
+
+ private static final String USERNAME = System.getProperties().getProperty(
+ "sqoop.provider.postgresql.username",
+ "sqoop"
+ );
+
+ private static final String PASSWORD = System.getProperties().getProperty(
+ "sqoop.provider.postgresql.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 boolean isSupportingScheme() {
+ return true;
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return DRIVER;
+ }
+
+ public String escape(String entity) {
+ return "\"" + entity + "\"";
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/SqlServerProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/SqlServerProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/SqlServerProvider.java
new file mode 100644
index 0000000..9c56886
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/SqlServerProvider.java
@@ -0,0 +1,88 @@
+/**
+ * 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.common.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 boolean isSupportingScheme() {
+ return true;
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return DRIVER;
+ }
+
+ public String escape(String entity) {
+ return "[" + entity + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8b51236c/common-test/src/main/java/org/apache/sqoop/common/test/db/TeradataProvider.java
----------------------------------------------------------------------
diff --git a/common-test/src/main/java/org/apache/sqoop/common/test/db/TeradataProvider.java
b/common-test/src/main/java/org/apache/sqoop/common/test/db/TeradataProvider.java
new file mode 100644
index 0000000..f99d1ed
--- /dev/null
+++ b/common-test/src/main/java/org/apache/sqoop/common/test/db/TeradataProvider.java
@@ -0,0 +1,79 @@
+/**
+ * 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.common.test.db;
+
+/**
+ * Teradata Provider that will connect to remote Teradata 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 TeradataProvider extends DatabaseProvider {
+
+ public static final String DRIVER = "com.teradata.jdbc.TeraDriver";
+
+ private static final String CONNECTION = System.getProperties().getProperty(
+ "sqoop.provider.teradata.jdbc",
+ "jdbc:teradata://localhost/test"
+ );
+
+ private static final String USERNAME = System.getProperties().getProperty(
+ "sqoop.provider.teradata.username",
+ "sqoop"
+ );
+
+ private static final String PASSWORD = System.getProperties().getProperty(
+ "sqoop.provider.teradata.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 columnName;
+ }
+
+ @Override
+ public String escapeTableName(String tableName) {
+ return tableName;
+ }
+
+ @Override
+ public String escapeValueString(String value) {
+ return "'" + value + "'";
+ }
+
+ @Override
+ public String getJdbcDriver() {
+ return DRIVER;
+ }
+}
|