MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_table_guard.h
1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NDB_TABLE_GUARD_H
19 #define NDB_TABLE_GUARD_H
20 
21 #include <ndbapi/NdbDictionary.hpp>
22 
24 {
25 public:
27  : m_dict(dict), m_ndbtab(NULL), m_invalidate(0)
28  {}
29  Ndb_table_guard(NdbDictionary::Dictionary *dict, const char *tabname)
30  : m_dict(dict), m_ndbtab(NULL), m_invalidate(0)
31  {
32  DBUG_ENTER("Ndb_table_guard");
33  init(tabname);
34  DBUG_VOID_RETURN;
35  }
37  {
38  DBUG_ENTER("~Ndb_table_guard");
39  reinit();
40  DBUG_VOID_RETURN;
41  }
42  void init(const char *tabname)
43  {
44  DBUG_ENTER("Ndb_table_guard::init");
45  /* must call reinit() if already initialized */
46  DBUG_ASSERT(m_ndbtab == NULL);
47  m_ndbtab= m_dict->getTableGlobal(tabname);
48  m_invalidate= 0;
49  DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
50  DBUG_VOID_RETURN;
51  }
52  void reinit(const char *tabname= 0)
53  {
54  DBUG_ENTER("Ndb_table_guard::reinit");
55  if (m_ndbtab)
56  {
57  DBUG_PRINT("info", ("m_ndbtab: %p m_invalidate: %d",
58  m_ndbtab, m_invalidate));
59  m_dict->removeTableGlobal(*m_ndbtab, m_invalidate);
60  m_ndbtab= NULL;
61  m_invalidate= 0;
62  }
63  if (tabname)
64  init(tabname);
65  DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
66  DBUG_VOID_RETURN;
67  }
68  const NdbDictionary::Table *get_table() { return m_ndbtab; }
69  void invalidate() { m_invalidate= 1; }
70  const NdbDictionary::Table *release()
71  {
72  DBUG_ENTER("Ndb_table_guard::release");
73  const NdbDictionary::Table *tmp= m_ndbtab;
74  DBUG_PRINT("info", ("m_ndbtab: %p", m_ndbtab));
75  m_ndbtab = 0;
76  DBUG_RETURN(tmp);
77  }
78 private:
80  const NdbDictionary::Table *m_ndbtab;
81  int m_invalidate;
82 };
83 
84 #endif
85