diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/broker/NullMessageStore.cpp | 4 | ||||
-rw-r--r-- | cpp/src/qpid/broker/NullMessageStore.h | 2 | ||||
-rw-r--r-- | cpp/src/qpid/broker/TransactionalStore.h | 6 | ||||
-rw-r--r-- | cpp/src/qpid/broker/TxBuffer.cpp | 20 |
4 files changed, 20 insertions, 12 deletions
diff --git a/cpp/src/qpid/broker/NullMessageStore.cpp b/cpp/src/qpid/broker/NullMessageStore.cpp index 3a07961670..87df407ad8 100644 --- a/cpp/src/qpid/broker/NullMessageStore.cpp +++ b/cpp/src/qpid/broker/NullMessageStore.cpp @@ -46,8 +46,8 @@ void NullMessageStore::committed(const string * const){ void NullMessageStore::aborted(const string * const){ std::cout << "WARNING: Persistence not enabled." << std::endl; } -TransactionContext* NullMessageStore::begin(){ - return 0; +std::auto_ptr<TransactionContext> NullMessageStore::begin(){ + return std::auto_ptr<TransactionContext>(); } void NullMessageStore::commit(TransactionContext*){ } diff --git a/cpp/src/qpid/broker/NullMessageStore.h b/cpp/src/qpid/broker/NullMessageStore.h index 9b89920416..3b34a7f6a0 100644 --- a/cpp/src/qpid/broker/NullMessageStore.h +++ b/cpp/src/qpid/broker/NullMessageStore.h @@ -39,7 +39,7 @@ namespace qpid { void dequeue(TransactionContext* ctxt, Message::shared_ptr& msg, const Queue& queue, const string * const xid); void committed(const string * const xid); void aborted(const string * const xid); - TransactionContext* begin(); + std::auto_ptr<TransactionContext> begin(); void commit(TransactionContext* ctxt); void abort(TransactionContext* ctxt); ~NullMessageStore(){} diff --git a/cpp/src/qpid/broker/TransactionalStore.h b/cpp/src/qpid/broker/TransactionalStore.h index 57dc411cd8..f11c5de31b 100644 --- a/cpp/src/qpid/broker/TransactionalStore.h +++ b/cpp/src/qpid/broker/TransactionalStore.h @@ -18,8 +18,12 @@ #ifndef _TransactionalStore_ #define _TransactionalStore_ +#include <memory> + namespace qpid { namespace broker { + struct InvalidTransactionContextException : public std::exception {}; + class TransactionContext{ public: virtual ~TransactionContext(){} @@ -27,7 +31,7 @@ namespace qpid { class TransactionalStore{ public: - virtual TransactionContext* begin() = 0; + virtual std::auto_ptr<TransactionContext> begin() = 0; virtual void commit(TransactionContext*) = 0; virtual void abort(TransactionContext*) = 0; diff --git a/cpp/src/qpid/broker/TxBuffer.cpp b/cpp/src/qpid/broker/TxBuffer.cpp index fe2ea8fbb1..920b9862b0 100644 --- a/cpp/src/qpid/broker/TxBuffer.cpp +++ b/cpp/src/qpid/broker/TxBuffer.cpp @@ -20,27 +20,31 @@ using std::mem_fun; using namespace qpid::broker; -bool TxBuffer::prepare(TransactionalStore* const store){ - TransactionContext* ctxt(0); +bool TxBuffer::prepare(TransactionalStore* const store) +{ + std::auto_ptr<TransactionContext> ctxt; if(store) ctxt = store->begin(); for(op_iterator i = ops.begin(); i < ops.end(); i++){ - if(!(*i)->prepare(ctxt)){ - if(store) store->abort(ctxt); + if(!(*i)->prepare(ctxt.get())){ + if(store) store->abort(ctxt.get()); return false; } } - if(store) store->commit(ctxt); + if(store) store->commit(ctxt.get()); return true; } -void TxBuffer::commit(){ +void TxBuffer::commit() +{ for_each(ops.begin(), ops.end(), mem_fun(&TxOp::commit)); } -void TxBuffer::rollback(){ +void TxBuffer::rollback() +{ for_each(ops.begin(), ops.end(), mem_fun(&TxOp::rollback)); } -void TxBuffer::enlist(TxOp* const op){ +void TxBuffer::enlist(TxOp* const op) +{ ops.push_back(op); } |