/***************************************************************************
                   DB Manager Class Header ( DBManager.h )
                -----------------------------------------

	begin      : 2013/06/04
	copyright  : (C) 2013 Solbox Inc.
	author     : Development 1 Team
					- 2013/06/04 - 1st dadamin
	email      : dev1@solbox.com
	version    : 3.2.0

	CopyRight(C) 2005 Solbox Inc. All Rights reserved.
	Redistribution and use in source and binary forms, with or with out
	modification, are not permitted in outside of Solbox Inc.
***************************************************************************/
#ifndef __DB_MANAGER_H__
#define __DB_MANAGER_H__

#define  DB_POO_TIMEOUT		30000 // milliseconds(30 sec)
class CDataBaseInfo;

class CDBPools
{
public:
	CDBPools();
	~CDBPools();

	bool Create(string dbtype, int size, string comstr);
	void Finalized();
	
	bool GetDB(size_t & pos, int timeout =  DB_POO_TIMEOUT );
	void ReleaseDB( size_t pos);

	inline session & GetSession(size_t pos) { return m_pool->at(pos); }

private:
	size_t m_size;
	string m_dbtype;
	string m_comstr;
	connection_pool * m_pool;
};

class CDBManager
{
public:
	CDBManager();
	~CDBManager();

	bool CreatePool(string sDBtype, string sUsed, CDataBaseInfo& info);
	void Finalized();

	CDBPools * GetDBPool(string sDBtype, string sUsed);

protected:

private:
	int m_dbCnt;
	map<string, map<string, CDBPools> >m_manager;
};

#endif // __DB_MANAGER_H__
