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();
70 TableBase::TableBase(
void)
71 : MAX_VIEWS_IN_CACHE(1)
79 TableBase::~TableBase(
void) {}
82 std::string TableBase::getTypeId() {
return typeid(
this).name(); }
91 void TableBase::reset(
bool keepTemporaryVersions)
95 if(keepTemporaryVersions)
102 void TableBase::print(std::ostream& out)
const
106 if(!activeTableView_)
108 __COUT_ERR__ <<
"ERROR: No active view set" << __E__;
111 activeTableView_->print(out);
119 if(!isStored(version))
121 tableViews_[version].copy(
122 mockupTableView_, version, mockupTableView_.getAuthor());
124 if(!isStored(version))
126 __SS__ << __COUT_HDR_P__
127 <<
"IMPOSSIBLE ERROR: trimCache() is deleting the "
128 "latest view version "
129 << version <<
"!" << __E__;
135 __SS__ << __COUT_HDR_P__ <<
"View to fill with mockup already exists: " << version
136 <<
". Cannot overwrite!" << __E__;
137 ss << StringMacros::stackTrace() << __E__;
147 void TableBase::trimCache(
unsigned int trimSize)
151 if(trimSize == (
unsigned int)-1)
152 trimSize = MAX_VIEWS_IN_CACHE;
155 while(getNumberOfStoredViews() > trimSize)
158 time_t stalestTime = -1;
160 for(
auto& viewPair : tableViews_)
161 if(!viewPair.first.isTemporaryVersion())
163 if(stalestTime == -1 || viewPair.second.getLastAccessTime() < stalestTime)
165 versionToDelete = viewPair.first;
166 stalestTime = viewPair.second.getLastAccessTime();
172 if(versionToDelete.isInvalid())
174 __SS__ <<
"Can NOT have a stored view with an invalid version!" << __E__;
178 eraseView(versionToDelete);
187 void TableBase::trimTemporary(
TableVersion targetVersion)
189 if(targetVersion.isInvalid())
191 for(
auto it = tableViews_.begin(); it != tableViews_.end(); )
193 if(it->first.isTemporaryVersion())
195 __COUT__ <<
"Trimming temporary version: " << it->first << __E__;
196 if(activeTableView_ &&
197 getViewVersion() == it->first)
200 tableViews_.erase(it++);
206 else if(targetVersion.isTemporaryVersion())
208 __COUT__ <<
"Trimming temporary version: " << targetVersion << __E__;
209 eraseView(targetVersion);
214 __SS__ <<
"Temporary trim target was a persistent version: " << targetVersion
216 __COUT_ERR__ <<
"\n" << ss.str();
233 auto needleIt = tableViews_.find(needleVersion);
234 if(needleIt == tableViews_.end())
237 __SS__ <<
"needleVersion does not exist: " << needleVersion << __E__;
238 __COUT_ERR__ <<
"\n" << ss.str();
242 const TableView* needleView = &(needleIt->second);
243 unsigned int rows = needleView->getNumberOfRows();
244 unsigned int cols = needleView->getNumberOfColumns();
247 unsigned int potentialMatchCount = 0;
253 auto viewPairReverseIterator = tableViews_.rbegin();
254 for(; viewPairReverseIterator != tableViews_.rend(); ++viewPairReverseIterator)
256 if(viewPairReverseIterator->first == needleVersion)
258 if(viewPairReverseIterator->first == ignoreVersion)
260 if(viewPairReverseIterator->first.isTemporaryVersion())
263 if(viewPairReverseIterator->second.getNumberOfRows() != rows)
266 if(viewPairReverseIterator->second.getDataColumnSize() != cols ||
267 viewPairReverseIterator->second.getSourceColumnMismatch() != 0)
270 ++potentialMatchCount;
271 __COUT__ <<
"Checking version... " << viewPairReverseIterator->first << __E__;
281 match = viewPairReverseIterator->second.getSourceColumnNames().size() ==
282 needleView->getSourceColumnNames().size();
285 for(
auto& haystackColName :
286 viewPairReverseIterator->second.getSourceColumnNames())
287 if(needleView->getSourceColumnNames().find(haystackColName) ==
288 needleView->getSourceColumnNames().end())
290 __COUT__ <<
"Found column name mismach for '" << haystackColName
291 <<
"'... So allowing same data!" << __E__;
313 for(
unsigned int row = 0; match && row < rows; ++row)
315 for(
unsigned int col = 0; col < cols - 2;
317 if(viewPairReverseIterator->second.getDataView()[row][col] !=
318 needleView->getDataView()[row][col])
341 __COUT_INFO__ <<
"Duplicate version found: " << viewPairReverseIterator->first
343 return viewPairReverseIterator->first;
347 __COUT__ <<
"No duplicates found in " << potentialMatchCount <<
" potential matches."
353 void TableBase::changeVersionAndActivateView(
TableVersion temporaryVersion,
356 if(tableViews_.find(temporaryVersion) == tableViews_.end())
358 __SS__ <<
"ERROR: Temporary view version " << temporaryVersion
359 <<
" doesn't exists!" << __E__;
360 __COUT_ERR__ <<
"\n" << ss.str();
363 if(version.isInvalid())
365 __SS__ <<
"ERROR: Attempting to create an invalid version " << version
366 <<
"! Did you really run out of versions? (this should never happen)"
368 __COUT_ERR__ <<
"\n" << ss.str();
372 if(tableViews_.find(version) != tableViews_.end())
373 __COUT_WARN__ <<
"WARNING: View version " << version
374 <<
" already exists! Overwriting." << __E__;
376 tableViews_[version].copy(tableViews_[temporaryVersion],
378 tableViews_[temporaryVersion].getAuthor());
379 setActiveView(version);
380 eraseView(temporaryVersion);
384 bool TableBase::isStored(
const TableVersion& version)
const
386 return (tableViews_.find(version) != tableViews_.end());
392 if(!isStored(version))
395 if(activeTableView_ &&
396 getViewVersion() == version)
399 tableViews_.erase(version);
405 const std::string& TableBase::getTableName(
void)
const {
return tableName_; }
408 const std::string& TableBase::getTableDescription(
void)
const
410 return tableDescription_;
414 const TableVersion& TableBase::getViewVersion(
void)
const
416 return getView().getVersion();
422 bool TableBase::latestAndMockupColumnNumberMismatch(
void)
const
424 std::set<TableVersion> retSet = getStoredVersions();
425 if(retSet.size() && !retSet.rbegin()->isTemporaryVersion())
427 return tableViews_.find(*(retSet.rbegin()))->second.getNumberOfColumns() !=
428 mockupTableView_.getNumberOfColumns();
435 std::set<TableVersion> TableBase::getStoredVersions(
void)
const
437 std::set<TableVersion> retSet;
438 for(
auto& configs : tableViews_)
439 retSet.emplace(configs.first);
447 unsigned int TableBase::getNumberOfStoredViews(
void)
const
450 for(
auto& viewPair : tableViews_)
451 if(viewPair.first.isTemporaryVersion())
453 else if(viewPair.first.isInvalid())
463 __COUT__ <<
"There is an invalid version now!.. where did it come from?"
472 const TableView& TableBase::getView(
void)
const
474 if(!activeTableView_)
476 __SS__ <<
"activeTableView_ pointer is null! (...likely the active view was not "
477 "setup properly. Check your system setup.)"
481 return *activeTableView_;
487 if(!activeTableView_)
489 __SS__ <<
"activeTableView_ pointer is null! (...likely the active view was not "
490 "setup properly. Check your system setup.)"
494 return activeTableView_;
498 TableView* TableBase::getMockupViewP(
void) {
return &mockupTableView_; }
501 void TableBase::setTableName(
const std::string& tableName) { tableName_ = tableName; }
504 void TableBase::setTableDescription(
const std::string& tableDescription)
506 tableDescription_ = tableDescription;
512 void TableBase::deactivate() { activeTableView_ = 0; }
516 bool TableBase::isActive() {
return activeTableView_ ?
true :
false; }
521 if(!isStored(version))
526 __SS__ <<
"\nsetActiveView() ERROR: View with version " << version
527 <<
" has never been stored before!" << __E__;
531 activeTableView_ = &tableViews_[version];
533 if(tableViews_[version].getVersion() != version)
535 __SS__ <<
"Something has gone very wrong with the version handling!" << __E__;
554 const std::string& author,
555 const std::string& mergeApproach ,
556 std::map<std::pair<std::string /*original table*/, std::string /*original uidB*/>,
557 std::string >& uidConversionMap,
560 std::pair<std::string /*group linkid*/, std::string /*original gidB*/> >,
561 std::string >& groupidConversionMap,
562 bool fillRecordConversionMaps,
563 bool applyRecordConversionMaps,
564 bool generateUniqueDataColumns)
566 __COUT__ <<
"mergeViews starting..." << __E__;
578 if(!(mergeApproach ==
"Rename" || mergeApproach ==
"Replace" ||
579 mergeApproach ==
"Skip"))
581 __SS__ <<
"Error! Invalid merge approach '" << mergeApproach <<
".'" << __E__;
586 if(sourceViewA.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
588 __SS__ <<
"Error! Number of Columns of source view A must match destination "
590 <<
"Dimension of source is [" << sourceViewA.getNumberOfColumns()
591 <<
"] and of destination mockup is ["
592 << mockupTableView_.getNumberOfColumns() <<
"]." << __E__;
596 if(sourceViewB.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
598 __SS__ <<
"Error! Number of Columns of source view B must match destination "
600 <<
"Dimension of source is [" << sourceViewB.getNumberOfColumns()
601 <<
"] and of destination mockup is ["
602 << mockupTableView_.getNumberOfColumns() <<
"]." << __E__;
611 if(fillRecordConversionMaps && mergeApproach ==
"Rename")
613 __COUT__ <<
"Filling record conversion map." << __E__;
623 unsigned int uniqueId;
624 std::string uniqueIdString, uniqueIdBase;
625 char indexString[1000];
627 unsigned int numericStartIndex;
630 for(
unsigned int cb = 0; cb < sourceViewB.getNumberOfColumns(); ++cb)
633 if(!(sourceViewA.getColumnInfo(cb).isUID() ||
634 sourceViewA.getColumnInfo(cb).isGroupID()))
637 __COUT__ <<
"Have an ID column: " << cb <<
" "
638 << sourceViewA.getColumnInfo(cb).getType() << __E__;
641 if(sourceViewA.getColumnInfo(cb).getType() !=
642 sourceViewB.getColumnInfo(cb).getType() ||
643 sourceViewA.getColumnInfo(cb).getType() !=
644 mockupTableView_.getColumnInfo(cb).getType())
646 __SS__ <<
"Error! " << sourceViewA.getColumnInfo(cb).getType()
648 <<
" of source view A must match source B and destination mock-up "
650 <<
" Column of source B is ["
651 << sourceViewA.getColumnInfo(cb).getType()
652 <<
"] and of destination mockup is ["
653 << mockupTableView_.getColumnInfo(cb).getType() <<
"]." << __E__;
659 std::vector<std::string >
662 if(sourceViewA.getColumnInfo(cb).isGroupID())
664 std::set<std::string> aGroupids = sourceViewA.getSetOfGroupIDs(cb);
665 std::set<std::string> bGroupids = sourceViewB.getSetOfGroupIDs(cb);
667 for(
const auto& bGroupid : bGroupids)
669 if(aGroupids.find(bGroupid) == aGroupids.end())
673 __COUT__ <<
"found conflict: " << getTableName() <<
"/" << bGroupid
678 const std::string& str = bGroupid;
679 numericStartIndex = str.size();
682 while(numericStartIndex - 1 < str.size() &&
683 str[numericStartIndex - 1] >=
'0' &&
684 str[numericStartIndex - 1] <=
'9')
687 if(numericStartIndex < str.size())
689 uniqueId = atoi(str.substr(numericStartIndex).c_str()) + 1;
690 uniqueIdBase = str.substr(0, numericStartIndex);
698 __COUTV__(uniqueIdBase);
704 sprintf(indexString,
"%u", uniqueId);
705 uniqueIdString = uniqueIdBase + indexString;
706 __COUTV__(uniqueIdString);
710 if(aGroupids.find(uniqueIdString) != aGroupids.end())
712 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
714 if(!found && bGroupids.find(uniqueIdString) != bGroupids.end())
716 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
717 if(localConvertedIds[ra] == uniqueIdString)
723 sprintf(indexString,
"%u", uniqueId);
724 uniqueIdString = uniqueIdBase + indexString;
725 __COUTV__(uniqueIdString);
729 if(aGroupids.find(uniqueIdString) != aGroupids.end())
732 bGroupids.find(uniqueIdString) != bGroupids.end())
735 bGroupids.find(uniqueIdString) != bGroupids.end())
737 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
738 if(localConvertedIds[ra] == uniqueIdString)
744 __COUTV__(uniqueIdString);
747 [std::pair<std::string ,
748 std::pair<std::string ,
751 std::pair<std::string ,
753 sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
754 bGroupid))] = uniqueIdString;
755 localConvertedIds.push_back(uniqueIdString);
762 __COUTV__(StringMacros::mapToString(groupidConversionMap));
767 for(
unsigned int rb = 0; rb < sourceViewB.getNumberOfRows(); ++rb)
771 for(ra = 0; ra < sourceViewA.getDataView().size(); ++ra)
772 if(sourceViewA.getValueAsString(ra, cb) ==
773 sourceViewB.getValueAsString(rb, cb))
783 __COUT__ <<
"found conflict: " << getTableName() <<
"/"
784 << sourceViewB.getDataView()[rb][cb] << __E__;
788 const std::string& str = sourceViewB.getDataView()[rb][cb];
789 numericStartIndex = str.size();
792 while(numericStartIndex - 1 < str.size() &&
793 str[numericStartIndex - 1] >=
'0' &&
794 str[numericStartIndex - 1] <=
'9')
797 if(numericStartIndex < str.size())
799 uniqueId = atoi(str.substr(numericStartIndex).c_str()) + 1;
800 uniqueIdBase = str.substr(0, numericStartIndex);
808 __COUTV__(uniqueIdBase);
814 sprintf(indexString,
"%u", uniqueId);
815 uniqueIdString = uniqueIdBase + indexString;
816 __COUTV__(uniqueIdString);
820 for(ra = 0; !found && ra < sourceViewA.getDataView().size(); ++ra)
821 if(sourceViewA.getValueAsString(ra, cb) == uniqueIdString)
823 for(ra = 0; !found && ra < sourceViewB.getDataView().size(); ++ra)
826 else if(sourceViewB.getValueAsString(ra, cb) ==
829 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
830 if(localConvertedIds[ra] == uniqueIdString)
836 sprintf(indexString,
"%u", uniqueId);
837 uniqueIdString = uniqueIdBase + indexString;
838 __COUTV__(uniqueIdString);
842 for(ra = 0; !found && ra < sourceViewA.getDataView().size();
844 if(sourceViewA.getValueAsString(ra, cb) == uniqueIdString)
846 for(ra = 0; !found && ra < sourceViewB.getDataView().size();
850 else if(sourceViewB.getValueAsString(ra, cb) ==
853 for(ra = 0; !found && ra < localConvertedIds.size(); ++ra)
854 if(localConvertedIds[ra] == uniqueIdString)
860 __COUTV__(uniqueIdString);
862 uidConversionMap[std::pair<std::string ,
864 getTableName(), sourceViewB.getValueAsString(rb, cb))] =
866 localConvertedIds.push_back(uniqueIdString);
873 __COUTV__(StringMacros::mapToString(uidConversionMap));
880 __COUT__ <<
"Not filling record conversion map." << __E__;
882 if(!applyRecordConversionMaps)
884 __COUT__ <<
"Not applying record conversion map." << __E__;
889 __COUT__ <<
"Applying record conversion map." << __E__;
890 __COUTV__(StringMacros::mapToString(uidConversionMap));
891 __COUTV__(StringMacros::mapToString(groupidConversionMap));
895 destinationVersion = createTemporaryView(
TableVersion(), destinationVersion);
897 __COUT__ <<
"Merging from (A) " << sourceViewA.getTableName() <<
"_v"
898 << sourceViewA.getVersion() <<
" and (B) " << sourceViewB.getTableName()
899 <<
"_v" << sourceViewB.getVersion() <<
" to " << getTableName() <<
"_v"
900 << destinationVersion <<
" with approach '" << mergeApproach <<
".'"
908 TableView* destinationView = &(tableViews_[destinationVersion].copy(
909 sourceViewA, destinationVersion, author));
911 unsigned int destRow, destSize = destinationView->getDataView().size();
914 std::map<std::pair<std::string , std::string >,
915 std::string >::iterator uidConversionIt;
916 std::map<std::pair<std::string ,
917 std::pair<std::string ,
919 std::string >::iterator groupidConversionIt;
922 std::pair<
unsigned int ,
unsigned int > linkPair;
926 unsigned int colUID = mockupTableView_.getColUID();
929 for(
unsigned int rb = 0; rb < sourceViewB.getNumberOfRows(); ++rb)
931 if(mergeApproach ==
"Rename")
941 destRow = destinationView->copyRows(
947 generateUniqueDataColumns );
951 for(cb = 0; cb < sourceViewB.getNumberOfColumns(); ++cb)
953 if(sourceViewB.getColumnInfo(cb).isChildLink())
955 else if(sourceViewB.getColumnInfo(cb).isChildLinkUID())
957 __COUT__ <<
"Checking UID link... col=" << cb << __E__;
958 sourceViewB.getChildLink(cb, linkIsGroup, linkPair);
961 if((uidConversionIt = uidConversionMap.find(
962 std::pair<std::string ,
964 sourceViewB.getValueAsString(rb, linkPair.first),
965 sourceViewB.getValueAsString(
966 rb, linkPair.second)))) != uidConversionMap.end())
968 __COUT__ <<
"Found entry to remap: "
969 << sourceViewB.getDataView()[rb][linkPair.second]
970 <<
" ==> " << uidConversionIt->second << __E__;
971 destinationView->setValueAsString(
972 uidConversionIt->second, destRow, linkPair.second);
975 else if(sourceViewB.getColumnInfo(cb).isChildLinkGroupID())
977 __COUT__ <<
"Checking GroupID link... col=" << cb << __E__;
978 sourceViewB.getChildLink(cb, linkIsGroup, linkPair);
981 if((groupidConversionIt = groupidConversionMap.find(
982 std::pair<std::string ,
983 std::pair<std::string ,
985 sourceViewB.getValueAsString(rb, linkPair.first),
986 std::pair<std::string ,
988 sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
989 sourceViewB.getValueAsString(
990 rb, linkPair.second))))) !=
991 groupidConversionMap.end())
993 __COUT__ <<
"Found entry to remap: "
994 << sourceViewB.getDataView()[rb][linkPair.second]
995 <<
" ==> " << groupidConversionIt->second << __E__;
996 destinationView->setValueAsString(
997 groupidConversionIt->second, destRow, linkPair.second);
1000 else if(sourceViewB.getColumnInfo(cb).isUID())
1002 __COUT__ <<
"Checking UID... col=" << cb << __E__;
1003 if((uidConversionIt = uidConversionMap.find(
1004 std::pair<std::string ,
1007 sourceViewB.getValueAsString(rb, cb)))) !=
1008 uidConversionMap.end())
1010 __COUT__ <<
"Found entry to remap: "
1011 << sourceViewB.getDataView()[rb][cb] <<
" ==> "
1012 << uidConversionIt->second << __E__;
1013 destinationView->setValueAsString(
1014 uidConversionIt->second, destRow, cb);
1017 else if(sourceViewB.getColumnInfo(cb).isGroupID())
1019 __COUT__ <<
"Checking GroupID... col=" << cb << __E__;
1020 if((groupidConversionIt = groupidConversionMap.find(
1021 std::pair<std::string ,
1022 std::pair<std::string ,
1025 std::pair<std::string ,
1027 sourceViewB.getColumnInfo(cb).getChildLinkIndex(),
1028 sourceViewB.getValueAsString(rb, cb))))) !=
1029 groupidConversionMap.end())
1031 __COUT__ <<
"Found entry to remap: "
1032 << sourceViewB.getDataView()[rb][cb] <<
" ==> "
1033 << groupidConversionIt->second << __E__;
1034 destinationView->setValueAsString(
1035 groupidConversionIt->second, destRow, cb);
1041 strb = sourceViewB.getValueAsString(rb, cb);
1042 if(strb.size() > getTableName().size() + 2 && strb[0] ==
'/')
1045 __COUT__ <<
"Checking col" << cb <<
" " << strb << __E__;
1048 for(
const auto& mapPairToPair : uidConversionMap)
1050 if((stri = strb.find(mapPairToPair.first.first +
"/" +
1051 mapPairToPair.first.second)) !=
1054 __COUT__ <<
"Found a text link match (stri=" << stri
1056 << (mapPairToPair.first.first +
"/" +
1057 mapPairToPair.first.second)
1058 <<
" ==> " << mapPairToPair.second << __E__;
1061 destinationView->setValueAsString(
1062 strb.substr(0, stri) +
1063 (mapPairToPair.first.first +
"/" +
1064 mapPairToPair.first.second) +
1066 (mapPairToPair.first.first +
"/" +
1067 mapPairToPair.first.second)
1073 <<
"Found entry to remap: "
1074 << sourceViewB.getDataView()[rb][cb] <<
" ==> "
1075 << destinationView->getDataView()[destRow][cb]
1091 for(destRow = 0; destRow < destSize; ++destRow)
1092 if(destinationView->getValueAsString(destRow, colUID) ==
1093 sourceViewB.getValueAsString(rb, colUID))
1100 __COUT__ <<
"No " << mergeApproach <<
" conflict: " << __E__;
1102 if(mergeApproach ==
"replace" || mergeApproach ==
"skip")
1106 destinationView->copyRows(
1107 author, sourceViewB, rb, 1 );
1116 __COUT__ <<
"found " << mergeApproach
1117 <<
" conflict: " << sourceViewB.getDataView()[rb][colUID] << __E__;
1119 if(mergeApproach ==
"replace")
1125 destinationView->deleteRow(destRow--);
1130 destinationView->copyRows(author, sourceViewB, rb, 1 );
1135 destinationView->print();
1139 __COUT_ERR__ <<
"Failed to merge " << sourceViewA.getTableName() <<
"_v"
1140 << sourceViewA.getVersion() <<
" and " << sourceViewB.getTableName()
1141 <<
"_v" << sourceViewB.getVersion() <<
" into " << getTableName()
1142 <<
"_v" << destinationVersion << __E__;
1143 __COUT_WARN__ <<
"Deleting the failed destination version " << destinationVersion
1145 eraseView(destinationVersion);
1149 return destinationVersion;
1162 const std::string& author)
1165 if(sourceView.getNumberOfColumns() != mockupTableView_.getNumberOfColumns())
1167 __SS__ <<
"Error! Number of Columns of source view must match destination "
1169 <<
"Dimension of source is [" << sourceView.getNumberOfColumns()
1170 <<
"] and of destination mockup is ["
1171 << mockupTableView_.getNumberOfColumns() <<
"]." << __E__;
1176 if(!destinationVersion.isInvalid() &&
1177 tableViews_.find(destinationVersion) != tableViews_.end())
1179 __SS__ <<
"Error! Asked to copy a view with a conflicting version: "
1180 << destinationVersion << __E__;
1185 destinationVersion = createTemporaryView(
TableVersion(), destinationVersion);
1187 __COUT__ <<
"Copying from " << sourceView.getTableName() <<
"_v"
1188 << sourceView.getVersion() <<
" to " << getTableName() <<
"_v"
1189 << destinationVersion << __E__;
1193 tableViews_[destinationVersion].copy(sourceView, destinationVersion, author);
1197 __COUT_ERR__ <<
"Failed to copy from " << sourceView.getTableName() <<
"_v"
1198 << sourceView.getVersion() <<
" to " << getTableName() <<
"_v"
1199 << destinationVersion << __E__;
1200 __COUT_WARN__ <<
"Deleting the failed destination version " << destinationVersion
1202 eraseView(destinationVersion);
1206 return destinationVersion;
1219 __COUT__ <<
"Table: " << getTableName() << __E__;
1221 __COUT__ <<
"Num of Views: " << tableViews_.size()
1222 <<
" (Temporary Views: " << (tableViews_.size() - getNumberOfStoredViews())
1226 if(tmpVersion.isInvalid())
1227 tmpVersion = TableVersion::getNextTemporaryVersion();
1228 while(isStored(tmpVersion) &&
1229 !(tmpVersion = TableVersion::getNextTemporaryVersion(tmpVersion)).isInvalid())
1231 if(isStored(tmpVersion) || tmpVersion.isInvalid())
1233 __SS__ <<
"Invalid destination temporary version: " << destTemporaryViewVersion
1234 <<
". Expected next temporary version < " << tmpVersion << __E__;
1235 __COUT_ERR__ << ss.str();
1239 if(sourceViewVersion ==
1240 TableVersion::INVALID ||
1241 tableViews_.find(sourceViewVersion) == tableViews_.end())
1243 if(sourceViewVersion != -1)
1245 __SS__ <<
"ERROR: sourceViewVersion " << sourceViewVersion <<
" not found. "
1246 <<
"Invalid source version. Version requested is not stored (yet?) or "
1249 __COUT_ERR__ << ss.str();
1252 __COUT__ <<
"Using Mock-up view" << __E__;
1253 tableViews_[tmpVersion].copy(
1254 mockupTableView_, tmpVersion, mockupTableView_.getAuthor());
1260 tableViews_[tmpVersion].copy(tableViews_[sourceViewVersion],
1262 tableViews_[sourceViewVersion].getAuthor());
1267 <<
"createTemporaryView() Source view failed init(). "
1268 <<
"This is being ignored (hopefully the new copy is being fixed)."
1280 TableVersion TableBase::getNextTemporaryVersion()
const
1285 if(tableViews_.size() != 0 && tableViews_.begin()->first.isTemporaryVersion())
1286 tmpVersion = TableVersion::getNextTemporaryVersion(tableViews_.begin()->first);
1288 tmpVersion = TableVersion::getNextTemporaryVersion();
1291 if(isStored(tmpVersion) || tmpVersion.isInvalid() || !tmpVersion.isTemporaryVersion())
1293 __SS__ <<
"Invalid destination temporary version: " << tmpVersion << __E__;
1294 __COUT_ERR__ << ss.str();
1309 if(tableViews_.size() != 0 && !tableViews_.rbegin()->first.isTemporaryVersion())
1310 tmpVersion = TableVersion::getNextVersion(tableViews_.rbegin()->first);
1312 tmpVersion = TableVersion::getNextVersion();
1315 if(isStored(tmpVersion) || tmpVersion.isInvalid() || tmpVersion.isTemporaryVersion())
1317 __SS__ <<
"Invalid destination next version: " << tmpVersion << __E__;
1318 __COUT_ERR__ << ss.str();
1331 if(!temporaryVersion.isTemporaryVersion() || !isStored(temporaryVersion))
1333 __SS__ << getTableName() <<
":: Error! Temporary version not found!" << __E__;
1334 __COUT_ERR__ << ss.str();
1337 return &tableViews_[temporaryVersion];
1344 std::string TableBase::convertToCaps(std::string& str,
bool isConfigName)
1347 unsigned int configPos = (
unsigned int)std::string::npos;
1348 if(isConfigName && (configPos = str.find(
"Table")) != str.size() - strlen(
"Table"))
1353 std::string capsStr =
"";
1354 for(
unsigned int c = 0; c < str.size(); ++c)
1355 if(str[c] >=
'A' && str[c] <=
'Z')
1358 if(c == configPos ||
1359 (c && str[c - 1] >=
'a' &&
1360 str[c - 1] <=
'z') ||
1361 (c && str[c - 1] >=
'A' &&
1362 str[c - 1] <=
'Z' &&
1363 c + 1 < str.size() && str[c + 1] >=
'a' && str[c + 1] <=
'z'))
1367 else if(str[c] >=
'a' && str[c] <=
'z')
1368 capsStr += char(str[c] - 32);
1369 else if(str[c] >=
'0' && str[c] <=
'9')
1372 __THROW__(std::string(
"TableBase::convertToCaps::") +
1373 "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)