98
static bool isEndStatement(const message::Statement &statement)
100
switch (statement.type())
102
case (message::Statement::INSERT):
104
const message::InsertData &data= statement.insert_data();
105
if (not data.end_segment())
109
case (message::Statement::UPDATE):
111
const message::UpdateData &data= statement.update_data();
112
if (not data.end_segment())
116
case (message::Statement::DELETE):
118
const message::DeleteData &data= statement.delete_data();
119
if (not data.end_segment())
98
129
static void printTransaction(const message::Transaction &transaction)
131
static uint64_t last_trx_id= 0;
132
bool should_commit= true;
100
133
const message::TransactionContext trx= transaction.transaction_context();
102
135
size_t num_statements= transaction.statement_size();
105
cout << "START TRANSACTION;" << endl;
139
* One way to determine when a new transaction begins is when the
140
* transaction id changes. We check that here.
142
if (trx.transaction_id() != last_trx_id)
143
cout << "START TRANSACTION;" << endl;
145
last_trx_id= trx.transaction_id();
106
147
for (x= 0; x < num_statements; ++x)
108
149
const message::Statement &statement= transaction.statement(x);
152
should_commit= isEndStatement(statement);
109
154
printStatement(statement);
111
cout << "COMMIT;" << endl;
158
* If ALL Statements are end segments, we can commit this Transaction.
159
* We can also check to see if the transaction_id changed, but this
160
* wouldn't work for the last Transaction in the transaction log since
161
* we don't have another Transaction to compare to. Checking for all
162
* end segments (like we do above) covers this case.
165
cout << "COMMIT;" << endl;
114
168
int main(int argc, char* argv[])