📄 csqlconnectionimpl.cpp
字号:
#include "CSqlConnectionImpl.h" #include "CSqlConnection.h"#include "comlog.h"class CSqlConnection ;CSqlConnectionManager*CSqlConnectionManager::s_singleManger=NULL ;CSqlConnectionManager::CSqlConnectionManager(){}/*! Destroys the object and frees any allocated resources. All open Connection connections are closed. All database connections are deleted.*/CSqlConnectionManager::~CSqlConnectionManager(){ map<string,CSqlConnection*>:: iterator it=dbMap.begin(); while(it!=dbMap.end()) { (it->second)->close(); delete it->second ; it->second=NULL ; ++it ; }}CSqlConnectionManager*CSqlConnectionManager::instance(){ #if defined(_REENTRANT) ZcMutexLocker singleManger_locker(zc_global_mutexpool->get((void*)(&CSqlConnectionManager::s_singleManger))); #endif LOG(NULL,0,"instance()"); if(s_singleManger==NULL) { s_singleManger=new CSqlConnectionManager(); } return s_singleManger ;}/*! Returns the database connection called \a name. If \a open is TRUE, the database connection is opened. If \a name does not exist in the list of managed databases, 0 is returned.*/CSqlConnection *CSqlConnectionManager::connection(const string&name,bool open){ if(!contains(name)) { return NULL ; } CSqlConnectionManager*sqlConnection=instance(); CSqlConnection*db=sqlConnection->dbMap[name]; if(!db) { return NULL ; } if(!db->isOpen()&&open) { db->open(); } return db ;}/*! Returns TRUE if the list of database connections contains \a name; otherwise returns FALSE.*/bool CSqlConnectionManager::contains(const string&name){ LOG1(NULL,0,"调用CSqlConnectionManager类方法contains(...)判断连接[%s]是否存在",name.c_str()); CSqlConnectionManager *sqlConnection=instance(); CSqlConnection *db=sqlConnection->dbMap[name]; if(db) { return TRUE ; } return FALSE ;}/*================================================================================** 主要功能: 增加连接。如果重名,先删除旧的连接。** 入口参数: ** 序号 参数类新 参数名称 作用 说明** 1 CSqlConnection * db 连接** 2 const string& name 连接名称 ** 出口参数: 类型: CSqlConnection * 作用:加入的连接** 修改记录:** 序号 修改人 修改日期 修改内容 修改目的** =================================================================================== */CSqlConnection *CSqlConnectionManager::addConnection(CSqlConnection*db,const string&name){ LOG1(NULL,0,"调用CSqlConnectionManager类方法addConnection(...)增加连接[%s]",\ name.c_str()); CSqlConnectionManager*sqlConnection=instance(); if(sqlConnection==NULL) { return NULL ; } if(contains(name)) { LOG1(NULL,0,"警告:连接[%s]已经存在,删除该连接",name.c_str()); sqlConnection->removeConnection(name); } else { LOG1(NULL,0,"连接[%s]不存在,增加该连接",name.c_str()); sqlConnection->dbMap[name]=db ; } return db ;}/*================================================================================** 函数名称: CSqlConnection *** CSqlConnectionManager::removeConnection (const string & name)** 主要功能: 删除连接。** 入口参数: ** 序号 参数类新 参数名称 作用 说明** 1 CSqlConnection * db 连接** 2 const string& name 连接名称 ** 出口参数: 类型: CSqlConnection * 作用:加入的连接** 修改记录:** 序号 修改人 修改日期 修改内容 修改目的** =================================================================================== */void CSqlConnectionManager::removeConnection(const string&name){ CSqlConnectionManager*sqlConnection=instance(); CSqlConnection*db=sqlConnection->dbMap[name]; if(db) { delete db ; db=NULL ; sqlConnection->dbMap.erase(name); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -