[ 1839065 ] Connection dialog hang if database parameter is not valid

This commit is contained in:
Heng Sin Low 2007-11-26 23:34:48 +00:00
parent cb12d009c1
commit 98a49b22b5
3 changed files with 49 additions and 81 deletions

View File

@ -1320,24 +1320,6 @@ public class CConnection implements Serializable, Cloneable
{
ee = e;
}
if (conn == null)
{
Thread.yield();
log.config("retrying - " + ee);
conn = m_db.getCachedConnection(this, autoCommit, transactionIsolation);
}
// System.err.println ("CConnection.getConnection(Cache) - " + getConnectionURL() + ", AutoCommit=" + autoCommit + ", TrxLevel=" + trxLevel);
// }
// else if (isDataSource()) // Client
// {
// conn = m_ds.getConnection();
// System.err.println ("CConnection.getConnection(DataSource) - " + getConnectionURL() + ", AutoCommit=" + autoCommit + ", TrxLevel=" + trxLevel);
// }
// else
// {
// conn = m_db.getDriverConnection (this);
// System.err.println ("CConnection.getConnection(Driver) - " + getConnectionURL() + ", AutoCommit=" + autoCommit + ", TrxLevel=" + trxLevel);
// }
// Verify Connection
if (conn != null)
{
@ -1359,10 +1341,17 @@ public class CConnection implements Serializable, Cloneable
{
m_dbException = ex;
if (conn == null)
{
//log might cause infinite loop since it will try to acquire database connection again
/*
log.log(Level.SEVERE, getConnectionURL ()
+ ", (1) AutoCommit=" + autoCommit + ",TrxIso=" + getTransactionIsolationInfo(transactionIsolation)
// + " (" + getDbUid() + "/" + getDbPwd() + ")"
+ " - " + ex.getMessage());
*/
System.err.println(getConnectionURL ()
+ ", (1) AutoCommit=" + autoCommit + ",TrxIso=" + getTransactionIsolationInfo(transactionIsolation)
+ " - " + ex.getMessage());
}
else
{
try
@ -1385,7 +1374,9 @@ public class CConnection implements Serializable, Cloneable
catch (Exception ex)
{
m_dbException = ex;
log.log(Level.SEVERE, getConnectionURL(), ex);
//log might cause infinite loop since it will try to acquire database connection again
//log.log(Level.SEVERE, getConnectionURL(), ex);
System.err.println(getConnectionURL() + " - " + ex.getLocalizedMessage());
}
// System.err.println ("CConnection.getConnection - " + conn);
return conn;

View File

@ -558,7 +558,7 @@ public class DB_Oracle implements AdempiereDatabase
cpds.setPassword(connection.getDbPwd());
cpds.setPreferredTestQuery(DEFAULT_CONN_TEST_SQL);
cpds.setIdleConnectionTestPeriod(1200);
cpds.setAcquireRetryAttempts(5);
cpds.setAcquireRetryAttempts(2);
//cpds.setTestConnectionOnCheckin(true);
//cpds.setTestConnectionOnCheckout(true);
//cpds.setCheckoutTimeout(60);
@ -591,7 +591,9 @@ public class DB_Oracle implements AdempiereDatabase
catch (Exception ex)
{
m_ds = null;
log.log(Level.SEVERE, "Could not initialise C3P0 Datasource", ex);
//log might cause infinite loop since it will try to acquire database connection again
//log.log(Level.SEVERE, "Could not initialise C3P0 Datasource", ex);
System.err.println("Could not initialise C3P0 Datasource: " + ex.getLocalizedMessage());
}
return m_ds;
@ -617,14 +619,7 @@ public class DB_Oracle implements AdempiereDatabase
if (m_ds == null)
getDataSource(connection);
// Properties connAttr = new Properties();
// connAttr.setProperty("TRANSACTION_ISOLATION", CConnection.getTransactionIsolationInfo(transactionIsolation));
// OracleConnection conn = (OracleConnection)m_ds.getConnection(connAttr);
//
// Try 5 times max
for (int i = 0; i < 5; i++)
{
try
{
conn = (Connection)m_ds.getConnection();
@ -644,60 +639,42 @@ public class DB_Oracle implements AdempiereDatabase
if (e instanceof SQLException
&& ((SQLException)e).getErrorCode() == 1017) // invalid username/password
{
//log might cause infinite loop since it will try to acquire database connection again
/*
log.severe("Cannot connect to database: "
+ getConnectionURL(connection)
+ " - UserID=" + connection.getDbUid());
break;
*/
System.err.println("Cannot connect to database: "
+ getConnectionURL(connection)
+ " - UserID=" + connection.getDbUid());
}
}
try
{
if (conn != null && conn.isClosed())
conn = null;
// OK
if (conn != null && !conn.isClosed())
break;
if (i == 0)
Thread.yield(); // give some time
else
Thread.sleep(100);
}
catch (Exception e)
{
exception = e;
conn = null;
}
} // 5 tries
if (conn == null && exception != null)
{
//log might cause infinite loop since it will try to acquire database connection again
/*
log.log(Level.SEVERE, exception.toString());
log.fine(toString());
// log.finest("Reference=" + m_ds.getReference());
log.fine(toString()); */
System.err.println(exception.toString());
}
// else
// {
// System.out.println(conn + " " + getStatus());
// conn.registerConnectionCacheCallback(this, "test", OracleConnection.ALL_CONNECTION_CALLBACKS);
// }
}
catch (Exception e)
{
// System.err.println ("DB_Oracle.getCachedConnection");
// if (!(e instanceof SQLException))
// e.printStackTrace();
exception = e;
}
try
{
if (conn != null) {
int numConnections = m_ds.getNumBusyConnections();
//if (numConnections > m_maxbusyconnections)
if(numConnections % 10 == 0)
if(numConnections >= m_maxbusyconnections )
{
log.warning(getStatus());
}
}
}
catch (Exception ex)
{

View File

@ -541,7 +541,7 @@ public class DB_PostgreSQL implements AdempiereDatabase
cpds.setIdleConnectionTestPeriod(1200);
//cpds.setTestConnectionOnCheckin(true);
//cpds.setTestConnectionOnCheckout(true);
cpds.setAcquireRetryAttempts(5);
cpds.setAcquireRetryAttempts(2);
//cpds.setCheckoutTimeout(60);
if (Ini.isClient())