caosdb/connection.h

Configuration and setup of the connection.

Author

Timm Fitschen

Date

2021-05-18

namespace caosdb::connection
class Connection
#include <connection.h>

A reusable connection to a CaosDBServer.

Public Functions

explicit Connection(const ConnectionConfiguration &configuration)
auto RetrieveVersionInfoNoExceptions() const noexcept -> TransactionStatus

Request the server’s version and return the status of this request after termination..

The version is stored in the connection object and may be retrieved via GetVersionInfo() if the request was successful.

This method does not throw any exceptions. Errors are indicated in the return value instead.

auto RetrieveVersionInfo() const -> const VersionInfo&

Request and return the server’s version.

If the request terminated unsuccessfully, a corresponding exception is being thrown.

inline auto GetVersionInfo() const noexcept -> const VersionInfo*

Return the server’s version.

Clients need to call RetrieveVersionInfo() or RetrieveVersionInfoNoExceptions() before the version info is locally available. Otherwise a nullptr is being returned.

auto CreateTransaction() const -> std::unique_ptr<Transaction>

Private Members

std::shared_ptr<grpc::Channel> channel

GRPC-Channel (HTTP/2 Connection plus Authentication). We use a shared pointer because Transaction instances also own the channel.

std::unique_ptr<GeneralInfoService::Stub> general_info_service

Service for retrieving the server’s version. We use a unique pointer because only this connection owns and uses this service.

mutable std::unique_ptr<VersionInfo> version_info

The server’s version. It’s mutable because it is rather a cache than a data member which is subject to change.

std::shared_ptr<EntityTransactionService::Stub> entity_transaction_service

Service for entity transactions. We use a shared pointer because Transaction instances also own this service stub.

std::shared_ptr<FileTransmissionService::Stub> file_transmission_service

Service for file transmission (download and upload). We use a shared pointer because Transaction instances also own this service stub.

class ConnectionManager
#include <connection.h>

Lazily creates and caches reusable connection instances.

Lazily creates and caches reusable connection instances. Singleton.

This class delegates the configuration of new connections to the global ConfigurationManager.

A reset of the ConfigurationManager also resets the ConnectionManager.

Public Functions

ConnectionManager(ConnectionManager const&) = delete
void operator=(ConnectionManager const&) = delete

Public Static Functions

static inline ConnectionManager &GetInstance()
static inline auto HasConnection(const std::string &name) -> bool
static inline auto GetConnection(const std::string &name) -> const std::shared_ptr<Connection>&
static inline auto GetDefaultConnection() -> const std::shared_ptr<Connection>&

Get the connection marked by the “default” key in the configuration.

static inline auto Reset() -> void

Private Functions

inline ConnectionManager()
auto mHasConnection(const std::string &name) const -> bool
auto mGetConnection(const std::string &name) const -> const std::shared_ptr<Connection>&
auto mGetDefaultConnection() const -> const std::shared_ptr<Connection>&
inline auto mReset() -> void

Private Members

mutable std::map<std::string, std::shared_ptr<Connection>> connections
mutable std::string default_connection_name