IDEMPIERE-5376 CConnection and DB clean up (#1432)
This commit is contained in:
parent
d8f48d1f17
commit
3a2f0ff64d
|
@ -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;
|
||||
|
@ -1131,20 +1130,9 @@ 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;
|
||||
}
|
||||
// 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,17 +1163,15 @@ 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() + ")"
|
||||
System.err.println(getConnectionURL ()
|
||||
+ ", (1) AutoCommit=" + autoCommit + ",TrxIso=" + getTransactionIsolationInfo(transactionIsolation)
|
||||
+ " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1199,11 +1179,8 @@ public class CConnection implements Serializable, Cloneable
|
|||
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
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
|
|
@ -419,20 +419,10 @@ public final class DB
|
|||
public static Connection createConnection (boolean autoCommit, int trxLevel)
|
||||
{
|
||||
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
|
||||
if (CLogMgt.isLevelFinest())
|
||||
|
||||
if (conn == null)
|
||||
{
|
||||
/**
|
||||
try
|
||||
{
|
||||
log.finest(s_cc.getConnectionURL()
|
||||
+ ", UserID=" + s_cc.getDbUid()
|
||||
+ ", AutoCommit=" + conn.getAutoCommit() + " (" + autoCommit + ")"
|
||||
+ ", TrxIso=" + conn.getTransactionIsolation() + "( " + trxLevel + ")");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
**/
|
||||
throw new IllegalStateException("DB.createConnection - @NoDBConnection@");
|
||||
}
|
||||
|
||||
//hengsin: failed to set autocommit can lead to severe lock up of the system
|
||||
|
@ -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
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue