22 #include "userHandle.h"
23 #include "userInterface.h"
26 #include "ndb_schema.hpp"
27 #include "ndb_error.hpp"
38 startTransaction(
Ndb * pNDB, ServerId inServerId,
const SubscriberNumber inNumber){
40 const int keyDataLenBytes =
sizeof(ServerId)+SUBSCRIBER_NUMBER_LENGTH;
41 const int keyDataLen_64Words = keyDataLenBytes >> 3;
43 Uint64 keyDataBuf[keyDataLen_64Words+1];
45 char * keyDataBuf_charP = (
char *)&keyDataBuf[0];
46 Uint32 * keyDataBuf_wo32P = (Uint32 *)&keyDataBuf[0];
49 keyDataBuf_wo32P[0] = inServerId;
51 memcpy(&keyDataBuf_charP[
sizeof(ServerId)], inNumber, SUBSCRIBER_NUMBER_LENGTH);
71 SubscriberNumber number,
72 Location new_location,
74 ChangedTime changed_time){
75 Ndb * pNDB = uh->pNDB;
77 DEBUG2(
"T1(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
83 if (MyTransaction != NULL) {
85 if (MyOperation != NULL) {
87 MyOperation->
equal(IND_SUBSCRIBER_NUMBER,
89 MyOperation->
setValue(IND_SUBSCRIBER_LOCATION,
90 (
char *)&new_location);
91 MyOperation->
setValue(IND_SUBSCRIBER_CHANGED_BY,
93 MyOperation->
setValue(IND_SUBSCRIBER_CHANGED_TIME,
95 check = MyTransaction->
execute( Commit );
100 CHECK_MINUS_ONE(check,
"T1: Commit",
104 CHECK_NULL(MyOperation,
"T1: getNdbOperation", MyTransaction);
107 error_handler(
"T1-1: startTranscation", pNDB->getNdbErrorString(), pNDB->
getNdbError());
127 SubscriberNumber number,
128 Location * readLocation,
129 ChangedBy changed_by,
130 ChangedTime changed_time,
131 SubscriberName subscriberName){
132 Ndb * pNDB = uh->pNDB;
134 DEBUG2(
"T2(%.*s):\n", SUBSCRIBER_NUMBER_LENGTH, number);
140 if (MyTransaction == NULL)
141 error_handler(
"T2-1: startTransaction", pNDB->getNdbErrorString(), pNDB->
getNdbError());
144 CHECK_NULL(MyOperation,
"T2: getNdbOperation",
147 MyOperation->readTuple();
148 MyOperation->equal(IND_SUBSCRIBER_NUMBER,
150 MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
151 (
char *)readLocation);
152 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
154 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
156 MyOperation->getValue(IND_SUBSCRIBER_NAME,
158 check = MyTransaction->
execute( Commit );
159 CHECK_MINUS_ONE(check,
"T2: Commit",
183 SubscriberNumber inNumber,
185 ServerBit inServerBit,
186 SessionDetails outSessionDetails,
187 BranchExecuted * outBranchExecuted){
188 Ndb * pNDB = uh->pNDB;
190 char outChangedBy [
sizeof(ChangedBy) +(4-(
sizeof(ChangedBy) & 3))];
191 char outChangedTime [
sizeof(ChangedTime)+(4-(
sizeof(ChangedTime) & 3))];
192 Location outLocation;
194 ActiveSessions sessions;
195 Permission permission;
196 SubscriberSuffix inSuffix;
198 DEBUG3(
"T3(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
203 NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
204 if (MyTransaction == NULL)
205 error_handler(
"T3-1: startTranscation", pNDB->getNdbErrorString(), pNDB->
getNdbError());
208 CHECK_NULL(MyOperation,
"T3-1: getNdbOperation",
211 MyOperation->readTuple();
212 MyOperation->equal(IND_SUBSCRIBER_NUMBER,
214 MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
215 (
char *)&outLocation);
216 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
218 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
220 MyOperation->getValue(IND_SUBSCRIBER_GROUP,
222 MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
224 check = MyTransaction->
execute( NoCommit );
225 CHECK_MINUS_ONE(check,
"T3-1: NoCommit",
231 CHECK_NULL(MyOperation,
"T3-2: getNdbOperation",
235 MyOperation->readTuple();
236 MyOperation->equal(IND_GROUP_ID,
238 MyOperation->getValue(IND_GROUP_ALLOW_READ,
239 (
char *)&permission);
240 check = MyTransaction->
execute( NoCommit );
241 CHECK_MINUS_ONE(check,
"T3-2: NoCommit",
244 if(((permission & inServerBit) == inServerBit) &&
245 ((sessions & inServerBit) == inServerBit)){
248 &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
249 DEBUG2(
"reading(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
253 CHECK_NULL(MyOperation,
"T3-3: getNdbOperation",
256 MyOperation->simpleRead();
258 MyOperation->equal(IND_SESSION_SUBSCRIBER,
260 MyOperation->equal(IND_SESSION_SERVER,
262 MyOperation->getValue(IND_SESSION_DATA,
263 (
char *)outSessionDetails);
266 CHECK_NULL(MyOperation,
"T3-4: getNdbOperation",
269 MyOperation->interpretedUpdateTuple();
270 MyOperation->equal(IND_SERVER_ID,
272 MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
274 MyOperation->incValue(IND_SERVER_READS, (uint32)1);
275 (* outBranchExecuted) = 1;
277 (* outBranchExecuted) = 0;
280 check = MyTransaction->
execute( Commit );
281 CHECK_MINUS_ONE(check,
"T3: Commit",
309 SubscriberNumber inNumber,
311 ServerBit inServerBit,
312 SessionDetails inSessionDetails,
313 DoRollback inDoRollback,
314 BranchExecuted * outBranchExecuted){
316 Ndb * pNDB = uh->pNDB;
318 char outChangedBy [
sizeof(ChangedBy) +(4-(
sizeof(ChangedBy) & 3))];
319 char outChangedTime [
sizeof(ChangedTime)+(4-(
sizeof(ChangedTime) & 3))];
320 Location outLocation;
322 ActiveSessions sessions;
323 Permission permission;
324 SubscriberSuffix inSuffix;
326 DEBUG3(
"T4(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
331 NdbConnection * MyTransaction = startTransaction(pNDB, inServerId, inNumber);
332 if (MyTransaction == NULL)
333 error_handler(
"T4-1: startTranscation", pNDB->getNdbErrorString(), pNDB->
getNdbError());
336 CHECK_NULL(MyOperation,
"T4-1: getNdbOperation",
339 MyOperation->interpretedUpdateTuple();
340 MyOperation->equal(IND_SUBSCRIBER_NUMBER,
342 MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
343 (
char *)&outLocation);
344 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
346 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
348 MyOperation->getValue(IND_SUBSCRIBER_GROUP,
350 MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
352 MyOperation->incValue(IND_SUBSCRIBER_SESSIONS,
353 (uint32)inServerBit);
354 check = MyTransaction->
execute( NoCommit );
359 CHECK_NULL(MyOperation,
"T4-2: getNdbOperation",
362 MyOperation->readTuple();
363 MyOperation->equal(IND_GROUP_ID,
365 MyOperation->getValue(IND_GROUP_ALLOW_INSERT,
366 (
char *)&permission);
367 check = MyTransaction->
execute( NoCommit );
368 CHECK_MINUS_ONE(check,
"T4-2: NoCommit",
371 if(((permission & inServerBit) == inServerBit) &&
372 ((sessions & inServerBit) == 0)){
375 &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
377 DEBUG2(
"inserting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
382 CHECK_NULL(MyOperation,
"T4-3: getNdbOperation",
385 MyOperation->insertTuple();
386 MyOperation->equal(IND_SESSION_SUBSCRIBER,
388 MyOperation->equal(IND_SESSION_SERVER,
390 MyOperation->setValue(SESSION_DATA,
391 (
char *)inSessionDetails);
396 CHECK_NULL(MyOperation,
"T4-5: getNdbOperation",
399 MyOperation->interpretedUpdateTuple();
400 MyOperation->equal(IND_SERVER_ID,
402 MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
404 MyOperation->incValue(IND_SERVER_INSERTS, (uint32)1);
405 (* outBranchExecuted) = 1;
407 (* outBranchExecuted) = 0;
408 DEBUG1(
"%s", ((permission & inServerBit) ?
"permission - " :
"no permission - "));
409 DEBUG1(
"%s", ((sessions & inServerBit) ?
"in session - " :
"no in session - "));
412 if(!inDoRollback && (* outBranchExecuted)){
414 check = MyTransaction->
execute( Commit );
415 CHECK_MINUS_ONE(check,
"T4: Commit",
419 check = MyTransaction->
execute(Rollback);
420 CHECK_MINUS_ONE(check,
"T4:Rollback",
447 SubscriberNumber inNumber,
449 ServerBit inServerBit,
450 DoRollback inDoRollback,
451 BranchExecuted * outBranchExecuted){
452 Ndb * pNDB = uh->pNDB;
454 DEBUG3(
"T5(%.*s, %.2d): ", SUBSCRIBER_NUMBER_LENGTH, inNumber, inServerId);
459 char outChangedBy [
sizeof(ChangedBy) +(4-(
sizeof(ChangedBy) & 3))];
460 char outChangedTime [
sizeof(ChangedTime)+(4-(
sizeof(ChangedTime) & 3))];
461 Location outLocation;
463 ActiveSessions sessions;
464 Permission permission;
465 SubscriberSuffix inSuffix;
471 if (MyTransaction == NULL)
472 error_handler(
"T5-1: startTranscation", pNDB->getNdbErrorString(), pNDB->
getNdbError());
475 CHECK_NULL(MyOperation,
"T5-1: getNdbOperation",
478 MyOperation->interpretedUpdateTuple();
479 MyOperation->equal(IND_SUBSCRIBER_NUMBER,
481 MyOperation->getValue(IND_SUBSCRIBER_LOCATION,
482 (
char *)&outLocation);
483 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_BY,
485 MyOperation->getValue(IND_SUBSCRIBER_CHANGED_TIME,
487 MyOperation->getValue(IND_SUBSCRIBER_GROUP,
489 MyOperation->getValue(IND_SUBSCRIBER_SESSIONS,
491 MyOperation->subValue(IND_SUBSCRIBER_SESSIONS,
492 (uint32)inServerBit);
493 MyTransaction->
execute( NoCommit );
497 CHECK_NULL(MyOperation,
"T5-2: getNdbOperation",
500 MyOperation->readTuple();
501 MyOperation->equal(IND_GROUP_ID,
503 MyOperation->getValue(IND_GROUP_ALLOW_DELETE,
504 (
char *)&permission);
505 check = MyTransaction->
execute( NoCommit );
506 CHECK_MINUS_ONE(check,
"T5-2: NoCommit",
509 if(((permission & inServerBit) == inServerBit) &&
510 ((sessions & inServerBit) == inServerBit)){
513 &inNumber[SUBSCRIBER_NUMBER_LENGTH-SUBSCRIBER_NUMBER_SUFFIX_LENGTH], SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
515 DEBUG2(
"deleting(%.*s) - ", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, inSuffix);
519 CHECK_NULL(MyOperation,
"T5-3: getNdbOperation",
522 MyOperation->deleteTuple();
523 MyOperation->equal(IND_SESSION_SUBSCRIBER,
525 MyOperation->equal(IND_SESSION_SERVER,
531 CHECK_NULL(MyOperation,
"T5-5: getNdbOperation",
535 MyOperation->interpretedUpdateTuple();
536 MyOperation->equal(IND_SERVER_ID,
538 MyOperation->equal(IND_SERVER_SUBSCRIBER_SUFFIX,
540 MyOperation->incValue(IND_SERVER_DELETES, (uint32)1);
541 (* outBranchExecuted) = 1;
543 (* outBranchExecuted) = 0;
544 DEBUG1(
"%s", ((permission & inServerBit) ?
"permission - " :
"no permission - "));
545 DEBUG1(
"%s", ((sessions & inServerBit) ?
"in session - " :
"no in session - "));
548 if(!inDoRollback && (* outBranchExecuted)){
550 check = MyTransaction->
execute( Commit );
551 CHECK_MINUS_ONE(check,
"T5: Commit",
555 check = MyTransaction->
execute(Rollback);
556 CHECK_MINUS_ONE(check,
"T5:Rollback",