~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/plugin/xa_storage_engine.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
#ifndef DRIZZLED_PLUGIN_XA_STORAGE_ENGINE_H
 
22
#define DRIZZLED_PLUGIN_XA_STORAGE_ENGINE_H
 
23
 
 
24
#include "drizzled/plugin/transactional_storage_engine.h"
 
25
#include "drizzled/plugin/xa_resource_manager.h"
 
26
 
 
27
namespace drizzled
 
28
{
 
29
 
 
30
class XID;
 
31
 
 
32
namespace plugin
 
33
{
 
34
 
 
35
/**
 
36
 * A type of storage engine which supports distributed
 
37
 * transactions in the XA protocol.
 
38
 *
 
39
 * The real XA resource manager interface is in the
 
40
 * plugin::XaResourceManager class.  We would extend
 
41
 * XaResourceManager from plugin::Plugin but unfortunately
 
42
 * that would lead to member name ambiguity (because plugin::Plugin
 
43
 * has member data).  So, in this case, TransactionalStorageEngine
 
44
 * inherits from plugin::Plugin and XaResourceManager is a pure
 
45
 * virtual abstract base class with the X/Open XA distributed
 
46
 * transaction protocol interface for resource managers.
 
47
 */
 
48
class XaStorageEngine :public TransactionalStorageEngine,
 
49
                       public XaResourceManager
 
50
{
 
51
public:
 
52
  XaStorageEngine(const std::string name_arg,
 
53
                  const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
 
54
 
 
55
  virtual ~XaStorageEngine();
 
56
 
 
57
  int startTransaction(Session *session, start_transaction_option_t options)
 
58
  {
 
59
    TransactionServices &transaction_services= TransactionServices::singleton();
 
60
    transaction_services.registerResourceForTransaction(session, this, this, this);
 
61
    return doStartTransaction(session, options);
 
62
  }
 
63
 
 
64
  void startStatement(Session *session)
 
65
  {
 
66
    TransactionServices &transaction_services= TransactionServices::singleton();
 
67
    transaction_services.registerResourceForStatement(session, this, this, this);
 
68
    doStartStatement(session);
 
69
  }
 
70
 
 
71
  /* 
 
72
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
 
73
   * interface.
 
74
   */
 
75
  bool participatesInSqlTransaction() const
 
76
  {
 
77
    return true; /* We DO participate in the SQL transaction */
 
78
  }
 
79
  bool participatesInXaTransaction() const
 
80
  {
 
81
    return true; /* We DO participate in the XA transaction */
 
82
  }
 
83
  bool alwaysRegisterForXaTransaction() const
 
84
  {
 
85
    return false; /* We only register in the XA transaction if the engine's data is modified */
 
86
  }
 
87
 
 
88
  /* Class Methods for operating on plugin */
 
89
  static bool addPlugin(plugin::XaStorageEngine *engine);
 
90
  static void removePlugin(plugin::XaStorageEngine *engine);
 
91
 
 
92
private:
 
93
  /*
 
94
   * Indicates to a storage engine the start of a
 
95
   * new SQL transaction.  This is called ONLY in the following
 
96
   * scenarios:
 
97
   *
 
98
   * 1) An explicit BEGIN WORK/START TRANSACTION is called
 
99
   * 2) After an explicit COMMIT AND CHAIN is called
 
100
   * 3) After an explicit ROLLBACK AND RELEASE is called
 
101
   * 4) When in AUTOCOMMIT mode and directly before a new
 
102
   *    SQL statement is started.
 
103
   *
 
104
   * Engines should typically use the doStartStatement()
 
105
   * and doEndStatement() methods to manage transaction state,
 
106
   * since the kernel ALWAYS notifies engines at the start
 
107
   * and end of statement transactions and at the end of the
 
108
   * normal transaction by calling doCommit() or doRollback().
 
109
   */
 
110
  virtual int doStartTransaction(Session *session, start_transaction_option_t options)
 
111
  {
 
112
    (void) session;
 
113
    (void) options;
 
114
    return 0;
 
115
  }
 
116
 
 
117
  /*
 
118
   * Indicates to a storage engine the start of a
 
119
   * new SQL statement.
 
120
   */
 
121
  virtual void doStartStatement(Session *session)
 
122
  {
 
123
    (void) session;
 
124
  }
 
125
};
 
126
 
 
127
} /* namespace plugin */
 
128
} /* namespace drizzled */
 
129
 
 
130
#endif /* DRIZZLED_PLUGIN_XA_STORAGE_ENGINE_H */