-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Oracle] Fixes #40001 : Use QgsTask to retrieve available tables so w…
…e can properly cancel it
- Loading branch information
Showing
7 changed files
with
215 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*************************************************************************** | ||
qgscolumntypetask.cpp - lookup oracle geometry type and srid in a thread | ||
------------------- | ||
begin : 3.1.2012 | ||
copyright : (C) 2012 by Juergen E. Fischer | ||
email : jef at norbit dot de | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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 "qgsoraclecolumntypetask.h" | ||
#include "qgslogger.h" | ||
#include "qgsoracleconnpool.h" | ||
|
||
#include <QMetaType> | ||
|
||
QgsOracleColumnTypeTask::QgsOracleColumnTypeTask( const QString &name, const QString &limitToSchema, bool useEstimatedMetadata, bool allowGeometrylessTables ) | ||
: QgsTask( tr( "Scanning tables for %1" ).arg( name ) ) | ||
, mName( name ) | ||
, mSchema( limitToSchema ) | ||
, mUseEstimatedMetadata( useEstimatedMetadata ) | ||
, mAllowGeometrylessTables( allowGeometrylessTables ) | ||
{ | ||
qRegisterMetaType<QgsOracleLayerProperty>( "QgsOracleLayerProperty" ); | ||
} | ||
|
||
bool QgsOracleColumnTypeTask::run() | ||
{ | ||
QString conninfo = QgsOracleConn::toPoolName( QgsOracleConn::connUri( mName ) ); | ||
QgsOracleConn *conn = QgsOracleConnPool::instance()->acquireConnection( conninfo ); | ||
if ( !conn ) | ||
{ | ||
QgsDebugMsg( "Connection failed - " + conninfo ); | ||
return false; | ||
} | ||
|
||
emit progressMessage( tr( "Retrieving tables of %1…" ).arg( mName ) ); | ||
QVector<QgsOracleLayerProperty> layerProperties; | ||
if ( !conn->supportedLayers( layerProperties, | ||
mSchema, | ||
QgsOracleConn::geometryColumnsOnly( mName ), | ||
QgsOracleConn::userTablesOnly( mName ), | ||
mAllowGeometrylessTables ) || | ||
layerProperties.isEmpty() ) | ||
{ | ||
return false; | ||
} | ||
|
||
int i = 0, n = layerProperties.size(); | ||
for ( QVector<QgsOracleLayerProperty>::iterator it = layerProperties.begin(), | ||
end = layerProperties.end(); | ||
it != end; ++it ) | ||
{ | ||
QgsOracleLayerProperty &layerProperty = *it; | ||
if ( !isCanceled() ) | ||
{ | ||
setProgress( ( i * 100. ) / n ); | ||
emit progressMessage( tr( "Scanning column %1.%2.%3…" ) | ||
.arg( layerProperty.ownerName, | ||
layerProperty.tableName, | ||
layerProperty.geometryColName ) ); | ||
conn->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata, QgsOracleConn::onlyExistingTypes( mName ) ); | ||
} | ||
|
||
if ( isCanceled() ) | ||
{ | ||
layerProperty.types.clear(); | ||
layerProperty.srids.clear(); | ||
} | ||
|
||
// Now tell the layer list dialog box... | ||
emit setLayerType( layerProperty ); | ||
} | ||
|
||
// store the list for later use (cache) | ||
if ( !isCanceled() ) | ||
mLayerProperties = layerProperties; | ||
|
||
setProgress( 100 ); | ||
emit progressMessage( tr( "Table retrieval finished." ) ); | ||
|
||
QgsOracleConnPool::instance()->releaseConnection( conn ); | ||
|
||
return true; | ||
} |
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,67 @@ | ||
/*************************************************************************** | ||
qgsoraclecolumntypetask.h - lookup oracle geometry type and srid in a thread | ||
------------------- | ||
begin : 12.12.2012 | ||
copyright : (C) 2012 by Juergen E. Fischer | ||
email : jef at norbit dot de | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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 QGSORACLECOLUMNTYPETASK_H | ||
#define QGSORACLECOLUMNTYPETASK_H | ||
|
||
#include "qgstaskmanager.h" | ||
#include "qgsoracleconn.h" | ||
|
||
// A class that determines the geometry type of a given database | ||
// schema.table.column, with the option of doing so in a separate | ||
// thread. | ||
|
||
class QgsOracleColumnTypeTask : public QgsTask | ||
{ | ||
Q_OBJECT | ||
public: | ||
|
||
/** | ||
* | ||
* \param connName | ||
* \param limitToSchema If specified, only tables from this schema will be scanned | ||
* \param useEstimatedMetaData | ||
* \param allowGeometrylessTables | ||
*/ | ||
QgsOracleColumnTypeTask( const QString &connName, | ||
const QString &limitToSchema, | ||
bool useEstimatedMetaData, | ||
bool allowGeometrylessTables ); | ||
|
||
// These functions get the layer types and pass that information out | ||
// by emitting the setLayerType() signal. | ||
bool run() override; | ||
|
||
QVector<QgsOracleLayerProperty> layerProperties() const { return mLayerProperties; } | ||
QString connectionName() const { return mName; } | ||
bool useEstimatedMetadata() const { return mUseEstimatedMetadata; } | ||
bool allowGeometrylessTables() const { return mAllowGeometrylessTables; } | ||
|
||
signals: | ||
void setLayerType( const QgsOracleLayerProperty &layerProperty ); | ||
void progressMessage( const QString &message ); | ||
|
||
private: | ||
QgsOracleColumnTypeTask() = default; | ||
|
||
QString mName; | ||
QString mSchema; | ||
bool mUseEstimatedMetadata = false; | ||
bool mAllowGeometrylessTables = false; | ||
QVector<QgsOracleLayerProperty> mLayerProperties; | ||
}; | ||
|
||
#endif // QGSORACLECOLUMNTYPETASK_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
Oops, something went wrong.