Drizzled Public API Documentation

transactional_storage_engine.h
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 #pragma once
00022 
00023 #include <drizzled/definitions.h> /* for start_transaction_option_t */
00024 #include <drizzled/plugin/storage_engine.h>
00025 #include <drizzled/transaction_services.h>
00026 
00027 #include <drizzled/visibility.h>
00028 
00029 namespace drizzled {
00030 namespace plugin {
00031 
00057 class DRIZZLED_API TransactionalStorageEngine : public StorageEngine
00058 {
00059   friend class SEAPITester;
00060 public:
00061   TransactionalStorageEngine(const std::string &name_arg,
00062                              const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
00063 
00064   virtual int startTransaction(Session *session, start_transaction_option_t options)
00065   {
00066     TransactionServices::registerResourceForTransaction(*session, this, this);
00067     return doStartTransaction(session, options);
00068   }
00069 
00070   virtual void startStatement(Session *session)
00071   {
00072     TransactionServices::registerResourceForStatement(*session, this, this);
00073     doStartStatement(session);
00074   }
00075 
00076   virtual int commit(Session *session, bool normal_transaction)
00077   {
00078     return doCommit(session, normal_transaction);
00079   }
00080 
00081   virtual int rollback(Session *session, bool normal_transaction)
00082   {
00083     return doRollback(session, normal_transaction);
00084   }
00085 
00086   int setSavepoint(Session *session, NamedSavepoint &sp)
00087   {
00088     return doSetSavepoint(session, sp);
00089   }
00090 
00091   int rollbackToSavepoint(Session *session, NamedSavepoint &sp)
00092   {
00093      return doRollbackToSavepoint(session, sp);
00094   }
00095 
00096   int releaseSavepoint(Session *session, NamedSavepoint &sp)
00097   {
00098     return doReleaseSavepoint(session, sp);
00099   }
00100 
00101   /* 
00102    * The below are simple virtual overrides for the plugin::MonitoredInTransaction
00103    * interface.
00104    */
00105   virtual bool participatesInSqlTransaction() const
00106   {
00107     return true; /* We DO participate in the SQL transaction */
00108   }
00109   virtual bool participatesInXaTransaction() const
00110   {
00111     return false; /* We DON'T participate in the XA transaction */
00112   }
00113   virtual bool alwaysRegisterForXaTransaction() const
00114   {
00115     return false;
00116   }
00117 
00122   static int notifyStartTransaction(Session *session, start_transaction_option_t options);
00126   static void releaseTemporaryLatches(Session *session);
00127 
00128   /* Class Methods for operating on plugin */
00129   static bool addPlugin(plugin::TransactionalStorageEngine *engine);
00130   static void removePlugin(plugin::TransactionalStorageEngine *engine);
00131 
00132 private:
00133   void setTransactionReadWrite(Session& session);
00134 
00135   /*
00136    * Indicates to a storage engine the start of a
00137    * new SQL transaction.  This is called ONLY in the following
00138    * scenarios:
00139    *
00140    * 1) An explicit BEGIN WORK/START TRANSACTION is called
00141    * 2) After an explicit COMMIT AND CHAIN is called
00142    * 3) After an explicit ROLLBACK AND RELEASE is called
00143    * 4) When in AUTOCOMMIT mode and directly before a new
00144    *    SQL statement is started.
00145    *
00146    * Engines should typically use the doStartStatement()
00147    * and doEndStatement() methods to manage transaction state,
00148    * since the kernel ALWAYS notifies engines at the start
00149    * and end of statement transactions and at the end of the
00150    * normal transaction by calling doCommit() or doRollback().
00151    */
00152   virtual int doStartTransaction(Session *session, start_transaction_option_t options)
00153   {
00154     (void) session;
00155     (void) options;
00156     return 0;
00157   }
00158 
00159   /*
00160    * Indicates to a storage engine the start of a
00161    * new SQL statement.
00162    */
00163   virtual void doStartStatement(Session *session)
00164   {
00165     (void) session;
00166   }
00167 
00168   /*
00169    * Indicates to a storage engine the end of
00170    * the current SQL statement in the supplied
00171    * Session.
00172    */
00173   virtual void doEndStatement(Session *session)
00174   {
00175     (void) session;
00176   }
00181   virtual int doSetSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
00182   virtual int doRollbackToSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
00183   virtual int doReleaseSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
00184   
00197   virtual int doCommit(Session *session, bool normal_transaction)= 0;
00198 
00211   virtual int doRollback(Session *session, bool normal_transaction)= 0;
00212   virtual int doReleaseTemporaryLatches(Session*)
00213   {
00214     return 0;
00215   }
00216   virtual int doStartConsistentSnapshot(Session*)
00217   {
00218     return 0;
00219   }
00220 };
00221 
00222 } /* namespace plugin */
00223 } /* namespace drizzled */
00224