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

Go to the SVN repository for this file.

1 #ifndef DBAPI_DRIVER_CONN_MGR_HPP
2 #define DBAPI_DRIVER_CONN_MGR_HPP
3 
4 
5 /* $Id: dbapi_driver_conn_mgr.hpp 71465 2016-03-07 15:06:35Z ucko $
6  * ===========================================================================
7  *
8  * PUBLIC DOMAIN NOTICE
9  * National Center for Biotechnology Information
10  *
11  * This software/database is a "United States Government Work" under the
12  * terms of the United States Copyright Act. It was written as part of
13  * the author's official duties as a United States Government employee and
14  * thus cannot be copyrighted. This software/database is freely available
15  * to the public for use. The National Library of Medicine and the U.S.
16  * Government have not placed any restriction on its use or reproduction.
17  *
18  * Although all reasonable efforts have been taken to ensure the accuracy
19  * and reliability of the software and data, the NLM and the U.S.
20  * Government do not and cannot warrant the performance or results that
21  * may be obtained by using this software or data. The NLM and the U.S.
22  * Government disclaim all warranties, express or implied, including
23  * warranties of performance, merchantability or fitness for any particular
24  * purpose.
25  *
26  * Please cite the author in any work or product based on this material.
27  *
28  * ===========================================================================
29  *
30  * Author: Sergey Sikorskiy
31  *
32  * File Description: Connection manager
33  *
34  */
35 
36 #include <corelib/ncbiobj.hpp>
37 #include <corelib/ncbimtx.hpp>
39 
41 
42 
43 namespace impl
44 {
45  class CDriverContext;
46  class CConnection;
47 }
48 
49 
50 ///////////////////////////////////////////////////////////////////////////////
51 // Forward declaration
52 
53 class IRegistry;
54 template <typename T> class CSafeStatic_Allocator;
55 
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 /// IConnValidator
59 ///
60 
62 {
63 public:
64  enum EConnStatus {
65  eValidConn, //< means "everything is fine"
66  eInvalidConn, //< means "bad connection, do not use it any more"
67  eTempInvalidConn //< means "temporarily unavailable connection"
68  };
69 
70  virtual ~IConnValidator(void);
71 
72  // All CException-derived exceptions might be caught by a connection factory.
73  // Please use other tools to report validation information to a user.
74  virtual EConnStatus Validate(CDB_Connection& conn) = 0;
75  // This method shouldn't rethrow the exception.
76  virtual EConnStatus ValidateException(const CDB_Exception& ex);
77  // Return unique name of validator. This name is used to identify a pair of
78  // server and validator in order to validate resource against a particular
79  // validator. Empty name is reserved.
80  virtual string GetName(void) const;
81 };
82 
83 ///////////////////////////////////////////////////////////////////////////////
84 /// IDBConnectionFactory
85 ///
86 
88 {
89 public:
90  /// IDBConnectionFactory will take ownership of validator if there is any.
92  virtual ~IDBConnectionFactory(void);
93 
94  /// Configure connection policy using registry.
95  virtual void Configure(const IRegistry* registry = NULL) = 0;
96 
97 protected:
98  /// Create new connection object for the given context
99  /// and connection attributes.
100  virtual CDB_Connection* MakeDBConnection(
101  I_DriverContext& ctx,
102  const CDBConnParams& params) = 0;
103 
104  /// Helper method to provide access to a protected method in I_DriverContext
105  /// for child classses.
106  static CDB_Connection* CtxMakeConnection(
107  I_DriverContext& ctx,
108  const CDBConnParams& params);
109 
111  {
112  return NULL;
113  }
114 
115 private:
116  // Friends
117  friend class impl::CDriverContext;
118 };
119 
120 
121 ///////////////////////////////////////////////////////////////////////////////
122 /// CDbapiConnMgr
123 ///
124 
126 {
127 public:
128  /// Get access to the class instance.
129  static CDbapiConnMgr& Instance(void);
130 
131  /// What to do if a connection factory has already been
132  /// explicitly registered.
133  enum EIfSet {
134  eIfSet_Replace, ///< Replace it anyway.
135  eIfSet_KeepSilently, ///< Silently keep it.
136  eIfSet_KeepAndWarn, ///< Keep it, but issue a warning.
137  eIfSet_KeepAndThrow ///< Keep it and throw an exception.
138  };
139 
140  /// Set up a connection factory.
141  void SetConnectionFactory(IDBConnectionFactory* factory,
142  EIfSet if_set = eIfSet_Replace);
143 
144  /// Retrieve a connection factory.
146  {
147  return m_ConnectFactory;
148  }
149 
150  static void SetMaxConnect(unsigned int max_connect);
151 
152  static unsigned int GetMaxConnect(void);
153 
154 private:
155  CDbapiConnMgr(void);
156  ~CDbapiConnMgr(void);
157 
158  bool AddConnect(void);
159  void DelConnect(void);
160 
162 
164  unsigned int m_NumConnect;
166 
167  // Friends
169  friend class impl::CConnection;
170 };
171 
172 
173 ///////////////////////////////////////////////////////////////////////////////
174 inline
178  const CDBConnParams& params)
179 {
180  return ctx.MakePooledConnection(params);
181 }
182 
184 
185 
186 #endif /* DBAPI_DRIVER_CONN_MGR_HPP */
187 
EIfSet
What to do if a connection factory has already been explicitly registered.
IRegistry –.
Definition: ncbireg.hpp:74
#define NCBI_DBAPIDRIVER_EXPORT
Definition: ncbi_export.h:391
CFastMutex –.
Definition: ncbimtx.hpp:651
#define NULL
Definition: ncbistd.hpp:225
IConnValidator.
virtual CDB_UserHandler::TExceptions * GetExceptions(void)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
Helper class for object allocation/deallocation.
Definition: metareg.hpp:43
CRef< IDBConnectionFactory > GetConnectionFactory(void) const
Retrieve a connection factory.
IDBConnectionFactory.
CRef< IDBConnectionFactory > m_ConnectFactory
deque< CDB_Exception * > TExceptions
Exception container type.
Definition: exception.hpp:554
CDBConnParams::
Definition: interfaces.hpp:250
virtual CDB_Connection * MakePooledConnection(const CDBConnParams &params)=0
Create connection object WITHOUT using of Load Balancer / connection factory.
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
Keep it, but issue a warning.
static CDB_Connection * CtxMakeConnection(I_DriverContext &ctx, const CDBConnParams &params)
Helper method to provide access to a protected method in I_DriverContext for child classses...
CDB_Exception –.
Definition: exception.hpp:116
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx...
Multi-threading – mutexes; rw-locks; semaphore.
CObject –.
Definition: ncbiobj.hpp:180
static CS_CONNECTION * conn
Definition: get_send_data.c:18
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
Modified on Tue Jul 25 19:56:12 2017 by modify_doxy.py rev. 533848