[ 1839065 ] Connection dialog hang if database parameter is not valid
This commit is contained in:
parent
cb12d009c1
commit
98a49b22b5
|
@ -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;
|
||||
|
|
|
@ -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,86 +619,61 @@ 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
|
||||
{
|
||||
try
|
||||
conn = (Connection)m_ds.getConnection();
|
||||
if (conn != null)
|
||||
{
|
||||
conn = (Connection)m_ds.getConnection();
|
||||
if (conn != null)
|
||||
{
|
||||
if (conn.getTransactionIsolation() != transactionIsolation)
|
||||
conn.setTransactionIsolation(transactionIsolation);
|
||||
if (conn.getAutoCommit() != autoCommit)
|
||||
conn.setAutoCommit(autoCommit);
|
||||
if (conn.getTransactionIsolation() != transactionIsolation)
|
||||
conn.setTransactionIsolation(transactionIsolation);
|
||||
if (conn.getAutoCommit() != autoCommit)
|
||||
conn.setAutoCommit(autoCommit);
|
||||
// conn.setDefaultRowPrefetch(20); // 10 default - reduces round trips
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
exception = e;
|
||||
conn = null;
|
||||
if (e instanceof SQLException
|
||||
&& ((SQLException)e).getErrorCode() == 1017) // invalid username/password
|
||||
{
|
||||
exception = e;
|
||||
conn = null;
|
||||
if (e instanceof SQLException
|
||||
&& ((SQLException)e).getErrorCode() == 1017) // invalid username/password
|
||||
{
|
||||
log.severe("Cannot connect to database: "
|
||||
//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());
|
||||
*/
|
||||
System.err.println("Cannot connect to database: "
|
||||
+ getConnectionURL(connection)
|
||||
+ " - UserID=" + connection.getDbUid());
|
||||
break;
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
int numConnections = m_ds.getNumBusyConnections();
|
||||
//if (numConnections > m_maxbusyconnections)
|
||||
if(numConnections % 10 == 0)
|
||||
{
|
||||
log.warning(getStatus());
|
||||
}
|
||||
if (conn != null) {
|
||||
int numConnections = m_ds.getNumBusyConnections();
|
||||
if(numConnections >= m_maxbusyconnections )
|
||||
{
|
||||
log.warning(getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue