NCBI C++ ToolKit
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CConnection Class Reference

Search Toolkit Book for CConnection

#include "conn_impl.hpp"
(Private to src/dbapi.)

+ Inheritance diagram for CConnection:
+ Collaboration diagram for CConnection:

Public Member Functions

 CConnection (CDataSource *ds, EOwnership ownership)
 
virtual ~CConnection ()
 
virtual void SetMode (EConnMode mode)
 Set connection mode. More...
 
virtual void ResetMode (EConnMode mode)
 Reset connection mode. More...
 
virtual unsigned int GetModeMask ()
 Get mode mask. More...
 
virtual void ForceSingle (bool enable)
 Force single connection mode, default false. More...
 
virtual IDataSourceGetDataSource ()
 Get parent datasource object. More...
 
virtual void Connect (const string &user, const string &password, const string &server, const string &database=kEmptyStr)
 Connect to a database. More...
 
virtual void Connect (const CDBConnParams &params)
 Connect to a database. More...
 
virtual void ConnectValidated (IConnValidator &validator, const string &user, const string &password, const string &server, const string &database=kEmptyStr)
 Connect to a database using connect validator. More...
 
virtual IConnectionCloneConnection (EOwnership ownership)
 Clone existing connection. More...
 
virtual IStatementGetStatement ()
 Get statement object for regular SQL queries. More...
 
virtual ICallableStatementGetCallableStatement (const string &proc)
 Get callable statement object for stored procedures. More...
 
virtual ICursorGetCursor (const string &name, const string &sql, int batchSize)
 Get cursor object. More...
 
virtual IBulkInsertGetBulkInsert (const string &table_name)
 Create bulk insert object. More...
 
virtual IStatementCreateStatement ()
 Get statement object for regular SQL queries. More...
 
virtual ICallableStatementPrepareCall (const string &proc)
 Get callable statement object for stored procedures. More...
 
virtual ICursorCreateCursor (const string &name, const string &sql, int batchSize)
 Get cursor object. More...
 
virtual IBulkInsertCreateBulkInsert (const string &table_name)
 Create bulk insert object. More...
 
virtual void Close ()
 Close connecti. More...
 
virtual void Abort ()
 Abort connection. More...
 
virtual void SetTimeout (size_t nof_secs)
 Set connection timeout. More...
 
virtual void SetCancelTimeout (size_t nof_secs)
 Set timeout for command cancellation and connection closing. More...
 
virtual CDB_ConnectionGetCDB_Connection ()
 Returns the internal driver connection object. More...
 
virtual void SetDatabase (const string &name)
 Set current database. More...
 
virtual string GetDatabase ()
 Get current database. More...
 
virtual bool IsAlive ()
 Check if the connection is alive. More...
 
CConnectionClone ()
 
void SetDbName (const string &name, CDB_Connection *conn=0)
 
CDB_ConnectionCloneCDB_Conn ()
 
bool IsAux ()
 
virtual void Action (const CDbapiEvent &e)
 
virtual void MsgToEx (bool v)
 If enabled, redirects all error messages to CDB_MultiEx object (see below). More...
 
virtual CDB_MultiExGetErrorAsEx ()
 Returns all error messages as a CDB_MultiEx object. More...
 
virtual string GetErrorInfo ()
 Returns all error messages as a single string. More...
 
- Public Member Functions inherited from CActiveObject
 CActiveObject ()
 
virtual ~CActiveObject ()
 
void AddListener (CActiveObject *obj)
 
void RemoveListener (CActiveObject *obj)
 
void Notify (const CDbapiEvent &e)
 
string GetIdent () const
 
- Public Member Functions inherited from IEventListener
virtual ~IEventListener ()
 
- Public Member Functions inherited from IConnection
virtual ~IConnection ()
 Destructor. More...
 
ICallableStatementGetCallableStatement (const string &proc, int)
 
ICursorGetCursor (const string &name, const string &sql)
 
ICursorGetCursor (const string &name, const string &sql, int, int batchSize)
 
IBulkInsertGetBulkInsert (const string &table_name, unsigned int)
 
ICallableStatementPrepareCall (const string &proc, int)
 
ICursorCreateCursor (const string &name, const string &sql)
 
ICursorCreateCursor (const string &name, const string &sql, int, int batchSize)
 
IBulkInsertCreateBulkInsert (const string &table_name, unsigned int)
 
virtual size_t GetTimeout (void) const
 Get connection timeout. More...
 
virtual size_t GetCancelTimeout (void) const
 Get timeout for command cancellation and connection closing. More...
 

Protected Member Functions

 CConnection (class CDB_Connection *conn, CDataSource *ds)
 
CConnectionGetAuxConn ()
 
class CToMultiExHandlerGetHandler ()
 
