![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 #include <stdlib.h> 00002 #include <iostream> 00003 00004 #include <cppconn/driver.h> 00005 00006 #include "DbConnectionFactory.h" 00007 #include "ObjectPool.h" 00008 #include "Singleton.h" 00009 00010 namespace SraData 00011 { 00015 sql::Connection* DbConnectionFactory::createInstance() 00016 { 00017 //create a new instance for the given arguments 00018 sql::Connection *con = _driver->connect(_dbName, _login, _password); 00019 con->setSchema(_schema); 00020 return con; 00021 } 00022 00026 DbConnectionFactory::DbConnectionFactory(const std::string& dbName, const std::string& login, const std::string& password, const std::string& schema): 00027 _dbName(dbName), 00028 _login(login), 00029 _password(password), 00030 _schema(schema) 00031 { 00032 //create an instance of the driver on creation of the factory 00033 //this will be used to create connections in the future 00034 _driver = get_driver_instance(); 00035 00036 //set singleton up for this class 00037 SetSingleton(this); 00038 00039 //when this factory dies, all of its children must die (so sad) 00040 setDeleteAllInstances(true); 00041 } 00042 00046 sql::Connection* DbConnectionFactory::getConnection() 00047 { 00048 return getInstance(); 00049 } 00050 00054 void DbConnectionFactory::recycleConnection(sql::Connection* conn) 00055 { 00056 recycle(conn); 00057 } 00058 }
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.