Skip to content
Permalink
Browse files

oracle provider:

- make searching in meta data table default
- also list synonyms
- more progress messages
  • Loading branch information
jef-n committed May 12, 2013
1 parent 82e78ff commit 4182baaa6e78107a5430deaf33fc8e296db2b17e
@@ -33,4 +33,7 @@ determined from all_tables.num_rows. Table extents are always determined with
the SDO_TUNE.EXTENTS_OF function even if a layer filter is applied. The table
geometry is determined from the first 100 non-null geometry rows in the table.

<li> <label>Only existing geometry types</label> Only list the existing
geometry types and don't offer to add others.

</ul>
@@ -20,10 +20,11 @@ email : jef at norbit dot de

#include <QMetaType>

QgsOracleColumnTypeThread::QgsOracleColumnTypeThread( QString name, bool useEstimatedMetadata )
QgsOracleColumnTypeThread::QgsOracleColumnTypeThread( QString name, bool useEstimatedMetadata, bool allowGeometrylessTables )
: QThread()
, mName( name )
, mUseEstimatedMetadata( useEstimatedMetadata )
, mAllowGeometrylessTables( allowGeometrylessTables )
{
qRegisterMetaType<QgsOracleLayerProperty>( "QgsOracleLayerProperty" );
}
@@ -50,7 +51,7 @@ void QgsOracleColumnTypeThread::run()
if ( !conn->supportedLayers( layerProperties,
QgsOracleConn::geometryColumnsOnly( mName ),
QgsOracleConn::userTablesOnly( mName ),
QgsOracleConn::allowGeometrylessTables( mName ) ) ||
mAllowGeometrylessTables ) ||
layerProperties.isEmpty() )
{
return;
@@ -66,7 +67,7 @@ void QgsOracleColumnTypeThread::run()
.arg( layerProperty.ownerName )
.arg( layerProperty.tableName )
.arg( layerProperty.geometryColName ) );
conn->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata );
conn->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata, QgsOracleConn::onlyExistingTypes( mName ) );
}

if ( mStopped )
@@ -28,7 +28,9 @@ class QgsOracleColumnTypeThread : public QThread
{
Q_OBJECT
public:
QgsOracleColumnTypeThread( QString connName, bool useEstimatedMetaData );
QgsOracleColumnTypeThread( QString connName,
bool useEstimatedMetaData,
bool allowGeometrylessTables );

// These functions get the layer types and pass that information out
// by emitting the setLayerType() signal.
@@ -47,6 +49,7 @@ class QgsOracleColumnTypeThread : public QThread

QString mName;
bool mUseEstimatedMetadata;
bool mAllowGeometrylessTables;
bool mStopped;
QList<QgsOracleLayerProperty> layerProperties;
};
@@ -22,7 +22,6 @@
#include "qgscredentials.h"
#include "qgsfield.h"
#include "qgsoracletablemodel.h"
#include "qgsdatasourceuri.h"

