1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
5
* Copyright (c) 2009-2010 Jay Pipes <jaypipes@gmail.com>
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.
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.
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
21
#ifndef DRIZZLED_PLUGIN_TRANSACTIONAL_STORAGE_ENGINE_H
22
#define DRIZZLED_PLUGIN_TRANSACTIONAL_STORAGE_ENGINE_H
24
#include "drizzled/definitions.h" /* for start_transaction_option_t */
25
#include "drizzled/plugin/storage_engine.h"
26
#include "drizzled/transaction_services.h"
35
* A type of storage engine which supports SQL transactions.
37
* This class adds the SQL transactional API to the regular
38
* storage engine. In other words, it adds support for the
39
* following SQL statements:
44
* ROLLBACK TO SAVEPOINT;
50
* This class does not implement the XA protocol (two phase commit).
51
* There is an XaStorageEngine class which extends this class that
56
* kill two_phase_commit member. Use an HTON flag if
57
* absolutely needed to keep.
59
class TransactionalStorageEngine :public StorageEngine
62
TransactionalStorageEngine(const std::string name_arg,
63
const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
65
virtual ~TransactionalStorageEngine();
67
virtual int startTransaction(Session *session, start_transaction_option_t options)
69
TransactionServices &transaction_services= TransactionServices::singleton();
70
transaction_services.registerResourceForTransaction(session, this, this);
71
return doStartTransaction(session, options);
74
virtual void startStatement(Session *session)
76
TransactionServices &transaction_services= TransactionServices::singleton();
77
transaction_services.registerResourceForStatement(session, this, this);
78
doStartStatement(session);
81
virtual int commit(Session *session, bool normal_transaction)
83
return doCommit(session, normal_transaction);
86
virtual int rollback(Session *session, bool normal_transaction)
88
return doRollback(session, normal_transaction);
91
int setSavepoint(Session *session, NamedSavepoint &sp)
93
return doSetSavepoint(session, sp);
96
int rollbackToSavepoint(Session *session, NamedSavepoint &sp)
98
return doRollbackToSavepoint(session, sp);
101
int releaseSavepoint(Session *session, NamedSavepoint &sp)
103
return doReleaseSavepoint(session, sp);
107
* The below are simple virtual overrides for the plugin::MonitoredInTransaction
110
virtual bool participatesInSqlTransaction() const
112
return true; /* We DO participate in the SQL transaction */
114
virtual bool participatesInXaTransaction() const
116
return false; /* We DON'T participate in the XA transaction */
118
virtual bool alwaysRegisterForXaTransaction() const
124
* The below static class methods wrap the interaction
125
* of the vector of transactional storage engines.
127
static int notifyStartTransaction(Session *session, start_transaction_option_t options);
129
* @todo Kill this one entirely. It's implementation, not interface...
131
static int releaseTemporaryLatches(Session *session);
133
/* Class Methods for operating on plugin */
134
static bool addPlugin(plugin::TransactionalStorageEngine *engine);
135
static void removePlugin(plugin::TransactionalStorageEngine *engine);
138
void setTransactionReadWrite(Session& session);
141
* Indicates to a storage engine the start of a
142
* new SQL transaction. This is called ONLY in the following
145
* 1) An explicit BEGIN WORK/START TRANSACTION is called
146
* 2) After an explicit COMMIT AND CHAIN is called
147
* 3) After an explicit ROLLBACK AND RELEASE is called
148
* 4) When in AUTOCOMMIT mode and directly before a new
149
* SQL statement is started.
151
* Engines should typically use the doStartStatement()
152
* and doEndStatement() methods to manage transaction state,
153
* since the kernel ALWAYS notifies engines at the start
154
* and end of statement transactions and at the end of the
155
* normal transaction by calling doCommit() or doRollback().
157
virtual int doStartTransaction(Session *session, start_transaction_option_t options)
165
* Indicates to a storage engine the start of a
168
virtual void doStartStatement(Session *session)
174
* Indicates to a storage engine the end of
175
* the current SQL statement in the supplied
178
virtual void doEndStatement(Session *session)
183
* Implementing classes should override these to provide savepoint
186
virtual int doSetSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
187
virtual int doRollbackToSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
188
virtual int doReleaseSavepoint(Session *session, NamedSavepoint &savepoint)= 0;
191
* Commits either the "statement transaction" or the "normal transaction".
193
* @param[in] The Session
194
* @param[in] true if it's a real commit, that makes persistent changes
195
* false if it's not in fact a commit but an end of the
196
* statement that is part of the transaction.
199
* 'normal_transaction' is also false in auto-commit mode where 'end of statement'
200
* and 'real commit' mean the same event.
202
virtual int doCommit(Session *session, bool normal_transaction)= 0;
205
* Rolls back either the "statement transaction" or the "normal transaction".
207
* @param[in] The Session
208
* @param[in] true if it's a real commit, that makes persistent changes
209
* false if it's not in fact a commit but an end of the
210
* statement that is part of the transaction.
213
* 'normal_transaction' is also false in auto-commit mode where 'end of statement'
214
* and 'real commit' mean the same event.
216
virtual int doRollback(Session *session, bool normal_transaction)= 0;
217
virtual int doReleaseTemporaryLatches(Session *session)
222
virtual int doStartConsistentSnapshot(Session *session)
229
} /* namespace plugin */
230
} /* namespace drizzled */
232
#endif /* DRIZZLED_PLUGIN_TRANSACTIONAL_STORAGE_ENGINE_H */