From a7aca75d41d2993172ccf3c158b72aebabefcd9d Mon Sep 17 00:00:00 2001 From: Ran Tavory Date: Thu, 20 May 2010 13:31:04 +0300 Subject: [PATCH] Add Command.execute that accepts a configurable FailoverPolicy --- CHANGELOG | 1 + .../me/prettyprint/cassandra/dao/Command.java | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 640a954ba..411bf958a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ Changes by version: 0.6.0-14 ======== Add getRangeSuperSlices http://github.com/rantav/hector/issues/#issue/38 +Add Command.execute that accepts a configurable FailoverPolicy 0.6.0-13 ======== diff --git a/src/main/java/me/prettyprint/cassandra/dao/Command.java b/src/main/java/me/prettyprint/cassandra/dao/Command.java index 1c8e6ddba..cfb6f0ae0 100644 --- a/src/main/java/me/prettyprint/cassandra/dao/Command.java +++ b/src/main/java/me/prettyprint/cassandra/dao/Command.java @@ -4,6 +4,8 @@ import me.prettyprint.cassandra.service.CassandraClientPool; import me.prettyprint.cassandra.service.CassandraClientPoolFactory; import me.prettyprint.cassandra.service.Keyspace; +import me.prettyprint.cassandra.service.CassandraClient.FailoverPolicy; + import org.apache.cassandra.thrift.ConsistencyLevel; /** @@ -86,14 +88,27 @@ public final OUTPUT execute(CassandraClientPool pool, String[] hosts, String key } } + /** + * Use this execute method if you need a special {@link FailoverPolicy} + */ + public OUTPUT execute(String[] hosts, String keyspace, ConsistencyLevel consistency, + FailoverPolicy failoverPolicy) throws Exception { + return execute(getPool().borrowClient(hosts), keyspace, consistency, failoverPolicy); + } + + protected OUTPUT execute(CassandraClient c, String keyspace, ConsistencyLevel consistency, + FailoverPolicy failoverPolicy) throws Exception { + Keyspace ks = c.getKeyspace(keyspace, consistency, failoverPolicy); + try { + return execute(ks); + } finally { + getPool().releaseClient(ks.getClient()); + } + } + /** * Executes on a client obtained from the default pool - * @param c - * @param keyspace - * @param consistency - * @return - * @throws Exception */ protected final OUTPUT execute(CassandraClient c, String keyspace, ConsistencyLevel consistency) throws Exception {