下载本文示例代码
接着我们就必须来完成Bean实体自己了。这个实体所做的工作与session bean中的工做大致相同,但是它的继承的父类不是session bean了而是EntiyBean了。具体代码如下:package net.chinacode.addressbook;import javax.ejb.*;import java.rmi.*;public class AddressEntryBean extends Object implements EntityBean { public static int instanceCount = 0; private transient TraceHelper tracer; public AddressEntryBean() { int instanceNr = instanceCount ; tracer = new TraceHelper("AddressEntryBean[" instanceCount ']'); tracer.trace(""); } public String name; public String address; public String city; public String getName() { tracer.trace("getName", name); return name; } public String getAddress() { tracer.trace("getAddress", address); return address; } public String getCity() { tracer.trace("getCity", city); return city; } public void setAddress(String newAddress) { tracer.trace("setAddress", new String[] { newAddress }); address = newAddress; } public void setCity(String newCity) { tracer.trace("setCity", new String[] { newCity }); city = newCity; } public void ejbActivate() { tracer.trace("ejbActivate"); } public void ejbStore() { tracer.trace("ejbStore"); } public void setEntityContext(EntityContext entityContext) { tracer.trace("setEntityContext", new String[] { String.valueOf(entityContext) }); } public void unsetEntityContext() { tracer.trace("unsetEntityContext"); } public void ejbPassivate() { tracer.trace("ejbPassivate"); } public void ejbLoad() { tracer.trace("ejbLoad"); } public void ejbRemove() { tracer.trace("ejbRemove"); } public String ejbCreate(String initialName, String initialAddress, String initialCity) throws CreateException, RemoteException { tracer.trace("ejbCreate", new String[] { initialName, initialAddress, initialCity }, initialName); name = initialName; address = initialAddress; city = initialCity; return initialName; } public void ejbPostCreate(String initialName, String initialAddress, String initialCity) throws CreateException, RemoteException { tracer.trace("ejbPostCreate", new String[] { initialName, initialAddress, initialCity} ); }} 我们将这段代码存入hdsite\src\java\net\chinacode\addressbook\AddressEntryBean.java文件中。这里使用了一个tracer的TraceHelper类,它只是用来向orion终端输入调试信息的。除去了tracer的代码,哪么剩余的代码已经变的很少了,而且好像没有任何操作的地方。这就是EJB帮助我们完成了所有的事。共2页。 1 2 8 :
接着我们就必须来完成Bean实体自己了。这个实体所做的工作与session bean中的工做大致相同,但是它的继承的父类不是session bean了而是EntiyBean了。具体代码如下:package net.chinacode.addressbook;import javax.ejb.*;import java.rmi.*;public class AddressEntryBean extends Object implements EntityBean { public static int instanceCount = 0; private transient TraceHelper tracer; public AddressEntryBean() { int instanceNr = instanceCount ; tracer = new TraceHelper("AddressEntryBean[" instanceCount ']'); tracer.trace(""); } public String name; public String address; public String city; public String getName() { tracer.trace("getName", name); return name; } public String getAddress() { tracer.trace("getAddress", address); return address; } public String getCity() { tracer.trace("getCity", city); return city; } public void setAddress(String newAddress) { tracer.trace("setAddress", new String[] { newAddress }); address = newAddress; } public void setCity(String newCity) { tracer.trace("setCity", new String[] { newCity }); city = newCity; } public void ejbActivate() { tracer.trace("ejbActivate"); } public void ejbStore() { tracer.trace("ejbStore"); } public void setEntityContext(EntityContext entityContext) { tracer.trace("setEntityContext", new String[] { String.valueOf(entityContext) }); } public void unsetEntityContext() { tracer.trace("unsetEntityContext"); } public void ejbPassivate() { tracer.trace("ejbPassivate"); } public void ejbLoad() { tracer.trace("ejbLoad"); } public void ejbRemove() { tracer.trace("ejbRemove"); } public String ejbCreate(String initialName, String initialAddress, String initialCity) throws CreateException, RemoteException { tracer.trace("ejbCreate", new String[] { initialName, initialAddress, initialCity }, initialName); name = initialName; address = initialAddress; city = initialCity; return initialName; } public void ejbPostCreate(String initialName, String initialAddress, String initialCity) throws CreateException, RemoteException { tracer.trace("ejbPostCreate", new String[] { initialName, initialAddress, initialCity} ); }} 我们将这段代码存入hdsite\src\java\net\chinacode\addressbook\AddressEntryBean.java文件中。这里使用了一个tracer的TraceHelper类,它只是用来向orion终端输入调试信息的。除去了tracer的代码,哪么剩余的代码已经变的很少了,而且好像没有任何操作的地方。这就是EJB帮助我们完成了所有的事。共2页。 1 2 8 :
下载本文示例代码
完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体完善Bean实体