From 62e234c114d2b6ead93a1d39593c66b648c3d0a6 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 1 Feb 2024 15:47:37 +0300 Subject: Turn libodb-oracle repository into package for muti-package repository --- libodb-oracle/odb/oracle/connection-factory.hxx | 134 ++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 libodb-oracle/odb/oracle/connection-factory.hxx (limited to 'libodb-oracle/odb/oracle/connection-factory.hxx') diff --git a/libodb-oracle/odb/oracle/connection-factory.hxx b/libodb-oracle/odb/oracle/connection-factory.hxx new file mode 100644 index 0000000..835759e --- /dev/null +++ b/libodb-oracle/odb/oracle/connection-factory.hxx @@ -0,0 +1,134 @@ +// file : odb/oracle/connection-factory.hxx +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_CONNECTION_FACTORY_HXX +#define ODB_ORACLE_CONNECTION_FACTORY_HXX + +#include + +#include +#include // std::size_t +#include + +#include +#include +#include + +#include +#include +#include + +#include + +namespace odb +{ + namespace oracle + { + class LIBODB_ORACLE_EXPORT new_connection_factory: public connection_factory + { + public: + new_connection_factory () {} + + virtual connection_ptr + connect (); + + private: + new_connection_factory (const new_connection_factory&); + new_connection_factory& operator= (const new_connection_factory&); + }; + + class LIBODB_ORACLE_EXPORT connection_pool_factory: + public connection_factory + { + public: + // The max_connections argument specifies the maximum number of + // concurrent connections this pool will maintain. If this value + // is 0 then the pool will create a new connection every time all + // of the existing connections are in use. + // + // The min_connections argument specifies the minimum number of + // connections that should be maintained by the pool. If the + // number of connections maintained by the pool exceeds this + // number and there are no active waiters for a new connection, + // then the pool will release the excess connections. If this + // value is 0 then the pool will maintain all the connections + // that were ever created. + // + connection_pool_factory (std::size_t max_connections = 0, + std::size_t min_connections = 0) + : max_ (max_connections), + min_ (min_connections), + in_use_ (0), + waiters_ (0), + cond_ (mutex_) + { + // max_connections == 0 means unlimited. + // + assert (max_connections == 0 || max_connections >= min_connections); + } + + virtual connection_ptr + connect (); + + virtual void + database (database_type&); + + virtual + ~connection_pool_factory (); + + private: + connection_pool_factory (const connection_pool_factory&); + connection_pool_factory& operator= (const connection_pool_factory&); + + protected: + class LIBODB_ORACLE_EXPORT pooled_connection: public connection + { + public: + pooled_connection (connection_pool_factory&); + pooled_connection (connection_pool_factory&, OCISvcCtx*); + + private: + static bool + zero_counter (void*); + + private: + friend class connection_pool_factory; + + shared_base::refcount_callback cb_; + }; + + friend class pooled_connection; + + typedef details::shared_ptr pooled_connection_ptr; + typedef std::vector connections; + + // This function is called whenever the pool needs to create a new + // connection. + // + virtual pooled_connection_ptr + create (); + + protected: + // Return true if the connection should be deleted, false otherwise. + // + bool + release (pooled_connection*); + + protected: + const std::size_t max_; + const std::size_t min_; + + std::size_t in_use_; // Number of connections currently in use. + std::size_t waiters_; // Number of threads waiting for a connection. + + connections connections_; + + details::mutex mutex_; + details::condition cond_; + }; + } +} + +#include + +#endif // ODB_ORACLE_CONNECTION_FACTORY_HXX -- cgit v1.1