mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-30 21:50:47 +01:00
SF [2643953] Improve Data::Session connection
This commit is contained in:
@@ -72,11 +72,12 @@ public:
|
||||
typedef Poco::Any (C::*PropertyGetter)(const std::string&);
|
||||
/// The getter method for a property.
|
||||
|
||||
AbstractSessionImpl(const std::string& connectionString): SessionImpl(connectionString),
|
||||
_storage(std::string("deque")),
|
||||
_bulk(false),
|
||||
_emptyStringIsNull(false),
|
||||
_forceEmptyString(false)
|
||||
AbstractSessionImpl(const std::string& connectionString,
|
||||
std::size_t timeout = CONNECT_TIMEOUT_DEFAULT): SessionImpl(connectionString, timeout),
|
||||
_storage(std::string("deque")),
|
||||
_bulk(false),
|
||||
_emptyStringIsNull(false),
|
||||
_forceEmptyString(false)
|
||||
/// Creates the AbstractSessionImpl.
|
||||
///
|
||||
/// Adds "storage" property and sets the default internal storage container
|
||||
|
||||
@@ -66,7 +66,8 @@ public:
|
||||
virtual const std::string& name() const = 0;
|
||||
/// Returns the name associated with this connector.
|
||||
|
||||
virtual Poco::AutoPtr<SessionImpl> createSession(const std::string& connectionString) = 0;
|
||||
virtual Poco::AutoPtr<SessionImpl> createSession(const std::string& connectionString,
|
||||
std::size_t timeout = SessionImpl::CONNECT_TIMEOUT_DEFAULT) = 0;
|
||||
/// Create a SessionImpl object and initialize it with the given connectionString.
|
||||
};
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExhaustedException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExistsException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, NoDataException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, LengthExceededException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, ConnectionFailedException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, NotConnectedException, DataException)
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
@@ -70,6 +70,7 @@ public:
|
||||
void begin();
|
||||
void commit();
|
||||
void rollback();
|
||||
void open(const std::string& connect = "");
|
||||
void close();
|
||||
bool isConnected();
|
||||
bool canTransact();
|
||||
|
||||
@@ -173,6 +173,7 @@ class Data_API Session
|
||||
/// For complete list of supported data types with their respective specifications, see the documentation for format in Foundation.
|
||||
{
|
||||
public:
|
||||
static const std::size_t CONNECT_TIMEOUT_DEFAULT = SessionImpl::CONNECT_TIMEOUT_DEFAULT;
|
||||
static const Poco::UInt32 TRANSACTION_READ_UNCOMMITTED = 0x00000001L;
|
||||
static const Poco::UInt32 TRANSACTION_READ_COMMITTED = 0x00000002L;
|
||||
static const Poco::UInt32 TRANSACTION_REPEATABLE_READ = 0x00000004L;
|
||||
@@ -181,11 +182,14 @@ public:
|
||||
Session(Poco::AutoPtr<SessionImpl> ptrImpl);
|
||||
/// Creates the Session.
|
||||
|
||||
Session(const std::string& connector, const std::string& connectionString);
|
||||
Session(const std::string& connector,
|
||||
const std::string& connectionString,
|
||||
std::size_t timeout = CONNECT_TIMEOUT_DEFAULT);
|
||||
/// Creates a new session, using the given connector (which must have
|
||||
/// been registered), and connectionString.
|
||||
|
||||
Session(const std::string& connection);
|
||||
Session(const std::string& connection,
|
||||
std::size_t timeout = CONNECT_TIMEOUT_DEFAULT);
|
||||
/// Creates a new session, using the given connection (must be in
|
||||
/// "connection:///connectionString" format).
|
||||
|
||||
@@ -211,6 +215,29 @@ public:
|
||||
StatementImpl* createStatementImpl();
|
||||
/// Creates a StatementImpl.
|
||||
|
||||
void open(const std::string& connect = "");
|
||||
/// Opens the session using the supplied string.
|
||||
/// Can also be used with default empty string to
|
||||
/// reconnect a disconnected session.
|
||||
/// If the connection is not established,
|
||||
/// a ConnectionFailedException is thrown.
|
||||
/// Zero timout means indefinite
|
||||
|
||||
void close();
|
||||
/// Closes the session.
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true iff session is connected, false otherwise.
|
||||
|
||||
void reconnect();
|
||||
/// Closes the session and opens it.
|
||||
|
||||
void setTimeout(std::size_t timeout);
|
||||
/// Sets the session timeout value.
|
||||
|
||||
std::size_t getTimeout() const;
|
||||
/// Returns the session timeout value.
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction.
|
||||
|
||||
@@ -219,12 +246,6 @@ public:
|
||||
|
||||
void rollback();
|
||||
/// Rolls back and ends a transaction.
|
||||
|
||||
void close();
|
||||
/// Closes the session.
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true iff session is connected, false otherwise.
|
||||
|
||||
bool canTransact();
|
||||
/// Returns true if session has transaction capabilities.
|
||||
@@ -296,7 +317,7 @@ public:
|
||||
private:
|
||||
Session();
|
||||
|
||||
Poco::AutoPtr<SessionImpl> _ptrImpl;
|
||||
Poco::AutoPtr<SessionImpl> _pImpl;
|
||||
StatementCreator _statementCreator;
|
||||
};
|
||||
|
||||
@@ -306,73 +327,97 @@ private:
|
||||
//
|
||||
inline StatementImpl* Session::createStatementImpl()
|
||||
{
|
||||
return _ptrImpl->createStatementImpl();
|
||||
return _pImpl->createStatementImpl();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::begin()
|
||||
inline void Session::open(const std::string& connect)
|
||||
{
|
||||
return _ptrImpl->begin();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::commit()
|
||||
{
|
||||
return _ptrImpl->commit();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::rollback()
|
||||
{
|
||||
return _ptrImpl->rollback();
|
||||
_pImpl->open(connect);
|
||||
}
|
||||
|
||||
|
||||
inline void Session::close()
|
||||
{
|
||||
_ptrImpl->close();
|
||||
_pImpl->close();
|
||||
}
|
||||
|
||||
|
||||
inline bool Session::isConnected()
|
||||
{
|
||||
return _ptrImpl->isConnected();
|
||||
return _pImpl->isConnected();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::reconnect()
|
||||
{
|
||||
_pImpl->reconnect();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::setTimeout(std::size_t timeout)
|
||||
{
|
||||
_pImpl->setTimeout(timeout);
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Session::getTimeout() const
|
||||
{
|
||||
return _pImpl->getTimeout();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::begin()
|
||||
{
|
||||
return _pImpl->begin();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::commit()
|
||||
{
|
||||
return _pImpl->commit();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::rollback()
|
||||
{
|
||||
return _pImpl->rollback();
|
||||
}
|
||||
|
||||
|
||||
inline bool Session::canTransact()
|
||||
{
|
||||
return _ptrImpl->canTransact();
|
||||
return _pImpl->canTransact();
|
||||
}
|
||||
|
||||
|
||||
inline bool Session::isTransaction()
|
||||
{
|
||||
return _ptrImpl->isTransaction();
|
||||
return _pImpl->isTransaction();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::setTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
_ptrImpl->setTransactionIsolation(ti);
|
||||
_pImpl->setTransactionIsolation(ti);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 Session::getTransactionIsolation()
|
||||
{
|
||||
return _ptrImpl->getTransactionIsolation();
|
||||
return _pImpl->getTransactionIsolation();
|
||||
}
|
||||
|
||||
|
||||
inline bool Session::hasTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
return _ptrImpl->hasTransactionIsolation(ti);
|
||||
return _pImpl->hasTransactionIsolation(ti);
|
||||
}
|
||||
|
||||
|
||||
inline bool Session::isTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
return _ptrImpl->isTransactionIsolation(ti);
|
||||
return _pImpl->isTransactionIsolation(ti);
|
||||
}
|
||||
|
||||
|
||||
@@ -385,37 +430,37 @@ inline std::string Session::uri(const std::string& connector,
|
||||
|
||||
inline std::string Session::uri()
|
||||
{
|
||||
return _ptrImpl->uri();
|
||||
return _pImpl->uri();
|
||||
}
|
||||
|
||||
|
||||
inline void Session::setFeature(const std::string& name, bool state)
|
||||
{
|
||||
_ptrImpl->setFeature(name, state);
|
||||
_pImpl->setFeature(name, state);
|
||||
}
|
||||
|
||||
|
||||
inline bool Session::getFeature(const std::string& name) const
|
||||
{
|
||||
return const_cast<SessionImpl*>(_ptrImpl.get())->getFeature(name);
|
||||
return const_cast<SessionImpl*>(_pImpl.get())->getFeature(name);
|
||||
}
|
||||
|
||||
|
||||
inline void Session::setProperty(const std::string& name, const Poco::Any& value)
|
||||
{
|
||||
_ptrImpl->setProperty(name, value);
|
||||
_pImpl->setProperty(name, value);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::Any Session::getProperty(const std::string& name) const
|
||||
{
|
||||
return const_cast<SessionImpl*>(_ptrImpl.get())->getProperty(name);
|
||||
return const_cast<SessionImpl*>(_pImpl.get())->getProperty(name);
|
||||
}
|
||||
|
||||
|
||||
inline SessionImpl* Session::impl()
|
||||
{
|
||||
return _ptrImpl;
|
||||
return _pImpl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -83,11 +83,14 @@ public:
|
||||
/// Lowers the reference count for the Connector registered under that key. If the count reaches zero,
|
||||
/// the object is removed.
|
||||
|
||||
Session create(const std::string& key, const std::string& connectionString);
|
||||
Session create(const std::string& key,
|
||||
const std::string& connectionString,
|
||||
std::size_t timeout = Session::CONNECT_TIMEOUT_DEFAULT);
|
||||
/// 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);
|
||||
Session create(const std::string& uri,
|
||||
std::size_t timeout = Session::CONNECT_TIMEOUT_DEFAULT);
|
||||
/// 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.
|
||||
|
||||
|
||||
@@ -59,7 +59,14 @@ class Data_API SessionImpl: public Poco::RefCountedObject
|
||||
/// SessionImpl objects are noncopyable.
|
||||
{
|
||||
public:
|
||||
SessionImpl(const std::string& connectionString);
|
||||
static const std::size_t CONNECT_TIMEOUT_INFINITE = 0;
|
||||
/// Infinite connection/login timeout.
|
||||
|
||||
static const std::size_t CONNECT_TIMEOUT_DEFAULT = 30;
|
||||
/// Default connection/login timeout in seconds.
|
||||
|
||||
SessionImpl(const std::string& connectionString,
|
||||
std::size_t timeout = CONNECT_TIMEOUT_DEFAULT);
|
||||
/// Creates the SessionImpl.
|
||||
|
||||
virtual ~SessionImpl();
|
||||
@@ -68,6 +75,29 @@ public:
|
||||
virtual StatementImpl* createStatementImpl() = 0;
|
||||
/// Creates a StatementImpl.
|
||||
|
||||
virtual void open(const std::string& connectionString = "") = 0;
|
||||
/// Opens the session using the supplied string.
|
||||
/// Can also be used with default empty string to reconnect
|
||||
/// a disconnected session.
|
||||
/// If the connection is not established within requested timeout
|
||||
/// (specified in seconds), a ConnectionFailedException is thrown.
|
||||
/// Zero timout means indefinite
|
||||
|
||||
virtual void close() = 0;
|
||||
/// Closes the connection.
|
||||
|
||||
virtual bool isConnected() = 0;
|
||||
/// Returns true if session is connected, false otherwise.
|
||||
|
||||
void setTimeout(std::size_t timeout);
|
||||
/// Sets the session timeout value.
|
||||
|
||||
std::size_t getTimeout() const;
|
||||
/// Returns the session timeout value.
|
||||
|
||||
void reconnect();
|
||||
/// Closes the connection and opens it again.
|
||||
|
||||
virtual void begin() = 0;
|
||||
/// Starts a transaction.
|
||||
|
||||
@@ -77,12 +107,6 @@ public:
|
||||
virtual void rollback() = 0;
|
||||
/// Aborts a transaction.
|
||||
|
||||
virtual void close() = 0;
|
||||
/// Closes the connection.
|
||||
|
||||
virtual bool isConnected() = 0;
|
||||
/// Returns true if session is connected, false otherwise.
|
||||
|
||||
virtual bool canTransact() = 0;
|
||||
/// Returns true if session has transaction capabilities.
|
||||
|
||||
@@ -151,12 +175,19 @@ public:
|
||||
/// Throws a NotSupportedException if the requested property is
|
||||
/// not supported by the underlying implementation.
|
||||
|
||||
protected:
|
||||
void setConnectionString(const std::string& connectionString);
|
||||
/// Sets the connection string. Should only be called on
|
||||
/// disconnetced sessions. Throws InvalidAccessException when called on
|
||||
/// a connected session.
|
||||
|
||||
private:
|
||||
SessionImpl();
|
||||
SessionImpl(const SessionImpl&);
|
||||
SessionImpl& operator = (const SessionImpl&);
|
||||
|
||||
std::string _connectionString;
|
||||
std::size_t _timeout;
|
||||
};
|
||||
|
||||
|
||||
@@ -169,6 +200,18 @@ inline const std::string& SessionImpl::connectionString()
|
||||
}
|
||||
|
||||
|
||||
inline void SessionImpl::setTimeout(std::size_t timeout)
|
||||
{
|
||||
_timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t SessionImpl::getTimeout() const
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
|
||||
inline std::string SessionImpl::uri(const std::string& connector,
|
||||
const std::string& connectionString)
|
||||
{
|
||||
|
||||
@@ -76,6 +76,9 @@ public:
|
||||
Statement operator << (const T& t)
|
||||
/// Creates a Statement.
|
||||
{
|
||||
if (!_ptrImpl->isConnected())
|
||||
throw NotConnectedException(_ptrImpl->connectionString());
|
||||
|
||||
Statement stmt(_ptrImpl->createStatementImpl());
|
||||
stmt << t;
|
||||
return stmt;
|
||||
|
||||
@@ -435,14 +435,14 @@ private:
|
||||
|
||||
State _state;
|
||||
Limit _extrLimit;
|
||||
std::size_t _lowerLimit;
|
||||
std::size_t _lowerLimit;
|
||||
std::vector<int> _columnsExtracted;
|
||||
SessionImpl& _rSession;
|
||||
Storage _storage;
|
||||
std::ostringstream _ostr;
|
||||
AbstractBindingVec _bindings;
|
||||
AbstractExtractionVecVec _extractors;
|
||||
std::size_t _curDataSet;
|
||||
std::size_t _curDataSet;
|
||||
BulkType _bulkBinding;
|
||||
BulkType _bulkExtraction;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user