1 |
// Connector |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id$ |
6 |
|
7 |
#ifndef _Connector_hpp_ |
8 |
#define _Connector_hpp_ |
9 |
|
10 |
#include <cxx/platform.hpp> |
11 |
|
12 |
#ifdef MENES_PRAGMA_ONCE |
13 |
#pragma once |
14 |
#endif |
15 |
|
16 |
#include <api/threads.hpp> |
17 |
#include <dbi/driver.hpp> |
18 |
#include <dbi/connection.hpp> |
19 |
#include <ext/stack.hpp> |
20 |
|
21 |
class Connector : public ext::ReferenceCounted |
22 |
{ |
23 |
private: |
24 |
_R<dbi::Driver> driver; |
25 |
cse::String host, user, password, database; |
26 |
api::ThreadMutex connectionsLock; |
27 |
ext::Stack<_R<dbi::Connection> > connections; |
28 |
bool running; |
29 |
_S<api::Thread> cleanup; |
30 |
int Cleanup(); |
31 |
public: |
32 |
Connector(const cse::String& configuration); |
33 |
~Connector() { running = false; cleanup.Join(); } |
34 |
_R<dbi::Connection> Connect(); |
35 |
void Release(const _R<dbi::Connection>& connection); |
36 |
}; |
37 |
|
38 |
#endif//_Connector_hpp_ |