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::DatabaseUtilitySession Class Reference

#include <DatabaseUtilitySession.h>

Public Member Functions

Handle< DatabaseContainercontainerHandle (const std::string &name)
 
 DatabaseUtilitySession (DatabaseSession &dbSession)
 
bool dumpMapping (const std::string &mappingVersion, std::ostream &outputStream)
 
void eraseMapping (const std::string &mappingVersion)
 
void importContainer (const std::string &sourceConnectionString, const std::string &containerName)
 
void importContainerSchema (const std::string &sourceConnectionString, const std::string &containerName)
 
std::map< std::string,
std::string > 
listMappings (int containerId)
 
std::set< std::string > listMappingVersions (int containerId)
 
virtual ~DatabaseUtilitySession ()
 

Private Member Functions

bool existsContainer (const std::string &containerName)
 
Handle< ora::DatabaseContainerimportContainerSchema (const std::string &containerName, DatabaseSession &sourceDbSession)
 

Private Attributes

DatabaseSessionm_session
 

Detailed Description

Definition at line 14 of file DatabaseUtilitySession.h.

Constructor & Destructor Documentation

ora::DatabaseUtilitySession::DatabaseUtilitySession ( DatabaseSession dbSession)
explicit

Definition at line 13 of file DatabaseUtilitySession.cc.

13  :
14  m_session( dbSession ){
15 }
ora::DatabaseUtilitySession::~DatabaseUtilitySession ( )
virtual

Definition at line 17 of file DatabaseUtilitySession.cc.

17  {
18 }

Member Function Documentation

ora::Handle< ora::DatabaseContainer > ora::DatabaseUtilitySession::containerHandle ( const std::string &  name)

Definition at line 227 of file DatabaseUtilitySession.cc.

References ora::throwException().

227  {
228  if( !m_session.exists() ){
229  throwException( "ORA Database not found in \""+m_session.connectionString()+"\".",
230  "DatabaseUtilitySession::containerHandle");
231 
232  }
233  m_session.open();
234  return m_session.containerHandle( name );
235 }
Handle< DatabaseContainer > containerHandle(const std::string &name)
const std::string & connectionString()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
bool ora::DatabaseUtilitySession::dumpMapping ( const std::string &  mappingVersion,
std::ostream &  outputStream 
)

Definition at line 32 of file DatabaseUtilitySession.cc.

References alignCSCRings::dest, and ora::MappingTree::printXML().

33  {
34  MappingTree dest;
35  if(m_session.mappingDatabase().getMappingByVersion( mappingVersion, dest )){
36  dest.printXML( outputStream );
37  return true;
38  }
39  return false;
40 }
MappingDatabase & mappingDatabase()
bool getMappingByVersion(const std::string &version, MappingTree &destination)
void ora::DatabaseUtilitySession::eraseMapping ( const std::string &  mappingVersion)

Definition at line 218 of file DatabaseUtilitySession.cc.

References ora::throwException().

218  {
219  if( !m_session.exists() ){
220  throwException( "ORA Database not found in \""+m_session.connectionString()+"\".",
221  "DatabaseUtilitySession::eraseMapping");
222 
223  }
224  m_session.mappingDatabase().removeMapping( mappingVersion );
225 }
const std::string & connectionString()
MappingDatabase & mappingDatabase()
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
void removeMapping(const std::string &version)
bool ora::DatabaseUtilitySession::existsContainer ( const std::string &  containerName)
private

Definition at line 184 of file DatabaseUtilitySession.cc.

References newFWLiteAna::found.

184  {
185  bool found = false;
186  for( std::map<int, Handle<DatabaseContainer> >::const_iterator iC = m_session.containers().begin();
187  iC != m_session.containers().end(); ++iC ){
188  if( iC->second->name() == containerName ) {
189  found = true;
190  break;
191  }
192  }
193  return found;
194 }
const std::map< int, Handle< DatabaseContainer > > & containers()
void ora::DatabaseUtilitySession::importContainer ( const std::string &  sourceConnectionString,
const std::string &  containerName 
)

Definition at line 196 of file DatabaseUtilitySession.cc.

References ora::DatabaseSession::connect(), generateEDF::cont, AlCaHLTBitMon_QueryRunRegistry::data, edm::TypeWithDict::destruct(), ora::DatabaseContainer::flush(), ora::IteratorBuffer::getItem(), ora::DatabaseContainer::insertItem(), ora::DatabaseContainer::iteratorBuffer(), ora::IteratorBuffer::next(), and ora::DatabaseContainer::type().

