mirror of
https://github.com/apache/sqoop.git
synced 2025-05-07 00:03:22 +08:00
SQOOP-579. Simple refactoring of org.apache.sqoop.manager.DefaultManagerFactory - extract methods for reuse.
(Seetharam Venkatesh via Jarek Jarcec Cecho) git-svn-id: https://svn.apache.org/repos/asf/sqoop/trunk@1375401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0c396d575b
commit
1b896f3e46
@ -37,33 +37,8 @@ public class DefaultManagerFactory
|
||||
|
||||
public ConnManager accept(JobData data) {
|
||||
SqoopOptions options = data.getSqoopOptions();
|
||||
String connectStr = options.getConnectString();
|
||||
|
||||
// java.net.URL follows RFC-2396 literally, which does not allow a ':'
|
||||
// character in the scheme component (section 3.1). JDBC connect strings,
|
||||
// however, commonly have a multi-scheme addressing system. e.g.,
|
||||
// jdbc:mysql://...; so we cannot parse the scheme component via URL
|
||||
// objects. Instead, attempt to pull out the scheme as best as we can.
|
||||
|
||||
// First, see if this is of the form [scheme://hostname-and-etc..]
|
||||
int schemeStopIdx = connectStr.indexOf("//");
|
||||
if (-1 == schemeStopIdx) {
|
||||
// If no hostname start marker ("//"), then look for the right-most ':'
|
||||
// character.
|
||||
schemeStopIdx = connectStr.lastIndexOf(':');
|
||||
if (-1 == schemeStopIdx) {
|
||||
// Warn that this is nonstandard. But we should be as permissive
|
||||
// as possible here and let the ConnectionManagers themselves throw
|
||||
// out the connect string if it doesn't make sense to them.
|
||||
LOG.warn("Could not determine scheme component of connect string");
|
||||
|
||||
// Use the whole string.
|
||||
schemeStopIdx = connectStr.length();
|
||||
}
|
||||
}
|
||||
|
||||
String scheme = connectStr.substring(0, schemeStopIdx);
|
||||
|
||||
String scheme = extractScheme(options);
|
||||
if (null == scheme) {
|
||||
// We don't know if this is a mysql://, hsql://, etc.
|
||||
// Can't do anything with this.
|
||||
@ -97,5 +72,34 @@ public ConnManager accept(JobData data) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected String extractScheme(SqoopOptions options) {
|
||||
String connectStr = options.getConnectString();
|
||||
|
||||
// java.net.URL follows RFC-2396 literally, which does not allow a ':'
|
||||
// character in the scheme component (section 3.1). JDBC connect strings,
|
||||
// however, commonly have a multi-scheme addressing system. e.g.,
|
||||
// jdbc:mysql://...; so we cannot parse the scheme component via URL
|
||||
// objects. Instead, attempt to pull out the scheme as best as we can.
|
||||
|
||||
// First, see if this is of the form [scheme://hostname-and-etc..]
|
||||
int schemeStopIdx = connectStr.indexOf("//");
|
||||
if (-1 == schemeStopIdx) {
|
||||
// If no hostname start marker ("//"), then look for the right-most ':'
|
||||
// character.
|
||||
schemeStopIdx = connectStr.lastIndexOf(':');
|
||||
if (-1 == schemeStopIdx) {
|
||||
// Warn that this is nonstandard. But we should be as permissive
|
||||
// as possible here and let the ConnectionManagers themselves throw
|
||||
// out the connect string if it doesn't make sense to them.
|
||||
LOG.warn("Could not determine scheme component of connect string");
|
||||
|
||||
// Use the whole string.
|
||||
schemeStopIdx = connectStr.length();
|
||||
}
|
||||
}
|
||||
|
||||
return connectStr.substring(0, schemeStopIdx);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user