Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 966b0d539 -> 262078251


PHOENIX-2875 Fix isolation level returned by PhoenixDatabaseMetaData for 
transactional tables


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/26207825
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/26207825
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/26207825

Branch: refs/heads/4.x-HBase-0.98
Commit: 262078251f93b66c20f06df7ed8cf00923daf1c6
Parents: 966b0d5
Author: James Taylor <jamestay...@apache.org>
Authored: Thu May 5 22:40:54 2016 -0700
Committer: James Taylor <jamestay...@apache.org>
Committed: Thu May 5 22:45:25 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/exception/SQLExceptionCode.java    |  2 +-
 .../java/org/apache/phoenix/jdbc/PhoenixConnection.java   |  9 +++++++--
 .../java/org/apache/phoenix/jdbc/PhoenixDriverTest.java   | 10 +++++++---
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/26207825/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java 
b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 4d18cbb..5661098 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -282,7 +282,7 @@ public enum SQLExceptionCode {
     CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP(1081, "44A12", "Cannot alter 
table to be transactional table if transactions are disabled."),
     TX_MUST_BE_ENABLED_TO_SET_TX_CONTEXT(1082, "44A13", "Cannot set 
transaction context if transactions are disabled."),
     TX_MUST_BE_ENABLED_TO_SET_AUTO_FLUSH(1083, "44A14", "Cannot set auto flush 
if transactions are disabled."),
-    TX_MUST_BE_ENABLED_TO_SET_ISOLATION_LEVEL(1084, "44A15", "Cannot set 
isolation level to TRANSACTION_READ_COMMITTED or TRANSACTION_SERIALIZABLE if 
transactions are disabled."),
+    TX_MUST_BE_ENABLED_TO_SET_ISOLATION_LEVEL(1084, "44A15", "Cannot set 
isolation level to TRANSACTION_REPEATABLE_READ if transactions are disabled."),
     TX_UNABLE_TO_GET_WRITE_FENCE(1085, "44A16", "Unable to obtain write fence 
for DDL operation."),
     
     SEQUENCE_NOT_CASTABLE_TO_AUTO_PARTITION_ID_COLUMN(1086, "44A17", "Sequence 
Value not castable to auto-partition id column"),

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26207825/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java 
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
index 08b300b..6fc8e10 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixConnection.java
@@ -112,6 +112,8 @@ import org.cloudera.htrace.Sampler;
 import org.cloudera.htrace.TraceScope;
 import org.apache.phoenix.util.SchemaUtil;
 
+import co.cask.tephra.TransactionContext;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
 import com.google.common.base.Strings;
@@ -662,7 +664,7 @@ public class PhoenixConnection implements Connection, 
MetaDataMutated, SQLClosea
         boolean transactionsEnabled = 
getQueryServices().getProps().getBoolean(QueryServices.TRANSACTIONS_ENABLED, 
                 QueryServicesOptions.DEFAULT_TRANSACTIONS_ENABLED);
         return  transactionsEnabled ?
-                Connection.TRANSACTION_SERIALIZABLE : 
Connection.TRANSACTION_READ_COMMITTED;
+                Connection.TRANSACTION_REPEATABLE_READ : 
Connection.TRANSACTION_READ_COMMITTED;
     }
 
     @Override
@@ -824,7 +826,10 @@ public class PhoenixConnection implements Connection, 
MetaDataMutated, SQLClosea
     public void setTransactionIsolation(int level) throws SQLException {
         boolean transactionsEnabled = 
getQueryServices().getProps().getBoolean(QueryServices.TRANSACTIONS_ENABLED, 
                 QueryServicesOptions.DEFAULT_TRANSACTIONS_ENABLED);
-        if (!transactionsEnabled && (level == 
Connection.TRANSACTION_REPEATABLE_READ || level == 
Connection.TRANSACTION_SERIALIZABLE)) {
+        if (level == Connection.TRANSACTION_SERIALIZABLE) {
+            throw new SQLFeatureNotSupportedException();
+        }
+        if (!transactionsEnabled && level == 
Connection.TRANSACTION_REPEATABLE_READ) {
             throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.TX_MUST_BE_ENABLED_TO_SET_ISOLATION_LEVEL)
             .build().buildException();
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/26207825/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
index bc9ed3b..fde70d0 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/jdbc/PhoenixDriverTest.java
@@ -25,6 +25,7 @@ import java.sql.Driver;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.util.Properties;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
@@ -105,14 +106,17 @@ public class PhoenixDriverTest extends 
BaseConnectionlessQueryTest {
             conn = DriverManager.getConnection(getUrl());
             conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
             fail();
-        } catch(SQLException e) {
-            
assertEquals(SQLExceptionCode.TX_MUST_BE_ENABLED_TO_SET_ISOLATION_LEVEL.getErrorCode(),
 e.getErrorCode());
+        } catch(SQLFeatureNotSupportedException e) {
         }
         Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
         props.setProperty(QueryServices.TRANSACTIONS_ENABLED, 
Boolean.toString(true));
         conn = DriverManager.getConnection(getUrl(), props);
         conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
-        conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+        try {
+            conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+            fail();
+        } catch(SQLFeatureNotSupportedException e) {
+        }
     }
 
     @Test

Reply via email to