CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondCore/ORA/src/Sequences.cc

Go to the documentation of this file.
00001 #include "CondCore/ORA/interface/Exception.h"
00002 #include "Sequences.h"
00003 #include "IDatabaseSchema.h"
00004 
00005 ora::Sequences::Sequences( ora::IDatabaseSchema& schema ):
00006   m_lastIds(),
00007   m_schema( schema){
00008 }
00009 
00010 ora::Sequences::~Sequences(){
00011 }
00012 
00013 void ora::Sequences::create( const std::string& sequenceName ){
00014   m_schema.sequenceTable().add( sequenceName );
00015 }
00016 
00017 int ora::Sequences::getNextId( const std::string& sequenceName, bool sinchronize ){
00018   int next = 0;
00019   std::map<std::string,int>::iterator iS = m_lastIds.find( sequenceName );
00020   if( iS == m_lastIds.end() ){
00021     bool found = m_schema.sequenceTable().getLastId( sequenceName, next );
00022     if( ! found ) {
00023       throwException("Sequence \""+sequenceName+"\" does not exists.","Sequences::getNextId");
00024     } else {
00025       next += 1;
00026     }
00027     m_lastIds.insert( std::make_pair( sequenceName, next ));
00028   } else {
00029     next = ++iS->second;
00030   }
00031 
00032   if( sinchronize){
00033     m_schema.sequenceTable().sinchronize( sequenceName, next );
00034   }  
00035   return next;
00036 }
00037 
00038 void ora::Sequences::sinchronize( const std::string& sequenceName ){
00039   std::map<std::string,int>::iterator iS = m_lastIds.find( sequenceName );
00040   if( iS != m_lastIds.end() ){
00041     int lastOnDb = 0;
00042     m_schema.sequenceTable().getLastId( sequenceName, lastOnDb );
00043     if( lastOnDb < iS->second ) m_schema.sequenceTable().sinchronize( sequenceName, iS->second );
00044     m_lastIds.erase( sequenceName );
00045   }
00046 }
00047 
00048 void ora::Sequences::sinchronizeAll(){
00049   for( std::map<std::string,int>::iterator iS = m_lastIds.begin();
00050        iS != m_lastIds.end(); iS++ ){
00051     int lastOnDb = 0;
00052     m_schema.sequenceTable().getLastId( iS->first, lastOnDb );
00053     if( lastOnDb < iS->second ) m_schema.sequenceTable().sinchronize( iS->first, iS->second );    
00054   }
00055   clear();
00056 }
00057 
00058 void ora::Sequences::erase( const std::string& sequenceName ){
00059   m_schema.sequenceTable().erase( sequenceName );
00060 }
00061 
00062 void ora::Sequences::clear(){
00063   m_lastIds.clear();
00064 }
00065 
00066 ora::NamedSequence::NamedSequence( const std::string& sequenceName, ora::IDatabaseSchema& dbSchema ):
00067   m_name( sequenceName ),
00068   m_sequences( dbSchema ){
00069 }
00070 
00071 ora::NamedSequence::~NamedSequence(){
00072 }
00073 
00074 void ora::NamedSequence::create(){
00075   m_sequences.create( m_name );
00076 }
00077 
00078 int ora::NamedSequence::getNextId( bool sinchronize ){
00079   return m_sequences.getNextId( m_name, sinchronize );
00080 }
00081 
00082 void ora::NamedSequence::sinchronize(){
00083   m_sequences.sinchronize( m_name );
00084 }
00085 
00086 void ora::NamedSequence::erase(){
00087   m_sequences.erase( m_name );
00088 }
00089 
00090 void ora::NamedSequence::clear(){
00091   m_sequences.clear();
00092 }
00093