~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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) 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
/**
 
22
 * @file Transaction processing code
 
23
 */
 
24
 
 
25
#ifndef DRIZZLED_TRANSACTION_SERVICES_H
 
26
#define DRIZZLED_TRANSACTION_SERVICES_H
 
27
 
 
28
namespace drizzled
 
29
{
 
30
 
 
31
/* some forward declarations needed */
 
32
namespace plugin
 
33
{
 
34
  class MonitoredInTransaction;
 
35
  class XaResourceManager;
 
36
  class TransactionalStorageEngine;
 
37
}
 
38
 
 
39
class Session;
 
40
class NamedSavepoint;
 
41
 
 
42
/**
 
43
 * This is a class which manages the XA transaction processing
 
44
 * in the server
 
45
 */
 
46
class TransactionServices
 
47
{
 
48
public:
 
49
  /**
 
50
   * Constructor
 
51
   */
 
52
  TransactionServices() {}
 
53
 
 
54
  /**
 
55
   * Singleton method
 
56
   * Returns the singleton instance of TransactionServices
 
57
   */
 
58
  static inline TransactionServices &singleton()
 
59
  {
 
60
    static TransactionServices transaction_services;
 
61
    return transaction_services;
 
62
  }
 
63
  /* transactions: interface to plugin::StorageEngine functions */
 
64
  int ha_commit_one_phase(Session *session, bool all);
 
65
  int ha_rollback_trans(Session *session, bool all);
 
66
 
 
67
  /* transactions: these functions never call plugin::StorageEngine functions directly */
 
68
  int ha_commit_trans(Session *session, bool all);
 
69
  int ha_autocommit_or_rollback(Session *session, int error);
 
70
 
 
71
  /* savepoints */
 
72
  int ha_rollback_to_savepoint(Session *session, NamedSavepoint &sv);
 
73
  int ha_savepoint(Session *session, NamedSavepoint &sv);
 
74
  int ha_release_savepoint(Session *session, NamedSavepoint &sv);
 
75
  bool mysql_xa_recover(Session *session);
 
76
 
 
77
  /**
 
78
   * Marks a storage engine as participating in a statement
 
79
   * transaction.
 
80
   *
 
81
   * @note
 
82
   * 
 
83
   * This method is idempotent
 
84
   *
 
85
   * @todo
 
86
   *
 
87
   * This method should not be called more than once per resource
 
88
   * per statement, and therefore should not need to be idempotent.
 
89
   * Put in assert()s to test this.
 
90
   *
 
91
   * @param[in] Session pointer
 
92
   * @param[in] Descriptor for the resource which will be participating
 
93
   * @param[in] Pointer to the TransactionalStorageEngine resource
 
94
   */
 
95
  void registerResourceForStatement(Session *session,
 
96
                                    plugin::MonitoredInTransaction *monitored,
 
97
                                    plugin::TransactionalStorageEngine *engine);
 
98
 
 
99
  /**
 
100
   * Marks an XA storage engine as participating in a statement
 
101
   * transaction.
 
102
   *
 
103
   * @note
 
104
   * 
 
105
   * This method is idempotent
 
106
   *
 
107
   * @todo
 
108
   *
 
109
   * This method should not be called more than once per resource
 
110
   * per statement, and therefore should not need to be idempotent.
 
111
   * Put in assert()s to test this.
 
112
   *
 
113
   * @param[in] Session pointer
 
114
   * @param[in] Descriptor for the resource which will be participating
 
115
   * @param[in] Pointer to the TransactionalStorageEngine resource
 
116
   * @param[in] Pointer to the XaResourceManager resource manager
 
117
   */
 
118
  void registerResourceForStatement(Session *session,
 
119
                                    plugin::MonitoredInTransaction *monitored,
 
120
                                    plugin::TransactionalStorageEngine *engine,
 
121
                                    plugin::XaResourceManager *resource_manager);
 
122
 
 
123
  /**
 
124
   * Registers a resource manager in the "normal" transaction.
 
125
   *
 
126
   * @note
 
127
   *
 
128
   * This method is idempotent and must be idempotent
 
129
   * because it can be called both by the above 
 
130
   * TransactionServices::registerResourceForStatement(),
 
131
   * which occurs at the beginning of each SQL statement,
 
132
   * and also manually when a BEGIN WORK/START TRANSACTION
 
133
   * statement is executed. If the latter case (BEGIN WORK)
 
134
   * is called, then subsequent contained statement transactions
 
135
   * will call this method as well.
 
136
   *
 
137
   * @note
 
138
   *
 
139
   * This method checks to see if the supplied resource
 
140
   * is also registered in the statement transaction, and
 
141
   * if not, registers the resource in the statement
 
142
   * transaction.  This happens ONLY when the user has
 
143
   * called BEGIN WORK/START TRANSACTION, which is the only
 
144
   * time when this method is called except from the
 
145
   * TransactionServices::registerResourceForStatement method.
 
146
   */
 
147
  void registerResourceForTransaction(Session *session,
 
148
                                      plugin::MonitoredInTransaction *monitored,
 
149
                                      plugin::TransactionalStorageEngine *engine);
 
150
  void registerResourceForTransaction(Session *session,
 
151
                                      plugin::MonitoredInTransaction *monitored,
 
152
                                      plugin::TransactionalStorageEngine *engine,
 
153
                                      plugin::XaResourceManager *resource_manager);
 
154
};
 
155
 
 
156
} /* namespace drizzled */
 
157
 
 
158
#endif /* DRIZZLED_TRANSACTION_SERVICES_H */