Drizzled Public API Documentation

xa_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) 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/plugin/transactional_storage_engine.h>
00024 #include <drizzled/plugin/xa_resource_manager.h>
00025 
00026 #include <drizzled/visibility.h>
00027 
00028 namespace drizzled
00029 {
00030 
00031 class XID;
00032 
00033 namespace plugin
00034 {
00035 
00049 class DRIZZLED_API XaStorageEngine :
00050   public TransactionalStorageEngine,
00051   public XaResourceManager
00052 {
00053 public:
00054   XaStorageEngine(const std::string name_arg,
00055                   const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
00056 
00057   virtual ~XaStorageEngine();
00058 
00059   int startTransaction(Session *session, start_transaction_option_t options)
00060   {
00061     TransactionServices &transaction_services= TransactionServices::singleton();
00062     transaction_services.registerResourceForTransaction(*session, this, this, this);
00063     return doStartTransaction(session, options);
00064   }
00065 
00066   void startStatement(Session *session)
00067   {
00068     TransactionServices &transaction_services= TransactionServices::singleton();
00069     transaction_services.registerResourceForStatement(*session, this, this, this);
00070     doStartStatement(session);
00071   }
00072 
00073   /* 
00074    * The below are simple virtual overrides for the plugin::MonitoredInTransaction
00075    * interface.
00076    */
00077   bool participatesInSqlTransaction() const
00078   {
00079     return true; /* We DO participate in the SQL transaction */
00080   }
00081   bool participatesInXaTransaction() const
00082   {
00083     return true; /* We DO participate in the XA transaction */
00084   }
00085   bool alwaysRegisterForXaTransaction() const
00086   {
00087     return false; /* We only register in the XA transaction if the engine's data is modified */
00088   }
00089 
00090   /* Class Methods for operating on plugin */
00091   static bool addPlugin(plugin::XaStorageEngine *engine);
00092   static void removePlugin(plugin::XaStorageEngine *engine);
00093 
00094 private:
00095   /*
00096    * Indicates to a storage engine the start of a
00097    * new SQL transaction.  This is called ONLY in the following
00098    * scenarios:
00099    *
00100    * 1) An explicit BEGIN WORK/START TRANSACTION is called
00101    * 2) After an explicit COMMIT AND CHAIN is called
00102    * 3) After an explicit ROLLBACK AND RELEASE is called
00103    * 4) When in AUTOCOMMIT mode and directly before a new
00104    *    SQL statement is started.
00105    *
00106    * Engines should typically use the doStartStatement()
00107    * and doEndStatement() methods to manage transaction state,
00108    * since the kernel ALWAYS notifies engines at the start
00109    * and end of statement transactions and at the end of the
00110    * normal transaction by calling doCommit() or doRollback().
00111    */
00112   virtual int doStartTransaction(Session *session, start_transaction_option_t options)
00113   {
00114     (void) session;
00115     (void) options;
00116     return 0;
00117   }
00118 
00119   /*
00120    * Indicates to a storage engine the start of a
00121    * new SQL statement.
00122    */
00123   virtual void doStartStatement(Session *session)
00124   {
00125     (void) session;
00126   }
00127 };
00128 
00129 } /* namespace plugin */
00130 } /* namespace drizzled */
00131