Skip to content

Commit 3071ed1

Browse files
committed
update to the latest oatpp API version.
1 parent 50f5e06 commit 3071ed1

18 files changed

+119
-116
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
55
## use these variables to configure module installation
66

77
set(OATPP_THIS_MODULE_NAME oatpp-postgresql) ## name of the module (also name of folders in installation dirs)
8-
set(OATPP_THIS_MODULE_VERSION "1.2.5") ## version of the module (also sufix of folders in installation dirs)
8+
set(OATPP_THIS_MODULE_VERSION "1.3.0") ## version of the module (also sufix of folders in installation dirs)
99
set(OATPP_THIS_MODULE_LIBRARIES oatpp-postgresql) ## list of libraries to find when find_package is called
1010
set(OATPP_THIS_MODULE_TARGETS oatpp-postgresql) ## list of targets to install
1111
set(OATPP_THIS_MODULE_DIRECTORIES oatpp-postgresql) ## list of directories to install

azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# https://aka.ms/yaml
55

66
jobs:
7-
- job: ubuntu_16_04
8-
displayName: 'Build - Ubuntu 16.04'
7+
- job: ubuntu_20_04
8+
displayName: 'Build - Ubuntu 20.04'
99
continueOnError: false
1010
pool:
11-
vmImage: 'Ubuntu 16.04'
11+
vmImage: 'ubuntu-20.04'
1212
workspace:
1313
clean: all
1414
steps:

src/oatpp-postgresql/Connection.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,21 @@ class ConnectionImpl : public Connection {
6868

6969
struct ConnectionAcquisitionProxy : public provider::AcquisitionProxy<Connection, ConnectionAcquisitionProxy> {
7070

71-
ConnectionAcquisitionProxy(const std::shared_ptr<Connection> &resource,
71+
ConnectionAcquisitionProxy(const provider::ResourceHandle<Connection> &resource,
7272
const std::shared_ptr<PoolInstance> &pool)
7373
: provider::AcquisitionProxy<Connection, ConnectionAcquisitionProxy>(resource, pool)
7474
{}
7575

7676
PGconn* getHandle() override {
77-
return _obj->getHandle();
77+
return _handle.object->getHandle();
7878
}
7979

8080
void setPrepared(const oatpp::String& statementName) override {
81-
_obj->setPrepared(statementName);
81+
_handle.object->setPrepared(statementName);
8282
}
8383

8484
bool isPrepared(const oatpp::String& statementName) override {
85-
return _obj->isPrepared(statementName);
85+
return _handle.object->isPrepared(statementName);
8686
}
8787

8888
};

src/oatpp-postgresql/ConnectionProvider.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@
2626

2727
namespace oatpp { namespace postgresql {
2828

29+
void ConnectionProvider::ConnectionInvalidator::invalidate(const std::shared_ptr<orm::Connection> &resource) {
30+
(void) resource;
31+
//Do nothing.
32+
}
33+
2934
ConnectionProvider::ConnectionProvider(const oatpp::String& connectionString)
30-
: m_connectionString(connectionString)
35+
: m_invalidator(std::make_shared<ConnectionInvalidator>())
36+
, m_connectionString(connectionString)
3137
{}
3238

33-
std::shared_ptr<Connection> ConnectionProvider::get() {
39+
provider::ResourceHandle<orm::Connection> ConnectionProvider::get() {
3440

3541
auto handle = PQconnectdb(m_connectionString->c_str());
3642

@@ -41,18 +47,14 @@ std::shared_ptr<Connection> ConnectionProvider::get() {
4147
"Error. Can't connect. " + errMsg);
4248
}
4349

44-
return std::make_shared<ConnectionImpl>(handle);
50+
return provider::ResourceHandle<orm::Connection>(std::make_shared<ConnectionImpl>(handle), m_invalidator);
4551

4652
}
4753

48-
async::CoroutineStarterForResult<const std::shared_ptr<Connection>&> ConnectionProvider::getAsync() {
54+
async::CoroutineStarterForResult<const provider::ResourceHandle<orm::Connection>&> ConnectionProvider::getAsync() {
4955
throw std::runtime_error("[oatpp::postgresql::ConnectionProvider::getAsync()]: Error. Not implemented!");
5056
}
5157

52-
void ConnectionProvider::invalidate(const std::shared_ptr<Connection>& resource) {
53-
// DO nothing
54-
}
55-
5658
void ConnectionProvider::stop() {
5759
// DO nothing
5860
}

src/oatpp-postgresql/ConnectionProvider.hpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ namespace oatpp { namespace postgresql {
3535
/**
3636
* Connection provider.
3737
*/
38-
class ConnectionProvider : public provider::Provider<Connection> {
38+
class ConnectionProvider : public provider::Provider<orm::Connection> {
3939
private:
40+
41+
class ConnectionInvalidator : public provider::Invalidator<orm::Connection> {
42+
public:
43+
void invalidate(const std::shared_ptr<orm::Connection>& resource) override;
44+
};
45+
46+
private:
47+
std::shared_ptr<ConnectionInvalidator> m_invalidator;
4048
oatpp::String m_connectionString;
4149
public:
4250

@@ -50,19 +58,13 @@ class ConnectionProvider : public provider::Provider<Connection> {
5058
* Get Connection.
5159
* @return - resource.
5260
*/
53-
std::shared_ptr<Connection> get() override;
61+
provider::ResourceHandle<orm::Connection> get() override;
5462

5563
/**
5664
* Get Connection in Async manner.
5765
* @return - &id:oatpp::async::CoroutineStarterForResult; of `Connection`.
5866
*/
59-
async::CoroutineStarterForResult<const std::shared_ptr<Connection>&> getAsync() override;
60-
61-
/**
62-
* Invalidate Connection that was previously created by this provider. <br>
63-
* @param resource
64-
*/
65-
void invalidate(const std::shared_ptr<Connection>& resource) override;
67+
async::CoroutineStarterForResult<const provider::ResourceHandle<orm::Connection>&> getAsync() override;
6668

6769
/**
6870
* Stop provider and free associated resources.
@@ -77,7 +79,7 @@ class ConnectionProvider : public provider::Provider<Connection> {
7779
* - &id:oatpp::postgresql::ConnectionAcquisitionProxy;.
7880
*/
7981
typedef oatpp::provider::Pool<
80-
provider::Provider<Connection>,
82+
provider::Provider<orm::Connection>,
8183
Connection,
8284
ConnectionAcquisitionProxy
8385
> ConnectionPool;

0 commit comments

Comments
 (0)