edits
[iotcloud.git] / version2 / src / C / PendingTransaction.cc
index 088238e93aa4d9610a2dc44beb8742aa3b1880d0..be7575f7e9aac70bf87ba2f0108408f411b1d0ee 100644 (file)
@@ -14,12 +14,16 @@ PendingTransaction::PendingTransaction(int64_t _machineId) :
        currentDataSize(0) {
 }
 
+PendingTransaction::~PendingTransaction() {
+       delete keyValueUpdateSet;
+       delete keyValueGuardSet;
+}
+
 /**
  * Add a new key value to the updates
  *
  */
 void PendingTransaction::addKV(KeyValue *newKV) {
-
        KeyValue *rmKV = NULL;
 
        // Make sure there are no duplicates
@@ -27,7 +31,6 @@ void PendingTransaction::addKV(KeyValue *newKV) {
        while (kvit->hasNext()) {
                KeyValue *kv = kvit->next();
                if (kv->getKey()->equals(newKV->getKey())) {
-
                        // Remove key if we are adding a newer version of the same key
                        rmKV = kv;
                        break;
@@ -64,7 +67,6 @@ bool PendingTransaction::checkArbitrator(int64_t arb) {
                arbitrator = arb;
                return true;
        }
-
        return arb == arbitrator;
 }
 
@@ -72,21 +74,21 @@ bool PendingTransaction::evaluateGuard(Hashtable<IoTString *, KeyValue *> *keyVa
        SetIterator<KeyValue *> *kvit = keyValueGuardSet->iterator();
        while (kvit->hasNext()) {
                KeyValue *kvGuard = kvit->next();
-
-               // First check if the key is in the speculative table, this is the value of the latest assumption
+               // First check if the key is in the speculative table, this is the
+               // value of the latest assumption
                KeyValue *kv = keyValTablePendingTransSpeculative->get(kvGuard->getKey());
 
 
                if (kv == NULL) {
-                       // if it is not in the pending trans table then check the speculative table and use that
-                       // value as our latest assumption
+                       // if it is not in the pending trans table then check the
+                       // speculative table and use that value as our latest assumption
                        kv = keyValTableSpeculative->get(kvGuard->getKey());
                }
 
 
                if (kv == NULL) {
-                       // if it is not in the speculative table then check the committed table and use that
-                       // value as our latest assumption
+                       // if it is not in the speculative table then check the
+                       // committed table and use that value as our latest assumption
                        kv = keyValTableCommitted->get(kvGuard->getKey());
                }
 
@@ -114,18 +116,15 @@ Transaction *PendingTransaction::createTransaction() {
        Array<char> *charData = convertDataToBytes();
 
        int currentPosition = 0;
-       int remaining = charData->length();
-
-       while (remaining > 0) {
-
+       for(int remaining = charData->length(); remaining > 0;) {
                bool isLastPart = false;
                // determine how much to copy
                int copySize = TransactionPart_MAX_NON_HEADER_SIZE;
                if (remaining <= TransactionPart_MAX_NON_HEADER_SIZE) {
                        copySize = remaining;
-                       isLastPart = true;// last bit of data so last part
+                       isLastPart = true;//last bit of data so last part
                }
-
+               
                // Copy to a smaller version
                Array<char> *partData = new Array<char>(copySize);
                System_arraycopy(charData, currentPosition, partData, 0, copySize);
@@ -188,4 +187,3 @@ Array<char> *PendingTransaction::convertDataToBytes() {
 
        return bbEncode->array();
 }
-