mirror of
https://github.com/apache/sqoop.git
synced 2025-05-02 17:40:39 +08:00
SQOOP-125. Allow user to specify database type.
This fix allows the user to optionally specify the connection manager class to be used, instead of inferring it from the connection string. From: Ahmed Radwan <ahmed@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149993 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b794959457
commit
df738df6c1
@ -23,6 +23,9 @@ Database connection and common options
|
|||||||
--connect (jdbc-uri)::
|
--connect (jdbc-uri)::
|
||||||
Specify JDBC connect string (required)
|
Specify JDBC connect string (required)
|
||||||
|
|
||||||
|
--connect-manager (class-name)::
|
||||||
|
Specify connection manager class name (optional)
|
||||||
|
|
||||||
--driver (class-name)::
|
--driver (class-name)::
|
||||||
Manually specify JDBC driver class to use
|
Manually specify JDBC driver class to use
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
Argument Description
|
Argument Description
|
||||||
---------------------------------------------------------------------
|
---------------------------------------------------------------------
|
||||||
+\--connect <jdbc-uri>+ Specify JDBC connect string
|
+\--connect <jdbc-uri>+ Specify JDBC connect string
|
||||||
|
+\--connect-manager <class-name>+ Specify connection manager class to use
|
||||||
+\--driver <class-name>+ Manually specify JDBC driver class to use
|
+\--driver <class-name>+ Manually specify JDBC driver class to use
|
||||||
+\--hadoop-home <dir>+ Override $HADOOP_HOME
|
+\--hadoop-home <dir>+ Override $HADOOP_HOME
|
||||||
+\--help+ Print usage instructions
|
+\--help+ Print usage instructions
|
||||||
|
@ -65,6 +65,7 @@ usage: sqoop import [GENERIC-ARGS] [TOOL-ARGS]
|
|||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
--connect <jdbc-uri> Specify JDBC connect string
|
--connect <jdbc-uri> Specify JDBC connect string
|
||||||
|
--connect-manager <class-name> Specify connection manager class to use
|
||||||
--driver <class-name> Manually specify JDBC driver class to use
|
--driver <class-name> Manually specify JDBC driver class to use
|
||||||
--hadoop-home <dir> Override $HADOOP_HOME
|
--hadoop-home <dir> Override $HADOOP_HOME
|
||||||
--help Print usage instructions
|
--help Print usage instructions
|
||||||
|
@ -123,6 +123,7 @@ usage: sqoop import [GENERIC-ARGS] [TOOL-ARGS]
|
|||||||
|
|
||||||
Common arguments:
|
Common arguments:
|
||||||
--connect <jdbc-uri> Specify JDBC connect string
|
--connect <jdbc-uri> Specify JDBC connect string
|
||||||
|
--connect-manager <jdbc-uri> Specify connection manager class to use
|
||||||
--driver <class-name> Manually specify JDBC driver class to use
|
--driver <class-name> Manually specify JDBC driver class to use
|
||||||
--hadoop-home <dir> Override $HADOOP_HOME
|
--hadoop-home <dir> Override $HADOOP_HOME
|
||||||
--help Print usage instructions
|
--help Print usage instructions
|
||||||
|
@ -224,6 +224,9 @@ public enum IncrementalMode {
|
|||||||
// a temporary holding area for compilation work done by this process.
|
// a temporary holding area for compilation work done by this process.
|
||||||
private static String curNonce;
|
private static String curNonce;
|
||||||
|
|
||||||
|
// the connection manager fully qualified class name
|
||||||
|
private String connManagerClassName;
|
||||||
|
|
||||||
public SqoopOptions() {
|
public SqoopOptions() {
|
||||||
initDefaults(null);
|
initDefaults(null);
|
||||||
}
|
}
|
||||||
@ -1586,5 +1589,13 @@ public String getMergeKeyCol() {
|
|||||||
return this.mergeKeyCol;
|
return this.mergeKeyCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConnManagerClassName(String connManagerClass) {
|
||||||
|
this.connManagerClassName = connManagerClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConnManagerClassName() {
|
||||||
|
return connManagerClassName;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
package com.cloudera.sqoop.manager;
|
package com.cloudera.sqoop.manager;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@ -42,6 +44,26 @@ public ConnManager accept(JobData data) {
|
|||||||
return new GenericJdbcManager(manualDriver, options);
|
return new GenericJdbcManager(manualDriver, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null != options.getConnManagerClassName()){
|
||||||
|
String className = options.getConnManagerClassName();
|
||||||
|
ConnManager connManager = null;
|
||||||
|
try {
|
||||||
|
Class<ConnManager> cls = (Class<ConnManager>) Class.forName(className);
|
||||||
|
Constructor<ConnManager> constructor =
|
||||||
|
cls.getDeclaredConstructor(SqoopOptions.class);
|
||||||
|
connManager = constructor.newInstance(options);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err
|
||||||
|
.println("problem finding the connection manager for class name :"
|
||||||
|
+ className);
|
||||||
|
// Log the stack trace for this exception
|
||||||
|
LOG.debug(e.getMessage(), e);
|
||||||
|
// Print exception message.
|
||||||
|
System.err.println(e.getMessage());
|
||||||
|
}
|
||||||
|
return connManager;
|
||||||
|
}
|
||||||
|
|
||||||
String connectStr = options.getConnectString();
|
String connectStr = options.getConnectString();
|
||||||
|
|
||||||
// java.net.URL follows RFC-2396 literally, which does not allow a ':'
|
// java.net.URL follows RFC-2396 literally, which does not allow a ':'
|
||||||
|
@ -62,6 +62,8 @@ public abstract class BaseSqoopTool extends SqoopTool {
|
|||||||
// use consistently. The argument parser applies the leading '--' to each
|
// use consistently. The argument parser applies the leading '--' to each
|
||||||
// string.
|
// string.
|
||||||
public static final String CONNECT_STRING_ARG = "connect";
|
public static final String CONNECT_STRING_ARG = "connect";
|
||||||
|
public static final String CONN_MANAGER_CLASS_NAME =
|
||||||
|
"connection-manager";
|
||||||
public static final String DRIVER_ARG = "driver";
|
public static final String DRIVER_ARG = "driver";
|
||||||
public static final String USERNAME_ARG = "username";
|
public static final String USERNAME_ARG = "username";
|
||||||
public static final String PASSWORD_ARG = "password";
|
public static final String PASSWORD_ARG = "password";
|
||||||
@ -329,6 +331,10 @@ protected RelatedOptions getCommonOptions() {
|
|||||||
.hasArg().withDescription("Specify JDBC connect string")
|
.hasArg().withDescription("Specify JDBC connect string")
|
||||||
.withLongOpt(CONNECT_STRING_ARG)
|
.withLongOpt(CONNECT_STRING_ARG)
|
||||||
.create());
|
.create());
|
||||||
|
commonOpts.addOption(OptionBuilder.withArgName("conn-manager-class-name")
|
||||||
|
.hasArg().withDescription("Specify connection manager class name")
|
||||||
|
.withLongOpt(CONN_MANAGER_CLASS_NAME)
|
||||||
|
.create());
|
||||||
commonOpts.addOption(OptionBuilder.withArgName("class-name")
|
commonOpts.addOption(OptionBuilder.withArgName("class-name")
|
||||||
.hasArg().withDescription("Manually specify JDBC driver class to use")
|
.hasArg().withDescription("Manually specify JDBC driver class to use")
|
||||||
.withLongOpt(DRIVER_ARG)
|
.withLongOpt(DRIVER_ARG)
|
||||||
@ -558,6 +564,10 @@ protected void applyCommonOptions(CommandLine in, SqoopOptions out)
|
|||||||
out.setConnectString(in.getOptionValue(CONNECT_STRING_ARG));
|
out.setConnectString(in.getOptionValue(CONNECT_STRING_ARG));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in.hasOption(CONN_MANAGER_CLASS_NAME)) {
|
||||||
|
out.setConnManagerClassName(in.getOptionValue(CONN_MANAGER_CLASS_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
if (in.hasOption(DRIVER_ARG)) {
|
if (in.hasOption(DRIVER_ARG)) {
|
||||||
out.setDriverClassName(in.getOptionValue(DRIVER_ARG));
|
out.setDriverClassName(in.getOptionValue(DRIVER_ARG));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user