Public Member Functions | Protected Attributes

mozStorageTransaction Class Reference

This class wraps a transaction inside a given C++ scope, guaranteeing that the transaction will be completed even if you have an exception or return early. More...

#include <mozStorageHelper.h>

Collaboration diagram for mozStorageTransaction:

List of all members.

Public Member Functions

 mozStorageTransaction (mozIStorageConnection *aConnection, PRBool aCommitOnComplete, PRInt32 aType=mozIStorageConnection::TRANSACTION_DEFERRED)
 ~mozStorageTransaction ()
nsresult Commit ()
 Commits the transaction if one is in progress.
nsresult Rollback ()
 Rolls back the transaction in progress.
PRBool HasTransaction ()
 Returns whether this object wraps a real transaction.
void SetDefaultAction (PRBool aCommitOnComplete)
 This sets the default action (commit or rollback) when this object goes out of scope.

Protected Attributes

nsCOMPtr< mozIStorageConnectionmConnection
PRBool mHasTransaction
PRBool mCommitOnComplete
PRBool mCompleted

Detailed Description

This class wraps a transaction inside a given C++ scope, guaranteeing that the transaction will be completed even if you have an exception or return early.

aCommitOnComplete controls whether the transaction is committed or rolled back when it goes out of scope. A common use is to create an instance with commitOnComplete = FALSE (rollback), then call Commit on this object manually when your function completes successfully.

Note that nested transactions are not supported by sqlite, so if a transaction is already in progress, this object does nothing. Note that in this case, you may not get the transaction type you ask for, and you won't be able to rollback.


Constructor & Destructor Documentation

mozStorageTransaction::mozStorageTransaction ( mozIStorageConnection aConnection,
PRBool  aCommitOnComplete,
PRInt32  aType = mozIStorageConnection::TRANSACTION_DEFERRED 
) [inline]
mozStorageTransaction::~mozStorageTransaction (  )  [inline]

Member Function Documentation

nsresult mozStorageTransaction::Commit (  )  [inline]

Commits the transaction if one is in progress.

If one is not in progress, this is a NOP since the actual owner of the transaction outside of our scope is in charge of finally comitting or rolling back the transaction.

PRBool mozStorageTransaction::HasTransaction (  )  [inline]

Returns whether this object wraps a real transaction.

False means that this object doesn't do anything because there was already a transaction in progress when it was created.

nsresult mozStorageTransaction::Rollback (  )  [inline]

Rolls back the transaction in progress.

You should only call this function if this object has a real transaction (HasTransaction() = true) because otherwise, there is no transaction to roll back.

void mozStorageTransaction::SetDefaultAction ( PRBool  aCommitOnComplete  )  [inline]

This sets the default action (commit or rollback) when this object goes out of scope.


Member Data Documentation


The documentation for this class was generated from the following file: