#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 std::string &className, DatabaseSession &session) | |
ContainerSchema (int containerId, const std::string &containerName, const Reflex::Type &containerType, 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 () |
coral::ISchema & | storageSchema () |
const Reflex::Type & | type () |
~ContainerSchema () | |
Private Member Functions | |
void | extend (const Reflex::Type &dependentClass) |
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 60 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 75 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 90 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 302 of file ContainerSchema.cc.
{ return m_session.configuration().blobStreamingService(); }
const std::string & ora::ContainerSchema::className | ( | ) |
Definition at line 322 of file ContainerSchema.cc.
{ return m_className; }
int ora::ContainerSchema::containerId | ( | ) |
Definition at line 314 of file ContainerSchema.cc.
{ return m_containerId; }
const std::string & ora::ContainerSchema::containerName | ( | ) |
Definition at line 318 of file ContainerSchema.cc.
{ return m_containerName; }
ora::Sequences & ora::ContainerSchema::containerSequences | ( | ) |
Definition at line 298 of file ContainerSchema.cc.
{ return m_containerSchemaSequences; }
void ora::ContainerSchema::create | ( | ) |
Definition at line 103 of file ContainerSchema.cc.
References ora::MappingToSchema::create(), and ora::MappingGenerator::createNewMapping().
{ initClassDict(); std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName ); MappingGenerator mapGen( m_session.schema().storageSchema() ); mapGen.createNewMapping( m_containerName, m_classDict, m_mapping ); //if(!mapGen.createNewMapping( m_containerName, m_classDict, m_mapping )){ // throwException("Mapping generation failed.", // "ContainerSchema::create"); //} m_mapping.setVersion( newMappingVersion ); m_session.mappingDatabase().storeMapping( m_mapping ); m_session.mappingDatabase().insertClassVersion( m_classDict, 0, m_containerId, newMappingVersion, true ); MappingToSchema mapping2Schema( m_session.schema().storageSchema() ); m_mapping.tables(); mapping2Schema.create( m_mapping ); m_loaded = true; }
void ora::ContainerSchema::create | ( | const Reflex::Type & | dependentClass | ) |
Definition at line 230 of file ContainerSchema.cc.
References className(), and ora::MappingToSchema::create().
{ 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 ); }
ora::DatabaseSession & ora::ContainerSchema::dbSession | ( | ) |
Definition at line 330 of file ContainerSchema.cc.
{ return m_session; }
void ora::ContainerSchema::drop | ( | ) |
Definition at line 122 of file ContainerSchema.cc.
References ora::addFromTableHierarchy(), ora::MappingTree::className(), ora::getTableHierarchyFromMappingElement(), ora::MappingRules::sequenceNameForContainer(), ora::MappingRules::sequenceNameForDependentClass(), ora::MappingElement::tableName(), and ora::MappingTree::topElement().
{ std::set<std::string> containerMappingVersions; if( m_session.mappingDatabase().getMappingVersionsForContainer( m_containerId, containerMappingVersions )){ 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 ); m_containerSchemaSequences.erase( MappingRules::sequenceNameForDependentClass( m_containerName, mapping.className())); } } std::vector<std::string> orderedTableList; for(std::set<std::string>::const_iterator iMainT = topLevelTables.begin(); iMainT != topLevelTables.end(); ++iMainT ){ addFromTableHierarchy( *iMainT, tableHierarchy, orderedTableList ); } for(std::vector<std::string>::reverse_iterator iTable = orderedTableList.rbegin(); iTable != orderedTableList.rend(); iTable++ ){ m_session.schema().storageSchema().dropIfExistsTable( *iTable ); } } for( std::set<std::string>::const_iterator iM = containerMappingVersions.begin(); iM != containerMappingVersions.end(); ++iM ){ m_session.mappingDatabase().removeMapping( *iM ); } m_containerSchemaSequences.erase( MappingRules::sequenceNameForContainer( m_containerName )); }
void ora::ContainerSchema::evolve | ( | const Reflex::Type & | dependentClass, |
MappingTree & | baseMapping | ||
) |
Definition at line 174 of file ContainerSchema.cc.
References ora::MappingTree::className(), className(), 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 156 of file ContainerSchema.cc.
References ora::MappingToSchema::alter(), 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 244 of file ContainerSchema.cc.
References className(), and SurfaceDeformationFactory::create().
{ 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 255 of file ContainerSchema.cc.
References runTheMatrix::ret.
{ bool ret = false; if( ! loadMappingForDependentClass( dependentClassDict ) ){ extend( dependentClassDict ); ret = true; } return ret; }
void ora::ContainerSchema::initClassDict | ( | ) | [private] |
Definition at line 97 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 214 of file ContainerSchema.cc.
References className(), and ora::throwException().
{ 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( dependentClassDict, m_containerId, *iDep->second ) ){ m_dependentMappings.erase( className ); return false; } } return true; }
ora::MappingTree & ora::ContainerSchema::mapping | ( | bool | writeEnabled = false | ) |
Definition at line 194 of file ContainerSchema.cc.
References ora::Configuration::automaticSchemaEvolution(), and ora::throwException().
Referenced by ora::DeleteBuffer::DeleteBuffer(), ora::IteratorBuffer::IteratorBuffer(), ora::ReadBuffer::ReadBuffer(), ora::UpdateBuffer::UpdateBuffer(), and ora::WriteBuffer::WriteBuffer().
{ initClassDict(); if(!m_loaded ){ if( !m_session.mappingDatabase().getMappingForContainer( m_classDict, m_containerId, m_mapping ) ){ // if enabled, invoke the evolution if( writeEnabled && m_session.configuration().properties().getFlag( Configuration::automaticSchemaEvolution() )){ evolve(); } } 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 264 of file ContainerSchema.cc.
References ora::Configuration::automaticContainerCreation(), ora::Configuration::automaticDatabaseCreation(), ora::Configuration::automaticSchemaEvolution(), className(), SurfaceDeformationFactory::create(), 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 294 of file ContainerSchema.cc.
Referenced by ora::DeleteBuffer::DeleteBuffer(), and ora::UpdateBuffer::UpdateBuffer().
{ return m_session.mappingDatabase().getDependentMappingsForContainer( m_containerId, destination ); }
const std::string & ora::ContainerSchema::mappingVersion | ( | ) |
Definition at line 310 of file ContainerSchema.cc.
{ return m_mapping.version(); }
ora::IReferenceHandler * ora::ContainerSchema::referenceHandler | ( | ) |
Definition at line 306 of file ContainerSchema.cc.
{ return m_session.configuration().referenceHandler(); }
coral::ISchema & ora::ContainerSchema::storageSchema | ( | ) |
Definition at line 326 of file ContainerSchema.cc.
Referenced by ora::DependentClassReader::build().
{ return m_session.schema().storageSchema(); }
const Reflex::Type & ora::ContainerSchema::type | ( | ) |
Definition at line 190 of file ContainerSchema.cc.
Referenced by ora::UpdateBuffer::UpdateBuffer(), and ora::WriteBuffer::WriteBuffer().
{ return m_classDict; }
Reflex::Type ora::ContainerSchema::m_classDict [private] |
Definition at line 81 of file ContainerSchema.h.
std::string ora::ContainerSchema::m_className [private] |
Definition at line 80 of file ContainerSchema.h.
int ora::ContainerSchema::m_containerId [private] |
Definition at line 78 of file ContainerSchema.h.
std::string ora::ContainerSchema::m_containerName [private] |
Definition at line 79 of file ContainerSchema.h.
Definition at line 84 of file ContainerSchema.h.
std::map<std::string,MappingTree*> ora::ContainerSchema::m_dependentMappings [private] |
Definition at line 86 of file ContainerSchema.h.
bool ora::ContainerSchema::m_loaded [private] |
Definition at line 83 of file ContainerSchema.h.
MappingTree ora::ContainerSchema::m_mapping [private] |
Definition at line 85 of file ContainerSchema.h.
DatabaseSession& ora::ContainerSchema::m_session [private] |
Definition at line 82 of file ContainerSchema.h.