#include "Transaction.h"
+#include "TransactionPart.h"
+#include "KeyValue.h"
+#include "ByteBuffer.h"
+#include "IoTString.h"
+#include "TransactionStatus.h"
Transaction::Transaction() :
parts(new Hashtable<int32_t, TransactionPart *>()),
clientLocalSequenceNumber = newPart->getClientLocalSequenceNumber();
machineId = newPart->getMachineId();
- TransactionPart previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
+ TransactionPart * previoslySeenPart = parts->put(newPart->getPartNumber(), newPart);
if (previoslySeenPart != NULL) {
// Set dead the old one since the new one is a rescued version of this part
if ((partsPendingSend->size() == 0) || (partsPendingSend->size() == nextPartToSend)) {
return NULL;
}
- TransactionPart part = parts->get(partsPendingSend->get(nextPartToSend));
+ TransactionPart *part = parts->get(partsPendingSend->get(nextPartToSend));
nextPartToSend++;
return part;
}
// Make all the parts of this transaction dead
for (int32_t partNumber : parts->keySet()) {
- TransactionPart part = parts->get(partNumber);
+ TransactionPart* part = parts->get(partNumber);
part->setDead();
}
}
// Calculate the size of the data section
int dataSize = 0;
for (int i = 0; i < parts->keySet()->size(); i++) {
- TransactionPart tp = parts->get(i);
+ TransactionPart *tp = parts->get(i);
dataSize += tp->getDataSize();
}
- Array<char> *combinedData = new char[dataSize];
+ Array<char> *combinedData = new Array<char>(dataSize);
int currentPosition = 0;
// Stitch all the data sections together
for (int i = 0; i < parts->keySet()->size(); i++) {
- TransactionPart tp = parts->get(i);
+ TransactionPart *tp = parts->get(i);
System_arraycopy(tp->getData(), 0, combinedData, currentPosition, tp->getDataSize());
currentPosition += tp->getDataSize();
}
// Decoder Object
- ByteBuffer bbDecode = ByteBuffer_wrap(combinedData);
+ ByteBuffer* bbDecode = ByteBuffer_wrap(combinedData);
// Decode how many key value pairs need to be decoded
int numberOfKVGuards = bbDecode->getInt();
// Decode all the guard key values
for (int i = 0; i < numberOfKVGuards; i++) {
- KeyValue * kv = (KeyValue *)KeyValue_decode(bbDecode);
+ KeyValue *kv = (KeyValue *)KeyValue_decode(bbDecode);
keyValueGuardSet->add(kv);
}
// Decode all the updates key values
for (int i = 0; i < numberOfKVUpdates; i++) {
- KeyValue * kv = (KeyValue *)KeyValue_decode(bbDecode);
+ KeyValue *kv = (KeyValue *)KeyValue_decode(bbDecode);
keyValueUpdateSet->add(kv);
}
}
for (KeyValue *kvGuard : keyValueGuardSet) {
// First check if the key is in the speculative table, this is the value of the latest assumption
- KeyValue * kv = NULL;
+ KeyValue *kv = NULL;
// If we have a speculation table then use it first
if (pendingTransactionSpeculatedKeyValueTable != NULL) {
if (kv != NULL) {
- System.out.println(kvGuard->getValue() + " " + kv->getValue());
+ printf("%s %s\n", kvGuard->getKey()->internalBytes()->internalArray(), kv->getValue()->internalBytes()->internalArray());
} else {
- System.out.println(kvGuard->getValue() + " " + kv);
+ printf("%s null\n", kvGuard->getValue()->internalBytes()->internalArray());
}
return false;