#include <ContainerSchema.h>
Public Member Functions | |
IBlobStreamingService * | blobStreamingService () |
const std::string & | className () |
int | containerId () |
const std::string & | containerName () |
ContainerSchema (int containerId, const std::string &containerName, const Reflex::Type &containerType, DatabaseSession &session) | |
ContainerSchema (int containerId, const std::string &containerName, const std::string &className, DatabaseSession &session) | |
Sequences & | containerSequences () |
void | create () |
void | create (const Reflex::Type &dependentClass) |
DatabaseSession & | dbSession () |
void | drop () |
void | evolve (const Reflex::Type &dependentClass, MappingTree &baseMapping) |
void | evolve () |
bool | extendIfRequired (const Reflex::Type &dependentClass) |
MappingTree & | mapping (bool writeEnabled=false) |
MappingElement & | mappingForDependentClass (const Reflex::Type &dependentClass, bool writeEnabled=false) |
bool | mappingForDependentClasses (std::vector< MappingElement > &destination) |
const std::string & | mappingVersion () |
IReferenceHandler * | referenceHandler () |
void | setAccessPermission (const std::string &principal, bool forWrite) |
coral::ISchema & | storageSchema () |
const Reflex::Type & | type () |
~ContainerSchema () | |
Private Member Functions | |
void | extend (const Reflex::Type &dependentClass) |
void | getTableHierarchy (const std::set< std::string > &containerMappingVersions, std::vector< std::string > &destination) |
void | initClassDict () |
bool | loadMappingForDependentClass (const Reflex::Type &dependentClass) |
Private Attributes | |
Reflex::Type | m_classDict |
std::string | m_className |
int | m_containerId |
std::string | m_containerName |
Sequences | m_containerSchemaSequences |
std::map< std::string, MappingTree * > | m_dependentMappings |
bool | m_loaded |
MappingTree | m_mapping |
DatabaseSession & | m_session |
Definition at line 19 of file ContainerSchema.h.
ora::ContainerSchema::ContainerSchema | ( | int | containerId, |
const std::string & | containerName, | ||
const Reflex::Type & | containerType, | ||
DatabaseSession & | session | ||
) |
Definition at line 50 of file ContainerSchema.cc.
: m_containerId( containerId ), m_containerName( containerName ), m_className( containerType.Name( Reflex::SCOPED ) ), m_classDict( containerType ), m_session( session ), m_loaded( false ), m_containerSchemaSequences( session.schema() ), m_mapping(), m_dependentMappings(){ }
ora::ContainerSchema::ContainerSchema | ( | int | containerId, |
const std::string & | containerName, | ||
const std::string & | className, | ||
DatabaseSession & | session | ||
) |
Definition at line 65 of file ContainerSchema.cc.
: m_containerId( containerId ), m_containerName( containerName ), m_className( className ), m_classDict(), m_session( session ), m_loaded( false ), m_containerSchemaSequences( session.schema() ), m_mapping(), m_dependentMappings(){ }
ora::ContainerSchema::~ContainerSchema | ( | ) |
Definition at line 80 of file ContainerSchema.cc.
{ for( std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.begin(); iDep != m_dependentMappings.end(); ++iDep ){ delete iDep->second; } }
ora::IBlobStreamingService * ora::ContainerSchema::blobStreamingService | ( | ) |
Definition at line 339 of file ContainerSchema.cc.
{ return m_session.configuration().blobStreamingService(); }
const std::string & ora::ContainerSchema::className | ( | ) |
Definition at line 359 of file ContainerSchema.cc.
{ return m_className; }
int ora::ContainerSchema::containerId | ( | ) |
Definition at line 351 of file ContainerSchema.cc.
{ return m_containerId; }
const std::string & ora::ContainerSchema::containerName | ( | ) |
Definition at line 355 of file ContainerSchema.cc.
{ return m_containerName; }
ora::Sequences & ora::ContainerSchema::containerSequences | ( | ) |
Definition at line 335 of file ContainerSchema.cc.
{ return m_containerSchemaSequences; }
void ora::ContainerSchema::create | ( | const Reflex::Type & | dependentClass | ) |
Definition at line 266 of file ContainerSchema.cc.
References className(), ora::MappingToSchema::create(), ora::MappingRules::sequenceNameForDependentClass(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ std::string className = dependentClassDict.Name(Reflex::SCOPED); std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.insert( std::make_pair( className, new MappingTree ) ).first; MappingGenerator mapGen( m_session.schema().storageSchema() ); MappingToSchema mapping2Schema( m_session.schema().storageSchema() ); mapGen.createNewDependentMapping( dependentClassDict, m_mapping, *iDep->second ); mapping2Schema.create( *iDep->second ); std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName ); iDep->second->setVersion( newMappingVersion ); m_session.mappingDatabase().storeMapping( *iDep->second ); m_session.mappingDatabase().insertClassVersion( dependentClassDict, 1, m_containerId, newMappingVersion, true ); m_containerSchemaSequences.create( MappingRules::sequenceNameForDependentClass( m_containerName, className )); }
void ora::ContainerSchema::create | ( | ) |
Definition at line 93 of file ContainerSchema.cc.
References ora::MappingToSchema::create(), ora::MappingGenerator::createNewMapping(), ora::MappingRules::sequenceNameForContainer(), ora::MappingRules::sequenceNameForDependentClass(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ initClassDict(); // adding the new entry in the container table m_session.schema().containerHeaderTable().addContainer( m_containerId, m_containerName, m_className ); // creating and storing the mapping std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName ); MappingGenerator mapGen( m_session.schema().storageSchema() ); mapGen.createNewMapping( m_containerName, m_classDict, m_mapping ); m_mapping.setVersion( newMappingVersion ); m_session.mappingDatabase().storeMapping( m_mapping ); m_session.mappingDatabase().insertClassVersion( m_classDict, 0, m_containerId, newMappingVersion, true ); //m_mapping.tables(); // creating the sequences... m_containerSchemaSequences.create( MappingRules::sequenceNameForContainer( m_containerName ) ); for( std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.begin(); iDep != m_dependentMappings.end(); ++iDep ){ m_containerSchemaSequences.create( MappingRules::sequenceNameForDependentClass( m_containerName, iDep->first )); } // finally create the tables... MappingToSchema mapping2Schema( m_session.schema().storageSchema() ); mapping2Schema.create( m_mapping ); m_loaded = true; }
ora::DatabaseSession & ora::ContainerSchema::dbSession | ( | ) |
Definition at line 367 of file ContainerSchema.cc.
{ return m_session; }
void ora::ContainerSchema::drop | ( | ) |
Definition at line 137 of file ContainerSchema.cc.
References ora::MappingRules::sequenceNameForContainer(), and ora::MappingRules::sequenceNameForDependentClass().
{ std::set<std::string> containerMappingVersions; m_session.mappingDatabase().getMappingVersionsForContainer( m_containerId, containerMappingVersions ); std::vector<std::string> orderedTableList; getTableHierarchy( containerMappingVersions, orderedTableList ); // getting the dependent class list... std::set<std::string> depClasses; m_session.mappingDatabase().getDependentClassesForContainer( m_containerId, depClasses ); // now the mappings can be removed for( std::set<std::string>::const_iterator iM = containerMappingVersions.begin(); iM != containerMappingVersions.end(); ++iM ){ m_session.mappingDatabase().removeMapping( *iM ); } // removing the sequences m_containerSchemaSequences.erase( MappingRules::sequenceNameForContainer( m_containerName )); for(std::set<std::string>::const_iterator iDepCl = depClasses.begin(); iDepCl != depClasses.end(); iDepCl++){ m_containerSchemaSequences.erase( MappingRules::sequenceNameForDependentClass( m_containerName, *iDepCl ) ); } // removing the entry in the containers table m_session.schema().containerHeaderTable().removeContainer( m_containerId ); // finally drop the container tables following the hierarchy for(std::vector<std::string>::reverse_iterator iTable = orderedTableList.rbegin(); iTable != orderedTableList.rend(); iTable++ ){ m_session.schema().storageSchema().dropIfExistsTable( *iTable ); } }
void ora::ContainerSchema::evolve | ( | const Reflex::Type & | dependentClass, |
MappingTree & | baseMapping | ||
) |
Definition at line 189 of file ContainerSchema.cc.
References ora::MappingTree::className(), className(), AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().
{ std::string className = dependentClass.Name(Reflex::SCOPED); MappingGenerator mapGen( m_session.schema().storageSchema() ); std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.insert( std::make_pair( className, new MappingTree ) ).first; if( baseMapping.className() != dependentClass.Name(Reflex::SCOPED) ){ throwException("Provided base mapping does not map class \""+dependentClass.Name(Reflex::SCOPED)+"\".", "ContainerSchema::evolve"); } mapGen.createNewDependentMapping( dependentClass, m_mapping, baseMapping, *iDep->second ); std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName ); iDep->second->setVersion( newMappingVersion ); m_session.mappingDatabase().storeMapping( *iDep->second ); m_session.mappingDatabase().insertClassVersion( dependentClass, 1, m_containerId, newMappingVersion, false ); }
void ora::ContainerSchema::evolve | ( | ) |
Definition at line 171 of file ContainerSchema.cc.
References ora::MappingToSchema::alter(), AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().
{ MappingGenerator mapGen( m_session.schema().storageSchema() ); // retrieve the base mapping MappingTree baseMapping; if( !m_session.mappingDatabase().getBaseMappingForContainer( m_classDict.Name(Reflex::SCOPED), m_containerId, baseMapping )){ throwException("Base mapping has not been found in the database.", "ContainerSchema::evolve"); } mapGen.createNewMapping( m_containerName, m_classDict, baseMapping, m_mapping ); std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName ); m_mapping.setVersion( newMappingVersion ); m_session.mappingDatabase().storeMapping( m_mapping ); m_session.mappingDatabase().insertClassVersion( m_classDict, 0, m_containerId, newMappingVersion ); MappingToSchema mapping2Schema( m_session.schema().storageSchema() ); mapping2Schema.alter( m_mapping ); m_loaded = true; }
void ora::ContainerSchema::extend | ( | const Reflex::Type & | dependentClass | ) | [private] |
Definition at line 281 of file ContainerSchema.cc.
References className(), SurfaceDeformationFactory::create(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ std::string className = dependentClassDict.Name(Reflex::SCOPED); MappingTree baseMapping; if( !m_session.mappingDatabase().getBaseMappingForContainer( className, m_containerId, baseMapping ) ){ create( dependentClassDict ); } else { evolve( dependentClassDict, baseMapping ); } }
bool ora::ContainerSchema::extendIfRequired | ( | const Reflex::Type & | dependentClass | ) |
Definition at line 292 of file ContainerSchema.cc.
References run_regression::ret.
{ bool ret = false; if( ! loadMappingForDependentClass( dependentClassDict ) ){ extend( dependentClassDict ); ret = true; } return ret; }
void ora::ContainerSchema::getTableHierarchy | ( | const std::set< std::string > & | containerMappingVersions, |
std::vector< std::string > & | destination | ||
) | [private] |
Definition at line 119 of file ContainerSchema.cc.
References ora::addFromTableHierarchy(), ora::getTableHierarchyFromMappingElement(), ora::MappingElement::tableName(), and ora::MappingTree::topElement().
{ // building the table hierarchy std::map< std::string, std::set<std::string> > tableHierarchy; std::set<std::string> topLevelTables; // should be strictly only one! for( std::set<std::string>::const_iterator iV = containerMappingVersions.begin(); iV!= containerMappingVersions.end(); ++iV ){ MappingTree mapping; if( m_session.mappingDatabase().getMappingByVersion( *iV, mapping ) ){ topLevelTables.insert( mapping.topElement().tableName() ); getTableHierarchyFromMappingElement( mapping.topElement(), tableHierarchy ); } } for(std::set<std::string>::const_iterator iMainT = topLevelTables.begin(); iMainT != topLevelTables.end(); ++iMainT ){ addFromTableHierarchy( *iMainT, tableHierarchy, destination ); } }
void ora::ContainerSchema::initClassDict | ( | ) | [private] |
Definition at line 87 of file ContainerSchema.cc.
References ora::ClassUtils::lookupDictionary(), and ora::throwException().
{ if( !m_classDict ) m_classDict = ClassUtils::lookupDictionary( m_className, false ); if( !m_classDict ) throwException("Container class \""+m_className+"\" has not been found in the dictionary.", "ContainerSchema::initClassDict"); }
bool ora::ContainerSchema::loadMappingForDependentClass | ( | const Reflex::Type & | dependentClass | ) | [private] |
Definition at line 247 of file ContainerSchema.cc.
References className(), AlCaHLTBitMon_QueryRunRegistry::string, ora::throwException(), and ora::MappingDatabase::versionOfClass().
{ if( !dependentClassDict ) throwException("The dependent class has not been found in the dictionary.", "ContainerSchema::loadMappingForDependentClass"); std::string className = dependentClassDict.Name(Reflex::SCOPED); std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.find( className ); if( iDep == m_dependentMappings.end() ){ // not in cache, search the database... iDep = m_dependentMappings.insert( std::make_pair( className, new MappingTree ) ).first; if( ! m_session.mappingDatabase().getMappingForContainer( className, MappingDatabase::versionOfClass( dependentClassDict ), m_containerId, *iDep->second ) ){ m_dependentMappings.erase( className ); return false; } } return true; }
ora::MappingTree & ora::ContainerSchema::mapping | ( | bool | writeEnabled = false | ) |
Definition at line 222 of file ContainerSchema.cc.
References ora::Configuration::automaticSchemaEvolution(), lumiQueryAPI::msg, AlCaHLTBitMon_QueryRunRegistry::string, ora::throwException(), and ora::MappingDatabase::versionOfClass().
Referenced by ora::WriteBuffer::flush(), ora::DeleteBuffer::flush(), ora::UpdateBuffer::flush(), ora::IteratorBuffer::IteratorBuffer(), and ora::ReadBuffer::ReadBuffer().
{ initClassDict(); if(!m_loaded ){ std::string classVersion = MappingDatabase::versionOfClass( m_classDict ); if( !m_session.mappingDatabase().getMappingForContainer( m_className, classVersion, m_containerId, m_mapping ) ){ // if enabled, invoke the evolution if( writeEnabled && m_session.configuration().properties().getFlag( Configuration::automaticSchemaEvolution() )){ evolve(); } else { std::string msg( "No mapping available for the class=\""+m_className+"\" version=\""+classVersion+"\"." ); throwException( msg, "ContainerSchema::mapping"); } } else { m_loaded = true; } } if( m_mapping.topElement().find( m_className )==m_mapping.topElement().end() ){ throwException( "Mapping for container class \""+m_className+"\" could not be loaded.", "ContainerSchema::mapping"); } return m_mapping; }
ora::MappingElement & ora::ContainerSchema::mappingForDependentClass | ( | const Reflex::Type & | dependentClass, |
bool | writeEnabled = false |
||
) |
Definition at line 301 of file ContainerSchema.cc.
References ora::Configuration::automaticContainerCreation(), ora::Configuration::automaticDatabaseCreation(), ora::Configuration::automaticSchemaEvolution(), className(), SurfaceDeformationFactory::create(), AlCaHLTBitMon_QueryRunRegistry::string, and ora::throwException().
{ std::string className = dependentClassDict.Name(Reflex::SCOPED); if( ! loadMappingForDependentClass( dependentClassDict ) ){ if( writeEnabled ){ // check if a base is available: MappingTree baseMapping; if( !m_session.mappingDatabase().getBaseMappingForContainer( className, m_containerId, baseMapping ) ){ // mapping has to be generated from scratch if( m_session.configuration().properties().getFlag( Configuration::automaticDatabaseCreation()) || m_session.configuration().properties().getFlag( Configuration::automaticContainerCreation() ) ){ create( dependentClassDict ); } } else { // evolve if allowed if( m_session.configuration().properties().getFlag( Configuration::automaticSchemaEvolution() )){ evolve( dependentClassDict, baseMapping ); } } } } std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.find( className ); if( iDep == m_dependentMappings.end() ){ throwException( "Mapping for class \""+ className + "\" is not available in the database.", "ContainerSchema::mappingForDependentClass"); } return iDep->second->topElement(); }
bool ora::ContainerSchema::mappingForDependentClasses | ( | std::vector< MappingElement > & | destination | ) |
Definition at line 331 of file ContainerSchema.cc.
Referenced by ora::DeleteBuffer::flush(), and ora::UpdateBuffer::flush().
{ return m_session.mappingDatabase().getDependentMappingsForContainer( m_containerId, destination ); }
const std::string & ora::ContainerSchema::mappingVersion | ( | ) |
Definition at line 347 of file ContainerSchema.cc.
{ return m_mapping.version(); }
ora::IReferenceHandler * ora::ContainerSchema::referenceHandler | ( | ) |
Definition at line 343 of file ContainerSchema.cc.
{ return m_session.configuration().referenceHandler(); }
void ora::ContainerSchema::setAccessPermission | ( | const std::string & | principal, |
bool | forWrite | ||
) |
Definition at line 205 of file ContainerSchema.cc.
References cmsRelvalreport::principal(), and ora::setTableAccessPermission().
{ std::set<std::string> containerMappingVersions; m_session.mappingDatabase().getMappingVersionsForContainer( m_containerId, containerMappingVersions ); std::vector<std::string> orderedTableList; getTableHierarchy( containerMappingVersions, orderedTableList ); for( std::vector<std::string>::const_iterator iT = orderedTableList.begin(); iT != orderedTableList.end(); iT++ ){ setTableAccessPermission( m_session.schema().storageSchema().tableHandle( *iT ), principal, forWrite ); } }
coral::ISchema & ora::ContainerSchema::storageSchema | ( | ) |
Definition at line 363 of file ContainerSchema.cc.
Referenced by ora::DependentClassReader::build(), ora::WriteBuffer::flush(), ora::DeleteBuffer::flush(), and ora::UpdateBuffer::flush().
{ return m_session.schema().storageSchema(); }
const Reflex::Type & ora::ContainerSchema::type | ( | ) |
Definition at line 217 of file ContainerSchema.cc.
Referenced by ora::WriteBuffer::flush(), and ora::UpdateBuffer::flush().
{ initClassDict(); return m_classDict; }
Reflex::Type ora::ContainerSchema::m_classDict [private] |
Definition at line 84 of file ContainerSchema.h.
std::string ora::ContainerSchema::m_className [private] |
Definition at line 83 of file ContainerSchema.h.
int ora::ContainerSchema::m_containerId [private] |
Definition at line 81 of file ContainerSchema.h.
std::string ora::ContainerSchema::m_containerName [private] |
Definition at line 82 of file ContainerSchema.h.
Definition at line 87 of file ContainerSchema.h.
std::map<std::string,MappingTree*> ora::ContainerSchema::m_dependentMappings [private] |
Definition at line 89 of file ContainerSchema.h.
bool ora::ContainerSchema::m_loaded [private] |
Definition at line 86 of file ContainerSchema.h.
MappingTree ora::ContainerSchema::m_mapping [private] |
Definition at line 88 of file ContainerSchema.h.
DatabaseSession& ora::ContainerSchema::m_session [private] |
Definition at line 85 of file ContainerSchema.h.