phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gr...@apache.org
Subject [1/2] phoenix git commit: PHOENIX-1559 Add AutoCommit flag to connection url
Date Thu, 01 Jan 2015 11:08:56 GMT
Repository: phoenix
Updated Branches:
  refs/heads/3.0 bf064b7c3 -> abb5c24f4


PHOENIX-1559 Add AutoCommit flag to connection url

Allow supplying AutoCommit=true (or AutoCommit=false) in a JDBC
url or connection properties when creating a new connection. This
will allow Phoenix to currently operate in a standards-compliant
mode for now, as well as making it easier to run Phoenix in a
backwards-compatible mode once PHOENIX-1543 is implemented.


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

Branch: refs/heads/3.0
Commit: 745425fb93dab772662d48bae917b0ce3ad23521
Parents: bf064b7
Author: Gabriel Reid <greid@apache.org>
Authored: Wed Dec 24 17:28:01 2014 +0100
Committer: Gabriel Reid <greid@apache.org>
Committed: Thu Jan 1 12:05:14 2015 +0100

----------------------------------------------------------------------
 .../apache/phoenix/jdbc/PhoenixConnection.java  |  1 +
 .../java/org/apache/phoenix/util/JDBCUtil.java  | 15 +++++++++
 .../org/apache/phoenix/util/PhoenixRuntime.java |  5 +++
 .../org/apache/phoenix/util/JDBCUtilTest.java   | 34 ++++++++++++++++++++
 4 files changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/745425fb/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 75f9f55..7353ffd 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
@@ -173,6 +173,7 @@ public class PhoenixConnection implements Connection, org.apache.phoenix.jdbc.Jd
             };
         }
         this.scn = JDBCUtil.getCurrentSCN(url, this.info);
+        this.isAutoCommit = JDBCUtil.getAutoCommit(url, this.info);
         this.tenantId = tenantId;
         this.mutateBatchSize = JDBCUtil.getMutateBatchSize(url, this.info, this.services.getProps());
         datePattern = this.services.getProps().get(QueryServices.DATE_FORMAT_ATTRIB, DateUtil.DEFAULT_DATE_FORMAT);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/745425fb/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
index ff7ec20..e2efe79 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/JDBCUtil.java
@@ -94,4 +94,19 @@ public class JDBCUtil {
         String tenantId = findProperty(url, info, PhoenixRuntime.TENANT_ID_ATTRIB);
         return (tenantId == null ? null : PNameFactory.newName(tenantId));
     }
+
+    // TODO Make true the default return value once PHOENIX-1543 is in place
+    /**
+     * Retrieve the value of the optional auto-commit setting from JDBC url or connection
+     * properties.
+     *
+     * @param url JDBC url used for connecting to Phoenix
+     * @param info connection properties
+     * @return <tt>true</tt> if AutoCommit=true was specified in the connection
URL or properties,
+     * otherwise false
+     */
+    public static boolean getAutoCommit(String url, Properties info) {
+        String autoCommit = findProperty(url, info, PhoenixRuntime.AUTO_COMMIT_ATTRIB);
+        return Boolean.valueOf(autoCommit);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/745425fb/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index c0c2783..abe9a03 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -122,6 +122,11 @@ public class PhoenixRuntime {
     public static final String TENANT_ID_ATTRIB = "TenantId";
 
     /**
+     * Use this connection property to explicity enable or disable auto-commit on a new connection.
+     */
+    public static final String AUTO_COMMIT_ATTRIB = "AutoCommit";
+
+    /**
      * Use this as the zookeeper quorum name to have a connection-less connection. This enables
      * Phoenix-compatible HFiles to be created in a map/reduce job by creating tables,
      * upserting data into them, and getting the uncommitted state through {@link #getUncommittedData(Connection)}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/745425fb/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
index 28e830b..b41ce5b 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/JDBCUtilTest.java
@@ -20,6 +20,10 @@ package org.apache.phoenix.util;
 
 import static org.apache.phoenix.util.PhoenixRuntime.TENANT_ID_ATTRIB;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
 
 import org.junit.Test;
 
@@ -32,4 +36,34 @@ public class JDBCUtilTest {
         assertEquals("localhost;TenantId=abc", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar",
"foo"));
         assertEquals("localhost;TenantId=abc;foo=bar", JDBCUtil.removeProperty("localhost;TenantId=abc;foo=bar",
"bar"));
     }
+
+    @Test
+    public void testGetAutoCommit_NotSpecified() {
+        // TODO Make true the default return value once PHOENIX-1543 is in place
+        assertFalse(JDBCUtil.getAutoCommit("localhost", new Properties()));
+    }
+
+    @Test
+    public void testGetAutoCommit_TrueInUrl() {
+        assertTrue(JDBCUtil.getAutoCommit("localhost;AutoCommit=TrUe", new Properties()));
+    }
+
+    @Test
+    public void testGetAutoCommit_FalseInUrl() {
+        assertFalse(JDBCUtil.getAutoCommit("localhost;AutoCommit=FaLse", new Properties()));
+    }
+
+    @Test
+    public void testGetAutoCommit_TrueInProperties() {
+        Properties props = new Properties();
+        props.setProperty("AutoCommit", "true");
+        assertTrue(JDBCUtil.getAutoCommit("localhost", props));
+    }
+
+    @Test
+    public void testGetAutoCommit_FalseInProperties() {
+        Properties props = new Properties();
+        props.setProperty("AutoCommit", "false");
+        assertFalse(JDBCUtil.getAutoCommit("localhost", props));
+    }
 }


Mime
View raw message