~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/resource_context.h

Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef DRIZZLED_HA_TRX_INFO_H
21
 
#define DRIZZLED_HA_TRX_INFO_H
 
20
#ifndef DRIZZLED_RESOURCE_CONTEXT_H
 
21
#define DRIZZLED_RESOURCE_CONTEXT_H
22
22
 
 
23
#include <cstddef>
23
24
 
24
25
namespace drizzled
25
26
{
26
27
 
27
 
class Session_TRANS;
28
28
namespace plugin
29
29
{
30
30
class StorageEngine;
31
31
}
32
32
 
33
 
 
34
33
/**
35
 
  Either statement transaction or normal transaction - related
36
 
  thread-specific storage engine data.
37
 
 
38
 
  If a storage engine participates in a statement/transaction,
39
 
  an instance of this class is present in
40
 
  session->transaction.{stmt|all}.ha_list. The addition to
41
 
  {stmt|all}.ha_list is made by trans_register_ha().
42
 
 
43
 
  When it's time to commit or rollback, each element of ha_list
44
 
  is used to access storage engine's prepare()/commit()/rollback()
45
 
  methods, and also to evaluate if a full two phase commit is
46
 
  necessary.
47
 
 
48
 
  @sa General description of transaction handling in handler.cc.
49
 
*/
50
 
 
51
 
class Ha_trx_info
 
34
 * Either statement transaction or normal transaction - related
 
35
 * session-specific storage engine data.
 
36
 *
 
37
 * If a storage engine participates in a statement/transaction,
 
38
 * an instance of this class is present in
 
39
 * session->transaction.{stmt|all}.resource_contexts.
 
40
 *
 
41
 * When it's time to commit or rollback, each element of ha_list
 
42
 * is used to access resource manager's prepare()/commit()/rollback()
 
43
 * methods, and also to evaluate if a full two phase commit is
 
44
 * necessary.
 
45
 * 
 
46
 * @sa General description of transaction handling in drizzled/transaction_services.cc.
 
47
 */
 
48
class ResourceContext
52
49
{
53
50
public:
54
 
  /** Register this storage engine in the given transaction context. */
55
 
  void register_ha(Session_TRANS *trans,
56
 
                   plugin::StorageEngine *engine_arg);
 
51
  ResourceContext() :
 
52
    resource(NULL),
 
53
    modified_data(false)
 
54
  {}
57
55
 
58
56
  /** Clear, prepare for reuse. */
59
57
  void reset();
60
 
  Ha_trx_info() { reset(); }
61
 
 
62
 
  void set_trx_read_write();
63
 
  bool is_trx_read_write() const;
64
 
  bool is_started() const;
65
 
 
66
 
  /** Mark this transaction read-write if the argument is read-write. */
67
 
  void coalesce_trx_with(const Ha_trx_info *stmt_trx);
68
 
  Ha_trx_info *next() const;
69
 
  plugin::StorageEngine *engine() const;
70
 
 
 
58
 
 
59
  /**
 
60
   * Marks that the underlying resource manager
 
61
   * has modified data state.
 
62
   */
 
63
  void markModifiedData();
 
64
 
 
65
  /**
 
66
   * Returns true if the underlying resource manager
 
67
   * has modified data state.
 
68
   */
 
69
  bool hasModifiedData() const;
 
70
 
 
71
  /**
 
72
   * Returns true if the underlying resource
 
73
   * manager has registered with the transaction
 
74
   * manager for this transaction.
 
75
   */
 
76
  bool isStarted() const;
 
77
 
 
78
  /** 
 
79
   * Mark this context as modifying data if the argument has also modified data
 
80
   */
 
81
  void coalesceWith(const ResourceContext *stmt_trx);
 
82
 
 
83
  /**
 
84
   * Returns the underlying resource manager
 
85
   * this context tracks.
 
86
   */
 
87
  drizzled::plugin::StorageEngine *getResource() const
 
88
  {
 
89
    return resource;
 
90
  }
 
91
 
 
92
  /**
 
93
   * Sets the underlying resource
 
94
   */
 
95
  void setResource(drizzled::plugin::StorageEngine *in_engine)
 
96
  {
 
97
    resource= in_engine;
 
98
  }
71
99
private:
72
 
  enum { TRX_READ_ONLY= 0, TRX_READ_WRITE= 1 };
73
 
  /** Auxiliary, used for ha_list management */
74
 
  Ha_trx_info *m_next;
75
 
  /**
76
 
    Although a given Ha_trx_info instance is currently always used
77
 
    for the same storage engine, 'engine' is not-NULL only when the
78
 
    corresponding storage is a part of a transaction.
79
 
  */
80
 
  plugin::StorageEngine *m_engine;
81
 
  /**
82
 
    Transaction flags related to this engine.
83
 
    Not-null only if this instance is a part of transaction.
84
 
    May assume a combination of enum values above.
85
 
  */
86
 
  unsigned char       m_flags;
 
100
  /**
 
101
    Although a given ResourceContext instance is always used
 
102
    for the same resource manager, 'resource' is not-NULL only when the
 
103
    corresponding resource manager is a part of a transaction.
 
104
  */
 
105
  drizzled::plugin::StorageEngine *resource;
 
106
  /**
 
107
   * Whether the underlying resource manager has changed
 
108
   * some data state.
 
109
   */
 
110
  bool modified_data;
87
111
};
88
112
 
89
113
} /* namespace drizzled */
90
114
 
91
 
#endif /* DRIZZLED_HA_TRX_INFO_H */
 
115
#endif /* DRIZZLED_RESOURCE_CONTEXT_H */