CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ora::ContainerSchema Class Reference

#include <ContainerSchema.h>

Public Member Functions

IBlobStreamingServiceblobStreamingService ()
 
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)
 
SequencescontainerSequences ()
 
void create ()
 
void create (const Reflex::Type &dependentClass)
 
DatabaseSessiondbSession ()
 
void drop ()
 
void evolve ()
 
void evolve (const Reflex::Type &dependentClass, MappingTree &baseMapping)
 
bool extendIfRequired (const Reflex::Type &dependentClass)
 
MappingTreemapping (bool writeEnabled=false)
 
MappingElementmappingForDependentClass (const Reflex::Type &dependentClass, bool writeEnabled=false)
 
bool mappingForDependentClasses (std::vector< MappingElement > &destination)
 
const std::string & mappingVersion ()
 
IReferenceHandlerreferenceHandler ()
 
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
 
DatabaseSessionm_session
 

Detailed Description

Definition at line 19 of file ContainerSchema.h.

Constructor & Destructor Documentation

ora::ContainerSchema::ContainerSchema ( int  containerId,
const std::string &  containerName,
const Reflex::Type &  containerType,
DatabaseSession session 
)

Definition at line 60 of file ContainerSchema.cc.

63  :
66  m_className( containerType.Name( Reflex::SCOPED ) ),
67  m_classDict( containerType ),
68  m_session( session ),
69  m_loaded( false ),
71  m_mapping(),
73 }
std::map< std::string, MappingTree * > m_dependentMappings
Reflex::Type m_classDict
Sequences m_containerSchemaSequences
DatabaseSession & m_session
std::string m_containerName
const std::string & containerName()
ora::ContainerSchema::ContainerSchema ( int  containerId,
const std::string &  containerName,
const std::string &  className,
DatabaseSession session 
)

Definition at line 75 of file ContainerSchema.cc.

78  :
82  m_classDict(),
83  m_session( session ),
84  m_loaded( false ),
86  m_mapping(),
88 }
std::map< std::string, MappingTree * > m_dependentMappings
Reflex::Type m_classDict
Sequences m_containerSchemaSequences
const std::string & className()
DatabaseSession & m_session
std::string m_containerName
const std::string & containerName()
ora::ContainerSchema::~ContainerSchema ( )

Definition at line 90 of file ContainerSchema.cc.

90  {
91  for( std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.begin();
92  iDep != m_dependentMappings.end(); ++iDep ){
93  delete iDep->second;
94  }
95 }
std::map< std::string, MappingTree * > m_dependentMappings

Member Function Documentation

ora::IBlobStreamingService * ora::ContainerSchema::blobStreamingService ( )

Definition at line 302 of file ContainerSchema.cc.

302  {
304 }
DatabaseSession & m_session
IBlobStreamingService * blobStreamingService()
Configuration & configuration()
const std::string & ora::ContainerSchema::className ( )

Definition at line 322 of file ContainerSchema.cc.

322  {
323  return m_className;
324 }
int ora::ContainerSchema::containerId ( )

Definition at line 314 of file ContainerSchema.cc.

314  {
315  return m_containerId;
316 }
const std::string & ora::ContainerSchema::containerName ( )

Definition at line 318 of file ContainerSchema.cc.

318  {
319  return m_containerName;
320 }
std::string m_containerName
ora::Sequences & ora::ContainerSchema::containerSequences ( )

Definition at line 298 of file ContainerSchema.cc.

298  {
300 }
Sequences m_containerSchemaSequences
void ora::ContainerSchema::create ( )

Definition at line 103 of file ContainerSchema.cc.

References ora::MappingToSchema::create(), and ora::MappingGenerator::createNewMapping().

103  {
104 
105  initClassDict();
106  std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName );
107  MappingGenerator mapGen( m_session.schema().storageSchema() );
108  mapGen.createNewMapping( m_containerName, m_classDict, m_mapping );
109  //if(!mapGen.createNewMapping( m_containerName, m_classDict, m_mapping )){
110  // throwException("Mapping generation failed.",
111  // "ContainerSchema::create");
112  //}
113  m_mapping.setVersion( newMappingVersion );
115  m_session.mappingDatabase().insertClassVersion( m_classDict, 0, m_containerId, newMappingVersion, true );
116  MappingToSchema mapping2Schema( m_session.schema().storageSchema() );
117  m_mapping.tables();
118  mapping2Schema.create( m_mapping );
119  m_loaded = true;
120 }
void insertClassVersion(const Reflex::Type &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false)
IDatabaseSchema & schema()
void storeMapping(const MappingTree &mappingStructure)
Reflex::Type m_classDict
DatabaseSession & m_session
std::vector< TableInfo > tables() const
Definition: MappingTree.cc:120
coral::ISchema & storageSchema()
MappingDatabase & mappingDatabase()
std::string newMappingVersionForContainer(const std::string &className)
std::string m_containerName
void setVersion(const std::string &version)
Definition: MappingTree.h:129
void ora::ContainerSchema::create ( const Reflex::Type &  dependentClass)

