NCBI C++ ToolKit
conn_impl.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef _CONN_IMPL_HPP_
2 #define _CONN_IMPL_HPP_
3 
4 /* $Id: conn_impl.hpp 83966 2018-10-04 14:52:03Z ucko $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * File Name: $Id: conn_impl.hpp 83966 2018-10-04 14:52:03Z ucko $
30 *
31 * Author: Michael Kholodov
32 *
33 * File Description: Connection implementation
34 *
35 *
36 */
37 
38 #include <dbapi/dbapi.hpp>
39 #include "active_obj.hpp"
40 
42 
43 class CDataSource;
44 
45 class CConnection : public CActiveObject,
46  public IConnection
47 {
48 public:
49  CConnection(CDataSource* ds, EOwnership ownership);
50 
51 public:
52  virtual ~CConnection();
53 
54  virtual void SetMode(EConnMode mode);
55  virtual void ResetMode(EConnMode mode);
56  virtual unsigned int GetModeMask();
57 
58  virtual void ForceSingle(bool enable);
59 
60  virtual IDataSource* GetDataSource();
61 
62  virtual void Connect(const string& user,
63  const string& password,
64  const string& server,
65  const string& database = kEmptyStr);
66 
67  virtual void Connect(const CDBConnParams& params);
68 
69  virtual void ConnectValidated(IConnValidator& validator,
70  const string& user,
71  const string& password,
72  const string& server,
73  const string& database = kEmptyStr);
74 
75  virtual IConnection* CloneConnection(EOwnership ownership);
76 
77  // New part begin
78 
79  virtual IStatement* GetStatement();
80  virtual ICallableStatement* GetCallableStatement(const string& proc);
81  virtual ICursor* GetCursor(const string& name,
82  const string& sql,
83  int batchSize);
84 
85  virtual IBulkInsert* GetBulkInsert(const string& table_name);
86 
87  // New part end
88 
89  virtual IStatement* CreateStatement();
90  virtual ICallableStatement* PrepareCall(const string& proc);
91  virtual ICursor* CreateCursor(const string& name,
92  const string& sql,
93  int batchSize);
94 
95  virtual IBulkInsert* CreateBulkInsert(const string& table_name);
96 
97  virtual void Close();
98  virtual void Abort();
99  virtual void SetTimeout(size_t nof_secs);
100  virtual void SetCancelTimeout(size_t nof_secs);
101 
103 
104  virtual void SetDatabase(const string& name);
105 
106  virtual string GetDatabase();
107 
108  virtual bool IsAlive();
109 
110  CConnection* Clone();
111 
112  void SetDbName(const string& name, CDB_Connection* conn = 0);
113 
115 
116  bool IsAux() {
117  return m_connCounter < 0;
118  }
119 
120  // Interface IEventListener implementation
121  virtual void Action(const CDbapiEvent& e);
122 
123  // If enabled, redirects all error messages
124  // to CDB_MultiEx object (see below)
125  virtual void MsgToEx(bool v);
126 
127  // Returns all error messages as a CDB_MultiEx object
128  virtual CDB_MultiEx* GetErrorAsEx();
129 
130  // Returns all error messages as a single string
131  virtual string GetErrorInfo();
132 
133 protected:
135  CDataSource* ds);
136  // Clone connection, if the original cmd structure is taken
138  // void DeleteConn(CConnection* conn);
139 
140  class CToMultiExHandler* GetHandler();
141 
142  void FreeResources();
143 
144 private:
145  string m_database;
150  unsigned int m_modeMask;
153  bool m_msgToEx;
154 
156 
157 private:
158  void x_SendXactAbort(void);
159 };
160 
161 //====================================================================
163 
164 #endif // _CONN_IMPL_HPP_
CRef< CToMultiExHandler > m_multiExH
Definition: conn_impl.hpp:152
CConnection * Clone()
Definition: conn_impl.cpp:245
virtual string GetErrorInfo()
Returns all error messages as a single string.
Definition: conn_impl.cpp:547
virtual void Action(const CDbapiEvent &e)
Definition: conn_impl.cpp:457
virtual CDB_MultiEx * GetErrorAsEx()
Returns all error messages as a CDB_MultiEx object.
Definition: conn_impl.cpp:542
bool m_forceSingle
Definition: conn_impl.hpp:151
virtual ICursor * GetCursor(const string &name, const string &sql, int batchSize)
Get cursor object.
Definition: conn_impl.cpp:368
CDB_Connection * m_connection
Definition: conn_impl.hpp:147
virtual ICallableStatement * PrepareCall(const string &proc)
Get callable statement object for stored procedures.
Definition: conn_impl.cpp:422
virtual void SetMode(EConnMode mode)
Set connection mode.
Definition: conn_impl.cpp:79
virtual void SetDatabase(const string &name)
Set current database.
Definition: conn_impl.cpp:180
virtual ICursor * CreateCursor(const string &name, const string &sql, int batchSize)
Get cursor object.
Definition: conn_impl.cpp:433
virtual void Abort()
Abort connection.
Definition: conn_impl.cpp:308
bool IsAux()
Definition: conn_impl.hpp:116
virtual void MsgToEx(bool v)
If enabled, redirects all error messages to CDB_MultiEx object (see below).
Definition: conn_impl.cpp:515
virtual ICallableStatement * GetCallableStatement(const string &proc)
Get callable statement object for stored procedures.
Definition: conn_impl.cpp:346
virtual IConnection * CloneConnection(EOwnership ownership)
Clone existing connection.
Definition: conn_impl.cpp:258
virtual IDataSource * GetDataSource()
Get parent datasource object.
Definition: conn_impl.cpp:89
EOwnership m_ownership
Definition: conn_impl.hpp:155
virtual unsigned int GetModeMask()
Get mode mask.
Definition: conn_impl.cpp:94
unsigned int m_modeMask
Definition: conn_impl.hpp:150
class CDataSource * m_ds
Definition: conn_impl.hpp:146
void SetDbName(const string &name, CDB_Connection *conn=0)
Definition: conn_impl.cpp:195
virtual IBulkInsert * CreateBulkInsert(const string &table_name)
Create bulk insert object.
Definition: conn_impl.cpp:446
virtual void Close()
Close connecti.
Definition: conn_impl.cpp:303
virtual IStatement * GetStatement()
Get statement object for regular SQL queries.
Definition: conn_impl.cpp:331
bool m_msgToEx
Definition: conn_impl.hpp:153
CDB_Connection * CloneCDB_Conn()
Definition: conn_impl.cpp:206
virtual ~CConnection()
Definition: conn_impl.cpp:164
CConnection * GetAuxConn()
Definition: conn_impl.cpp:279
virtual void SetTimeout(size_t nof_secs)
Set connection timeout.
Definition: conn_impl.cpp:314
virtual void ResetMode(EConnMode mode)
Reset connection mode.
Definition: conn_impl.cpp:84
void FreeResources()
Definition: conn_impl.cpp:324
virtual void ForceSingle(bool enable)
Force single connection mode, default false.
Definition: conn_impl.cpp:99
virtual IBulkInsert * GetBulkInsert(const string &table_name)
Create bulk insert object.
Definition: conn_impl.cpp:389
virtual IStatement * CreateStatement()
Get statement object for regular SQL queries.
Definition: conn_impl.cpp:410
CConnection(CDataSource *ds, EOwnership ownership)
Definition: conn_impl.cpp:60
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.
Definition: conn_impl.cpp:143
virtual string GetDatabase()
Get current database.
Definition: conn_impl.cpp:185
virtual CDB_Connection * GetCDB_Connection()
Returns the internal driver connection object.
Definition: conn_impl.cpp:105
bool m_connUsed
Definition: conn_impl.hpp:149
virtual void SetCancelTimeout(size_t nof_secs)
Set timeout for command cancellation and connection closing.
Definition: conn_impl.cpp:319
int m_connCounter
Definition: conn_impl.hpp:148
virtual bool IsAlive()
Check if the connection is alive.
Definition: conn_impl.cpp:190
virtual void Connect(const string &user, const string &password, const string &server, const string &database=kEmptyStr)
Connect to a database.
Definition: conn_impl.cpp:111
string m_database
Definition: conn_impl.hpp:145
void x_SendXactAbort(void)
Definition: conn_impl.cpp:576
class CToMultiExHandler * GetHandler()
Definition: conn_impl.cpp:534
CDBConnParams::
Definition: interfaces.hpp:258
IBulkInsert –.
Definition: dbapi.hpp:665
ICallableStatement –.
Definition: dbapi.hpp:510
ICursor –.
Definition: dbapi.hpp:564
IDataSource –.
Definition: dbapi.hpp:963
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
Defines the database API innterfaces for a variety of DBMS.
EConnMode
Which connection mode.
Definition: dbapi.hpp:731
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
enum ENcbiOwnership EOwnership
Ownership relations between objects.
use only n Cassandra database for the lookups</td > n</tr > n< tr > n< td > yes</td > n< td > do not use tables BIOSEQ_INFO and BLOB_PROP in the Cassandra database
mdb_mode_t mode
Definition: lmdb++.h:38
static const char table_name[]
Definition: bcp.c:249
static char sql[1024]
Definition: putdata.c:19
static const char * proc
Definition: stats.c:21
Modified on Mon Feb 26 04:04:36 2024 by modify_doxy.py rev. 669887