Drizzled Public API Documentation

xa_storage_engine.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  * Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #pragma once
22 
23 #include <drizzled/plugin/transactional_storage_engine.h>
24 #include <drizzled/plugin/xa_resource_manager.h>
25 #include <drizzled/visibility.h>
26 
27 namespace drizzled {
28 namespace plugin {
29 
45  public XaResourceManager
46 {
47 public:
48  XaStorageEngine(const std::string &name_arg,
49  const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
50 
51  virtual ~XaStorageEngine();
52 
53  int startTransaction(Session *session, start_transaction_option_t options)
54  {
55  TransactionServices::registerResourceForTransaction(*session, this, this, this);
56  return doStartTransaction(session, options);
57  }
58 
59  void startStatement(Session *session)
60  {
61  TransactionServices::registerResourceForStatement(*session, this, this, this);
62  doStartStatement(session);
63  }
64 
65  /*
66  * The below are simple virtual overrides for the plugin::MonitoredInTransaction
67  * interface.
68  */
70  {
71  return true; /* We DO participate in the SQL transaction */
72  }
74  {
75  return true; /* We DO participate in the XA transaction */
76  }
78  {
79  return false; /* We only register in the XA transaction if the engine's data is modified */
80  }
81 
82  /* Class Methods for operating on plugin */
83  static bool addPlugin(plugin::XaStorageEngine *engine);
84  static void removePlugin(plugin::XaStorageEngine *engine);
85 
86 private:
87  /*
88  * Indicates to a storage engine the start of a
89  * new SQL transaction. This is called ONLY in the following
90  * scenarios:
91  *
92  * 1) An explicit BEGIN WORK/START TRANSACTION is called
93  * 2) After an explicit COMMIT AND CHAIN is called
94  * 3) After an explicit ROLLBACK AND RELEASE is called
95  * 4) When in AUTOCOMMIT mode and directly before a new
96  * SQL statement is started.
97  *
98  * Engines should typically use the doStartStatement()
99  * and doEndStatement() methods to manage transaction state,
100  * since the kernel ALWAYS notifies engines at the start
101  * and end of statement transactions and at the end of the
102  * normal transaction by calling doCommit() or doRollback().
103  */
104  virtual int doStartTransaction(Session *session, start_transaction_option_t options)
105  {
106  (void) session;
107  (void) options;
108  return 0;
109  }
110 
111  /*
112  * Indicates to a storage engine the start of a
113  * new SQL statement.
114  */
115  virtual void doStartStatement(Session *session)
116  {
117  (void) session;
118  }
119 };
120 
121 } /* namespace plugin */
122 } /* namespace drizzled */
123