diff options
author | Gordon Sim <gsim@apache.org> | 2006-11-07 16:58:31 +0000 |
---|---|---|
committer | Gordon Sim <gsim@apache.org> | 2006-11-07 16:58:31 +0000 |
commit | fd69619118c808b2c30af3dbb4a9882f192237b3 (patch) | |
tree | 21e6fd2171eab3a028ff8c9bbb847a24b6410536 /cpp/src | |
parent | 0b03d292bad662cf4e65017bf944937b54b6933d (diff) | |
download | qpid-python-fd69619118c808b2c30af3dbb4a9882f192237b3.tar.gz |
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
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); } |