MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trigger_definitions.h
1 /*
2  Copyright (C) 2003-2008 MySQL AB
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 #ifndef NDB_TRIGGER_DEFINITIONS_H
20 #define NDB_TRIGGER_DEFINITIONS_H
21 
22 #include <ndb_global.h>
23 #include "ndb_limits.h"
24 #include <Bitmask.hpp>
25 #include <signaldata/DictTabInfo.hpp>
26 
27 #define ILLEGAL_TRIGGER_ID ((Uint32)(~0))
28 
29 struct TriggerType {
30  enum Value {
31  //CONSTRAINT = 0,
32  SECONDARY_INDEX = DictTabInfo::HashIndexTrigger,
33  //FOREIGN_KEY = 2,
34  //SCHEMA_UPGRADE = 3,
35  //API_TRIGGER = 4,
36  //SQL_TRIGGER = 5,
37  SUBSCRIPTION = DictTabInfo::SubscriptionTrigger,
38  READ_ONLY_CONSTRAINT = DictTabInfo::ReadOnlyConstraint,
39  ORDERED_INDEX = DictTabInfo::IndexTrigger,
40 
41  SUBSCRIPTION_BEFORE = 9, // Only used by TUP/SUMA, should be REMOVED!!
42  REORG_TRIGGER = DictTabInfo::ReorgTrigger
43  };
44 };
45 
47  enum Value {
48  TA_BEFORE = 0, /* Immediate, before operation */
49  TA_AFTER = 1, /* Immediate, after operation */
50  TA_DEFERRED = 2, /* Before commit */
51  TA_DETACHED = 3, /* After commit in a separate transaction, NYI */
52  TA_CUSTOM = 4 /* Hardcoded per TriggerType */
53  };
54 };
55 
56 struct TriggerEvent {
58  enum Value {
59  TE_INSERT = 0,
60  TE_DELETE = 1,
61  TE_UPDATE = 2,
62  TE_CUSTOM = 3 /* Hardcoded per TriggerType */
63  };
64 };
65 
66 struct TriggerInfo {
67  TriggerType::Value triggerType;
68  TriggerActionTime::Value triggerActionTime;
69  TriggerEvent::Value triggerEvent;
70  bool monitorReplicas;
71  bool monitorAllAttributes;
72  bool reportAllMonitoredAttributes;
73 
74  // static methods
75 
76  // get/set bits in Uint32
77  static TriggerType::Value
78  getTriggerType(const Uint32& info) {
79  const Uint32 val = BitmaskImpl::getField(1, &info, 0, 8);
80  return (TriggerType::Value)val;
81  }
82  static void
83  setTriggerType(Uint32& info, TriggerType::Value val) {
84  BitmaskImpl::setField(1, &info, 0, 8, (Uint32)val);
85  }
86  static TriggerActionTime::Value
87  getTriggerActionTime(const Uint32& info) {
88  const Uint32 val = BitmaskImpl::getField(1, &info, 8, 8);
89  return (TriggerActionTime::Value)val;
90  }
91  static void
92  setTriggerActionTime(Uint32& info, TriggerActionTime::Value val) {
93  BitmaskImpl::setField(1, &info, 8, 8, (Uint32)val);
94  }
95  static TriggerEvent::Value
96  getTriggerEvent(const Uint32& info) {
97  const Uint32 val = BitmaskImpl::getField(1, &info, 16, 8);
98  return (TriggerEvent::Value)val;
99  }
100  static void
101  setTriggerEvent(Uint32& info, TriggerEvent::Value val) {
102  BitmaskImpl::setField(1, &info, 16, 8, (Uint32)val);
103  }
104  static bool
105  getMonitorReplicas(const Uint32& info) {
106  return BitmaskImpl::getField(1, &info, 24, 1);
107  }
108  static void
109  setMonitorReplicas(Uint32& info, bool val) {
110  BitmaskImpl::setField(1, &info, 24, 1, val);
111  }
112  static bool
113  getMonitorAllAttributes(const Uint32& info) {
114  return BitmaskImpl::getField(1, &info, 25, 1);
115  }
116  static void
117  setMonitorAllAttributes(Uint32& info, bool val) {
118  BitmaskImpl::setField(1, &info, 25, 1, val);
119  }
120  static bool
121  getReportAllMonitoredAttributes(const Uint32& info) {
122  return BitmaskImpl::getField(1, &info, 26, 1);
123  }
124  static void
125  setReportAllMonitoredAttributes(Uint32& info, bool val) {
126  BitmaskImpl::setField(1, &info, 26, 1, val);
127  }
128 
129  // convert between Uint32 and struct
130  static void
131  packTriggerInfo(Uint32& val, const TriggerInfo& str) {
132  val = 0;
133  setTriggerType(val, str.triggerType);
134  setTriggerActionTime(val, str.triggerActionTime);
135  setTriggerEvent(val, str.triggerEvent);
136  setMonitorReplicas(val, str.monitorReplicas);
137  setMonitorAllAttributes(val, str.monitorAllAttributes);
138  setReportAllMonitoredAttributes(val, str.reportAllMonitoredAttributes);
139  }
140  static void
141  unpackTriggerInfo(const Uint32& val, TriggerInfo& str) {
142  str.triggerType = getTriggerType(val);
143  str.triggerActionTime = getTriggerActionTime(val);
144  str.triggerEvent = getTriggerEvent(val);
145  str.monitorReplicas = getMonitorReplicas(val);
146  str.monitorAllAttributes = getMonitorAllAttributes(val);
147  str.reportAllMonitoredAttributes = getReportAllMonitoredAttributes(val);
148  }
149 
150  // for debug print
151  static const char*
152  triggerTypeName(Uint32 val) {
153  switch (val) {
154  case TriggerType::SECONDARY_INDEX:
155  return "SECONDARY_INDEX";
156  case TriggerType::SUBSCRIPTION:
157  return "SUBSCRIPTION";
158  case TriggerType::READ_ONLY_CONSTRAINT:
159  return "READ_ONLY_CONSTRAINT";
160  case TriggerType::ORDERED_INDEX:
161  return "ORDERED_INDEX";
162  case TriggerType::SUBSCRIPTION_BEFORE:
163  return "SUBSCRIPTION_BEFORE";
164  }
165  return "UNKNOWN";
166  }
167  static const char*
168  triggerActionTimeName(Uint32 val) {
169  switch (val) {
170  case TriggerActionTime::TA_BEFORE:
171  return "TA_BEFORE";
172  case TriggerActionTime::TA_AFTER:
173  return "TA_AFTER";
174  case TriggerActionTime::TA_DEFERRED:
175  return "TA_DEFERRED";
176  case TriggerActionTime::TA_DETACHED:
177  return "TA_DETACHED";
178  case TriggerActionTime::TA_CUSTOM:
179  return "TA_CUSTOM";
180  }
181  return "UNKNOWN";
182  }
183  static const char*
184  triggerEventName(Uint32 val) {
185  switch (val) {
186  case TriggerEvent::TE_INSERT:
187  return "TE_INSERT";
188  case TriggerEvent::TE_DELETE:
189  return "TE_DELETE";
190  case TriggerEvent::TE_UPDATE:
191  return "TE_UPDATE";
192  case TriggerEvent::TE_CUSTOM:
193  return "TE_CUSTOM";
194  }
195  return "UNKNOWN";
196  }
197 };
198 
200 {
201  STATIC_CONST( DeferredBit = (Uint32(1) << 31) );
202 
203  static Uint32 getFiredCount(Uint32 v) {
204  return v & ~(Uint32(DeferredBit));
205  }
206  static Uint32 getDeferredBit(Uint32 v) {
207  return (v & Uint32(DeferredBit)) != 0;
208  }
209  static void setDeferredBit(Uint32 & v) {
210  v |= Uint32(DeferredBit);
211  }
212 };
213 
214 #endif