[ 2042733 ] Remove non-Lan connection profile code

[ 2188252 ] Make Adempiere build using both jdk 5 and jdk 6
This commit is contained in:
Heng Sin Low 2008-10-24 22:29:40 +00:00
parent b0d7f89e8a
commit 126f1f06e3
41 changed files with 751 additions and 6330 deletions

View File

@ -43,7 +43,6 @@
<classpathentry exported="true" kind="lib" path="tools/lib/commons-logging.jar"/>
<classpathentry exported="true" kind="lib" path="tools/lib/commons-net-1.4.0.jar"/>
<classpathentry exported="true" kind="lib" path="tools/lib/jgraph.jar"/>
<classpathentry exported="true" kind="lib" path="tools/lib/jcommon-1.0.5.jar"/>
<classpathentry exported="true" kind="lib" path="tools/lib/postgresql.jar"/>
<classpathentry exported="true" kind="lib" path="tools/lib/c3p0-0.9.1.2.jar"/>
<classpathentry exported="true" kind="lib" path="tools/lib/c3p0-oracle-thin-extras-0.9.1.2.jar"/>

View File

@ -1,7 +1,8 @@
#Sun Aug 03 07:33:03 SGT 2008
#Fri Oct 24 10:43:33 SGT 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -46,7 +46,6 @@ import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import org.compiere.db.CConnection;
import org.compiere.db.ServerConnection;
import org.compiere.interfaces.MD5;
import org.compiere.interfaces.MD5Home;
import org.compiere.model.MAttachment;
@ -351,16 +350,9 @@ public class ReportStarter implements ProcessCall, ClientProcess {
* @return Connection DB Connection
*/
protected Connection getConnection()
{
if (DB.isRemoteObjects())
{
return new ServerConnection();
}
else
{
return DB.getConnectionRW();
}
}
/**
* Start the process.

View File

@ -27,8 +27,6 @@ import javax.swing.JOptionPane;
import org.compiere.*;
import org.compiere.interfaces.*;
import org.compiere.util.*;
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimplePrincipal;
/**
* Adempiere Connection Descriptor
@ -45,12 +43,12 @@ public class CConnection implements Serializable, Cloneable
private static CLogger log = CLogger.getCLogger (CConnection.class);
/** Connection profiles */
@Deprecated
public static ValueNamePair[] CONNECTIONProfiles = new ValueNamePair[]{
new ValueNamePair("L", "LAN"),
new ValueNamePair("V", "VPN"),
new ValueNamePair("W", "WAN") };
new ValueNamePair("L", "LAN")};
/** Connection Profile LAN */
@Deprecated
public static final String PROFILE_LAN = "L";
/**
* Connection Profile Terminal Server
@ -58,8 +56,10 @@ public class CConnection implements Serializable, Cloneable
**/
public static final String PROFILE_TERMINAL = "T";
/** Connection Profile VPM */
@Deprecated
public static final String PROFILE_VPN = "V";
/** Connection Profile WAN */
@Deprecated
public static final String PROFILE_WAN = "W";
/**
@ -199,7 +199,7 @@ public class CConnection implements Serializable, Cloneable
private String m_db_name = "MyDBName";
/** Connection Profile */
private String m_connectionProfile = null;
private String m_connectionProfile = PROFILE_LAN;
/** In Memory connection */
private boolean m_bequeath = false;
@ -545,71 +545,43 @@ public class CConnection implements Serializable, Cloneable
/**
* RMI over HTTP
*
* Deprecated, always return false
* @return true if RMI over HTTP (Wan Connection Profile)
* @deprecated
*/
public boolean isRMIoverHTTP ()
{
return Ini.isClient()
&& getConnectionProfile().equals(PROFILE_WAN);
return false;
} // isRMIoverHTTP
/**
* Set Connection Profile
* @param connectionProfile connection profile
* @deprecated
*/
public void setConnectionProfile (ValueNamePair connectionProfile)
{
if (connectionProfile != null)
setConnectionProfile(connectionProfile.getValue());
setConnectionProfile(PROFILE_LAN);
} // setConnectionProfile
/**
* Set Connection Profile
* @param connectionProfile connection profile
* @deprecated
*/
public void setConnectionProfile (String connectionProfile)
{
if (connectionProfile == null
|| (m_connectionProfile != null
&& m_connectionProfile.equals(connectionProfile))) // same
return;
if (PROFILE_TERMINAL.equals(connectionProfile))
connectionProfile = PROFILE_LAN;
if (PROFILE_LAN.equals(connectionProfile)
|| PROFILE_VPN.equals(connectionProfile)
|| PROFILE_WAN.equals(connectionProfile))
{
if (m_connectionProfile != null)
{
log.config(m_connectionProfile + " -> " + connectionProfile);
m_connectionProfile = connectionProfile;
if (PROFILE_WAN.equals(m_connectionProfile))
setAppsPort(80);
else
setAppsPort(DEFAULT_APP_SERVER_PORT);
Ini.setProperty(Ini.P_CONNECTION, toStringLong());
}
else
m_connectionProfile = connectionProfile;
//hengsin, reset initial context and env
m_iContext = null;
m_env = null;
}
else
log.warning("Invalid: " + connectionProfile);
} // setConnectionProfile
/**
* Get Connection Profile
* @return connection profile
* @deprecated
*/
public String getConnectionProfile ()
{
if (m_connectionProfile != null)
return m_connectionProfile;
return PROFILE_LAN;
} // getConnectionProfile
@ -617,6 +589,7 @@ public class CConnection implements Serializable, Cloneable
* Get Connection Profile Text
* @param connectionProfile
* @return connection profile text
* @deprecated
*/
public String getConnectionProfileText (String connectionProfile)
{
@ -631,6 +604,7 @@ public class CConnection implements Serializable, Cloneable
/**
* Get Connection Profile Text
* @return connection profile text
* @deprecated
*/
public String getConnectionProfileText ()
{
@ -640,6 +614,7 @@ public class CConnection implements Serializable, Cloneable
/**
* Get Connection Profile
* @return connection profile
* @deprecated
*/
public ValueNamePair getConnectionProfilePair ()
{
@ -654,23 +629,21 @@ public class CConnection implements Serializable, Cloneable
/**
* Should objects be created on Server ?
* @return true if client and VPN/WAN
* @deprecated
*/
public boolean isServerObjects()
{
return (Ini.isClient()
&& (getConnectionProfile().equals(PROFILE_VPN)
|| getConnectionProfile().equals(PROFILE_WAN) ));
return false;
} // isServerObjects
/**
* Should objects be created on Server ?
* @return true if client and Terminal/VPN/WAN
* @deprecated
*/
public boolean isServerProcess()
{
return (Ini.isClient()
&& (getConnectionProfile().equals(PROFILE_VPN)
|| getConnectionProfile().equals(PROFILE_WAN) ));
return false;
} // isServerProcess
/**
@ -956,10 +929,6 @@ public class CConnection implements Serializable, Cloneable
*/
public Exception testDatabase(boolean retest)
{
// At this point Application Server Connection is tested.
if (DB.isRemoteObjects())
return null;
if (!retest && m_ds != null && m_okDB)
return null;
@ -1093,7 +1062,6 @@ public class CConnection implements Serializable, Cloneable
sb.append ("name=").append (m_name)
.append (",AppsHost=").append (m_apps_host)
.append (",AppsPort=").append (m_apps_port)
.append (",Profile=").append (getConnectionProfile())
.append (",type=").append (m_type)
.append (",DBhost=").append (m_db_host)
.append (",DBport=").append (m_db_port)
@ -1121,9 +1089,6 @@ public class CConnection implements Serializable, Cloneable
setAppsHost (attributes.substring (attributes.indexOf ("AppsHost=") + 9, attributes.indexOf (",AppsPort=")));
int index = attributes.indexOf("AppsPort=");
setAppsPort (attributes.substring (index + 9, attributes.indexOf (",", index)));
index = attributes.indexOf("Profile=");
if (index > 0) // new attribute, may not exist
setConnectionProfile(attributes.substring(index+8, attributes.indexOf (",", index)));
//
setType (attributes.substring (attributes.indexOf ("type=")+5, attributes.indexOf (",DBhost=")));
setDbHost (attributes.substring (attributes.indexOf ("DBhost=") + 7, attributes.indexOf (",DBport=")));
@ -1159,7 +1124,6 @@ public class CConnection implements Serializable, Cloneable
&& cc.getAppsPort() == m_apps_port
&& cc.getDbHost().equals (m_db_host)
&& cc.getDbPort() == m_db_port
&& cc.getConnectionProfile().equals(getConnectionProfile())
&& cc.getDbName().equals(m_db_name)
&& cc.getType().equals(m_type)
&& cc.getDbUid().equals(m_db_uid)
@ -1217,13 +1181,9 @@ public class CConnection implements Serializable, Cloneable
break;
}
}
//hengsin, don't test datasource for wan profile
if (!DB.isRemoteObjects())
{
if (m_db != null) // test class loader ability
m_db.getDataSource(this);
}
}
catch (NoClassDefFoundError ee)
{
System.err.println("Environment Error - Check Adempiere.properties - " + ee);
@ -1448,7 +1408,7 @@ public class CConnection implements Serializable, Cloneable
* Get Initial Environment
* @param AppsHost host
* @param AppsPort port
* @param RMIoverHTTP true if tunnel through HTTP
* @param RMIoverHTTP ignore
* @param principal
* @param credential
* @return environment
@ -1459,21 +1419,9 @@ public class CConnection implements Serializable, Cloneable
// Set Environment
Hashtable<String,String> env = new Hashtable<String,String>();
String connect = AppsHost;
if (RMIoverHTTP)
{
env.put (Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.HttpNamingContextFactory");
if (AppsHost.indexOf("://") == -1)
connect = "http://" + AppsHost + ":" + AppsPort
+ "/invoker/JNDIFactory";
env.put(Context.PROVIDER_URL, connect);
}
else
{
env.put (Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
if (AppsHost.indexOf("://") == -1)
connect = "jnp://" + AppsHost + ":" + AppsPort;
env.put (Context.PROVIDER_URL, connect);
}
env.put (Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
// HTTP - default timeout 0
env.put (org.jnp.interfaces.TimedSocketFactory.JNP_TIMEOUT, "5000"); // timeout in ms
@ -1483,13 +1431,13 @@ public class CConnection implements Serializable, Cloneable
if (principal != null && credential != null)
{
SecurityAssociation.setPrincipal(new SimplePrincipal(principal));
SecurityAssociation.setCredential(credential);
env.put (Context.INITIAL_CONTEXT_FACTORY,"org.jboss.security.jndi.JndiLoginInitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, principal);
env.put(Context.SECURITY_CREDENTIALS, credential);
}
else
{
SecurityAssociation.setPrincipal(null);
SecurityAssociation.setCredential(null);
env.put (Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
}
return env;
@ -1600,9 +1548,6 @@ public class CConnection implements Serializable, Cloneable
setDbPort (svr.getDbPort ());
setDbName (svr.getDbName ());
setDbUid (svr.getDbUid ());
if (DB.isRemoteObjects())
setDbPwd ("");
else
setDbPwd (svr.getDbPwd ());
setBequeath (false);
//

View File

@ -122,8 +122,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
private CLabel dbUidLabel = new CLabel();
private CTextField dbUidField = new CTextField();
private JPasswordField dbPwdField = new JPasswordField();
private CLabel connectionProfileLabel = new CLabel();
private CComboBox connectionProfileField = new CComboBox(CConnection.CONNECTIONProfiles);
private boolean isCancel = true;
@ -166,8 +164,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
//cbOverwrite.setText(res.getString("Overwrite"));
dbUidLabel.setText(res.getString("DBUidPwd"));
dbUidField.setColumns(10);
connectionProfileLabel.setText(res.getString("ConnectionProfile"));
connectionProfileField.addActionListener(this);
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.add(centerPanel, BorderLayout.CENTER);
mainPanel.add(southPanel, BorderLayout.SOUTH);
@ -187,51 +183,47 @@ public class CConnectionDialog extends CDialog implements ActionListener
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(appsPortField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
centerPanel.add(connectionProfileLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(connectionProfileField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
//
centerPanel.add(bTestApps, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
centerPanel.add(bTestApps, new GridBagConstraints(1, 3, 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));
// DB
centerPanel.add(dbTypeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
centerPanel.add(dbTypeLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(dbTypeField, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0
centerPanel.add(dbTypeField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0));
centerPanel.add(cbBequeath, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0
centerPanel.add(cbBequeath, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 12), 0, 0));
centerPanel.add(hostLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
centerPanel.add(hostLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0));
centerPanel.add(hostField, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0
centerPanel.add(hostField, new GridBagConstraints(1, 5, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0));
centerPanel.add(portLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
centerPanel.add(portLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(dbPortField, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0
centerPanel.add(dbPortField, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(sidLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
centerPanel.add(sidLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(sidField, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0
centerPanel.add(sidField, new GridBagConstraints(1, 7, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(dbUidLabel, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0
centerPanel.add(dbUidLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(dbUidField, new GridBagConstraints(1, 9, 1, 1, 0.0, 0.0
centerPanel.add(dbUidField, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(dbPwdField, new GridBagConstraints(2, 9, 1, 1, 1.0, 0.0
centerPanel.add(dbPwdField, new GridBagConstraints(2, 8, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 12), 0, 0));
centerPanel.add(cbFirewall, new GridBagConstraints(1, 10, 2, 1, 0.0, 0.0
centerPanel.add(cbFirewall, new GridBagConstraints(1, 9, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 12), 0, 0));
centerPanel.add(fwHostLabel, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
centerPanel.add(fwHostLabel, new GridBagConstraints(0, 10, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fwHostField, new GridBagConstraints(1, 11, 2, 1, 0.0, 0.0
centerPanel.add(fwHostField, new GridBagConstraints(1, 10, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0));
centerPanel.add(fwPortLabel, new GridBagConstraints(0, 12, 1, 1, 0.0, 0.0
centerPanel.add(fwPortLabel, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0));
centerPanel.add(fwPortField, new GridBagConstraints(1, 12, 1, 1, 0.0, 0.0
centerPanel.add(fwPortField, new GridBagConstraints(1, 11, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0));
centerPanel.add(bTestDB, new GridBagConstraints(1, 13, 1, 1, 0.0, 0.0
centerPanel.add(bTestDB, new GridBagConstraints(1, 12, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0));
//
nameField.addActionListener(this);
@ -260,8 +252,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
appsPortLabel.setVisible(false);
appsPortField.setVisible(false);
bTestApps.setVisible(false);
connectionProfileLabel.setVisible(false);
connectionProfileField.setVisible(false);
}
else // Client
cbBequeath.setVisible(false);
@ -342,16 +332,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
dispose();
return;
}
else if (src == connectionProfileField)
{
ValueNamePair pp = (ValueNamePair)connectionProfileField.getSelectedItem();
m_cc.setConnectionProfile(pp.getValue());
if (m_cc.isRMIoverHTTP())
appsPortField.setText(APPS_PORT_HTTP);
else
appsPortField.setText(APPS_PORT_JNP);
return;
}
else if (src == dbTypeField)
{
if (dbTypeField.getSelectedItem() == null)
@ -395,9 +375,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
else
m_cc.setAppsHost("localhost");
//
ValueNamePair pp = (ValueNamePair)connectionProfileField.getSelectedItem();
m_cc.setConnectionProfile(pp.getValue());
//
m_cc.setType((String)dbTypeField.getSelectedItem());
m_cc.setDbHost(hostField.getText());
m_cc.setDbPort(dbPortField.getText());
@ -420,19 +397,6 @@ public class CConnectionDialog extends CDialog implements ActionListener
appsHostField.setText(m_cc.getAppsHost());
appsPortField.setText(String.valueOf(m_cc.getAppsPort()));
//
String cp = m_cc.getConnectionProfile();
ValueNamePair cpPP = null;
for (int i = 0; i < CConnection.CONNECTIONProfiles.length; i++)
{
if (cp.equals(CConnection.CONNECTIONProfiles[i].getValue()))
{
cpPP = CConnection.CONNECTIONProfiles[i];
break;
}
}
if (cpPP == null) // LAN
cpPP = CConnection.CONNECTIONProfiles[0];
connectionProfileField.setSelectedItem(cpPP);
bTestApps.setIcon(getStatusIcon(m_cc.isAppsServerOK(false)));
// bTestApps.setToolTipText(m_cc.getRmiUri());

View File

@ -0,0 +1,71 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.compiere.db;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.compiere.util.CStatementVO;
import org.compiere.util.DB;
import org.compiere.util.Trx;
/**
* Dynamic proxy for the CCallableStatement
* @author Low Heng Sin
*/
public class CallableStatementProxy extends PreparedStatementProxy {
public CallableStatementProxy(CStatementVO vo) {
super(vo);
}
public CallableStatementProxy(int resultSetType, int resultSetConcurrency,
String sql0, String trxName) {
super(resultSetType, resultSetConcurrency, sql0, trxName);
}
/**
* Initialise the prepared statement wrapper object
*/
protected void init()
{
try
{
Connection conn = null;
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
if (trx != null)
{
conn = trx.getConnection();
}
else
{
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
m_conn = DB.getConnectionRW ();
else
m_conn = DB.getConnectionRO();
conn = m_conn;
}
if (conn == null)
throw new DBException("No Connection");
p_stmt = conn.prepareCall(p_vo.getSql(), p_vo.getResultSetType(), p_vo.getResultSetConcurrency());
return;
}
catch (Exception e)
{
log.log(Level.SEVERE, p_vo.getSql(), e);
throw new DBException(e);
}
}
}

View File

@ -0,0 +1,104 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.compiere.db;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.logging.Level;
import javax.sql.RowSet;
import org.adempiere.exceptions.DBException;
import org.compiere.util.CCachedRowSet;
import org.compiere.util.CStatementVO;
import org.compiere.util.DB;
import org.compiere.util.Trx;
/**
* Dynamic proxy for the CPreparedStatement interface
* @author Low Heng Sin
*/
public class PreparedStatementProxy extends StatementProxy {
public PreparedStatementProxy(int resultSetType, int resultSetConcurrency,
String sql0, String trxName) {
if (sql0 == null || sql0.length() == 0)
throw new IllegalArgumentException("sql required");
p_vo = new CStatementVO(resultSetType, resultSetConcurrency, DB
.getDatabase().convertStatement(sql0));
p_vo.setTrxName(trxName);
init();
} // PreparedStatementProxy
public PreparedStatementProxy(CStatementVO vo)
{
super(vo);
} // PreparedStatementProxy
/**
* Initialise the prepared statement wrapper object
*/
protected void init() {
try {
Connection conn = null;
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo
.getTrxName(), true);
if (trx != null) {
conn = trx.getConnection();
} else {
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
m_conn = DB.getConnectionRW();
else
m_conn = DB.getConnectionRO();
conn = m_conn;
}
if (conn == null)
throw new DBException("No Connection");
p_stmt = conn.prepareStatement(p_vo.getSql(), p_vo
.getResultSetType(), p_vo.getResultSetConcurrency());
} catch (Exception e) {
log.log(Level.SEVERE, p_vo.getSql(), e);
throw new DBException(e);
}
}
@Override
protected RowSet getRowSet()
{
log.finest("local_getRowSet");
RowSet rowSet = null;
ResultSet rs = null;
PreparedStatement pstmt = (PreparedStatement)p_stmt;
try
{
rs = pstmt.executeQuery();
rowSet = CCachedRowSet.getRowSet(rs);
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
finally
{
DB.close(rs);
}
return rowSet;
} // local_getRowSet
}

View File

@ -0,0 +1,106 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.compiere.db;
import java.lang.reflect.Proxy;
import org.compiere.util.CCallableStatement;
import org.compiere.util.CPreparedStatement;
import org.compiere.util.CStatement;
import org.compiere.util.CStatementVO;
/**
*
* Factory class to instantiate dynamic proxy for CStatement, CPreparedStatement and CCallableStatement
* @author Low Heng Sin
*
*/
public class ProxyFactory {
/**
*
* @param resultSetType
* @param resultSetConcurrency
* @param trxName
* @return CStatement proxy
*/
public static CStatement newCStatement(int resultSetType,
int resultSetConcurrency, String trxName) {
return (CStatement)Proxy.newProxyInstance(CStatement.class.getClassLoader(),
new Class[]{CStatement.class},
new StatementProxy(resultSetType, resultSetConcurrency, trxName));
}
/**
*
* @param resultSetType
* @param resultSetConcurrency
* @param sql
* @param trxName
* @return CPreparedStatement proxy
*/
public static CPreparedStatement newCPreparedStatement(int resultSetType,
int resultSetConcurrency, String sql, String trxName) {
return (CPreparedStatement)Proxy.newProxyInstance(CPreparedStatement.class.getClassLoader(),
new Class[]{CPreparedStatement.class},
new PreparedStatementProxy(resultSetType, resultSetConcurrency, sql, trxName));
}
/**
*
* @param resultSetType
* @param resultSetConcurrency
* @param sql
* @param trxName
* @return CCallableStatement proxy
*/
public static CCallableStatement newCCallableStatement(int resultSetType,
int resultSetConcurrency, String sql, String trxName) {
return (CCallableStatement)Proxy.newProxyInstance(CCallableStatement.class.getClassLoader(),
new Class[]{CCallableStatement.class},
new CallableStatementProxy(resultSetType, resultSetConcurrency, sql, trxName));
}
/**
*
* @param info
* @return CStatement proxy
*/
public static CStatement newCStatement(CStatementVO info) {
return (CStatement)Proxy.newProxyInstance(CStatement.class.getClassLoader(),
new Class[]{CStatement.class},
new StatementProxy(info));
}
/**
*
* @param info
* @return CPreparedStatement proxy
*/
public static CPreparedStatement newCPreparedStatement(CStatementVO info) {
return (CPreparedStatement)Proxy.newProxyInstance(CPreparedStatement.class.getClassLoader(),
new Class[]{CPreparedStatement.class},
new PreparedStatementProxy(info));
}
/**
*
* @param info
* @return CCallableStatement proxy
*/
public static CCallableStatement newCCallableStatement(CStatementVO info) {
return (CCallableStatement)Proxy.newProxyInstance(CCallableStatement.class.getClassLoader(),
new Class[]{CCallableStatement.class},
new CallableStatementProxy(info));
}
}

View File

@ -1,311 +0,0 @@
/**
* Product: Posterita Web-Based POS, Webstore and Adempiere Plugin
* Copyright (C) 2007 Posterita Ltd
* This file is part of POSterita
*
* POSterita is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
package org.compiere.db;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.Map;
import org.compiere.util.DB;
import org.compiere.util.Trx;
/**
* Connection that is used to execute query on Server for Client processes
* Need for Jasper Report processes as the Jasper Manager uses a connection
*
* @author Ashley G Ramdass
*/
public class ServerConnection implements Connection
{
private String trxName = null;
public ServerConnection() {
}
public ServerConnection(String trxName) {
this.trxName = trxName;
}
public void clearWarnings() throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method clearWarnings() not yet implemented.");
}
public void close() throws SQLException
{
if (trxName != null) {
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.close();
trxName = null;
}
}
public void commit() throws SQLException
{
if (trxName != null) {
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.commit(true);
}
}
public Statement createStatement() throws SQLException
{
return DB.createStatement();
}
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException
{
return DB.createStatement(resultSetType, resultSetConcurrency, trxName);
}
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
{
return createStatement(resultSetType, resultSetConcurrency);
}
public boolean getAutoCommit() throws SQLException
{
return (trxName != null);
}
public String getCatalog() throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method getCatalog() not yet implemented.");
}
public int getHoldability() throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method getHoldability() not yet implemented.");
}
public DatabaseMetaData getMetaData() throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method getMetaData() not yet implemented.");
}
public int getTransactionIsolation() throws SQLException
{
return Connection.TRANSACTION_READ_COMMITTED;
}
public Map<String, Class<?>> getTypeMap() throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method getTypeMap() not yet implemented.");
}
public SQLWarning getWarnings() throws SQLException
{
return null;
}
public boolean isClosed() throws SQLException
{
return false;
}
public boolean isReadOnly() throws SQLException
{
return false;
}
public String nativeSQL(String sql) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method nativeSQL() not yet implemented.");
}
public CallableStatement prepareCall(String sql) throws SQLException
{
return DB.prepareCall(sql);
}
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
{
return DB.prepareCall(sql, resultSetConcurrency, trxName);
}
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
{
return DB.prepareCall(sql, resultSetConcurrency, trxName);
}
public PreparedStatement prepareStatement(String sql) throws SQLException
{
return DB.prepareStatement(sql);
}
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method prepareStatement() not yet implemented.");
}
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method prepareStatement() not yet implemented.");
}
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method prepareStatement() not yet implemented.");
}
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException
{
return DB.prepareStatement(sql, resultSetConcurrency, resultSetConcurrency);
}
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException
{
return prepareStatement(sql, resultSetType, resultSetConcurrency);
}
public void releaseSavepoint(Savepoint savepoint) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method releaseSavepoint() not yet implemented.");
}
public void rollback() throws SQLException
{
if (trxName != null) {
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.rollback(true);
}
}
public void rollback(Savepoint savepoint) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method rollback() not yet implemented.");
}
public void setAutoCommit(boolean autoCommit) throws SQLException
{
if (autoCommit) {
if (trxName != null) {
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.close();
}
} else {
if (trxName == null) {
trxName = Trx.createTrxName();
}
}
}
public void setCatalog(String catalog) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method setCatalog() not yet implemented.");
}
public void setHoldability(int holdability) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method setHoldability() not yet implemented.");
}
public void setReadOnly(boolean readOnly) throws SQLException
{
}
public Savepoint setSavepoint() throws SQLException
{
return setSavepoint(null);
}
public Savepoint setSavepoint(String name) throws SQLException
{
if (trxName == null) {
trxName = Trx.createTrxName();
}
Trx trx = Trx.get(trxName, false);
return trx.setSavepoint(name);
}
public void setTransactionIsolation(int level) throws SQLException
{
}
public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException
{
throw new java.lang.UnsupportedOperationException ("Method setTypeMap() not yet implemented.");
}
/* Java 6 support - teo_sarca BF [ 1806700 ] */
public java.sql.Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public java.sql.Blob createBlob() throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public java.sql.Clob createClob() throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public java.sql.NClob createNClob() throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public java.sql.SQLXML createSQLXML() throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public java.sql.Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public java.util.Properties getClientInfo() throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public String getClientInfo(String name) throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public boolean isValid(int timeout) throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public void setClientInfo(java.util.Properties properties) throws java.sql.SQLClientInfoException {
}
public void setClientInfo(String name, String value) throws java.sql.SQLClientInfoException {
}
public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
public <T> T unwrap(Class<T> iface) throws SQLException {
throw new java.lang.UnsupportedOperationException ("Method not yet implemented.");
}
/* Java 6 support - teo_sarca BF [ 1806700 ] */
}

View File

@ -0,0 +1,198 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.compiere.db;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import javax.sql.RowSet;
import org.adempiere.exceptions.DBException;
import org.compiere.util.CCachedRowSet;
import org.compiere.util.CLogger;
import org.compiere.util.CStatementVO;
import org.compiere.util.DB;
import org.compiere.util.Trx;
/**
*
* Dynamic proxy for the CStatement interface
* @author Low Heng Sin
*/
public class StatementProxy implements InvocationHandler {
protected Connection m_conn = null;
private boolean close = false;
/** Logger */
protected transient CLogger log = CLogger.getCLogger (getClass());
/** Used if local */
protected transient Statement p_stmt = null;
/** Value Object */
protected CStatementVO p_vo = null;
public StatementProxy(int resultSetType, int resultSetConcurrency, String trxName) {
p_vo = new CStatementVO (resultSetType, resultSetConcurrency);
p_vo.setTrxName(trxName);
init();
}
public StatementProxy(CStatementVO vo) {
p_vo = vo;
init();
}
//for subclass
protected StatementProxy() {}
public Object invoke(Object obj, Method method, Object[] args)
throws Throwable {
String name = method.getName();
//handle special case
if (name.equals("executeQuery") || name.equals("executeUpdate")
|| name.equals("execute") || name.equals("addBatch")) {
if (args != null && args.length > 0 && args[0] != null && args[0] instanceof String) {
String sql = (String)args[0];
p_vo.setSql(DB.getDatabase().convertStatement(sql));
args[0] = p_vo.getSql();
}
} else if (name.equals("close") && (args == null || args.length == 0)) {
close();
return null;
} else if (name.equals("getRowSet") && (args == null || args.length == 0)) {
return getRowSet();
} else if (name.equals("isClosed") && (args == null || args.length == 0)) {
return close;
} else if (name.equals("finalize") && (args == null || args.length == 0)) {
if (p_stmt != null && !close)
{
this.close();
}
return null;
} else if (name.equals("commit") && (args == null || args.length == 0)) {
commit();
return null;
}
Method m = p_stmt.getClass().getMethod(name, method.getParameterTypes());
return m.invoke(p_stmt, args);
}
/**
* Initialise the statement wrapper object
*/
protected void init()
{
try
{
Connection conn = null;
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
if (trx != null)
{
conn = trx.getConnection();
}
else
{
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
m_conn = DB.getConnectionRW ();
else
m_conn = DB.getConnectionRO();
conn = m_conn;
}
if (conn == null)
throw new DBException("No Connection");
p_stmt = conn.createStatement(p_vo.getResultSetType(), p_vo.getResultSetConcurrency());
}
catch (SQLException e)
{
log.log(Level.SEVERE, "CStatement", e);
throw new DBException(e);
}
}
/**
* Close
* @throws SQLException
* @see java.sql.Statement#close()
*/
private void close () throws SQLException
{
if (close) return;
try {
if (p_stmt != null)
{
p_stmt.close();
}
} finally {
if (m_conn != null)
{
try
{
m_conn.close();
}
catch (Exception e)
{}
}
m_conn = null;
close = true;
}
} // close
/**
* Execute Query
* @return ResultSet or RowSet
* @throws SQLException
* @see java.sql.PreparedStatement#executeQuery()
*/
protected RowSet getRowSet()
{
log.finest("getRowSet");
RowSet rowSet = null;
ResultSet rs = null;
try
{
rs = p_stmt.executeQuery(p_vo.getSql());
rowSet = CCachedRowSet.getRowSet(rs);
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
finally
{
DB.close(rs);
}
return rowSet;
} // local_getRowSet
/**
* Commit (if local)
* @throws SQLException
*/
private void commit() throws SQLException
{
if (m_conn != null && !m_conn.getAutoCommit())
{
m_conn.commit();
}
} // commit
}

View File

@ -9,16 +9,6 @@ package org.compiere.interfaces;
public interface Server
extends javax.ejb.EJBObject
{
/**
* Get and create Window Model Value Object
* @param ctx Environment Properties
* @param WindowNo number of this window
* @param AD_Window_ID the internal number of the window, if not 0, AD_Menu_ID is ignored
* @param AD_Menu_ID ine internal menu number, used when AD_Window_ID is 0
* @return initialized Window Model */
public org.compiere.model.GridWindowVO getWindowVO( java.util.Properties ctx,int WindowNo,int AD_Window_ID,int AD_Menu_ID )
throws java.rmi.RemoteException;
/**
* Post Immediate
* @param ctx Client Context
@ -31,82 +21,6 @@ public interface Server
public java.lang.String postImmediate( java.util.Properties ctx,int AD_Client_ID,int AD_Table_ID,int Record_ID,boolean force,java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Get Prepared Statement ResultSet
* @param info Result info
* @param token Security Token
* @return RowSet
* @throws NotSerializableException */
public javax.sql.RowSet pstmt_getRowSet( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
throws java.io.NotSerializableException, java.rmi.RemoteException;
/**
* Get Statement ResultSet
* @param info Result info
* @param token Security Token
* @return RowSet */
public javax.sql.RowSet stmt_getRowSet( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException;
/**
* Execute Update
* @param info Result info
* @param token Security Token
* @return row count */
public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException;
public org.compiere.util.ExecuteResult stmt_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException;
public org.compiere.util.CallableResult callable_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException;
/**
* Get next number for Key column = 0 is Error.
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @return next no */
public int getNextID( int AD_Client_ID,java.lang.String TableName,java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Get Document No from table
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @return document no or null */
public java.lang.String getDocumentNo( int AD_Client_ID,java.lang.String TableName,java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Get Document No from table
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @param po
* @return document no or null */
public java.lang.String getDocumentNo( int AD_Client_ID,java.lang.String TableName,java.lang.String trxName,org.compiere.model.PO po )
throws java.rmi.RemoteException;
/**
* Get Document No based on Document Type
* @param C_DocType_ID document type
* @param trxName optional Transaction Name
* @return document no or null */
public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName,boolean definite )
throws java.rmi.RemoteException;
/**
* Get Document No based on Document Type
* @param C_DocType_ID document type
* @param trxName optional Transaction Name
* @param po
* @return document no or null */
public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName,boolean definite,org.compiere.model.PO po )
throws java.rmi.RemoteException;
/**
* Process Remote
* @param ctx Context
@ -124,16 +38,6 @@ public interface Server
public org.compiere.process.ProcessInfo workflow( java.util.Properties ctx,org.compiere.process.ProcessInfo pi,int AD_Workflow_ID )
throws java.rmi.RemoteException;
/**
* Online Payment from Server
* @param ctx Context
* @param C_Payment_ID payment
* @param C_PaymentProcessor_ID processor
* @param trxName transaction
* @return true if approved */
public boolean paymentOnline( java.util.Properties ctx,int C_Payment_ID,int C_PaymentProcessor_ID,java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Create EMail from Server (Request User)
* @param ctx Context
@ -158,7 +62,7 @@ public interface Server
throws java.rmi.RemoteException;
/**
* Create EMail from Server (Request User)
* Execute task on server
* @param AD_Task_ID task
* @return execution trace */
public java.lang.String executeTask( int AD_Task_ID )
@ -172,85 +76,18 @@ public interface Server
public int cacheReset( java.lang.String tableName,int Record_ID )
throws java.rmi.RemoteException;
/**
* LOB update
* @param sql table name
* @param displayType display type (i.e. BLOB/CLOB)
* @param value the data
* @param trxName
* @param token Security Token
* @return true if updated */
public boolean updateLOB( java.lang.String sql,int displayType,java.lang.Object value,java.lang.String trxName,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException;
/**
* Describes the instance and its content for debugging purpose
* @return Debugging information about the instance and its content */
public java.lang.String getStatus( )
throws java.rmi.RemoteException;
/**
* Set savepoint
* @param trxName
* @param savePointName
* @return true if success, false otherwise */
public org.compiere.util.SavepointVO setSavepoint( java.lang.String trxName,java.lang.String savePointName )
throws java.rmi.RemoteException;
/**
* Start remote transaction
* @param trxName */
public void startTransaction( java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Close remote transaction
* @param trxName */
public void closeTransaction( java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Commit the named transaction on server
* @param trxName
* @return true if success, false otherwise */
public boolean commit( java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Rollback the named transaction on server
* @param trxName
* @return true if success, false otherwise */
public boolean rollback( java.lang.String trxName )
throws java.rmi.RemoteException;
/**
* Rollback the named transaction on server
* @param trxName
* @return true if success, false otherwise */
public boolean rollback( java.lang.String trxName,org.compiere.util.SavepointVO savePoint )
throws java.rmi.RemoteException;
/**
* Execute db proces on server
* @param processInfo
* @param procedureName
* @param trxName
* @return ProcessInfo */
public org.compiere.process.ProcessInfo dbProcess( org.compiere.process.ProcessInfo processInfo,java.lang.String procedureName,java.lang.String trxName,org.compiere.util.SecurityToken token )
throws java.rmi.RemoteException;
/**
* Load fields meta data from database
* @param gridTabVO
* @return ArrayList */
public java.util.ArrayList getFields( org.compiere.model.GridTabVO gridTabVO )
throws java.rmi.RemoteException;
/**
* Get table id from ad_table by table name
* @param tableName
* @return tableName */
public int getTableID( java.lang.String tableName )
public org.compiere.process.ProcessInfo dbProcess( org.compiere.process.ProcessInfo processInfo,java.lang.String procedureName )
throws java.rmi.RemoteException;
}

View File

@ -9,15 +9,6 @@ package org.compiere.interfaces;
public interface ServerLocal
extends javax.ejb.EJBLocalObject
{
/**
* Get and create Window Model Value Object
* @param ctx Environment Properties
* @param WindowNo number of this window
* @param AD_Window_ID the internal number of the window, if not 0, AD_Menu_ID is ignored
* @param AD_Menu_ID ine internal menu number, used when AD_Window_ID is 0
* @return initialized Window Model */
public org.compiere.model.GridWindowVO getWindowVO( java.util.Properties ctx,int WindowNo,int AD_Window_ID,int AD_Menu_ID ) ;
/**
* Post Immediate
* @param ctx Client Context
@ -29,72 +20,6 @@ public interface ServerLocal
* @return null, if success or error message */
public java.lang.String postImmediate( java.util.Properties ctx,int AD_Client_ID,int AD_Table_ID,int Record_ID,boolean force,java.lang.String trxName ) ;
/**
* Get Prepared Statement ResultSet
* @param info Result info
* @param token Security Token
* @return RowSet
* @throws NotSerializableException */
public javax.sql.RowSet pstmt_getRowSet( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) throws java.io.NotSerializableException;
/**
* Get Statement ResultSet
* @param info Result info
* @param token Security Token
* @return RowSet */
public javax.sql.RowSet stmt_getRowSet( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ;
/**
* Execute Update
* @param info Result info
* @param token Security Token
* @return row count */
public int stmt_executeUpdate( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ;
public org.compiere.util.ExecuteResult stmt_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ;
public org.compiere.util.CallableResult callable_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token ) ;
/**
* Get next number for Key column = 0 is Error.
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @return next no */
public int getNextID( int AD_Client_ID,java.lang.String TableName,java.lang.String trxName ) ;
/**
* Get Document No from table
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @return document no or null */
public java.lang.String getDocumentNo( int AD_Client_ID,java.lang.String TableName,java.lang.String trxName ) ;
/**
* Get Document No from table
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @param po
* @return document no or null */
public java.lang.String getDocumentNo( int AD_Client_ID,java.lang.String TableName,java.lang.String trxName,org.compiere.model.PO po ) ;
/**
* Get Document No based on Document Type
* @param C_DocType_ID document type
* @param trxName optional Transaction Name
* @return document no or null */
public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName,boolean definite ) ;
/**
* Get Document No based on Document Type
* @param C_DocType_ID document type
* @param trxName optional Transaction Name
* @param po
* @return document no or null */
public java.lang.String getDocumentNo( int C_DocType_ID,java.lang.String trxName,boolean definite,org.compiere.model.PO po ) ;
/**
* Process Remote
* @param ctx Context
@ -110,15 +35,6 @@ public interface ServerLocal
* @return process info */
public org.compiere.process.ProcessInfo workflow( java.util.Properties ctx,org.compiere.process.ProcessInfo pi,int AD_Workflow_ID ) ;
/**
* Online Payment from Server
* @param ctx Context
* @param C_Payment_ID payment
* @param C_PaymentProcessor_ID processor
* @param trxName transaction
* @return true if approved */
public boolean paymentOnline( java.util.Properties ctx,int C_Payment_ID,int C_PaymentProcessor_ID,java.lang.String trxName ) ;
/**
* Create EMail from Server (Request User)
* @param ctx Context
@ -141,7 +57,7 @@ public interface ServerLocal
public org.compiere.util.EMail createEMail( java.util.Properties ctx,int AD_Client_ID,int AD_User_ID,java.lang.String to,java.lang.String subject,java.lang.String message ) ;
/**
* Create EMail from Server (Request User)
* Execute task on server
* @param AD_Task_ID task
* @return execution trace */
public java.lang.String executeTask( int AD_Task_ID ) ;
@ -153,74 +69,16 @@ public interface ServerLocal
* @return number of records reset */
public int cacheReset( java.lang.String tableName,int Record_ID ) ;
/**
* LOB update
* @param sql table name
* @param displayType display type (i.e. BLOB/CLOB)
* @param value the data
* @param trxName
* @param token Security Token
* @return true if updated */
public boolean updateLOB( java.lang.String sql,int displayType,java.lang.Object value,java.lang.String trxName,org.compiere.util.SecurityToken token ) ;
/**
* Describes the instance and its content for debugging purpose
* @return Debugging information about the instance and its content */
public java.lang.String getStatus( ) ;
/**
* Set savepoint
* @param trxName
* @param savePointName
* @return true if success, false otherwise */
public org.compiere.util.SavepointVO setSavepoint( java.lang.String trxName,java.lang.String savePointName ) ;
/**
* Start remote transaction
* @param trxName */
public void startTransaction( java.lang.String trxName ) ;
/**
* Close remote transaction
* @param trxName */
public void closeTransaction( java.lang.String trxName ) ;
/**
* Commit the named transaction on server
* @param trxName
* @return true if success, false otherwise */
public boolean commit( java.lang.String trxName ) ;
/**
* Rollback the named transaction on server
* @param trxName
* @return true if success, false otherwise */
public boolean rollback( java.lang.String trxName ) ;
/**
* Rollback the named transaction on server
* @param trxName
* @return true if success, false otherwise */
public boolean rollback( java.lang.String trxName,org.compiere.util.SavepointVO savePoint ) ;
/**
* Execute db proces on server
* @param processInfo
* @param procedureName
* @param trxName
* @return ProcessInfo */
public org.compiere.process.ProcessInfo dbProcess( org.compiere.process.ProcessInfo processInfo,java.lang.String procedureName,java.lang.String trxName,org.compiere.util.SecurityToken token ) ;
/**
* Load fields meta data from database
* @param gridTabVO
* @return ArrayList */
public java.util.ArrayList getFields( org.compiere.model.GridTabVO gridTabVO ) ;
/**
* Get table id from ad_table by table name
* @param tableName
* @return tableName */
public int getTableID( java.lang.String tableName ) ;
public org.compiere.process.ProcessInfo dbProcess( org.compiere.process.ProcessInfo processInfo,java.lang.String procedureName ) ;
}

View File

@ -253,18 +253,6 @@ public class GridTabVO implements Evaluatee, Serializable
*/
private static boolean createFields (GridTabVO mTabVO)
{
if (DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false))
{
remoteCreateFields(mTabVO);
return mTabVO.initFields;
}
if (CConnection.get().isServerObjects())
{
CLogger.get().log(Level.SEVERE, "Application server not available.");
return false;
}
//local only or remote fail for vpn profile
mTabVO.Fields = new ArrayList<GridFieldVO>();
@ -297,50 +285,6 @@ public class GridTabVO implements Evaluatee, Serializable
return mTabVO.Fields.size() != 0;
} // createFields
private static boolean remoteCreateFields (GridTabVO mTabVO)
{
Server server = CConnection.get().getServer();
if (server != null)
{
try
{
mTabVO.Fields = server.getFields(mTabVO);
mTabVO.initFields =
(mTabVO.Fields != null && mTabVO.Fields.size() > 0);
//sync context
int size = mTabVO.Fields.size();
for (int i = 0; i < size; i++)
{
GridFieldVO field = (GridFieldVO)mTabVO.Fields.get(i);
Properties ctx = field.ctx;
field.setCtx(mTabVO.ctx);
Set keys = ctx.keySet();
//check any key added remotely
for(Iterator k = keys.iterator(); k.hasNext(); )
{
Object key = k.next();
if (mTabVO.ctx.containsKey(key) == false)
{
Object value = ctx.get(key);
mTabVO.ctx.put(key, value);
}
}
}
} catch (Exception e)
{
CLogger.get().log(Level.SEVERE, "Application Server Error: " + e.getLocalizedMessage(), e);
mTabVO.initFields = false;
}
}
else
{
if (CConnection.get().isServerObjects())
CLogger.get().log(Level.SEVERE, "Remote Connection - Application server not available.");
}
return false;
}
/**
* Return the SQL statement used for the MTabVO.create
* @param ctx context

View File

@ -1213,8 +1213,6 @@ public class GridTable extends AbstractTableModel
Object[] rowDataDB = null;
// Prepare
boolean manualUpdate = ResultSet.CONCUR_READ_ONLY == rs.getConcurrency();
if (DB.isRemoteObjects())
manualUpdate = true;
// Manual update if log migration scripts is enabled - teo_sarca BF [ 1901192 ]
if(!manualUpdate && Ini.isPropertyBool(Ini.P_LOGMIGRATIONSCRIPT))
manualUpdate = true;

View File

@ -457,34 +457,7 @@ public final class MPayment extends X_C_Payment
}
boolean approved = false;
/** Process Payment on Server */
if (DB.isRemoteObjects())
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
String trxName = null; // unconditionally save
save(trxName); // server reads from disk
approved = server.paymentOnline (getCtx(), getC_Payment_ID(),
m_mPaymentProcessor.getC_PaymentProcessor_ID(), trxName);
if (CLogMgt.isLevelFinest())
s_log.fine("server => " + approved);
load(trxName); // server saves to disk
setIsApproved(approved);
return approved;
}
log.log(Level.WARNING, "AppsServer not found");
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
}
}
/** **/
// Try locally
try
{
PaymentProcessor pp = PaymentProcessor.create(m_mPaymentProcessor, this);

View File

@ -81,30 +81,6 @@ public class MSequence extends X_AD_Sequence
if (TableName == null || TableName.length() == 0)
throw new IllegalArgumentException("TableName missing");
//get from server
if (DB.isRemoteObjects())
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
// hengsin: don't execute getNextID in tranaction to fix performance and locking issue
int id = server.getNextID(AD_Client_ID, TableName, null);
s_log.finest("server => " + id);
if (id < 0)
throw new DBException("No NextID");
return id;
}
s_log.log(Level.SEVERE, "AppsServer not found - " + TableName);
}
catch (RemoteException ex)
{
s_log.log(Level.SEVERE, "AppsServer error", ex);
}
// Try locally
}
int retValue = -1;
// Check AdempiereSys
@ -116,7 +92,7 @@ public class MSequence extends X_AD_Sequence
s_log.log(LOGLEVEL, TableName + " - AdempiereSys=" + adempiereSys + " [" + trxName + "]");
//begin vpj-cd e-evolution 09/02/2005 PostgreSQL
String selectSQL = null;
if (DB.isOracle() == false || DB.isRemoteObjects())
if (DB.isOracle() == false)
{
selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID "
+ "FROM AD_Sequence "
@ -382,28 +358,6 @@ public class MSequence extends X_AD_Sequence
if (TableName == null || TableName.length() == 0)
throw new IllegalArgumentException("TableName missing");
//get from server
if (DB.isRemoteObjects())
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
String dn = server.getDocumentNo (AD_Client_ID, TableName, trxName, po);
s_log.finest("Server => " + dn);
if (dn != null)
return dn;
}
s_log.log(Level.SEVERE, "AppsServer not found - " + TableName);
}
catch (RemoteException ex)
{
s_log.log(Level.SEVERE, "AppsServer error", ex);
}
}
//local
// Check AdempiereSys
boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
if (adempiereSys && AD_Client_ID > 11)
@ -445,7 +399,7 @@ public class MSequence extends X_AD_Sequence
String selectSQL = null;
if (DB.isOracle() == false || DB.isRemoteObjects())
if (DB.isOracle() == false)
{
if (isStartNewYear) {
selectSQL = "SELECT y.CurrentNext, s.CurrentNextSys, s.IncrementNo, s.Prefix, s.Suffix, s.DecimalPattern, s.AD_Sequence_ID "
@ -673,29 +627,6 @@ public class MSequence extends X_AD_Sequence
return null;
}
//get from server
if (DB.isRemoteObjects())
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
String dn = server.getDocumentNo (C_DocType_ID, trxName, definite, po);
s_log.finest("Server => " + dn);
if (dn != null)
return dn;
}
s_log.log(Level.SEVERE, "AppsServer not found - " + C_DocType_ID);
}
catch (RemoteException ex)
{
s_log.log(Level.SEVERE, "AppsServer error", ex);
}
}
//local
MDocType dt = MDocType.get (Env.getCtx(), C_DocType_ID); // wrong for SERVER, but r/o
if (dt != null && !dt.isDocNoControlled())
{

View File

@ -416,12 +416,9 @@ public class MSystem extends X_AD_System
* Set DB Info
*/
private void setDBInfo()
{
if (!DB.isRemoteObjects())
{
String dbAddress = CConnection.get().getConnectionURL();
setDBAddress(dbAddress.toLowerCase());
}
//
if (!Ini.isClient())
{

View File

@ -748,13 +748,6 @@ public class MTable extends X_AD_Table
int retValue = 0;
String SQL = "SELECT AD_Table_ID FROM AD_Table WHERE tablename = ?";
try
{
if (DB.isRemoteObjects())
{
Server server = CConnection.get().getServer();
retValue = server.getTableID(tableName);
}
else
{
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
pstmt.setString(1, tableName);
@ -764,7 +757,6 @@ public class MTable extends X_AD_Table
rs.close();
pstmt.close();
}
}
catch (Exception e)
{
s_log.log(Level.SEVERE, SQL, e);

View File

@ -109,28 +109,6 @@ public class PO_LOB implements Serializable
.append(" SET ").append(m_columnName)
.append("=? WHERE ").append(m_whereClause);
//
boolean success = true;
if (DB.isRemoteObjects())
{
log.fine("[" + trxName + "] - Remote - " + m_value);
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
success = server.updateLOB (sql.toString(), m_displayType, m_value, trxName, SecurityToken.getInstance());
if (CLogMgt.isLevelFinest())
log.fine("server.updateLOB => " + success);
return success;
}
log.log(Level.SEVERE, "AppsServer not found");
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
}
return false;
}
log.fine("[" + trxName + "] - Local - " + m_value);
// Connection
@ -150,7 +128,7 @@ public class PO_LOB implements Serializable
}
PreparedStatement pstmt = null;
success = true;
boolean success = true;
try
{
pstmt = con.prepareStatement(sql.toString());

File diff suppressed because it is too large Load Diff

View File

@ -591,18 +591,6 @@ public class CLogMgt
//
sb.append(")\n ");
//
boolean remoteObjects = DB.isRemoteObjects();
boolean remoteProcess = DB.isRemoteProcess();
String realCP = CConnection.PROFILE_LAN;
if (cc.isRMIoverHTTP())
realCP = CConnection.PROFILE_WAN;
else if (remoteObjects && remoteProcess)
realCP = CConnection.PROFILE_VPN;
sb.append(cc.getConnectionProfileText(realCP));
sb.append(": Tunnel=").append(cc.isRMIoverHTTP())
.append(", Objects=").append(remoteObjects)
.append(", Process=").append(remoteProcess);
return sb.toString();
} // getServerInfo

View File

@ -16,972 +16,14 @@
*****************************************************************************/
package org.compiere.util;
import java.io.*;
import java.math.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.sql.*;
import org.adempiere.exceptions.DBException;
import org.compiere.db.*;
import org.compiere.interfaces.*;
/**
* Adempiere Prepared Statement
*
* @author Jorg Janke
* @version $Id: CPreparedStatement.java,v 1.3 2006/07/30 00:54:36 jjanke Exp $
* ---
* Modifications: Handle connections properly
* Reason : Due to changes brought in the connection pooling whereby the system
* no more relies upon abandoned connections.
* @author Ashley Ramdass (Posterita)
*/
public class CPreparedStatement extends CStatement implements PreparedStatement
{
/**
* Prepared Statement Constructor
*
* @param resultSetType - ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE
* @param resultSetConcurrency - ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
* @param sql0 unconverted sql statement
* @param trxName transaction name or null
*/
public CPreparedStatement (int resultSetType, int resultSetConcurrency,
String sql0, String trxName)
{
if (sql0 == null || sql0.length() == 0)
throw new IllegalArgumentException ("sql required");
p_vo = new CStatementVO (resultSetType, resultSetConcurrency,
DB.getDatabase().convertStatement(sql0));
p_vo.setTrxName(trxName);
init();
} // CPreparedStatement
/**
* Initialise the prepared statement wrapper object
*/
protected void init()
{
//Local access
if (!DB.isRemoteObjects())
{
try
{
Connection conn = null;
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
if (trx != null)
{
conn = trx.getConnection();
}
else
{
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
m_conn = DB.getConnectionRW ();
else
m_conn = DB.getConnectionRO();
conn = m_conn;
}
if (conn == null)
throw new DBException("No Connection");
p_stmt = conn.prepareStatement (p_vo.getSql(), p_vo.getResultSetType(), p_vo.getResultSetConcurrency());
return;
}
catch (Exception e)
{
log.log(Level.SEVERE, p_vo.getSql(), e);
}
}
}
/**
* Remote Constructor
* @param vo value object
*/
public CPreparedStatement (CStatementVO vo)
{
super(vo);
} // CPreparedStatement
/**
* Execute Query
* @return ResultSet or RowSet
* @throws SQLException
* @see java.sql.PreparedStatement#executeQuery()
*/
public ResultSet executeQuery () throws SQLException
{
if (p_stmt != null) // local
return ((PreparedStatement)p_stmt).executeQuery();
//
// Client -> remote sever
log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
try
{
boolean remote = DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false);
if (remote && p_remoteErrors > 1)
remote = CConnection.get().isAppsServerOK(true);
if (remote)
{
Server server = CConnection.get().getServer();
if (server != null)
{
ResultSet rs = server.pstmt_getRowSet (p_vo, SecurityToken.getInstance());
p_vo.clearParameters(); // re-use of result set
if (rs == null)
log.warning("ResultSet is null - " + p_vo);
else
p_remoteErrors = 0;
return rs;
}
log.log(Level.SEVERE, "AppsServer not found");
p_remoteErrors++;
}
}
catch (Exception ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++;
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
}
throw new IllegalStateException("Remote Connection - Application server not available");
} // executeQuery
/**
* Execute Query
* @param sql0 unconverted SQL to execute
* @return ResultSet or RowSet
* @throws SQLException
* @see java.sql.Statement#executeQuery(String)
*/
public ResultSet executeQuery (String sql0) throws SQLException
{
// Convert SQL
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) // local
return p_stmt.executeQuery(p_vo.getSql());
//
return executeQuery();
} // executeQuery
/**************************************************************************
* Execute Update
* @return no of updated rows
* @throws SQLException
* @see java.sql.PreparedStatement#executeUpdate()
*/
public int executeUpdate () throws SQLException
{
if (p_stmt != null)
return ((PreparedStatement)p_stmt).executeUpdate();
//
// Client -> remote sever
log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
try
{
if (DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false))
{
Server server = CConnection.get().getServer();
if (server != null)
{
int result = server.stmt_executeUpdate (p_vo, SecurityToken.getInstance());
p_vo.clearParameters(); // re-use of result set
return result;
}
log.log(Level.SEVERE, "AppsServer not found");
}
}
catch (Exception ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
}
throw new IllegalStateException("Remote Connection - Application server not available");
} // executeUpdate
/**
* Execute Update
* @param sql0 unconverted sql
* @return no of updated rows
* @throws SQLException
* @see java.sql.Statement#executeUpdate(String)
*/
public int executeUpdate (String sql0) throws SQLException
{
// Convert SQL
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) // local
return p_stmt.executeUpdate (p_vo.getSql());
return executeUpdate();
} // executeUpdate
/**
* Method execute
* @return boolean
* @throws SQLException
* @see java.sql.PreparedStatement#execute()
*/
public boolean execute () throws SQLException
{
if (p_stmt != null)
return ((PreparedStatement)p_stmt).execute();
return remote_execute();
}
/**
* Method getMetaData
* @return ResultSetMetaData
* @throws SQLException
* @see java.sql.PreparedStatement#getMetaData()
*/
public ResultSetMetaData getMetaData () throws SQLException
{
if (p_stmt != null)
return ((PreparedStatement)p_stmt).getMetaData ();
else
throw new java.lang.UnsupportedOperationException ("Method getMetaData() not yet implemented.");
}
/**
* Method getParameterMetaData
* @return ParameterMetaData
* @throws SQLException
* @see java.sql.PreparedStatement#getParameterMetaData()
*/
public ParameterMetaData getParameterMetaData () throws SQLException
{
if (p_stmt != null)
return ((PreparedStatement)p_stmt).getParameterMetaData();
throw new java.lang.UnsupportedOperationException ("Method getParameterMetaData() not yet implemented.");
}
/**
* Method addBatch
* @throws SQLException
* @see java.sql.PreparedStatement#addBatch()
*/
public void addBatch () throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).addBatch ();
else
throw new java.lang.UnsupportedOperationException ("Method addBatch() not yet implemented.");
}
/**************************************************************************
* Set Null
* @param parameterIndex index
* @param sqlType type
* @throws SQLException
*/
public void setNull (int parameterIndex, int sqlType) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setNull (parameterIndex, sqlType);
else
p_vo.setParameter(parameterIndex, new NullParameter(sqlType));
} // setNull
/**
* Method setNull
* @param parameterIndex int
* @param sqlType int
* @param typeName String
* @throws SQLException
* @see java.sql.PreparedStatement#setNull(int, int, String)
*/
public void setNull (int parameterIndex, int sqlType, String typeName) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setNull (parameterIndex, sqlType);
else
p_vo.setParameter(parameterIndex, new NullParameter(sqlType));
}
/**
* Method setBoolean
* @param parameterIndex int
* @param x boolean
* @throws SQLException
* @see java.sql.PreparedStatement#setBoolean(int, boolean)
*/
public void setBoolean (int parameterIndex, boolean x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setBoolean (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Boolean(x));
}
/**
* Method setByte
* @param parameterIndex int
* @param x byte
* @throws SQLException
* @see java.sql.PreparedStatement#setByte(int, byte)
*/
public void setByte (int parameterIndex, byte x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setByte (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Byte(x));
}
/**
* Method setShort
* @param parameterIndex int
* @param x short
* @throws SQLException
* @see java.sql.PreparedStatement#setShort(int, short)
*/
public void setShort (int parameterIndex, short x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setShort (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Short(x));
}
/**
* Method setInt
* @param parameterIndex int
* @param x int
* @throws SQLException
* @see java.sql.PreparedStatement#setInt(int, int)
*/
public void setInt (int parameterIndex, int x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setInt (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Integer(x));
}
/**
* Method setLong
* @param parameterIndex int
* @param x long
* @throws SQLException
* @see java.sql.PreparedStatement#setLong(int, long)
*/
public void setLong (int parameterIndex, long x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setLong (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Long(x));
}
/**
* Method setFloat
* @param parameterIndex int
* @param x float
* @throws SQLException
* @see java.sql.PreparedStatement#setFloat(int, float)
*/
public void setFloat (int parameterIndex, float x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setFloat (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Float(x));
}
/**
* Method setDouble
* @param parameterIndex int
* @param x double
* @throws SQLException
* @see java.sql.PreparedStatement#setDouble(int, double)
*/
public void setDouble (int parameterIndex, double x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setDouble (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, new Double(x));
}
/**
* Method setBigDecimal
* @param parameterIndex int
* @param x BigDecimal
* @throws SQLException
* @see java.sql.PreparedStatement#setBigDecimal(int, BigDecimal)
*/
public void setBigDecimal (int parameterIndex, BigDecimal x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setBigDecimal (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setString
* @param parameterIndex int
* @param x String
* @throws SQLException
* @see java.sql.PreparedStatement#setString(int, String)
*/
public void setString (int parameterIndex, String x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setString (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setBytes
* @param parameterIndex int
* @param x byte[]
* @throws SQLException
* @see java.sql.PreparedStatement#setBytes(int, byte[])
*/
public void setBytes (int parameterIndex, byte[] x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setBytes (parameterIndex, x);
else
p_vo.setParameter (parameterIndex, x);
}
/**
* Method setDate
* @param parameterIndex int
* @param x java.sql.Date
* @throws SQLException
* @see java.sql.PreparedStatement#setDate(int, java.sql.Date)
*/
public void setDate (int parameterIndex, java.sql.Date x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setDate (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setTime
* @param parameterIndex int
* @param x Time
* @throws SQLException
* @see java.sql.PreparedStatement#setTime(int, Time)
*/
public void setTime (int parameterIndex, Time x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setTime (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setTimestamp
* @param parameterIndex int
* @param x Timestamp
* @throws SQLException
* @see java.sql.PreparedStatement#setTimestamp(int, Timestamp)
*/
public void setTimestamp (int parameterIndex, Timestamp x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setTimestamp (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setAsciiStream
* @param parameterIndex int
* @param x InputStream
* @param length int
* @throws SQLException
* @see java.sql.PreparedStatement#setAsciiStream(int, InputStream, int)
*/
public void setAsciiStream (int parameterIndex, InputStream x, int length) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setAsciiStream (parameterIndex, x, length);
else
throw new java.lang.UnsupportedOperationException ("Method setAsciiStream() not yet implemented.");
}
/**
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x a <code>java.io.InputStream</code> object that contains the
* Unicode parameter value as two-byte Unicode characters
* @param length the number of bytes in the stream
* @exception SQLException if a database access error occurs
* see java.sql.PreparedStatement#setUnicodeStream(int, InputStream, int)
* @deprecated
*/
public void setUnicodeStream (int parameterIndex, InputStream x, int length) throws SQLException
{
throw new UnsupportedOperationException ("Method setUnicodeStream() not yet implemented.");
}
/**
* Method setBinaryStream
* @param parameterIndex int
* @param x InputStream
* @param length int
* @throws SQLException
* @see java.sql.PreparedStatement#setBinaryStream(int, InputStream, int)
*/
public void setBinaryStream (int parameterIndex, InputStream x, int length) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setBinaryStream (parameterIndex, x, length);
else
throw new java.lang.UnsupportedOperationException ("Method setBinaryStream() not yet implemented.");
}
/**
* Method clearParameters
* @throws SQLException
* @see java.sql.PreparedStatement#clearParameters()
*/
public void clearParameters () throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).clearParameters ();
else
p_vo.clearParameters();
}
/**
* Method setObject
* @param parameterIndex int
* @param x Object
* @param targetSqlType int
* @param scale int
* @throws SQLException
* @see java.sql.PreparedStatement#setObject(int, Object, int, int)
*/
public void setObject (int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x, targetSqlType, scale);
else
throw new java.lang.UnsupportedOperationException ("Method setObject() not yet implemented.");
}
/**
* Method setObject
* @param parameterIndex int
* @param x Object
* @param targetSqlType int
* @throws SQLException
* @see java.sql.PreparedStatement#setObject(int, Object, int)
*/
public void setObject (int parameterIndex, Object x, int targetSqlType) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x);
else
throw new java.lang.UnsupportedOperationException ("Method setObject() not yet implemented.");
}
/**
* Method setObject
* @param parameterIndex int
* @param x Object
* @throws SQLException
* @see java.sql.PreparedStatement#setObject(int, Object)
*/
public void setObject (int parameterIndex, Object x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setCharacterStream
* @param parameterIndex int
* @param reader Reader
* @param length int
* @throws SQLException
* @see java.sql.PreparedStatement#setCharacterStream(int, Reader, int)
*/
public void setCharacterStream (int parameterIndex, Reader reader, int length) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setCharacterStream (parameterIndex, reader, length);
else
throw new java.lang.UnsupportedOperationException ("Method setCharacterStream() not yet implemented.");
}
/**
* Method setRef
* @param parameterIndex int
* @param x Ref
* @throws SQLException
* @see java.sql.PreparedStatement#setRef(int, Ref)
*/
public void setRef (int parameterIndex, Ref x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setRef (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setBlob
* @param parameterIndex int
* @param x Blob
* @throws SQLException
* @see java.sql.PreparedStatement#setBlob(int, Blob)
*/
public void setBlob (int parameterIndex, Blob x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setClob
* @param parameterIndex int
* @param x Clob
* @throws SQLException
* @see java.sql.PreparedStatement#setClob(int, Clob)
*/
public void setClob (int parameterIndex, Clob x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setArray
* @param parameterIndex int
* @param x Array
* @throws SQLException
* @see java.sql.PreparedStatement#setArray(int, Array)
*/
public void setArray (int parameterIndex, Array x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* Method setDate
* @param parameterIndex int
* @param x java.sql.Date
* @param cal Calendar
* @throws SQLException
* @see java.sql.PreparedStatement#setDate(int, java.sql.Date, Calendar)
*/
public void setDate (int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setDate (parameterIndex, x, cal);
else
throw new java.lang.UnsupportedOperationException ("Method setDate() not yet implemented.");
}
/**
* Method setTime
* @param parameterIndex int
* @param x Time
* @param cal Calendar
* @throws SQLException
* @see java.sql.PreparedStatement#setTime(int, Time, Calendar)
*/
public void setTime (int parameterIndex, Time x, Calendar cal) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setTime (parameterIndex, x, cal);
else
throw new java.lang.UnsupportedOperationException ("Method setTime() not yet implemented.");
}
/**
* Method setTimestamp
* @param parameterIndex int
* @param x Timestamp
* @param cal Calendar
* @throws SQLException
* @see java.sql.PreparedStatement#setTimestamp(int, Timestamp, Calendar)
*/
public void setTimestamp (int parameterIndex, Timestamp x, Calendar cal) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setTimestamp (parameterIndex, x, cal);
else
throw new java.lang.UnsupportedOperationException ("Method setTimestamp() not yet implemented.");
}
/**
* Method setURL
* @param parameterIndex int
* @param x URL
* @throws SQLException
* @see java.sql.PreparedStatement#setURL(int, URL)
*/
public void setURL (int parameterIndex, URL x) throws SQLException
{
if (p_stmt != null)
((PreparedStatement)p_stmt).setObject (parameterIndex, x);
else
p_vo.setParameter(parameterIndex, x);
}
/**
* String representation
* @return info
*/
public String toString()
{
if (p_stmt != null)
return "CPreparedStatement[Local=" + p_stmt + "]";
return "CPreparedStatement[" + p_vo + "]";
} // toString
import java.sql.PreparedStatement;
/**
* Interface to wrap PreparedStatement
* @author Low Heng Sin
*
*/
public void fillParametersFromVO()
public interface CPreparedStatement extends CStatement, PreparedStatement
{
log.finest(p_vo.getSql());
try
{
// Set Parameters
ArrayList parameters = p_vo.getParameters();
PreparedStatement pstmt = (PreparedStatement)p_stmt;
for (int i = 0; i < parameters.size(); i++)
{
Object o = parameters.get(i);
if (o == null)
throw new IllegalArgumentException ("Local - Null Parameter #" + i);
else if (o instanceof NullParameter)
{
int type = ((NullParameter)o).getType();
pstmt.setNull(i+1, type);
log.finest("#" + (i+1) + " - Null");
}
else if (o instanceof Integer)
{
pstmt.setInt(i+1, ((Integer)o).intValue());
log.finest("#" + (i+1) + " - int=" + o);
}
else if (o instanceof String)
{
pstmt.setString(i+1, (String)o);
log.finest("#" + (i+1) + " - String=" + o);
}
else if (o instanceof Timestamp)
{
pstmt.setTimestamp(i+1, (Timestamp)o);
log.finest("#" + (i+1) + " - Timestamp=" + o);
}
else if (o instanceof BigDecimal)
{
pstmt.setBigDecimal(i+1, (BigDecimal)o);
log.finest("#" + (i+1) + " - BigDecimal=" + o);
}
else if (o instanceof java.sql.Date)
{
pstmt.setDate(i+1, (java.sql.Date)o);
log.finest("#" + (i+1) + " - Date=" + o);
}
else if (o instanceof java.util.Date)
{
pstmt.setTimestamp(i+1, new Timestamp(((java.util.Date)o).getTime()));
log.finest("#" + (i+1) + " - Date=" + o);
}
else if (o instanceof Double)
{
pstmt.setDouble(i+1, (Double)o);
log.finest("#" + (i+1) + " - Double=" + o);
}
else if (o instanceof Float)
{
pstmt.setFloat(i+1, (Float)o);
log.finest("#" + (i+1) + " - Double=" + o);
}
else
throw new java.lang.UnsupportedOperationException ("Unknown Parameter Class=" + o.getClass());
}
}
catch (SQLException ex)
{
log.log(Level.SEVERE, "fillParametersFromVO", ex);
}
} // local_getPreparedStatement
/**
* Get Result as RowSet for local system.
* Note that connection is closed when closing Oracle CachedRowSet!
* @return result as RowSet
**/
@Override
protected RowSet local_getRowSet()
{
log.finest("local_getRowSet");
RowSet rowSet = null;
ResultSet rs = null;
PreparedStatement pstmt = (PreparedStatement)p_stmt;
try
{
fillParametersFromVO();
//
rs = pstmt.executeQuery();
rowSet = CCachedRowSet.getRowSet(rs);
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
finally
{
DB.close(rs);
}
return rowSet;
} // local_getRowSet
public void setAsciiStream(int parameterIndex, java.io.InputStream x, long length)
throws SQLException
{
}
//uncomment the following methods to compile using jdk 6
//vpj-cd add support java 6
public void setBinaryStream(int parameterIndex, java.io.InputStream x,
long length) throws SQLException
{
}
public void setCharacterStream(int parameterIndex,
java.io.Reader reader,
long length) throws SQLException
{
}
public void setAsciiStream(int parameterIndex, java.io.InputStream x)
throws SQLException
{
}
public void setBinaryStream(int parameterIndex, java.io.InputStream x)
throws SQLException
{
}
public void setCharacterStream(int parameterIndex,
java.io.Reader reader) throws SQLException
{
}
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException
{
}
public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException
{
}
public void setClob(int parameterIndex, Reader reader)
throws SQLException
{
}
public void setClob(int parameterIndex, Reader reader, long length)
throws SQLException
{
}
public void setNClob(int parameterIndex, Reader reader, long length)
throws SQLException
{
}
public void setNClob(int parameterIndex, Reader reader)
throws SQLException
{
}
public void setNClob(int i,java.sql.NClob c)
throws SQLException
{
}
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException
{
}
public void setBlob(int parameterIndex, InputStream inputStream)
throws SQLException
{
}
public void setNString(int parameterIndex, String value) throws SQLException
{
}
public void setSQLXML(int parameterIndex, java.sql.SQLXML xmlObject) throws SQLException
{
}
public void setRowId(int parameterIndex, java.sql.RowId x) throws SQLException{}
} // CPreparedStatement

View File

@ -17,878 +17,46 @@
package org.compiere.util;
import java.sql.*;
import java.util.logging.*;
import javax.sql.*;
import org.adempiere.exceptions.DBException;
import org.compiere.db.*;
import org.compiere.interfaces.*;
/**
* Adempiere Statement
* Interface to wrap and extend Statement
* @author Low Heng Sin
*
* @author Jorg Janke
* @version $Id: CStatement.java,v 1.3 2006/07/30 00:54:36 jjanke Exp $
* ---
* Modifications: Handle connections properly
* Close the associated connection when the statement is closed
* Reason : Due to changes brought in the connection pooling whereby the system
* no more relies upon abandoned connections.
* @author Ashley Ramdass (Posterita)
*/
public class CStatement implements Statement
public interface CStatement extends Statement
{
protected Connection m_conn = null;
private boolean close = false;
/**
* Prepared Statement Constructor
*
* @param resultSetType - ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE
* @param resultSetConcurrency - ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE
* @param trxName transaction name or null
*/
public CStatement (int resultSetType, int resultSetConcurrency,
String trxName)
{
p_vo = new CStatementVO (resultSetType, resultSetConcurrency);
p_vo.setTrxName(trxName);
init();
} // CPreparedStatement
/**
* Initialise the statement wrapper object
*/
protected void init()
{
//Local access
if (!DB.isRemoteObjects())
{
try
{
Connection conn = null;
Trx trx = p_vo.getTrxName() == null ? null : Trx.get(p_vo.getTrxName(), true);
if (trx != null)
{
conn = trx.getConnection();
}
else
{
if (p_vo.getResultSetConcurrency() == ResultSet.CONCUR_UPDATABLE)
m_conn = DB.getConnectionRW ();
else
m_conn = DB.getConnectionRO();
conn = m_conn;
}
if (conn == null)
throw new DBException("No Connection");
p_stmt = conn.createStatement(p_vo.getResultSetType(), p_vo.getResultSetConcurrency());
return;
}
catch (SQLException e)
{
log.log(Level.SEVERE, "CStatement", e);
}
}
}
/**
* Minimum Constructor for sub classes
*/
protected CStatement()
{
super();
} // CStatement
/**
* Remote Constructor
* @param vo value object
*/
public CStatement (CStatementVO vo)
{
p_vo = vo;
init();
} // CPreparedStatement
/** Logger */
protected transient CLogger log = CLogger.getCLogger (getClass());
/** Used if local */
protected transient Statement p_stmt = null;
/** Value Object */
protected CStatementVO p_vo = null;
/** Remote Errors */
protected int p_remoteErrors = 0;
/** Object to hold remote execute result **/
protected ExecuteResult executeResult;
/**
* Execute Query
* @param sql0 unconverted SQL to execute
* @return ResultSet or RowSet
* @throws SQLException
* @see java.sql.Statement#executeQuery(String)
*/
public ResultSet executeQuery (String sql0) throws SQLException
{
// Convert SQL
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) // local
return p_stmt.executeQuery(p_vo.getSql());
// Client -> remote sever
log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
try
{
boolean remote = DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false);
if (remote && p_remoteErrors > 1)
remote = CConnection.get().isAppsServerOK(true);
if (remote)
{
Server server = CConnection.get().getServer();
if (server != null)
{
ResultSet rs = server.stmt_getRowSet (p_vo, SecurityToken.getInstance());
if (rs == null)
log.warning("ResultSet is null - " + p_vo);
else
p_remoteErrors = 0;
return rs;
}
log.log(Level.SEVERE, "AppsServer not found");
p_remoteErrors++;
}
}
catch (Exception ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++;
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
}
throw new IllegalStateException("Remote Connection - Application server not available");
} // executeQuery
/**
* Execute Update
* @param sql0 unconverted sql
* @return no of updated rows
* @throws SQLException
* @see java.sql.Statement#executeUpdate(String)
*/
public int executeUpdate (String sql0) throws SQLException
{
// Convert SQL
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null) // local
return p_stmt.executeUpdate (p_vo.getSql());
// Client -> remote sever
log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
try
{
boolean remote = DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false);
if (remote && p_remoteErrors > 1)
remote = CConnection.get().isAppsServerOK(true);
if (remote)
{
Server server = CConnection.get().getServer();
if (server != null)
{
int result = server.stmt_executeUpdate(p_vo, SecurityToken.getInstance());
p_vo.clearParameters(); // re-use of result set
return result;
}
log.log(Level.SEVERE, "AppsServer not found");
p_remoteErrors++;
}
}
catch (Exception ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++;
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
}
throw new IllegalStateException("Remote Connection - Application server not available");
} // executeUpdate
/**
* Get Sql
* @return sql
*/
public String getSql()
{
if (p_vo != null)
return p_vo.getSql();
return null;
} // getSql
public String getSql();
/**
* Get Connection
* @return connection for local - or null for remote
* @throws SQLException
* @see java.sql.Statement#getConnection()
*/
public Connection getConnection () throws SQLException
{
if (p_stmt != null)
return p_stmt.getConnection();
return null;
} // getConnection
/**
* Commit (if local)
* @throws SQLException
*/
public void commit() throws SQLException
{
Connection conn = getConnection();
if (conn != null && !conn.getAutoCommit())
{
conn.commit();
log.fine("commit");
}
} // commit
/**
* Method executeUpdate
* @param sql0 String
* @param autoGeneratedKeys int
* @return int
* @throws SQLException
* @see java.sql.Statement#executeUpdate(String, int)
*/
public int executeUpdate (String sql0, int autoGeneratedKeys) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.executeUpdate(p_vo.getSql(), autoGeneratedKeys);
throw new java.lang.UnsupportedOperationException ("Method executeUpdate() not yet implemented.");
}
/**
* Method executeUpdate
* @param sql0 String
* @param columnIndexes int[]
* @return int
* @throws SQLException
* @see java.sql.Statement#executeUpdate(String, int[])
*/
public int executeUpdate (String sql0, int[] columnIndexes) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.executeUpdate(p_vo.getSql(), columnIndexes);
throw new java.lang.UnsupportedOperationException ("Method executeUpdate() not yet implemented.");
}
/**
* Method executeUpdate
* @param sql0 String
* @param columnNames String[]
* @return int
* @throws SQLException
* @see java.sql.Statement#executeUpdate(String, String[])
*/
public int executeUpdate (String sql0, String[] columnNames) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.executeUpdate(p_vo.getSql(), columnNames);
throw new java.lang.UnsupportedOperationException ("Method executeUpdate() not yet implemented.");
}
/**
* Method execute
* @param sql0 String
* @return boolean
* @throws SQLException
* @see java.sql.Statement#execute(String)
*/
public boolean execute (String sql0) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.execute(p_vo.getSql());
return remote_execute();
}
/**
* Method execute
* @param sql0 String
* @param autoGeneratedKeys int
* @return boolean
* @throws SQLException
* @see java.sql.Statement#execute(String, int)
*/
public boolean execute (String sql0, int autoGeneratedKeys) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.execute(p_vo.getSql(), autoGeneratedKeys);
throw new java.lang.UnsupportedOperationException ("Method execute(sql, autoGeneratedKeys) not yet implemented.");
}
/**
* Method execute
* @param sql0 String
* @param columnIndexes int[]
* @return boolean
* @throws SQLException
* @see java.sql.Statement#execute(String, int[])
*/
public boolean execute (String sql0, int[] columnIndexes) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.execute(p_vo.getSql(), columnIndexes);
throw new java.lang.UnsupportedOperationException ("Method execute(sql, columnIndexes) not yet implemented.");
}
/**
* Method execute
* @param sql0 String
* @param columnNames String[]
* @return boolean
* @throws SQLException
* @see java.sql.Statement#execute(String, String[])
*/
public boolean execute (String sql0, String[] columnNames) throws SQLException
{
p_vo.setSql(DB.getDatabase().convertStatement(sql0));
if (p_stmt != null)
return p_stmt.execute(p_vo.getSql(), columnNames);
throw new java.lang.UnsupportedOperationException ("Method execute(sql, columnNames) not yet implemented.");
}
/**************************************************************************
* Get Max Field Size
* @return field size
* @throws SQLException
* @see java.sql.Statement#getMaxFieldSize()
*/
public int getMaxFieldSize () throws SQLException
{
if (p_stmt != null)
return p_stmt.getMaxFieldSize();
throw new java.lang.UnsupportedOperationException ("Method getMaxFieldSize() not yet implemented.");
}
/**
* Method setMaxFieldSize
* @param max int
* @throws SQLException
* @see java.sql.Statement#setMaxFieldSize(int)
*/
public void setMaxFieldSize (int max) throws SQLException
{
if (p_stmt != null)
p_stmt.setMaxFieldSize(max);
else
throw new java.lang.UnsupportedOperationException ("Method setMaxFieldSize() not yet implemented.");
}
/**
* Method getMaxRows
* @return int
* @throws SQLException
* @see java.sql.Statement#getMaxRows()
*/
public int getMaxRows () throws SQLException
{
if (p_stmt != null)
return p_stmt.getMaxRows();
throw new java.lang.UnsupportedOperationException ("Method getMaxRows() not yet implemented.");
}
/**
* Method setMaxRows
* @param max int
* @throws SQLException
* @see java.sql.Statement#setMaxRows(int)
*/
public void setMaxRows (int max) throws SQLException
{
if (p_stmt != null)
p_stmt.setMaxRows(max);
else
throw new java.lang.UnsupportedOperationException ("Method setMaxRows() not yet implemented.");
}
/*************************************************************************
* Add Batch
* @param sql sql
* @throws SQLException
* @see java.sql.Statement#addBatch(String)
*/
public void addBatch (String sql) throws SQLException
{
if (p_stmt != null)
p_stmt.addBatch(sql);
else
throw new java.lang.UnsupportedOperationException ("Method addBatch() not yet implemented.");
}
/**
* Method clearBatch
* @throws SQLException
* @see java.sql.Statement#clearBatch()
*/
public void clearBatch () throws SQLException
{
if (p_stmt != null)
p_stmt.clearBatch();
else
throw new java.lang.UnsupportedOperationException ("Method clearBatch() not yet implemented.");
}
/**
* Method executeBatch
* @return int[]
* @throws SQLException
* @see java.sql.Statement#executeBatch()
*/
public int[] executeBatch () throws SQLException
{
if (p_stmt != null)
return p_stmt.executeBatch();
throw new java.lang.UnsupportedOperationException ("Method executeBatch() not yet implemented.");
}
/**
* Method getMoreResults
* @param current int
* @return boolean
* @throws SQLException
* @see java.sql.Statement#getMoreResults(int)
*/
public boolean getMoreResults (int current) throws SQLException
{
if (p_stmt != null)
return p_stmt.getMoreResults(current);
throw new java.lang.UnsupportedOperationException ("Method getMoreResults() not yet implemented.");
}
/**
* Method getGeneratedKeys
* @return ResultSet
* @throws SQLException
* @see java.sql.Statement#getGeneratedKeys()
*/
public ResultSet getGeneratedKeys () throws SQLException
{
if (p_stmt != null)
return p_stmt.getGeneratedKeys();
throw new java.lang.UnsupportedOperationException ("Method getGeneratedKeys() not yet implemented.");
}
/**
* Method getResultSetHoldability
* @return int
* @throws SQLException
* @see java.sql.Statement#getResultSetHoldability()
*/
public int getResultSetHoldability () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSetHoldability();
throw new java.lang.UnsupportedOperationException ("Method getResultSetHoldability() not yet implemented.");
}
/**
* Method setEscapeProcessing
* @param enable boolean
* @throws SQLException
* @see java.sql.Statement#setEscapeProcessing(boolean)
*/
public void setEscapeProcessing (boolean enable) throws SQLException
{
if (p_stmt != null)
p_stmt.setEscapeProcessing(enable);
else
throw new java.lang.UnsupportedOperationException ("Method setEscapeProcessing() not yet implemented.");
}
/**
* Method getQueryTimeout
* @return int
* @throws SQLException
* @see java.sql.Statement#getQueryTimeout()
*/
public int getQueryTimeout () throws SQLException
{
if (p_stmt != null)
return p_stmt.getQueryTimeout();
throw new java.lang.UnsupportedOperationException ("Method getQueryTimeout() not yet implemented.");
}
/**
* Method setQueryTimeout
* @param seconds int
* @throws SQLException
* @see java.sql.Statement#setQueryTimeout(int)
*/
public void setQueryTimeout (int seconds) throws SQLException
{
if (p_stmt != null)
p_stmt.setQueryTimeout (seconds);
else
throw new java.lang.UnsupportedOperationException ("Method setQueryTimeout() not yet implemented.");
}
/**
* Method cancel
* @throws SQLException
* @see java.sql.Statement#cancel()
*/
public void cancel () throws SQLException
{
if (p_stmt != null)
p_stmt.cancel();
else
throw new java.lang.UnsupportedOperationException ("Method cancel() not yet implemented.");
}
/**
* Method getWarnings
* @return SQLWarning
* @throws SQLException
* @see java.sql.Statement#getWarnings()
*/
public SQLWarning getWarnings () throws SQLException
{
if (p_stmt != null)
return p_stmt.getWarnings();
throw new java.lang.UnsupportedOperationException ("Method getWarnings() not yet implemented.");
}
/**
* Method clearWarnings
* @throws SQLException
* @see java.sql.Statement#clearWarnings()
*/
public void clearWarnings () throws SQLException
{
if (p_stmt != null)
p_stmt.clearWarnings();
else
throw new java.lang.UnsupportedOperationException ("Method clearWarnings() not yet implemented.");
}
/**
* Method setCursorName
* @param name String
* @throws SQLException
* @see java.sql.Statement#setCursorName(String)
*/
public void setCursorName (String name) throws SQLException
{
if (p_stmt != null)
p_stmt.setCursorName(name);
else
throw new java.lang.UnsupportedOperationException ("Method setCursorName() not yet implemented.");
}
/**
* Method getResultSet
* @return ResultSet
* @throws SQLException
* @see java.sql.Statement#getResultSet()
*/
public ResultSet getResultSet () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSet();
throw new java.lang.UnsupportedOperationException ("Method getResultSet() not yet implemented.");
}
/**
* Method getUpdateCount
* @return int
* @throws SQLException
* @see java.sql.Statement#getUpdateCount()
*/
public int getUpdateCount () throws SQLException
{
if (p_stmt != null)
return p_stmt.getUpdateCount();
throw new java.lang.UnsupportedOperationException ("Method getUpdateCount() not yet implemented.");
}
/**
* Method getMoreResults
* @return boolean
* @throws SQLException
* @see java.sql.Statement#getMoreResults()
*/
public boolean getMoreResults () throws SQLException
{
if (p_stmt != null)
return p_stmt.getMoreResults();
throw new java.lang.UnsupportedOperationException ("Method getMoreResults() not yet implemented.");
}
/**
* Method setFetchDirection
* @param direction int
* @throws SQLException
* @see java.sql.Statement#setFetchDirection(int)
*/
public void setFetchDirection (int direction) throws SQLException
{
if (p_stmt != null)
p_stmt.setFetchDirection(direction);
else
throw new java.lang.UnsupportedOperationException ("Method setFetchDirection() not yet implemented.");
}
/**
* Method getFetchDirection
* @return int
* @throws SQLException
* @see java.sql.Statement#getFetchDirection()
*/
public int getFetchDirection () throws SQLException
{
if (p_stmt != null)
return p_stmt.getFetchDirection();
throw new java.lang.UnsupportedOperationException ("Method getFetchDirection() not yet implemented.");
}
/**
* Method setFetchSize
* @param rows int
* @throws SQLException
* @see java.sql.Statement#setFetchSize(int)
*/
public void setFetchSize (int rows) throws SQLException
{
if (p_stmt != null)
p_stmt.setFetchSize(rows);
else
throw new java.lang.UnsupportedOperationException ("Method setFetchSize() not yet implemented.");
}
/**
* Method getFetchSize
* @return int
* @throws SQLException
* @see java.sql.Statement#getFetchSize()
*/
public int getFetchSize () throws SQLException
{
if (p_stmt != null)
return p_stmt.getFetchSize();
throw new java.lang.UnsupportedOperationException ("Method getFetchSize() not yet implemented.");
}
/**
* Method getResultSetConcurrency
* @return int
* @throws SQLException
* @see java.sql.Statement#getResultSetConcurrency()
*/
public int getResultSetConcurrency () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSetConcurrency();
throw new java.lang.UnsupportedOperationException ("Method getResultSetConcurrency() not yet implemented.");
}
/**
* Method getResultSetType
* @return int
* @throws SQLException
* @see java.sql.Statement#getResultSetType()
*/
public int getResultSetType () throws SQLException
{
if (p_stmt != null)
return p_stmt.getResultSetType();
throw new java.lang.UnsupportedOperationException ("Method getResultSetType() not yet implemented.");
}
/**
* Close
* @throws SQLException
* @see java.sql.Statement#close()
*/
public void close () throws SQLException
{
if (close) return;
try {
if (p_stmt != null)
{
p_stmt.close();
}
} finally {
if (m_conn != null)
{
try
{
m_conn.close();
}
catch (Exception e)
{}
}
m_conn = null;
close = true;
}
} // close
/**
*
* @return boolean
* @throws SQLException
*/
protected boolean remote_execute() throws SQLException {
// Client -> remote sever
log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
try
{
if (DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false))
{
Server server = CConnection.get().getServer();
if (server != null)
{
executeResult = server.stmt_execute(p_vo, SecurityToken.getInstance());
p_vo.clearParameters(); // re-use of result set
return executeResult.isFirstResult();
}
log.log(Level.SEVERE, "AppsServer not found");
}
throw new IllegalStateException("Remote Connection - Application server not available");
}
catch (Exception ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
if (ex instanceof SQLException)
throw (SQLException)ex;
else if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
}
}
/**
* Execute Query
* @return ResultSet or RowSet
* @throws SQLException
* @see java.sql.PreparedStatement#executeQuery()
*/
public RowSet getRowSet()
{
if (p_stmt != null) // local
return local_getRowSet();
//
// Client -> remote sever
log.finest("server => " + p_vo + ", Remote=" + DB.isRemoteObjects());
try
{
boolean remote = DB.isRemoteObjects() && CConnection.get().isAppsServerOK(false);
if (remote && p_remoteErrors > 1)
remote = CConnection.get().isAppsServerOK(true);
if (remote)
{
Server server = CConnection.get().getServer();
if (server != null)
{
RowSet rs = server.stmt_getRowSet (p_vo, SecurityToken.getInstance());
p_vo.clearParameters(); // re-use of result set
if (rs == null)
log.warning("RowSet is null - " + p_vo);
else
p_remoteErrors = 0;
return rs;
}
log.log(Level.SEVERE, "AppsServer not found");
p_remoteErrors++;
}
}
catch (Exception ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
p_remoteErrors++;
if (ex instanceof RuntimeException)
throw (RuntimeException)ex;
else
throw new RuntimeException(ex);
}
throw new IllegalStateException("Remote Connection - Application server not available");
}
public RowSet getRowSet();
/*************************************************************************
* Get Result as RowSet for Remote.
* Note that close the oracle OracleCachedRowSet also close connection!
* @return result as RowSet
/**
* @return boolean
* @throws SQLException
*/
protected RowSet local_getRowSet()
{
log.finest("local_getRowSet");
RowSet rowSet = null;
ResultSet rs = null;
try
{
rs = p_stmt.executeQuery(p_vo.getSql());
rowSet = CCachedRowSet.getRowSet(rs);
}
catch (Exception ex)
{
log.log(Level.SEVERE, p_vo.toString(), ex);
throw new RuntimeException (ex);
}
finally
{
DB.close(rs);
}
return rowSet;
} // local_getRowSet
public boolean isClosed() throws SQLException;
public boolean isPoolable() throws SQLException{ return false;}
public void setPoolable(boolean a) throws SQLException{};
public boolean isClosed() throws SQLException{ return close;}
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;}
@Override
protected void finalize() throws Throwable
{
//hengsin: not the best way but it help to reduce connection and statement leakage.
if (p_stmt != null && !close)
{
this.close();
}
}
/**
*
* @throws SQLException
*/
public void commit() throws SQLException;
/**
* don't call this directly, invoke by finalizer thread
* @throws Throwable
*/
public void finalize() throws Throwable;
} // CStatement

View File

@ -17,9 +17,6 @@
package org.compiere.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* Adempiere Statement Value Object
@ -61,15 +58,8 @@ public class CStatementVO implements Serializable
private int m_resultSetConcurrency;
/** SQL Statement */
private String m_sql;
/** Parameters */
private ArrayList<Object> m_parameters = new ArrayList<Object>();
/** Transaction Name **/
private String m_trxName = null;
private Map<String, OutputParameter> m_namedOutput = new HashMap<String, OutputParameter>();
private Map<String, Object>m_namedParameters = new HashMap<String, Object>();
/**
* String representation
* @return info
@ -77,86 +67,13 @@ public class CStatementVO implements Serializable
public String toString()
{
StringBuffer sb = new StringBuffer("CStatementVO[");
sb.append(getSql());
for (int i = 0; i < m_parameters.size(); i++)
sb.append("; #").append(i+1).append("=").append(m_parameters.get(i));
sb.append("SQL="+getSql());
if (m_trxName != null)
sb.append(" TrxName=" + m_trxName);
sb.append("]");
return sb.toString();
} // toString
/**
* Set Parameter
* @param index1 1 based index
* @param element element
*/
public void setParameter (int index1, Object element)
{
if (element != null && !(element instanceof Serializable))
throw new java.lang.RuntimeException("setParameter not Serializable - " + element.getClass().toString());
int zeroIndex = index1 - 1;
if (m_parameters.size() == zeroIndex)
{
m_parameters.add(element);
}
else if (m_parameters.size() < zeroIndex)
{
while (m_parameters.size() < zeroIndex)
m_parameters.add (null); // fill with nulls
m_parameters.add(element);
}
else
m_parameters.set(zeroIndex, element);
} // setParameter
/**
* Set Parameter
* @param index1 1 based index
* @param element element
*/
public void setParameter (String name, Object element)
{
if (element != null && !(element instanceof Serializable))
throw new java.lang.RuntimeException("setParameter not Serializable - " + element.getClass().toString());
m_namedParameters.put(name, element);
} // setParametsr
/**
* Clear Parameters
*/
public void clearParameters()
{
m_parameters = new ArrayList<Object>();
m_namedParameters = new HashMap<String, Object>();
} // clearParameters
/**
* Get Parameters
* @return arraylist
*/
public ArrayList<Object> getParameters()
{
return m_parameters;
} // getParameters
/***
* get named parameters for callable statement
* @return map
*/
public Map<String, Object> getNamedParameters()
{
return m_namedParameters;
}
/**
* Get Parameter Count
* @return arraylist
*/
public int getParameterCount()
{
return m_parameters.size();
} // getParameterCount
/**
* Get SQL
* @return sql
@ -174,18 +91,6 @@ public class CStatementVO implements Serializable
*/
public void setSql(String sql)
{
if (sql != null && DB.isRemoteObjects())
{
// Handle RowID in the select part (not where clause)
int pos = sql.indexOf("ROWID");
int posTrim = sql.indexOf("TRIM(ROWID)");
int posWhere = sql.indexOf("WHERE");
if (pos != -1 && posTrim == -1 && (posWhere == -1 || pos < posWhere))
m_sql = sql.substring(0, pos) + "TRIM(ROWID)" + sql.substring(pos+5);
else
m_sql = sql;
}
else
m_sql = sql;
} // setSql
@ -238,54 +143,4 @@ public class CStatementVO implements Serializable
{
m_trxName = trxName;
}
public void registerOutParameter(String parameterName, int sqlType,
int scale)
{
OutputParameter o = new OutputParameter(sqlType, scale, null);
m_namedOutput.put(parameterName, o);
}
public void registerOutParameter(int paramIndex, int sqlType,
String typeName)
{
OutputParameter o = new OutputParameter(sqlType, -1, typeName);
this.setParameter(paramIndex, o);
}
public void registerOutParameter(int parameterIndex, int sqlType, int scale)
{
OutputParameter o = new OutputParameter(sqlType, scale, null);
this.setParameter(parameterIndex, o);
}
public void registerOutParameter(String parameterName, int sqlType)
{
OutputParameter o = new OutputParameter(sqlType, -1, null);
m_namedOutput.put(parameterName, o);
}
public void registerOutParameter(int parameterIndex, int sqlType)
{
OutputParameter o = new OutputParameter(sqlType, -1, null);
this.setParameter(parameterIndex, o);
}
public void registerOutParameter(String parameterName, int sqlType,
String typeName)
{
OutputParameter o = new OutputParameter(sqlType, -1, typeName);
m_namedOutput.put(parameterName, o);
}
public Map<String, OutputParameter> getNamedOutput()
{
return m_namedOutput;
}
/*
public boolean hasOutputParameters() {
return m_ordinalOutput.size() > 0 || m_namedOutput.size() > 0;
}*/
} // CStatementVO

View File

@ -168,24 +168,7 @@ public class CacheMgt
}
}
log.info(tableName + ": #" + counter + " (" + total + ")");
// Update Server
if (DB.isRemoteObjects())
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
int serverTotal = server.cacheReset(tableName, 0);
if (CLogMgt.isLevelFinest())
log.fine("Server => " + serverTotal);
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
}
}
return total;
} // reset

View File

@ -44,7 +44,7 @@ import org.compiere.Adempiere;
import org.compiere.db.AdempiereDatabase;
import org.compiere.db.CConnection;
import org.compiere.db.Database;
import org.compiere.db.ServerConnection;
import org.compiere.db.ProxyFactory;
import org.compiere.model.MAcctSchema;
import org.compiere.model.MLanguage;
import org.compiere.model.MRole;
@ -80,16 +80,6 @@ public final class DB
{
/** Connection Descriptor */
private static CConnection s_cc = null;
// /** Connection Cache r/o */
// private static Connection[] s_connections = null;
// /** Connection Cache Size */
// private static int s_conCacheSize = Ini.isClient() ? 1 : 3;
// /** Connection counter */
// private static int s_conCount = 0;
// /** Connection r/w */
// private static Connection s_connectionRW = null;
// /** Connection r/w for ID */
// private static Connection s_connectionID = null;
/** Logger */
private static CLogger log = CLogger.getCLogger (DB.class);
@ -262,7 +252,7 @@ public final class DB
{
s_cc = cc;
}
if ( isRemoteObjects() == false)
s_cc.setDataSource();
log.config(s_cc + " - DS=" + s_cc.isDataSource());
@ -274,10 +264,6 @@ public final class DB
* @return True if success, false otherwise
*/
public static boolean connect() {
//wan and vpn profile ( remote connection )
if (isRemoteObjects())
return CConnection.get().isAppsServerOK(true);
//direct connection
boolean success =false;
try
@ -331,10 +317,6 @@ public final class DB
//bug [1637432]
if (s_cc == null) return false;
//wan/vpn profile ( remote connection )
if (CConnection.get().isServerObjects())
return s_cc.isAppsServerOK(createNew);
//direct connection
boolean success = false;
CLogErrorBuffer eb = CLogErrorBuffer.get(false);
@ -408,10 +390,6 @@ public final class DB
*/
public static Connection createConnection (boolean autoCommit, int trxLevel)
{
//wan/vpn profile ( remote connection )
if (CConnection.get().isServerObjects())
return new ServerConnection();
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
if (CLogMgt.isLevelFinest())
{
@ -450,10 +428,6 @@ public final class DB
*/
public static Connection createConnection (boolean autoCommit, boolean readOnly, int trxLevel)
{
//wan/vpn profile ( remote connection )
if (CConnection.get().isServerObjects())
return new ServerConnection();
Connection conn = s_cc.getConnection (autoCommit, trxLevel);
//hengsin: this could be problematic as it can be reuse for readwrite activites after return to pool
@ -703,7 +677,8 @@ public final class DB
{
if (SQL == null || SQL.length() == 0)
throw new IllegalArgumentException("Required parameter missing - " + SQL);
return new CCallableStatement(ResultSet.TYPE_FORWARD_ONLY, resultSetConcurrency, SQL, trxName);
return ProxyFactory.newCCallableStatement(ResultSet.TYPE_FORWARD_ONLY, resultSetConcurrency, SQL,
trxName);
} // prepareCall
@ -765,7 +740,7 @@ public final class DB
if (sql == null || sql.length() == 0)
throw new IllegalArgumentException("No SQL");
//
return new CPreparedStatement(resultSetType, resultSetConcurrency, sql, trxName);
return ProxyFactory.newCPreparedStatement(resultSetType, resultSetConcurrency, sql, trxName);
} // prepareStatement
/**
@ -786,7 +761,7 @@ public final class DB
*/
public static Statement createStatement(int resultSetType, int resultSetConcurrency, String trxName)
{
return new CStatement(resultSetType, resultSetConcurrency, trxName);
return ProxyFactory.newCStatement(resultSetType, resultSetConcurrency, trxName);
} // createStatement
/**
@ -943,7 +918,7 @@ public final class DB
throw new IllegalArgumentException("Required parameter missing - " + sql);
//
int no = -1;
CPreparedStatement cs = new CPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call
try
@ -999,7 +974,7 @@ public final class DB
throw new IllegalArgumentException("Required parameter missing - " + sql);
//
int no = -1;
CPreparedStatement cs = new CPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
CPreparedStatement cs = ProxyFactory.newCPreparedStatement(ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_UPDATABLE, sql, trxName); // converted in call
try
@ -1147,7 +1122,7 @@ public final class DB
// RowSet.TYPE_SCROLL_INSENSITIVE, RowSet.CONCUR_READ_ONLY, sql);
CStatementVO info = new CStatementVO (RowSet.TYPE_SCROLL_INSENSITIVE, RowSet.CONCUR_READ_ONLY, DB.getDatabase().convertStatement(sql));
// End add vpj-cd e-evolution
CPreparedStatement stmt = new CPreparedStatement(info);
CPreparedStatement stmt = ProxyFactory.newCPreparedStatement(info);
retValue = stmt.getRowSet();
try {
stmt.close();
@ -1622,25 +1597,27 @@ public final class DB
} // getDocumentNo
/**
* Is this a remote client connection
* Is this a remote client connection.
*
* Deprecated, always return false.
* @return true if client and RMI or Objects on Server
* @deprecated
*/
public static boolean isRemoteObjects()
{
//avoid infinite loop
if (s_cc == null) return false;
return CConnection.get().isServerObjects();
return false;
} // isRemoteObjects
/**
* Is this a remote client connection
*
* Deprecated, always return false.
* @return true if client and RMI or Process on Server
* @deprecated
*/
public static boolean isRemoteProcess()
{
return CConnection.get().isServerProcess()
&& CConnection.get().isAppsServerOK(false);
return false;
} // isRemoteProcess

View File

@ -1,87 +0,0 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*
* Copyright (C) 2007 Low Heng Sin hengsin@avantz.com
* _____________________________________________
*****************************************************************************/
package org.compiere.util;
import java.io.Serializable;
import java.security.CodeSource;
import java.security.cert.Certificate;
import org.compiere.Adempiere;
/**
* Security token, send from client to server for security validation.
* @author Low Heng Sin
*/
public class SecurityToken implements Serializable {
private Certificate codeCertificate;
private String codeBaseHost;
private final static SecurityToken TOKEN = SecurityToken.getSecurityToken();
private SecurityToken(Certificate cert, String host)
{
codeCertificate = cert;
codeBaseHost = host;
}
/**
* Get the certificate that is use to sign the jar library.
* @return Certificate
*/
public final Certificate getCodeCertificate()
{
return codeCertificate;
}
/**
* Get the host that the code is loaded from.
* @return String
*/
public final String getCodeBaseHost()
{
return codeBaseHost;
}
/**
* Construct the application wide security token.
* @return SecurityToken
*/
private static SecurityToken getSecurityToken()
{
Certificate cert = null;
String host = null;
CodeSource cs
= SecurityToken.class.getProtectionDomain().getCodeSource();
if (cs != null)
{
Certificate[] certs = cs.getCertificates();
if (certs != null && certs.length > 0)
cert = certs[0];
}
host = Adempiere.getCodeBaseHost();
return new SecurityToken(cert, host);
}
/**
* Get the application wide security token.
* @return SecurityToken
*/
public static SecurityToken getInstance()
{
return TOKEN;
}
}

View File

@ -19,7 +19,6 @@ package org.compiere.util;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
@ -29,9 +28,6 @@ import java.util.UUID;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.db.CConnection;
import org.compiere.db.ServerConnection;
import org.compiere.interfaces.Server;
/**
* Transaction Management.
@ -125,9 +121,6 @@ public class Trx implements VetoableChangeListener
// log.info (trxName);
setTrxName (trxName);
setConnection (con);
//create remote transaction immediately
if (DB.isRemoteObjects())
this.start();
} // Trx
/** Logger */
@ -146,9 +139,6 @@ public class Trx implements VetoableChangeListener
public Connection getConnection()
{
log.log(Level.ALL, "Active=" + isActive() + ", Connection=" + m_connection);
//wan profile
if (DB.isRemoteObjects())
return new ServerConnection(getTrxName());
if (m_connection == null) // get new Connection
setConnection(DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED));
@ -208,9 +198,6 @@ public class Trx implements VetoableChangeListener
log.warning("Trx in progress " + m_trxName);
return false;
}
if (DB.isRemoteObjects()) {
startRemoteTransaction();
}
m_active = true;
m_startTime = System.currentTimeMillis();
return true;
@ -224,26 +211,6 @@ public class Trx implements VetoableChangeListener
return new Date(m_startTime);
}
private void startRemoteTransaction() {
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
server.startTransaction(getTrxName());
}
else
{
log.log(Level.WARNING, "AppsServer not found");
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
}
}
/**
* Transaction is Active
* @return true if transaction active
@ -260,12 +227,6 @@ public class Trx implements VetoableChangeListener
*/
public boolean rollback(boolean throwException) throws SQLException
{
//remote
if (DB.isRemoteObjects())
{
return remote_rollback(throwException);
}
//local
try
{
@ -310,12 +271,6 @@ public class Trx implements VetoableChangeListener
*/
public boolean rollback(Savepoint savepoint) throws SQLException
{
//remote
if (DB.isRemoteObjects())
{
return remote_rollback(savepoint);
}
//local
try
{
@ -334,97 +289,6 @@ public class Trx implements VetoableChangeListener
return false;
} // rollback
/**
* Rollback a remote transaction
* @param throwException
* @return true if success, false otherwise
* @throws SQLException
*/
private boolean remote_rollback(boolean throwException) throws SQLException
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
return server.rollback(m_trxName);
}
else
{
log.log(Level.SEVERE, "AppsServer not found");
if (throwException)
throw new SQLException("AppsServer not found");
return false;
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
if (throwException)
{
if (ex.getCause() instanceof RuntimeException)
{
RuntimeException r = (RuntimeException)ex.getCause();
if (r.getCause() instanceof SQLException)
throw (SQLException)r.getCause();
else if ( r.getCause() != null )
throw new SQLException("Application server exception - " + r.getCause().getMessage());
else
throw new SQLException("Application server exception - " + r.getMessage());
}
else
throw new SQLException("Application server exception - " + ex.getMessage());
}
return false;
}
}
/**
* Rollback a remote transaction
* @param throwException
* @return true if success, false otherwise
* @throws SQLException
*/
private boolean remote_rollback(Savepoint savepoint) throws SQLException
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{
SavepointVO sp = null;
if (savepoint instanceof SavepointVO)
sp = (SavepointVO)savepoint;
else
sp = new SavepointVO(savepoint);
return server.rollback(m_trxName, sp);
}
else
{
log.log(Level.SEVERE, "AppsServer not found");
throw new SQLException("AppsServer not found");
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
if (ex.getCause() instanceof RuntimeException)
{
RuntimeException r = (RuntimeException)ex.getCause();
if (r.getCause() instanceof SQLException)
throw (SQLException)r.getCause();
else if ( r.getCause() != null )
throw new SQLException("Application server exception - " + r.getCause().getMessage());
else
throw new SQLException("Application server exception - " + r.getMessage());
}
else
{
throw new SQLException("Application server exception - " + ex.getMessage());
}
}
}
/**
* Commit
* @param throwException if true, re-throws exception
@ -432,12 +296,6 @@ public class Trx implements VetoableChangeListener
**/
public boolean commit(boolean throwException) throws SQLException
{
//remote
if (DB.isRemoteObjects())
{
return remote_commit(throwException);
}
//local
try
{
@ -462,52 +320,6 @@ public class Trx implements VetoableChangeListener
return false;
} // commit
/**
* Commit a remote transaction
* @param throwException
* @return true if success, false otherwise
* @throws SQLException
*/
private boolean remote_commit(boolean throwException) throws SQLException
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
return server.commit(m_trxName);
}
else
{
log.log(Level.SEVERE, "AppsServer not found");
if (throwException)
throw new SQLException("AppsServer not found");
return false;
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
if (throwException)
{
if (ex.getCause() instanceof RuntimeException)
{
RuntimeException r = (RuntimeException)ex.getCause();
if (r.getCause() instanceof SQLException)
throw (SQLException)r.getCause();
else if ( r.getCause() != null )
throw new SQLException("Application server exception - " + r.getCause().getMessage());
else
throw new SQLException("Application server exception - " + r.getMessage());
}
else
throw new SQLException("Application server exception - " + ex.getMessage());
}
return false;
}
}
/**
* Commit
* @return true if success
@ -534,13 +346,6 @@ public class Trx implements VetoableChangeListener
if (s_cache != null)
s_cache.remove(getTrxName());
//remote
if (DB.isRemoteObjects()) {
closeRemoteTransaction();
m_active = false;
return true;
}
//local
if (m_connection == null)
return true;
@ -563,26 +368,6 @@ public class Trx implements VetoableChangeListener
return true;
} // close
private void closeRemoteTransaction() {
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
server.closeTransaction(getTrxName());
}
else
{
log.log(Level.WARNING, "AppsServer not found");
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
}
}
/**
*
* @param name
@ -590,12 +375,6 @@ public class Trx implements VetoableChangeListener
* @throws SQLException
*/
public Savepoint setSavepoint(String name) throws SQLException {
//remote
if (DB.isRemoteObjects())
{
return setRemoteSavepoint(name);
}
if (m_connection == null)
getConnection();
@ -609,38 +388,6 @@ public class Trx implements VetoableChangeListener
}
}
private Savepoint setRemoteSavepoint(String name) throws SQLException {
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
return server.setSavepoint(m_trxName, name);
}
else
{
log.log(Level.SEVERE, "AppsServer not found");
throw new SQLException("AppsServer not found");
}
}
catch (RemoteException ex)
{
log.log(Level.SEVERE, "AppsServer error", ex);
if (ex.getCause() instanceof RuntimeException)
{
RuntimeException r = (RuntimeException)ex.getCause();
if (r.getCause() instanceof SQLException)
throw (SQLException)r.getCause();
else if ( r.getCause() != null )
throw new SQLException("Application server exception - " + r.getCause().getMessage());
else
throw new SQLException("Application server exception - " + r.getMessage());
}
else
throw new SQLException("Application server exception - " + ex.getMessage());
}
}
/**
* String Representation
* @return info

View File

@ -873,46 +873,6 @@ public final class AEnv
log.info("Cached=" + mWindowVO);
}
}
// try to get from Server when enabled
if (mWindowVO == null && DB.isRemoteObjects() && isServerActive())
{
log.config("trying server");
try
{
s_server = CConnection.get().getServer();
if (s_server != null)
{
mWindowVO = s_server.getWindowVO(Env.getCtx(), WindowNo, AD_Window_ID, AD_Menu_ID);
log.config("from Server: success");
}
}
catch (RemoteException e)
{
log.log(Level.SEVERE, "(RE)", e);
mWindowVO = null;
s_server = null;
}
catch (Exception e)
{
Throwable tt = e.getCause();
if (tt != null && tt instanceof InvalidClassException)
log.log(Level.SEVERE, "(Server<>Client class) " + tt);
else if (tt != null && tt instanceof NotSerializableException)
log.log(Level.SEVERE, "Serialization: " + tt.getMessage(), e);
else
log.log(Level.SEVERE, "ex", e);
mWindowVO = null;
s_server = null;
}
catch (Throwable t)
{
log.log(Level.SEVERE, t.toString());
mWindowVO = null;
s_server = null;
}
if (mWindowVO != null)
s_windows.put(AD_Window_ID, mWindowVO);
} // from Server
// Create Window Model on Client
if (mWindowVO == null)

View File

@ -363,25 +363,12 @@ public final class ALogin extends CDialog
private void validateAppServer() {
m_cc.testAppsServer();
if (m_cc.getAppsServerException() != null)
{
if (m_cc.isServerObjects())
{
m_cc.getAppsServerException().printStackTrace();
JOptionPane.showMessageDialog(null,
m_cc.getAppsServerException().getLocalizedMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
private void connectToDatabase() {
//Check connection
DB.setDBTarget(m_cc);
//wan or vpn ( remote connection )
if (m_cc.isServerObjects()) return;
//direct
DB.connect();
}

View File

@ -42,7 +42,6 @@ import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Msg;
import org.compiere.util.SecurityToken;
import org.compiere.util.Trx;
import org.compiere.wf.MWFProcess;
@ -551,7 +550,7 @@ public class ProcessCtl implements Runnable
{
log.fine(AD_Workflow_ID + " - " + m_pi);
boolean started = false;
if (DB.isRemoteProcess() || m_IsServerProcess)
if (m_IsServerProcess)
{
Server server = CConnection.get().getServer();
try
@ -604,15 +603,13 @@ public class ProcessCtl implements Runnable
} catch (Exception e) {}
}
if ((DB.isRemoteProcess() || m_IsServerProcess) && !clientOnly)
if (m_IsServerProcess && !clientOnly)
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{
if (m_trx != null)
m_pi.setTransactionName(m_trx.getTrxName());
// See ServerBean
m_pi = server.process (Env.getCtx(), m_pi);
log.finest("server => " + m_pi);
@ -669,14 +666,14 @@ public class ProcessCtl implements Runnable
log.fine(ProcedureName + "(" + m_pi.getAD_PInstance_ID() + ")");
boolean started = false;
String trxName = m_trx != null ? m_trx.getTrxName() : null;
if (DB.isRemoteProcess() || m_IsServerProcess)
if (m_IsServerProcess)
{
Server server = CConnection.get().getServer();
try
{
if (server != null)
{ // See ServerBean
m_pi = server.dbProcess(m_pi, ProcedureName, trxName, SecurityToken.getInstance());
m_pi = server.dbProcess(m_pi, ProcedureName);
log.finest("server => " + m_pi);
started = true;
}

View File

@ -108,34 +108,6 @@
destdir="${build.dir}/META-INF"/>
<deploymentdescriptor destdir="${build.dir}/META-INF"/>
</ejbdoclet>
<replace file="${build.dir}/META-INF/jboss.xml">
<replacetoken><![CDATA[<local-jndi-name>adempiere/ServerLocal</local-jndi-name>]]></replacetoken>
<replacevalue><![CDATA[
<local-jndi-name>adempiere/ServerLocal</local-jndi-name>
<invoker-bindings>
<invoker>
<invoker-proxy-binding-name>
stateless-http-invoker
</invoker-proxy-binding-name>
</invoker>
</invoker-bindings>
]]></replacevalue>
</replace>
<replace file="${build.dir}/META-INF/jboss.xml">
<replacetoken><![CDATA[<local-jndi-name>adempiere/StatusLocal</local-jndi-name>]]></replacetoken>
<replacevalue><![CDATA[
<local-jndi-name>adempiere/StatusLocal</local-jndi-name>
<invoker-bindings>
<invoker>
<invoker-proxy-binding-name>
stateless-http-invoker
</invoker-proxy-binding-name>
</invoker>
</invoker-bindings>
]]></replacevalue>
</replace>
</target>

View File

@ -16,16 +16,10 @@
*****************************************************************************/
package org.compiere.session;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.cert.Certificate;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.ejb.*;
import javax.sql.*;
import org.adempiere.util.ProcessUtil;
import org.compiere.*;
@ -83,26 +77,6 @@ public class ServerBean implements SessionBean
private int m_cacheResetCount = 0;
private int m_updateLOBCount = 0;
/**
* Get and create Window Model Value Object
* @ejb.interface-method view-type="both"
*
* @param ctx Environment Properties
* @param WindowNo number of this window
* @param AD_Window_ID the internal number of the window, if not 0, AD_Menu_ID is ignored
* @param AD_Menu_ID ine internal menu number, used when AD_Window_ID is 0
* @return initialized Window Model
*/
public GridWindowVO getWindowVO (Properties ctx, int WindowNo, int AD_Window_ID, int AD_Menu_ID)
{
log.info ("getWindowVO[" + m_no + "] Window=" + AD_Window_ID);
// log.fine(ctx);
GridWindowVO vo = GridWindowVO.create(ctx, WindowNo, AD_Window_ID, AD_Menu_ID);
m_windowCount++;
return vo;
} // getWindowVO
/**
* Post Immediate
* @ejb.interface-method view-type="both"
@ -129,440 +103,6 @@ public class ServerBean implements SessionBean
return Doc.postImmediate(ass, AD_Table_ID, Record_ID, force, trxName);
} // postImmediate
/*************************************************************************
* Get Prepared Statement ResultSet
* @ejb.interface-method view-type="both"
*
* @param info Result info
* @param token Security Token
* @return RowSet
* @throws NotSerializableException
*/
public RowSet pstmt_getRowSet (CStatementVO info, SecurityToken token)
throws NotSerializableException
{
validateSecurityToken(token);
if (info.getTrxName() != null) {
if (Trx.get(info.getTrxName(), false) == null)
throw new RuntimeException("Transaction lost - " + info.getTrxName());
}
m_stmt_rowSetCount++;
CPreparedStatement pstmt = new CPreparedStatement(info);
RowSet rowset = null;
try
{
rowset = pstmt.getRowSet();
}
finally
{
try
{
pstmt.close();
}
catch (Exception ex)
{
log.log(Level.SEVERE, "Could not close prepared statement", ex);
}
}
return rowset;
} // pstmt_getRowSet
/**
* Get Statement ResultSet
* @ejb.interface-method view-type="both"
*
* @param info Result info
* @param token Security Token
* @return RowSet
*/
public RowSet stmt_getRowSet (CStatementVO info, SecurityToken token)
{
validateSecurityToken(token);
if (info.getTrxName() != null) {
if (Trx.get(info.getTrxName(), false) == null)
throw new RuntimeException("Transaction lost - " + info.getTrxName());
}
m_stmt_rowSetCount++;
CPreparedStatement stmt = new CPreparedStatement(info);
RowSet rowset = null;
try
{
rowset = stmt.getRowSet();
}
finally
{
DB.close(stmt);
}
return rowset;
} // stmt_getRowSet
/**
* Execute Update
* @ejb.interface-method view-type="both"
*
* @param info Result info
* @param token Security Token
* @return row count
*/
public int stmt_executeUpdate (CStatementVO info, SecurityToken token)
{
validateSecurityToken(token);
if (info.getTrxName() != null) {
if (Trx.get(info.getTrxName(), false) == null)
throw new RuntimeException("Transaction lost - " + info.getTrxName());
}
m_stmt_updateCount++;
CPreparedStatement stmt = null;
int retVal = -1;
try
{
stmt = new CPreparedStatement(info);
if (info.getParameterCount() > 0)
stmt.fillParametersFromVO();
retVal = stmt.executeUpdate();
}
catch (SQLException e)
{
log.log(Level.SEVERE, info.toString(), e);
throw new RuntimeException (e);
}
finally
{
DB.close(stmt);
}
return retVal;
} // stmt_executeUpdate
/**
* @ejb.interface-method view-type="both"
*
* @param info
* @param token
* @return ExecuteResult
*/
public ExecuteResult stmt_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
{
ExecuteResult result = new ExecuteResult();
if (info.getTrxName() != null)
{
if (Trx.get(info.getTrxName(), false) == null)
throw new RuntimeException("Transaction lost - " + info.getTrxName());
}
CPreparedStatement stmt = null;
try
{
stmt = new CPreparedStatement(info);
stmt.fillParametersFromVO();
boolean b = stmt.execute();
result.setFirstResult(b);
while (b)
{
ResultSet rs = stmt.getResultSet();
result.addResultSet(CCachedRowSet.getRowSet(rs));
rs.close();
b = stmt.getMoreResults();
}
result.setUpdateCount(stmt.getUpdateCount());
}
catch (SQLException e)
{
log.log(Level.SEVERE, info.toString(), e);
throw new RuntimeException (e);
}
finally
{
DB.close(stmt);
}
return result;
}
/***
* @ejb.interface-method view-type="both"
*
* @param info
* @param token
* @return CallableResult
*/
public CallableResult callable_execute( org.compiere.util.CStatementVO info,org.compiere.util.SecurityToken token )
{
CallableResult result = new CallableResult();
if (info.getTrxName() != null) {
if (Trx.get(info.getTrxName(), false) == null)
throw new RuntimeException("Transaction lost - " + info.getTrxName());
}
CCallableStatement stmt = null;
try
{
stmt = new CCallableStatement(info);
stmt.fillParametersFromVO();
boolean b = stmt.execute();
result.setFirstResult(b);
//retrieve result set and update count
while (b) {
ResultSet rs = stmt.getResultSet();
result.addResultSet(CCachedRowSet.getRowSet(rs));
rs.close();
b = stmt.getMoreResults();
}
result.setUpdateCount(stmt.getUpdateCount());
//get ordinal outputparameter value
ArrayList ordinal = info.getParameters();
Map ordinalOutput = new HashMap();
for (int i = 0; i < ordinal.size(); i++)
{
Object o = ordinal.get(i);
if (o instanceof OutputParameter)
{
OutputParameter output = (OutputParameter)o;
retrieveOutputParameter(stmt, output, i+1, null);
ordinalOutput.put((i+1), o);
}
}
result.setOrdinalOutput(ordinalOutput);
//get named output parameter value
Map named = info.getNamedOutput();
for (Iterator iter = named.entrySet().iterator(); iter.hasNext(); )
{
Map.Entry e = (Map.Entry)iter.next();
String s = (String)e.getKey();
OutputParameter output = (OutputParameter)e.getValue();
retrieveOutputParameter(stmt, output, -1, s);
}
result.setNamedOutput(named);
} catch (SQLException e) {
log.log(Level.SEVERE, info.toString(), e);
throw new RuntimeException (e);
}
finally
{
DB.close(stmt);
}
return result;
}
private void retrieveOutputParameter(CallableStatement stmt, OutputParameter o, int i, String s) throws SQLException
{
switch (o.getSqlType()) {
case Types.BIGINT:
if (i > 0)
o.setValue(stmt.getLong(i));
else
o.setValue(stmt.getLong(s));
break;
case Types.BINARY:
case Types.LONGVARBINARY:
case Types.VARBINARY:
if (i > 0)
o.setValue(stmt.getBytes(i));
else
o.setValue(stmt.getBytes(s));
break;
case Types.BOOLEAN:
if (i > 0)
o.setValue(stmt.getBoolean(i));
else
o.setValue(stmt.getBoolean(s));
break;
case Types.CHAR:
case Types.LONGVARCHAR:
case Types.VARCHAR:
if (i > 0)
o.setValue(stmt.getString(i));
else
o.setValue(stmt.getString(s));
break;
case Types.DATE:
if (i > 0)
o.setValue(stmt.getDate(i));
else
o.setValue(stmt.getDate(s));
break;
case Types.DECIMAL:
case Types.NUMERIC:
if (i > 0)
o.setValue(stmt.getBigDecimal(i));
else
o.setValue(stmt.getBigDecimal(s));
break;
case Types.DOUBLE:
if (i > 0)
o.setValue(stmt.getDouble(i));
else
o.setValue(stmt.getDouble(s));
break;
case Types.FLOAT:
case Types.REAL:
if (i > 0)
o.setValue(stmt.getFloat(i));
else
o.setValue(stmt.getFloat(s));
break;
case Types.INTEGER:
case Types.BIT:
if (i > 0)
o.setValue(stmt.getInt(i));
else
o.setValue(stmt.getInt(s));
break;
case Types.SMALLINT:
case Types.TINYINT:
if (i > 0)
o.setValue(stmt.getShort(i));
else
o.setValue(stmt.getShort(s));
break;
case Types.TIME:
if (i > 0)
o.setValue(stmt.getTime(i));
else
o.setValue(stmt.getTime(s));
break;
case Types.TIMESTAMP:
if (i > 0)
o.setValue(stmt.getTimestamp(i));
else
o.setValue(stmt.getTimestamp(s));
break;
default:
try {
if (i > 0)
o.setValue((Serializable)stmt.getObject(i));
else
o.setValue((Serializable)stmt.getObject(s));
} catch (Throwable t) {}
break;
}
}
/*************************************************************************
* Get next number for Key column = 0 is Error.
* @ejb.interface-method view-type="both"
*
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @return next no
*/
public int getNextID (int AD_Client_ID, String TableName, String trxName)
{
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
int retValue = DB.getNextID (AD_Client_ID, TableName, trxName);
log.finer("[" + m_no + "] " + TableName + " = " + retValue);
m_nextSeqCount++;
return retValue;
} // getNextID
/**
* Get Document No from table
* @ejb.interface-method view-type="both"
*
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @return document no or null
*/
public String getDocumentNo (int AD_Client_ID, String TableName, String trxName)
{
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
m_nextSeqCount++;
String dn = MSequence.getDocumentNo (AD_Client_ID, TableName, trxName);
if (dn == null) // try again
dn = MSequence.getDocumentNo (AD_Client_ID, TableName, trxName);
return dn;
} // GetDocumentNo
/**
* Get Document No from table
* @ejb.interface-method view-type="both"
*
* @param AD_Client_ID client
* @param TableName table name
* @param trxName optional Transaction Name
* @param po
* @return document no or null
*/
public String getDocumentNo (int AD_Client_ID, String TableName, String trxName, PO po)
{
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
m_nextSeqCount++;
String dn = MSequence.getDocumentNo (AD_Client_ID, TableName, trxName, po);
if (dn == null) // try again
dn = MSequence.getDocumentNo (AD_Client_ID, TableName, trxName, po);
return dn;
} // GetDocumentNo
/**
* Get Document No based on Document Type
* @ejb.interface-method view-type="both"
*
* @param C_DocType_ID document type
* @param trxName optional Transaction Name
* @return document no or null
*/
public String getDocumentNo (int C_DocType_ID, String trxName, boolean definite)
{
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
m_nextSeqCount++;
String dn = MSequence.getDocumentNo (C_DocType_ID, trxName, definite);
if (dn == null) // try again
dn = MSequence.getDocumentNo (C_DocType_ID, trxName, definite);
return dn;
} // getDocumentNo
/**
* Get Document No based on Document Type
* @ejb.interface-method view-type="both"
*
* @param C_DocType_ID document type
* @param trxName optional Transaction Name
* @param po
* @return document no or null
*/
public String getDocumentNo (int C_DocType_ID, String trxName, boolean definite, PO po)
{
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
m_nextSeqCount++;
String dn = MSequence.getDocumentNo (C_DocType_ID, trxName, definite, po);
if (dn == null) // try again
dn = MSequence.getDocumentNo (C_DocType_ID, trxName, definite, po);
return dn;
} // getDocumentNo
/*************************************************************************
* Process Remote
* @ejb.interface-method view-type="both"
@ -577,13 +117,7 @@ public class ServerBean implements SessionBean
m_processCount++;
// Start Process
String trxName = pi.getTransactionName();
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
if (trxName == null) trxName = Trx.createTrxName("ServerPrc");
String trxName = Trx.createTrxName("ServerPrc");
Trx trx = Trx.get(trxName, true);
ProcessUtil.startJavaProcess(ctx, pi, trx);
return pi;
@ -607,53 +141,6 @@ public class ServerBean implements SessionBean
return pi;
} // workflow
/**
* Online Payment from Server
* @ejb.interface-method view-type="both"
* Called from MPayment processOnline
* @param ctx Context
* @param C_Payment_ID payment
* @param C_PaymentProcessor_ID processor
* @param trxName transaction
* @return true if approved
*/
public boolean paymentOnline (Properties ctx,
int C_Payment_ID, int C_PaymentProcessor_ID, String trxName)
{
if (trxName != null) {
if (Trx.get(trxName, false) == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
MPayment payment = new MPayment (ctx, C_Payment_ID, trxName);
MPaymentProcessor mpp = new MPaymentProcessor (ctx, C_PaymentProcessor_ID, null);
log.info ("[" + m_no + "] " + payment + " - " + mpp);
m_paymentCount++;
boolean approved = false;
try
{
PaymentProcessor pp = PaymentProcessor.create(mpp, payment);
if (pp == null)
payment.setErrorMessage("No Payment Processor");
else
{
approved = pp.processCC ();
if (approved)
payment.setErrorMessage(null);
else
payment.setErrorMessage("From " + payment.getCreditCardName()
+ ": " + payment.getR_RespMsg());
}
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
payment.setErrorMessage("Payment Processor Error");
}
payment.save();
return approved;
} // paymentOnline
/**
* Create EMail from Server (Request User)
* @ejb.interface-method view-type="both"
@ -705,7 +192,7 @@ public class ServerBean implements SessionBean
/**
* Create EMail from Server (Request User)
* Execute task on server
* @ejb.interface-method view-type="both"
* @param AD_Task_ID task
* @return execution trace
@ -732,113 +219,6 @@ public class ServerBean implements SessionBean
return CacheMgt.get().reset(tableName, Record_ID);
} // cacheReset
/**
* LOB update
* @ejb.interface-method view-type="both"
*
* @param sql table name
* @param displayType display type (i.e. BLOB/CLOB)
* @param value the data
* @param trxName
* @param token Security Token
* @return true if updated
*/
public boolean updateLOB (String sql, int displayType, Object value, String trxName, SecurityToken token)
{
validateSecurityToken(token);
if (sql == null || value == null)
{
log.fine("No sql or data");
return false;
}
log.fine(sql);
Trx trx = null;
if (trxName != null && trxName.trim().length() > 0) {
trx = Trx.get(trxName, false);
if ( trx == null)
throw new RuntimeException("Transaction lost - " + trxName);
}
m_updateLOBCount++;
boolean success = true;
Connection con = trx != null ? trx.getConnection() : DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED);
PreparedStatement pstmt = null;
try
{
pstmt = con.prepareStatement(sql);
if (displayType == DisplayType.TextLong)
pstmt.setString(1, (String)value);
else
pstmt.setBytes(1, (byte[])value);
int no = pstmt.executeUpdate();
//
}
catch (Exception e)
{
log.log(Level.FINE, sql, e);
success = false;
}
finally
{
DB.close(pstmt);
pstmt = null;
}
// Success - commit local trx
if (success && trx == null)
{
try
{
con.commit();
}
catch (Exception e)
{
log.log(Level.SEVERE, "commit" , e);
success = false;
}
finally
{
try {
con.close();
} catch (SQLException e) {
}
con = null;
}
}
// Error - roll back
if (!success)
{
log.severe ("rollback");
if ( trx == null)
{
try
{
con.rollback();
}
catch (Exception ee)
{
log.log(Level.SEVERE, "rollback" , ee);
}
finally
{
try {
con.close();
} catch (SQLException e) {
}
con = null;
}
}
else
{
trx.rollback();
}
}
return success;
} // updateLOB
/**************************************************************************
* Describes the instance and its content for debugging purpose
* @ejb.interface-method view-type="both"
@ -863,177 +243,21 @@ public class ServerBean implements SessionBean
return sb.toString();
} // getStatus
/**
* Set savepoint
* @ejb.interface-method view-type="both"
* @param trxName
* @param savePointName
* @return true if success, false otherwise
*/
public SavepointVO setSavepoint(String trxName, String savePointName)
{
Trx trx = Trx.get(trxName, false);
if (trx != null)
{
try
{
Savepoint sp = null;
if (savePointName != null)
sp = trx.getConnection().setSavepoint(savePointName);
else
sp = trx.getConnection().setSavepoint();
return new SavepointVO(sp);
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
return null;
}
/**
* Start remote transaction
* @ejb.interface-method view-type="both"
* @param trxName
*/
public void startTransaction(String trxName) {
Trx trx = Trx.get(trxName, true);
trx.start();
}
/**
* Close remote transaction
* @ejb.interface-method view-type="both"
* @param trxName
*/
public void closeTransaction(String trxName) {
Trx trx = Trx.get(trxName, false);
if (trx != null)
trx.close();
}
/**
* Commit the named transaction on server
* @ejb.interface-method view-type="both"
* @param trxName
* @return true if success, false otherwise
*/
public boolean commit(String trxName)
{
boolean success = false;
Trx trx = Trx.get(trxName, false);
if (trx != null)
{
try
{
success = trx.commit(true);
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
return success;
}
/**
* Rollback the named transaction on server
* @ejb.interface-method view-type="both"
* @param trxName
* @return true if success, false otherwise
*/
public boolean rollback(String trxName)
{
boolean success = false;
Trx trx = Trx.get(trxName, false);
if (trx != null)
{
try
{
success = trx.rollback(true);
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
return success;
}
/**
* Rollback the named transaction on server
* @ejb.interface-method view-type="both"
* @param trxName
* @return true if success, false otherwise
*/
public boolean rollback(String trxName, SavepointVO savePoint)
{
boolean success = false;
Trx trx = Trx.get(trxName, false);
if (trx != null)
{
try
{
trx.getConnection().rollback(savePoint);
success = true;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
}
return success;
}
/**
* Execute db proces on server
* @ejb.interface-method view-type="both"
* @param processInfo
* @param procedureName
* @param trxName
* @return ProcessInfo
*/
public ProcessInfo dbProcess(ProcessInfo processInfo, String procedureName, String trxName, SecurityToken token)
public ProcessInfo dbProcess(ProcessInfo processInfo, String procedureName)
{
validateSecurityToken(token);
Trx trx = null;
if (trxName != null) {
trx = Trx.get(trxName, false);
if (trx == null) {
throw new RuntimeException("Transaction lost - " + trxName);
}
}
String trxName = Trx.createTrxName("ServerDBPrc");
Trx trx = Trx.get(trxName, true);
ProcessUtil.startDatabaseProcedure(processInfo, procedureName, trx);
return processInfo;
}
/**
* Load fields meta data from database
* @ejb.interface-method view-type="both"
* @param gridTabVO
* @return ArrayList
*/
public ArrayList getFields(GridTabVO gridTabVO)
{
//this will load all fields meta data from database
return gridTabVO.getFields();
}
/**
* Get table id from ad_table by table name
* @ejb.interface-method view-type="both"
* @ejb.permission unchecked="true"
* @param tableName
* @return tableName
*/
public int getTableID(String tableName)
{
return MTable.getTable_ID(tableName);
}
/**
* String Representation
* @return info
@ -1129,109 +353,13 @@ public class ServerBean implements SessionBean
System.out.println (s);
} // dumpSVUID
/**
* Validate security token from client
* @param token
*/
private void validateSecurityToken(SecurityToken token)
{
if (Ini.isServerValidateSecurityToken())
{
checkCertificate(token);
checkCodeBaseHost(token);
}
}
/**
* Verify client code is sign with the same certificate as server
* @param token
*/
private void checkCertificate(SecurityToken token)
{
Certificate certs[] =
this.getClass().getProtectionDomain().getCodeSource().getCertificates();
if (certs != null && certs.length > 0)
{
if (!certs[0].equals(token.getCodeCertificate()))
throw new RuntimeException("Client not signed or not signed with the same certificate");
}
}
/**
* Verify client code is loaded from trusted server
* @param token
*/
private void checkCodeBaseHost(SecurityToken token)
{
InetAddress host = null;
try {
host = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
}
String hostName = null;
String hostAddress = null;
if (host != null)
{
hostName = host.getHostName();
hostAddress = host.getHostAddress();
}
else
{
hostName = "localhost";
hostAddress = "127.0.0.1";
}
if (!hostName.equals(token.getCodeBaseHost()) &&
!hostAddress.equals(token.getCodeBaseHost()))
{
throw new RuntimeException("Client code not originated from server.");
}
}
/**
* Print UID of used classes.
* R2.5.1h
org.compiere.process.ProcessInfo ==
static final long serialVersionUID = -1993220053515488725L;
org.compiere.util.CStatementVO ==
static final long serialVersionUID = -3393389471515956399L;
org.compiere.model.MQuery ==
static final long serialVersionUID = 1511402030597166113L;
org.compiere.model.POInfo ==
static final long serialVersionUID = -5976719579744948419L;
org.compiere.model.POInfoColumn ==
static final long serialVersionUID = -3983585608504631958L;
org.compiere.model.MWindowVO ==
static final long serialVersionUID = 3802628212531678981L;
org.compiere.model.MTabVO ==
static final long serialVersionUID = 9160212869277319305L;
org.compiere.model.MFieldVO ==
static final long serialVersionUID = 4385061125114436797L;
org.compiere.model.MLookupInfo ==
static final long serialVersionUID = -7958664359250070233L;
*
* * @param args ignored
* @param args ignored
*/
public static void main (String[] args)
{
dumpSVUID(ProcessInfo.class);
dumpSVUID(CStatementVO.class);
dumpSVUID(MQuery.class);
dumpSVUID(POInfo.class);
dumpSVUID(POInfoColumn.class);
dumpSVUID(GridWindowVO.class);
dumpSVUID(GridTabVO.class);
dumpSVUID(GridFieldVO.class);
dumpSVUID(MLookupInfo.class);
} // main
} // ServerBean

View File

@ -364,46 +364,6 @@ public final class AEnv
log.info("Cached=" + mWindowVO);
}
}
// try to get from Server when enabled
if (mWindowVO == null && DB.isRemoteObjects() && isServerActive())
{
log.config("trying server");
try
{
s_server = CConnection.get().getServer();
if (s_server != null)
{
mWindowVO = s_server.getWindowVO(Env.getCtx(), WindowNo, AD_Window_ID, AD_Menu_ID);
log.config("from Server: success");
}
}
catch (RemoteException e)
{
log.log(Level.SEVERE, "(RE)", e);
mWindowVO = null;
s_server = null;
}
catch (Exception e)
{
Throwable tt = e.getCause();
if (tt != null && tt instanceof InvalidClassException)
log.log(Level.SEVERE, "(Server<>Client class) " + tt);
else if (tt != null && tt instanceof NotSerializableException)
log.log(Level.SEVERE, "Serialization: " + tt.getMessage(), e);
else
log.log(Level.SEVERE, "ex", e);
mWindowVO = null;
s_server = null;
}
catch (Throwable t)
{
log.log(Level.SEVERE, t.toString());
mWindowVO = null;
s_server = null;
}
if (mWindowVO != null)
s_windows.put(AD_Window_ID, mWindowVO);
} // from Server
// Create Window Model on Client
if (mWindowVO == null)