-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add connection pool for OGR provider (Funded by Sourcepole QGIS Enter…
…prise)
- Loading branch information
1 parent
2c5c866
commit b4f4663
Showing
9 changed files
with
191 additions
and
13 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,41 @@ | ||
/*************************************************************************** | ||
qgsogrconnpool.cpp | ||
--------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Sandro Mani | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsogrconnpool.h" | ||
|
||
|
||
QgsOgrConnPool* QgsOgrConnPool::instance() | ||
{ | ||
static QgsOgrConnPool sInstance; | ||
return &sInstance; | ||
} | ||
|
||
QgsOgrConnPool::QgsOgrConnPool() : QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup>() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
||
QgsOgrConnPool::~QgsOgrConnPool() | ||
{ | ||
QgsDebugCall; | ||
} | ||
|
||
void QgsOgrConnPool::invalidateHandles( const QString& connInfo ) | ||
{ | ||
mMutex.lock(); | ||
if ( mGroups.contains( connInfo ) ) | ||
mGroups[connInfo]->invalidateConnections(); | ||
mMutex.unlock(); | ||
} |
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,93 @@ | ||
/*************************************************************************** | ||
qgsogrconnpool.h | ||
--------------------- | ||
begin : May 2015 | ||
copyright : (C) 2015 by Sandro Mani | ||
email : smani at sourcepole dot ch | ||
*************************************************************************** | ||
* * | ||
* 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 QGSOGRCONNPOOL_H | ||
#define QGSOGRCONNPOOL_H | ||
|
||
#include "qgsconnectionpool.h" | ||
#include <ogr_api.h> | ||
|
||
|
||
struct QgsOgrConn | ||
{ | ||
QString path; | ||
OGRDataSourceH ds; | ||
bool valid; | ||
}; | ||
|
||
inline QString qgsConnectionPool_ConnectionToName( QgsOgrConn* c ) | ||
{ | ||
return c->path; | ||
} | ||
|
||
inline void qgsConnectionPool_ConnectionCreate( QString connInfo, QgsOgrConn*& c ) | ||
{ | ||
c = new QgsOgrConn; | ||
c->ds = OGROpen( connInfo.toUtf8().constData(), false, NULL ); | ||
c->path = connInfo; | ||
c->valid = true; | ||
} | ||
|
||
inline void qgsConnectionPool_ConnectionDestroy( QgsOgrConn* c ) | ||
{ | ||
OGR_DS_Destroy( c->ds ); | ||
delete c; | ||
} | ||
|
||
inline void qgsConnectionPool_InvalidateConnection( QgsOgrConn* c ) | ||
{ | ||
c->valid = false; | ||
} | ||
|
||
inline bool qgsConnectionPool_ConnectionIsValid( QgsOgrConn* c ) | ||
{ | ||
return c->valid; | ||
} | ||
|
||
class QgsOgrConnPoolGroup : public QObject, public QgsConnectionPoolGroup<QgsOgrConn*> | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
QgsOgrConnPoolGroup( QString name ) : QgsConnectionPoolGroup<QgsOgrConn*>( name ) { initTimer( this ); } | ||
|
||
protected slots: | ||
void handleConnectionExpired() { onConnectionExpired(); } | ||
void startExpirationTimer() { expirationTimer->start(); } | ||
void stopExpirationTimer() { expirationTimer->stop(); } | ||
|
||
protected: | ||
Q_DISABLE_COPY( QgsOgrConnPoolGroup ) | ||
|
||
}; | ||
|
||
/** Ogr connection pool - singleton */ | ||
class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup> | ||
{ | ||
public: | ||
static QgsOgrConnPool* instance(); | ||
|
||
void invalidateHandles( const QString& connInfo ); | ||
|
||
protected: | ||
Q_DISABLE_COPY( QgsOgrConnPool ) | ||
|
||
private: | ||
QgsOgrConnPool(); | ||
~QgsOgrConnPool(); | ||
}; | ||
|
||
|
||
#endif // QGSOGRCONNPOOL_H |
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
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
b4f4663
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manisandro , I believe this regression ( http://hub.qgis.org/issues/14560 ) is caused by connection pooling for OGR provider. Basically, when you load a singular dataset onto two layers of different geometry type (e.g. polygon and point), the feature fetching process gets messed up.
The above-refered issue has a test project file and straight forward steps to reproduce the issue. Hope that can be of help. As it stands, it'll be a regression when people upgrade from 2.8 LTS to 2.14 LTS.