197  {
198  DatabaseSession sourceSession( m_session.connectionPool() );
199  sourceSession.connect(sourceConnectionString, true );
200  sourceSession.startTransaction( true );
201  Handle<ora::DatabaseContainer> newCont = importContainerSchema(containerName, sourceSession );
202  Handle<ora::DatabaseContainer> cont = sourceSession.containerHandle( containerName );
203  Handle<IteratorBuffer> iterator = cont->iteratorBuffer();
204  std::vector<void*> objects;
205  const edm::TypeWithDict& contType = cont->type();
206  while( iterator->next() ){
207  void* data = iterator->getItem();
208  objects.push_back( data );
209  newCont->insertItem( data, contType );
210  }
211  newCont->flush();
212  for( std::vector<void*>::const_iterator iO = objects.begin(); iO != objects.end(); iO++ ){
213  contType.destruct( *iO );
214  }
215  sourceSession.commitTransaction();
216 }
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
boost::shared_ptr< ConnectionPool > & connectionPool()
void importContainerSchema(const std::string &sourceConnectionString, const std::string &containerName)
void destruct(void *address, bool dealloc=true) const
void ora::DatabaseUtilitySession::importContainerSchema ( const std::string &  sourceConnectionString,
const std::string &  containerName 
)

Definition at line 174 of file DatabaseUtilitySession.cc.

References ora::DatabaseSession::connect().

175  {
176  DatabaseSession sourceSession( m_session.connectionPool() );
177  sourceSession.connect(sourceConnectionString, true );
178  sourceSession.startTransaction( true );
179  importContainerSchema(containerName, sourceSession );
180  sourceSession.commitTransaction();
181 }
boost::shared_ptr< ConnectionPool > & connectionPool()
void importContainerSchema(const std::string &sourceConnectionString, const std::string &containerName)
ora::Handle< ora::DatabaseContainer > ora::DatabaseUtilitySession::importContainerSchema ( const std::string &  containerName,
DatabaseSession sourceDbSession 
)
private

third evolve the schema for all the further versions involved

Definition at line 42 of file DatabaseUtilitySession.cc.

References ora::Configuration::automaticDatabaseCreation(), className(), ora::DatabaseContainer::className(), ora::MappingTree::className(), generateEDF::cont, ora::DatabaseSession::containerHandle(), plotBeamSpotDB::first, ora::MappingDatabase::getBaseMappingForContainer(), ora::MappingDatabase::getClassVersionListForMappingVersion(), ora::MappingDatabase::getDependentClassesForContainer(), ora::MappingDatabase::getMappingByVersion(), ora::MappingDatabase::getMappingVersionsForContainer(), ora::DatabaseContainer::id(), ora::DatabaseSession::mappingDatabase(), ora::DatabaseSession::open(), ora::MappingRules::sequenceNameForContainer(), ora::MappingRules::sequenceNameForDependentClass(), AlCaHLTBitMon_QueryRunRegistry::string, ora::throwException(), and ora::MappingTree::version().

