cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [1/2] git commit: (ninja) Deduplicate BatchStatement hasConditions inference logic
Date Fri, 20 Jun 2014 22:49:14 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk e88c83006 -> c1ce969c6


(ninja) Deduplicate BatchStatement hasConditions inference logic


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

Branch: refs/heads/trunk
Commit: bf9b49ca8443b020cee6f0e1550763fed5a36363
Parents: ee401cf
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Fri Jun 20 15:46:16 2014 -0700
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Fri Jun 20 15:46:16 2014 -0700

----------------------------------------------------------------------
 .../cql3/statements/BatchStatement.java         | 20 ++++++++------------
 .../transport/messages/BatchMessage.java        | 15 +++++----------
 2 files changed, 13 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/bf9b49ca/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
index b7d69cc..0521485 100644
--- a/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/BatchStatement.java
@@ -64,8 +64,12 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache
      * @param statements a list of UpdateStatements
      * @param attrs additional attributes for statement (CL, timestamp, timeToLive)
      */
-    public BatchStatement(int boundTerms, Type type, List<ModificationStatement> statements,
Attributes attrs, boolean hasConditions)
+    public BatchStatement(int boundTerms, Type type, List<ModificationStatement> statements,
Attributes attrs)
     {
+        boolean hasConditions = false;
+        for (ModificationStatement statement : statements)
+            hasConditions |= statement.hasConditions();
+
         this.boundTerms = boundTerms;
         this.type = type;
         this.statements = statements;
@@ -304,7 +308,7 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache
         String cfName = null;
         ColumnFamily updates = null;
         CQL3CasConditions conditions = null;
-        Set<ColumnDefinition> columnsWithConditions = new LinkedHashSet<ColumnDefinition>();
+        Set<ColumnDefinition> columnsWithConditions = new LinkedHashSet<>();
 
         for (int i = 0; i < statements.size(); i++)
         {
@@ -397,21 +401,13 @@ public class BatchStatement implements CQLStatement, MeasurableForPreparedCache
             VariableSpecifications boundNames = getBoundVariables();
 
             List<ModificationStatement> statements = new ArrayList<>(parsedStatements.size());
-            boolean hasConditions = false;
-
             for (ModificationStatement.Parsed parsed : parsedStatements)
-            {
-                ModificationStatement stmt = parsed.prepare(boundNames);
-                if (stmt.hasConditions())
-                    hasConditions = true;
-
-                statements.add(stmt);
-            }
+                statements.add(parsed.prepare(boundNames));
 
             Attributes prepAttrs = attrs.prepare("[batch]", "[batch]");
             prepAttrs.collectMarkerSpecification(boundNames);
 
-            BatchStatement batchStatement = new BatchStatement(boundNames.size(), type, statements,
prepAttrs, hasConditions);
+            BatchStatement batchStatement = new BatchStatement(boundNames.size(), type, statements,
prepAttrs);
             batchStatement.validate();
 
             return new ParsedStatement.Prepared(batchStatement, boundNames);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bf9b49ca/src/java/org/apache/cassandra/transport/messages/BatchMessage.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/messages/BatchMessage.java b/src/java/org/apache/cassandra/transport/messages/BatchMessage.java
index c199a62..19fa6aa 100644
--- a/src/java/org/apache/cassandra/transport/messages/BatchMessage.java
+++ b/src/java/org/apache/cassandra/transport/messages/BatchMessage.java
@@ -29,9 +29,9 @@ import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.cql3.statements.BatchStatement;
 import org.apache.cassandra.cql3.statements.ModificationStatement;
 import org.apache.cassandra.cql3.statements.ParsedStatement;
-import org.apache.cassandra.db.ConsistencyLevel;
 import org.apache.cassandra.exceptions.InvalidRequestException;
 import org.apache.cassandra.exceptions.PreparedQueryNotFoundException;
+import org.apache.cassandra.service.ClientState;
 import org.apache.cassandra.service.QueryState;
 import org.apache.cassandra.tracing.Tracing;
 import org.apache.cassandra.transport.*;
@@ -169,9 +169,8 @@ public class BatchMessage extends Message.Request
                 Tracing.instance.begin("Execute batch of CQL3 queries", Collections.<String,
String>emptyMap());
             }
 
-            QueryHandler handler = state.getClientState().getCQLQueryHandler();
+            QueryHandler handler = ClientState.getCQLQueryHandler();
             List<ParsedStatement.Prepared> prepared = new ArrayList<>(queryOrIdList.size());
-            boolean hasConditions = false;
             for (int i = 0; i < queryOrIdList.size(); i++)
             {
                 Object query = queryOrIdList.get(i);
@@ -202,20 +201,16 @@ public class BatchMessage extends Message.Request
             {
                 ParsedStatement.Prepared p = prepared.get(i);
                 batchOptions.forStatement(i).prepare(p.boundNames);
-                CQLStatement statement = p.statement;
 
-                if (!(statement instanceof ModificationStatement))
+                if (!(p.statement instanceof ModificationStatement))
                     throw new InvalidRequestException("Invalid statement in batch: only UPDATE,
INSERT and DELETE statements are allowed.");
 
-                ModificationStatement mst = (ModificationStatement)statement;
-                hasConditions |= mst.hasConditions();
-
-                statements.add(mst);
+                statements.add((ModificationStatement)p.statement);
             }
 
             // Note: It's ok at this point to pass a bogus value for the number of bound
terms in the BatchState ctor
             // (and no value would be really correct, so we prefer passing a clearly wrong
one).
-            BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none(),
hasConditions);
+            BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none());
             Message.Response response = handler.processBatch(batch, state, batchOptions);
 
             if (tracingId != null)


Mime
View raw message