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, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License, version 2.0, for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26
27 extern "C" {
28 #include "user_populate.h"
29 }
30
31 #include <ndb_global.h>
32 #include <NdbApi.hpp>
33
34 #include "ndb_schema.hpp"
35 #include "ndb_error.hpp"
36
37 int
insert_subscriber(void * obj,SubscriberNumber number,SubscriberName name,GroupId groupId,Location l,ActiveSessions activeSessions,ChangedBy changedBy,ChangedTime changedTime)38 insert_subscriber(void * obj,
39 SubscriberNumber number,
40 SubscriberName name,
41 GroupId groupId,
42 Location l,
43 ActiveSessions activeSessions,
44 ChangedBy changedBy,
45 ChangedTime changedTime){
46 Ndb * pNDB = (Ndb *)obj;
47 int check;
48
49 NdbConnection * MyTransaction = pNDB->startTransaction();
50 if (MyTransaction == NULL)
51 error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
52
53 NdbOperation *MyOperation = MyTransaction->getNdbOperation(SUBSCRIBER_TABLE);
54 CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
55
56 check = MyOperation->insertTuple();
57 CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
58
59 check = MyOperation->equal(SUBSCRIBER_NUMBER, number);
60 CHECK_MINUS_ONE(check, "equal", MyTransaction);
61
62 check = MyOperation->setValue(SUBSCRIBER_NAME, name);
63 CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
64
65 check = MyOperation->setValue(SUBSCRIBER_GROUP, (char*)&groupId);
66 CHECK_MINUS_ONE(check, "setValue group", MyTransaction);
67
68 check = MyOperation->setValue(SUBSCRIBER_LOCATION, (char*)&l);
69 CHECK_MINUS_ONE(check, "setValue location", MyTransaction);
70
71 check = MyOperation->setValue(SUBSCRIBER_SESSIONS, (char*)&activeSessions);
72 CHECK_MINUS_ONE(check, "setValue sessions", MyTransaction);
73
74 check = MyOperation->setValue(SUBSCRIBER_CHANGED_BY, changedBy);
75 CHECK_MINUS_ONE(check, "setValue changedBy", MyTransaction);
76
77 check = MyOperation->setValue(SUBSCRIBER_CHANGED_TIME, changedTime);
78 CHECK_MINUS_ONE(check, "setValue changedTime", MyTransaction);
79
80 check = MyTransaction->execute( Commit );
81 CHECK_MINUS_ONE(check, "commit", MyTransaction);
82
83 pNDB->closeTransaction(MyTransaction);
84 return 0;
85 }
86
87 int
insert_server(void * obj,ServerId serverId,SubscriberSuffix suffix,ServerName name,Counter noOfRead,Counter noOfInsert,Counter noOfDelete)88 insert_server(void * obj,
89 ServerId serverId,
90 SubscriberSuffix suffix,
91 ServerName name,
92 Counter noOfRead,
93 Counter noOfInsert,
94 Counter noOfDelete){
95 Ndb * pNDB = (Ndb *)obj;
96 int check;
97
98 NdbConnection * MyTransaction = pNDB->startTransaction();
99 if (MyTransaction == NULL)
100 error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
101
102 NdbOperation *MyOperation = MyTransaction->getNdbOperation(SERVER_TABLE);
103 CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
104
105 check = MyOperation->insertTuple();
106 CHECK_MINUS_ONE(check, "insert tuple", MyTransaction);
107
108 check = MyOperation->equal(SERVER_ID, (char*)&serverId);
109 CHECK_MINUS_ONE(check, "setValue id", MyTransaction);
110
111 check = MyOperation->setValue(SERVER_SUBSCRIBER_SUFFIX, suffix);
112 CHECK_MINUS_ONE(check, "setValue suffix", MyTransaction);
113
114 check = MyOperation->setValue(SERVER_NAME, name);
115 CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
116
117 check = MyOperation->setValue(SERVER_READS, (char*)&noOfRead);
118 CHECK_MINUS_ONE(check, "setValue reads", MyTransaction);
119
120 check = MyOperation->setValue(SERVER_INSERTS, (char*)&noOfInsert);
121 CHECK_MINUS_ONE(check, "setValue inserts", MyTransaction);
122
123 check = MyOperation->setValue(SERVER_DELETES, (char*)&noOfDelete);
124 CHECK_MINUS_ONE(check, "setValue deletes", MyTransaction);
125
126 check = MyTransaction->execute( Commit );
127 CHECK_MINUS_ONE(check, "commit", MyTransaction);
128
129 pNDB->closeTransaction(MyTransaction);
130 return 0;
131 }
132
133 int
insert_group(void * obj,GroupId groupId,GroupName name,Permission allowRead,Permission allowInsert,Permission allowDelete)134 insert_group(void * obj,
135 GroupId groupId,
136 GroupName name,
137 Permission allowRead,
138 Permission allowInsert,
139 Permission allowDelete){
140 Ndb * pNDB = (Ndb *)obj;
141 int check;
142
143 NdbConnection * MyTransaction = pNDB->startTransaction();
144 if (MyTransaction == NULL)
145 error_handler("startTranscation", pNDB->getNdbErrorString(), 0);
146
147 NdbOperation *MyOperation = MyTransaction->getNdbOperation(GROUP_TABLE);
148 CHECK_NULL(MyOperation, "getNdbOperation", MyTransaction);
149
150 check = MyOperation->insertTuple();
151 CHECK_MINUS_ONE(check, "insertTuple", MyTransaction);
152
153 check = MyOperation->equal(GROUP_ID, (char*)&groupId);
154 CHECK_MINUS_ONE(check, "equal", MyTransaction);
155
156 check = MyOperation->setValue(GROUP_NAME, name);
157 CHECK_MINUS_ONE(check, "setValue name", MyTransaction);
158
159 check = MyOperation->setValue(GROUP_ALLOW_READ, (char*)&allowRead);
160 CHECK_MINUS_ONE(check, "setValue allowRead", MyTransaction);
161
162 check = MyOperation->setValue(GROUP_ALLOW_INSERT, (char*)&allowInsert);
163 CHECK_MINUS_ONE(check, "setValue allowInsert", MyTransaction);
164
165 check = MyOperation->setValue(GROUP_ALLOW_DELETE, (char*)&allowDelete);
166 CHECK_MINUS_ONE(check, "setValue allowDelete", MyTransaction);
167
168 check = MyTransaction->execute( Commit );
169 CHECK_MINUS_ONE(check, "commit", MyTransaction);
170
171 pNDB->closeTransaction(MyTransaction);
172 return 0;
173 }
174
175