Definition at line 230 of file ContainerSchema.cc.

References className(), and ora::MappingToSchema::create().

230  {
231  std::string className = dependentClassDict.Name(Reflex::SCOPED);
232  std::map<std::string,MappingTree*>::iterator iDep =
233  m_dependentMappings.insert( std::make_pair( className, new MappingTree ) ).first;
234  MappingGenerator mapGen( m_session.schema().storageSchema() );
235  MappingToSchema mapping2Schema( m_session.schema().storageSchema() );
236  mapGen.createNewDependentMapping( dependentClassDict, m_mapping, *iDep->second );
237  mapping2Schema.create( *iDep->second );
238  std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName );
239  iDep->second->setVersion( newMappingVersion );
240  m_session.mappingDatabase().storeMapping( *iDep->second );
241  m_session.mappingDatabase().insertClassVersion( dependentClassDict, 1, m_containerId, newMappingVersion, true );
242 }
std::map< std::string, MappingTree * > m_dependentMappings
void insertClassVersion(const Reflex::Type &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false)
IDatabaseSchema & schema()
void storeMapping(const MappingTree &mappingStructure)
const std::string & className()
DatabaseSession & m_session
coral::ISchema & storageSchema()
MappingDatabase & mappingDatabase()
std::string newMappingVersionForContainer(const std::string &className)
std::string m_containerName
ora::DatabaseSession & ora::ContainerSchema::dbSession ( )

Definition at line 330 of file ContainerSchema.cc.

330  {
331  return m_session;
332 }
DatabaseSession & 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().

122  {
123 
124  std::set<std::string> containerMappingVersions;
125  if( m_session.mappingDatabase().getMappingVersionsForContainer( m_containerId, containerMappingVersions )){
126  std::map< std::string, std::set<std::string> > tableHierarchy;
127  std::set<std::string> topLevelTables; // should be strictly only one!
128  for( std::set<std::string>::const_iterator iV = containerMappingVersions.begin();
129  iV!= containerMappingVersions.end(); ++iV ){
130  MappingTree mapping;
131  if( m_session.mappingDatabase().getMappingByVersion( *iV, mapping ) ){
132  topLevelTables.insert( mapping.topElement().tableName() );
133  getTableHierarchyFromMappingElement( mapping.topElement(), tableHierarchy );
135  }
136  }
137 
138  std::vector<std::string> orderedTableList;
139  for(std::set<std::string>::const_iterator iMainT = topLevelTables.begin();
140  iMainT != topLevelTables.end(); ++iMainT ){
141  addFromTableHierarchy( *iMainT, tableHierarchy, orderedTableList );
142  }
143  for(std::vector<std::string>::reverse_iterator iTable = orderedTableList.rbegin();
144  iTable != orderedTableList.rend(); iTable++ ){
145  m_session.schema().storageSchema().dropIfExistsTable( *iTable );
146  }
147  }
148  for( std::set<std::string>::const_iterator iM = containerMappingVersions.begin();
149  iM != containerMappingVersions.end(); ++iM ){
151  }
153 
154 }
void addFromTableHierarchy(const std::string &tableName, std::map< std::string, std::set< std::string > > &tableList, std::vector< std::string > &orderedList)
void erase(const std::string &sequenceName)
Definition: Sequences.cc:53
void getTableHierarchyFromMappingElement(const MappingElement &source, std::map< std::string, std::set< std::string > > &tableList)
IDatabaseSchema & schema()
bool getMappingVersionsForContainer(int containerId, std::set< std::string > &versionList)
Sequences m_containerSchemaSequences
DatabaseSession & m_session
coral::ISchema & storageSchema()
MappingDatabase & mappingDatabase()
bool getMappingByVersion(const std::string &version, MappingTree &destination)
std::string m_containerName
MappingTree & mapping(bool writeEnabled=false)
static std::string sequenceNameForContainer(const std::string &containerName)
Definition: MappingRules.cc:14
static std::string sequenceNameForDependentClass(const std::string &containerName, const std::string &className)
Definition: MappingRules.cc:20
void removeMapping(const std::string &version)
void ora::ContainerSchema::evolve ( )

Definition at line 156 of file ContainerSchema.cc.

References ora::MappingToSchema::alter(), and ora::throwException().

