2.本地HOME接口的实现:
为了提高EJB的性能,如果是在同一个虚拟机中,EJB可以通过本地接口来调用方法,以提高运行速度。实现代码如下:
/*
* Generated by XDoclet - Do not edit!
*/
package com.ejb.sessionbean;
/**
* Home interface for PersonManager.
*/
public interface PersonManagerHome
extends javax.ejb.EJBHome
{
public static final String COMP_NAME="java:comp/env/ejb/PersonManager";
public static final String JNDI_NAME="PersonManagerHomeRemote";
public com.ejb.sessionbean.PersonManager create()
throws javax.ejb.CreateException,java.rmi.RemoteException;
}
PersonManagerHome接口只有一个方法,create方法,它与会话bean的具体实现类中ejbCeate方法一一对应。
3.具体实现类:
PersonManagerBean是会话BEAN的具体实现类,必须实现SessionBean接口,而且同时实现了在远程接口中定义的相关业务逻辑方法,具体实现代码如下
package com.ejb.sessionbean;
import java.rmi.RemoteException;
import java.util.*;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.pojo.*;
/**
* @ejb.bean description = "PersonManagerBean" display-name =
* "PersonManagerBean" jndi-name="PersonManagerHomeRemote"
* name="PersonManager" type="Stateless" view-type="remote"
* transaction-type="Container"
* @jboss-net.web-service urn = "PersonManagerService" expose-all = "true"
*/
public class PersonManagerBean
implements SessionBean
{
private SessionContext ctx;
private static Map database;
/**
* @ejb.create-method
*
*/
public void ejbCreate()
{
}
public void setSessionContext( SessionContext ctx ) throws EJBException,
RemoteException
{
// TODO 自动生成方法存根
}
public void ejbRemove() throws EJBException, RemoteException
{
// TODO 自动生成方法存根
}
public void ejbActivate() throws EJBException, RemoteException
{
// TODO 自动生成方法存根
}
public void ejbPassivate() throws EJBException, RemoteException
{
// TODO 自动生成方法存根
}
/**
* @ejb.interface-method view-type = "remote"
* @param name
* @return
*/
public Person getPersonByName( String name )
{
if (database != null)
{
return (Person) database.get(name);
}
return null;
}
/**
* @ejb.interface-method view-type = "remote"
* @param person
*/
public void storePerson( Person person )
{
if (database == null)
{
database = new HashMap();
}
database.put(person.getName(), person);
}
/**
* @ejb.interface-method view-type = "remote"
* @param name
*/
public void deletePerson( String name )
{
if (database != null)
{
database.remove(name);
}
}
}