#include <QSettings>
#include <QSqlError>
@@ -186,27 +185,25 @@ bool QgsOracleConn::tableInfo( bool geometryColumnsOnly, bool userTablesOnly, bo
prefix( userTablesOnly ? "user" : "all" ),
owner( userTablesOnly ? "user AS owner" : "c.owner" );

sql = QString( "SELECT %1,c.table_name,c.column_name,%2,t.table_name AS isview"
sql = QString( "SELECT %1,c.table_name,c.column_name,%2,o.object_type AS type"
" FROM %3_%4 c"
" LEFT OUTER JOIN %3_tables t ON c.table_name=t.table_name%5"
" WHERE %6" )
" JOIN %3_objects o ON c.table_name=o.object_name AND o.object_type IN ('TABLE','VIEW','SYNONYM')%5%6" )
.arg( owner )
.arg( geometryColumnsOnly ? "c.srid" : "NULL AS srid" )
.arg( prefix )
.arg( geometryColumnsOnly ? "sdo_geom_metadata" : "tab_columns" )
.arg( userTablesOnly ? "" : " AND c.owner=t.owner" )
.arg( geometryColumnsOnly ? "NOT t.dropped" : "c.data_type='SDO_GEOMETRY'" );
.arg( userTablesOnly ? "" : " AND c.owner=o.owner" )
.arg( geometryColumnsOnly ? "" : " WHERE c.data_type='SDO_GEOMETRY'" );

if ( allowGeometrylessTables )
{
sql += QString( " UNION SELECT %1,table_name,NULL AS column_name,NULL AS srid,table_name AS isview FROM %2_tables c"
" UNION SELECT %1,view_name,NULL AS column_name,NULL AS srid,NULL AS isview FROM %2_views c" )
sql += QString( " UNION SELECT %1,object_name,NULL AS column_name,NULL AS srid,object_type AS type"
" FROM %2_objects c WHERE c.object_type IN ('TABLE','VIEW','SYNONYM')" )
.arg( owner ).arg( prefix );
}

sql = "SELECT * FROM (" + sql + ")";

sql += " ORDER BY owner,isview,table_name,column_name";
// sql = "SELECT * FROM (" + sql + ")";
// sql += " ORDER BY owner,isview,table_name,column_name";

QSqlQuery qry( mDatabase );
if ( !exec( qry, sql ) )
@@ -223,7 +220,7 @@ bool QgsOracleConn::tableInfo( bool geometryColumnsOnly, bool userTablesOnly, bo
layerProperty.geometryColName = qry.value( 2 ).toString();
layerProperty.types = QList<QGis::WkbType>() << ( qry.value( 2 ).isNull() ? QGis::WKBNoGeometry : QGis::WKBUnknown );
layerProperty.srids = QList<int>() << qry.value( 3 ).toInt();
layerProperty.isView = qry.value( 4 ).isNull();
layerProperty.isView = qry.value( 4 ) != "TABLE";
layerProperty.pkCols.clear();

mLayersSupported << layerProperty;
@@ -316,7 +313,7 @@ QString QgsOracleConn::fieldExpression( const QgsField &fld )
#endif
}

void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, bool useEstimatedMetadata )
void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, bool useEstimatedMetadata, bool onlyExistingTypes )
{
if ( layerProperty.geometryColName.isEmpty() )
return;
@@ -385,10 +382,10 @@ void QgsOracleConn::retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, b

qry.finish();

if ( srids.size() == 1 )
if ( !onlyExistingTypes )
{
layerProperty.types << QGis::WKBUnknown;
layerProperty.srids << *srids.constBegin();
layerProperty.srids << ( srids.size() == 1 ? *srids.constBegin() : 0 );
}

if ( layerProperty.isView )
@@ -582,6 +579,7 @@ void QgsOracleConn::deleteConnection( QString theConnName )
settings.remove( key + "/geometryColumnsOnly" );
settings.remove( key + "/allowGeometrylessTables" );
settings.remove( key + "/estimatedMetadata" );
settings.remove( key + "/onlyExistingTypes" );
settings.remove( key + "/saveUsername" );
settings.remove( key + "/savePassword" );
settings.remove( key + "/save" );
@@ -647,7 +645,7 @@ bool QgsOracleConn::userTablesOnly( QString theConnName )
bool QgsOracleConn::geometryColumnsOnly( QString theConnName )
{
QSettings settings;
return settings.value( "/Oracle/connections/" + theConnName + "/geometryColumnsOnly", false ).toBool();
return settings.value( "/Oracle/connections/" + theConnName + "/geometryColumnsOnly", true ).toBool();
}

bool QgsOracleConn::allowGeometrylessTables( QString theConnName )
@@ -662,6 +660,12 @@ bool QgsOracleConn::estimatedMetadata( QString theConnName )
return settings.value( "/Oracle/connections/" + theConnName + "/estimatedMetadata", false ).toBool();
}

bool QgsOracleConn::onlyExistingTypes( QString theConnName )
{
QSettings settings;
return settings.value( "/Oracle/connections/" + theConnName + "/onlyExistingTypes", false ).toBool();
}