43  {
44  if(!m_session.exists()){
46  m_session.create();
47  m_session.open();
48  } else {
49  throwException( "ORA Database not found in \""+m_session.connectionString()+"\".",
50  "DatabaseUtilitySession::importContainerSchema");
51  }
52  } else {
53  m_session.open();
54  if( existsContainer( containerName ) ){
55  throwException( "A Container named \""+containerName+"\" already exists in the database.",
56  "DatabaseUtilitySession::importContainerSchema" );
57  }
58  }
59  sourceSession.open();
60  Sequences containerSchemaSequences( m_session.schema() );
61  Handle<ora::DatabaseContainer> cont = sourceSession.containerHandle( containerName );
62  // first create the container locally:
63  Handle<ora::DatabaseContainer> newCont = m_session.addContainer( containerName, cont->className() );
64  cont->className();
65  MappingToSchema mapping2Schema( m_session.schema().storageSchema() );
66  std::set<std::string> existingVersions = m_session.mappingDatabase().versions();
67  std::set<std::string> baseVersions;
68  // first create the cont base schema
69  MappingTree baseMapping;
70  if(!sourceSession.mappingDatabase().getBaseMappingForContainer( cont->className(), cont->id(), baseMapping )){
71  throwException( "Base mapping for class \""+cont->className()+"\" has not been found in the database.",
72  "DatabaseUtilitySession::importContainerSchema");
73  }
74  std::set<std::string> classVersions;
75  if(!sourceSession.mappingDatabase().getClassVersionListForMappingVersion( baseMapping.version(), classVersions )){
76  throwException( "No class versions found for mapping \""+baseMapping.version()+"\".",
77  "DatabaseUtilitySession::importContainerSchema");
78  }
79  if( existingVersions.find( baseMapping.version() )!= existingVersions.end() ){
80  throwException("Mapping version \""+baseMapping.version()+"\" for base mapping of class \""+cont->className()+"\" already exists in the database.","DatabaseUtilitySession::importContainerSchema");
81  }
82  if( !mapping2Schema.check( baseMapping ) ){
83  throwException("Schema base for class \""+baseMapping.className()+"\" cannot be replicated, because some schema objects have been found with the same name.","DatabaseUtilitySession::importContainerSchema");
84  }
85  baseVersions.insert( baseMapping.version() );
86  existingVersions.insert( baseMapping.version() );
87  m_session.mappingDatabase().storeMapping( baseMapping );
88  bool first = true;
89  for( std::set<std::string>::const_iterator iCv = classVersions.begin(); iCv != classVersions.end(); ++iCv ){
90  m_session.mappingDatabase().insertClassVersion( cont->className(), *iCv , 0, newCont->id(), baseMapping.version(), first );
91  first = false;
92  }
93  // ...the main container sequence...
94  containerSchemaSequences.create( MappingRules::sequenceNameForContainer( containerName ));
95  // ...the main tables
96  mapping2Schema.create( baseMapping );
97  // second create the base dependencies if any
98  std::set<std::string> dependentClasses;
99  sourceSession.mappingDatabase().getDependentClassesForContainer( cont->id(), dependentClasses );
100  for( std::set<std::string>::const_iterator iCl = dependentClasses.begin(); iCl != dependentClasses.end(); ++iCl ){
101  MappingTree baseDepMapping;
102  if(!sourceSession.mappingDatabase().getBaseMappingForContainer( *iCl, cont->id(), baseDepMapping )){
103  throwException( "Base mapping for class \""+*iCl+"\" has not been found in the database.",
104  "DatabaseUtilitySession::importContainerSchema");
105  }
106  std::set<std::string> depClassVersions;
107  if(!sourceSession.mappingDatabase().getClassVersionListForMappingVersion( baseDepMapping.version(), depClassVersions )){
108  throwException( "No class versions found for mapping \""+baseDepMapping.version()+"\".",
109  "DatabaseUtilitySession::importContainerSchema");
110  }
111  if( existingVersions.find( baseDepMapping.version() )!= existingVersions.end() ){
112  throwException("Mapping version \""+baseDepMapping.version()+"\" for base mapping of class \""+*iCl+"\" already exists in the database.","DatabaseUtilitySession::importContainerSchema");
113  }
114  if( !mapping2Schema.check( baseDepMapping ) ){
115  throwException("Schema base for class \""+baseDepMapping.className()+"\" cannot be replicated, because some schema objects have been found with the same name.","DatabaseUtilitySession::importContainerSchema");
116  }
117  baseVersions.insert( baseDepMapping.version() );
118  existingVersions.insert( baseDepMapping.version() );
119  m_session.mappingDatabase().storeMapping( baseDepMapping );
120  first = true;
121  for( std::set<std::string>::const_iterator iCv = depClassVersions.begin(); iCv != depClassVersions.end(); ++iCv ){
122  m_session.mappingDatabase().insertClassVersion( *iCl, *iCv , 1, newCont->id(), baseDepMapping.version(), first );
123  first = false;
124  }
125  // create the dep classes sequences.
126  containerSchemaSequences.create( MappingRules::sequenceNameForDependentClass( containerName, *iCl ));
127  // create the dep tables
128  mapping2Schema.create( baseDepMapping );
129  }
131  std::set<std::string> allVersions;
132  if(!sourceSession.mappingDatabase().getMappingVersionsForContainer( cont->id(), allVersions )){
133  std::stringstream mess;
134  mess << "No mapping versions found for container id="<<cont->id();
135  throwException( mess.str(), "DatabaseUtilitySession::importContainerSchema");
136  }
137  for( std::set<std::string>::const_iterator iVer = allVersions.begin(); iVer != allVersions.end(); ++iVer ){
138  // skip the bases
139  if( baseVersions.find( *iVer )== baseVersions.end() ){
140  MappingTree evMapping;
141  if(!sourceSession.mappingDatabase().getMappingByVersion( *iVer, evMapping) ){
142  throwException("Mapping version \""+*iVer+"\" has not been found in the database.",
143  "DatabaseUtilitySession::importContainerSchema");
144  }
145  std::set<std::string> cvs;
146  if(!sourceSession.mappingDatabase().getClassVersionListForMappingVersion( evMapping.version(), cvs )){
147  throwException( "No class versions found for mapping \""+evMapping.version()+"\".",
148  "DatabaseUtilitySession::importContainerSchema");
149  }
150  if( existingVersions.find( *iVer )!= existingVersions.end() ){
151  throwException("Mapping version \""+*iVer+"\" for mapping of class \""+evMapping.className()+"\" already exists in the database.","DatabaseUtilitySession::importContainerSchema");
152  }
153  if( !mapping2Schema.check( evMapping ) ){
154  throwException("Evolved schema for class \""+evMapping.className()+"\" cannot be replicated, because some schema objects have been found with the same name.","DatabaseUtilitySession::importContainerSchema");
155  }
156  m_session.mappingDatabase().storeMapping( evMapping );
157  existingVersions.insert( evMapping.version() );
158  int depIndex = 0;
159  std::string className = evMapping.className();
160  if( evMapping.className() != baseMapping.className() ){
161  // dependencies
162  depIndex = 1;
163  }
164  for( std::set<std::string>::const_iterator iCv = cvs.begin(); iCv != cvs.end(); ++iCv ){
165  m_session.mappingDatabase().insertClassVersion( evMapping.className(), *iCv , depIndex, newCont->id(), evMapping.version() );
166  }
167  // then evolve the schema
168  mapping2Schema.alter( evMapping );
169  }
170  }
171  return newCont;
172 }
const std::string & connectionString()
bool getFlag(const std::string &flagName) const
Definition: Properties.cc:36
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
Properties & properties()
static std::string automaticDatabaseCreation()
IDatabaseSchema & schema()
void storeMapping(const MappingTree &mappingStructure)
const std::string & className()
coral::ISchema & storageSchema()
MappingDatabase & mappingDatabase()
void create(const std::string &userSchemaVersion=std::string(""))
const std::set< std::string > & versions()
void insertClassVersion(const edm::TypeWithDict &dictionaryEntry, int dependencyIndex, int containerId, const std::string &mappingVersion, bool asBase=false)
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
Configuration & configuration()
bool existsContainer(const std::string &containerName)
static std::string sequenceNameForContainer(const std::string &containerName)
Definition: MappingRules.cc:15
static std::string sequenceNameForDependentClass(const std::string &containerName, const std::string &className)
Definition: MappingRules.cc:21
std::string className(const T &t)
Definition: ClassName.h:30
Handle< ora::DatabaseContainer > addContainer(const std::string &containerName, const std::string &className)
std::map< std::string, std::string > ora::DatabaseUtilitySession::listMappings ( int  containerId)

Definition at line 26 of file DatabaseUtilitySession.cc.

26  {
27  std::map<std::string,std::string> versionMap;
28  m_session.mappingDatabase().getClassVersionListForContainer( containerId, versionMap );
29  return versionMap;
30 }
MappingDatabase & mappingDatabase()
bool getClassVersionListForContainer(int containerId, std::map< std::string, std::string > &versionMap)
std::set< std::string > ora::DatabaseUtilitySession::listMappingVersions ( int  containerId)

Definition at line 20 of file DatabaseUtilitySession.cc.

20  {
21  std::set<std::string> mappingList;
22  m_session.mappingDatabase().getMappingVersionsForContainer( containerId, mappingList );
23  return mappingList;
24 }
bool getMappingVersionsForContainer(int containerId, std::set< std::string > &versionList)
MappingDatabase & mappingDatabase()

Member Data Documentation

DatabaseSession& ora::DatabaseUtilitySession::m_session
private

Definition at line 42 of file DatabaseUtilitySession.h.