mirror of
https://github.com/oatpp/oatpp.git
synced 2025-02-05 17:09:38 +08:00
ORM: use provider::ResourceHandle.
This commit is contained in:
parent
05405fff86
commit
ddb25bed54
@ -118,7 +118,7 @@ OATPP_MACRO_PARAM_USECASE_BODY X
|
||||
const oatpp::data::share::StringTemplate Z_QUERY_TEMPLATE_##NAME = \
|
||||
this->parseQueryTemplate(#NAME, QUERY_TEXT, {}, false); \
|
||||
\
|
||||
std::shared_ptr<oatpp::orm::QueryResult> NAME(const std::shared_ptr<oatpp::orm::Connection>& connection = nullptr) { \
|
||||
std::shared_ptr<oatpp::orm::QueryResult> NAME(const oatpp::provider::ResourceHandle<oatpp::orm::Connection>& connection = nullptr) { \
|
||||
std::unordered_map<oatpp::String, oatpp::Void> __params; \
|
||||
return this->execute(Z_QUERY_TEMPLATE_##NAME, __params, connection); \
|
||||
}
|
||||
@ -139,7 +139,7 @@ const oatpp::data::share::StringTemplate Z_QUERY_TEMPLATE_##NAME = Z_QUERY_TEMPL
|
||||
\
|
||||
std::shared_ptr<oatpp::orm::QueryResult> NAME( \
|
||||
OATPP_MACRO_FOREACH(OATPP_MACRO_DB_CLIENT_PARAM_PUT_DECL, __VA_ARGS__) \
|
||||
const std::shared_ptr<oatpp::orm::Connection>& connection = nullptr \
|
||||
const oatpp::provider::ResourceHandle<oatpp::orm::Connection>& connection = nullptr \
|
||||
) { \
|
||||
std::unordered_map<oatpp::String, oatpp::Void> __params; \
|
||||
OATPP_MACRO_FOREACH(OATPP_MACRO_DB_CLIENT_PARAM_PUT, __VA_ARGS__) \
|
||||
|
@ -33,7 +33,7 @@ DbClient::DbClient(const std::shared_ptr<Executor>& executor)
|
||||
, m_typeResolver(executor->createTypeResolver())
|
||||
{}
|
||||
|
||||
std::shared_ptr<Connection> DbClient::getConnection() {
|
||||
provider::ResourceHandle<Connection> DbClient::getConnection() {
|
||||
return m_executor->getConnection();
|
||||
}
|
||||
|
||||
@ -55,19 +55,19 @@ data::share::StringTemplate DbClient::parseQueryTemplate(const oatpp::String& na
|
||||
|
||||
std::shared_ptr<QueryResult> DbClient::execute(const data::share::StringTemplate& queryTemplate,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<Connection>& connection)
|
||||
const provider::ResourceHandle<Connection>& connection)
|
||||
{
|
||||
return m_executor->execute(queryTemplate, params, m_typeResolver, connection);
|
||||
}
|
||||
|
||||
std::shared_ptr<QueryResult> DbClient::executeQuery(const oatpp::String& query,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<Connection>& connection)
|
||||
const provider::ResourceHandle<Connection>& connection)
|
||||
{
|
||||
return m_executor->execute(query, params, m_typeResolver, connection);
|
||||
}
|
||||
|
||||
Transaction DbClient::beginTransaction(const std::shared_ptr<Connection>& connection) {
|
||||
Transaction DbClient::beginTransaction(const provider::ResourceHandle<Connection>& connection) {
|
||||
return Transaction(m_executor, connection);
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
* Get database connection.
|
||||
* @return
|
||||
*/
|
||||
std::shared_ptr<Connection> getConnection();
|
||||
provider::ResourceHandle<Connection> getConnection();
|
||||
|
||||
/**
|
||||
* Set enabled type interpretations.
|
||||
@ -94,7 +94,7 @@ public:
|
||||
*/
|
||||
std::shared_ptr<QueryResult> execute(const data::share::StringTemplate& queryTemplate,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<Connection>& connection = nullptr);
|
||||
const provider::ResourceHandle<Connection>& connection = nullptr);
|
||||
|
||||
/**
|
||||
* Execute arbitrary query.
|
||||
@ -105,14 +105,14 @@ public:
|
||||
*/
|
||||
std::shared_ptr<QueryResult> executeQuery(const oatpp::String& query,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<Connection>& connection = nullptr);
|
||||
const provider::ResourceHandle<Connection>& connection = nullptr);
|
||||
|
||||
/**
|
||||
* Begin database transaction.
|
||||
* @param connection - database connection.
|
||||
* @return - &id:oatpp::orm::Transaction;.
|
||||
*/
|
||||
Transaction beginTransaction(const std::shared_ptr<Connection>& connection = nullptr);
|
||||
Transaction beginTransaction(const provider::ResourceHandle<Connection>& connection = nullptr);
|
||||
|
||||
};
|
||||
|
||||
|
@ -37,7 +37,7 @@ std::shared_ptr<const data::mapping::TypeResolver> Executor::getDefaultTypeResol
|
||||
std::shared_ptr<QueryResult> Executor::execute(const oatpp::String& query,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<const data::mapping::TypeResolver>& typeResolver,
|
||||
const std::shared_ptr<Connection>& connection)
|
||||
const provider::ResourceHandle<Connection>& connection)
|
||||
{
|
||||
const auto& qt = parseQueryTemplate(nullptr, query, ParamsTypeMap(), false);
|
||||
return execute(qt, params, typeResolver, connection);
|
||||
|
@ -72,7 +72,7 @@ public:
|
||||
* Get database connection.
|
||||
* @return
|
||||
*/
|
||||
virtual std::shared_ptr<Connection> getConnection() = 0;
|
||||
virtual provider::ResourceHandle<Connection> getConnection() = 0;
|
||||
|
||||
/**
|
||||
* Parse query template.
|
||||
@ -98,7 +98,7 @@ public:
|
||||
virtual std::shared_ptr<QueryResult> execute(const StringTemplate& queryTemplate,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<const data::mapping::TypeResolver>& typeResolver = nullptr,
|
||||
const std::shared_ptr<Connection>& connection = nullptr) = 0;
|
||||
const provider::ResourceHandle<Connection>& connection = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* Execute an arbitrary database query. <br>
|
||||
@ -113,28 +113,28 @@ public:
|
||||
virtual std::shared_ptr<QueryResult> execute(const oatpp::String& query,
|
||||
const std::unordered_map<oatpp::String, oatpp::Void>& params,
|
||||
const std::shared_ptr<const data::mapping::TypeResolver>& typeResolver = nullptr,
|
||||
const std::shared_ptr<Connection>& connection = nullptr);
|
||||
const provider::ResourceHandle<Connection>& connection = nullptr);
|
||||
|
||||
/**
|
||||
* Begin database transaction. Should NOT be used directly. Use &id:oatpp::orm::Transaction; instead.
|
||||
* @param connection - database connection.
|
||||
* @return - &id:oatpp::orm::QueryResult;.
|
||||
*/
|
||||
virtual std::shared_ptr<QueryResult> begin(const std::shared_ptr<Connection>& connection = nullptr) = 0;
|
||||
virtual std::shared_ptr<QueryResult> begin(const provider::ResourceHandle<Connection>& connection = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* Commit database transaction. Should NOT be used directly. Use &id:oatpp::orm::Transaction; instead.
|
||||
* @param connection
|
||||
* @return - &id:oatpp::orm::QueryResult;.
|
||||
*/
|
||||
virtual std::shared_ptr<QueryResult> commit(const std::shared_ptr<Connection>& connection) = 0;
|
||||
virtual std::shared_ptr<QueryResult> commit(const provider::ResourceHandle<Connection>& connection) = 0;
|
||||
|
||||
/**
|
||||
* Rollback database transaction. Should NOT be used directly. Use &id:oatpp::orm::Transaction; instead.
|
||||
* @param connection
|
||||
* @return - &id:oatpp::orm::QueryResult;.
|
||||
*/
|
||||
virtual std::shared_ptr<QueryResult> rollback(const std::shared_ptr<Connection>& connection) = 0;
|
||||
virtual std::shared_ptr<QueryResult> rollback(const provider::ResourceHandle<Connection>& connection) = 0;
|
||||
|
||||
/**
|
||||
* Get current database schema version.
|
||||
@ -143,7 +143,7 @@ public:
|
||||
* @return - schema version.
|
||||
*/
|
||||
virtual v_int64 getSchemaVersion(const oatpp::String& suffix = nullptr,
|
||||
const std::shared_ptr<Connection>& connection = nullptr) = 0;
|
||||
const provider::ResourceHandle<Connection>& connection = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* Run schema migration script. Should NOT be used directly. Use &id:oatpp::orm::SchemaMigration; instead.
|
||||
@ -155,7 +155,7 @@ public:
|
||||
virtual void migrateSchema(const oatpp::String& script,
|
||||
v_int64 newVersion,
|
||||
const oatpp::String& suffix = nullptr,
|
||||
const std::shared_ptr<Connection>& connection = nullptr) = 0;
|
||||
const provider::ResourceHandle<Connection>& connection = nullptr) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#define oatpp_orm_QueryResult_hpp
|
||||
|
||||
#include "Connection.hpp"
|
||||
#include "oatpp/core/provider/Provider.hpp"
|
||||
#include "oatpp/core/Types.hpp"
|
||||
|
||||
namespace oatpp { namespace orm {
|
||||
@ -45,7 +46,7 @@ public:
|
||||
* Get DB connection associated with this result.
|
||||
* @return
|
||||
*/
|
||||
virtual std::shared_ptr<Connection> getConnection() const = 0;
|
||||
virtual provider::ResourceHandle<Connection> getConnection() const = 0;
|
||||
|
||||
/**
|
||||
* Check if the query was successful.
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
namespace oatpp { namespace orm {
|
||||
|
||||
Transaction::Transaction(const base::ObjectHandle<Executor>& executor, const std::shared_ptr<Connection>& connection)
|
||||
Transaction::Transaction(const base::ObjectHandle<Executor>& executor, const provider::ResourceHandle<Connection>& connection)
|
||||
: m_executor(executor)
|
||||
, m_open(true)
|
||||
{
|
||||
@ -70,7 +70,7 @@ Transaction& Transaction::operator=(Transaction&& other) {
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Connection> Transaction::getConnection() const {
|
||||
provider::ResourceHandle<Connection> Transaction::getConnection() const {
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ private:
|
||||
base::ObjectHandle<Executor> m_executor;
|
||||
bool m_open;
|
||||
private:
|
||||
std::shared_ptr<Connection> m_connection;
|
||||
provider::ResourceHandle<Connection> m_connection;
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ public:
|
||||
* @param executor - &id:oatpp::orm::Executor;.
|
||||
* @param connection - database connection.
|
||||
*/
|
||||
Transaction(const base::ObjectHandle<Executor>& executor, const std::shared_ptr<Connection>& connection = nullptr);
|
||||
Transaction(const base::ObjectHandle<Executor>& executor, const provider::ResourceHandle<Connection>& connection = nullptr);
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
@ -73,7 +73,7 @@ public:
|
||||
* **Note:** all database queries within the transaction MUST be called on this connection.
|
||||
* @return
|
||||
*/
|
||||
std::shared_ptr<Connection> getConnection() const;
|
||||
provider::ResourceHandle<Connection> getConnection() const;
|
||||
|
||||
/**
|
||||
* Commit transaction.
|
||||
|
Loading…
Reference in New Issue
Block a user