Index: src/libchcore/TSQLiteSerializer.cpp =================================================================== diff -u -N -r11b0a299be97bc3afaa633d6522c17b214ba3b79 -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TSQLiteSerializer.cpp (.../TSQLiteSerializer.cpp) (revision 11b0a299be97bc3afaa633d6522c17b214ba3b79) +++ src/libchcore/TSQLiteSerializer.cpp (.../TSQLiteSerializer.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -26,85 +26,84 @@ #include "TSimpleTimer.h" #include "SerializerTrace.h" -BEGIN_CHCORE_NAMESPACE - -using namespace sqlite; - -TSQLiteSerializer::TSQLiteSerializer(const TSmartPath& pathDB, const ISerializerSchemaPtr& spSchema) : - m_spDatabase(new TSQLiteDatabase(pathDB)), - m_spSchema(spSchema) +namespace chcore { - if(!m_spDatabase || !m_spSchema) - THROW_CORE_EXCEPTION(eErr_InvalidArgument); + using namespace sqlite; - // initialize db params - SetupDBOptions(); + TSQLiteSerializer::TSQLiteSerializer(const TSmartPath& pathDB, const ISerializerSchemaPtr& spSchema) : + m_spDatabase(new TSQLiteDatabase(pathDB)), + m_spSchema(spSchema) + { + if (!m_spDatabase || !m_spSchema) + THROW_CORE_EXCEPTION(eErr_InvalidArgument); - m_spSchema->Setup(m_spDatabase); -} + // initialize db params + SetupDBOptions(); -TSQLiteSerializer::~TSQLiteSerializer() -{ - // clear the containers first, so that we can safely get rid of the strings pool - m_mapContainers.clear(); - m_poolStrings.Clear(false); -} + m_spSchema->Setup(m_spDatabase); + } -ISerializerContainerPtr TSQLiteSerializer::GetContainer(const TString& strContainerName) -{ - ContainerMap::iterator iterMap = m_mapContainers.find(strContainerName); - if(iterMap == m_mapContainers.end()) - iterMap = m_mapContainers.insert(std::make_pair( - strContainerName, - TSQLiteSerializerContainerPtr(new TSQLiteSerializerContainer(strContainerName, m_spDatabase, m_poolStrings)))).first; + TSQLiteSerializer::~TSQLiteSerializer() + { + // clear the containers first, so that we can safely get rid of the strings pool + m_mapContainers.clear(); + m_poolStrings.Clear(false); + } - return iterMap->second; -} + ISerializerContainerPtr TSQLiteSerializer::GetContainer(const TString& strContainerName) + { + ContainerMap::iterator iterMap = m_mapContainers.find(strContainerName); + if (iterMap == m_mapContainers.end()) + iterMap = m_mapContainers.insert(std::make_pair( + strContainerName, + TSQLiteSerializerContainerPtr(new TSQLiteSerializerContainer(strContainerName, m_spDatabase, m_poolStrings)))).first; -TSmartPath TSQLiteSerializer::GetLocation() const -{ - return m_spDatabase->GetLocation(); -} + return iterMap->second; + } -void TSQLiteSerializer::Flush() -{ - DBTRACE0(_T(" ## Serializer::Flush() - started\n")); + TSmartPath TSQLiteSerializer::GetLocation() const + { + return m_spDatabase->GetLocation(); + } - TSQLiteTransaction tran(m_spDatabase); + void TSQLiteSerializer::Flush() + { + DBTRACE0(_T(" ## Serializer::Flush() - started\n")); - TSimpleTimer timer(true); + TSQLiteTransaction tran(m_spDatabase); - for(ContainerMap::iterator iterContainer = m_mapContainers.begin(); iterContainer != m_mapContainers.end(); ++iterContainer) - { - iterContainer->second->Flush(); - } + TSimpleTimer timer(true); - unsigned long long ullFlushGatherTime = timer.Checkpoint(); ullFlushGatherTime; + for (ContainerMap::iterator iterContainer = m_mapContainers.begin(); iterContainer != m_mapContainers.end(); ++iterContainer) + { + iterContainer->second->Flush(); + } - tran.Commit(); + unsigned long long ullFlushGatherTime = timer.Checkpoint(); ullFlushGatherTime; - unsigned long long ullFlushCommitTime = timer.Checkpoint(); ullFlushCommitTime; - DBTRACE2(_T(" ## Serializer::Flush() - container flushes: %I64u ms, transaction commit: %I64u ms\n"), ullFlushGatherTime, ullFlushCommitTime); + tran.Commit(); - m_mapContainers.clear(); - m_poolStrings.Clear(); + unsigned long long ullFlushCommitTime = timer.Checkpoint(); ullFlushCommitTime; + DBTRACE2(_T(" ## Serializer::Flush() - container flushes: %I64u ms, transaction commit: %I64u ms\n"), ullFlushGatherTime, ullFlushCommitTime); - unsigned long long ullFlushClearTime = timer.Checkpoint(); ullFlushClearTime; - DBTRACE1(_T(" ## Serializer::Flush() - container clearing: %I64u ms\n"), ullFlushClearTime); -} + m_mapContainers.clear(); + m_poolStrings.Clear(); -void TSQLiteSerializer::SetupDBOptions() -{ -/* - TSQLiteStatement tStatement(m_spDatabase); - tStatement.Prepare(_T("PRAGMA JOURNAL_MODE=WAL")); - TSQLiteStatement::EStepResult eResult = tStatement.Step(); - if(eResult != TSQLiteStatement::eStep_HasRow) - THROW_CORE_EXCEPTION(eErr_CannotSetDatabaseOptions); + unsigned long long ullFlushClearTime = timer.Checkpoint(); ullFlushClearTime; + DBTRACE1(_T(" ## Serializer::Flush() - container clearing: %I64u ms\n"), ullFlushClearTime); + } - TString strResult = tStatement.GetText(0); - if(strResult != _T("wal")) - THROW_CORE_EXCEPTION(eErr_CannotSetDatabaseOptions);*/ -} + void TSQLiteSerializer::SetupDBOptions() + { + /* + TSQLiteStatement tStatement(m_spDatabase); + tStatement.Prepare(_T("PRAGMA JOURNAL_MODE=WAL")); + TSQLiteStatement::EStepResult eResult = tStatement.Step(); + if(eResult != TSQLiteStatement::eStep_HasRow) + THROW_CORE_EXCEPTION(eErr_CannotSetDatabaseOptions); -END_CHCORE_NAMESPACE + TString strResult = tStatement.GetText(0); + if(strResult != _T("wal")) + THROW_CORE_EXCEPTION(eErr_CannotSetDatabaseOptions);*/ + } +}