1 #include "otsdaq-core/TableCore/TableBase.h"
6 #include "otsdaq-core/TableCore/TableInfoReader.h"
11 #define __MF_SUBJECT__ "TableBase-" + getTableName()
19 TableBase::TableBase(std::string tableName,
20 std::string* accumulatedExceptions)
21 : MAX_VIEWS_IN_CACHE(20)
23 , tableName_(tableName)
30 std::string returnedExceptions = tableInfoReader.read(
this);
32 if(returnedExceptions !=
"")
33 __COUT_ERR__ << returnedExceptions << __E__;
35 if(accumulatedExceptions)
36 *accumulatedExceptions += std::string(
"\n") + returnedExceptions;
40 __SS__ <<
"Failure in tableInfoReader.read(this). "
41 <<
"Perhaps you need to run otsdaq_convert_config_to_table ?" << __E__;
42 __COUT_ERR__ <<
"\n" << ss.str();
43 if(accumulatedExceptions)
44 *accumulatedExceptions += std::string(
"\n") + ss.str();
53 getMockupViewP()->init();
55 catch(std::runtime_error&
58 if(accumulatedExceptions)
59 *accumulatedExceptions += std::string(
"\n") + e.what();
69 TableBase::TableBase(
void)
70 : MAX_VIEWS_IN_CACHE(1)
78 TableBase::~TableBase(
void) {}
81 std::string TableBase::getTypeId() {
return typeid(
this).name(); }
90 void TableBase::reset(
bool keepTemporaryVersions)
94 if(keepTemporaryVersions)
101 void TableBase::print(std::ostream& out)
const
105 if(!activeTableView_)
107 __COUT_ERR__ <<
"ERROR: No active view set" << __E__;
110 activeTableView_->print(out);
118 if(!isStored(version))
120 tableViews_[version].copy(
121 mockupTableView_, version, mockupTableView_.getAuthor());
123 if(!isStored(version))
125 __SS__ <<
"\nsetupMockupView() IMPOSSIBLE ERROR: trimCache() is deleting the "
126 "latest view version "
127 << version <<
"!" << __E__;
128 __COUT_ERR__ <<
"\n" << ss.str();
134 __SS__ <<
"\nsetupMockupView() ERROR: View to fill with mockup already exists: "
135 << version <<
". Cannot overwrite!" << __E__;
136 __COUT_ERR__ <<
"\n" << ss.str();
146 void TableBase::trimCache(
unsigned int trimSize)
150 if(trimSize == (
unsigned int)-1)
151 trimSize = MAX_VIEWS_IN_CACHE;
154 while(getNumberOfStoredViews() > trimSize)
157 time_t stalestTime = -1;
159 for(
auto& viewPair : tableViews_)
160 if(!viewPair.first.isTemporaryVersion())
162 if(stalestTime == -1 || viewPair.second.getLastAccessTime() < stalestTime)
164 versionToDelete = viewPair.first;
165 stalestTime = viewPair.second.getLastAccessTime();
171 if(versionToDelete.isInvalid())
173 __SS__ <<
"Can NOT have a stored view with an invalid version!";
177 eraseView(versionToDelete);
186 void TableBase::trimTemporary(
TableVersion targetVersion)
188 if(targetVersion.isInvalid())
190 for(
auto it = tableViews_.begin(); it != tableViews_.end(); )
192 if(it->first.isTemporaryVersion())
194 __COUT__ <<
"Trimming temporary version: " << it->first << __E__;
195 if(activeTableView_ &&
196 getViewVersion() == it->first)
199 tableViews_.erase(it++);
205 else if(targetVersion.isTemporaryVersion())
207 __COUT__ <<
"Trimming temporary version: " << targetVersion << __E__;
208 eraseView(targetVersion);
213 __SS__ <<
"Temporary trim target was a persistent version: " << targetVersion
215 __COUT_ERR__ <<
"\n" << ss.str();
232 auto needleIt = tableViews_.find(needleVersion);
233 if(needleIt == tableViews_.end())
236 __SS__ <<
"needleVersion does not exist: " << needleVersion << __E__;
237 __COUT_ERR__ <<
"\n" << ss.str();
241 const TableView* needleView = &(needleIt->second);
242 unsigned int rows = needleView->getNumberOfRows();
243 unsigned int cols = needleView->getNumberOfColumns();
246 unsigned int potentialMatchCount = 0;
252 auto viewPairReverseIterator = tableViews_.rbegin();
253 for(; viewPairReverseIterator != tableViews_.rend(); ++viewPairReverseIterator)
255 if(viewPairReverseIterator->first == needleVersion)
257 if(viewPairReverseIterator->first == ignoreVersion)
259 if(viewPairReverseIterator->first.isTemporaryVersion())
262 if(viewPairReverseIterator->second.getNumberOfRows() != rows)
265 if(viewPairReverseIterator->second.getDataColumnSize() != cols ||
266 viewPairReverseIterator->second.getSourceColumnMismatch() != 0)
269 ++potentialMatchCount;
270 __COUT__ <<
"Checking version... " << viewPairReverseIterator->first << __E__;
280 match = viewPairReverseIterator->second.getSourceColumnNames().size() ==
281 needleView->getSourceColumnNames().size();
284 for(
auto& haystackColName :
285 viewPairReverseIterator->second.getSourceColumnNames())
286 if(needleView->getSourceColumnNames().find(haystackColName) ==
287 needleView->getSourceColumnNames().end())
289 __COUT__ <<
"Found column name mismach for '" << haystackColName
290 <<
"'... So allowing same data!" << __E__;
312 for(
unsigned int row = 0; match && row < rows; ++row)
314 for(
unsigned int col = 0; col < cols - 2;
316 if(viewPairReverseIterator->second.getDataView()[row][col] !=
317 needleView->getDataView()[row][col])
340 __COUT_INFO__ <<
"Duplicate version found: " << viewPairReverseIterator->first
342 return viewPairReverseIterator->first;
346 __COUT__ <<
"No duplicates found in " << potentialMatchCount <<
" potential matches."
352 void TableBase::changeVersionAndActivateView(
TableVersion temporaryVersion,
355 if(tableViews_.find(temporaryVersion) == tableViews_.end())
357 __SS__ <<
"ERROR: Temporary view version " << temporaryVersion
358 <<
" doesn't exists!" << __E__;
359 __COUT_ERR__ <<
"\n" << ss.str();
362 if(version.isInvalid())
364 __SS__ <<
"ERROR: Attempting to create an invalid version " << version
365 <<
"! Did you really run out of versions? (this should never happen)"
367 __COUT_ERR__ <<
"\n" << ss.str();
371 if(tableViews_.find(version) != tableViews_.end())
372 __COUT_WARN__ <<
"WARNING: View version " << version
373 <<
" already exists! Overwriting." << __E__;
375 tableViews_[version].copy(tableViews_[temporaryVersion],
377 tableViews_[temporaryVersion].getAuthor());
378 setActiveView(version);
379 eraseView(temporaryVersion);
383 bool TableBase::isStored(
const TableVersion& version)
const
385 return (tableViews_.find(version) != tableViews_.end());
391 if(!isStored(version))
394 if(activeTableView_ &&
395 getViewVersion() == version)
398 tableViews_.erase(version);
404 const std::string& TableBase::getTableName(
void)
const {
return tableName_; }
407 const std::string& TableBase::getTableDescription(
void)
const
409 return tableDescription_;
413 const TableVersion& TableBase::getViewVersion(
void)
const
415 return getView().getVersion();
421 bool TableBase::latestAndMockupColumnNumberMismatch(
void)
const
423 std::set<TableVersion> retSet = getStoredVersions();
424 if(retSet.size() && !retSet.rbegin()->isTemporaryVersion())
426 return tableViews_.find(*(retSet.rbegin()))->second.getNumberOfColumns() !=
427 mockupTableView_.getNumberOfColumns();
434 std::set<TableVersion> TableBase::getStoredVersions(
void)
const
436 std::set<TableVersion> retSet;
437 for(
auto& configs : tableViews_)
438 retSet.emplace(configs.first);
446 unsigned int TableBase::getNumberOfStoredViews(
void)
const
449 for(
auto& viewPair : tableViews_)
450 if(viewPair.first.isTemporaryVersion())
452 else if(viewPair.first.isInvalid())
462 __COUT__ <<
"There is an invalid version now!.. where did it come from?"
471 const TableView& TableBase::getView(
void)
const
473 if(!activeTableView_)
475 __SS__ <<
"activeTableView_ pointer is null! (...likely the active view was not "
476 "setup properly. Check your system setup.)";
479 return *activeTableView_;
485 if(!activeTableView_)
487 __SS__ <<
"activeTableView_ pointer is null! (...likely the active view was not "
488 "setup properly. Check your system setup.)";
491 return activeTableView_;
495 TableView* TableBase::getMockupViewP(
void) {
return &mockupTableView_; }
498 void TableBase::setTableName(
const std::string& tableName) { tableName_ = tableName; }
501 void TableBase::setTableDescription(
const std::string& tableDescription)
503 tableDescription_ = tableDescription;
509 void TableBase::deactivate() { activeTableView_ = 0; }
513 bool TableBase::isActive() {
return activeTableView_ ?
true :
false; }
518 if(!isStored(version))
523 __SS__ <<
"\nsetActiveView() ERROR: View with version " << version
524 <<
" has never been stored before!" << __E__;
528 activeTableView_ = &tableViews_[version];
530 if(tableViews_[version].getVersion() != version)
532 __SS__ <<
"Something has gone very wrong with the version handling!" << __E__;
551 const std::string& author,
552 const std::string& mergeApproach ,
553 std::map<std::pair<std::string /*original table*/, std::string /*original uidB*/>,
554 std::string >& uidConversionMap,
557 std::pair<std::string /*group linkid*/, std::string /*original gidB*/> >,
558 std::string >& groupidConversionMap,
559 bool fillRecordConversionMaps,
560 bool applyRecordConversionMaps,
561 bool generateUniqueDataColumns)
563 __COUT__ <<
"mergeViews starting..." << __E__;
575 if(!(mergeApproach ==
"Rename" || mergeApproach ==
"Replace" ||
576 mergeApproach ==
"Skip"))
578 __SS__ <<
"Error! Invalid merge approach '" << mergeApproach <<
".'" << __E__;
583 if(sourceViewA.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
585 __SS__ <<
"Error! Number of Columns of source view A must match destination "
587 <<
"Dimension of source is [" << sourceViewA.getNumberOfColumns()
588 <<
"] and of destination mockup is ["
589 << mockupTableView_.getNumberOfColumns() <<
"]." << __E__;
593 if(sourceViewB.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
595 __SS__ <<
"Error! Number of Columns of source view B must match destination "
597 <<
"Dimension of source is [" << sourceViewB.getNumberOfColumns()
598 <<
"] and of destination mockup is ["
599 << mockupTableView_.getNumberOfColumns() <<
"]." << __E__;
608 if(fillRecordConversionMaps && mergeApproach ==
"Rename")
610 __COUT__ <<
"Filling record conversion map." << __E__;
620 unsigned int uniqueId;
621 std::string uniqueIdString, uniqueIdBase;
622 char indexString[1000];
624 unsigned int numericStartIndex;
627 for(
unsigned int cb = 0; cb < sourceViewB.getNumberOfColumns(); ++cb)
630 if(!(sourceViewA.getColumnInfo(cb).isUID() ||
631 sourceViewA.getColumnInfo(cb).isGroupID()))
634 __COUT__ <<
"Have an ID column: " << cb <<
" "
635 << sourceViewA.getColumnInfo(cb).getType() << __E__;
638 if(sourceViewA.getColumnInfo(cb).getType() !=
639 sourceViewB.getColumnInfo(cb).getType() ||
640 sourceViewA.getColumnInfo(cb).getType() !=
641 mockupTableView_.getColumnInfo(cb).getType())
643 __SS__ <<
"Error! " << sourceViewA.getColumnInfo(cb).getType()
645 <<
" of source view A must match source B and destination mock-up "
647 <<
" Column of source B is ["
648 << sourceViewA.getColumnInfo(cb).getType()
649 <<
"] and of destination mockup is ["
650 << mockupTableView_.getColumnInfo(cb).getType() <<
"]." << __E__;
656 std::vector<std::string >
659 if(sourceViewA.getColumnInfo(cb).isGroupID())
661 std::set<std::string> aGroupids = sourceViewA.getSetOfGroupIDs(cb);
662 std::set<std::string> bGroupids = sourceViewB.getSetOfGroupIDs(cb);
664 for(
const auto& bGroupid : bGroupids)
666 if(aGroupids.find(bGroupid) == aGroupids.end())
670 __COUT__ <<
"found conflict: " << getTableName() <<
"/" << bGroupid
675 const std::string& str = bGroupid;
676 numericStartIndex = str.size();
679 while(numericStartIndex - 1 < str.size() &&
680 str[numericStartIndex - 1] >=
'0' &&
681 str[numericStartIndex - 1] <=
'9')
684 if(numericStartIndex < str.size())
686 uniqueId = atoi(str.substr(numericStartIndex).c_str()) + 1;
687 uniqueIdBase = str.substr(0, numericStartIndex);
695 __COUTV__(uniqueIdBase);
701 sprintf(indexString,
"%u", uniqueId);
702 uniqueIdString = uniqueIdBase + indexString;
703 __COUTV__(uniqueIdString);
707 if(aGroupids.find(uniqueIdString) != aGroupids.end())
709 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
711 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
713 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
714 if(localConvertedIds[ra] == uniqueIdString)
720 sprintf(indexString,
"%u", uniqueId);
721 uniqueIdString = uniqueIdBase + indexString;
722 __COUTV__(uniqueIdString);
726 if(aGroupids.find(uniqueIdString) != aGroupids.end())
729 bGroupids.find(uniqueIdString) != bGroupids.end())
732 bGroupids.find(uniqueIdString) != bGroupids.end())
734 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
735 if(localConvertedIds[ra] == uniqueIdString)
741 __COUTV__(uniqueIdString);
744 [std::pair<std::string ,
745 std::pair<std::string ,
748 std::pair<std::string ,
750 sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
751 bGroupid))] = uniqueIdString;
752 localConvertedIds.push_back(uniqueIdString);
759 __COUTV__(StringMacros::mapToString(groupidConversionMap));
764 for(
unsigned int rb = 0; rb < sourceViewB.getNumberOfRows(); ++rb)
768 for(ra = 0; ra < sourceViewA.getDataView().size(); ++ra)
769 if(sourceViewA.getValueAsString(ra, cb) ==
770 sourceViewB.getValueAsString(rb, cb))
780 __COUT__ <<
"found conflict: " << getTableName() <<
"/"
781 << sourceViewB.getDataView()[rb][cb] << __E__;
785 const std::string& str = sourceViewB.getDataView()[rb][cb];
786 numericStartIndex = str.size();
789 while(numericStartIndex - 1 < str.size() &&
790 str[numericStartIndex - 1] >=
'0' &&
791 str[numericStartIndex - 1] <=
'9')
794 if(numericStartIndex < str.size())
796 uniqueId = atoi(str.substr(numericStartIndex).c_str()) + 1;
797 uniqueIdBase = str.substr(0, numericStartIndex);
805 __COUTV__(uniqueIdBase);
811 sprintf(indexString,
"%u", uniqueId);
812 uniqueIdString = uniqueIdBase + indexString;
813 __COUTV__(uniqueIdString);
817 for(ra = 0; !found && ra < sourceViewA.getDataView().size(); ++ra)
818 if(sourceViewA.getValueAsString(ra, cb) == uniqueIdString)
820 for(ra = 0; !found && ra < sourceViewB.getDataView().size(); ++ra)
823 else if(sourceViewB.getValueAsString(ra, cb) ==
826 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
827 if(localConvertedIds[ra] == uniqueIdString)
833 sprintf(indexString,
"%u", uniqueId);
834 uniqueIdString = uniqueIdBase + indexString;
835 __COUTV__(uniqueIdString);
839 for(ra = 0; !found && ra < sourceViewA.getDataView().size();
841 if(sourceViewA.getValueAsString(ra, cb) == uniqueIdString)
843 for(ra = 0; !found && ra < sourceViewB.getDataView().size();
847 else if(sourceViewB.getValueAsString(ra, cb) ==
850 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
851 if(localConvertedIds[ra] == uniqueIdString)
857 __COUTV__(uniqueIdString);
859 uidConversionMap[std::pair<std::string ,
861 getTableName(), sourceViewB.getValueAsString(rb, cb))] =
863 localConvertedIds.push_back(uniqueIdString);
870 __COUTV__(StringMacros::mapToString(uidConversionMap));
877 __COUT__ <<
"Not filling record conversion map." << __E__;
879 if(!applyRecordConversionMaps)
881 __COUT__ <<
"Not applying record conversion map." << __E__;
886 __COUT__ <<
"Applying record conversion map." << __E__;
887 __COUTV__(StringMacros::mapToString(uidConversionMap));
888 __COUTV__(StringMacros::mapToString(groupidConversionMap));
892 destinationVersion = createTemporaryView(
TableVersion(), destinationVersion);
894 __COUT__ <<
"Merging from (A) " << sourceViewA.getTableName() <<
"_v"
895 << sourceViewA.getVersion() <<
" and (B) " << sourceViewB.getTableName()
896 <<
"_v" << sourceViewB.getVersion() <<
" to " << getTableName() <<
"_v"
897 << destinationVersion <<
" with approach '" << mergeApproach <<
".'"
905 TableView* destinationView = &(tableViews_[destinationVersion].copy(
906 sourceViewA, destinationVersion, author));
908 unsigned int destRow, destSize = destinationView->getDataView().size();
911 std::map<std::pair<std::string , std::string >,
912 std::string >::iterator uidConversionIt;
913 std::map<std::pair<std::string ,
914 std::pair<std::string ,
916 std::string >::iterator groupidConversionIt;
919 std::pair<
unsigned int ,
unsigned int > linkPair;
923 unsigned int colUID = mockupTableView_.getColUID();
926 for(
unsigned int rb = 0; rb < sourceViewB.getNumberOfRows(); ++rb)
928 if(mergeApproach ==
"Rename")
938 destRow = destinationView->copyRows(
944 generateUniqueDataColumns );
948 for(cb = 0; cb < sourceViewB.getNumberOfColumns(); ++cb)
950 if(sourceViewB.getColumnInfo(cb).isChildLink())
952 else if(sourceViewB.getColumnInfo(cb).isChildLinkUID())
954 __COUT__ <<
"Checking UID link... col=" << cb << __E__;
955 sourceViewB.getChildLink(cb, linkIsGroup, linkPair);
958 if((uidConversionIt = uidConversionMap.find(
959 std::pair<std::string ,
961 sourceViewB.getValueAsString(rb, linkPair.first),
962 sourceViewB.getValueAsString(
963 rb, linkPair.second)))) != uidConversionMap.end())
965 __COUT__ <<
"Found entry to remap: "
966 << sourceViewB.getDataView()[rb][linkPair.second]
967 <<
" ==> " << uidConversionIt->second << __E__;
968 destinationView->setValueAsString(
969 uidConversionIt->second, destRow, linkPair.second);
972 else if(sourceViewB.getColumnInfo(cb).isChildLinkGroupID())
974 __COUT__ <<
"Checking GroupID link... col=" << cb << __E__;
975 sourceViewB.getChildLink(cb, linkIsGroup, linkPair);
978 if((groupidConversionIt = groupidConversionMap.find(
979 std::pair<std::string ,
980 std::pair<std::string ,
982 sourceViewB.getValueAsString(rb, linkPair.first),
983 std::pair<std::string ,
985 sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
986 sourceViewB.getValueAsString(
987 rb, linkPair.second))))) !=
988 groupidConversionMap.end())
990 __COUT__ <<
"Found entry to remap: "
991 << sourceViewB.getDataView()[rb][linkPair.second]
992 <<
" ==> " << groupidConversionIt->second << __E__;
993 destinationView->setValueAsString(
994 groupidConversionIt->second, destRow, linkPair.second);
997 else if(sourceViewB.getColumnInfo(cb).isUID())
999 __COUT__ <<
"Checking UID... col=" << cb << __E__;
1000 if((uidConversionIt = uidConversionMap.find(
1001 std::pair<std::string ,
1004 sourceViewB.getValueAsString(rb, cb)))) !=
1005 uidConversionMap.end())
1007 __COUT__ <<
"Found entry to remap: "
1008 << sourceViewB.getDataView()[rb][cb] <<
" ==> "
1009 << uidConversionIt->second << __E__;
1010 destinationView->setValueAsString(
1011 uidConversionIt->second, destRow, cb);
1014 else if(sourceViewB.getColumnInfo(cb).isGroupID())
1016 __COUT__ <<
"Checking GroupID... col=" << cb << __E__;
1017 if((groupidConversionIt = groupidConversionMap.find(
1018 std::pair<std::string ,
1019 std::pair<std::string ,
1022 std::pair<std::string ,
1024 sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
1025 sourceViewB.getValueAsString(rb, cb))))) !=
1026 groupidConversionMap.end())
1028 __COUT__ <<
"Found entry to remap: "
1029 << sourceViewB.getDataView()[rb][cb] <<
" ==> "
1030 << groupidConversionIt->second << __E__;
1031 destinationView->setValueAsString(
1032 groupidConversionIt->second, destRow, cb);
1038 strb = sourceViewB.getValueAsString(rb, cb);
1039 if(strb.size() > getTableName().size() + 2 && strb[0] ==
'/')
1042 __COUT__ <<
"Checking col" << cb <<
" " << strb << __E__;
1045 for(
const auto& mapPairToPair : uidConversionMap)
1047 if((stri = strb.find(mapPairToPair.first.first +
"/" +
1048 mapPairToPair.first.second)) !=
1051 __COUT__ <<
"Found a text link match (stri=" << stri
1053 << (mapPairToPair.first.first +
"/" +
1054 mapPairToPair.first.second)
1055 <<
" ==> " << mapPairToPair.second << __E__;
1058 destinationView->setValueAsString(
1059 strb.substr(0, stri) +
1060 (mapPairToPair.first.first +
"/" +
1061 mapPairToPair.first.second) +
1063 (mapPairToPair.first.first +
"/" +
1064 mapPairToPair.first.second)
1070 <<
"Found entry to remap: "
1071 << sourceViewB.getDataView()[rb][cb] <<
" ==> "
1072 << destinationView->getDataView()[destRow][cb]
1088 for(destRow = 0; destRow < destSize; ++destRow)
1089 if(destinationView->getValueAsString(destRow, colUID) ==
1090 sourceViewB.getValueAsString(rb, colUID))
1097 __COUT__ <<
"No " << mergeApproach <<
" conflict: " << __E__;
1099 if(mergeApproach ==
"replace" || mergeApproach ==
"skip")
1103 destinationView->copyRows(
1104 author, sourceViewB, rb, 1 );
1113 __COUT__ <<
"found " << mergeApproach
1114 <<
" conflict: " << sourceViewB.getDataView()[rb][colUID] << __E__;
1116 if(mergeApproach ==
"replace")
1122 destinationView->deleteRow(destRow--);
1127 destinationView->copyRows(author, sourceViewB, rb, 1 );
1132 destinationView->print();
1136 __COUT_ERR__ <<
"Failed to merge " << sourceViewA.getTableName() <<
"_v"
1137 << sourceViewA.getVersion() <<
" and " << sourceViewB.getTableName()
1138 <<
"_v" << sourceViewB.getVersion() <<
" into " << getTableName()
1139 <<
"_v" << destinationVersion << __E__;
1140 __COUT_WARN__ <<
"Deleting the failed destination version " << destinationVersion
1142 eraseView(destinationVersion);
1146 return destinationVersion;
1159 const std::string& author)
1162 if(sourceView.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
1164 __SS__ <<
"Error! Number of Columns of source view must match destination "
1166 <<
"Dimension of source is [" << sourceView.getNumberOfColumns()
1167 <<
"] and of destination mockup is ["
1168 << mockupTableView_.getNumberOfColumns() <<
"]." << __E__;
1173 if(!destinationVersion.isInvalid() &&
1174 tableViews_.find(destinationVersion) != tableViews_.end())
1176 __SS__ <<
"Error! Asked to copy a view with a conflicting version: "
1177 << destinationVersion << __E__;
1182 destinationVersion = createTemporaryView(
TableVersion(), destinationVersion);
1184 __COUT__ <<
"Copying from " << sourceView.getTableName() <<
"_v"
1185 << sourceView.getVersion() <<
" to " << getTableName() <<
"_v"
1186 << destinationVersion << __E__;
1190 tableViews_[destinationVersion].copy(sourceView, destinationVersion, author);
1194 __COUT_ERR__ <<
"Failed to copy from " << sourceView.getTableName() <<
"_v"
1195 << sourceView.getVersion() <<
" to " << getTableName() <<
"_v"
1196 << destinationVersion << __E__;
1197 __COUT_WARN__ <<
"Deleting the failed destination version " << destinationVersion
1199 eraseView(destinationVersion);
1203 return destinationVersion;
1216 __COUT__ <<
"Table: " << getTableName() << __E__;
1218 __COUT__ <<
"Num of Views: " << tableViews_.size()
1219 <<
" (Temporary Views: " << (tableViews_.size() - getNumberOfStoredViews())
1223 if(tmpVersion.isInvalid())
1224 tmpVersion = TableVersion::getNextTemporaryVersion();
1225 while(isStored(tmpVersion) &&
1226 !(tmpVersion = TableVersion::getNextTemporaryVersion(tmpVersion)).isInvalid())
1228 if(isStored(tmpVersion) || tmpVersion.isInvalid())
1230 __SS__ <<
"Invalid destination temporary version: " << destTemporaryViewVersion
1231 <<
". Expected next temporary version < " << tmpVersion << __E__;
1232 __COUT_ERR__ << ss.str();
1236 if(sourceViewVersion ==
1237 TableVersion::INVALID ||
1238 tableViews_.find(sourceViewVersion) == tableViews_.end())
1240 if(sourceViewVersion != -1)
1242 __SS__ <<
"ERROR: sourceViewVersion " << sourceViewVersion <<
" not found. "
1243 <<
"Invalid source version. Version requested is not stored (yet?) or "
1246 __COUT_ERR__ << ss.str();
1249 __COUT__ <<
"Using Mock-up view" << __E__;
1250 tableViews_[tmpVersion].copy(
1251 mockupTableView_, tmpVersion, mockupTableView_.getAuthor());
1257 tableViews_[tmpVersion].copy(tableViews_[sourceViewVersion],
1259 tableViews_[sourceViewVersion].getAuthor());
1264 <<
"createTemporaryView() Source view failed init(). "
1265 <<
"This is being ignored (hopefully the new copy is being fixed)."
1277 TableVersion TableBase::getNextTemporaryVersion()
const
1282 if(tableViews_.size() != 0 && tableViews_.begin()->first.isTemporaryVersion())
1283 tmpVersion = TableVersion::getNextTemporaryVersion(tableViews_.begin()->first);
1285 tmpVersion = TableVersion::getNextTemporaryVersion();
1288 if(isStored(tmpVersion) || tmpVersion.isInvalid() || !tmpVersion.isTemporaryVersion())
1290 __SS__ <<
"Invalid destination temporary version: " << tmpVersion << __E__;
1291 __COUT_ERR__ << ss.str();
1306 if(tableViews_.size() != 0 && !tableViews_.rbegin()->first.isTemporaryVersion())
1307 tmpVersion = TableVersion::getNextVersion(tableViews_.rbegin()->first);
1309 tmpVersion = TableVersion::getNextVersion();
1312 if(isStored(tmpVersion) || tmpVersion.isInvalid() || tmpVersion.isTemporaryVersion())
1314 __SS__ <<
"Invalid destination next version: " << tmpVersion << __E__;
1315 __COUT_ERR__ << ss.str();
1328 if(!temporaryVersion.isTemporaryVersion() || !isStored(temporaryVersion))
1330 __SS__ << getTableName() <<
":: Error! Temporary version not found!" << __E__;
1331 __COUT_ERR__ << ss.str();
1334 return &tableViews_[temporaryVersion];
1341 std::string TableBase::convertToCaps(std::string& str,
bool isConfigName)
1344 unsigned int configPos = (
unsigned int)std::string::npos;
1345 if(isConfigName && (configPos = str.find(
"Table")) != str.size() - strlen(
"Table"))
1350 std::string capsStr =
"";
1351 for(
unsigned int c = 0; c < str.size(); ++c)
1352 if(str[c] >=
'A' && str[c] <=
'Z')
1355 if(c == configPos ||
1356 (c && str[c - 1] >=
'a' &&
1357 str[c - 1] <=
'z') ||
1358 (c && str[c - 1] >=
'A' &&
1359 str[c - 1] <=
'Z' &&
1360 c + 1 < str.size() && str[c + 1] >=
'a' && str[c + 1] <=
'z'))
1364 else if(str[c] >=
'a' && str[c] <=
'z')
1365 capsStr += char(str[c] - 32);
1366 else if(str[c] >=
'0' && str[c] <=
'9')
1369 __THROW__(std::string(
"TableBase::convertToCaps::") +
1370 "Invalid character found in name (allowed: A-Z, a-z, 0-9):" + str);
TableVersion mergeViews(const TableView &sourceViewA, const TableView &sourceViewB, TableVersion destinationVersion, const std::string &author, const std::string &mergeApproach, std::map< std::pair< std::string, std::string >, std::string > &uidConversionMap, std::map< std::pair< std::string, std::pair< std::string, std::string > >, std::string > &groupidConversionMap, bool fillRecordConversionMaps, bool applyRecordConversionMaps, bool generateUniqueDataColumns=false)