diff --git jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java index 59ce692..94293cd 100644 --- jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java +++ jdbc/src/java/org/apache/hadoop/hive/jdbc/HiveConnection.java @@ -29,6 +29,8 @@ import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransportException; + +import java.sql.ResultSet; import java.util.concurrent.Executor; import java.sql.Array; @@ -343,6 +345,9 @@ public int getHoldability() throws SQLException { */ public DatabaseMetaData getMetaData() throws SQLException { + if (isClosed) { + throw new SQLException("Connection is closed"); + } return new HiveDatabaseMetaData(client); } @@ -354,8 +359,19 @@ public int getNetworkTimeout() throws SQLException { public String getSchema() throws SQLException { - // JDK 1.7 - throw new SQLException("Method not supported"); + if (isClosed) { + throw new SQLException("Connection is closed"); + } + Statement stmt = createStatement(); + try { + ResultSet res = stmt.executeQuery("SELECT current_database()"); + if (!res.next()) { + throw new SQLException("Failed to get schema information"); + } + return res.getString(1); + } finally { + stmt.close(); + } } /* * (non-Javadoc) @@ -574,8 +590,9 @@ public void rollback(Savepoint savepoint) throws SQLException { */ public void setAutoCommit(boolean autoCommit) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + if (autoCommit) { + throw new SQLException("enabling autocommit is not supported"); + } } /* @@ -585,8 +602,12 @@ public void setAutoCommit(boolean autoCommit) throws SQLException { */ public void setCatalog(String catalog) throws SQLException { - // TODO Auto-generated method stub - throw new SQLException("Method not supported"); + // Per JDBC spec, if the driver does not support catalogs, + // it will silently ignore this request. + if (isClosed) { + throw new SQLException("Connection is closed"); + } + return; } /* @@ -664,7 +685,15 @@ public Savepoint setSavepoint(String name) throws SQLException { public void setSchema(String schema) throws SQLException { // JDK 1.7 - throw new SQLException("Method not supported"); + if (isClosed) { + throw new SQLException("Connection is closed"); + } + if (schema == null || schema.isEmpty()) { + throw new SQLException("Schema name is null or empty"); + } + Statement stmt = createStatement(); + stmt.execute("use " + schema); + stmt.close(); } /*