maedhroz commented on code in PR #2049:
URL: https://github.com/apache/cassandra/pull/2049#discussion_r1061770091


##########
src/java/org/apache/cassandra/cql3/statements/CQL3CasRequest.java:
##########
@@ -399,11 +425,72 @@ public boolean appliesTo(FilteredPartition current) 
throws InvalidRequestExcepti
             }
             return true;
         }
+
+        @Override
+        public TxnCondition asTxnCondition()
+        {
+            return new TxnCondition.ColumnConditionsAdapter(clustering, 
conditions.values());
+        }
     }
     
     @Override
     public String toString()
     {
         return ToStringBuilder.reflectionToString(this, 
ToStringStyle.SHORT_PREFIX_STYLE);
     }
+
+    @Override
+    public Txn toAccordTxn(ClientState clientState, int nowInSecs) {
+        SinglePartitionReadCommand readCommand = readCommand(nowInSecs);
+        Update update = createUpdate(clientState);
+        // In a CAS request only one key is supported and writes
+        // can't be dependent on any data that is read (only conditions)
+        // so the only relevant keys are the read key
+        TxnRead read = TxnRead.createRead(readCommand);
+        return new Txn.InMemory(read.keys(), read, TxnQuery.CONDITION, update);
+    }
+
+    private Update createUpdate(ClientState clientState)
+    {
+        return new TxnUpdate(createWriteFragments(clientState), 
createCondition());
+    }
+
+    private TxnCondition createCondition()
+    {
+        List<TxnCondition> txnConditions = new ArrayList<>();
+        if (staticConditions != null)
+        {
+            txnConditions.add(staticConditions.asTxnCondition());
+        }
+        conditions.values()
+                  .stream()
+                  .map(RowCondition::asTxnCondition)
+                  .forEach(txnConditions::add);

Review Comment:
   nit: Having been burned many times by the object creation hidden here, I can 
only suggest...
   
   ```
   for (RowCondition condition : conditions.values())
       txnConditions.add(condition.asTxnCondition());
   ```
   ...although in this case, it feels slightly more readable as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to