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
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_TRANSACTION_CONTEXT_H
21
#define DRIZZLED_TRANSACTION_CONTEXT_H
27
class ResourceContext;
29
class TransactionContext
32
TransactionContext() :
35
modified_non_trans_table(false)
38
void reset() { no_2pc= false; modified_non_trans_table= false; resource_contexts.clear();}
40
typedef std::vector<ResourceContext *> ResourceContexts;
42
void setResourceContexts(ResourceContexts &new_contexts)
44
resource_contexts.assign(new_contexts.begin(), new_contexts.end());
47
ResourceContexts &getResourceContexts()
49
return resource_contexts;
51
/** Register a resource context in this transaction context */
52
void registerResource(ResourceContext *resource)
54
resource_contexts.push_back(resource);
57
/* true is not all entries in the resource contexts support 2pc */
60
/* storage engines that registered in this transaction */
61
ResourceContexts resource_contexts;
64
The purpose of this flag is to keep track of non-transactional
65
tables that were modified in scope of:
66
- transaction, when the variable is a member of
67
Session::transaction.all
68
- top-level statement or sub-statement, when the variable is a
69
member of Session::transaction.stmt
70
This member has the following life cycle:
71
* stmt.modified_non_trans_table is used to keep track of
72
modified non-transactional tables of top-level statements. At
73
the end of the previous statement and at the beginning of the session,
74
it is reset to false. If such functions
75
as mysql_insert, mysql_update, mysql_delete etc modify a
76
non-transactional table, they set this flag to true. At the
77
end of the statement, the value of stmt.modified_non_trans_table
78
is merged with all.modified_non_trans_table and gets reset.
79
* all.modified_non_trans_table is reset at the end of transaction
81
* Since we do not have a dedicated context for execution of a
82
sub-statement, to keep track of non-transactional changes in a
83
sub-statement, we re-use stmt.modified_non_trans_table.
84
At entrance into a sub-statement, a copy of the value of
85
stmt.modified_non_trans_table (containing the changes of the
86
outer statement) is saved on stack. Then
87
stmt.modified_non_trans_table is reset to false and the
88
substatement is executed. Then the new value is merged with the
91
bool modified_non_trans_table;
94
} /* namespace drizzled */
96
#endif /* DRIZZLED_TRANSACTION_CONTEXT_H */