/* libzzdb
*
* This program is distributed under the GNU General Public License, version 2.
* A copy of this license is included with this source.
*
* Copyright 2000-2006, Toni Thomsson <toni@tonjac.org>
*/
/**
Database pool
Toni Thomsson, toni@tonjac.org
*/
#ifndef zz_db_pool_h
#define zz_db_pool_h
#include <zz_string.h>
#include <zz_db.h>
#include <zz_db_exception.h>
#include <map>
/**
Database pool
@author Toni Thomsson, toni@tonjac.org
*/
class ZZ_API CzzDbPool
{
public:
/**
Create a pool of database connections
@param connect Connect string
@param size Number of connections
@param autocommit Autocommit on/off 1=on, 0=off
*/
CzzDbPool( const char* connect, int size, int autocommit = 1 );
virtual ~CzzDbPool();
/**
Get a free connection from pool
*/
CzzDb* getConnection( void );
/**
Return connection to pool, unlocks the connection to be used
by someone else
*/
void freeConnection( CzzDb* connection );
protected:
private:
CzzLog m_Log;
CzzString m_Connect;
int m_Size;
map<int, CzzDb* > m_Pool;
map<int, bool > m_Locktable;
static CzzWinThreadMutex m_Mutex;
};
#endif // zz_db_pool_h