* [ 1852099 ] Simplication of Connection Profile
* [ 1854500 ] CStatement should always close connection if not using trx
This commit is contained in:
parent
2c79b7ff79
commit
35fa73dbdb
|
@ -47,13 +47,15 @@ public class CConnection implements Serializable, Cloneable
|
|||
/** Connection profiles */
|
||||
public static ValueNamePair[] CONNECTIONProfiles = new ValueNamePair[]{
|
||||
new ValueNamePair("L", "LAN"),
|
||||
new ValueNamePair("T", "Terminal Server"),
|
||||
new ValueNamePair("V", "VPN"),
|
||||
new ValueNamePair("W", "WAN") };
|
||||
|
||||
/** Connection Profile LAN */
|
||||
public static final String PROFILE_LAN = "L";
|
||||
/** Connection Profile Terminal Server */
|
||||
/**
|
||||
* Connection Profile Terminal Server
|
||||
* @deprecated
|
||||
**/
|
||||
public static final String PROFILE_TERMINAL = "T";
|
||||
/** Connection Profile VPM */
|
||||
public static final String PROFILE_VPN = "V";
|
||||
|
@ -572,8 +574,10 @@ public class CConnection implements Serializable, Cloneable
|
|||
&& m_connectionProfile.equals(connectionProfile))) // same
|
||||
return;
|
||||
|
||||
if (PROFILE_TERMINAL.equals(connectionProfile))
|
||||
connectionProfile = PROFILE_LAN;
|
||||
|
||||
if (PROFILE_LAN.equals(connectionProfile)
|
||||
|| PROFILE_TERMINAL.equals(connectionProfile)
|
||||
|| PROFILE_VPN.equals(connectionProfile)
|
||||
|| PROFILE_WAN.equals(connectionProfile))
|
||||
{
|
||||
|
@ -665,18 +669,18 @@ public class CConnection implements Serializable, Cloneable
|
|||
public boolean isServerProcess()
|
||||
{
|
||||
return (Ini.isClient()
|
||||
&& (getConnectionProfile().equals(PROFILE_TERMINAL)
|
||||
|| getConnectionProfile().equals(PROFILE_VPN)
|
||||
&& (getConnectionProfile().equals(PROFILE_VPN)
|
||||
|| getConnectionProfile().equals(PROFILE_WAN) ));
|
||||
} // isServerProcess
|
||||
|
||||
/**
|
||||
* Is this a Terminal Server ?
|
||||
* @return true if client and Terminal
|
||||
* @deprecated
|
||||
*/
|
||||
public boolean isTerminalServer()
|
||||
{
|
||||
return Ini.isClient() && getConnectionProfile().equals(PROFILE_TERMINAL);
|
||||
return false;
|
||||
} // isTerminalServer
|
||||
|
||||
/**
|
||||
|
@ -953,8 +957,9 @@ public class CConnection implements Serializable, Cloneable
|
|||
public Exception testDatabase(boolean retest)
|
||||
{
|
||||
// At this point Application Server Connection is tested.
|
||||
if (DB.isRemoteObjects() || isRMIoverHTTP())
|
||||
if (DB.isRemoteObjects())
|
||||
return null;
|
||||
|
||||
if (!retest && m_ds != null && m_okDB)
|
||||
return null;
|
||||
|
||||
|
@ -1213,7 +1218,7 @@ public class CConnection implements Serializable, Cloneable
|
|||
}
|
||||
}
|
||||
//hengsin, don't test datasource for wan profile
|
||||
if (!DB.isRemoteObjects() && !isRMIoverHTTP())
|
||||
if (!DB.isRemoteObjects())
|
||||
{
|
||||
if (m_db != null) // test class loader ability
|
||||
m_db.getDataSource(this);
|
||||
|
@ -1595,7 +1600,7 @@ public class CConnection implements Serializable, Cloneable
|
|||
setDbPort (svr.getDbPort ());
|
||||
setDbName (svr.getDbName ());
|
||||
setDbUid (svr.getDbUid ());
|
||||
if (isRMIoverHTTP() || DB.isRemoteObjects())
|
||||
if (DB.isRemoteObjects())
|
||||
setDbPwd ("");
|
||||
else
|
||||
setDbPwd (svr.getDbPwd ());
|
||||
|
|
|
@ -70,7 +70,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
|
|||
/** Connection Profiles */
|
||||
CConnection.CONNECTIONProfiles = new ValueNamePair[]{
|
||||
new ValueNamePair("L", res.getString("LAN")),
|
||||
new ValueNamePair("T", res.getString("TerminalServer")),
|
||||
new ValueNamePair("V", res.getString("VPN")),
|
||||
new ValueNamePair("W", res.getString("WAN"))
|
||||
};
|
||||
|
@ -119,7 +118,7 @@ public class CConnectionDialog extends CDialog implements ActionListener
|
|||
private CLabel appsPortLabel = new CLabel();
|
||||
private CTextField appsPortField = new CTextField();
|
||||
private CButton bTestApps = new CButton();
|
||||
private CCheckBox cbOverwrite = new CCheckBox();
|
||||
//private CCheckBox cbOverwrite = new CCheckBox();
|
||||
private CLabel dbUidLabel = new CLabel();
|
||||
private CTextField dbUidField = new CTextField();
|
||||
private JPasswordField dbPwdField = new JPasswordField();
|
||||
|
@ -164,7 +163,7 @@ public class CConnectionDialog extends CDialog implements ActionListener
|
|||
appsPortField.setColumns(10);
|
||||
bTestApps.setText(res.getString("TestApps"));
|
||||
bTestApps.setHorizontalAlignment(JLabel.LEFT);
|
||||
cbOverwrite.setText(res.getString("Overwrite"));
|
||||
//cbOverwrite.setText(res.getString("Overwrite"));
|
||||
dbUidLabel.setText(res.getString("DBUidPwd"));
|
||||
dbUidField.setColumns(10);
|
||||
connectionProfileLabel.setText(res.getString("ConnectionProfile"));
|
||||
|
@ -195,8 +194,8 @@ public class CConnectionDialog extends CDialog implements ActionListener
|
|||
//
|
||||
centerPanel.add(bTestApps, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0));
|
||||
centerPanel.add(cbOverwrite, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 12), 0, 0));
|
||||
//centerPanel.add(cbOverwrite, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
|
||||
//,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 12), 0, 0));
|
||||
// DB
|
||||
centerPanel.add(dbTypeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
|
||||
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
|
||||
|
@ -238,7 +237,7 @@ public class CConnectionDialog extends CDialog implements ActionListener
|
|||
nameField.addActionListener(this);
|
||||
appsHostField.addActionListener(this);
|
||||
appsPortField.addActionListener(this);
|
||||
cbOverwrite.addActionListener(this);
|
||||
//cbOverwrite.addActionListener(this);
|
||||
bTestApps.addActionListener(this);
|
||||
//
|
||||
dbTypeField.addActionListener(this);
|
||||
|
@ -437,8 +436,8 @@ public class CConnectionDialog extends CDialog implements ActionListener
|
|||
bTestApps.setIcon(getStatusIcon(m_cc.isAppsServerOK(false)));
|
||||
// bTestApps.setToolTipText(m_cc.getRmiUri());
|
||||
|
||||
cbOverwrite.setVisible(m_cc.isAppsServerOK(false));
|
||||
boolean rw = cbOverwrite.isSelected() || !m_cc.isAppsServerOK(false);
|
||||
//cbOverwrite.setVisible(m_cc.isAppsServerOK(false));
|
||||
boolean rw = !m_cc.isAppsServerOK(false);
|
||||
//
|
||||
dbTypeLabel.setReadWrite(rw);
|
||||
dbTypeField.setReadWrite(rw);
|
||||
|
|
|
@ -255,7 +255,7 @@ public class GridTabVO implements Evaluatee, Serializable
|
|||
return mTabVO.initFields;
|
||||
}
|
||||
|
||||
if (CConnection.get().isRMIoverHTTP() || CConnection.get().getDatabase().getStatus() == null)
|
||||
if (CConnection.get().isServerObjects())
|
||||
{
|
||||
CLogger.get().log(Level.SEVERE, "Application server not available.");
|
||||
return false;
|
||||
|
@ -331,8 +331,8 @@ public class GridTabVO implements Evaluatee, Serializable
|
|||
}
|
||||
else
|
||||
{
|
||||
if (CConnection.get().isRMIoverHTTP())
|
||||
CLogger.get().log(Level.SEVERE, "WAN - Application server not available.");
|
||||
if (CConnection.get().isServerObjects())
|
||||
CLogger.get().log(Level.SEVERE, "Remote Connection - Application server not available.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.Calendar;
|
|||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
/**
|
||||
* Adempiere Callable Statement
|
||||
*
|
||||
|
@ -71,13 +72,16 @@ public class CCallableStatement extends CPreparedStatement implements CallableSt
|
|||
Connection conn = null;
|
||||
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
|
||||
if (trx != null)
|
||||
{
|
||||
conn = trx.getConnection();
|
||||
useTransactionConnection = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
|
||||
conn = DB.getConnectionRW ();
|
||||
else
|
||||
conn = DB.getConnectionRO();
|
||||
conn = DB.getConnectionRO();
|
||||
}
|
||||
if (conn == null)
|
||||
throw new DBException("No Connection");
|
||||
|
|
|
@ -593,14 +593,12 @@ public class CLogMgt
|
|||
boolean remoteObjects = DB.isRemoteObjects();
|
||||
boolean remoteProcess = DB.isRemoteProcess();
|
||||
String realCP = CConnection.PROFILE_LAN;
|
||||
if (cc.isRMIoverHTTP() && cc.isAppsServerOK(false))
|
||||
if (cc.isRMIoverHTTP())
|
||||
realCP = CConnection.PROFILE_WAN;
|
||||
else if (remoteObjects && remoteProcess)
|
||||
realCP = CConnection.PROFILE_VPN;
|
||||
else if (remoteProcess)
|
||||
realCP = CConnection.PROFILE_TERMINAL;
|
||||
sb.append(cc.getConnectionProfileText(realCP));
|
||||
sb.append(": Tunnel=").append(cc.isRMIoverHTTP() && cc.isAppsServerOK(false))
|
||||
sb.append(": Tunnel=").append(cc.isRMIoverHTTP())
|
||||
.append(", Objects=").append(remoteObjects)
|
||||
.append(", Process=").append(remoteProcess);
|
||||
|
||||
|
|
|
@ -76,7 +76,10 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
|
|||
Connection conn = null;
|
||||
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
|
||||
if (trx != null)
|
||||
{
|
||||
conn = trx.getConnection();
|
||||
useTransactionConnection = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
|
||||
|
@ -152,19 +155,7 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
|
|||
else
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
// Try locally
|
||||
if (!CConnection.get().isRMIoverHTTP() && CConnection.get().getDatabase().getStatus() != null)
|
||||
{
|
||||
log.warning("Execute locally");
|
||||
p_stmt = local_getPreparedStatement (false, null); // shared connection
|
||||
p_vo.clearParameters(); // re-use of result set
|
||||
ResultSet rs = ((PreparedStatement)p_stmt).executeQuery();
|
||||
return rs;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("WAN - Application server not available");
|
||||
}
|
||||
throw new IllegalStateException("Remote Connection - Application server not available");
|
||||
} // executeQuery
|
||||
|
||||
/**
|
||||
|
@ -222,18 +213,7 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
|
|||
else
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
// Try locally
|
||||
if (!CConnection.get().isRMIoverHTTP() && CConnection.get().getDatabase().getStatus() != null)
|
||||
{
|
||||
log.warning("execute locally");
|
||||
p_stmt = local_getPreparedStatement (false, null); // shared connection
|
||||
p_vo.clearParameters(); // re-use of result set
|
||||
return ((PreparedStatement)p_stmt).executeUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("WAN - Application server not available");
|
||||
}
|
||||
throw new IllegalStateException("Remote Connection - Application server not available");
|
||||
} // executeUpdate
|
||||
|
||||
/**
|
||||
|
@ -940,18 +920,7 @@ public class CPreparedStatement extends CStatement implements PreparedStatement
|
|||
else
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
// Try locally
|
||||
if (!CConnection.get().isRMIoverHTTP() && CConnection.get().getDatabase().getStatus() != null)
|
||||
{
|
||||
log.warning("Execute locally");
|
||||
p_stmt = local_getPreparedStatement (false, null); // shared connection
|
||||
p_vo.clearParameters(); // re-use of result set
|
||||
return local_getRowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("WAN - Application server not available");
|
||||
}
|
||||
throw new IllegalStateException("Remote Connection - Application server not available");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,11 @@ import org.compiere.interfaces.*;
|
|||
*/
|
||||
public class CStatement implements Statement
|
||||
{
|
||||
protected boolean useTransactionConnection = false;
|
||||
|
||||
private boolean close = false;
|
||||
|
||||
|
||||
/**
|
||||
* Prepared Statement Constructor
|
||||
*
|
||||
|
@ -67,7 +72,10 @@ public class CStatement implements Statement
|
|||
Connection conn = null;
|
||||
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
|
||||
if (trx != null)
|
||||
{
|
||||
conn = trx.getConnection();
|
||||
useTransactionConnection = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
|
||||
|
@ -164,17 +172,7 @@ public class CStatement implements Statement
|
|||
else
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
// Try locally
|
||||
if (!CConnection.get().isRMIoverHTTP() && CConnection.get().getDatabase().getStatus() != null)
|
||||
{
|
||||
log.warning("execute locally");
|
||||
p_stmt = local_getStatement (false, null); // shared connection
|
||||
return p_stmt.executeQuery(p_vo.getSql());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("WAN - Application server not available");
|
||||
}
|
||||
throw new IllegalStateException("Remote Connection - Application server not available");
|
||||
} // executeQuery
|
||||
|
||||
|
||||
|
@ -223,17 +221,7 @@ public class CStatement implements Statement
|
|||
else
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
// Try locally
|
||||
if (!CConnection.get().isRMIoverHTTP() && CConnection.get().getDatabase().getStatus() != null)
|
||||
{
|
||||
log.warning("execute locally");
|
||||
p_stmt = local_getStatement (false, null); // shared connection
|
||||
return p_stmt.executeUpdate(p_vo.getSql());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("WAN - Application server not available");
|
||||
}
|
||||
throw new IllegalStateException("Remote Connection - Application server not available");
|
||||
} // executeUpdate
|
||||
|
||||
/**
|
||||
|
@ -752,11 +740,12 @@ public class CStatement implements Statement
|
|||
Connection conn = p_stmt.getConnection();
|
||||
p_stmt.close();
|
||||
|
||||
if (!conn.isClosed() && conn.getAutoCommit())
|
||||
if (!close && !useTransactionConnection)
|
||||
{
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
close = true;
|
||||
} // close
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -927,18 +916,7 @@ public class CStatement implements Statement
|
|||
else
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
// Try locally
|
||||
if (!CConnection.get().isRMIoverHTTP() && CConnection.get().getDatabase().getStatus() != null)
|
||||
{
|
||||
log.warning("Execute locally");
|
||||
p_stmt = local_getStatement(false, null); // shared connection
|
||||
p_vo.clearParameters(); // re-use of result set
|
||||
return local_getRowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("WAN - Application server not available");
|
||||
}
|
||||
throw new IllegalStateException("Remote Connection - Application server not available");
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
|
@ -967,14 +945,22 @@ public class CStatement implements Statement
|
|||
return rowSet;
|
||||
} // local_getRowSet
|
||||
|
||||
public boolean isPoolable() throws SQLException{ return false;}
|
||||
public boolean isPoolable() throws SQLException{ return false;}
|
||||
|
||||
public void setPoolable(boolean a) throws SQLException{};
|
||||
public void setPoolable(boolean a) throws SQLException{};
|
||||
|
||||
public boolean isClosed() throws SQLException{ return false;}
|
||||
public boolean isClosed() throws SQLException{ return close;}
|
||||
|
||||
public boolean isWrapperFor(java.lang.Class c) throws SQLException{ return false;}
|
||||
public boolean isWrapperFor(java.lang.Class c) throws SQLException{ return false;}
|
||||
|
||||
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException{return null;}
|
||||
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException{return null;}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return is using transaction connection
|
||||
*/
|
||||
public boolean isUseTransactionConnection() {
|
||||
return useTransactionConnection;
|
||||
}
|
||||
|
||||
} // CStatement
|
||||
|
|
|
@ -245,14 +245,10 @@ public final class DB
|
|||
* @return True if success, false otherwise
|
||||
*/
|
||||
public static boolean connect() {
|
||||
//wan profile
|
||||
if (CConnection.get().isRMIoverHTTP())
|
||||
//wan and vpn profile ( remote connection )
|
||||
if (isRemoteObjects())
|
||||
return CConnection.get().isAppsServerOK(true);
|
||||
|
||||
//vpn profile
|
||||
if (isRemoteObjects() && CConnection.get().isAppsServerOK(true))
|
||||
return true;
|
||||
|
||||
//direct connection
|
||||
boolean success =false;
|
||||
try
|
||||
|
@ -306,14 +302,10 @@ public final class DB
|
|||
//bug [1637432]
|
||||
if (s_cc == null) return false;
|
||||
|
||||
//wan profile
|
||||
if (CConnection.get().isRMIoverHTTP())
|
||||
//wan/vpn profile ( remote connection )
|
||||
if (CConnection.get().isServerObjects())
|
||||
return s_cc.isAppsServerOK(createNew);
|
||||
|
||||
//vpn
|
||||
if (isRemoteObjects() && s_cc.isAppsServerOK(createNew))
|
||||
return true;
|
||||
|
||||
//direct connection
|
||||
boolean success = false;
|
||||
CLogErrorBuffer eb = CLogErrorBuffer.get(false);
|
||||
|
@ -387,11 +379,8 @@ public final class DB
|
|||
*/
|
||||
public static Connection createConnection (boolean autoCommit, int trxLevel)
|
||||
{
|
||||
//wan/vpn profile
|
||||
if (CConnection.get().isRMIoverHTTP() ||
|
||||
(CConnection.get().isServerObjects() &&
|
||||
CConnection.get().isAppsServerOK(false) &&
|
||||
CConnection.get().getDatabase().getStatus() == null))
|
||||
//wan/vpn profile ( remote connection )
|
||||
if (CConnection.get().isServerObjects())
|
||||
return new ServerConnection();
|
||||
|
||||
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
|
||||
|
@ -423,11 +412,8 @@ public final class DB
|
|||
*/
|
||||
public static Connection createConnection (boolean autoCommit, boolean readOnly, int trxLevel)
|
||||
{
|
||||
//wan/vpn profile
|
||||
if (CConnection.get().isRMIoverHTTP() ||
|
||||
( CConnection.get().isServerObjects() &&
|
||||
CConnection.get().isAppsServerOK(false) &&
|
||||
CConnection.get().getDatabase().getStatus() == null ))
|
||||
//wan/vpn profile ( remote connection )
|
||||
if (CConnection.get().isServerObjects())
|
||||
return new ServerConnection();
|
||||
|
||||
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
|
||||
|
@ -1478,8 +1464,7 @@ public final class DB
|
|||
//avoid infinite loop
|
||||
if (s_cc == null) return false;
|
||||
|
||||
return CConnection.get().isServerObjects()
|
||||
&& CConnection.get().isAppsServerOK(false);
|
||||
return CConnection.get().isServerObjects();
|
||||
} // isRemoteObjects
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue