15_AOP入门准备_静态代理模式
2016-06-13 01:46
441 查看
【工程截图】
【PersonDao.java】
【PersonDaoImpl.java】
【Transaction.java】
【PersonDaoProxy.java】
【testPerson.java】
【运行结果】
【PersonDao.java】
package com.HigginCui.daoProxy; public interface PersonDao { public void savePerson(); }
【PersonDaoImpl.java】
package com.HigginCui.daoProxy; public class PersonDaoImpl implements PersonDao{ @Override public void savePerson() { System.out.println("save Person..."); } }
【Transaction.java】
package com.HigginCui.daoProxy; public class Transaction { public void beginTransaction(){ System.out.println("begin transaction..."); } public void commit(){ System.out.println("begin commit..."); } }
【PersonDaoProxy.java】
package com.HigginCui.daoProxy; public class PersonDaoProxy implements PersonDao{ private PersonDao personDao; private Transaction transaction; public PersonDaoProxy(PersonDao personDao,Transaction transaction){ this.personDao=personDao; this.transaction=transaction; } @Override public void savePerson() { //1.开启事务 this.transaction.beginTransaction(); //2.进行save操作 this.personDao.savePerson(); //3.事务提交 this.transaction.commit(); } }
【testPerson.java】
package com.HigginCui.test; import org.junit.Test; import com.HigginCui.daoProxy.PersonDao; import com.HigginCui.daoProxy.PersonDaoImpl; import com.HigginCui.daoProxy.PersonDaoProxy; import com.HigginCui.daoProxy.Transaction; public class testPerson { @Test public void test(){ PersonDao personDao=new PersonDaoImpl(); Transaction transaction=new Transaction(); PersonDaoProxy personDaoProxy=new PersonDaoProxy(personDao,transaction); personDaoProxy.savePerson(); } }
【运行结果】
begin transaction... save Person... begin commit...
相关文章推荐
- LVS-NAT模型实现负载均衡
- 共享库
- Centos 7 静态IP设置
- Openstack MOS 8.0安装教程
- Libxml2在linux下的使用
- linux内核升级
- harbor 中 使用 push 上传镜像时候 显示 没有认证
- tar.xz文件如何解压(linux内核源文件解压)
- vmware harbor源码编译
- Centos 6.5 防火墙配置详解
- Windows下PHP开发环境搭建教程(Apache+PHP+MySQL)
- Ubuntu下让Linux开发板通过笔记本上网
- 即将迈入大学未来想做网站运营,如何避免走弯路?
- (document).height()和$(window).height()、scrollTop
- Linux2.4打开一个文件的系统调用
- Linux2.6系统调用
- Linux2.6-4G的线性地址空间的分配与使用
- docker误区
- linux0.12-文件系统-底层通用函数
- Linux0.12-文件系统-系统调用接口