You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by na...@apache.org on 2013/05/24 14:49:20 UTC
svn commit: r1486038 - in /hive/trunk/jdbc/src:
java/org/apache/hive/jdbc/HiveDriver.java
test/org/apache/hive/jdbc/TestJdbcDriver2.java
Author: navis
Date: Fri May 24 12:49:20 2013
New Revision: 1486038
URL: http://svn.apache.org/r1486038
Log:
JDBC2: HiveDriver should not throw RuntimeException when passed an invalid URL (Richard Ding via Navis)
Modified:
hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveDriver.java
hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
Modified: hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveDriver.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveDriver.java?rev=1486038&r1=1486037&r2=1486038&view=diff
==============================================================================
--- hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveDriver.java (original)
+++ hive/trunk/jdbc/src/java/org/apache/hive/jdbc/HiveDriver.java Fri May 24 12:49:20 2013
@@ -100,8 +100,13 @@ public class HiveDriver implements Drive
return Pattern.matches(URL_PREFIX + ".*", url);
}
+ /*
+ * As per JDBC 3.0 Spec (section 9.2)
+ * "If the Driver implementation understands the URL, it will return a Connection object;
+ * otherwise it returns null"
+ */
public Connection connect(String url, Properties info) throws SQLException {
- return new HiveConnection(url, info);
+ return acceptsURL(url) ? new HiveConnection(url, info) : null;
}
/**
Modified: hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java
URL: http://svn.apache.org/viewvc/hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java?rev=1486038&r1=1486037&r2=1486038&view=diff
==============================================================================
--- hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java (original)
+++ hive/trunk/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java Fri May 24 12:49:20 2013
@@ -34,6 +34,7 @@ import java.sql.Types;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
@@ -43,6 +44,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hive.common.util.HiveVersionInfo;
+
/**
* TestJdbcDriver2
*
@@ -1263,4 +1265,14 @@ public class TestJdbcDriver2 extends Tes
assertFalse(res.next());
}
+ /**
+ * If the Driver implementation understands the URL, it will return a Connection object;
+ * otherwise it returns null
+ */
+ public void testInvalidURL() throws Exception {
+ HiveDriver driver = new HiveDriver();
+ Connection conn = driver.connect("jdbc:derby://localhost:10000/default", new Properties());
+ assertNull(conn);
+ }
+
}