#include <MappingDatabase.h>
Public Member Functions | |
void | clear () |
bool | getBaseMappingForContainer (const std::string &className, int containerId, MappingTree &destination) |
bool | getClassVersionListForContainer (int containerId, std::map< std::string, std::string > &versionMap) |
bool | getClassVersionListForMappingVersion (const std::string &mappingVersion, std::set< std::string > &destination) |
bool | getDependentClassesForContainer (int containerId, std::set< std::string > &list) |
bool | getDependentMappingsForContainer (int containerId, std::vector< MappingElement > &destination) |
bool | getMappingByVersion (const std::string &version, MappingTree &destination) |
bool | getMappingForContainer (const std::string &className, const std::string &classVersion, int containerId, MappingTree &destination) |
bool | getMappingVersionsForContainer (int containerId, std::set< std::string > &versionList) |
void | insertClassVersion (const Reflex::Type &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false) |
void | insertClassVersion (const std::string &className, const std::string &classVersion, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false) |
MappingDatabase (IDatabaseSchema &schema) | |
Constructor. | |
std::string | newMappingVersionForContainer (const std::string &className) |
std::string | newMappingVersionForDependentClass (const std::string &containerName, const std::string &className) |
void | removeMapping (const std::string &version) |
void | setMappingVersionForClass (const Reflex::Type &dictionaryEntry, int containerId, const std::string &mappingVersion, bool dependency=false) |
void | setUp () |
void | storeMapping (const MappingTree &mappingStructure) |
const std::set< std::string > & | versions () |
~MappingDatabase () | |
Destructor. | |
Static Public Member Functions | |
static std::string | versionOfClass (const Reflex::Type &dictionary) |
Private Member Functions | |
void | buildElement (MappingElement &parentElement, const std::string &scopeName, std::map< std::string, std::vector< MappingRawElement > > &innerElements) |
void | unfoldElement (const MappingElement &element, MappingRawData &destination) |
Private Attributes | |
bool | m_isLoaded |
NamedSequence | m_mappingSequence |
IDatabaseSchema & | m_schema |
The schema in use. | |
std::set< std::string > | m_versions |
Utility class to manage the object-relational mappings for the C++ classes.
Definition at line 27 of file MappingDatabase.h.
ora::MappingDatabase::MappingDatabase | ( | ora::IDatabaseSchema & | schema | ) | [explicit] |
Constructor.
Definition at line 58 of file MappingDatabase.cc.
: m_schema( schema ), m_mappingSequence( MappingRules::sequenceNameForMapping(), schema ), m_versions(), m_isLoaded( false ){ }
ora::MappingDatabase::~MappingDatabase | ( | ) |
void ora::MappingDatabase::buildElement | ( | MappingElement & | parentElement, |
const std::string & | scopeName, | ||
std::map< std::string, std::vector< MappingRawElement > > & | innerElements | ||
) | [private] |
Definition at line 22 of file MappingDatabase.cc.
References ora::MappingElement::appendSubElement(), ora::MappingElement::setColumnNames(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ std::map<std::string,std::vector<MappingRawElement> >::iterator iScope = innerElements.find(scopeName); if(iScope != innerElements.end()){ for( std::vector<MappingRawElement>::const_iterator iM = iScope->second.begin(); iM != iScope->second.end(); ++iM ){ MappingElement& element = parentElement.appendSubElement( iM->elementType, iM->variableName, iM->variableType, iM->tableName ); element.setColumnNames(iM->columns); std::string nextScope(scopeName); nextScope.append("::").append(iM->variableName); buildElement( element, nextScope, innerElements ); } } innerElements.erase(scopeName); }
void ora::MappingDatabase::clear | ( | void | ) |
Definition at line 321 of file MappingDatabase.cc.
{ m_versions.clear(); m_isLoaded = false; }
bool ora::MappingDatabase::getBaseMappingForContainer | ( | const std::string & | className, |
int | containerId, | ||
MappingTree & | destination | ||
) |
Definition at line 203 of file MappingDatabase.cc.
References ora::MappingRules::baseIdForClass(), ora::MappingTree::className(), className(), newFWLiteAna::found, run_regression::ret, AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ bool ret = false; std::string classId = MappingRules::baseIdForClass( className ); std::string mappingVersion(""); bool found = m_schema.mappingSchema().selectMappingVersion( classId, containerId, mappingVersion ); if( found ){ ret = getMappingByVersion( mappingVersion, destination ); if( !ret ){ throwException("Mapping version \""+mappingVersion+"\" not found.", "MappingDatabase::getBaseMappingForContainer"); } if( destination.className() != className ){ throwException("Mapping inconsistency detected for version=\""+mappingVersion+"\"", "MappingDatabase::getBaseMappingForContainer"); } } return ret; }
bool ora::MappingDatabase::getClassVersionListForContainer | ( | int | containerId, |
std::map< std::string, std::string > & | versionMap | ||
) |
Definition at line 263 of file MappingDatabase.cc.
{ return m_schema.mappingSchema().getClassVersionListForContainer( containerId, versionMap ); }
bool ora::MappingDatabase::getClassVersionListForMappingVersion | ( | const std::string & | mappingVersion, |
std::set< std::string > & | destination | ||
) |
Definition at line 245 of file MappingDatabase.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ return m_schema.mappingSchema().getClassVersionListForMappingVersion( mappingVersion, destination ); }
bool ora::MappingDatabase::getDependentClassesForContainer | ( | int | containerId, |
std::set< std::string > & | list | ||
) |
Definition at line 316 of file MappingDatabase.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
bool ora::MappingDatabase::getDependentMappingsForContainer | ( | int | containerId, |
std::vector< MappingElement > & | destination | ||
) |
Definition at line 225 of file MappingDatabase.cc.
References run_regression::ret, ora::throwException(), and ora::MappingTree::topElement().
{ bool ret = false; std::set<std::string> versions; if( m_schema.mappingSchema().getMappingVersionListForContainer( containerId, versions, true ) ){ ret = true; for( std::set<std::string>::iterator iM = versions.begin(); iM != versions.end(); ++iM ){ MappingTree mapping; if( ! getMappingByVersion( *iM, mapping )){ throwException("Mapping version \""+*iM+"\" not found.", "MappingDatabase::getDependentMappingsForContainer"); } destination.push_back( mapping.topElement() ); } } return ret; }
bool ora::MappingDatabase::getMappingByVersion | ( | const std::string & | version, |
MappingTree & | destination | ||
) |
Definition at line 127 of file MappingDatabase.cc.
References ora::MappingElement::classMappingElementType(), ora::MappingRawElement::columns, ora::MappingElement::dependencyMappingElementType(), ora::MappingRawData::elements, ora::MappingRawElement::elementType, ora::MappingRawElement::emptyScope(), run_regression::ret, ora::MappingElement::setColumnNames(), ora::MappingTree::setTopElement(), ora::MappingTree::setVersion(), ora::MappingRawElement::tableName, ora::throwException(), and ora::MappingRawElement::variableName.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ bool ret = false; MappingRawData mapData; if(m_schema.mappingSchema().getMapping( version, mapData )){ ret = true; MappingRawElement topLevelElement; bool topLevelFound = false; bool dependency = false; std::map<std::string, std::vector<MappingRawElement> > innerElements; for( std::map< int, MappingRawElement>::iterator iElem = mapData.elements.begin(); iElem != mapData.elements.end(); iElem++ ){ // first loading the top level elements if( iElem->second.scopeName == MappingRawElement::emptyScope() ){ if( iElem->second.elementType == MappingElement::classMappingElementType() || iElem->second.elementType == MappingElement::dependencyMappingElementType() ){ if( topLevelFound ){ throwException("Mapping inconsistent.More then one top level element found.", "MappingDatabase::getMappingByVersion"); } topLevelElement = iElem->second; if( topLevelElement.elementType == MappingElement::dependencyMappingElementType() ) dependency = true; topLevelFound = true; } } else { std::map<std::string, std::vector<MappingRawElement> >::iterator iN = innerElements.find( iElem->second.scopeName ); if(iN==innerElements.end()){ innerElements.insert( std::make_pair( iElem->second.scopeName, std::vector<MappingRawElement>(1,iElem->second) ) ); } else { iN->second.push_back( iElem->second ); } } } if( !topLevelFound ){ throwException( "Could not find top element for mapping version \""+version+"\".", "MappingDatabase::getMappingByVersion" ); } MappingElement& topElement = destination.setTopElement( topLevelElement.variableName, topLevelElement.tableName, dependency ); topElement.setColumnNames( topLevelElement.columns); buildElement( topElement, topLevelElement.variableName, innerElements ); destination.setVersion( version ); } return ret; }
bool ora::MappingDatabase::getMappingForContainer | ( | const std::string & | className, |
const std::string & | classVersion, | ||
int | containerId, | ||
MappingTree & | destination | ||
) |
Definition at line 178 of file MappingDatabase.cc.
References ora::MappingRules::classId(), ora::MappingTree::className(), className(), newFWLiteAna::found, run_regression::ret, AlCaHLTBitMon_QueryRunRegistry::string, ora::throwException(), and BeamSplash_cfg::version.
{ bool ret = false; // The classId parameter std::string classId = MappingRules::classId( className, classVersion ); std::string version(""); bool found = m_schema.mappingSchema().selectMappingVersion( classId, containerId, version ); if( found ){ ret = getMappingByVersion( version, destination ); if( !ret ){ throwException("Mapping version \""+version+"\" not found.", "MappingDatabase::getMappingForContainer"); } if( destination.className() != className ){ throwException("Mapping inconsistency detected for version=\""+version+"\"", "MappingDatabase::getMappingForContainer"); } } return ret; }
bool ora::MappingDatabase::getMappingVersionsForContainer | ( | int | containerId, |
std::set< std::string > & | versionList | ||
) |
Definition at line 304 of file MappingDatabase.cc.
Referenced by ora::DatabaseUtilitySession::importContainerSchema().
{ return m_schema.mappingSchema().getMappingVersionListForContainer( containerId, versionList ); }
void ora::MappingDatabase::insertClassVersion | ( | const Reflex::Type & | dictionaryEntry, |
int | dependencyIndex, | ||
int | containerId, | ||
const std::string & | mappingVersion, | ||
bool | asBase = false |
||
) |
Definition at line 269 of file MappingDatabase.cc.
References className(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ std::string className = dictionaryEntry.Name( Reflex::SCOPED ); std::string classVersion = versionOfClass( dictionaryEntry ); insertClassVersion( className, classVersion, depIndex, containerId, mappingVersion, asBase ); }
void ora::MappingDatabase::insertClassVersion | ( | const std::string & | className, |
const std::string & | classVersion, | ||
int | dependencyIndex, | ||
int | containerId, | ||
const std::string & | mappingVersion, | ||
bool | asBase = false |
||
) |
Definition at line 250 of file MappingDatabase.cc.
References ora::MappingRules::baseClassVersion(), ora::MappingRules::baseIdForClass(), ora::MappingRules::classId(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ std::string classId = MappingRules::classId( className, classVersion ); m_schema.mappingSchema().insertClassVersion( className, classVersion, classId, dependencyIndex, containerId, mappingVersion ); if( asBase ){ m_schema.mappingSchema().insertClassVersion( className, MappingRules::baseClassVersion(), MappingRules::baseIdForClass( className ), dependencyIndex, containerId, mappingVersion ); } }
std::string ora::MappingDatabase::newMappingVersionForContainer | ( | const std::string & | className | ) |
Definition at line 74 of file MappingDatabase.cc.
References newFWLiteAna::found, align_cfg::iteration, ora::MappingRules::newMappingVersionForContainer(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ if(!m_isLoaded){ m_schema.mappingSchema().getVersionList( m_versions ); m_isLoaded = true; } std::string newMappingVersion = ""; for ( int iteration = 0;; ++iteration ) { newMappingVersion = MappingRules::newMappingVersionForContainer( containerName, iteration ); bool found = false; for ( std::set<std::string>::reverse_iterator iVersion = m_versions.rbegin(); iVersion != m_versions.rend(); ++iVersion ) { if ( *iVersion == newMappingVersion ) { found = true; break; } } if ( ! found ){ m_versions.insert( newMappingVersion ); break; } } return newMappingVersion; }
std::string ora::MappingDatabase::newMappingVersionForDependentClass | ( | const std::string & | containerName, |
const std::string & | className | ||
) |
Definition at line 101 of file MappingDatabase.cc.
References newFWLiteAna::found, align_cfg::iteration, ora::MappingRules::newMappingVersionForDependentClass(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ if(!m_isLoaded){ m_schema.mappingSchema().getVersionList( m_versions ); m_isLoaded = true; } std::string newMappingVersion = ""; for ( int iteration = 0;; ++iteration ) { newMappingVersion = MappingRules::newMappingVersionForDependentClass( containerName, className, iteration ); bool found = false; for ( std::set<std::string>::reverse_iterator iVersion = m_versions.rbegin(); iVersion != m_versions.rend(); ++iVersion ) { if ( *iVersion == newMappingVersion ) { found = true; break; } } if ( ! found ){ m_versions.insert( newMappingVersion ); break; } } return newMappingVersion; }
void ora::MappingDatabase::removeMapping | ( | const std::string & | version | ) |
Definition at line 173 of file MappingDatabase.cc.
void ora::MappingDatabase::setMappingVersionForClass | ( | const Reflex::Type & | dictionaryEntry, |
int | containerId, | ||
const std::string & | mappingVersion, | ||
bool | dependency = false |
||
) |
Definition at line 279 of file MappingDatabase.cc.
References ora::MappingRules::classId(), className(), newFWLiteAna::found, and AlCaHLTBitMon_QueryRunRegistry::string.
{ std::string className = dictionaryEntry.Name( Reflex::SCOPED ); std::string classVersion = versionOfClass( dictionaryEntry ); std::string classId = MappingRules::classId( className, classVersion ); std::string mv(""); bool found = m_schema.mappingSchema().selectMappingVersion( classId, containerId, mv ); if( !found ){ int depIndex = 0; if( dependency ) depIndex = 1; m_schema.mappingSchema().insertClassVersion( className, classVersion, classId, depIndex, containerId, mappingVersion ); } else { m_schema.mappingSchema().setMappingVersion( classId, containerId, mappingVersion ); } }
void ora::MappingDatabase::setUp | ( | ) |
Definition at line 69 of file MappingDatabase.cc.
{ m_mappingSequence.create(); }
void ora::MappingDatabase::storeMapping | ( | const MappingTree & | mappingStructure | ) |
Definition at line 297 of file MappingDatabase.cc.
References ora::MappingTree::topElement(), and ora::MappingTree::version().
{ MappingRawData rowMapping( mapping.version() ); unfoldElement( mapping.topElement(), rowMapping ); m_mappingSequence.sinchronize(); m_schema.mappingSchema().storeMapping( rowMapping ); }
void ora::MappingDatabase::unfoldElement | ( | const MappingElement & | element, |
MappingRawData & | destination | ||
) | [private] |
Definition at line 42 of file MappingDatabase.cc.
References ora::MappingRawData::addElement(), ora::MappingElement::begin(), ora::MappingElement::columnNames(), ora::MappingRawElement::columns, HTMLExport::elem(), ora::MappingElement::elementType(), ora::MappingRawElement::elementType, ora::MappingElement::elementTypeAsString(), ora::MappingRawElement::emptyScope(), ora::MappingElement::end(), ora::MappingElement::scopeName(), ora::MappingRawElement::scopeName, ora::MappingRawElement::tableName, ora::MappingElement::tableName(), ora::MappingElement::variableName(), ora::MappingRawElement::variableName, ora::MappingRawElement::variableType, and ora::MappingElement::variableType().
{ int newElemId = m_mappingSequence.getNextId(); MappingRawElement& elem = destination.addElement( newElemId ); elem.elementType = MappingElement::elementTypeAsString( element.elementType() ); elem.scopeName = element.scopeName(); if(elem.scopeName.empty()) elem.scopeName = MappingRawElement::emptyScope(); elem.variableName = element.variableName(); elem.variableType = element.variableType(); elem.tableName = element.tableName(); elem.columns = element.columnNames(); for ( MappingElement::const_iterator iSubEl = element.begin(); iSubEl != element.end(); ++iSubEl) { unfoldElement( iSubEl->second, destination ); } }
std::string ora::MappingDatabase::versionOfClass | ( | const Reflex::Type & | dictionary | ) | [static] |
Definition at line 12 of file MappingDatabase.cc.
References className(), ora::MappingRules::classVersionPropertyNameInDictionary(), ora::MappingRules::defaultClassVersion(), and AlCaHLTBitMon_QueryRunRegistry::string.
Referenced by ora::ContainerSchema::loadMappingForDependentClass(), and ora::ContainerSchema::mapping().
{ std::string className = dictionary.Name(Reflex::SCOPED); Reflex::PropertyList classProps = dictionary.Properties(); std::string classVersion = MappingRules::defaultClassVersion(className); if(classProps.HasProperty(MappingRules::classVersionPropertyNameInDictionary())){ classVersion = classProps.PropertyAsString(MappingRules::classVersionPropertyNameInDictionary()); } return classVersion; }
const std::set< std::string > & ora::MappingDatabase::versions | ( | ) |
Definition at line 308 of file MappingDatabase.cc.
{ if(!m_isLoaded){ m_schema.mappingSchema().getVersionList( m_versions ); m_isLoaded = true; } return m_versions; }
bool ora::MappingDatabase::m_isLoaded [private] |
Definition at line 86 of file MappingDatabase.h.
Definition at line 84 of file MappingDatabase.h.
IDatabaseSchema& ora::MappingDatabase::m_schema [private] |
The schema in use.
Definition at line 83 of file MappingDatabase.h.
std::set<std::string> ora::MappingDatabase::m_versions [private] |
Definition at line 85 of file MappingDatabase.h.