- Fixed a compiler warning in Indexer

- Cleaned up ScopedTransaction
This commit is contained in:
casey 2016-07-04 15:28:14 -07:00
parent 5916bc11b2
commit d918c4e028
3 changed files with 23 additions and 67 deletions

View File

@ -39,71 +39,42 @@
using namespace musik::core::db;
//////////////////////////////////////////
///\brief
///Constructor
///
///\param connection
///Connection to run transaction on
//////////////////////////////////////////
ScopedTransaction::ScopedTransaction(Connection &connection) : canceled(false){
this->connection = &connection;
ScopedTransaction::ScopedTransaction(Connection &connection)
: canceled(false) {
this->connection = &connection;
this->Begin();
}
//////////////////////////////////////////
///\brief
///Destructor will end the transaction if it's the last nested transaction
//////////////////////////////////////////
ScopedTransaction::~ScopedTransaction(){
ScopedTransaction::~ScopedTransaction() {
this->End();
}
//////////////////////////////////////////
///\brief
///If canceled, this all statements in the transaction scope will be canceled
//////////////////////////////////////////
void ScopedTransaction::Cancel(){
this->canceled = true;
void ScopedTransaction::Cancel() {
this->canceled = true;
}
//////////////////////////////////////////
///\brief
///Sometimes it's a good option to be able to commit a transaction and restart it all over.
//////////////////////////////////////////
void ScopedTransaction::CommitAndRestart(){
void ScopedTransaction::CommitAndRestart() {
this->End();
this->Begin();
}
//////////////////////////////////////////
///\brief
///Runs the acctual BEGIN TRANSACTION on the database
//////////////////////////////////////////
void ScopedTransaction::Begin(){
if(this->connection->transactionCounter==0){
if (this->connection->transactionCounter == 0) {
this->connection->Execute("BEGIN TRANSACTION");
}
++this->connection->transactionCounter;
}
//////////////////////////////////////////
///\brief
///Runs the COMMIT or ROLLBACK on the database
//////////////////////////////////////////
void ScopedTransaction::End(){
void ScopedTransaction::End() {
--this->connection->transactionCounter;
if(this->connection->transactionCounter==0){
if(this->canceled){
if (this->connection->transactionCounter == 0) {
if (this->canceled) {
this->connection->Execute("ROLLBACK TRANSACTION");
}else{
}
else {
this->connection->Execute("COMMIT TRANSACTION");
}
}
}

View File

@ -39,39 +39,24 @@
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
namespace musik{ namespace core{ namespace db{
namespace musik { namespace core { namespace db {
// Forward declare
class Connection;
//////////////////////////////////////////
///\brief
///ScopedTransaction is used to make transactions easier
///
///Usage like this:
///\code
///{
/// musik::code::db::ScopedTransaction transactionScope(db)
/// //everything in this scope is included in the transation
///}
///\endcode
///
///\remarks
///Nested transations are partially supported. First scope is the one deciding when transaction is commited.
//////////////////////////////////////////
class ScopedTransaction : boost::noncopyable{
class ScopedTransaction : boost::noncopyable {
public:
ScopedTransaction(Connection &connection);
~ScopedTransaction();
void Cancel();
void CommitAndRestart();
private:
Connection *connection;
bool canceled;
inline void Begin();
inline void End();
Connection *connection;
bool canceled;
};
} } }

View File

@ -382,7 +382,7 @@ void Indexer::SyncDirectory(
catch(...) {
}
#undef WAIT_FOR_ACTIVE()
#undef WAIT_FOR_ACTIVE
}
void Indexer::ThreadLoop() {