5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-04 02:21:10 +08:00

SQOOP-1640. Sqoop2: Pull DatabaseProvider into sqoop-common-test module

(Abraham Elmahrek via Hari Shreedharan)
This commit is contained in:
Hari Shreedharan 2014-10-31 13:45:21 -07:00
parent 21d4a9518b
commit 184f024648
16 changed files with 17 additions and 1136 deletions

View File

@ -257,6 +257,11 @@ limitations under the License.
<artifactId>sqoop-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-common-test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-core</artifactId>
@ -470,6 +475,7 @@ limitations under the License.
<modules>
<module>common</module>
<module>common-test</module>
<module>spi</module>
<module>core</module>
<module>repository</module>

View File

@ -35,6 +35,11 @@ limitations under the License.
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-common-test</artifactId>
</dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-core</artifactId>

View File

@ -1,74 +0,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.
*/
package org.apache.sqoop.test.asserts;
import org.apache.sqoop.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
}
}

View File

@ -17,7 +17,7 @@
*/
package org.apache.sqoop.test.data;
import org.apache.sqoop.test.db.DatabaseProvider;
import org.apache.sqoop.common.test.db.DatabaseProvider;
/**
* Simple listing of few world's cities to do basic sanity tests.

View File

@ -17,7 +17,7 @@
*/
package org.apache.sqoop.test.data;
import org.apache.sqoop.test.db.DatabaseProvider;
import org.apache.sqoop.common.test.db.DatabaseProvider;
/**
* Abstract class for basic testing data sets.

View File

@ -17,7 +17,7 @@
*/
package org.apache.sqoop.test.data;
import org.apache.sqoop.test.db.DatabaseProvider;
import org.apache.sqoop.common.test.db.DatabaseProvider;
/**
* Releases of Ubuntu Linux.

View File

@ -1,406 +0,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.
*/
package org.apache.sqoop.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);
}
}
}

View File

@ -1,39 +0,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.
*/
package org.apache.sqoop.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();
}
}

View File

@ -1,107 +0,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.
*/
package org.apache.sqoop.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;
}
}

View File

@ -1,83 +0,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.
*/
package org.apache.sqoop.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 + "`";
}
}

View File

@ -1,83 +0,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.
*/
package org.apache.sqoop.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;
}
}

View File

@ -1,83 +0,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.
*/
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 + "\"";
}
}

View File

@ -1,88 +0,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.
*/
package org.apache.sqoop.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 + "\"";
}
}

View File

@ -1,88 +0,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.
*/
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 boolean isSupportingScheme() {
return true;
}
@Override
public String getJdbcDriver() {
return DRIVER;
}
public String escape(String entity) {
return "[" + entity + "]";
}
}

View File

@ -1,79 +0,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.
*/
package org.apache.sqoop.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;
}
}

View File

@ -25,17 +25,17 @@
import org.apache.log4j.Logger;
import org.apache.sqoop.client.SubmissionCallback;
import org.apache.sqoop.common.Direction;
import org.apache.sqoop.common.test.asserts.ProviderAsserts;
import org.apache.sqoop.common.test.db.DatabaseProvider;
import org.apache.sqoop.common.test.db.DatabaseProviderFactory;
import org.apache.sqoop.connector.hdfs.configuration.ToFormat;
import org.apache.sqoop.model.MConfigList;
import org.apache.sqoop.model.MJob;
import org.apache.sqoop.model.MLink;
import org.apache.sqoop.model.MPersistableEntity;
import org.apache.sqoop.model.MSubmission;
import org.apache.sqoop.test.asserts.ProviderAsserts;
import org.apache.sqoop.test.data.Cities;
import org.apache.sqoop.test.data.UbuntuReleases;
import org.apache.sqoop.test.db.DatabaseProvider;
import org.apache.sqoop.test.db.DatabaseProviderFactory;
import org.apache.sqoop.test.hadoop.HadoopMiniClusterRunner;
import org.apache.sqoop.test.hadoop.HadoopRunnerFactory;
import org.apache.sqoop.validation.Status;