drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
transactional_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) 2009-2010 Jay Pipes <[email protected]>
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/definitions.h> /* for start_transaction_option_t */
24#include <drizzled/plugin/storage_engine.h>
25#include <drizzled/transaction_services.h>
26
27#include <drizzled/visibility.h>
28
29namespace drizzled {
30namespace plugin {
31
57class DRIZZLED_API TransactionalStorageEngine : public StorageEngine
58{
59 friend class SEAPITester;
60public:
61 TransactionalStorageEngine(const std::string &name_arg,
62 const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
63
64 virtual int startTransaction(Session *session, start_transaction_option_t options)
65 {
67 return doStartTransaction(session, options);
68 }
69
70 virtual void startStatement(Session *session)
71 {
73 doStartStatement(session);
74 }
75
76 virtual int commit(Session *session, bool normal_transaction)
77 {
78 return doCommit(session, normal_transaction);
79 }
80
81 virtual int rollback(Session *session, bool normal_transaction)
82 {
83 return doRollback(session, normal_transaction);
84 }
85
86 int setSavepoint(Session *session, NamedSavepoint &sp)
87 {
88 return doSetSavepoint(session, sp);
89 }
90
91 int rollbackToSavepoint(Session *session, NamedSavepoint &sp)
92 {
93 return doRollbackToSavepoint(session, sp);
94 }
95
96 int releaseSavepoint(Session *session, NamedSavepoint &sp)
97 {
98 return doReleaseSavepoint(session, sp);
99 }
100
101 /*
102 * The below are simple virtual overrides for the plugin::MonitoredInTransaction
103 * interface.
104 */
105 virtual bool participatesInSqlTransaction() const
106 {
107 return true; /* We DO participate in the SQL transaction */
108 }
109 virtual bool participatesInXaTransaction() const
110 {
111 return false; /* We DON'T participate in the XA transaction */
112 }
114 {
115 return false;
116 }
117
122 static int notifyStartTransaction(Session *session, start_transaction_option_t options);
126 static void releaseTemporaryLatches(Session *session);
127
128 /* Class Methods for operating on plugin */
129 static bool addPlugin(plugin::TransactionalStorageEngine &engine);
130 static void removePlugin(plugin::TransactionalStorageEngine &engine);
131
132private:
133 void setTransactionReadWrite(Session& session);
134
135 /*
136 * Indicates to a storage engine the start of a
137 * new SQL transaction. This is called ONLY in the following
138 * scenarios:
139 *
140 * 1) An explicit BEGIN WORK/START TRANSACTION is called
141 * 2) After an explicit COMMIT AND CHAIN is called
142 * 3) After an explicit ROLLBACK AND RELEASE is called
143 * 4) When in AUTOCOMMIT mode and directly before a new
144 * SQL statement is started.
145 *
146 * Engines should typically use the doStartStatement()
147 * and doEndStatement() methods to manage transaction state,
148 * since the kernel ALWAYS notifies engines at the start
149 * and end of statement transactions and at the end of the
150 * normal transaction by calling doCommit() or doRollback().
151 */
152 virtual int doStartTransaction(Session *session, start_transaction_option_t options)
153 {
154 (void) session;
155 (void) options;
156 return 0;
157 }
158
159 /*
160 * Indicates to a storage engine the start of a
161 * new SQL statement.
162 */
163 virtual void doStartStatement(Session *session)
164 {
165 (void) session;
166 }
167
168 /*
169 * Indicates to a storage engine the end of
170 * the current SQL statement in the supplied
171 * Session.
172 */
173 virtual void doEndStatement(Session *session)
174 {
175 (void) session;
176 }
181 virtual int doSetSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
182 virtual int doRollbackToSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
183 virtual int doReleaseSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
184
197 virtual int doCommit(Session *session, bool normal_transaction)= 0;
198
211 virtual int doRollback(Session *session, bool normal_transaction)= 0;
212 virtual int doReleaseTemporaryLatches(Session*)
213 {
214 return 0;
215 }
216 virtual int doStartConsistentSnapshot(Session*)
217 {
218 return 0;
219 }
220};
221
222} /* namespace plugin */
223} /* namespace drizzled */
224
static void registerResourceForStatement(Session &, plugin::MonitoredInTransaction *, plugin::TransactionalStorageEngine *)
static void registerResourceForTransaction(Session &, plugin::MonitoredInTransaction *, plugin::TransactionalStorageEngine *)
virtual int doRollback(Session *session, bool normal_transaction)=0
virtual int doSetSavepoint(Session *session, NamedSavepoint &savepoint)=0
virtual int doCommit(Session *session, bool normal_transaction)=0
TODO: Rename this file - func.h is stupid.
Visibility Control Macros.
#define DRIZZLED_API
Definition visibility.h:38