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