From fd69619118c808b2c30af3dbb4a9882f192237b3 Mon Sep 17 00:00:00 2001 From: Gordon Sim Date: Tue, 7 Nov 2006 16:58:31 +0000 Subject: Modified TransactionalStore to return the txn ctxt as an auto_ptr to make ownership more obvious. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@472166 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/NullMessageStore.cpp | 4 ++-- cpp/src/qpid/broker/NullMessageStore.h | 2 +- cpp/src/qpid/broker/TransactionalStore.h | 6 +++++- cpp/src/qpid/broker/TxBuffer.cpp | 20 ++++++++++++-------- 4 files changed, 20 insertions(+), 12 deletions(-) (limited to 'cpp/src/qpid') 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 NullMessageStore::begin(){ + return std::auto_ptr(); } 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 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 + 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 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 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); } -- cgit v1.2.1