156  {
157  MappingGenerator mapGen( m_session.schema().storageSchema() );
158  // retrieve the base mapping
159  MappingTree baseMapping;
160  if( !m_session.mappingDatabase().getBaseMappingForContainer( m_classDict.Name(Reflex::SCOPED), m_containerId, baseMapping )){
161  throwException("Base mapping has not been found in the database.",
162  "ContainerSchema::evolve");
163  }
164  mapGen.createNewMapping( m_containerName, m_classDict, baseMapping, m_mapping );
165  std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName );
166  m_mapping.setVersion( newMappingVersion );
169  MappingToSchema mapping2Schema( m_session.schema().storageSchema() );
170  mapping2Schema.alter( m_mapping );
171  m_loaded = true;
172 }
bool getBaseMappingForContainer(const std::string &className, int containerId, MappingTree &destination)
void insertClassVersion(const Reflex::Type &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false)
IDatabaseSchema & schema()
void storeMapping(const MappingTree &mappingStructure)
Reflex::Type m_classDict
DatabaseSession & m_session
coral::ISchema & storageSchema()
MappingDatabase & mappingDatabase()
std::string newMappingVersionForContainer(const std::string &className)
std::string m_containerName
void setVersion(const std::string &version)
Definition: MappingTree.h:129
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::ContainerSchema::evolve ( const Reflex::Type &  dependentClass,
MappingTree baseMapping 
)

Definition at line 174 of file ContainerSchema.cc.

References className(), ora::MappingTree::className(), and ora::throwException().

174  {
175  std::string className = dependentClass.Name(Reflex::SCOPED);
176  MappingGenerator mapGen( m_session.schema().storageSchema() );
177  std::map<std::string,MappingTree*>::iterator iDep =
178  m_dependentMappings.insert( std::make_pair( className, new MappingTree ) ).first;
179  if( baseMapping.className() != dependentClass.Name(Reflex::SCOPED) ){
180  throwException("Provided base mapping does not map class \""+dependentClass.Name(Reflex::SCOPED)+"\".",
181  "ContainerSchema::evolve");
182  }
183  mapGen.createNewDependentMapping( dependentClass, m_mapping, baseMapping, *iDep->second );
184  std::string newMappingVersion = m_session.mappingDatabase().newMappingVersionForContainer( m_containerName );
185  iDep->second->setVersion( newMappingVersion );
186  m_session.mappingDatabase().storeMapping( *iDep->second );
187  m_session.mappingDatabase().insertClassVersion( dependentClass, 1, m_containerId, newMappingVersion, false );
188 }
std::map< std::string, MappingTree * > m_dependentMappings
void insertClassVersion(const Reflex::Type &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false)
IDatabaseSchema & schema()
void storeMapping(const MappingTree &mappingStructure)
const std::string & className()
DatabaseSession & m_session
coral::ISchema & storageSchema()
MappingDatabase & mappingDatabase()
std::string newMappingVersionForContainer(const std::string &className)
std::string m_containerName
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void ora::ContainerSchema::extend ( const Reflex::Type &  dependentClass)
private

Definition at line 244 of file ContainerSchema.cc.

References className(), and SurfaceDeformationFactory::create().

Referenced by hltFindDuplicates.ModuleList::__init__(), Config.Process::load(), and Mixins._ValidatingParameterListBase::setValue().

244  {
245  std::string className = dependentClassDict.Name(Reflex::SCOPED);
246  MappingTree baseMapping;
248  m_containerId, baseMapping ) ){
249  create( dependentClassDict );
250  } else {
251  evolve( dependentClassDict, baseMapping );
252  }
253 }
bool getBaseMappingForContainer(const std::string &className, int containerId, MappingTree &destination)
const std::string & className()
DatabaseSession & m_session
MappingDatabase & mappingDatabase()
bool ora::ContainerSchema::extendIfRequired ( const Reflex::Type &  dependentClass)

Definition at line 255 of file ContainerSchema.cc.

References runTheMatrix::ret.

255  {
256  bool ret = false;
257  if( ! loadMappingForDependentClass( dependentClassDict ) ){
258  extend( dependentClassDict );
259  ret = true;
260  }
261  return ret;
262 }
bool loadMappingForDependentClass(const Reflex::Type &dependentClass)
void extend(const Reflex::Type &dependentClass)
void ora::ContainerSchema::initClassDict ( )
private

Definition at line 97 of file ContainerSchema.cc.

References ora::ClassUtils::lookupDictionary(), and ora::throwException().

97  {
99  if( !m_classDict ) throwException("Container class \""+m_className+"\" has not been found in the dictionary.",
100  "ContainerSchema::initClassDict");
101 }
Reflex::Type m_classDict
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
Reflex::Type lookupDictionary(const std::type_info &typeInfo, bool throwFlag=true)
Definition: ClassUtils.cc:84
bool ora::ContainerSchema::loadMappingForDependentClass ( const Reflex::Type &  dependentClass)
private

