mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-03 12:58:03 +01:00
remove unecessary toLower()
make SessionFactory map keys case insensitive nad remove unnecessary toLower() calls
This commit is contained in:
parent
56812d353b
commit
7e1374a004
@ -55,7 +55,7 @@ SessionImpl::SessionImpl(const std::string& connect,
|
|||||||
bool autoBind,
|
bool autoBind,
|
||||||
bool autoExtract):
|
bool autoExtract):
|
||||||
Poco::Data::AbstractSessionImpl<SessionImpl>(connect, loginTimeout),
|
Poco::Data::AbstractSessionImpl<SessionImpl>(connect, loginTimeout),
|
||||||
_connector(toLower(Connector::KEY)),
|
_connector(Connector::KEY),
|
||||||
_maxFieldSize(maxFieldSize),
|
_maxFieldSize(maxFieldSize),
|
||||||
_autoBind(autoBind),
|
_autoBind(autoBind),
|
||||||
_autoExtract(autoExtract),
|
_autoExtract(autoExtract),
|
||||||
@ -73,7 +73,7 @@ SessionImpl::SessionImpl(const std::string& connect,
|
|||||||
bool enforceCapability,
|
bool enforceCapability,
|
||||||
bool autoBind,
|
bool autoBind,
|
||||||
bool autoExtract): Poco::Data::AbstractSessionImpl<SessionImpl>(connect),
|
bool autoExtract): Poco::Data::AbstractSessionImpl<SessionImpl>(connect),
|
||||||
_connector(toLower(Connector::KEY)),
|
_connector(Connector::KEY),
|
||||||
_maxFieldSize(maxFieldSize),
|
_maxFieldSize(maxFieldSize),
|
||||||
_autoBind(autoBind),
|
_autoBind(autoBind),
|
||||||
_autoExtract(autoExtract),
|
_autoExtract(autoExtract),
|
||||||
|
@ -60,7 +60,7 @@ const std::string SessionImpl::ABORT_TRANSACTION("ROLLBACK");
|
|||||||
|
|
||||||
SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
|
SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
|
||||||
Poco::Data::AbstractSessionImpl<SessionImpl>(fileName, loginTimeout),
|
Poco::Data::AbstractSessionImpl<SessionImpl>(fileName, loginTimeout),
|
||||||
_connector(toLower(Connector::KEY)),
|
_connector(Connector::KEY),
|
||||||
_pDB(0),
|
_pDB(0),
|
||||||
_connected(false),
|
_connected(false),
|
||||||
_isTransaction(false)
|
_isTransaction(false)
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "Poco/Data/Session.h"
|
#include "Poco/Data/Session.h"
|
||||||
#include "Poco/Mutex.h"
|
#include "Poco/Mutex.h"
|
||||||
#include "Poco/SharedPtr.h"
|
#include "Poco/SharedPtr.h"
|
||||||
|
#include "Poco/String.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
@ -71,6 +72,7 @@ class Data_API SessionFactory
|
|||||||
/// Session ses("SQLite", "dummy.db");
|
/// Session ses("SQLite", "dummy.db");
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static SessionFactory& instance();
|
static SessionFactory& instance();
|
||||||
/// returns the static instance of the singleton.
|
/// returns the static instance of the singleton.
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ public:
|
|||||||
Session create(const std::string& uri,
|
Session create(const std::string& uri,
|
||||||
std::size_t timeout = Session::LOGIN_TIMEOUT_DEFAULT);
|
std::size_t timeout = Session::LOGIN_TIMEOUT_DEFAULT);
|
||||||
/// Creates a Session for the given URI (must be in key:///connectionString format).
|
/// Creates a Session for the given URI (must be in key:///connectionString format).
|
||||||
/// Throws an Poco:Data::UnknownDataBaseException if no Connector is registered for the key.
|
/// Throws a Poco:Data::UnknownDataBaseException if no Connector is registered for the key.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SessionFactory();
|
SessionFactory();
|
||||||
@ -107,7 +109,15 @@ private:
|
|||||||
SessionInfo(Connector* pSI);
|
SessionInfo(Connector* pSI);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::string, SessionInfo> Connectors;
|
struct ILT
|
||||||
|
{
|
||||||
|
bool operator() (const std::string& s1, const std::string& s2) const
|
||||||
|
{
|
||||||
|
return Poco::icompare(s1, s2) < 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<std::string, SessionInfo, ILT> Connectors;
|
||||||
Connectors _connectors;
|
Connectors _connectors;
|
||||||
Poco::FastMutex _mutex;
|
Poco::FastMutex _mutex;
|
||||||
};
|
};
|
||||||
|
@ -227,7 +227,7 @@ inline std::size_t SessionImpl::getLoginTimeout() const
|
|||||||
inline std::string SessionImpl::uri(const std::string& connector,
|
inline std::string SessionImpl::uri(const std::string& connector,
|
||||||
const std::string& connectionString)
|
const std::string& connectionString)
|
||||||
{
|
{
|
||||||
return format("%s:///%s", toLower(connector), connectionString);
|
return format("%s:///%s", connector, connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class TypeHandler: public AbstractTypeHandler
|
|||||||
/// poco_assert_dbg (pBinder != 0);
|
/// poco_assert_dbg (pBinder != 0);
|
||||||
/// TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder, dir);
|
/// TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder, dir);
|
||||||
/// TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder, dir);
|
/// TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder, dir);
|
||||||
/// TypeHandler<int>::bind(pos++, obj.getAge(), pBinder);
|
/// TypeHandler<int>::bind(pos++, obj.getAge(), pBinder, dir);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// static void prepare(std::size_t pos, const Person& obj, AbstractPreparator* pPreparator)
|
/// static void prepare(std::size_t pos, const Person& obj, AbstractPreparator* pPreparator)
|
||||||
|
@ -118,12 +118,12 @@ int main(int argc, char** argv)
|
|||||||
// insert some rows
|
// insert some rows
|
||||||
DateTime hd(1956, 3, 1);
|
DateTime hd(1956, 3, 1);
|
||||||
session << "INSERT INTO Simpsons VALUES('Homer Simpson', 'Springfield', 42, ?)", use(hd), now;
|
session << "INSERT INTO Simpsons VALUES('Homer Simpson', 'Springfield', 42, ?)", use(hd), now;
|
||||||
DateTime md(1954, 10, 1);
|
hd.assign(1954, 10, 1);
|
||||||
session << "INSERT INTO Simpsons VALUES('Marge Simpson', 'Springfield', 38, ?)", use(md), now;
|
session << "INSERT INTO Simpsons VALUES('Marge Simpson', 'Springfield', 38, ?)", use(hd), now;
|
||||||
DateTime bd(1980, 4, 1);
|
hd.assign(1980, 4, 1);
|
||||||
session << "INSERT INTO Simpsons VALUES('Bart Simpson', 'Springfield', 12, ?)", use(bd), now;
|
session << "INSERT INTO Simpsons VALUES('Bart Simpson', 'Springfield', 12, ?)", use(hd), now;
|
||||||
DateTime ld(1982, 5, 9);
|
hd.assign(1982, 5, 9);
|
||||||
session << "INSERT INTO Simpsons VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(ld), now;
|
session << "INSERT INTO Simpsons VALUES('Lisa Simpson', 'Springfield', 10, ?)", use(hd), now;
|
||||||
|
|
||||||
// create a statement and print the column names and data as HTML table
|
// create a statement and print the column names and data as HTML table
|
||||||
HTMLTableFormatter tf;
|
HTMLTableFormatter tf;
|
||||||
|
@ -65,7 +65,7 @@ void SessionFactory::add(Connector* pIn)
|
|||||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
SessionInfo info(pIn);
|
SessionInfo info(pIn);
|
||||||
std::pair<Connectors::iterator, bool> res =
|
std::pair<Connectors::iterator, bool> res =
|
||||||
_connectors.insert(std::make_pair(toLower(pIn->name()), info));
|
_connectors.insert(std::make_pair(pIn->name(), info));
|
||||||
if (!res.second) res.first->second.cnt++;
|
if (!res.second) res.first->second.cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ void SessionFactory::add(Connector* pIn)
|
|||||||
void SessionFactory::remove(const std::string& key)
|
void SessionFactory::remove(const std::string& key)
|
||||||
{
|
{
|
||||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
Connectors::iterator it = _connectors.find(toLower(key));
|
Connectors::iterator it = _connectors.find(key);
|
||||||
poco_assert (_connectors.end() != it);
|
poco_assert (_connectors.end() != it);
|
||||||
|
|
||||||
--(it->second.cnt);
|
--(it->second.cnt);
|
||||||
@ -86,7 +86,7 @@ Session SessionFactory::create(const std::string& key,
|
|||||||
std::size_t timeout)
|
std::size_t timeout)
|
||||||
{
|
{
|
||||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||||
Connectors::iterator it = _connectors.find(toLower(key));
|
Connectors::iterator it = _connectors.find(key);
|
||||||
poco_assert (_connectors.end() != it);
|
poco_assert (_connectors.end() != it);
|
||||||
|
|
||||||
return Session(it->second.ptrSI->createSession(connectionString, timeout));
|
return Session(it->second.ptrSI->createSession(connectionString, timeout));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user