Connection pool fixes

This commit is contained in:
Sandro Mani 2015-05-26 10:58:28 +02:00
parent 72c9830178
commit a6bf6e9a6b
4 changed files with 17 additions and 14 deletions

View File

@ -123,9 +123,8 @@ class QgsConnectionPoolGroup
void release( T conn )
{
acquiredConns.removeAll( conn );
connMutex.lock();
acquiredConns.removeAll( conn );
Item i;
i.c = conn;
i.lastUsedTime = QTime::currentTime();
@ -255,6 +254,20 @@ class QgsConnectionPool
group->release( conn );
}
//! Invalidates all connections to the specified resource.
//! The internal state of certain handles (for instance OGR) are altered
//! when a dataset is modified. Consquently, all open handles need to be
//! invalidated when such datasets are changed to ensure the handles are
//! refreshed. See the OGR provider for an example where this is needed.
void invalidateConnections( const QString& connInfo )
{
mMutex.lock();
if ( mGroups.contains( connInfo ) )
mGroups[connInfo]->invalidateConnections();
mMutex.unlock();
}
protected:
T_Groups mGroups;
QMutex mMutex;

View File

@ -31,11 +31,3 @@ QgsOgrConnPool::~QgsOgrConnPool()
{
QgsDebugCall;
}
void QgsOgrConnPool::invalidateHandles( const QString& connInfo )
{
mMutex.lock();
if ( mGroups.contains( connInfo ) )
mGroups[connInfo]->invalidateConnections();
mMutex.unlock();
}

View File

@ -79,8 +79,6 @@ class QgsOgrConnPool : public QgsConnectionPool<QgsOgrConn*, QgsOgrConnPoolGroup
public:
static QgsOgrConnPool* instance();
void invalidateHandles( const QString& connInfo );
protected:
Q_DISABLE_COPY( QgsOgrConnPool )

View File

@ -741,7 +741,7 @@ OGRwkbGeometryType QgsOgrProvider::getOgrGeomType( OGRLayerH ogrLayer )
void QgsOgrProvider::loadFields()
{
QgsOgrConnPool::instance()->invalidateHandles( filePath() );
QgsOgrConnPool::instance()->invalidateConnections( filePath() );
//the attribute fields need to be read again when the encoding changes
mAttributeFields.clear();
@ -2524,7 +2524,7 @@ void QgsOgrProvider::recalculateFeatureCount()
OGR_L_SetSpatialFilter( ogrLayer, filter );
}
QgsOgrConnPool::instance()->invalidateHandles( filePath() );
QgsOgrConnPool::instance()->invalidateConnections( filePath() );
}
OGRwkbGeometryType QgsOgrProvider::ogrWkbSingleFlatten( OGRwkbGeometryType type )