QString QgsOracleConn::databaseName( QString database, QString host, QString port )
{
QString db;
@@ -99,7 +99,6 @@ struct QgsOracleLayerProperty
class QgsOracleConn : public QThread
{
Q_OBJECT;

public:
static QgsOracleConn *connectDb( QgsDataSourceURI uri );
void disconnect();
@@ -112,13 +111,13 @@ class QgsOracleConn : public QThread
*/
static QString quotedValue( QVariant value );

//! Get the list of usable to check
//! Get the list of supported layers
bool supportedLayers( QVector<QgsOracleLayerProperty> &layers,
bool geometryTablesOnly,
bool userTablesOnly = true,
bool allowGeometrylessTables = false );

void retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, bool useEstimatedMetadata );
void retrieveLayerTypes( QgsOracleLayerProperty &layerProperty, bool useEstimatedMetadata, bool onlyExistingTypes );

/** Gets information about the spatial tables */
bool tableInfo( bool geometryTablesOnly, bool userTablesOnly, bool allowGeometrylessTables );
@@ -151,6 +150,7 @@ class QgsOracleConn : public QThread
static bool geometryColumnsOnly( QString theConnName );
static bool allowGeometrylessTables( QString theConnName );
static bool estimatedMetadata( QString theConnName );
static bool onlyExistingTypes( QString theConnName );
static void deleteConnection( QString theConnName );
static QString databaseName( QString database, QString host, QString port );

@@ -53,46 +53,49 @@ void QgsOracleConnectionItem::stop()

void QgsOracleConnectionItem::refresh()
{
QgsDebugMsg( "Entering." );

QApplication::setOverrideCursor( Qt::WaitCursor );

stop();

foreach ( QgsDataItem *child, mChildren )
{
QgsDebugMsg( QString( "Deleting child: %1" ).arg( child->name() ) );
deleteChildItem( child );
}

foreach ( QgsDataItem *item, createChildren() )
{
QgsDebugMsg( QString( "Adding child %1" ).arg( item->name() ) );
addChildItem( item, true );
}

QApplication::restoreOverrideCursor();

QgsDebugMsg( "Leaving." );
}

QVector<QgsDataItem*> QgsOracleConnectionItem::createChildren()
{
QgsDebugMsg( "Entered" );
QgsDataSourceURI uri = QgsOracleConn::connUri( mName );

mOwnerMap.clear();

stop();

if ( !mColumnTypeThread )
{
mColumnTypeThread = new QgsOracleColumnTypeThread( mName, true /* useEstimatedMetadata */ );
mColumnTypeThread = new QgsOracleColumnTypeThread( mName,
/* useEstimatedMetadata */ true,
QgsOracleConn::allowGeometrylessTables( mName ) );

connect( mColumnTypeThread, SIGNAL( setLayerType( QgsOracleLayerProperty ) ),
this, SLOT( setLayerType( QgsOracleLayerProperty ) ) );
connect( mColumnTypeThread, SIGNAL( started() ), this, SLOT( threadStarted() ) );
connect( mColumnTypeThread, SIGNAL( finished() ), this, SLOT( threadFinished() ) );

if ( QgsOracleRootItem::sMainWindow )
{
connect( mColumnTypeThread, SIGNAL( progress( int, int ) ),
QgsOracleRootItem::sMainWindow, SLOT( showProgress( int, int ) ) );
connect( mColumnTypeThread, SIGNAL( progressMessage( QString ) ),
QgsOracleRootItem::sMainWindow, SLOT( showStatusMessage( QString ) ) );
}
}

if ( mColumnTypeThread )
@@ -116,15 +119,7 @@ void QgsOracleConnectionItem::threadFinished()
void QgsOracleConnectionItem::setLayerType( QgsOracleLayerProperty layerProperty )
{
QgsDebugMsg( layerProperty.toString() );

QgsOracleOwnerItem *ownerItem = mOwnerMap.value( layerProperty.ownerName, 0 );
if ( !ownerItem )
{
ownerItem = new QgsOracleOwnerItem( this, layerProperty.ownerName, mPath + "/" + layerProperty.ownerName );
QgsDebugMsg( "add owner item: " + layerProperty.ownerName );
addChildItem( ownerItem, true );
mOwnerMap[ layerProperty.ownerName ] = ownerItem;
}

for ( int i = 0 ; i < layerProperty.size(); i++ )
{
@@ -135,11 +130,17 @@ void QgsOracleConnectionItem::setLayerType( QgsOracleLayerProperty layerProperty
continue;
}

if ( !ownerItem )
{
ownerItem = new QgsOracleOwnerItem( this, layerProperty.ownerName, mPath + "/" + layerProperty.ownerName );
QgsDebugMsg( "add owner item: " + layerProperty.ownerName );
addChildItem( ownerItem, true );
mOwnerMap[ layerProperty.ownerName ] = ownerItem;
}

QgsDebugMsg( "ADD LAYER" );
ownerItem->addLayer( layerProperty.at( i ) );
}

QgsDebugMsg( "Leaving" );
}

bool QgsOracleConnectionItem::equal( const QgsDataItem *other )
@@ -318,8 +319,8 @@ void QgsOracleLayerItem::deleteLayer()
QString QgsOracleLayerItem::createUri()
{
Q_ASSERT( mLayerProperty.size() == 1 );

QgsOracleConnectionItem *connItem = qobject_cast<QgsOracleConnectionItem *>( parent() ? parent()->parent() : 0 );

if ( !connItem )
{
QgsDebugMsg( "connection item not found." );
@@ -452,3 +453,10 @@ void QgsOracleRootItem::newConnection()
refresh();
}
}

QMainWindow *QgsOracleRootItem::sMainWindow = 0;

QGISEXTERN void registerGui( QMainWindow *mainWindow )
{
QgsOracleRootItem::sMainWindow = mainWindow;
}
@@ -16,6 +16,7 @@
#define QGSORACLEDATAITEMS_H

#include <QSqlDatabase>
#include <QMainWindow>

#include "qgsdataitem.h"

@@ -44,6 +45,8 @@ class QgsOracleRootItem : public QgsDataCollectionItem

virtual QList<QAction*> actions();

static QMainWindow *sMainWindow;

public slots:
void connectionsChanged();
void newConnection();
@@ -45,9 +45,10 @@ QgsOracleNewConnection::QgsOracleNewConnection( QWidget *parent, const QString&
}
txtPort->setText( port );
cb_userTablesOnly->setChecked( settings.value( key + "/userTablesOnly", false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", false ).toBool() );
cb_geometryColumnsOnly->setChecked( settings.value( key + "/geometryColumnsOnly", true ).toBool() );
cb_allowGeometrylessTables->setChecked( settings.value( key + "/allowGeometrylessTables", false ).toBool() );
cb_useEstimatedMetadata->setChecked( settings.value( key + "/estimatedMetadata", false ).toBool() );
cb_onlyExistingTypes->setChecked( settings.value( key + "/onlyExistingTypes", true ).toBool() );

if ( settings.value( key + "/saveUsername" ).toString() == "true" )
{
@@ -121,6 +122,7 @@ void QgsOracleNewConnection::accept()
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/allowGeometrylessTables", cb_allowGeometrylessTables->isChecked() );
settings.setValue( baseKey + "/estimatedMetadata", cb_useEstimatedMetadata->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/onlyExistingTypes", cb_onlyExistingTypes->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/saveUsername", chkStoreUsername->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/savePassword", chkStorePassword->isChecked() ? "true" : "false" );

@@ -2136,7 +2136,7 @@ bool QgsOracleProvider::getGeometryDetails()
delim = " AND ";
}

mConnection->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata );
mConnection->retrieveLayerTypes( layerProperty, mUseEstimatedMetadata, false );

Q_ASSERT( layerProperty.types.size() == layerProperty.srids.size() );

0 comments on commit 4182baa

Please sign in to comment.
You can’t perform that action at this time.