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