This commit is contained in:
parent
a3d3c92dc7
commit
aaf1ac619c
|
@ -0,0 +1,36 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Copyright (C) 2009 Low Heng Sin *
|
||||||
|
* Copyright (C) 2009 Idalica Corporation *
|
||||||
|
* 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.adempiere.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import org.compiere.session.ServerBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author hengsin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class EmbeddedServerProxy implements InvocationHandler {
|
||||||
|
|
||||||
|
private ServerBean server = new ServerBean();
|
||||||
|
|
||||||
|
public Object invoke(Object proxy, Method method, Object[] args)
|
||||||
|
throws Throwable {
|
||||||
|
Method m = ServerBean.class.getMethod(method.getName(), method.getParameterTypes());
|
||||||
|
return m.invoke(server, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,7 @@
|
||||||
package org.compiere.db;
|
package org.compiere.db;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Proxy;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -31,6 +32,7 @@ import javax.sql.DataSource;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import org.adempiere.as.ASFactory;
|
import org.adempiere.as.ASFactory;
|
||||||
|
import org.adempiere.util.EmbeddedServerProxy;
|
||||||
import org.compiere.Adempiere;
|
import org.compiere.Adempiere;
|
||||||
import org.compiere.interfaces.Server;
|
import org.compiere.interfaces.Server;
|
||||||
import org.compiere.interfaces.Status;
|
import org.compiere.interfaces.Status;
|
||||||
|
@ -83,6 +85,9 @@ public class CConnection implements Serializable, Cloneable
|
||||||
/** Prefer component namespace when running at server **/
|
/** Prefer component namespace when running at server **/
|
||||||
private boolean useComponentNamespace = !Ini.isClient();
|
private boolean useComponentNamespace = !Ini.isClient();
|
||||||
|
|
||||||
|
/** System property flag to embed server bean in process **/
|
||||||
|
public final static String SERVER_EMBEDDED = "org.adempiere.server.embedded";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get/Set default client/server Connection
|
* Get/Set default client/server Connection
|
||||||
* @return Connection Descriptor
|
* @return Connection Descriptor
|
||||||
|
@ -357,6 +362,9 @@ public class CConnection implements Serializable, Cloneable
|
||||||
*/
|
*/
|
||||||
public boolean isAppsServerOK (boolean tryContactAgain)
|
public boolean isAppsServerOK (boolean tryContactAgain)
|
||||||
{
|
{
|
||||||
|
if (isServerEmbedded())
|
||||||
|
return true;
|
||||||
|
|
||||||
if (Ini.isClient() && !tryContactAgain && m_queryAppsServer)
|
if (Ini.isClient() && !tryContactAgain && m_queryAppsServer)
|
||||||
return m_okApps;
|
return m_okApps;
|
||||||
|
|
||||||
|
@ -419,6 +427,13 @@ public class CConnection implements Serializable, Cloneable
|
||||||
//only cache ServerHome for client
|
//only cache ServerHome for client
|
||||||
if (m_server == null || !Ini.isClient())
|
if (m_server == null || !Ini.isClient())
|
||||||
{
|
{
|
||||||
|
if (isServerEmbedded())
|
||||||
|
{
|
||||||
|
m_server = (Server)Proxy.newProxyInstance(Server.class.getClassLoader(),
|
||||||
|
new Class[]{Server.class}, new EmbeddedServerProxy());
|
||||||
|
return m_server;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Server server = (Server)lookup (Server.JNDI_NAME);
|
Server server = (Server)lookup (Server.JNDI_NAME);
|
||||||
|
@ -1585,6 +1600,13 @@ public class CConnection implements Serializable, Cloneable
|
||||||
return "<?" + transactionIsolation + "?>";
|
return "<?" + transactionIsolation + "?>";
|
||||||
} // getTransactionIsolationInfo
|
} // getTransactionIsolationInfo
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if server is embedded in process
|
||||||
|
*/
|
||||||
|
public static boolean isServerEmbedded() {
|
||||||
|
return "true".equalsIgnoreCase(System.getProperty(SERVER_EMBEDDED));
|
||||||
|
}
|
||||||
|
|
||||||
public void setAppServerCredential(String principal, String credential)
|
public void setAppServerCredential(String principal, String credential)
|
||||||
{
|
{
|
||||||
SecurityPrincipal sp = new SecurityPrincipal();
|
SecurityPrincipal sp = new SecurityPrincipal();
|
||||||
|
|
Loading…
Reference in New Issue