MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbUtil.hpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB, 2010 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 /************************************************************************************************
20 Name: NdbUtil.H
21 Include:
22 Link:
23 Author: UABRONM Mikael Ronström UAB/B/SD
24 Date: 991029
25 Version: 0.4
26 Description: Utility classes for NDB API
27 Documentation:
28 Adjust: 991029 UABRONM First version.
29 Comment:
30 ************************************************************************************************/
31 #ifndef NdbUtil_H
32 #define NdbUtil_H
33 
34 #include <ndb_global.h>
35 
36 class Ndb;
37 class NdbApiSignal;
38 class NdbOperation;
39 class NdbTableImpl;
40 
41 template<class T>
43 {
44  Free_list_element() { theNext = 0;}
45  void next(T* obj) { theNext = obj;}
46  T* next() { return theNext;}
47 
48  T* theNext;
49 };
50 
51 class NdbLabel : public Free_list_element<NdbLabel>
52 {
53 friend class NdbOperation;
54 friend class Ndb;
55 public:
56  NdbLabel(Ndb*);
57  ~NdbLabel();
58 
59 private:
60  Uint32 theSubroutine[16];
61  Uint32 theLabelAddress[16];
62  Uint32 theLabelNo[16];
63 };
64 
65 class NdbSubroutine : public Free_list_element<NdbSubroutine>
66 {
67 friend class NdbOperation;
68 friend class Ndb;
69 
70 public:
72  ~NdbSubroutine();
73 
74  Uint32 theSubroutineAddress[16];
75 };
76 
77 class NdbBranch : public Free_list_element<NdbBranch>
78 {
79 friend class NdbOperation;
80 friend class Ndb;
81 
82 public:
83  NdbBranch(Ndb*);
84  ~NdbBranch();
85 
86  NdbApiSignal* theSignal;
87  Uint32 theSignalAddress;
88  Uint32 theBranchAddress;
89  Uint32 theBranchLabel;
90  Uint32 theSubroutine;
91 };
92 
93 class NdbCall : public Free_list_element<NdbCall>
94 {
95 friend class NdbOperation;
96 friend class Ndb;
97 
98 public:
99  NdbCall(Ndb*);
100  ~NdbCall();
101 
102  NdbApiSignal* theSignal;
103  Uint32 theSignalAddress;
104  Uint32 theSubroutine;
105 };
106 
107 class NdbLockHandle : public Free_list_element<NdbLockHandle>
108 {
109 
110 public:
111  enum State
112  {
113  FREE, /* In freelist */
114  ALLOCATED, /* Allocated, but not prepared */
115  PREPARED /* Prepared, and possibly executed
116  * if isLockRefValid() returns true
117  */
118  };
119 
120  State m_state;
121  const NdbTableImpl* m_table;
122 
123  /* Components of lock reference */
124  Uint32 m_lockRef[3];
125 
126  Uint32 m_openBlobCount;
127 
128  /* Used for per-transaction list of lockhandles */
129  NdbLockHandle* thePrev;
130 
131  NdbLockHandle(Ndb*);
132  ~NdbLockHandle();
133 
134  void init();
135  void release(Ndb* ndb);
136  inline bool isLockRefValid() const
137  {
138  /* LockRef[ 0 ] contains the NodeId and FragId
139  * A valid lockref would have a non-zero nodeid.
140  */
141  return ( m_lockRef[0] != 0 );
142  }
143  inline Uint32 getDistKey() const
144  {
145  /* First word of LockRef is distkey to send */
146  return m_lockRef[0];
147  }
148  inline const Uint32* getKeyInfoWords(Uint32& sz) const
149  {
150  /* Second and third words of LockRef are KeyInfo to send */
151  sz = 2;
152  return &m_lockRef[1];
153  }
154 };
155 #endif