mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-29 12:18:01 +01:00
[SF 2505290] DB connection as URI (MySQL not tested!)
This commit is contained in:
@@ -72,7 +72,8 @@ public:
|
||||
typedef Poco::Any (C::*PropertyGetter)(const std::string&);
|
||||
/// The getter method for a property.
|
||||
|
||||
AbstractSessionImpl(): _storage(std::string("deque")),
|
||||
AbstractSessionImpl(const std::string& connectionString): SessionImpl(connectionString),
|
||||
_storage(std::string("deque")),
|
||||
_bulk(false),
|
||||
_emptyStringIsNull(false),
|
||||
_forceEmptyString(false)
|
||||
|
||||
@@ -73,6 +73,7 @@ public:
|
||||
void close();
|
||||
bool isConnected();
|
||||
bool isTransaction();
|
||||
const std::string& connectorName();
|
||||
void setFeature(const std::string& name, bool state);
|
||||
bool getFeature(const std::string& name);
|
||||
void setProperty(const std::string& name, const Poco::Any& value);
|
||||
|
||||
@@ -180,6 +180,10 @@ public:
|
||||
/// Creates a new session, using the given connector (which must have
|
||||
/// been registered), and connectionString.
|
||||
|
||||
Session(const std::string& connection);
|
||||
/// Creates a new session, using the given connection (must be in
|
||||
/// "connection:///connectionString" format).
|
||||
|
||||
Session(const Session&);
|
||||
/// Creates a session by copying another one.
|
||||
|
||||
@@ -220,6 +224,14 @@ public:
|
||||
bool isTransaction();
|
||||
/// Returns true iff a transaction is in progress, false otherwise.
|
||||
|
||||
std::string uri();
|
||||
/// Returns the URI for this session.
|
||||
|
||||
static std::string uri(const std::string& connector,
|
||||
const std::string& connectionString);
|
||||
/// Utility function that teturns the URI formatted from supplied
|
||||
/// arguments as "connector://connectionString".
|
||||
|
||||
void setFeature(const std::string& name, bool state);
|
||||
/// Set the state of a feature.
|
||||
///
|
||||
@@ -312,6 +324,19 @@ inline bool Session::isTransaction()
|
||||
}
|
||||
|
||||
|
||||
inline std::string Session::uri(const std::string& connector,
|
||||
const std::string& connectionString)
|
||||
{
|
||||
return SessionImpl::uri(connector, connectionString);
|
||||
}
|
||||
|
||||
|
||||
inline std::string Session::uri()
|
||||
{
|
||||
return _ptrImpl->uri();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::setFeature(const std::string& name, bool state)
|
||||
{
|
||||
_ptrImpl->setFeature(name, state);
|
||||
|
||||
@@ -87,6 +87,10 @@ public:
|
||||
/// Creates a Session for the given key with the connectionString. Throws an Poco:Data::UnknownDataBaseException
|
||||
/// if no Connector is registered for that key.
|
||||
|
||||
Session create(const std::string& uri);
|
||||
/// 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.
|
||||
|
||||
private:
|
||||
SessionFactory();
|
||||
~SessionFactory();
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Any.h"
|
||||
|
||||
|
||||
@@ -57,7 +59,7 @@ class Data_API SessionImpl: public Poco::RefCountedObject
|
||||
/// SessionImpl objects are noncopyable.
|
||||
{
|
||||
public:
|
||||
SessionImpl();
|
||||
SessionImpl(const std::string& connectionString);
|
||||
/// Creates the SessionImpl.
|
||||
|
||||
virtual ~SessionImpl();
|
||||
@@ -84,6 +86,18 @@ public:
|
||||
virtual bool isTransaction() = 0;
|
||||
/// Returns true iff a transaction is a transaction is in progress, false otherwise.
|
||||
|
||||
virtual const std::string& connectorName() = 0;
|
||||
/// Returns the name of the connector.
|
||||
|
||||
const std::string& connectionString();
|
||||
/// Returns the connection string.
|
||||
|
||||
static std::string uri(const std::string& connector, const std::string& connectionString);
|
||||
/// Returns formatted URI.
|
||||
|
||||
std::string uri();
|
||||
/// Returns the URI for this session.
|
||||
|
||||
virtual void setFeature(const std::string& name, bool state) = 0;
|
||||
/// Set the state of a feature.
|
||||
///
|
||||
@@ -121,11 +135,36 @@ public:
|
||||
/// not supported by the underlying implementation.
|
||||
|
||||
private:
|
||||
SessionImpl();
|
||||
SessionImpl(const SessionImpl&);
|
||||
SessionImpl& operator = (const SessionImpl&);
|
||||
|
||||
std::string _connectionString;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline const std::string& SessionImpl::connectionString()
|
||||
{
|
||||
return _connectionString;
|
||||
}
|
||||
|
||||
|
||||
inline std::string SessionImpl::uri(const std::string& connector,
|
||||
const std::string& connectionString)
|
||||
{
|
||||
return format("%s:///%s", toLower(connector), connectionString);
|
||||
}
|
||||
|
||||
|
||||
inline std::string SessionImpl::uri()
|
||||
{
|
||||
return uri(connectorName(), connectionString());
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
|
||||
@@ -89,12 +89,12 @@ class Data_API SessionPool: public RefCountedObject
|
||||
/// ...
|
||||
{
|
||||
public:
|
||||
SessionPool(const std::string& sessionKey,
|
||||
SessionPool(const std::string& connector,
|
||||
const std::string& connectionString,
|
||||
int minSessions = 1,
|
||||
int maxSessions = 32,
|
||||
int idleTime = 60);
|
||||
/// Creates the SessionPool for sessions with the given sessionKey
|
||||
/// Creates the SessionPool for sessions with the given connector
|
||||
/// and connectionString.
|
||||
///
|
||||
/// The pool allows for at most maxSessions sessions to be created.
|
||||
@@ -136,9 +136,9 @@ public:
|
||||
std::string name() const;
|
||||
/// Returns the name for this pool.
|
||||
|
||||
static std::string name(const std::string sessionKey,
|
||||
static std::string name(const std::string& connector,
|
||||
const std::string& connectionString);
|
||||
/// Returns the name formatted from supplied arguments as "sessionKey://connectionString".
|
||||
/// Returns the name formatted from supplied arguments as "connector://connectionString".
|
||||
|
||||
void setFeature(const std::string& name, bool state);
|
||||
/// Sets feature for all the sessions.
|
||||
@@ -172,7 +172,7 @@ private:
|
||||
|
||||
void closeAll(SessionList& sessionList);
|
||||
|
||||
std::string _sessionKey;
|
||||
std::string _connector;
|
||||
std::string _connectionString;
|
||||
int _minSessions;
|
||||
int _maxSessions;
|
||||
@@ -191,16 +191,16 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline std::string SessionPool::name(const std::string sessionKey,
|
||||
inline std::string SessionPool::name(const std::string& connector,
|
||||
const std::string& connectionString)
|
||||
{
|
||||
return format("%s://%s", sessionKey, connectionString);
|
||||
return Session::uri(connector, connectionString);
|
||||
}
|
||||
|
||||
|
||||
inline std::string SessionPool::name() const
|
||||
{
|
||||
return name(_sessionKey, _connectionString);
|
||||
return name(_connector, _connectionString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user