|
25 | 25 | #include "qgssettings.h"
|
26 | 26 |
|
27 | 27 | #include <QSqlError>
|
28 |
| -#include <QDateTime> |
29 | 28 |
|
30 | 29 | QMap<QString, QgsOracleConn *> QgsOracleConn::sConnections;
|
31 | 30 | int QgsOracleConn::snConnections = 0;
|
32 | 31 | const int QgsOracleConn::sGeomTypeSelectLimit = 100;
|
| 32 | +QMap<QString, QDateTime> QgsOracleConn::sBrokenConnections; |
33 | 33 |
|
34 | 34 | QgsOracleConn *QgsOracleConn::connectDb( const QgsDataSourceUri &uri )
|
35 | 35 | {
|
@@ -72,24 +72,44 @@ QgsOracleConn::QgsOracleConn( QgsDataSourceUri uri )
|
72 | 72 | mDatabase.setUserName( uri.username() );
|
73 | 73 | mDatabase.setPassword( uri.password() );
|
74 | 74 |
|
75 |
| - QgsDebugMsg( QString( "Connecting with options: " ) + options ); |
| 75 | + QString username = uri.username(); |
| 76 | + QString password = uri.password(); |
76 | 77 |
|
77 |
| - if ( !mDatabase.open() ) |
| 78 | + QString realm( database ); |
| 79 | + if ( !username.isEmpty() ) |
| 80 | + realm.prepend( username + "@" ); |
| 81 | + |
| 82 | + if ( sBrokenConnections.contains( realm ) ) |
78 | 83 | {
|
79 |
| - QString username = uri.username(); |
80 |
| - QString password = uri.password(); |
| 84 | + QDateTime now( QDateTime::currentDateTime() ); |
| 85 | + QDateTime since( sBrokenConnections[ realm ] ); |
| 86 | + QgsDebugMsg( QString( "Broken since %1 [%2s ago]" ).arg( since.toString( Qt::ISODate ) ).arg( since.secsTo( now ) ) ); |
81 | 87 |
|
82 |
| - QString realm( database ); |
83 |
| - if ( !username.isEmpty() ) |
84 |
| - realm.prepend( username + "@" ); |
| 88 | + if ( since.secsTo( now ) < 30 ) |
| 89 | + { |
| 90 | + QgsMessageLog::logMessage( tr( "Connection failed %1s ago - skipping retry" ).arg( since.secsTo( now ) ), tr( "Oracle" ) ); |
| 91 | + mRef = 0; |
| 92 | + return; |
| 93 | + } |
| 94 | + } |
85 | 95 |
|
| 96 | + QgsDebugMsg( QString( "Connecting with options: " ) + options ); |
| 97 | + if ( !mDatabase.open() ) |
| 98 | + { |
86 | 99 | QgsCredentials::instance()->lock();
|
87 | 100 |
|
88 | 101 | while ( !mDatabase.open() )
|
89 | 102 | {
|
90 | 103 | bool ok = QgsCredentials::instance()->get( realm, username, password, mDatabase.lastError().text() );
|
91 | 104 | if ( !ok )
|
| 105 | + { |
| 106 | + QDateTime now( QDateTime::currentDateTime() ); |
| 107 | + QgsDebugMsg( QString( "get failed: %1 <= %2" ).arg( realm ).arg( now.toString( Qt::ISODate ) ) ); |
| 108 | + sBrokenConnections.insert( realm, now ); |
92 | 109 | break;
|
| 110 | + } |
| 111 | + |
| 112 | + sBrokenConnections.remove( realm ); |
93 | 113 |
|
94 | 114 | if ( !username.isEmpty() )
|
95 | 115 | {
|
|
0 commit comments