IDEMPIERE-5376 CConnection and DB clean up (#1432)

This commit is contained in:
hengsin 2022-08-10 20:52:53 +08:00 committed by GitHub
parent d8f48d1f17
commit 3a2f0ff64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 77 deletions

View File

@ -1116,7 +1116,6 @@ public class CConnection implements Serializable, Cloneable
* @param transactionIsolation Connection transaction level
* @return Connection
*/
@SuppressWarnings("unused")
public Connection getConnection (boolean autoCommit, int transactionIsolation)
{
Connection conn = null;
@ -1133,18 +1132,7 @@ public class CConnection implements Serializable, Cloneable
try
{
// if (!Ini.isClient() // Server
// && trxLevel != Connection.TRANSACTION_READ_COMMITTED) // PO_LOB.save()
// {
//Exception ee = null;
try
{
conn = m_db.getCachedConnection(this, autoCommit, transactionIsolation);
}
catch (Exception e)
{
//ee = e;
}
conn = m_db.getCachedConnection(this, autoCommit, transactionIsolation);
// Verify Connection
if (conn != null)
{
@ -1160,19 +1148,13 @@ public class CConnection implements Serializable, Cloneable
String msg = ule.getLocalizedMessage()
+ " -> Did you set the LD_LIBRARY_PATH ? - " + getConnectionURL();
m_dbException = new Exception(msg);
log.severe(msg);
System.err.println(msg);
}
catch (SQLException ex)
{
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)
+ " - " + ex.getMessage());
*/
System.err.println(getConnectionURL ()
+ ", (1) AutoCommit=" + autoCommit + ",TrxIso=" + getTransactionIsolationInfo(transactionIsolation)
+ " - " + ex.getMessage());
@ -1181,29 +1163,24 @@ public class CConnection implements Serializable, Cloneable
{
try
{
log.severe(getConnectionURL ()
System.err.println(getConnectionURL ()
+ ", (2) AutoCommit=" + conn.getAutoCommit() + "->" + autoCommit
+ ", TrxIso=" + getTransactionIsolationInfo(conn.getTransactionIsolation()) + "->" + getTransactionIsolationInfo(transactionIsolation)
// + " (" + getDbUid() + "/" + getDbPwd() + ")"
+ " - " + ex.getMessage());
}
catch (Exception ee)
{
log.severe(getConnectionURL ()
+ ", (3) AutoCommit=" + autoCommit + ", TrxIso=" + getTransactionIsolationInfo(transactionIsolation)
// + " (" + getDbUid() + "/" + getDbPwd() + ")"
+ " - " + ex.getMessage());
System.err.println(getConnectionURL ()
+ ", (1) AutoCommit=" + autoCommit + ",TrxIso=" + getTransactionIsolationInfo(transactionIsolation)
+ " - " + ex.getMessage());
}
}
}
catch (Exception ex)
{
m_dbException = 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;
} // getConnection
@ -1214,7 +1191,7 @@ public class CConnection implements Serializable, Cloneable
public Exception getDatabaseException ()
{
return m_dbException;
} // getConnectionException
}
/*************************************************************************/

View File

@ -419,22 +419,12 @@ public final class DB
public static Connection createConnection (boolean autoCommit, int trxLevel)
{
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
if (CLogMgt.isLevelFinest())
{
/**
try
{
log.finest(s_cc.getConnectionURL()
+ ", UserID=" + s_cc.getDbUid()
+ ", AutoCommit=" + conn.getAutoCommit() + " (" + autoCommit + ")"
+ ", TrxIso=" + conn.getTransactionIsolation() + "( " + trxLevel + ")");
}
catch (Exception e)
{
}
**/
}
if (conn == null)
{
throw new IllegalStateException("DB.createConnection - @NoDBConnection@");
}
//hengsin: failed to set autocommit can lead to severe lock up of the system
try {
if (conn != null && conn.getAutoCommit() != autoCommit)
@ -447,46 +437,19 @@ public final class DB
} // createConnection
/**
* @Deprecated (since="10", forRemoval=true)
* Create new Connection.
* The connection must be closed explicitly by the application
*
* @param autoCommit auto commit
* @param readOnly ignore
* @param trxLevel - Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ, or Connection.TRANSACTION_READ_COMMITTED.
* @return Connection connection
* @deprecated
*/
public static Connection createConnection (boolean autoCommit, boolean readOnly, int trxLevel)
{
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
//hengsin: this could be problematic as it can be reuse for readwrite activites after return to pool
/*
if (conn != null)
{
try
{
conn.setReadOnly(readOnly);
}
catch (SQLException ex)
{
conn = null;
log.log(Level.SEVERE, ex.getMessage(), ex);
}
}*/
if (conn == null)
{
throw new IllegalStateException("DB.getConnectionRO - @NoDBConnection@");
}
//hengsin: failed to set autocommit can lead to severe lock up of the system
try {
if (conn.getAutoCommit() != autoCommit)
{
throw new IllegalStateException("Failed to set the requested auto commit mode on connection. [autocommit=" + autoCommit +"]");
}
} catch (SQLException e) {}
return conn;
return createConnection(autoCommit, trxLevel);
} // createConnection
/**

View File

@ -45,7 +45,7 @@ public class AutoCommitConnectionBroker {
}
} catch (SQLException e) {}
Connection connection = DB.createConnection(true, false, Connection.TRANSACTION_READ_COMMITTED);
Connection connection = DB.createConnection(true, Connection.TRANSACTION_READ_COMMITTED);
connReference = new ConnectionReference(connection);
threadLocalConnection.set(connReference);
return connection;