void FreeResources ()
 
- Protected Member Functions inherited from CActiveObject
void SetIdent (const string &name)
 
TLListGetListenerList ()
 
- Protected Member Functions inherited from IEventListener
 IEventListener ()
 

Private Member Functions

void x_SendXactAbort (void)
 

Private Attributes

string m_database
 
class CDataSourcem_ds
 
CDB_Connectionm_connection
 
int m_connCounter
 
bool m_connUsed
 
unsigned int m_modeMask
 
bool m_forceSingle
 
CRef< CToMultiExHandlerm_multiExH
 
bool m_msgToEx
 
EOwnership m_ownership
 

Additional Inherited Members

- Public Types inherited from IConnection
enum  EConnMode { eBulkInsert = I_DriverContext::fBcpIn , ePasswordEncrypted = I_DriverContext::fPasswordEncrypted }
 Which connection mode. More...
 
- Protected Types inherited from CActiveObject
typedef list< CActiveObject * > TLList
 

Detailed Description

Definition at line 45 of file conn_impl.hpp.

Constructor & Destructor Documentation

◆ CConnection() [1/2]

CConnection::CConnection ( CDataSource ds,
EOwnership  ownership 
)

Definition at line 60 of file conn_impl.cpp.

References _TRACE, and CActiveObject::SetIdent().

Referenced by Clone(), and CloneConnection().

◆ ~CConnection()

CConnection::~CConnection ( void  )
virtual

◆ CConnection() [2/2]

CConnection::CConnection ( class CDB_Connection conn,
CDataSource ds 
)
protected

Definition at line 69 of file conn_impl.cpp.

References _TRACE, and CActiveObject::SetIdent().

Member Function Documentation

◆ Abort()

void CConnection::Abort ( )
virtual

Abort connection.

Implements IConnection.

Definition at line 308 of file conn_impl.cpp.

References CDB_Connection::Abort(), and GetCDB_Connection().

◆ Action()

void CConnection::Action ( const CDbapiEvent e)
virtual

◆ Clone()

CConnection * CConnection::Clone ( void  )

Definition at line 245 of file conn_impl.cpp.

References CConnection(), CHECK_NCBI_DBAPI, CloneCDB_Conn(), conn, m_connCounter, m_ds, m_msgToEx, and NULL.

Referenced by GetAuxConn().

◆ CloneCDB_Conn()

CDB_Connection * CConnection::CloneCDB_Conn ( )

◆ CloneConnection()

IConnection * CConnection::CloneConnection ( EOwnership  ownership)
virtual

Clone existing connection.

All settings are copied except message handlers Set ownership to eTakeOwnership to prevent deleting connection upon deleting parent object

Implements IConnection.

Definition at line 258 of file conn_impl.cpp.

References CActiveObject::AddListener(), CConnection(), CHECK_NCBI_DBAPI, CloneCDB_Conn(), conn, GetDatabase(), GetModeMask(), m_connection, m_database, m_ds, m_forceSingle, m_msgToEx, and NULL.

◆ Close()

void CConnection::Close ( )
virtual

Close connecti.

Implements IConnection.

Definition at line 303 of file conn_impl.cpp.

References FreeResources().

◆ Connect() [1/2]

void CConnection::Connect ( const CDBConnParams params)
virtual

Connect to a database.

Parameters
paramsConnection parameters. Parameters should include all necessary settings because all info set via SetMode() or ResetMode() will be ignored.

Implements IConnection.

Definition at line 131 of file conn_impl.cpp.

References CHECK_NCBI_DBAPI, CDB_Connection::DatabaseName(), CDataSource::GetDriverContext(), m_connection, m_database, m_ds, I_DriverContext::MakeConnection(), NULL, string, and x_SendXactAbort().

◆ Connect() [2/2]

void CConnection::Connect ( const string user,
const string password,
const string server,
const string database = kEmptyStr 
)
virtual

Connect to a database.

Parameters
userUser name.
passwordUser's password.
serverServer to connect to.
databaseDatabase to connect to.

Implements IConnection.

Definition at line 111 of file conn_impl.cpp.

References database, GetModeMask(), CDataSource::IsPoolUsed(), m_ds, and CDBDefaultConnParams::SetDatabaseName().

Referenced by ConnectValidated().

◆ ConnectValidated()

void CConnection::ConnectValidated ( IConnValidator validator,
const string user,
const string password,
const string server,
const string database = kEmptyStr 
)
virtual

Connect to a database using connect validator.

Parameters
validatorValidator implementation class.
userUser name.
passwordUser's password.
serverServer to connect to.
databaseDatabase to connect to.

Implements IConnection.

Definition at line 143 of file conn_impl.cpp.

References Connect(), database, GetModeMask(), CDataSource::IsPoolUsed(), m_ds, CDBDefaultConnParams::SetConnValidator(), and CDBDefaultConnParams::SetDatabaseName().

◆ CreateBulkInsert()

IBulkInsert * CConnection::CreateBulkInsert ( const string table_name)
virtual

Create bulk insert object.

Implements IConnection.

Definition at line 446 of file conn_impl.cpp.

References CActiveObject::AddListener(), GetAuxConn(), and table_name.

◆ CreateCursor()

ICursor * CConnection::CreateCursor ( const string name,
const string sql,
int  batchSize 
)
virtual

Get cursor object.

Implements IConnection.

Definition at line 433 of file conn_impl.cpp.

References CActiveObject::AddListener(), GetAuxConn(), and sql.

◆ CreateStatement()

IStatement * CConnection::CreateStatement ( )
virtual

Get statement object for regular SQL queries.

Implements IConnection.

Definition at line 410 of file conn_impl.cpp.

References CActiveObject::AddListener(), GetAuxConn(), and stmt.

◆ ForceSingle()

void CConnection::ForceSingle ( bool  enable)
virtual

Force single connection mode, default false.

Disable this mode before using BLOB output streams from IResultSet, because extra connection is needed in this case.

Implements IConnection.

Definition at line 99 of file conn_impl.cpp.

References m_forceSingle.

◆ FreeResources()

void CConnection::FreeResources ( )
protected

Definition at line 324 of file conn_impl.cpp.

References m_connection.

Referenced by Close(), and ~CConnection().

◆ GetAuxConn()

CConnection * CConnection::GetAuxConn ( )
protected

◆ GetBulkInsert()

IBulkInsert * CConnection::GetBulkInsert ( const string table_name)
virtual

Create bulk insert object.

Parameters
table_nametable name.
nof_colsNumber of columns.

Implements IConnection.

Definition at line 389 of file conn_impl.cpp.

References CActiveObject::AddListener(), and table_name.

◆ GetCallableStatement()

ICallableStatement * CConnection::GetCallableStatement ( const string proc)
virtual

Get callable statement object for stored procedures.

Parameters
procStored procedure name.
nofArgsNumber of arguments.

Implements IConnection.

Definition at line 346 of file conn_impl.cpp.

References CActiveObject::AddListener(), CHECK_NCBI_DBAPI, m_connUsed, and proc.

◆ GetCDB_Connection()

CDB_Connection * CConnection::GetCDB_Connection ( )
virtual

Returns the internal driver connection object.

Implements IConnection.

Definition at line 105 of file conn_impl.cpp.

References CHECK_NCBI_DBAPI, and m_connection.

Referenced by Abort(), Action(), CCursor::CCursor(), CDBAPIBulkInsert::CDBAPIBulkInsert(), CloneCDB_Conn(), GetAuxConn(), MsgToEx(), SetCancelTimeout(), SetDbName(), SetTimeout(), and CStatement::x_Send().

◆ GetCursor()

ICursor * CConnection::GetCursor ( const string name,
const string sql,
int  batchSize 
)
virtual

Get cursor object.

Implements IConnection.

Definition at line 368 of file conn_impl.cpp.

References CActiveObject::AddListener(), and sql.

◆ GetDatabase()

string CConnection::GetDatabase ( )
virtual

Get current database.

Implements IConnection.

Definition at line 185 of file conn_impl.cpp.

References m_database.

Referenced by CloneCDB_Conn(), CloneConnection(), and SetDbName().

◆ GetDataSource()

IDataSource * CConnection::GetDataSource ( )
virtual

Get parent datasource object.

Implements IConnection.

Definition at line 89 of file conn_impl.cpp.

References m_ds.

◆ GetErrorAsEx()

CDB_MultiEx * CConnection::GetErrorAsEx ( )
virtual

Returns all error messages as a CDB_MultiEx object.

Implements IConnection.

Definition at line 542 of file conn_impl.cpp.

References GetHandler(), and CToMultiExHandler::GetMultiEx().

◆ GetErrorInfo()

string CConnection::GetErrorInfo ( )
virtual

Returns all error messages as a single string.

Implements IConnection.

Definition at line 547 of file conn_impl.cpp.

References GetHandler(), CDB_UserHandler_Stream::HandleIt(), out(), and CToMultiExHandler::ReplaceMultiEx().

◆ GetHandler()

CToMultiExHandler * CConnection::GetHandler ( void  )
protected

◆ GetModeMask()

unsigned int CConnection::GetModeMask ( )
virtual

Get mode mask.

Implements IConnection.

Definition at line 94 of file conn_impl.cpp.

References m_modeMask.

Referenced by CloneCDB_Conn(), CloneConnection(), Connect(), and ConnectValidated().