Definition at line 214 of file ContainerSchema.cc.

References className(), and ora::throwException().

214  {
215  if( !dependentClassDict ) throwException("The dependent class has not been found in the dictionary.",
216  "ContainerSchema::loadMappingForDependentClass");
217  std::string className = dependentClassDict.Name(Reflex::SCOPED);
218  std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.find( className );
219  if( iDep == m_dependentMappings.end() ){
220  // not in cache, search the database...
221  iDep = m_dependentMappings.insert( std::make_pair( className, new MappingTree ) ).first;
222  if( ! m_session.mappingDatabase().getMappingForContainer( dependentClassDict, m_containerId, *iDep->second ) ){
223  m_dependentMappings.erase( className );
224  return false;
225  }
226  }
227  return true;
228 }
std::map< std::string, MappingTree * > m_dependentMappings
bool getMappingForContainer(const Reflex::Type &containerClass, int containerId, MappingTree &destination)
const std::string & className()
DatabaseSession & m_session
MappingDatabase & mappingDatabase()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
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().

194  {
195  initClassDict();
196  if(!m_loaded ){
198  // if enabled, invoke the evolution
200  evolve();
201  }
202  } else {
203  m_loaded = true;
204  }
205 
206  }
208  throwException( "Mapping for container class \""+m_className+"\" could not be loaded.",
209  "ContainerSchema::mapping");
210  }
211  return m_mapping;
212 }
bool getFlag(const std::string &flagName) const
Definition: Properties.cc:36
Properties & properties()
bool getMappingForContainer(const Reflex::Type &containerClass, int containerId, MappingTree &destination)
Reflex::Type m_classDict
const MappingElement & topElement() const
Definition: MappingTree.h:139
DatabaseSession & m_session
iterator find(const std::string &key)
Retrieves a sub-element.
MappingDatabase & mappingDatabase()
iterator end()
Returns an iterator in the end of the sequence.
Configuration & configuration()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
static std::string automaticSchemaEvolution()
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().

265  {
266  std::string className = dependentClassDict.Name(Reflex::SCOPED);
267  if( ! loadMappingForDependentClass( dependentClassDict ) ){
268  if( writeEnabled ){
269  // check if a base is available:
270  MappingTree baseMapping;
272  m_containerId, baseMapping ) ){
273  // mapping has to be generated from scratch
276  create( dependentClassDict );
277  }
278  } else {
279  // evolve if allowed
281  evolve( dependentClassDict, baseMapping );
282  }
283  }
284  }
285  }
286  std::map<std::string,MappingTree*>::iterator iDep = m_dependentMappings.find( className );
287  if( iDep == m_dependentMappings.end() ){
288  throwException( "Mapping for class \""+ className + "\" is not available in the database.",
289  "ContainerSchema::mappingForDependentClass");
290  }
291  return iDep->second->topElement();
292 }
bool getFlag(const std::string &flagName) const
Definition: Properties.cc:36
bool getBaseMappingForContainer(const std::string &className, int containerId, MappingTree &destination)
Properties & properties()
std::map< std::string, MappingTree * > m_dependentMappings
static std::string automaticContainerCreation()
static std::string automaticDatabaseCreation()
Definition: Configuration.cc:5
const std::string & className()
DatabaseSession & m_session
MappingDatabase & mappingDatabase()
bool loadMappingForDependentClass(const Reflex::Type &dependentClass)
Configuration & configuration()
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
static std::string automaticSchemaEvolution()
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().

294  {
296 }
bool getDependentMappingsForContainer(int containerId, std::vector< MappingElement > &destination)
DatabaseSession & m_session
MappingDatabase & mappingDatabase()
const std::string & ora::ContainerSchema::mappingVersion ( )

Definition at line 310 of file ContainerSchema.cc.

310  {
311  return m_mapping.version();
312 }
const std::string & version() const
Definition: MappingTree.h:124
ora::IReferenceHandler * ora::ContainerSchema::referenceHandler ( )

Definition at line 306 of file ContainerSchema.cc.

306  {
308 }
DatabaseSession & m_session
IReferenceHandler * referenceHandler()
Configuration & configuration()
coral::ISchema & ora::ContainerSchema::storageSchema ( )

Definition at line 326 of file ContainerSchema.cc.

Referenced by ora::QVReader::build(), ora::DependentClassReader::build(), and ora::QVReader::selectionCount().

326  {
327  return m_session.schema().storageSchema();
328 }
IDatabaseSchema & schema()
DatabaseSession & m_session
coral::ISchema & storageSchema()
const Reflex::Type & ora::ContainerSchema::type ( )

Member Data Documentation

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.

Sequences ora::ContainerSchema::m_containerSchemaSequences
private

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.