Skip to content
Permalink
Browse files
oracle provider: skip retrying unavailable connections for 30s
  • Loading branch information
jef-n committed Dec 5, 2016
1 parent 42b8ee9 commit b0126d017873e467f3cd69fa4b3a3bfd16e6a8c8
Showing with 30 additions and 8 deletions.
  1. +28 −8 src/providers/oracle/qgsoracleconn.cpp
  2. +2 −0 src/providers/oracle/qgsoracleconn.h
@@ -25,11 +25,11 @@

#include <QSettings>
#include <QSqlError>
#include <QDateTime>

QMap<QString, QgsOracleConn *> QgsOracleConn::sConnections;
int QgsOracleConn::snConnections = 0;
const int QgsOracleConn::sGeomTypeSelectLimit = 100;
QMap<QString, QDateTime> QgsOracleConn::sBrokenConnections;

QgsOracleConn *QgsOracleConn::connectDb( const QgsDataSourceURI& uri )
{
@@ -72,24 +72,44 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceURI uri )
mDatabase.setUserName( uri.username() );
mDatabase.setPassword( uri.password() );

QgsDebugMsg( QString( "Connecting with options: " ) + options );
QString username = uri.username();
QString password = uri.password();

if ( !mDatabase.open() )
QString realm( database );
if ( !username.isEmpty() )
realm.prepend( username + "@" );

if ( sBrokenConnections.contains( realm ) )
{
QString username = uri.username();
QString password = uri.password();
QDateTime now( QDateTime::currentDateTime() );
QDateTime since( sBrokenConnections[ realm ] );
QgsDebugMsg( QString( "Broken since %1 [%2s ago]" ).arg( since.toString( Qt::ISODate ) ).arg( since.secsTo( now ) ) );

QString realm( database );
if ( !username.isEmpty() )
realm.prepend( username + "@" );
if ( since.secsTo( now ) < 30 )
{
QgsMessageLog::logMessage( tr( "Connection failed %1s ago - skipping retry" ).arg( since.secsTo( now ) ), tr( "Oracle" ) );
mRef = 0;
return;
}
}

QgsDebugMsg( QString( "Connecting with options: " ) + options );
if ( !mDatabase.open() )
{
QgsCredentials::instance()->lock();

while ( !mDatabase.open() )
{
bool ok = QgsCredentials::instance()->get( realm, username, password, mDatabase.lastError().text() );
if ( !ok )
{
QDateTime now( QDateTime::currentDateTime() );
QgsDebugMsg( QString( "get failed: %1 <= %2" ).arg( realm ).arg( now.toString( Qt::ISODate ) ) );
sBrokenConnections.insert( realm, now );
break;
}

sBrokenConnections.remove( realm );

if ( !username.isEmpty() )
{
@@ -24,6 +24,7 @@
#include <QMap>
#include <QSet>
#include <QThread>
#include <QDateTime>

#include "qgis.h"
#include "qgsdatasourceuri.h"
@@ -190,6 +191,7 @@ class QgsOracleConn : public QObject

static QMap<QString, QgsOracleConn *> sConnections;
static int snConnections;
static QMap<QString, QDateTime> sBrokenConnections;
};

#endif

0 comments on commit b0126d0

Please sign in to comment.