diff options
author | randomdan <randomdan@localhost> | 2011-06-11 03:00:47 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-06-11 03:00:47 +0000 |
commit | 496a31c69cc55e1196406128e3a256db94404ba1 (patch) | |
tree | 2ceac3ab89da2a7dbb74b37f95ee135969cdb467 /project2/rdbmsDataSource.cpp | |
parent | Propagate features (diff) | |
download | project2-496a31c69cc55e1196406128e3a256db94404ba1.tar.bz2 project2-496a31c69cc55e1196406128e3a256db94404ba1.tar.xz project2-496a31c69cc55e1196406128e3a256db94404ba1.zip |
Make named types code totally generic
Convert RDBMS DB types to new named types system and remove all the hacky mess previous used
Diffstat (limited to 'project2/rdbmsDataSource.cpp')
-rw-r--r-- | project2/rdbmsDataSource.cpp | 42 |
1 files changed, 4 insertions, 38 deletions
diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index 1b0ab3c..f21c737 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -1,5 +1,4 @@ #include "rdbmsDataSource.h" -#include "xmlObjectLoader.h" #include <libxml++/nodes/textnode.h> #include <sys/utsname.h> #include "logger.h" @@ -7,16 +6,6 @@ #include <sqlext.h> #include <boost/foreach.hpp> -static const int NOTSET = 0; -#ifdef WITH_PQ -#include "../libpqpp/connection.h" -static const int PQ_TYPEID = 1; -#endif -#ifdef WITH_ODBC -#include "../libodbcpp/connection.h" -static const int ODBC_TYPEID = 2; -#endif - SimpleMessageException(UnknownConnectionProvider); /// Specialized ElementLoader for instances of RdbmsDataSource; handles persistent DB connections @@ -209,41 +198,18 @@ RdbmsDataSource::RdbmsConnection::isExpired() const return (time(NULL) > lastUsedTime + keepAliveTime); } -RdbmsDataSource::ConnectionInfo::ConnectionInfo(const xmlpp::Element * n) : - typeId(NOTSET) +RdbmsDataSource::ConnectionInfo::ConnectionInfo(const xmlpp::Element * n) { -#if WITH_ODBC - BOOST_FOREACH(const xmlpp::Node * node, n->find("odbc")) { - typeId = ODBC_TYPEID; - dsn = dynamic_cast<const xmlpp::Element *>(node)->get_child_text()->get_content(); - } -#endif -#if WITH_PQ - BOOST_FOREACH(const xmlpp::Node * node, n->find("postgresql")) { - typeId = PQ_TYPEID; + BOOST_FOREACH(const xmlpp::Node * node, n->get_children()) { + typeId = LoaderBase::getLoader<ConnectionLoader, UnknownConnectionProvider>(node->get_name()); dsn = dynamic_cast<const xmlpp::Element *>(node)->get_child_text()->get_content(); } -#endif - if (typeId == NOTSET || dsn.empty()) { - throw UnknownConnectionProvider(n->get_path()); - } } DB::Connection * RdbmsDataSource::ConnectionInfo::connect() const { -#if WITH_ODBC - if (typeId == ODBC_TYPEID) { - return new ODBC::Connection(dsn); - } -#endif -#if WITH_PQ - if (typeId == PQ_TYPEID) { - return new PQ::Connection(dsn); - } -#endif - // This should never happen if the object was constructed correctly - throw UnknownConnectionProvider(__PRETTY_FUNCTION__); + return typeId->connect(dsn); } bool |