📄 bpartnerbean.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.session;
import java.util.*;
import java.sql.*;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.naming.*;
import org.jnp.interfaces.NamingContext;
import java.sql.*;
import javax.sql.*;
import org.compiere.interfaces.*;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.compiere.Compiere;
import org.compiere.db.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* Compiere BPartner Bean
*
* @ejb:bean name="compiere/BPartner"
* display-name="Compiere BPartner Session Bean"
* type="Stateful"
* transaction-type="Bean"
* jndi-name="ejb/compiere/BPartner"
*
* @ejb:ejb-ref ejb-name="compiere/BPartner"
* ref-name="compiere/BPartner"
*
* @author Jorg Janke
* @version $Id: BPartnerBean.java,v 1.1 2002/12/31 20:13:03 jjanke Exp $
*/
public class BPartnerBean implements SessionBean
{
/** Context */
private SessionContext m_Context;
/** Logging */
private transient Logger log = Logger.getLogger(getClass());
/**
* Process class on Server
* @ejb:interface-method view-type="remote"
*
* @return 42
* @throws RemoteException
*/
public String process ()
throws RemoteException
{
log.debug("process");
try
{
log.info("Caller Principal = " + m_Context.getCallerPrincipal());
}
catch (Exception ex)
{
log.error("process1", ex);
}
try
{
log.info("EJB Meta IsSession = " + m_Context.getEJBHome().getEJBMetaData().isSession());
}
catch (Exception ex)
{
log.error("process2", ex);
}
try
{
log.info("EJB Meta IsStatelessSession = " + m_Context.getEJBHome().getEJBMetaData().isStatelessSession());
}
catch (Exception ex)
{
log.error("process3", ex);
}
try
{
log.info("RollbackOnly = " + m_Context.getRollbackOnly());
}
catch (Exception ex)
{
log.error("process4", ex);
}
try
{
log.info("User Trx = " + m_Context.getUserTransaction());
}
catch (Exception ex)
{
log.error("process5", ex);
}
//
return "42";
} // process
/**
* Process class on Server
* @ejb:interface-method view-type="remote"
*
* @return 42
* @throws RemoteException
*/
public String process2 ()
throws RemoteException
{
log.debug("process2");
//
try
{
InitialContext context = new InitialContext();
DataSource ds = (DataSource)context.lookup("java:OracleDS");
log.info ("OracleDS=" + ds.toString());
Connection con = ds.getConnection();
log.info("Connection AutoCommit=" + con.getAutoCommit());
log.info("Connection Catalog=" + con.getCatalog());
log.info("UserName=" + con.getMetaData().getUserName());
}
catch (Exception ex)
{
log.error("process2", ex);
}
try
{
InitialContext context = new InitialContext();
log.info("-- /");
listContext (0, (NamingEnumeration)context.list("/"));
log.info("");
log.info("-- java:");
listContext (0, (NamingEnumeration)context.list("java:"));
}
catch (Exception ex)
{
log.error("process2", ex);
}
return "42";
} // process
/**
* List Context
* @param level
* @param ne
* @throws Exception
*/
private void listContext (int level, NamingEnumeration ne) throws Exception
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < level; i++)
sb.append(" ");
String space = sb.toString();
while (ne.hasMore())
{
Object oo = ne.nextElement();
log.info(space + oo + " == " + oo.getClass());
if (oo instanceof NamingContext)
{
NamingContext nc = (NamingContext)oo;
log.info("->>1 " + nc.getNameInNamespace());
listContext(level+1, nc.list(nc.getNameInNamespace()));
log.info("->>2 " + nc.getEnvironment());
listContext(level+1, nc.list("/"));
}
}
} // listContext
/*************************************************************************/
/**
* Create the Session Bean
* @throws CreateException
* @ejb:create-method view-type="remote"
*/
public void ejbCreate() throws CreateException
{
log.setLevel(Level.ALL);
log.info("ejbCreate");
} // ejbCreate
/**
* Describes the instance and its content for debugging purpose
* @return Debugging information about the instance and its content
*/
public String toString()
{
return "BPartnerBean[" + "]";
} // toString
// -------------------------------------------------------------------------
// Framework Callbacks
// -------------------------------------------------------------------------
public void setSessionContext (SessionContext aContext) throws EJBException
{
m_Context = aContext;
}
public void ejbActivate() throws EJBException
{
if (log == null)
log = Logger.getLogger(getClass());
log.debug("ejbActivate");
}
public void ejbPassivate() throws EJBException
{
log.debug("ejbPassivate");
}
public void ejbRemove() throws EJBException
{
log.debug("ejbRemove");
}
} // ServerBean
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -