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