CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Sequences.cc
Go to the documentation of this file.
2 #include "Sequences.h"
3 #include "IDatabaseSchema.h"
4 
6  m_lastIds(),
7  m_table( schema.sequenceTable()){
8 }
9 
11  m_lastIds(),
12  m_table( table ){
13 }
14 
16 }
17 
18 void ora::Sequences::create( const std::string& sequenceName ){
19  m_table.add( sequenceName );
20 }
21 
22 int ora::Sequences::getNextId( const std::string& sequenceName, bool sinchronize ){
23  int next = 0;
24  std::map<std::string,int>::iterator iS = m_lastIds.find( sequenceName );
25  if( iS == m_lastIds.end() ){
26  bool found = m_table.getLastId( sequenceName, next );
27  if( ! found ) {
28  throwException("Sequence \""+sequenceName+"\" does not exists.","Sequences::getNextId");
29  } else {
30  next += 1;
31  }
32  m_lastIds.insert( std::make_pair( sequenceName, next ));
33  } else {
34  next = ++iS->second;
35  }
36 
37  if( sinchronize){
38  m_table.sinchronize( sequenceName, next );
39  }
40  return next;
41 }
42 
43 void ora::Sequences::sinchronize( const std::string& sequenceName ){
44  std::map<std::string,int>::iterator iS = m_lastIds.find( sequenceName );
45  if( iS != m_lastIds.end() ){
46  int lastOnDb = 0;
47  m_table.getLastId( sequenceName, lastOnDb );
48  if( lastOnDb < iS->second ) m_table.sinchronize( sequenceName, iS->second );
49  m_lastIds.erase( sequenceName );
50  }
51 }
52 
54  for( std::map<std::string,int>::iterator iS = m_lastIds.begin();
55  iS != m_lastIds.end(); iS++ ){
56  int lastOnDb = 0;
57  m_table.getLastId( iS->first, lastOnDb );
58  if( lastOnDb < iS->second ) m_table.sinchronize( iS->first, iS->second );
59  }
60  clear();
61 }
62 
63 void ora::Sequences::erase( const std::string& sequenceName ){
64  m_table.erase( sequenceName );
65 }
66 
68  m_lastIds.clear();
69 }
70 
71 ora::NamedSequence::NamedSequence( const std::string& sequenceName, ora::IDatabaseSchema& dbSchema ):
72  m_name( sequenceName ),
73  m_sequences( dbSchema ){
74 }
75 
77 }
78 
80  m_sequences.create( m_name );
81 }
82 
83 int ora::NamedSequence::getNextId( bool sinchronize ){
84  return m_sequences.getNextId( m_name, sinchronize );
85 }
86 
88  m_sequences.sinchronize( m_name );
89 }
90 
92  m_sequences.erase( m_name );
93 }
94 
96  m_sequences.clear();
97 }
98 
list table
Definition: asciidump.py:386
Sequences(IDatabaseSchema &dbSchema)
Definition: Sequences.cc:5
NamedSequence(const std::string &sequenceName, IDatabaseSchema &dbSchema)
Definition: Sequences.cc:71
virtual ~NamedSequence()
Definition: Sequences.cc:76
void erase(const std::string &sequenceName)
Definition: Sequences.cc:63
virtual ~Sequences()
Definition: Sequences.cc:15
int getNextId(bool sinchronize=false)
Definition: Sequences.cc:83
U second(std::pair< T, U > const &p)
void sinchronize(const std::string &sequenceName)
Definition: Sequences.cc:43
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
void sinchronizeAll()
Definition: Sequences.cc:53
int getNextId(const std::string &sequenceName, bool sinchronize=false)
Definition: Sequences.cc:22
void clear()
Definition: Sequences.cc:67
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:10
void create(const std::string &sequenceName)
Definition: Sequences.cc:18