~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to drizzled/plugin/transactional_storage_engine.h

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 *  Copyright (c) 2009-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
#ifndef DRIZZLED_PLUGIN_TRANSACTIONAL_STORAGE_ENGINE_H
 
22
#define DRIZZLED_PLUGIN_TRANSACTIONAL_STORAGE_ENGINE_H
 
23
 
 
24
#include "drizzled/definitions.h" /* for start_transaction_option_t */
 
25
#include "drizzled/plugin/storage_engine.h"
 
26
#include "drizzled/transaction_services.h"
 
27
 
 
28
namespace drizzled
 
29
{
 
30
 
 
31
namespace plugin
 
32
{
 
33
 
 
34
/**
 
35
 * A type of storage engine which supports SQL transactions.
 
36
 *
 
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:
 
40
 *
 
41
 * START TRANSACTION;
 
42
 * COMMIT;
 
43
 * ROLLBACK;
 
44
 * ROLLBACK TO SAVEPOINT;
 
45
 * SET SAVEPOINT;
 
46
 * RELEASE SAVEPOINT;
 
47
 *
 
48
 * @note
 
49
 *
 
50
 * This class does not implement the XA protocol (two phase commit).
 
51
 * There is an XaStorageEngine class which extends this class that
 
52
 * exposes the XA API.
 
53
 *
 
54
 * @todo
 
55
 *
 
56
 * kill two_phase_commit member. Use an HTON flag if
 
57
 * absolutely needed to keep.
 
58
 */
 
59
class TransactionalStorageEngine :public StorageEngine
 
60
{
 
61
public:
 
62
  TransactionalStorageEngine(const std::string name_arg,
 
63
                             const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
 
64
 
 
65
  virtual ~TransactionalStorageEngine();
 
66
 
 
67
  virtual int startTransaction(Session *session, start_transaction_option_t options)
 
68
  {
 
69
    TransactionServices &transaction_services= TransactionServices::singleton();
 
70
    transaction_services.registerResourceForTransaction(session, this, this);
 
71
    return doStartTransaction(session, options);
 
72
  }
 
73
 
 
74
  virtual void startStatement(Session *session)
 
75
  {
 
76
    TransactionServices &transaction_services= TransactionServices::singleton();
 
77
    transaction_services.registerResourceForStatement(session, this, this);
 
78
    doStartStatement(session);
 
79
  }
 
80
 
 
81
  virtual int commit(Session *session, bool normal_transaction)
 
82
  {
 
83
    return doCommit(session, normal_transaction);
 
84
  }
 
85
 
 
86
  virtual int rollback(Session *session, bool normal_transaction)
 
87
  {
 
88
    return doRollback(session, normal_transaction);
 
89
  }
 
90
 
 
91
  int setSavepoint(Session *session, NamedSavepoint &sp)
 
92
  {
 
93
    return doSetSavepoint(session, sp);
 
94
  }
 
95
 
 
96
  int rollbackToSavepoint(Session *session, NamedSavepoint &sp)
 
97
  {
 
98
     return doRollbackToSavepoint(session, sp);
 
99
  }
 
100
 
 
101
  int releaseSavepoint(Session *session, NamedSavepoint &sp)
 
102
  {
 
103
    return doReleaseSavepoint(session, sp);
 
104
  }
 
105
 
 
106
  /* 
 
107
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
 
108
   * interface.
 
109
   */
 
110
  virtual bool participatesInSqlTransaction() const
 
111
  {
 
112
    return true; /* We DO participate in the SQL transaction */
 
113
  }
 
114
  virtual bool participatesInXaTransaction() const
 
115
  {
 
116
    return false; /* We DON'T participate in the XA transaction */
 
117
  }
 
118
  virtual bool alwaysRegisterForXaTransaction() const
 
119
  {
 
120
    return false;
 
121
  }
 
122
 
 
123
  /** 
 
124
   * The below static class methods wrap the interaction
 
125
   * of the vector of transactional storage engines.
 
126
   */
 
127
  static int notifyStartTransaction(Session *session, start_transaction_option_t options);
 
128
  /**
 
129
   * @todo Kill this one entirely.  It's implementation, not interface...
 
130
   */
 
131
  static int releaseTemporaryLatches(Session *session);
 
132
 
 
133
  /* Class Methods for operating on plugin */
 
134
  static bool addPlugin(plugin::TransactionalStorageEngine *engine);
 
135
  static void removePlugin(plugin::TransactionalStorageEngine *engine);
 
136
 
 
137
private:
 
138
  void setTransactionReadWrite(Session& session);
 
139
 
 
140
  /*
 
141
   * Indicates to a storage engine the start of a
 
142
   * new SQL transaction.  This is called ONLY in the following
 
143
   * scenarios:
 
144
   *
 
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.
 
150
   *
 
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().
 
156
   */
 
157
  virtual int doStartTransaction(Session *session, start_transaction_option_t options)
 
158
  {
 
159
    (void) session;
 
160
    (void) options;
 
161
    return 0;
 
162
  }
 
163
 
 
164
  /*
 
165
   * Indicates to a storage engine the start of a
 
166
   * new SQL statement.
 
167
   */
 
168
  virtual void doStartStatement(Session *session)
 
169
  {
 
170
    (void) session;
 
171
  }
 
172
 
 
173
  /*
 
174
   * Indicates to a storage engine the end of
 
175
   * the current SQL statement in the supplied
 
176
   * Session.
 
177
   */
 
178
  virtual void doEndStatement(Session *session)
 
179
  {
 
180
    (void) session;
 
181
  }
 
182
  /**
 
183
   * Implementing classes should override these to provide savepoint
 
184
   * functionality.
 
185
   */
 
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;
 
189
  
 
190
  /**
 
191
   * Commits either the "statement transaction" or the "normal transaction".
 
192
   *
 
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.
 
197
   * @note
 
198
   *
 
199
   * 'normal_transaction' is also false in auto-commit mode where 'end of statement'
 
200
   * and 'real commit' mean the same event.
 
201
   */
 
202
  virtual int doCommit(Session *session, bool normal_transaction)= 0;
 
203
 
 
204
  /**
 
205
   * Rolls back either the "statement transaction" or the "normal transaction".
 
206
   *
 
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.
 
211
   * @note
 
212
   *
 
213
   * 'normal_transaction' is also false in auto-commit mode where 'end of statement'
 
214
   * and 'real commit' mean the same event.
 
215
   */
 
216
  virtual int doRollback(Session *session, bool normal_transaction)= 0;
 
217
  virtual int doReleaseTemporaryLatches(Session *session)
 
218
  {
 
219
    (void) session;
 
220
    return 0;
 
221
  }
 
222
  virtual int doStartConsistentSnapshot(Session *session)
 
223
  {
 
224
    (void) session;
 
225
    return 0;
 
226
  }
 
227
};
 
228
 
 
229
} /* namespace plugin */
 
230
} /* namespace drizzled */
 
231
 
 
232
#endif /* DRIZZLED_PLUGIN_TRANSACTIONAL_STORAGE_ENGINE_H */