Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Protected Member Functions | Protected Attributes
SraData::DbConnectionFactory Class Reference

#include <DbConnectionFactory.h>

Inheritance diagram for SraData::DbConnectionFactory:

List of all members.

Public Member Functions

 DbConnectionFactory (const std::string &dbName, const std::string &login, const std::string &password, const std::string &schema)
sql::ConnectiongetConnection ()
void recycleConnection (sql::Connection *conn)

Protected Member Functions

sql::ConnectioncreateInstance ()

Protected Attributes

std::string _dbName
sql::Driver_driver
std::string _login
std::string _password
std::string _schema

Detailed Description

This class wraps the MySQL driver class, providing easier change for the future Also, for performance, this class may one day become an ObjectPool of connections for greater efficiency

Definition at line 18 of file DbConnectionFactory.h.


Constructor & Destructor Documentation

SraData::DbConnectionFactory::DbConnectionFactory ( const std::string &  dbName,
const std::string &  login,
const std::string &  password,
const std::string &  schema 
)

Sets the database information for this object, sets this instance as the Singleton, and initializes the MySQL driver

Definition at line 26 of file DbConnectionFactory.cpp.

References _driver, get_driver_instance(), ObjectPool< sql::Connection >::setDeleteAllInstances(), and Singleton< DbConnectionFactory >::SetSingleton().

                                                                                                                                               : 
            _dbName(dbName), 
            _login(login),
            _password(password),
            _schema(schema)
    {
        //create an instance of the driver on creation of the factory
        //this will be used to create connections in the future
        _driver = get_driver_instance();

        //set singleton up for this class
        SetSingleton(this);

        //when this factory dies, all of its children must die (so sad)
        setDeleteAllInstances(true);
    }

Member Function Documentation

sql::Connection * SraData::DbConnectionFactory::createInstance ( ) [protected, virtual]

Creates a MySQL connection instance using the settings of this factory instance

Implements ObjectPool< sql::Connection >.

Definition at line 15 of file DbConnectionFactory.cpp.

References _dbName, _driver, _login, _password, _schema, sql::Driver::connect(), and sql::Connection::setSchema().

    {
        //create a new instance for the given arguments
        sql::Connection *con = _driver->connect(_dbName, _login, _password);
        con->setSchema(_schema);
        return con;
    }
sql::Connection * SraData::DbConnectionFactory::getConnection ( )

Returns an instance from the connection pool

Definition at line 46 of file DbConnectionFactory.cpp.

References ObjectPool< sql::Connection >::getInstance().

Referenced by SraData::DbStream::DbStream().

    {
        return getInstance();
    }
void SraData::DbConnectionFactory::recycleConnection ( sql::Connection conn)

returns an instance to the pool

Definition at line 54 of file DbConnectionFactory.cpp.

References ObjectPool< sql::Connection >::recycle().

Referenced by SraData::DbStream::~DbStream().

    {
        recycle(conn);
    }

Member Data Documentation

std::string SraData::DbConnectionFactory::_dbName [protected]

Definition at line 23 of file DbConnectionFactory.h.

Referenced by createInstance().

Definition at line 21 of file DbConnectionFactory.h.

Referenced by createInstance(), and DbConnectionFactory().

std::string SraData::DbConnectionFactory::_login [protected]

Definition at line 24 of file DbConnectionFactory.h.

Referenced by createInstance().

std::string SraData::DbConnectionFactory::_password [protected]

Definition at line 25 of file DbConnectionFactory.h.

Referenced by createInstance().

std::string SraData::DbConnectionFactory::_schema [protected]

Definition at line 26 of file DbConnectionFactory.h.

Referenced by createInstance().


The documentation for this class was generated from the following files:

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net