📄 client2.java~44~
字号:
package client;
import javax.rmi.PortableRemoteObject;
import prj32_1.CustomerBmpRemoteHome;
import prj32_1.CustomerBmpRemote;
/*
池里面的对象是可以被重用的(空壳,只含主键,并且主键会可能被覆盖)
1:findByXXXX方法,系统为生成一个对象放在池里面,为了节省内存考虑
2:调用get,set函数,bean都会到达准备状态
3:如果调用get,set函数时,池里面有空壳Bean,系统就根据远程接口使用空壳bean,否则生成对象
*/
public class Client2 {
public static void main(String args[]) throws Exception{
Object obj = EjbFactory.getEjbHome("CustomerBmp");
CustomerBmpRemoteHome home = (CustomerBmpRemoteHome) PortableRemoteObject.
narrow(obj, CustomerBmpRemoteHome.class);
//查询1
CustomerBmpRemote remote1 = home.findByPrimaryKey("0008");//0008载入这个Bean
//查询2
CustomerBmpRemote remote2 = home.findByPrimaryKey("0009");//0009载入这个Bean,覆盖掉0008,但是0008是被保存在context中,可以通过ejbActivate来得到
System.out.println(remote1.getAccount());//如果在get函数调用时,池中没有相应的Bean,系统就在context中寻找相应的主键,来生成Bean
System.out.println(remote2.getAccount());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -