Repository: phoenix Updated Branches: refs/heads/master d41565b7f -> d6a4caf5c
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/d6a4caf5 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d6a4caf5 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d6a4caf5 Branch: refs/heads/master Commit: d6a4caf5cff651cfef3602c93e3fcafe62bced9b Parents: d41565b Author: Gabriel Reid <[email protected]> Authored: Wed Dec 24 17:28:01 2014 +0100 Committer: Gabriel Reid <[email protected]> Committed: Sat Dec 27 13:51:32 2014 +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 | 31 ++++++++++++++++++++ 4 files changed, 52 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/d6a4caf5/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 6b236e8..325faa5 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 @@ -196,6 +196,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/d6a4caf5/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 df1f949..dbb3984 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 @@ -135,4 +135,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/d6a4caf5/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 269eda5..b2d7851 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 @@ -130,6 +130,11 @@ public class PhoenixRuntime { public static final String ANNOTATION_ATTRIB_PREFIX = "phoenix.annotation."; /** + * 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/d6a4caf5/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 71bd6df..72f81c9 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,7 @@ package org.apache.phoenix.util; import static org.apache.phoenix.util.PhoenixRuntime.ANNOTATION_ATTRIB_PREFIX; 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.Map; @@ -65,4 +66,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)); + } }
