forked from qgis/QGIS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This refactoring job is related to qgis/QGIS-Enhancement-Proposals#272 …
…and the original pull request for the AWS Redshift driver qgis#53018. - Move qgsConnectionPool_[connectionCreate|connectionDestroy|invalidateConnection|connectionIsValid|connectionToName] into their appropriate abstract classes and declare them as pure virual. - Implement the destructor and the functions above for all providers. - Refactor QgsPostgresConnPool[Group] to QgsSQLConnPool[Group], in order to reuse the template for future SQL based providers (AWS Redshift).
- Loading branch information
Alexey Karandashev
committed
Jul 20, 2023
1 parent
da02b23
commit 852ad1e
Showing
12 changed files
with
426 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/*************************************************************************** | ||
qgssqlconnpool.h | ||
--------------------- | ||
begin : January 2014 | ||
copyright : (C) 2014 by Martin Dobias | ||
email : wonder dot sk at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSQLCONNPOOL_H | ||
#define QGSSQLCONNPOOL_H | ||
#define SIP_NO_FILE | ||
|
||
#include "qgsconnectionpool.h" | ||
#include "qgslogger.h" | ||
|
||
/** | ||
* \ingroup core | ||
* \brief Template class for SQL based provider connection pool group. | ||
* \note not available in Python bindings. | ||
* \since QGIS 3.32 | ||
*/ | ||
template<typename T> | ||
class QgsSqlConnectionPoolGroup : public QgsConnectionPoolGroup<T *> | ||
{ | ||
public: | ||
|
||
/** | ||
* The descendants inherit from QObject and pass a self reference. | ||
*/ | ||
explicit QgsSqlConnectionPoolGroup( const QString &name, QObject *qobject ) : | ||
QgsConnectionPoolGroup<T*>( name ) | ||
{ | ||
QgsConnectionPoolGroup<T *>::initTimer( qobject ); | ||
} | ||
|
||
using typename QgsConnectionPoolGroup<T *>::Item; | ||
using QgsConnectionPoolGroup<T *>::mConnections; | ||
~QgsSqlConnectionPoolGroup() override | ||
{ | ||
for ( const Item &item : std::as_const( mConnections ) ) | ||
{ | ||
connectionDestroy( item.connection ); | ||
} | ||
} | ||
void connectionCreate( const QString &connectionInfo, T *&connection ) override | ||
{ | ||
connection = T::connectDb( connectionInfo, true, false ); | ||
} | ||
|
||
void connectionDestroy( T *connection ) override | ||
{ | ||
connection->unref(); // will delete itself | ||
} | ||
|
||
void invalidateConnection( T * ) override {} | ||
|
||
bool connectionIsValid( T * ) override | ||
{ | ||
return true; | ||
} | ||
}; | ||
|
||
/** | ||
* \ingroup core | ||
* \brief Template class for SQL based provider connection pool. | ||
* \note not available in Python bindings. | ||
* \since QGIS 3.32 | ||
*/ | ||
template<typename T, typename T_Group> | ||
class QgsSqlConnectionPool : public QgsConnectionPool<T *, T_Group> | ||
{ | ||
public: | ||
|
||
/** | ||
* \returns the instance singleton \a sInstance. | ||
*/ | ||
static QgsSqlConnectionPool<T, T_Group> *instance() | ||
{ | ||
if ( !sInstance ) | ||
sInstance = new QgsSqlConnectionPool<T, T_Group>(); | ||
return sInstance; | ||
} | ||
|
||
/** | ||
* Reset the global instance of the connection pool. | ||
*/ | ||
static void cleanupInstance() | ||
{ | ||
delete sInstance; | ||
sInstance = nullptr; | ||
} | ||
|
||
QString connectionToName( T *connection ) override | ||
{ | ||
return connection->connInfo(); | ||
} | ||
|
||
protected: | ||
|
||
/** | ||
* Constructor/Destructor implementation for the sole purpose of debugging. | ||
*/ | ||
QgsSqlConnectionPool<T, T_Group>() : QgsConnectionPool<T *, T_Group>() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
||
~QgsSqlConnectionPool<T, T_Group>() override | ||
{ | ||
QgsDebugCall; | ||
} | ||
private: | ||
static inline QgsSqlConnectionPool<T, T_Group> *sInstance = nullptr; | ||
}; | ||
|
||
|
||
#endif // QGSSQLCONNPOOL_H |
Oops, something went wrong.