MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_user_populate.cpp
1 /*
2  Copyright (C) 2003-2006 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 
20 extern "C" {
21 #include "user_populate.h"
22 }
23 
24 #include <ndb_global.h>
25 #include <NdbApi.hpp>
26 
27 #include "ndb_schema.hpp"
28 #include "ndb_error.hpp"
29 
30 int
31 insert_subscriber(void * obj,
32  SubscriberNumber number,
33  SubscriberName name,
34  GroupId groupId,
35  Location l,
36  ActiveSessions activeSessions,
37  ChangedBy changedBy,
38  ChangedTime changedTime){
39  Ndb * pNDB = (Ndb *)obj;
40  int check;
41 
42  NdbConnection * MyTransaction = pNDB->startTransaction();
43  if (MyTransaction == NULL)
44  error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
45 
46  NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
47  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
48 
49  check = MyOperation->insertTuple();
50  CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
51 
52  check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
53  CHECK_MINUS_ONE(check, "equal", MyTransaction);
54 
55  check = MyOperation->setValue(SUBSCRIBER_NAME, name);
56  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
57 
58  check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
59  CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
60 
61  check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
62  CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
63 
64  check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
65  CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
66 
67  check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
68  CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
69 
70  check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
71  CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
72 
73  check = MyTransaction->execute( Commit );
74  CHECK_MINUS_ONE(check, "commit", MyTransaction);
75 
76  pNDB->closeTransaction(MyTransaction);
77  return 0;
78 }
79 
80 int
81 insert_server(void * obj,
82  ServerId serverId,
83  SubscriberSuffix suffix,
84  ServerName name,
85  Counter noOfRead,
86  Counter noOfInsert,
87  Counter noOfDelete){
88  Ndb * pNDB = (Ndb *)obj;
89  int check;
90 
91  NdbConnection * MyTransaction = pNDB->startTransaction();
92  if (MyTransaction == NULL)
93  error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
94 
95  NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
96  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
97 
98  check = MyOperation->insertTuple();
99  CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);
100 
101  check = MyOperation->equal(SERVER_ID, (char*)&serverId);
102  CHECK_MINUS_ONE(check, "setValue id", MyTransaction);
103 
104  check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
105  CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);
106 
107  check = MyOperation->setValue(SERVER_NAME, name);
108  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
109 
110  check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
111  CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);
112 
113  check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
114  CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);
115 
116  check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
117  CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);
118 
119  check = MyTransaction->execute( Commit );
120  CHECK_MINUS_ONE(check, "commit", MyTransaction);
121 
122  pNDB->closeTransaction(MyTransaction);
123  return 0;
124 }
125 
126 int
127 insert_group(void * obj,
128  GroupId groupId,
129  GroupName name,
130  Permission allowRead,
131  Permission allowInsert,
132  Permission allowDelete){
133  Ndb * pNDB = (Ndb *)obj;
134  int check;
135 
136  NdbConnection * MyTransaction = pNDB->startTransaction();
137  if (MyTransaction == NULL)
138  error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
139 
140  NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
141  CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
142 
143  check = MyOperation->insertTuple();
144  CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
145 
146  check = MyOperation->equal(GROUP_ID, (char*)&groupId);
147  CHECK_MINUS_ONE(check, "equal", MyTransaction);
148 
149  check = MyOperation->setValue(GROUP_NAME, name);
150  CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
151 
152  check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
153  CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);
154 
155  check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
156  CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);
157 
158  check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
159  CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);
160 
161  check = MyTransaction->execute( Commit );
162  CHECK_MINUS_ONE(check, "commit", MyTransaction);
163 
164  pNDB->closeTransaction(MyTransaction);
165  return 0;
166 }
167