◆ GetStatement()

IStatement * CConnection::GetStatement ( )
virtual

Get statement object for regular SQL queries.

Implements IConnection.

Definition at line 331 of file conn_impl.cpp.

References CActiveObject::AddListener(), CHECK_NCBI_DBAPI, m_connection, m_connUsed, and stmt.

◆ IsAlive()

bool CConnection::IsAlive ( )
virtual

Check if the connection is alive.

Implements IConnection.

Definition at line 190 of file conn_impl.cpp.

References false, CDB_Connection::IsAlive(), and m_connection.

◆ IsAux()

bool CConnection::IsAux ( )
inline

◆ MsgToEx()

void CConnection::MsgToEx ( bool  v)
virtual

If enabled, redirects all error messages to CDB_MultiEx object (see below).

Implements IConnection.

Definition at line 515 of file conn_impl.cpp.

References _TRACE, GetCDB_Connection(), GetHandler(), m_msgToEx, CDB_Connection::PopMsgHandler(), and CDB_Connection::PushMsgHandler().

◆ PrepareCall()

ICallableStatement * CConnection::PrepareCall ( const string proc)
virtual

Get callable statement object for stored procedures.

Implements IConnection.

Definition at line 422 of file conn_impl.cpp.

References CActiveObject::AddListener(), GetAuxConn(), and proc.

◆ ResetMode()

void CConnection::ResetMode ( EConnMode  mode)
virtual

Reset connection mode.

Parameters
modeMode to reset to.

Implements IConnection.

Definition at line 84 of file conn_impl.cpp.

References m_modeMask.

◆ SetCancelTimeout()

void CConnection::SetCancelTimeout ( size_t  )
virtual

Set timeout for command cancellation and connection closing.

Reimplemented from IConnection.

Definition at line 319 of file conn_impl.cpp.

References GetCDB_Connection(), and CDB_Connection::SetCancelTimeout().

◆ SetDatabase()

void CConnection::SetDatabase ( const string name)
virtual

Set current database.

Parameters
nameName of database to set to.

Implements IConnection.

Definition at line 180 of file conn_impl.cpp.

References SetDbName().

◆ SetDbName()

void CConnection::SetDbName ( const string name,
CDB_Connection conn = 0 
)

◆ SetMode()

void CConnection::SetMode ( EConnMode  mode)
virtual

Set connection mode.

Parameters
modeMode to set to.

Implements IConnection.

Definition at line 79 of file conn_impl.cpp.

References m_modeMask.

◆ SetTimeout()

void CConnection::SetTimeout ( size_t  nof_secs)
virtual

Set connection timeout.

NOTE: if "nof_secs" is zero or is "too big" (depends on the underlying DB API), then set the timeout to infinite.

Implements IConnection.

Definition at line 314 of file conn_impl.cpp.

References GetCDB_Connection(), and CDB_Connection::SetTimeout().

◆ x_SendXactAbort()

void CConnection::x_SendXactAbort ( void  )
private

Member Data Documentation

◆ m_connCounter

int CConnection::m_connCounter
private

Definition at line 148 of file conn_impl.hpp.

Referenced by Action(), Clone(), GetAuxConn(), and IsAux().

◆ m_connection

CDB_Connection* CConnection::m_connection
private

◆ m_connUsed

bool CConnection::m_connUsed
private

Definition at line 149 of file conn_impl.hpp.

Referenced by Action(), GetAuxConn(), GetCallableStatement(), and GetStatement().

◆ m_database

string CConnection::m_database
private

Definition at line 145 of file conn_impl.hpp.

Referenced by CloneConnection(), Connect(), GetDatabase(), and SetDbName().

◆ m_ds

class CDataSource* CConnection::m_ds
private

◆ m_forceSingle

bool CConnection::m_forceSingle
private

Definition at line 151 of file conn_impl.hpp.

Referenced by CloneConnection(), ForceSingle(), and GetAuxConn().

◆ m_modeMask

unsigned int CConnection::m_modeMask
private

Definition at line 150 of file conn_impl.hpp.

Referenced by GetModeMask(), ResetMode(), and SetMode().

◆ m_msgToEx

bool CConnection::m_msgToEx
private

Definition at line 153 of file conn_impl.hpp.

Referenced by Clone(), CloneConnection(), and MsgToEx().

◆ m_multiExH

CRef<CToMultiExHandler> CConnection::m_multiExH
private

Definition at line 152 of file conn_impl.hpp.

Referenced by GetHandler().

◆ m_ownership

EOwnership CConnection::m_ownership
private

Definition at line 155 of file conn_impl.hpp.

Referenced by Action().


The documentation for this class was generated from the following files:
Modified on Mon Jun 24 05:20:24 2024 by modify_doxy.py rev. 669887