Drizzled Public API Documentation

transactional_storage_engine.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *  Copyright (C) 2009-2010 Jay Pipes <jaypipes@gmail.com>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; version 2 of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <drizzled/plugin/transactional_storage_engine.h>
00024 #include <drizzled/resource_context.h>
00025 #include <drizzled/session.h>
00026 
00027 #include <vector>
00028 #include <algorithm>
00029 #include <functional>
00030 
00031 namespace drizzled {
00032 namespace plugin {
00033 
00034 static std::vector<TransactionalStorageEngine*> g_engines;
00035 
00036 TransactionalStorageEngine::TransactionalStorageEngine(const std::string &name_arg,
00037                                                        const std::bitset<HTON_BIT_SIZE> &flags_arg)
00038     : StorageEngine(name_arg, flags_arg)
00039 {
00040 }
00041 
00042 void TransactionalStorageEngine::setTransactionReadWrite(Session& session)
00043 {
00044   ResourceContext& resource_context= session.getResourceContext(*this);
00045 
00046   /*
00047     When a storage engine method is called, the transaction must
00048     have been started, unless it's a DDL call, for which the
00049     storage engine starts the transaction internally, and commits
00050     it internally, without registering in the ha_list.
00051     Unfortunately here we can't know know for sure if the engine
00052     has registered the transaction or not, so we must check.
00053   */
00054   if (resource_context.isStarted())
00055     resource_context.markModifiedData();
00056 }
00057 
00076 void TransactionalStorageEngine::releaseTemporaryLatches(Session *session)
00077 {
00078   BOOST_FOREACH(TransactionalStorageEngine* it, g_engines) 
00079     it->doReleaseTemporaryLatches(session);
00080 }
00081 
00082 int TransactionalStorageEngine::notifyStartTransaction(Session *session, start_transaction_option_t options)
00083 {
00084   if (g_engines.empty())
00085     return 0;
00086   std::vector<int> results;
00087   results.reserve(g_engines.size());
00088   BOOST_FOREACH(TransactionalStorageEngine* it, g_engines)
00089     results.push_back(it->startTransaction(session, options));
00090   return *std::max_element(results.begin(), results.end());
00091 }
00092 
00093 bool TransactionalStorageEngine::addPlugin(TransactionalStorageEngine *engine)
00094 {
00095   g_engines.push_back(engine);
00096   return StorageEngine::addPlugin(engine);
00097 }
00098 
00099 void TransactionalStorageEngine::removePlugin(TransactionalStorageEngine*)
00100 {
00101   g_engines.clear();
00102 }
00103 
00104 } /* namespace plugin */
00105 } /* namespace drizzled */