00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 00003 * 00004 * Copyright (C) 2010 David Shrewsbury <shrewsbury.dave@gmail.com> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00025 #include <config.h> 00026 #include "transaction_manager.h" 00027 00028 using namespace std; 00029 using namespace drizzled; 00030 00031 00032 bool TransactionManager::store(const message::Transaction &transaction) 00033 { 00034 string msg; 00035 const message::TransactionContext trx_ctxt= transaction.transaction_context(); 00036 uint64_t trx_id= trx_ctxt.transaction_id(); 00037 transaction.SerializeToString(&msg); 00038 00039 cache[trx_id].push_back(msg); 00040 return true; 00041 } 00042 00043 bool TransactionManager::remove(uint64_t trx_id) 00044 { 00045 cache.erase(trx_id); 00046 return true; 00047 } 00048 00049 bool TransactionManager::contains(uint64_t trx_id) 00050 { 00051 boost::unordered_map< uint64_t, vector<string> >::const_iterator it= cache.find(trx_id); 00052 00053 if (it != cache.end()) 00054 return true; 00055 00056 return false; 00057 } 00058 00059 uint32_t TransactionManager::getTransactionBufferSize(uint64_t trx_id) 00060 { 00061 return static_cast<uint32_t>(cache[trx_id].size()); 00062 } 00063 00064 bool TransactionManager::getTransactionMessage(message::Transaction &trx, 00065 uint64_t trx_id, 00066 uint32_t position) 00067 { 00068 trx.ParseFromString(cache[trx_id].at(position)); 00069 return true; 00070 }