1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // CegoDistManager.cc
4 // ------------------
5 // Cego distributed table manager class implementation
6 //
7 // Design and Implementation by Bjoern Lemke
8 //
9 // (C)opyright 2000-2019 Bjoern Lemke
10 //
11 // IMPLEMENTATION MODULE
12 //
13 // Class: CegoDistManager
14 //
15 // Description: Distributed table manager
16 //
17 // Status: CLEAN
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21
22 // LFC INCLUDES
23 #include <lfcbase/Exception.h>
24
25 // CEGO INCLUDES
26 #include "CegoDistManager.h"
27 #include "CegoAVLIndexCursor.h"
28 #include "CegoAVLIndexManager.h"
29 #include "CegoBTreeManager.h"
30 #include "CegoXMLdef.h"
31 #include "CegoTypeConverter.h"
32 #include "CegoRecoveryManager.h"
33 #include "CegoAction.h"
34
35 // POSIX INCLUDES
36 #include <string.h>
37 #include <stdlib.h>
38
ActiveTSUser()39 CegoDistManager::ActiveTSUser::ActiveTSUser()
40 {
41 }
42
ActiveTSUser(const Chain & tableSet)43 CegoDistManager::ActiveTSUser::ActiveTSUser(const Chain& tableSet)
44 {
45 _tableSet = tableSet;
46 }
47
ActiveTSUser(const Chain & tableSet,const Chain & userName,const Chain & passwd)48 CegoDistManager::ActiveTSUser::ActiveTSUser (const Chain& tableSet, const Chain& userName, const Chain& passwd)
49 {
50 _tableSet = tableSet;
51 _userName = userName;
52 _passwd = passwd;
53 }
54
~ActiveTSUser()55 CegoDistManager::ActiveTSUser::~ActiveTSUser()
56 {
57 }
58
getUserName() const59 const Chain& CegoDistManager::ActiveTSUser::getUserName() const
60 {
61 return _userName;
62 }
63
getPasswd() const64 const Chain& CegoDistManager::ActiveTSUser::getPasswd() const
65 {
66 return _passwd;
67 }
68
operator =(const ActiveTSUser & u)69 CegoDistManager::ActiveTSUser& CegoDistManager::ActiveTSUser::operator = (const ActiveTSUser& u)
70 {
71 _tableSet = u._tableSet;
72 _userName = u._userName;
73 _passwd = u._passwd;
74 return (*this);
75 }
76
operator ==(const CegoDistManager::ActiveTSUser & u) const77 bool CegoDistManager::ActiveTSUser::operator == (const CegoDistManager::ActiveTSUser& u) const
78 {
79 if ( _tableSet == u._tableSet)
80 return true;
81 return false;
82 }
83
CegoDistManager(CegoDatabaseManager * pDBMng)84 CegoDistManager::CegoDistManager(CegoDatabaseManager *pDBMng) : CegoTableManager(pDBMng)
85 {
86 _modId = pDBMng->getModId("CegoDistManager");
87 _authEnabled = true;
88 _numAllocated = 0;
89 _threadId = 0;
90 _pPA = 0;
91 }
92
~CegoDistManager()93 CegoDistManager::~CegoDistManager()
94 {
95 if ( _pPA )
96 delete _pPA;
97 }
98
createTableSet(const Chain & tableSet)99 void CegoDistManager::createTableSet(const Chain& tableSet)
100 {
101 createBasicTableSet(tableSet);
102
103 Chain dbHost;
104 _pDBMng->getDBHost(dbHost);
105
106 startTableSet(tableSet, dbHost, false, false, false, false);
107
108 _pDBMng->log(_modId, Logger::NOTICE, Chain("Creating system space ..."));
109 int tabSetId = _pDBMng->getTabSetId(tableSet);
110 createSystemSpace(tabSetId);
111
112 stopTableSet(tableSet, false);
113 }
114
startDistTableSet(const Chain & tableSet,const Chain & secondary,bool cleanIt,bool autoCorrect,bool doTempReset,bool cpDump)115 void CegoDistManager::startDistTableSet(const Chain& tableSet, const Chain& secondary, bool cleanIt, bool autoCorrect, bool doTempReset, bool cpDump)
116 {
117 startTableSet(tableSet, secondary, cleanIt, cpDump, autoCorrect, doTempReset);
118 }
119
registerObjects(const Chain & tableSet)120 void CegoDistManager::registerObjects(const Chain& tableSet)
121 {
122 int tabSetId = _pDBMng->getTabSetId(tableSet);
123
124 ListT<Chain> tabList;
125 getObjectList(tabSetId, CegoObject::TABLE, tabList);
126
127 Chain *pTableName = tabList.First();
128 while ( pTableName )
129 {
130 #ifdef CGDEBUG
131 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding table ") + *pTableName + Chain(" to tableset ") + tableSet);
132 #endif
133 _pDBMng->addObject(tabSetId, *pTableName, CegoObject::TABLE);
134 pTableName = tabList.Next();
135 }
136
137 ListT<Chain> viewList;
138 getObjectList(tabSetId, CegoObject::VIEW, viewList);
139 Chain *pViewName = viewList.First();
140 while ( pViewName )
141 {
142 #ifdef CGDEBUG
143 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding view ") + *pViewName + Chain(" to tableset ") + tableSet);
144 #endif
145 _pDBMng->addObject(tabSetId, *pViewName, CegoObject::VIEW);
146 pViewName = viewList.Next();
147 }
148
149 ListT<Chain> idxList;
150 getObjectList(tabSetId, CegoObject::AVLTREE, idxList);
151 Chain *pIdxName = idxList.First();
152 while ( pIdxName )
153 {
154 #ifdef CGDEBUG
155 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding index ") + *pIdxName + Chain(" to tableset ") + tableSet);
156 #endif
157 _pDBMng->addObject(tabSetId, *pIdxName, CegoObject::AVLTREE);
158 pIdxName = idxList.Next();
159 }
160
161 ListT<Chain> btreeList;
162 getObjectList(tabSetId, CegoObject::BTREE, btreeList);
163 Chain *pBTreeName = btreeList.First();
164 while ( pBTreeName )
165 {
166 #ifdef CGDEBUG
167 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding btree ") + *pBTreeName + Chain(" to tableset ") + tableSet);
168 #endif
169 _pDBMng->addObject(tabSetId, *pBTreeName, CegoObject::BTREE);
170 pBTreeName = btreeList.Next();
171 }
172
173 ListT<Chain> procList;
174 getObjectList(tabSetId, CegoObject::PROCEDURE, procList);
175 Chain *pProcName = procList.First();
176 while ( pProcName )
177 {
178
179 #ifdef CGDEBUG
180 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding procedure ") + *pProcName + Chain(" to tableset ") + tableSet);
181 #endif
182 _pDBMng->addObject(tabSetId, *pProcName, CegoObject::PROCEDURE);
183 pProcName = procList.Next();
184 }
185
186 ListT<Chain> fkeyList;
187 getObjectList(tabSetId, CegoObject::FKEY, fkeyList);
188 Chain *pFKey = fkeyList.First();
189 while ( pFKey )
190 {
191
192 #ifdef CGDEBUG
193 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding foreign key ") + *pFKey + Chain(" to tableset ") + tableSet);
194 #endif
195 _pDBMng->addObject(tabSetId, *pFKey, CegoObject::FKEY);
196 pFKey = fkeyList.Next();
197 }
198
199 ListT<Chain> checkList;
200 getObjectList(tabSetId, CegoObject::CHECK, checkList);
201 Chain *pCheck = checkList.First();
202 while ( pCheck )
203 {
204
205 #ifdef CGDEBUG
206 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding check ") + *pCheck + Chain(" to tableset ") + tableSet);
207 #endif
208 _pDBMng->addObject(tabSetId, *pCheck, CegoObject::CHECK);
209 pCheck = checkList.Next();
210 }
211
212 ListT<Chain> triggerList;
213 getObjectList(tabSetId, CegoObject::TRIGGER, triggerList);
214 Chain *pTrigger = triggerList.First();
215 while ( pTrigger )
216 {
217
218 #ifdef CGDEBUG
219 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding trigger ") + *pTrigger + Chain(" to tableset ") + tableSet);
220 #endif
221 _pDBMng->addObject(tabSetId, *pTrigger, CegoObject::TRIGGER);
222 pTrigger = triggerList.Next();
223 }
224
225 ListT<Chain> aliasList;
226 getObjectList(tabSetId, CegoObject::ALIAS, aliasList);
227 Chain *pAlias = aliasList.First();
228 while ( pAlias )
229 {
230
231 #ifdef CGDEBUG
232 _pDBMng->log(_modId, Logger::DEBUG, Chain("Adding alias ") + *pAlias + Chain(" to tableset ") + tableSet);
233 #endif
234 _pDBMng->addObject(tabSetId, *pAlias, CegoObject::ALIAS);
235 pAlias = aliasList.Next();
236 }
237 }
238
stopDistTableSet(const Chain & tableSet,bool archComplete)239 void CegoDistManager::stopDistTableSet(const Chain& tableSet, bool archComplete)
240 {
241 int tabSetId = _pDBMng->getTabSetId(tableSet);
242
243 ListT<Chain> tabList;
244 getObjectList(tabSetId, CegoObject::TABLE, tabList);
245
246 _pDBMng->removeAllObjects(tabSetId);
247 _pDBMng->releaseTableCache(tableSet);
248 _pDBMng->releaseQueryCache(tableSet);
249
250 stopTableSet(tableSet, archComplete);
251 }
252
startTableSet(const Chain & tableSet,const Chain & secondary,bool cleanIt,bool cpDump,bool doAutoCorrect,bool doTempReset)253 void CegoDistManager::startTableSet(const Chain& tableSet, const Chain& secondary, bool cleanIt, bool cpDump, bool doAutoCorrect, bool doTempReset)
254 {
255 _pDBMng->log(_modId, Logger::NOTICE, Chain("Starting tableset ") + tableSet + Chain(" ..."));
256
257 _pDBMng->setCheckPointDump(tableSet, cpDump);
258
259 // check, if we have a real problem
260 Chain runState = _pDBMng->getTableSetRunState(tableSet);
261 if ( runState == Chain(XML_CHECKPOINT_VALUE) )
262 {
263 throw Exception(EXLOC, Chain("Checkpoint crash detected, tableset might be inconsistent"));
264 }
265
266 int tabSetId = _pDBMng->getTabSetId(tableSet);
267 regDataFiles(tableSet);
268
269 Chain dbHost;
270 _pDBMng->getDBHost(dbHost);
271
272 if ( secondary != dbHost )
273 {
274 int logPort;
275 _pDBMng->getLogPort(logPort);
276
277 Chain logUser = _pDBMng->getTSLogUser(tableSet);
278 Chain logPwd = _pDBMng->getUserPwd(logUser);
279
280 _pDBMng->allocateLogConnection(tabSetId, tableSet, secondary, logPort, logUser, logPwd);
281 long cplsn = _pDBMng->getCommittedLSN(tableSet);
282
283 _pDBMng->setCurrentLSN(tabSetId, cplsn);
284 _pDBMng->startLog(tabSetId);
285 }
286 else
287 {
288
289 // we have to set tableset state for recovery
290 _pDBMng->setTableSetRunState(tableSet, XML_RECOVERY_VALUE);
291
292 registerObjects(tableSet);
293
294 _pDBMng->setActiveLogFile(tableSet);
295
296 // get checkpoint lsn
297 long cplsn = _pDBMng->getCommittedLSN(tableSet);
298
299 // get max written lsn
300 long maxlsn = _pDBMng->getMaxLSN(tabSetId);
301
302 if ( cplsn == maxlsn || ( cplsn == 0 && maxlsn == 0 ) )
303 {
304 _pDBMng->log(_modId, Logger::NOTICE, Chain("Tableset ") + tableSet + Chain(" in sync at lsn=") + Chain(cplsn) + Chain(", no recovery required"));
305 finishOpenTransaction(tabSetId);
306 }
307 else if ( cplsn < maxlsn )
308 {
309
310 long minlsn = _pDBMng->getMinLSN(tabSetId);
311
312 if ( cplsn + 1 < minlsn )
313 {
314 throw Exception(EXLOC, Chain("Checkpoint lsn=") + Chain(cplsn) + Chain(" is too small ( minlsn=") + Chain(minlsn) + Chain(")"));
315 }
316 _pDBMng->log(_modId, Logger::NOTICE, Chain("Tableset ") + tableSet + Chain(" not in sync, recovery required ( Commited lsn=") + Chain(cplsn) + Chain(")"));
317
318 _pDBMng->setCurrentLSN(tabSetId, cplsn);
319
320 unsigned long long lsn;
321 unsigned long long ts = 0;
322
323 _pDBMng->log(_modId, Logger::NOTICE, Chain("Starting recovery ... "));
324
325 setIgnoreInvalid(true);
326
327 try
328 {
329 // we have to set tableset state for recovery, so occupied redo logs are archived via log manager
330 // _pDBMng->setTableSetRunState(tableSet, XML_RECOVERY_VALUE);
331
332 CegoRecoveryManager recoveryMng(this, CegoRecoveryManager::LOCAL);
333 recoveryMng.recoverCurrentTransactionLog(tabSetId, 0, lsn, ts);
334
335 // increase lsn to next
336 _pDBMng->setCurrentLSN(tabSetId, lsn);
337
338 _pDBMng->log(_modId, Logger::NOTICE, Chain("Recovery finished"));
339
340 _pDBMng->log(_modId, Logger::NOTICE, Chain("Closing open transactions ... "));
341 finishOpenTransaction(tabSetId);
342 _pDBMng->log(_modId, Logger::NOTICE, Chain("Transactions closed"));
343
344 setIgnoreInvalid(false);
345
346 // set lsn to last lsn in log
347 _pDBMng->writeCheckPoint(tableSet, true, false, _pLockHandle);
348
349 }
350 catch ( Exception e)
351 {
352 Chain msg;
353 e.pop(msg);
354 _pDBMng->log(_modId, Logger::LOGERR, msg);
355 _pDBMng->setTableSetRunState(tableSet, XML_OFFLINE_VALUE);
356 throw e;
357 }
358 }
359 else
360 {
361 throw Exception(EXLOC, "Checkpoint lsn is too high ( maxlsn = " + Chain(maxlsn) + ", lsn=" + Chain(cplsn) + Chain(")"));
362 }
363
364 // do autocorrect here
365
366 if ( doAutoCorrect )
367 {
368
369 try
370 {
371 bool isAutoCorrect = _pDBMng->getAutoCorrect(tableSet);
372
373 if ( isAutoCorrect )
374 {
375 _pDBMng->log(_modId, Logger::NOTICE, Chain("Perform autocorrect for tableset ") + tableSet + Chain(" ..."));
376 int tabSetId = _pDBMng->getTabSetId(tableSet);
377 correctTableSet(tabSetId, false);
378 }
379 }
380 catch ( Exception e)
381 {
382 Chain msg;
383 e.pop(msg);
384 _pDBMng->log(_modId, Logger::LOGERR, msg);
385 stopTableSet(tableSet, false);
386 throw Exception(EXLOC, Chain("Cannot correct tableset ") + tableSet);
387 }
388 }
389
390 if ( doTempReset )
391 {
392 _pDBMng->log(_modId, Logger::NOTICE, Chain("Resetting temp space for tableset ") + tableSet + Chain(" ..."));
393 resetTemp(tableSet);
394 }
395
396 // setting current lsn,
397 // since the cleanTableSet procedure might fix buffers and might write a checkpoint,
398 // this must be done BEFORE the cleanIt option is performced.
399 // Fixed with version 2.47.11
400
401 _pDBMng->log(_modId, Logger::NOTICE, Chain("Setting lsn to ") + Chain(maxlsn));
402 _pDBMng->setCurrentLSN(tabSetId, maxlsn);
403
404 if ( cleanIt )
405 {
406 _pDBMng->log(_modId, Logger::NOTICE, Chain("Cleaning tableset ") + tableSet + Chain(" ..."));
407 int cleanCount = cleanTableSet(tabSetId);
408 _pDBMng->log(_modId, Logger::NOTICE, Chain(cleanCount) + Chain(" pages cleaned"));
409 }
410
411
412 // now starting log
413 _pDBMng->log(_modId, Logger::NOTICE, Chain("Starting log for tableset ") + tableSet + Chain(" ..."));
414 _pDBMng->startLog(tabSetId);
415 }
416
417 _pDBMng->allocateTableCache(tableSet);
418 _pDBMng->allocateQueryCache(tableSet);
419
420 _pDBMng->setTableSetRunState(tableSet, XML_ONLINE_VALUE);
421 _pDBMng->setTableSetSyncState(tableSet, XML_SYNCHED_VALUE);
422 }
423
distObjectExists(const Chain & tableSet,const Chain & objName,CegoObject::ObjectType objType)424 bool CegoDistManager::distObjectExists(const Chain& tableSet, const Chain& objName, CegoObject::ObjectType objType)
425 {
426 int tabSetId = _pDBMng->getTabSetId(tableSet);
427
428 Chain hostName = _pDBMng->getPrimary(tabSetId);
429
430 Chain dbHost;
431 _pDBMng->getDBHost(dbHost);
432
433 if ( hostName == dbHost )
434 {
435 if ( _pDBMng->objectExists(tabSetId, objName, objType) )
436 return true;
437 }
438 else
439 {
440 Chain user;
441 Chain password;
442
443 getActiveUser(tableSet, user, password);
444
445 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
446
447 Chain msg;
448 CegoDbHandler::ResultType res;
449
450 res = pSH->reqObjectInfoOp(tabSetId, objName, objType);
451
452 _pDBMng->releaseSession(pSH);
453
454 if ( res == CegoDbHandler::DB_INFO )
455 return true;
456 }
457 return false;
458 }
459
getDistObject(const Chain & tableSet,const Chain & objName,CegoObject::ObjectType type,CegoDecodableObject & oe)460 void CegoDistManager::getDistObject(const Chain& tableSet, const Chain& objName, CegoObject::ObjectType type, CegoDecodableObject& oe)
461 {
462 int tabSetId = _pDBMng->getTabSetId(tableSet);
463
464 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, objName, type, CegoXMLSpace::READ, _authUser) == false )
465 {
466 Chain msg = Chain("Access not allowed for object ") + objName;
467 throw Exception(EXLOC, msg);
468 }
469
470 #ifdef CGDEBUG
471 _pDBMng->log(_modId, Logger::DEBUG, Chain("Getting object ") + objName + Chain(" of type ") + CegoTypeConverter::getObjectTypeString(type));
472 #endif
473
474 Chain hostName = _pDBMng->getPrimary(tabSetId);
475
476 Chain dbHost;
477 _pDBMng->getDBHost(dbHost);
478
479 if ( hostName == dbHost )
480 {
481 getLocalObject(tabSetId, objName, type, oe);
482 oe.setLocal(true);
483 oe.setTableSet(tableSet);
484 }
485 else
486 {
487 Chain user;
488 Chain password;
489
490 getActiveUser(tableSet, user, password);
491
492 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
493
494 Chain msg;
495 CegoDbHandler::ResultType res;
496
497 res = pSH->reqObjectInfoOp(tabSetId, objName, type);
498
499 if ( res == CegoDbHandler::DB_INFO )
500 {
501 oe.putElement( pSH->getObjElement() );
502 oe.setLocal(false);
503 _pDBMng->releaseSession(pSH);
504 }
505 else if ( res == CegoDbHandler::DB_ERROR )
506 {
507 Chain msg = pSH->getMsg();
508 _pDBMng->releaseSession(pSH);
509 throw Exception(EXLOC, msg);
510 }
511 }
512 }
513
getLocalObject(int tabSetId,const Chain & objName,CegoObject::ObjectType type,CegoDecodableObject & oe)514 void CegoDistManager::getLocalObject(int tabSetId, const Chain& objName, CegoObject::ObjectType type, CegoDecodableObject& oe)
515 {
516 getObject(tabSetId, objName, type, oe);
517 }
518
truncateDistTable(const Chain & tableName,const Chain & tableSet)519 void CegoDistManager::truncateDistTable(const Chain& tableName, const Chain& tableSet)
520 {
521 #ifdef CGDEBUG
522 _pDBMng->log(_modId, Logger::DEBUG, Chain("Truncating table ") + tableName);
523 #endif
524
525 int tabSetId = _pDBMng->getTabSetId(tableSet);
526
527 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, tableName, CegoObject::TABLE, CegoXMLSpace::MODIFY, _authUser) == false )
528 {
529 Chain msg = Chain("Access not allowed for table ") + tableName;
530 throw Exception(EXLOC, msg);
531 }
532
533 Chain hostName = _pDBMng->getPrimary(tabSetId);
534
535 Chain dbHost;
536 _pDBMng->getDBHost(dbHost);
537
538 if ( hostName == dbHost )
539 {
540 truncateTable(tabSetId, tableName);
541 _pDBMng->cleanCache(tabSetId, CegoObject::TABLE, tableName);
542
543 }
544 else
545 {
546 Chain user;
547 Chain password;
548
549 getActiveUser(tableSet, user, password);
550
551 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
552
553 Chain msg;
554 CegoDbHandler::ResultType res = CegoDbHandler::DB_ERROR;
555
556 // TODO
557 // res = pSH->reqTruncateTableOp(tableSet, objName, type);
558
559 if ( res == CegoDbHandler::DB_OK )
560 {
561 _pDBMng->releaseSession(pSH);
562 }
563 else if ( res == CegoDbHandler::DB_ERROR )
564 {
565 Chain msg = pSH->getMsg();
566 _pDBMng->releaseSession(pSH);
567 throw Exception(EXLOC, msg);
568 }
569 }
570 }
571
572
dropDistObject(const Chain & objName,const Chain & tableSet,CegoObject::ObjectType type)573 void CegoDistManager::dropDistObject(const Chain& objName, const Chain& tableSet, CegoObject::ObjectType type)
574 {
575 #ifdef CGDEBUG
576 _pDBMng->log(_modId, Logger::DEBUG, Chain("Dropping object ") + objName);
577 #endif
578
579 int tabSetId = _pDBMng->getTabSetId(tableSet);
580
581 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, objName, type, CegoXMLSpace::MODIFY, _authUser) == false )
582 {
583 Chain msg = Chain("Access not allowed for object ") + objName;
584 throw Exception(EXLOC, msg);
585 }
586
587 Chain hostName = _pDBMng->getPrimary(tabSetId);
588
589 Chain dbHost;
590 _pDBMng->getDBHost(dbHost);
591
592 if ( hostName == dbHost )
593 {
594 dropObjectSynced(tabSetId, objName, type);
595
596 if ( type == CegoObject::TABLE || type == CegoObject::VIEW )
597 {
598 _pDBMng->cleanCache(tabSetId, type, objName);
599 }
600 }
601 else
602 {
603 Chain user;
604 Chain password;
605
606 getActiveUser(tableSet, user, password);
607
608 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
609
610 Chain msg;
611 CegoDbHandler::ResultType res;
612
613 res = pSH->reqDropObjectOp(tableSet, objName, type);
614
615 if ( res == CegoDbHandler::DB_OK )
616 {
617 _pDBMng->releaseSession(pSH);
618 }
619 else if ( res == CegoDbHandler::DB_ERROR )
620 {
621 Chain msg = pSH->getMsg();
622 _pDBMng->releaseSession(pSH);
623 throw Exception(EXLOC, msg);
624 }
625 }
626 }
627
createDistDataTable(const Chain & tableSet,const Chain & tableName,CegoObject::ObjectType type,ListT<CegoField> & fldList,ListT<CegoField> & idxList,bool useColumnId)628 void CegoDistManager::createDistDataTable(const Chain& tableSet, const Chain& tableName, CegoObject::ObjectType type, ListT<CegoField>& fldList, ListT<CegoField>& idxList, bool useColumnId)
629 {
630 #ifdef CGDEBUG
631 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global table ") + tableName + Chain(" in tableset ") + tableSet);
632 #endif
633
634 Chain hostName = _pDBMng->getPrimary(tableSet);
635 int tabSetId = _pDBMng->getTabSetId(tableSet);
636
637 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, tableName, type, CegoXMLSpace::MODIFY, _authUser) == false )
638 {
639 Chain msg = Chain("Access not allowed for object ") + tableName;
640 throw Exception(EXLOC, msg);
641 }
642
643 Chain dbHost;
644 _pDBMng->getDBHost(dbHost);
645
646 if ( hostName == dbHost )
647 {
648 createLocalDataTable(tabSetId, tableName, CegoObject::TABLE, fldList, idxList, useColumnId);
649 }
650 else
651 {
652 Chain user;
653 Chain password;
654
655 getActiveUser(tableSet, user, password);
656
657 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
658
659 CegoDbHandler::ResultType res;
660 res = pSH->reqCreateTableOp(tableSet, tableName, type, fldList, idxList);
661
662 if ( res == CegoDbHandler::DB_OK )
663 {
664 _pDBMng->releaseSession(pSH);
665 }
666 else if ( res == CegoDbHandler::DB_ERROR )
667 {
668 Chain msg = pSH->getMsg();
669 _pDBMng->releaseSession(pSH);
670 throw Exception(EXLOC, msg);
671 }
672 }
673 }
674
createLocalDataTable(int tabSetId,const Chain & tableName,CegoObject::ObjectType type,ListT<CegoField> & fldList,ListT<CegoField> & idxList,bool useColumnId)675 void CegoDistManager::createLocalDataTable(int tabSetId, const Chain& tableName, CegoObject::ObjectType type, ListT<CegoField>& fldList, ListT<CegoField>& idxList, bool useColumnId)
676 {
677
678 createDataTable(tabSetId, tableName, type, fldList, useColumnId);
679 _pDBMng->addObject(tabSetId, tableName, CegoObject::TABLE);
680
681 if ( ! idxList.isEmpty() )
682 {
683 Chain idxName = tableName + Chain(TABMNG_PBTREE_SUFFIX);
684
685 try
686 {
687 createPrimaryIndexTable(tabSetId, idxName, tableName, idxList);
688 }
689 catch ( Exception e )
690 {
691 removeObject(tabSetId, tableName, CegoObject::TABLE);
692 _pDBMng->removeObject(tabSetId, tableName, CegoObject::TABLE);
693 throw e;
694 }
695 _pDBMng->addObject(tabSetId, idxName, CegoObject::BTREE);
696 }
697
698 }
699
createDistIndexTable(const Chain & tableSet,const Chain & indexName,const Chain & tableName,ListT<CegoField> & idxList,CegoObject::ObjectType type,bool isCached)700 void CegoDistManager::createDistIndexTable( const Chain& tableSet, const Chain& indexName, const Chain& tableName, ListT<CegoField>& idxList, CegoObject::ObjectType type, bool isCached)
701 {
702
703 #ifdef CGDEBUG
704 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global index ") + indexName + Chain(" in tableset ") + tableSet);
705 #endif
706
707 int tabSetId = _pDBMng->getTabSetId(tableSet);
708
709 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, indexName, CegoObject::AVLTREE, CegoXMLSpace::MODIFY, _authUser) == false )
710 {
711 Chain msg = Chain("Access not allowed for index ") + indexName;
712 throw Exception(EXLOC, msg);
713 }
714
715 Chain hostName =_pDBMng->getPrimary(tableSet);
716
717 Chain dbHost;
718 _pDBMng->getDBHost(dbHost);
719
720 if ( hostName == dbHost )
721 {
722 createIndexTableSynced(tabSetId, indexName, tableName, type, idxList, isCached);
723 }
724 else
725 {
726 Chain user;
727 Chain password;
728
729 getActiveUser(tableSet, user, password);
730
731 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
732
733 pSH->reqCreateIndexOp(tableSet, indexName, tableName, type, idxList);
734 _pDBMng->releaseSession(pSH);
735 }
736 }
737
createDistForeignKey(const Chain & tableSet,const Chain & fkey,const Chain & tableName,const ListT<CegoField> & keyList,const Chain & refTable,const ListT<CegoField> & refList)738 void CegoDistManager::createDistForeignKey( const Chain& tableSet, const Chain& fkey, const Chain& tableName, const ListT<CegoField>& keyList, const Chain& refTable, const ListT<CegoField>& refList)
739 {
740 #ifdef CGDEBUG
741 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global foreign key ") + fkey + Chain(" in tableset ") + tableSet);
742 #endif
743
744 Chain hostName = _pDBMng->getPrimary(tableSet);
745 int tabSetId = _pDBMng->getTabSetId(tableSet);
746
747 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, tableName, CegoObject::TABLE, CegoXMLSpace::MODIFY, _authUser) == false )
748 {
749 Chain msg = Chain("Access not allowed for object ") + tableName;
750 throw Exception(EXLOC, msg);
751 }
752
753 Chain dbHost;
754 _pDBMng->getDBHost(dbHost);
755
756 if ( hostName == dbHost )
757 {
758 createLocalForeignKey(tabSetId, fkey, tableName, keyList, refTable, refList);
759 }
760 else
761 {
762 Chain user;
763 Chain password;
764
765 getActiveUser(tableSet, user, password);
766
767 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
768
769 pSH->reqCreateFKeyOp(tabSetId, fkey, tableName, keyList, refTable, refList);
770 _pDBMng->releaseSession(pSH);
771 }
772 }
773
createLocalForeignKey(int tabSetId,const Chain & fkey,const Chain & tableName,const ListT<CegoField> & keyList,const Chain & refTable,const ListT<CegoField> & refList)774 void CegoDistManager::createLocalForeignKey(int tabSetId, const Chain& fkey, const Chain& tableName, const ListT<CegoField>& keyList, const Chain& refTable, const ListT<CegoField>& refList)
775 {
776 createForeignKey(tabSetId, fkey, tableName, keyList, refTable, refList);
777
778 _pDBMng->addObject(tabSetId, fkey, CegoObject::FKEY);
779 }
780
createDistCheck(const Chain & tableSet,const Chain & checkName,const Chain & tableName,CegoPredDesc * pPredDesc)781 void CegoDistManager::createDistCheck( const Chain& tableSet, const Chain& checkName, const Chain& tableName, CegoPredDesc *pPredDesc)
782 {
783 #ifdef CGDEBUG
784 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global check ") + checkName + Chain(" in tableset ") + tableSet);
785 #endif
786
787 Chain hostName = _pDBMng->getPrimary(tableSet);
788 int tabSetId = _pDBMng->getTabSetId(tableSet);
789
790 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, tableName, CegoObject::TABLE, CegoXMLSpace::MODIFY, _authUser) == false )
791 {
792 Chain msg = Chain("Access not allowed for object ") + tableName;
793 throw Exception(EXLOC, msg);
794 }
795
796 Chain dbHost;
797 _pDBMng->getDBHost(dbHost);
798
799 if ( hostName == dbHost )
800 {
801 createLocalCheck(tabSetId, checkName, tableName, pPredDesc);
802 }
803 else
804 {
805 Chain user;
806 Chain password;
807
808 getActiveUser(tableSet, user, password);
809
810 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
811
812 pSH->reqCreateCheckOp(tableSet, checkName, tableName, pPredDesc);
813 _pDBMng->releaseSession(pSH);
814 }
815 }
816
createLocalCheck(int tabSetId,const Chain & checkName,const Chain & tableName,CegoPredDesc * pPredDesc)817 void CegoDistManager::createLocalCheck(int tabSetId, const Chain& checkName, const Chain& tableName, CegoPredDesc *pPredDesc)
818 {
819 createCheck(tabSetId, checkName, tableName, pPredDesc);
820 _pDBMng->addObject(tabSetId, checkName, CegoObject::CHECK);
821 }
822
reorgDistObject(const Chain & tableSet,const Chain & objName,CegoObject::ObjectType type)823 void CegoDistManager::reorgDistObject(const Chain& tableSet, const Chain& objName, CegoObject::ObjectType type)
824 {
825 #ifdef CGDEBUG
826 _pDBMng->log(_modId, Logger::DEBUG, Chain("Reorg global object ") + objName + Chain(" in tableset ") + tableSet);
827 #endif
828
829 Chain hostName = _pDBMng->getPrimary(tableSet);
830 int tabSetId = _pDBMng->getTabSetId(tableSet);
831
832 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, objName, type, CegoXMLSpace::MODIFY, _authUser) == false )
833 {
834 Chain msg = Chain("Access not allowed for object ") + objName;
835 throw Exception(EXLOC, msg);
836 }
837
838 Chain dbHost;
839 _pDBMng->getDBHost(dbHost);
840
841 if ( hostName == dbHost )
842 {
843 reorgObjectSynced(tabSetId, objName, type);
844 }
845 else
846 {
847 Chain user;
848 Chain password;
849
850 getActiveUser(tableSet, user, password);
851
852 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
853
854 CegoDbHandler::ResultType res;
855 res = pSH->reqReorgObjectOp(tableSet, objName, type);
856
857 if ( res == CegoDbHandler::DB_OK )
858 {
859 _pDBMng->releaseSession(pSH);
860 }
861 else if ( res == CegoDbHandler::DB_ERROR )
862 {
863 Chain msg = pSH->getMsg();
864 _pDBMng->releaseSession(pSH);
865 throw Exception(EXLOC, msg);
866 }
867 }
868 }
869
startDistTransaction(const Chain & tableSet)870 void CegoDistManager::startDistTransaction( const Chain& tableSet)
871 {
872 #ifdef CGDEBUG
873 _pDBMng->log(_modId, Logger::DEBUG, Chain("Starting global transaction in tableset ") + tableSet);
874 #endif
875
876 Chain hostName = _pDBMng->getPrimary(tableSet);
877 int tabSetId = _pDBMng->getTabSetId(tableSet);
878
879 Chain dbHost;
880 _pDBMng->getDBHost(dbHost);
881
882 if ( hostName == dbHost )
883 {
884 beginTransaction(tabSetId, true);
885 }
886 else
887 {
888 Chain user;
889 Chain password;
890
891 getActiveUser(tableSet, user, password);
892
893 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
894
895 CegoDbHandler::ResultType res;
896 res = pSH->reqStartTransactionOp(tableSet);
897
898 if ( res == CegoDbHandler::DB_OK )
899 {
900 _pDBMng->releaseSession(pSH);
901 }
902 else if ( res == CegoDbHandler::DB_ERROR )
903 {
904 Chain msg = pSH->getMsg();
905 _pDBMng->releaseSession(pSH);
906 throw Exception(EXLOC, msg);
907 }
908 }
909 }
910
endDistTransaction(const Chain & tableSet)911 long CegoDistManager::endDistTransaction( const Chain& tableSet)
912 {
913 #ifdef CGDEBUG
914 _pDBMng->log(_modId, Logger::DEBUG, Chain("Ending global transaction in tableset ") + tableSet);
915 #endif
916
917 Chain hostName = _pDBMng->getPrimary(tableSet);
918 int tabSetId = _pDBMng->getTabSetId(tableSet);
919
920 Chain dbHost;
921 _pDBMng->getDBHost(dbHost);
922
923 if ( hostName == dbHost )
924 {
925 return commitTransactionSynced(tabSetId);
926 }
927 else
928 {
929 Chain user;
930 Chain password;
931
932 long numCommitOp=0;
933
934 getActiveUser(tableSet, user, password);
935
936 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
937
938 CegoDbHandler::ResultType res;
939 res = pSH->reqCommitTransactionOp(tableSet);
940
941 if ( res == CegoDbHandler::DB_OK )
942 {
943 _pDBMng->releaseSession(pSH);
944 }
945 else if ( res == CegoDbHandler::DB_ERROR )
946 {
947 Chain msg = pSH->getMsg();
948 _pDBMng->releaseSession(pSH);
949 throw Exception(EXLOC, msg);
950 }
951
952 // TODO : numCommitOp still not set up for distributed queries
953 return numCommitOp;
954 }
955 }
956
rollbackDistTransaction(const Chain & tableSet)957 long CegoDistManager::rollbackDistTransaction(const Chain& tableSet)
958 {
959
960 #ifdef CGDEBUG
961 _pDBMng->log(_modId, Logger::DEBUG, Chain("Rollbacking global transaction in tableset ") + tableSet);
962 #endif
963
964 Chain hostName = _pDBMng->getPrimary(tableSet);
965 int tabSetId = _pDBMng->getTabSetId(tableSet);
966
967 Chain dbHost;
968 _pDBMng->getDBHost(dbHost);
969
970 if ( hostName == dbHost )
971 {
972 return rollbackTransactionSynced(tabSetId);
973 }
974 else
975 {
976 Chain user;
977 Chain password;
978
979 long numRollbackOp=0;
980
981 getActiveUser(tableSet, user, password);
982
983 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
984
985 CegoDbHandler::ResultType res;
986 res = pSH->reqRollbackTransactionOp(tableSet);
987
988 if ( res == CegoDbHandler::DB_OK )
989 {
990 _pDBMng->releaseSession(pSH);
991 }
992 else if ( res == CegoDbHandler::DB_ERROR )
993 {
994 Chain msg = pSH->getMsg();
995 _pDBMng->releaseSession(pSH);
996 throw Exception(EXLOC, msg);
997 }
998
999 // TODO : numRollbackOp still not set up for distributed queries
1000 return numRollbackOp;
1001 }
1002 }
1003
getDistTid(const Chain & tableSet)1004 int CegoDistManager::getDistTid( const Chain& tableSet)
1005 {
1006 Chain hostName = _pDBMng->getPrimary(tableSet);
1007 int tabSetId = _pDBMng->getTabSetId(tableSet);
1008
1009 Chain dbHost;
1010 _pDBMng->getDBHost(dbHost);
1011
1012 if ( hostName == dbHost )
1013 {
1014 return getLocalTid(tabSetId);
1015 }
1016 else
1017 {
1018 Chain user;
1019 Chain password;
1020
1021 getActiveUser(tableSet, user, password);
1022
1023 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1024
1025 Chain msg;
1026 CegoDbHandler::ResultType res;
1027
1028 int tid = 0;
1029 res = pSH->reqGetTidOp(tableSet);
1030
1031 if ( res == CegoDbHandler::DB_INFO )
1032 {
1033 Chain tidString;
1034 pSH->getArgValue(XML_TID_ATTR, tidString);
1035
1036 tid = tidString.asInteger();
1037
1038 _pDBMng->releaseSession(pSH);
1039
1040 }
1041 else if ( res == CegoDbHandler::DB_ERROR )
1042 {
1043 Chain msg = pSH->getMsg();
1044 _pDBMng->releaseSession(pSH);
1045 throw Exception(EXLOC, msg);
1046 }
1047 return tid;
1048 }
1049 }
1050
getLocalTid(int tabSetId)1051 int CegoDistManager::getLocalTid(int tabSetId)
1052 {
1053 return getTID(tabSetId);
1054 }
1055
setAllocatedSortArea(unsigned long long n)1056 void CegoDistManager::setAllocatedSortArea(unsigned long long n)
1057 {
1058 _numAllocated = n;
1059 }
1060
getAllocatedSortArea() const1061 unsigned long long CegoDistManager::getAllocatedSortArea() const
1062 {
1063 return _numAllocated;
1064 }
1065
insertDistDataTable(CegoTableObject & oe,ListT<CegoField> & fvl)1066 void CegoDistManager::insertDistDataTable(CegoTableObject& oe, ListT<CegoField>& fvl)
1067 {
1068 #ifdef CGDEBUG
1069 _pDBMng->log(_modId, Logger::DEBUG, Chain("Inserting into global table ") + oe.getName());
1070 #endif
1071
1072 if ( _authEnabled == true && _pDBMng->verifyAccess(oe.getTabSetId(), oe.getName(), oe.getType(), CegoXMLSpace::WRITE, _authUser) == false )
1073 {
1074 Chain msg = Chain("Access not allowed for object ") + oe.getName();
1075 throw Exception(EXLOC, msg);
1076 }
1077
1078 Chain hostName = _pDBMng->getPrimary(oe.getTabSetId());
1079
1080 Chain dbHost;
1081 _pDBMng->getDBHost(dbHost);
1082
1083 if ( hostName == dbHost )
1084 {
1085 insertLocalDataTable(oe, fvl);
1086 }
1087 else
1088 {
1089 Chain tableSet = _pDBMng->getTabSetName(oe.getTabSetId());
1090
1091 Chain user;
1092 Chain password;
1093
1094 getActiveUser(tableSet, user, password);
1095
1096 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1097
1098 Chain msg;
1099 CegoDbHandler::ResultType res;
1100 res = pSH->reqInsertOp(tableSet, oe.getName(), fvl);
1101
1102 if ( res == CegoDbHandler::DB_OK )
1103 {
1104 _pDBMng->releaseSession(pSH);
1105 }
1106 else if ( res == CegoDbHandler::DB_ERROR )
1107 {
1108 Chain msg = pSH->getMsg();
1109 _pDBMng->releaseSession(pSH);
1110 throw Exception(EXLOC, msg);
1111 }
1112 }
1113 }
1114
insertLocalDataTable(CegoTableObject & oe,ListT<CegoField> & fvl)1115 void CegoDistManager::insertLocalDataTable(CegoTableObject& oe, ListT<CegoField>& fvl)
1116 {
1117 _pDBMng->useObject(oe.getTabSetId(), oe.getName(), oe.getType(), CegoDatabaseManager::SHARED, _threadId);
1118
1119 try {
1120
1121 ListT<CegoTableObject> idxList;
1122 ListT<CegoBTreeObject> btreeList;
1123 ListT<CegoKeyObject> keyList;
1124 ListT<CegoCheckObject> checkList;
1125 ListT<CegoTriggerObject> triggerList;
1126 ListT<CegoAliasObject> aliasList;
1127 int numInvalid;
1128
1129 bool doAppend;
1130 bool doLogging = true;
1131
1132 getObjectListByTable(oe.getTabSetId(), oe.getName(), idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
1133 if ( numInvalid > 0 )
1134 {
1135 // for ongoing transactions, we don't support online index build up
1136 if ( getTID(oe.getTabSetId() != 0 ))
1137 {
1138 throw Exception(EXLOC, Chain("Invalid index detected, must be valid for transactions"));
1139 }
1140 doAppend = true;
1141 }
1142 else
1143 {
1144 doAppend = _doAppend;
1145 }
1146
1147
1148 CegoTriggerObject *pTO = triggerList.First();
1149 while ( pTO )
1150 {
1151 if ( pTO->isOnInsert() && pTO->isBefore() )
1152 {
1153 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1154 pTrigger->execute(&fvl);
1155 }
1156 pTO = triggerList.Next();
1157 }
1158
1159 CegoDataPointer sysEntry;
1160 Chain virginIndex;
1161 CegoDataPointer dp;
1162 insertDataTable(oe, fvl, idxList, btreeList, keyList, checkList, sysEntry, virginIndex, dp, doLogging, doAppend, true, true);
1163
1164 pTO = triggerList.First();
1165 while ( pTO )
1166 {
1167 if ( pTO->isOnInsert() && pTO->isBefore() == false )
1168 {
1169 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1170 pTrigger->execute(&fvl);
1171 }
1172 pTO = triggerList.Next();
1173 }
1174 }
1175 catch ( Exception e )
1176 {
1177 _pDBMng->unuseObject(oe.getTabSetId(), oe.getName(), oe.getType());
1178 throw e;
1179 }
1180 _pDBMng->unuseObject(oe.getTabSetId(), oe.getName(), oe.getType());
1181 }
1182
1183
1184
insertDistDataTable(CegoTableObject & oe,ListT<ListT<CegoField>> & fva)1185 void CegoDistManager::insertDistDataTable(CegoTableObject& oe, ListT< ListT<CegoField> >& fva)
1186 {
1187 #ifdef CGDEBUG
1188 _pDBMng->log(_modId, Logger::DEBUG, Chain("Inserting into global table ") + oe.getName());
1189 #endif
1190
1191 if ( _authEnabled == true && _pDBMng->verifyAccess(oe.getTabSetId(), oe.getName(), oe.getType(), CegoXMLSpace::WRITE, _authUser) == false )
1192 {
1193 Chain msg = Chain("Access not allowed for object ") + oe.getName();
1194 throw Exception(EXLOC, msg);
1195 }
1196
1197 Chain hostName = _pDBMng->getPrimary(oe.getTabSetId());
1198
1199 Chain dbHost;
1200 _pDBMng->getDBHost(dbHost);
1201
1202 if ( hostName == dbHost )
1203 {
1204 insertLocalDataTable(oe, fva);
1205 }
1206 else
1207 {
1208 Chain tableSet = _pDBMng->getTabSetName(oe.getTabSetId());
1209
1210 Chain user;
1211 Chain password;
1212
1213 getActiveUser(tableSet, user, password);
1214
1215 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1216
1217 Chain msg;
1218 CegoDbHandler::ResultType res = CegoDbHandler::DB_ERROR;
1219 // TODO
1220 // res = pSH->reqInsertOp(tableSet, oe.getName(), fvl);
1221
1222 if ( res == CegoDbHandler::DB_OK )
1223 {
1224 _pDBMng->releaseSession(pSH);
1225 }
1226 else if ( res == CegoDbHandler::DB_ERROR )
1227 {
1228 Chain msg = pSH->getMsg();
1229 _pDBMng->releaseSession(pSH);
1230 throw Exception(EXLOC, msg);
1231 }
1232 }
1233 }
1234
insertLocalDataTable(CegoTableObject & oe,ListT<ListT<CegoField>> & fva)1235 void CegoDistManager::insertLocalDataTable(CegoTableObject& oe, ListT< ListT<CegoField> >& fva )
1236 {
1237 _pDBMng->useObject(oe.getTabSetId(), oe.getName(), oe.getType(), CegoDatabaseManager::SHARED, _threadId);
1238
1239 try {
1240
1241 ListT<CegoTableObject> idxList;
1242 ListT<CegoBTreeObject> btreeList;
1243 ListT<CegoKeyObject> keyList;
1244 ListT<CegoCheckObject> checkList;
1245 ListT<CegoTriggerObject> triggerList;
1246 ListT<CegoAliasObject> aliasList;
1247 int numInvalid;
1248
1249 bool doAppend;
1250 bool doLogging = true;
1251
1252 getObjectListByTable(oe.getTabSetId(), oe.getName(), idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
1253 if ( numInvalid > 0 )
1254 {
1255 // for ongoing transactions, we don't support online index build up
1256 if ( getTID(oe.getTabSetId() != 0 ))
1257 {
1258 throw Exception(EXLOC, Chain("Invalid index detected, must be valid for transactions"));
1259 }
1260 doAppend = true;
1261 }
1262 else
1263 {
1264 doAppend = _doAppend;
1265 }
1266
1267
1268 ListT<CegoField> *pFVL = fva.First();
1269 int numEntry = fva.Size();
1270 int entryCount=0;
1271
1272 while ( pFVL )
1273 {
1274 entryCount++;
1275
1276 CegoTriggerObject *pTO = triggerList.First();
1277 while ( pTO )
1278 {
1279 if ( pTO->isOnInsert() && pTO->isBefore() )
1280 {
1281 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1282 pTrigger->execute(pFVL);
1283 }
1284 pTO = triggerList.Next();
1285 }
1286
1287 CegoDataPointer sysEntry;
1288 Chain virginIndex;
1289 CegoDataPointer dp;
1290
1291 // for performance reasons, just for last insert call, we do flush log ( entryCount == numEntry )
1292 insertDataTable(oe, *pFVL, idxList, btreeList, keyList, checkList, sysEntry, virginIndex, dp, doLogging, doAppend, true, entryCount == numEntry);
1293
1294 pTO = triggerList.First();
1295 while ( pTO )
1296 {
1297 if ( pTO->isOnInsert() && pTO->isBefore() == false )
1298 {
1299 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1300 pTrigger->execute(pFVL);
1301 }
1302 pTO = triggerList.Next();
1303 }
1304
1305 pFVL = fva.Next();
1306 }
1307 }
1308 catch ( Exception e )
1309 {
1310 _pDBMng->unuseObject(oe.getTabSetId(), oe.getName(), oe.getType());
1311 throw e;
1312 }
1313 _pDBMng->unuseObject(oe.getTabSetId(), oe.getName(), oe.getType());
1314 }
1315
1316
deleteDistDataTable(CegoTableObject & oe,CegoPredDesc * pPred,CegoProcBlock * pBlock)1317 unsigned long long CegoDistManager::deleteDistDataTable(CegoTableObject& oe, CegoPredDesc* pPred, CegoProcBlock* pBlock)
1318 {
1319 #ifdef CGDEBUG
1320 _pDBMng->log(_modId, Logger::DEBUG, Chain("Deleting from global table ") + oe.getName());
1321 #endif
1322
1323 if ( _authEnabled == true && _pDBMng->verifyAccess(oe.getTabSetId(), oe.getName(), oe.getType(), CegoXMLSpace::WRITE, _authUser) == false )
1324 {
1325 Chain msg = Chain("Access not allowed for object ") + oe.getName();
1326 throw Exception(EXLOC, msg);
1327 }
1328
1329 Chain hostName = _pDBMng->getPrimary(oe.getTabSetId());
1330
1331 Chain dbHost;
1332 _pDBMng->getDBHost(dbHost);
1333
1334 if ( hostName == dbHost )
1335 {
1336 return deleteLocalDataTable(oe, pPred, pBlock);
1337 }
1338 else
1339 {
1340 Chain tableSet = _pDBMng->getTabSetName(oe.getTabSetId());
1341
1342 Chain user;
1343 Chain password;
1344
1345 getActiveUser(tableSet, user, password);
1346
1347 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1348
1349 pSH->reqDeleteOp(tableSet, oe.getName(), pPred);
1350 unsigned long long delCount = pSH->getAffected();
1351 _pDBMng->releaseSession(pSH);
1352
1353 return delCount;
1354 }
1355 }
1356
1357
deleteLocalDataTable(CegoTableObject & oe,CegoPredDesc * pPred,CegoProcBlock * pBlock)1358 unsigned long long CegoDistManager::deleteLocalDataTable(CegoTableObject& oe, CegoPredDesc* pPred, CegoProcBlock* pBlock)
1359 {
1360 unsigned long long delCount = 0;
1361
1362 bool forceTransaction=false;
1363 if ( getTID(oe.getTabSetId()) == 0 )
1364 {
1365 forceTransaction=true;
1366 beginTransaction(oe.getTabSetId(), true);
1367 }
1368
1369 _pDBMng->useObject(oe.getTabSetId(), oe.getName(), oe.getType(), CegoDatabaseManager::SHARED, _threadId);
1370
1371 try {
1372
1373 ListT<CegoTableObject> idxList;
1374 ListT<CegoBTreeObject> btreeList;
1375 ListT<CegoKeyObject> keyList;
1376 ListT<CegoCheckObject> checkList;
1377 ListT<CegoTriggerObject> triggerList;
1378 ListT<CegoAliasObject> aliasList;
1379 int numInvalid;
1380
1381 getObjectListByTable(oe.getTabSetId(), oe.getTabName(), idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
1382
1383 if ( numInvalid > 0 )
1384 {
1385 throw Exception(EXLOC, Chain("Invalid index detected, must be valid for delete opertions"));
1386 }
1387
1388 CegoTriggerObject *pTO = triggerList.First();
1389 while ( pTO )
1390 {
1391 if ( pTO->isOnDelete() && pTO->isBefore() )
1392 {
1393 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1394 pTrigger->execute();
1395 }
1396 pTO = triggerList.Next();
1397 }
1398
1399 delCount = deleteDataTable(oe, idxList, btreeList, keyList, pPred, pBlock, true);
1400
1401 pTO = triggerList.First();
1402 while ( pTO )
1403 {
1404 if ( pTO->isOnDelete() && pTO->isBefore() == false )
1405 {
1406 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1407 pTrigger->execute();
1408 }
1409 pTO = triggerList.Next();
1410 }
1411 }
1412 catch ( Exception e)
1413 {
1414
1415 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1416
1417 if ( forceTransaction )
1418 {
1419 _pDBMng->useObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE, CegoDatabaseManager::SHARED, _threadId);
1420
1421 try
1422 {
1423 rollbackTransaction(oe.getTabSetId(), true);
1424 }
1425 catch ( Exception e )
1426 {
1427 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1428 throw e;
1429 }
1430 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1431 }
1432
1433 throw e;
1434
1435 }
1436
1437 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1438
1439 if ( forceTransaction )
1440 {
1441 _pDBMng->useObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE, CegoDatabaseManager::EXCLUSIVE_WRITE, _threadId);
1442
1443 try
1444 {
1445 // for the commit, we have to use the table object in exclusive mode
1446 commitTransaction(oe.getTabSetId(), true);
1447 }
1448 catch ( Exception e )
1449 {
1450 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1451 throw e;
1452 }
1453
1454 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1455 }
1456
1457
1458 return delCount;
1459 }
1460
1461
updateDistDataTable(CegoTableObject & oe,CegoPredDesc * pPred,ListT<CegoField> & updSchema,ListT<CegoExpr * > & exprList,bool returnOnFirst,ListT<CegoField> & returnList,CegoProcBlock * pBlock)1462 unsigned long long CegoDistManager::updateDistDataTable(CegoTableObject& oe,
1463 CegoPredDesc* pPred,
1464 ListT<CegoField>& updSchema,
1465 ListT<CegoExpr*>& exprList,
1466 bool returnOnFirst,
1467 ListT<CegoField>& returnList,
1468 CegoProcBlock* pBlock)
1469 {
1470 #ifdef CGDEBUG
1471 _pDBMng->log(_modId, Logger::DEBUG, Chain("Updating global table ") + oe.getName());
1472 #endif
1473
1474 if ( _authEnabled == true && _pDBMng->verifyAccess(oe.getTabSetId(), oe.getName(), oe.getType(), CegoXMLSpace::WRITE, _authUser) == false )
1475 {
1476 Chain msg = Chain("Access not allowed for object ") + oe.getName();
1477 throw Exception(EXLOC, msg);
1478 }
1479
1480 Chain hostName = _pDBMng->getPrimary(oe.getTabSetId());
1481
1482 Chain dbHost;
1483 _pDBMng->getDBHost(dbHost);
1484
1485 if ( hostName == dbHost )
1486 {
1487 return updateLocalDataTable(oe, pPred, updSchema, exprList, returnOnFirst, returnList, pBlock);
1488 }
1489 else
1490 {
1491 Chain tableSet = _pDBMng->getTabSetName(oe.getTabSetId());
1492
1493 Chain user;
1494 Chain password;
1495
1496 getActiveUser(tableSet, user, password);
1497
1498 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1499
1500 pSH->reqUpdateOp(tableSet, oe.getName(), updSchema, exprList, pPred);
1501 long updCount = pSH->getAffected();
1502 _pDBMng->releaseSession(pSH);
1503
1504 return updCount;
1505 }
1506 }
1507
updateLocalDataTable(CegoTableObject & oe,CegoPredDesc * pPred,ListT<CegoField> & updList,ListT<CegoExpr * > & exprList,bool returnOnFirst,ListT<CegoField> & returnList,CegoProcBlock * pBlock)1508 unsigned long long CegoDistManager::updateLocalDataTable(CegoTableObject& oe,
1509 CegoPredDesc* pPred,
1510 ListT<CegoField>& updList,
1511 ListT<CegoExpr*>& exprList,
1512 bool returnOnFirst,
1513 ListT<CegoField>& returnList,
1514 CegoProcBlock* pBlock)
1515 {
1516 unsigned long long updCount = 0;
1517 bool forceTransaction=false;
1518 if ( getTID(oe.getTabSetId()) == 0 )
1519 {
1520 forceTransaction=true;
1521 beginTransaction(oe.getTabSetId(), true);
1522 }
1523
1524 _pDBMng->useObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE, CegoDatabaseManager::SHARED, _threadId);
1525
1526 try
1527 {
1528 ListT<CegoTableObject> idxList;
1529 ListT<CegoBTreeObject> btreeList;
1530 ListT<CegoKeyObject> keyList;
1531 ListT<CegoCheckObject> checkList;
1532 ListT<CegoTriggerObject> triggerList;
1533 ListT<CegoAliasObject> aliasList;
1534 int numInvalid;
1535
1536 getObjectListByTable(oe.getTabSetId(), oe.getTabName(), idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
1537
1538 if ( numInvalid > 0 )
1539 {
1540 throw Exception(EXLOC, Chain("Invalid index detected, must be valid for update operations"));
1541 }
1542
1543 CegoTriggerObject *pTO = triggerList.First();
1544 while ( pTO )
1545 {
1546 if ( pTO->isOnUpdate() && pTO->isBefore() )
1547 {
1548 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1549
1550 ListT<CegoField> tupdList = updList;
1551 CegoField* pF = tupdList.First();
1552 CegoExpr** pExpr = exprList.First();
1553 while ( pF )
1554 {
1555 CegoFieldValue fv = (*pExpr)->evalFieldValue();
1556 pF->setValue(fv);
1557 pF = tupdList.Next();
1558 pExpr = exprList.Next();
1559 }
1560 pTrigger->execute(&tupdList);
1561
1562 }
1563 pTO = triggerList.Next();
1564 }
1565
1566 updCount = updateDataTable(oe.getTabSetId(), oe.getTabName(), oe.getTabAlias(),
1567 idxList, btreeList, keyList, checkList,
1568 pPred, updList, exprList, returnOnFirst, returnList, pBlock);
1569
1570 pTO = triggerList.First();
1571 while ( pTO )
1572 {
1573 if ( pTO->isOnUpdate() && pTO->isBefore() == false )
1574 {
1575 CegoTrigger *pTrigger = getTrigger(pTO->getTabSetId(), pTO->getName());
1576
1577 ListT<CegoField> tupdList = updList;
1578 CegoField* pF = tupdList.First();
1579 CegoExpr** pExpr = exprList.First();
1580 while ( pF )
1581 {
1582 CegoFieldValue fv = (*pExpr)->evalFieldValue();
1583 pF->setValue(fv);
1584 pF = tupdList.Next();
1585 pExpr = exprList.Next();
1586 }
1587 pTrigger->execute(&tupdList);
1588
1589 }
1590 pTO = triggerList.Next();
1591 }
1592 }
1593 catch ( Exception e )
1594 {
1595
1596 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1597
1598 if ( forceTransaction )
1599 {
1600 _pDBMng->useObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE, CegoDatabaseManager::SHARED, _threadId);
1601
1602 try
1603 {
1604 rollbackTransaction(oe.getTabSetId(), true);
1605 }
1606 catch ( Exception e )
1607 {
1608 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1609 throw e;
1610 }
1611 }
1612
1613 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1614 throw e;
1615
1616 }
1617
1618 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1619
1620 if ( forceTransaction )
1621 {
1622 try
1623 {
1624 // for the commit, we have to use the table object in exclusive mode
1625 _pDBMng->useObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE, CegoDatabaseManager::EXCLUSIVE_WRITE, _threadId);
1626 commitTransaction(oe.getTabSetId(), true);
1627 }
1628 catch ( Exception e )
1629 {
1630 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1631 throw e;
1632 }
1633
1634 _pDBMng->unuseObject(oe.getTabSetId(), oe.getTabName(), CegoObject::TABLE);
1635 }
1636
1637 return updCount;
1638 }
1639
alterDistDataTable(CegoTableObject & oe,const ListT<CegoAlterDesc> & alterList)1640 void CegoDistManager::alterDistDataTable(CegoTableObject& oe, const ListT<CegoAlterDesc>& alterList)
1641 {
1642 #ifdef CGDEBUG
1643 _pDBMng->log(_modId, Logger::DEBUG, Chain("Altering global table ") + oe.getName());
1644 #endif
1645
1646 if ( _authEnabled == true && _pDBMng->verifyAccess(oe.getTabSetId(), oe.getName(), oe.getType(), CegoXMLSpace::MODIFY, _authUser) == false )
1647 {
1648 Chain msg = Chain("Access not allowed for object ") + oe.getName();
1649 throw Exception(EXLOC, msg);
1650 }
1651
1652 Chain hostName = _pDBMng->getPrimary(oe.getTabSetId());
1653
1654 Chain dbHost;
1655 _pDBMng->getDBHost(dbHost);
1656
1657 if ( hostName == dbHost )
1658 {
1659 alterDataTableSynced(oe, alterList);
1660 }
1661 else
1662 {
1663 Chain tableSet = _pDBMng->getTabSetName(oe.getTabSetId());
1664
1665 Chain user;
1666 Chain password;
1667
1668 getActiveUser(tableSet, user, password);
1669
1670 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1671
1672 pSH->reqAlterTableOp(tableSet, oe.getName(), alterList);
1673 _pDBMng->releaseSession(pSH);
1674 }
1675 }
1676
renameDistObject(const Chain & tableSet,const Chain & objName,CegoObject::ObjectType type,const Chain & newObjName)1677 void CegoDistManager::renameDistObject(const Chain& tableSet, const Chain& objName, CegoObject::ObjectType type, const Chain& newObjName)
1678 {
1679 #ifdef CGDEBUG
1680 _pDBMng->log(_modId, Logger::DEBUG, Chain("Renaming global table ") + objName);
1681 #endif
1682
1683 int tabSetId = _pDBMng->getTabSetId(tableSet);
1684
1685 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, objName, type, CegoXMLSpace::MODIFY, _authUser) == false )
1686 {
1687 Chain msg = Chain("Access not allowed for object ") + objName;
1688 throw Exception(EXLOC, msg);
1689 }
1690
1691 Chain hostName = _pDBMng->getPrimary(tabSetId);
1692
1693 Chain dbHost;
1694 _pDBMng->getDBHost(dbHost);
1695
1696 if ( hostName == dbHost )
1697 {
1698 renameLocalObject(tabSetId, objName, type, newObjName);
1699 }
1700 else
1701 {
1702 Chain user;
1703 Chain password;
1704
1705 getActiveUser(tableSet, user, password);
1706
1707 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1708
1709 pSH->reqRenameOp(tableSet, objName, type, newObjName);
1710 _pDBMng->releaseSession(pSH);
1711 }
1712 }
1713
renameLocalObject(int tabSetId,const Chain & objName,CegoObject::ObjectType type,const Chain & newObjName)1714 void CegoDistManager::renameLocalObject(int tabSetId, const Chain& objName, CegoObject::ObjectType type, const Chain& newObjName)
1715 {
1716 _pDBMng->removeObject(tabSetId, objName, type);
1717 renameObject(tabSetId, objName, type, newObjName);
1718 _pDBMng->addObject(tabSetId, newObjName, type);
1719 }
1720
createDistView(const Chain & tableSet,const Chain & viewName,const ListT<CegoField> & schema,const Chain & viewText)1721 void CegoDistManager::createDistView(const Chain& tableSet, const Chain& viewName, const ListT<CegoField>& schema, const Chain& viewText)
1722 {
1723 #ifdef CGDEBUG
1724 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global view ") + viewName + Chain(" in tableset ") + tableSet);
1725 #endif
1726
1727 int tabSetId = _pDBMng->getTabSetId(tableSet);
1728
1729 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, viewName, CegoObject::VIEW, CegoXMLSpace::MODIFY, _authUser) == false )
1730 {
1731 Chain msg = Chain("Access not allowed for object ") + viewName;
1732 throw Exception(EXLOC, msg);
1733 }
1734
1735 Chain hostName =_pDBMng->getPrimary(tabSetId);
1736
1737 Chain dbHost;
1738 _pDBMng->getDBHost(dbHost);
1739
1740 if ( hostName == dbHost )
1741 {
1742 createLocalView(tabSetId, viewName, schema, viewText);
1743 }
1744 else
1745 {
1746 Chain user;
1747 Chain password;
1748
1749 getActiveUser(tableSet, user, password);
1750
1751 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1752
1753 pSH->reqCreateViewOp(tableSet, viewName, schema, viewText);
1754 _pDBMng->releaseSession(pSH);
1755 }
1756 }
1757
createLocalView(int tabSetId,const Chain & viewName,const ListT<CegoField> & schema,const Chain & viewText)1758 void CegoDistManager::createLocalView( int tabSetId, const Chain& viewName, const ListT<CegoField>& schema, const Chain& viewText)
1759 {
1760 CegoViewObject vo( tabSetId, viewName, schema, viewText);
1761
1762 CegoLogRecord lr;
1763 lr.setLSN(_pDBMng->nextLSN(tabSetId));
1764
1765 createViewObject(vo);
1766
1767 // create log entry
1768 lr.setObjectInfo(vo.getName(), vo.getType());
1769 lr.setAction(CegoLogRecord::LOGREC_CREATE);
1770
1771 char *buf;
1772 buf = (char*)malloc(vo.getEntrySize());
1773 vo.encode(buf);
1774 lr.setData(buf);
1775 lr.setDataLen(vo.getEntrySize());
1776 // lr.setTID(0);
1777 _pDBMng->logIt(vo.getTabSetId(), lr, _pLockHandle);
1778 free(buf);
1779
1780 _pDBMng->addObject(tabSetId, viewName, CegoObject::VIEW);
1781 }
1782
createDistTrigger(const Chain & tableSet,const Chain & triggerName,bool isBefore,bool isOnInsert,bool isOnUpdate,bool isOnDelete,const Chain & tableName,const Chain & triggerText)1783 void CegoDistManager::createDistTrigger(const Chain& tableSet, const Chain& triggerName,
1784 bool isBefore, bool isOnInsert, bool isOnUpdate, bool isOnDelete,
1785 const Chain& tableName, const Chain& triggerText)
1786 {
1787 #ifdef CGDEBUG
1788 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global trigger ") + triggerName + Chain(" in tableset ") + tableSet);
1789 #endif
1790
1791 int tabSetId = _pDBMng->getTabSetId(tableSet);
1792
1793 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, triggerName, CegoObject::TRIGGER, CegoXMLSpace::MODIFY, _authUser) == false )
1794 {
1795 Chain msg = Chain("Access not allowed for object ") + triggerName;
1796 throw Exception(EXLOC, msg);
1797 }
1798
1799 Chain hostName = _pDBMng->getPrimary(tabSetId);
1800
1801 Chain dbHost;
1802 _pDBMng->getDBHost(dbHost);
1803
1804 if ( hostName == dbHost )
1805 {
1806 createLocalTrigger(tabSetId, triggerName, isBefore, isOnInsert, isOnUpdate, isOnDelete, tableName, triggerText);
1807 }
1808 else
1809 {
1810 Chain user;
1811 Chain password;
1812
1813 getActiveUser(tableSet, user, password);
1814
1815 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1816
1817 // TODO
1818 pSH->reqCreateTriggerOp(tableSet, triggerName, tableName, triggerText);
1819 _pDBMng->releaseSession(pSH);
1820 }
1821 }
1822
createLocalTrigger(int tabSetId,const Chain & triggerName,bool isBefore,bool isOnInsert,bool isOnUpdate,bool isOnDelete,const Chain & tableName,const Chain & triggerText)1823 void CegoDistManager::createLocalTrigger(int tabSetId, const Chain& triggerName,
1824 bool isBefore, bool isOnInsert, bool isOnUpdate, bool isOnDelete,
1825 const Chain& tableName, const Chain& triggerText)
1826 {
1827 createTrigger(tabSetId, triggerName, isBefore, isOnInsert, isOnUpdate, isOnDelete, tableName, triggerText);
1828
1829 _pDBMng->addObject(tabSetId, triggerName, CegoObject::TRIGGER);
1830 }
1831
createDistAlias(const Chain & tableSet,const Chain & aliasName,const Chain & tableName,const ListT<CegoAttrAlias> & aliasList)1832 void CegoDistManager::createDistAlias(const Chain& tableSet, const Chain& aliasName,
1833 const Chain& tableName, const ListT<CegoAttrAlias>& aliasList)
1834 {
1835
1836 #ifdef CGDEBUG
1837 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global alias ") + aliasName + Chain(" in tableset ") + tableSet);
1838 #endif
1839
1840 int tabSetId = _pDBMng->getTabSetId(tableSet);
1841
1842 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, aliasName, CegoObject::ALIAS, CegoXMLSpace::MODIFY, _authUser) == false )
1843 {
1844 Chain msg = Chain("Access not allowed for object ") + aliasName;
1845 throw Exception(EXLOC, msg);
1846 }
1847
1848 Chain hostName = _pDBMng->getPrimary(tabSetId);
1849
1850 Chain dbHost;
1851 _pDBMng->getDBHost(dbHost);
1852
1853 if ( hostName == dbHost )
1854 {
1855 createLocalAlias(tabSetId, aliasName, tableName, aliasList);
1856 }
1857 else
1858 {
1859 Chain user;
1860 Chain password;
1861
1862 getActiveUser(tableSet, user, password);
1863
1864 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1865
1866 // TODO
1867 // pSH->reqCreateAliasOp(tableSet, aliasName, tableName, aliasList);
1868 _pDBMng->releaseSession(pSH);
1869 }
1870 }
1871
1872
createLocalAlias(int tabSetId,const Chain & aliasName,const Chain & tableName,const ListT<CegoAttrAlias> & aliasList)1873 void CegoDistManager::createLocalAlias(int tabSetId, const Chain& aliasName,
1874 const Chain& tableName, const ListT<CegoAttrAlias>& aliasList)
1875 {
1876 createAlias(tabSetId, aliasName, tableName, aliasList);
1877 _pDBMng->addObject(tabSetId, aliasName, CegoObject::ALIAS);
1878 }
1879
createDistProc(const Chain & tableSet,const Chain & procName,const Chain & procText)1880 void CegoDistManager::createDistProc(const Chain& tableSet, const Chain& procName, const Chain& procText)
1881 {
1882 #ifdef CGDEBUG
1883 _pDBMng->log(_modId, Logger::DEBUG, Chain("Creating global procedure ") + procName + Chain(" in tableset ") + tableSet);
1884 #endif
1885
1886 int tabSetId = _pDBMng->getTabSetId(tableSet);
1887
1888 if ( _authEnabled == true && _pDBMng->verifyAccess(tabSetId, procName, CegoObject::PROCEDURE, CegoXMLSpace::MODIFY, _authUser) == false )
1889 {
1890 Chain msg = Chain("Access not allowed for object ") + procName;
1891 throw Exception(EXLOC, msg);
1892 }
1893
1894 Chain hostName = _pDBMng->getPrimary(tabSetId);
1895
1896 Chain dbHost;
1897 _pDBMng->getDBHost(dbHost);
1898
1899 if ( hostName == dbHost )
1900 {
1901 createLocalProc(tabSetId, procName, procText);
1902 }
1903 else
1904 {
1905 Chain user;
1906 Chain password;
1907
1908 getActiveUser(tableSet, user, password);
1909
1910 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1911
1912 pSH->reqCreateProcOp(tableSet, procName, procText);
1913 _pDBMng->releaseSession(pSH);
1914 }
1915 }
1916
createLocalProc(int tabSetId,const Chain & procName,const Chain & procText)1917 void CegoDistManager::createLocalProc(int tabSetId, const Chain& procName, const Chain& procText)
1918 {
1919 CegoProcObject po(tabSetId, procName, procText);
1920
1921 CegoLogRecord lr;
1922 lr.setLSN(_pDBMng->nextLSN(tabSetId));
1923
1924 createProcObject(po);
1925
1926 // create log entry
1927
1928 lr.setObjectInfo(po.getName(), po.getType());
1929 lr.setAction(CegoLogRecord::LOGREC_CREATE);
1930
1931 char *buf;
1932 buf = (char*)malloc(po.getEntrySize());
1933 po.encode(buf);
1934 lr.setData(buf);
1935 lr.setDataLen(po.getEntrySize());
1936 // lr.setTID(0);
1937 _pDBMng->logIt(po.getTabSetId(), lr, _pLockHandle);
1938 free(buf);
1939
1940 _pDBMng->addObject(tabSetId,procName, CegoObject::PROCEDURE);
1941 }
1942
getDistObjectList(const Chain & tableSet,CegoObject::ObjectType type,ListT<Chain> & objList)1943 void CegoDistManager::getDistObjectList(const Chain& tableSet, CegoObject::ObjectType type, ListT<Chain> &objList)
1944 {
1945 #ifdef CGDEBUG
1946 _pDBMng->log(_modId, Logger::DEBUG, Chain("Getting global object list in tableset ") + tableSet);
1947 #endif
1948
1949 int tabSetId = _pDBMng->getTabSetId(tableSet);
1950 Chain hostName = _pDBMng->getPrimary(tabSetId);
1951
1952 Chain dbHost;
1953 _pDBMng->getDBHost(dbHost);
1954
1955 if ( hostName == dbHost )
1956 {
1957 getLocalObjectList(tabSetId, type, objList);
1958 }
1959 else
1960 {
1961 Chain user;
1962 Chain password;
1963
1964 getActiveUser(tableSet, user, password);
1965
1966 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
1967
1968 CegoDbHandler::ResultType res;
1969
1970 res = pSH->reqGetObjectListOp(tabSetId, type);
1971
1972 if ( res == CegoDbHandler::DB_INFO )
1973 {
1974 pSH->getObjectList(objList);
1975 _pDBMng->releaseSession(pSH);
1976 }
1977 else if ( res == CegoDbHandler::DB_ERROR )
1978 {
1979 Chain msg = pSH->getMsg();
1980 _pDBMng->releaseSession(pSH);
1981 throw Exception(EXLOC, msg);
1982 }
1983 }
1984 }
1985
getLocalObjectList(int tabSetId,CegoObject::ObjectType type,ListT<Chain> & objList)1986 void CegoDistManager::getLocalObjectList(int tabSetId, CegoObject::ObjectType type, ListT<Chain> &objList)
1987 {
1988 getObjectList(tabSetId, type, objList);
1989 }
1990
getDistObjectByTableList(const Chain & tableSet,const Chain & tabName,ListT<CegoTableObject> & idxList,ListT<CegoBTreeObject> & btreeList,ListT<CegoKeyObject> & keyList,ListT<CegoCheckObject> & checkList,ListT<CegoTriggerObject> & triggerList,ListT<CegoAliasObject> & aliasList,int & numInvalid)1991 void CegoDistManager::getDistObjectByTableList(const Chain& tableSet,
1992 const Chain& tabName,
1993 ListT<CegoTableObject>& idxList,
1994 ListT<CegoBTreeObject>& btreeList,
1995 ListT<CegoKeyObject>& keyList,
1996 ListT<CegoCheckObject>& checkList,
1997 ListT<CegoTriggerObject>& triggerList,
1998 ListT<CegoAliasObject>& aliasList,
1999 int& numInvalid)
2000 {
2001 #ifdef CGDEBUG
2002 _pDBMng->log(_modId, Logger::DEBUG, Chain("Getting global object list by table ") + tabName + Chain(" in tableset ") + tableSet);
2003 #endif
2004
2005 int tabSetId = _pDBMng->getTabSetId(tableSet);
2006 Chain hostName = _pDBMng->getPrimary(tabSetId);
2007
2008 Chain dbHost;
2009 _pDBMng->getDBHost(dbHost);
2010
2011 if ( hostName == dbHost )
2012 {
2013 getObjectListByTable(tabSetId, tabName, idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
2014 }
2015 else
2016 {
2017 Chain user;
2018 Chain password;
2019
2020 getActiveUser(tableSet, user, password);
2021
2022 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
2023
2024 CegoDbHandler::ResultType res;
2025
2026 res = pSH->reqGetObjectByTableListOp(tableSet, tabName);
2027
2028 if ( res == CegoDbHandler::DB_INFO )
2029 {
2030 // TODO btree retrievel still not implemented
2031 pSH->getObjectByTableList(idxList, keyList, checkList);
2032 _pDBMng->releaseSession(pSH);
2033
2034 }
2035 else if ( res == CegoDbHandler::DB_ERROR )
2036 {
2037 Chain msg = pSH->getMsg();
2038 _pDBMng->releaseSession(pSH);
2039 throw Exception(EXLOC, msg);
2040 }
2041 }
2042 }
2043
getDistPageCount(const Chain & tableSet,const Chain & tabName,CegoObject::ObjectType type)2044 int CegoDistManager::getDistPageCount(const Chain& tableSet, const Chain& tabName, CegoObject::ObjectType type)
2045 {
2046 int tabSetId = _pDBMng->getTabSetId(tableSet);
2047 Chain hostName = _pDBMng->getPrimary(tabSetId);
2048
2049 Chain dbHost;
2050 _pDBMng->getDBHost(dbHost);
2051
2052 if ( hostName == dbHost )
2053 {
2054 return getPageCount(tabSetId, tabName, type);
2055 }
2056 else
2057 {
2058 Chain user;
2059 Chain password;
2060
2061 getActiveUser(tableSet, user, password);
2062
2063 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
2064
2065 CegoDbHandler::ResultType res;
2066
2067 res = pSH->reqGetPageCount(tableSet, tabName, type);
2068
2069 int pageCount = 0;
2070
2071 if ( res == CegoDbHandler::DB_INFO )
2072 {
2073 pSH->getPageCount(pageCount);
2074 _pDBMng->releaseSession(pSH);
2075
2076 }
2077 else if ( res == CegoDbHandler::DB_ERROR )
2078 {
2079 Chain msg = pSH->getMsg();
2080 _pDBMng->releaseSession(pSH);
2081 throw Exception(EXLOC, msg);
2082 }
2083
2084 return pageCount;
2085 }
2086 }
2087
getLockHandle()2088 CegoLockHandler* CegoDistManager::getLockHandle()
2089 {
2090 return _pLockHandle;
2091 }
2092
syncDistTableSet(const Chain & tableSet,const Chain & msg,const Chain & escCmd,int timeout)2093 void CegoDistManager::syncDistTableSet(const Chain& tableSet, const Chain& msg, const Chain& escCmd, int timeout)
2094 {
2095 int tabSetId = _pDBMng->getTabSetId(tableSet);
2096 Chain hostName =_pDBMng->getPrimary(tabSetId);
2097
2098 Chain dbHost;
2099 _pDBMng->getDBHost(dbHost);
2100
2101 if ( hostName == dbHost )
2102 {
2103 syncTableSet(tableSet, msg, escCmd, timeout);
2104 }
2105 else
2106 {
2107 Chain user;
2108 Chain password;
2109
2110 getActiveUser(tableSet, user, password);
2111
2112 CegoDistDbHandler *pSH = _pDBMng->allocateSession(hostName, tableSet, user, password);
2113
2114 pSH->reqSyncOp(tableSet, escCmd, timeout);
2115 _pDBMng->releaseSession(pSH);
2116 }
2117 }
2118
enableAuth()2119 void CegoDistManager::enableAuth()
2120 {
2121 _authEnabled = true;
2122 }
2123
disableAuth()2124 void CegoDistManager::disableAuth()
2125 {
2126 _authEnabled = false;
2127 }
2128
setActiveUser(const Chain & tableSet,const Chain & user,const Chain & passwd)2129 void CegoDistManager::setActiveUser(const Chain& tableSet, const Chain& user, const Chain& passwd)
2130 {
2131 _authUser = user;
2132
2133 if ( _userList.Find(ActiveTSUser(tableSet)) == 0 )
2134 _userList.Insert( ActiveTSUser(tableSet, user, passwd));
2135 }
2136
getUser() const2137 const Chain& CegoDistManager::getUser() const
2138 {
2139 return _authUser;
2140 }
2141
getActiveUser(const Chain & tableSet,Chain & user,Chain & passwd)2142 void CegoDistManager::getActiveUser(const Chain& tableSet, Chain& user, Chain& passwd)
2143 {
2144 ActiveTSUser *pTSA = _userList.Find( ActiveTSUser(tableSet));
2145 if ( pTSA )
2146 {
2147 user = pTSA->getUserName();
2148 passwd = pTSA->getPasswd();
2149 return;
2150 }
2151
2152 Chain msg = Chain("No active user for tableset <") + tableSet + Chain(">");
2153 throw Exception(EXLOC, msg);
2154 }
2155
verifyTable(const Chain & tableSet,const Chain & tableName)2156 Element* CegoDistManager::verifyTable(const Chain& tableSet, const Chain& tableName)
2157 {
2158 _pDBMng->log(_modId, Logger::NOTICE, Chain("Verifying table ") + tableName + Chain(" ..."));
2159
2160 int tabSetId = _pDBMng->getTabSetId(tableSet);
2161
2162 Element *pVerification = new Element(XML_VERIFICATION_ELEMENT);
2163
2164 int errorCount = 0;
2165
2166 ListT<CegoTableObject> idxList;
2167 ListT<CegoBTreeObject> btreeList;
2168 ListT<CegoKeyObject> keyList;
2169 ListT<CegoCheckObject> checkList;
2170 ListT<CegoTriggerObject> triggerList;
2171 ListT<CegoAliasObject> aliasList;
2172 int numInvalid;
2173
2174 getObjectListByTable(tabSetId, tableName, idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
2175
2176 CegoTableObject oe;
2177 getObject(tabSetId, tableName, CegoObject::TABLE, oe);
2178
2179 CegoTableCursor tc(this, tabSetId, tableName);
2180 ListT<CegoField> fl = oe.getSchema();
2181 CegoDataPointer dp;
2182 long tabCount = 0;
2183
2184 if ( tc.getFirst(fl, dp) )
2185 {
2186 tabCount++;
2187 while ( tc.getNext(fl, dp) )
2188 {
2189 tabCount++;
2190 }
2191 }
2192
2193 // verify keys
2194 bool keyCheck = checkKey(tabSetId, tableName, oe.getSchema(), keyList);
2195
2196 if ( keyCheck == false )
2197 {
2198 errorCount++;
2199 Chain tableStatus = Chain("Key constraint violation");
2200 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2201 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2202 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2203 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2204 pVerification->addContent(pTableCheck);
2205 }
2206
2207 // verify indexes
2208 CegoTableObject *pIdx = idxList.First();
2209 while ( pIdx )
2210 {
2211 if ( pIdx->isValid() )
2212 {
2213 CegoAVLIndexManager idxMng(this);
2214 char c = idxMng.checkIndex(tabSetId, pIdx->getName(), pIdx->getType());
2215
2216 if ( c < 0 )
2217 {
2218 errorCount++;
2219 Chain tableStatus = Chain("Index ") + pIdx->getName() + Chain(" due to height corrupted ");
2220 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2221 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2222 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2223 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2224 pVerification->addContent(pTableCheck);
2225 }
2226
2227 CegoAVLIndexCursor ic(this, tabSetId, pIdx->getName(), pIdx->getType(), 0, false, false);
2228
2229 ListT<CegoField> fl = oe.getSchema();
2230 CegoDataPointer dp;
2231 long idxCount = 0;
2232 if ( ic.getFirst(fl, dp) )
2233 {
2234 idxCount++;
2235 while ( ic.getNext(fl, dp) )
2236 idxCount++;
2237 }
2238 if ( tabCount != idxCount )
2239 {
2240 errorCount++;
2241 Chain tableStatus = Chain("Index ") + pIdx->getName() + Chain(" row mismatch (") + Chain(tabCount) + Chain("/") + Chain(idxCount) + Chain(")");
2242 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2243 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2244 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2245 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2246 pVerification->addContent(pTableCheck);
2247 }
2248 }
2249 else
2250 {
2251 errorCount++;
2252 Chain tableStatus = Chain("Index ") + pIdx->getName() + Chain(" not valid");
2253 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2254 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2255 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2256 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2257 pVerification->addContent(pTableCheck);
2258 }
2259
2260 pIdx = idxList.Next();
2261 }
2262
2263 // verify btree objects
2264 CegoBTreeObject *pBTree = btreeList.First();
2265 while ( pBTree )
2266 {
2267 if ( pBTree->isValid() )
2268 {
2269
2270 CegoBTreeManager btreeMng(this, pBTree);
2271 if ( btreeMng.verifyBTree() == false )
2272 {
2273 errorCount++;
2274 Chain tableStatus = Chain("Btree ") + pBTree->getName() + Chain(" node corruption ");
2275 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2276 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2277 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2278 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2279 pVerification->addContent(pTableCheck);
2280 }
2281
2282 CegoBTreeCursor bc(this, tabSetId, pBTree->getName(), pBTree->getType(), 0, false, false);
2283
2284 ListT<CegoField> fl = oe.getSchema();
2285 CegoDataPointer dp;
2286 long btreeCount = 0;
2287 if ( bc.getFirst(fl, dp) )
2288 {
2289 btreeCount++;
2290 while ( bc.getNext(fl, dp) )
2291 btreeCount++;
2292 }
2293 if ( tabCount != btreeCount )
2294 {
2295 errorCount++;
2296 Chain tableStatus = Chain("Btree ") + pBTree->getName() + Chain(" row mismatch (") + Chain(tabCount) + Chain("/") + Chain(btreeCount) + Chain(")");
2297 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2298 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2299 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2300 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2301 pVerification->addContent(pTableCheck);
2302 }
2303 }
2304 else
2305 {
2306 errorCount++;
2307 Chain tableStatus = Chain("Btree ") + pIdx->getName() + Chain(" not valid");
2308 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2309 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2310 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2311 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2312 pVerification->addContent(pTableCheck);
2313 }
2314 pBTree = btreeList.Next();
2315 }
2316
2317 if ( errorCount == 0 )
2318 {
2319 Chain tableStatus("ok");
2320 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2321 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2322 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2323 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2324 pVerification->addContent(pTableCheck);
2325 }
2326 return pVerification;
2327 }
2328
verifyView(const Chain & tableSet,const Chain & viewName)2329 Element* CegoDistManager::verifyView(const Chain& tableSet, const Chain& viewName)
2330 {
2331 int tabSetId = _pDBMng->getTabSetId(tableSet);
2332 Element *pVerification = new Element(XML_VERIFICATION_ELEMENT);
2333
2334 CegoViewObject vo;
2335 getObject(tabSetId, viewName, CegoObject::VIEW, vo);
2336
2337 Chain loadString = Chain("load ") + vo.getViewStmt();
2338
2339 CegoAction *pPA = getParser();
2340 pPA->cleanUp();
2341 pPA->setTableSet(tableSet);
2342 pPA->setCommandChain(loadString);
2343 pPA->parse();
2344
2345
2346 Chain viewStatus("ok");
2347 Element *pViewCheck = new Element(XML_CHECK_ELEMENT);
2348 pViewCheck->setAttribute(XML_TYPE_ATTR, Chain("View"));
2349 pViewCheck->setAttribute(XML_NAME_ATTR, viewName);
2350 pViewCheck->setAttribute(XML_VALUE_ATTR, viewStatus);
2351 pVerification->addContent(pViewCheck);
2352
2353 return pVerification;
2354 }
2355
verifyProcedure(const Chain & tableSet,const Chain & procName)2356 Element* CegoDistManager::verifyProcedure(const Chain& tableSet, const Chain& procName)
2357 {
2358 int tabSetId = _pDBMng->getTabSetId(tableSet);
2359 Element *pVerification = new Element(XML_VERIFICATION_ELEMENT);
2360
2361 CegoProcObject po;
2362 getObject(tabSetId, procName, CegoObject::PROCEDURE, po);
2363
2364 Chain loadString = Chain("load ") + po.getProcText();
2365
2366 CegoAction *pPA = getParser();
2367 pPA->cleanUp();
2368 pPA->setTableSet(tableSet);
2369 pPA->setCommandChain(loadString);
2370 pPA->parse();
2371
2372 Chain procStatus("ok");
2373 Element *pProcCheck = new Element(XML_CHECK_ELEMENT);
2374 pProcCheck->setAttribute(XML_TYPE_ATTR, Chain("Procedure"));
2375 pProcCheck->setAttribute(XML_NAME_ATTR, procName);
2376 pProcCheck->setAttribute(XML_VALUE_ATTR, procStatus);
2377 pVerification->addContent(pProcCheck);
2378
2379 return pVerification;
2380 }
2381
correctTable(const Chain & tableSet,const Chain & tableName)2382 Element* CegoDistManager::correctTable(const Chain& tableSet, const Chain& tableName)
2383 {
2384 _pDBMng->log(_modId, Logger::NOTICE, Chain("Correcting table ") + tableName + Chain(" ..."));
2385
2386 int tabSetId = _pDBMng->getTabSetId(tableSet);
2387
2388 Element *pCorrection = new Element(XML_CORRECTION_ELEMENT);
2389
2390 int errorCount = 0;
2391
2392 ListT<CegoTableObject> idxList;
2393 ListT<CegoBTreeObject> btreeList;
2394 ListT<CegoKeyObject> keyList;
2395 ListT<CegoCheckObject> checkList;
2396 ListT<CegoTriggerObject> triggerList;
2397 ListT<CegoAliasObject> aliasList;
2398 int numInvalid;
2399
2400 getObjectListByTable(tabSetId, tableName, idxList, btreeList, keyList, checkList, triggerList, aliasList, numInvalid);
2401
2402 // correct indexes
2403 CegoTableObject *pIdx = idxList.First();
2404 while ( pIdx )
2405 {
2406 if ( pIdx->isValid() == false )
2407 {
2408 errorCount++;
2409
2410 dropIndex(tabSetId, pIdx->getName());
2411 bool isCached=false;
2412 createIndexTable(tabSetId, pIdx->getName(), pIdx->getTabName(), pIdx->getSchema(), pIdx->getType(), isCached);
2413
2414 Chain tableStatus = Chain("Index ") + pIdx->getName() + Chain(" was corrected");
2415 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2416 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2417 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2418 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2419 pCorrection->addContent(pTableCheck);
2420 }
2421
2422 pIdx = idxList.Next();
2423 }
2424
2425 // correct btrees
2426 CegoBTreeObject *pBTree = btreeList.First();
2427 while ( pBTree )
2428 {
2429 if ( pBTree->isValid() == false )
2430 {
2431 errorCount++;
2432
2433 dropBTree(tabSetId, pBTree->getName());
2434 bool doSync=false;
2435 bool isCached=false;
2436 createBTree(tabSetId, pBTree->getName(), pBTree->getTabName(), pBTree->getSchema(), pBTree->getType(), doSync, isCached);
2437
2438 Chain tableStatus = Chain("Btree ") + pBTree->getName() + Chain(" was corrected");
2439 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2440 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2441 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2442 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2443 pCorrection->addContent(pTableCheck);
2444 }
2445 pBTree = btreeList.Next();
2446 }
2447
2448 if ( errorCount == 0 )
2449 {
2450 Chain tableStatus("ok");
2451 Element *pTableCheck = new Element(XML_CHECK_ELEMENT);
2452 pTableCheck->setAttribute(XML_TYPE_ATTR, Chain("Table"));
2453 pTableCheck->setAttribute(XML_NAME_ATTR, tableName);
2454 pTableCheck->setAttribute(XML_VALUE_ATTR, tableStatus);
2455 pCorrection->addContent(pTableCheck);
2456 }
2457
2458 return pCorrection;
2459 }
2460
checkKey(int tabSetId,const Chain & tableName,const ListT<CegoField> & schema,const ListT<CegoKeyObject> & keyList)2461 bool CegoDistManager::checkKey(int tabSetId, const Chain& tableName, const ListT<CegoField>& schema, const ListT<CegoKeyObject>& keyList)
2462 {
2463 CegoKeyObject* pKey = keyList.First();
2464 while ( pKey )
2465 {
2466 if ( (Chain)pKey->getTabName() == (Chain)tableName )
2467 {
2468 CegoTableCursor ktc(this, tabSetId, pKey->getTabName());
2469
2470 CegoTableObject oe;
2471 getObject(tabSetId, pKey->getTabName(), CegoObject::TABLE, oe);
2472
2473 ListT<CegoField> kfl = oe.getSchema();
2474
2475 CegoDataPointer dp;
2476 bool moreTuple = ktc.getFirst(kfl, dp);
2477
2478 while ( moreTuple )
2479 {
2480 ListT<CegoField> rfl = pKey->getRefSchema();
2481 CegoField *pKF = kfl.First();
2482 CegoField* pRF = rfl.First();
2483 while ( pKF && pRF)
2484 {
2485 pRF->setValue(pKF->getValue());
2486 pKF = kfl.Next();
2487 pRF = rfl.Next();
2488 }
2489
2490 CegoAttrCond ac;
2491 pRF = rfl.First();
2492 while ( pRF )
2493 {
2494 // cout << "Searching for " << pRF->getTableName() << "." << pRF->getAttrName() << " = " << pRF->getValue() << endl;
2495 ac.add(CegoAttrComp(pRF->getTableName(), pRF->getAttrName(), EQUAL, pRF->getValue()));
2496 pRF = rfl.Next();
2497 }
2498
2499 CegoTableCursor rtc(this, tabSetId, pKey->getRefTable());
2500 // no need for indexMatch value : CegoAttrCond::IndexMatch indexMatch = rtc.setup(ac);
2501 rtc.setup(ac);
2502
2503 if ( rtc.getFirst(rfl, dp) == false )
2504 return false;
2505
2506 moreTuple = ktc.getNext(kfl, dp);
2507
2508 }
2509 }
2510 pKey = keyList.Next();
2511 }
2512 return true;
2513 }
2514
getObjectDesc(const Chain & tableSet,const Chain & objName,CegoObject::ObjectType type,ListT<CegoField> & schema,ListT<ListT<CegoFieldValue>> & fa)2515 void CegoDistManager::getObjectDesc(const Chain& tableSet, const Chain& objName, CegoObject::ObjectType type,
2516 ListT<CegoField>& schema, ListT< ListT<CegoFieldValue> > &fa)
2517 {
2518 switch ( type )
2519 {
2520 case CegoObject::SYSTEM:
2521 case CegoObject::TABLE:
2522 {
2523 CegoTableObject to;
2524
2525 getDistObject(tableSet, objName, type, to);
2526
2527 int maxAttrLen=10;
2528 CegoField *pF = to.getSchema().First();
2529 while ( pF )
2530 {
2531 if ( pF->getAttrName().length() > maxAttrLen )
2532 maxAttrLen = pF->getAttrName().length();
2533 pF = to.getSchema().Next();
2534 }
2535
2536 schema.Insert(CegoField(Chain("TABLEDESC"), Chain("TABLEDESC"), Chain("ATTR"), VARCHAR_TYPE, maxAttrLen));
2537 schema.Insert(CegoField(Chain("TABLEDESC"), Chain("TABLEDESC"), Chain("TYPE"), VARCHAR_TYPE, 10));
2538 schema.Insert(CegoField(Chain("TABLEDESC"), Chain("TABLEDESC"), Chain("LENGTH"), VARCHAR_TYPE, 10));
2539 schema.Insert(CegoField(Chain("TABLEDESC"), Chain("TABLEDESC"), Chain("DIM"), VARCHAR_TYPE, 10));
2540 schema.Insert(CegoField(Chain("TABLEDESC"), Chain("TABLEDESC"), Chain("DEFAULT"), VARCHAR_TYPE, 10));
2541 schema.Insert(CegoField(Chain("TABLEDESC"), Chain("TABLEDESC"), Chain("NULLABLE"), VARCHAR_TYPE, 10));
2542
2543 pF = to.getSchema().First();
2544 while ( pF )
2545 {
2546 ListT<CegoFieldValue> fvl;
2547
2548 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pF->getAttrName()));
2549 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, CegoTypeConverter::getTypeString(pF->getType())));
2550 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain(pF->getLength())));
2551 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain(pF->getDim())));
2552
2553 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pF->getValue().valAsChain(false)));
2554
2555 if ( pF->isNullable() )
2556 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("yes")));
2557 else
2558 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("no")));
2559
2560 fa.Insert(fvl);
2561
2562 pF = to.getSchema().Next();
2563 }
2564 break;
2565 }
2566 case CegoObject::AVLTREE:
2567 case CegoObject::UAVLTREE:
2568 case CegoObject::PAVLTREE:
2569 {
2570 CegoTableObject io;
2571 getDistObject(tableSet, objName, type, io);
2572
2573 int maxAttrLen=10;
2574 CegoField *pF = io.getSchema().First();
2575 while ( pF )
2576 {
2577 if ( pF->getAttrName().length() > maxAttrLen )
2578 maxAttrLen = pF->getAttrName().length();
2579 pF = io.getSchema().Next();
2580 }
2581
2582 int maxTabLen=10;
2583 if ( io.getTabName().length() > maxTabLen )
2584 maxTabLen = io.getTabName().length();
2585
2586 schema.Insert(CegoField(Chain("INDEXDESC"), Chain("TABLEDESC"), Chain("ATTR"), VARCHAR_TYPE, maxAttrLen));
2587 schema.Insert(CegoField(Chain("INDEXDESC"), Chain("TABLEDESC"), Chain("TABLE"), VARCHAR_TYPE, maxTabLen));
2588 schema.Insert(CegoField(Chain("INDEXDESC"), Chain("TABLEDESC"), Chain("TYPE"), VARCHAR_TYPE, 10));
2589
2590 pF = io.getSchema().First();
2591 while ( pF )
2592 {
2593 ListT<CegoFieldValue> fvl;
2594
2595 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pF->getAttrName()));
2596 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, io.getTabName()));
2597
2598 if ( io.getType() == CegoObject::AVLTREE)
2599 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, XML_INDEX_VALUE));
2600 else if ( io.getType() == CegoObject::PAVLTREE)
2601 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, XML_PINDEX_VALUE));
2602 else if ( io.getType() == CegoObject::UAVLTREE)
2603 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, XML_UINDEX_VALUE));
2604
2605 fa.Insert(fvl);
2606
2607 pF = io.getSchema().Next();
2608 }
2609 break;
2610 }
2611 case CegoObject::BTREE:
2612 case CegoObject::UBTREE:
2613 case CegoObject::PBTREE:
2614 {
2615 CegoBTreeObject bto;
2616 getDistObject(tableSet, objName, type, bto);
2617
2618 int maxAttrLen=10;
2619 CegoField *pF = bto.getSchema().First();
2620 while ( pF )
2621 {
2622 if ( pF->getAttrName().length() > maxAttrLen )
2623 maxAttrLen = pF->getAttrName().length();
2624 pF = bto.getSchema().Next();
2625 }
2626
2627 int maxTabLen=10;
2628 if ( bto.getTabName().length() > maxTabLen )
2629 maxTabLen = bto.getTabName().length();
2630
2631 schema.Insert(CegoField(Chain("BTREEDESC"), Chain("TABLEDESC"), Chain("ATTR"), VARCHAR_TYPE, maxAttrLen));
2632 schema.Insert(CegoField(Chain("BTREEDESC"), Chain("TABLEDESC"), Chain("TABLE"), VARCHAR_TYPE, maxTabLen));
2633 schema.Insert(CegoField(Chain("BTREEDESC"), Chain("TABLEDESC"), Chain("TYPE"), VARCHAR_TYPE, 10));
2634
2635 pF = bto.getSchema().First();
2636 while ( pF )
2637 {
2638 ListT<CegoFieldValue> fvl;
2639
2640 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pF->getAttrName()));
2641 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, bto.getTabName()));
2642
2643 if ( bto.getType() == CegoObject::BTREE)
2644 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, XML_BTREE_VALUE));
2645 else if ( bto.getType() == CegoObject::PBTREE)
2646 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, XML_PBTREE_VALUE));
2647 else if ( bto.getType() == CegoObject::UBTREE)
2648 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, XML_UBTREE_VALUE));
2649
2650 fa.Insert(fvl);
2651
2652 pF = bto.getSchema().Next();
2653 }
2654 break;
2655 }
2656 case CegoObject::VIEW:
2657 {
2658 CegoViewObject vo;
2659 getDistObject(tableSet, objName, type, vo);
2660
2661 int maxAttrLen=10;
2662 CegoField *pF = vo.getSchema().First();
2663 while ( pF )
2664 {
2665 if ( pF->getAttrName().length() > maxAttrLen )
2666 maxAttrLen = pF->getAttrName().length();
2667 pF = vo.getSchema().Next();
2668 }
2669
2670 schema.Insert(CegoField(Chain("VIEWDESC"), Chain("VIEWDESC"), Chain("ATTR"), VARCHAR_TYPE, maxAttrLen));
2671 schema.Insert(CegoField(Chain("VIEWDESC"), Chain("VIEWDESC"), Chain("TYPE"), VARCHAR_TYPE, 10));
2672 schema.Insert(CegoField(Chain("VIEWDESC"), Chain("VIEWDESC"), Chain("LENGTH"), VARCHAR_TYPE, 10));
2673 schema.Insert(CegoField(Chain("VIEWDESC"), Chain("VIEWDESC"), Chain("DIM"), VARCHAR_TYPE, 10));
2674
2675 pF = vo.getSchema().First();
2676 while ( pF )
2677 {
2678 ListT<CegoFieldValue> fvl;
2679
2680 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pF->getAttrName()));
2681 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, CegoTypeConverter::getTypeString(pF->getType())));
2682 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain(pF->getLength())));
2683 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain(pF->getDim())));
2684
2685 fa.Insert(fvl);
2686
2687 pF = vo.getSchema().Next();
2688 }
2689 break;
2690 }
2691 case CegoObject::PROCEDURE:
2692 {
2693 int tabSetId = getDBMng()->getTabSetId(tableSet);
2694
2695 if ( checkCompProcedure(tabSetId, objName) == false )
2696 reloadProcedure( tabSetId, objName );
2697
2698 CegoProcedure* pProc = getCompProcedure(tabSetId, objName);
2699
2700 ListT<CegoProcVar> argList;
2701 pProc->getArgList(argList);
2702
2703 int maxAttrLen=10;
2704 CegoProcVar *pArg = argList.First();
2705 while ( pArg )
2706 {
2707 if ( pArg->getName().length() > maxAttrLen )
2708 maxAttrLen = pArg->getName().length();
2709 pArg = argList.Next();
2710 }
2711
2712 schema.Insert(CegoField(Chain("PROCDESC"), Chain("PROCDESC"), Chain("ATTR"), VARCHAR_TYPE, maxAttrLen));
2713 schema.Insert(CegoField(Chain("PROCDESC"), Chain("PROCDESC"), Chain("TYPE"), VARCHAR_TYPE, 10));
2714 schema.Insert(CegoField(Chain("PROCDESC"), Chain("PROCDESC"), Chain("LENGTH"), VARCHAR_TYPE, 10));
2715 schema.Insert(CegoField(Chain("PROCDESC"), Chain("PROCDESC"), Chain("DIM"), VARCHAR_TYPE, 10));
2716 schema.Insert(CegoField(Chain("PROCDESC"), Chain("PROCDESC"), Chain("INOUT"), VARCHAR_TYPE, 10));
2717
2718 pArg = argList.First();
2719 while ( pArg )
2720 {
2721 ListT<CegoFieldValue> fvl;
2722
2723 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pArg->getName()));
2724 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, CegoTypeConverter::getTypeString(pArg->getType())));
2725 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain(pArg->getLength())));
2726 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain(pArg->getDim())));
2727
2728 if ( pArg->getVarType() == CegoProcVar::INVAR )
2729 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("in")));
2730 else if ( pArg->getVarType() == CegoProcVar::OUTVAR )
2731 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("out")));
2732 else
2733 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("n/a")));
2734
2735 fa.Insert(fvl);
2736
2737 pArg = argList.Next();
2738
2739 }
2740 break;
2741 }
2742 case CegoObject::FKEY:
2743 {
2744 CegoKeyObject ko;
2745 getDistObject(tableSet, objName, type, ko);
2746
2747 int maxTabLen=10;
2748 if ( objName.length() > maxTabLen )
2749 maxTabLen = objName.length();
2750
2751 int maxAttrLen=10;
2752 CegoField *pK = ko.getKeySchema().First();
2753 while ( pK )
2754 {
2755 if ( pK->getAttrName().length() > maxAttrLen )
2756 maxAttrLen = pK->getAttrName().length();
2757
2758 pK = ko.getKeySchema().Next();
2759 }
2760 CegoField *pR = ko.getRefSchema().First();
2761 while ( pR )
2762 {
2763 if ( pR->getAttrName().length() > maxAttrLen )
2764 maxAttrLen = pR->getAttrName().length();
2765 pR = ko.getRefSchema().Next();
2766 }
2767
2768 schema.Insert(CegoField(Chain("KEYDESC"), Chain("KEYDESC"), Chain("TABLE"), VARCHAR_TYPE, maxTabLen));
2769 schema.Insert(CegoField(Chain("KEYDESC"), Chain("KEYDESC"), Chain("ATTR"), VARCHAR_TYPE, maxAttrLen));
2770 schema.Insert(CegoField(Chain("KEYDESC"), Chain("KEYDESC"), Chain("TYPE"), VARCHAR_TYPE, 10));
2771
2772 pK = ko.getKeySchema().First();
2773 while ( pK )
2774 {
2775 ListT<CegoFieldValue> fvl;
2776
2777 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, ko.getTabName()));
2778 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pK->getAttrName()));
2779 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("key")));
2780
2781 fa.Insert(fvl);
2782
2783 pK = ko.getKeySchema().Next();
2784 }
2785 pR = ko.getRefSchema().First();
2786 while ( pR )
2787 {
2788 ListT<CegoFieldValue> fvl;
2789
2790 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, ko.getRefTable()));
2791 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pR->getAttrName()));
2792 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, Chain("reference")));
2793
2794 fa.Insert(fvl);
2795
2796 pR = ko.getRefSchema().Next();
2797 }
2798 break;
2799 }
2800 case CegoObject::CHECK:
2801 {
2802 CegoCheckObject co;
2803 getDistObject(tableSet, objName, type, co);
2804
2805 int maxTabLen=10;
2806 if ( objName.length() > maxTabLen )
2807 maxTabLen = objName.length();
2808
2809 int maxCheckLen=30;
2810 schema.Insert(CegoField(Chain("CHECKDESC"), Chain("CHECKDESC"), Chain("TABLE"), VARCHAR_TYPE, maxTabLen));
2811 schema.Insert(CegoField(Chain("CHECKDESC"), Chain("CHECKDESC"), Chain("CONDITION"), VARCHAR_TYPE, maxCheckLen));
2812
2813 ListT<CegoFieldValue> fvl;
2814
2815 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, co.getTabName()));
2816 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, co.getPredDesc()->toChain()));
2817
2818 fa.Insert(fvl);
2819
2820 break;
2821 }
2822 case CegoObject::TRIGGER:
2823 {
2824 CegoTriggerObject to;
2825 getDistObject(tableSet, objName, type, to);
2826
2827 int maxTabLen=10;
2828 if ( objName.length() > maxTabLen )
2829 maxTabLen = objName.length();
2830
2831 int maxCheckLen=30;
2832 schema.Insert(CegoField(Chain("TRIGGERDESC"), Chain("TRIGGERDESC"), Chain("TABLE"), VARCHAR_TYPE, maxTabLen));
2833 schema.Insert(CegoField(Chain("TRIGGERDESC"), Chain("TRIGGERDESC"), Chain("TRIGGERTEXT"), VARCHAR_TYPE, maxCheckLen));
2834
2835 ListT<CegoFieldValue> fvl;
2836
2837 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, to.getTabName()));
2838 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, to.getTriggerText()));
2839
2840 fa.Insert(fvl);
2841
2842 break;
2843
2844 }
2845 case CegoObject::ALIAS:
2846 {
2847 CegoAliasObject ao;
2848 getDistObject(tableSet, objName, type, ao);
2849
2850 int maxTabLen=10;
2851 if ( objName.length() > maxTabLen )
2852 maxTabLen = objName.length();
2853
2854 int maxAliasLen=30;
2855 schema.Insert(CegoField(Chain("ALIASDESC"), Chain("ALIASDESC"), Chain("TABLE"), VARCHAR_TYPE, maxTabLen));
2856 schema.Insert(CegoField(Chain("ALIASDESC"), Chain("ALIASDESC"), Chain("ATTRIBUTE"), VARCHAR_TYPE, maxAliasLen));
2857 schema.Insert(CegoField(Chain("ALIASDESC"), Chain("ALIASDESC"), Chain("ALIAS"), VARCHAR_TYPE, maxAliasLen));
2858
2859 CegoAttrAlias *pAlias = ao.getAliasList().First();
2860 while ( pAlias )
2861 {
2862 ListT<CegoFieldValue> fvl;
2863 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, ao.getTabName()));
2864 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pAlias->getAttrName()));
2865 fvl.Insert(CegoFieldValue(VARCHAR_TYPE, pAlias->getAliasName()));
2866 fa.Insert(fvl);
2867 pAlias = ao.getAliasList().Next();
2868 }
2869
2870 break;
2871
2872 }
2873
2874 case CegoObject::RBSEG:
2875 case CegoObject::JOIN:
2876 case CegoObject::UNDEFINED:
2877 {
2878 throw Exception(EXLOC, Chain("Cannot get description for object type"));
2879 }
2880 }
2881 }
2882
getView(int tabSetId,const Chain & viewName)2883 CegoView* CegoDistManager::getView(int tabSetId, const Chain& viewName)
2884 {
2885 if ( checkCompView(tabSetId, viewName) == false )
2886 reloadView( tabSetId, viewName );
2887 return getCompView(tabSetId, viewName );
2888 }
2889
reloadView(int tabSetId,const Chain & viewName)2890 void CegoDistManager::reloadView(int tabSetId, const Chain& viewName)
2891 {
2892 CegoViewObject vo;
2893 getObject(tabSetId, viewName, CegoObject::VIEW, vo);
2894
2895 Chain loadString = Chain("load ") + vo.getViewStmt();
2896
2897 // since this message is produced for each database thread, we avoid this
2898 // _pDBMng->log(_modId, Logger::NOTICE, Chain("View ") + viewName + Chain(" is reloaded"));
2899
2900 // since views can be nested, we have to use dedicated parser here
2901 CegoAction *pPA = new CegoAction(this);
2902
2903 try
2904 {
2905 Chain tableSet = _pDBMng->getTabSetName(tabSetId);
2906
2907 // pPA->cleanUp();
2908 pPA->setTableSet(tableSet);
2909 pPA->setCommandChain(loadString);
2910 pPA->parse();
2911 CegoSelect* pSelect = pPA->getSelect();
2912
2913 CegoView *pView = new CegoView(viewName, pSelect);
2914
2915 pSelect->setTabSetId(tabSetId);
2916
2917 pSelect->prepare();
2918
2919 ListT<CegoField> schema;
2920 pSelect->getSchema(schema);
2921
2922 addCompView(tabSetId, pView);
2923
2924 // if schema is zero, recompile is required
2925 if ( vo.getSchema().Size() == 0 )
2926 {
2927
2928 _pDBMng->log(_modId, Logger::NOTICE, Chain("View ") + viewName + Chain(" detected as invalid"));
2929
2930 dropView(tabSetId, viewName);
2931 Chain viewStmt = Chain("view ") + viewName + Chain(" as\n") + pSelect->toChain() + Chain(";");
2932 createLocalView( tabSetId, viewName, schema, viewStmt);
2933
2934 _pDBMng->log(_modId, Logger::NOTICE, Chain("View ") + viewName + Chain(" validated sucessful"));
2935
2936 }
2937 }
2938 catch ( Exception e )
2939 {
2940 if ( pPA )
2941 delete pPA;
2942
2943 Chain msg = Chain("Cannot load view ") + viewName;
2944 throw Exception(EXLOC, msg, e);
2945 }
2946
2947 delete pPA;
2948 }
2949
2950
getTrigger(int tabSetId,const Chain & triggerName)2951 CegoTrigger* CegoDistManager::getTrigger(int tabSetId, const Chain& triggerName)
2952 {
2953 if ( checkCompTrigger(tabSetId, triggerName) == false )
2954 reloadTrigger( tabSetId, triggerName );
2955
2956 return getCompTrigger(tabSetId, triggerName );
2957 }
2958
reloadTrigger(int tabSetId,const Chain & triggerName)2959 void CegoDistManager::reloadTrigger(int tabSetId, const Chain& triggerName)
2960 {
2961
2962 CegoTriggerObject to;
2963 getObject(tabSetId, triggerName, CegoObject::TRIGGER, to);
2964
2965 Chain loadString = Chain("load ") + to.toChain() + Chain(";");
2966
2967 // since this message is produced for each database thread, we avoid this
2968 // _pDBMng->log(_modId, Logger::NOTICE, Chain("Trigger ") + triggerName + Chain(" is reloaded"));
2969
2970 CegoAction *pPA = new CegoAction(this);
2971
2972 try
2973 {
2974 Chain tableSet = _pDBMng->getTabSetName(tabSetId);
2975 pPA->setTableSet(tableSet);
2976 pPA->setCommandChain(loadString);
2977 pPA->parse();
2978
2979 CegoTrigger* pTrigger = pPA->getTrigger();
2980
2981 addCompTrigger(tabSetId, pTrigger);
2982 }
2983 catch ( Exception e )
2984 {
2985 if ( pPA )
2986 delete pPA;
2987
2988 Chain msg = Chain("Cannot load trigger ") + triggerName;
2989 throw Exception(EXLOC, msg, e);
2990 }
2991
2992 delete pPA;
2993 }
2994
getProcedure(int tabSetId,const Chain & procName)2995 CegoProcedure* CegoDistManager::getProcedure(int tabSetId, const Chain& procName)
2996 {
2997 if ( checkCompProcedure(tabSetId, procName) == false )
2998 reloadProcedure( tabSetId, procName );
2999 return getCompProcedure(tabSetId, procName );
3000 }
3001
getParser()3002 CegoAction* CegoDistManager::getParser()
3003 {
3004 if ( _pPA == 0 )
3005 _pPA = new CegoAction(this);
3006 return _pPA;
3007 }
3008
reloadProcedure(int tabSetId,const Chain & procName)3009 void CegoDistManager::reloadProcedure(int tabSetId, const Chain& procName)
3010 {
3011 CegoProcObject po;
3012 getObject(tabSetId, procName, CegoObject::PROCEDURE, po);
3013
3014 Chain loadString = Chain("load ") + po.getProcText();
3015
3016 // since this message is produced for each database thread, we avoid this
3017 // _pDBMng->log(_modId, Logger::NOTICE, Chain("Procedure ") + procName + Chain(" is reloaded"));
3018
3019 // since procedures can be nested, we have to use dedicated parser here
3020 CegoAction *pPA = new CegoAction(this);
3021
3022 try
3023 {
3024 Chain tableSet = _pDBMng->getTabSetName(tabSetId);
3025 pPA->setTableSet(tableSet);
3026 pPA->setCommandChain(loadString);
3027 pPA->parse();
3028
3029 CegoProcedure* pProc = pPA->getProcedure();
3030
3031 addCompProcedure(tabSetId, pProc);
3032 }
3033 catch ( Exception e )
3034 {
3035 if ( pPA )
3036 delete pPA;
3037
3038 Chain msg = Chain("Cannot load procedure ") + procName;
3039 throw Exception(EXLOC, msg, e);
3040 }
3041
3042 delete pPA;
3043 }
3044