|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
用java开发web只要两本书:一本是关于java基础的,一本是关于jsp、servlet的就可以了。开发周期长,我就来讲句题外话,现在有很多思想都是通过java来展现。这篇博客先容怎样使用Esper来处置POJO的嵌套事务。经由过程上篇博客已晓得详细的Esper引擎是怎样处置POJO对象的了,实在关于嵌套的POJO对象处置也是一样的。
起首创建POJO嵌套对象。
- importjava.util.List;
- importjava.util.Map;
- publicclassPerson{
- Stringname;
- intage;
- List<Child>children;
- Map<String,Integer>phones;
- Addressaddress;
- publicStringgetName(){
- returnname;
- }
- publicvoidsetName(Stringname){
- this.name=name;
- }
- publicintgetAge(){
- returnage;
- }
- publicvoidsetAge(intage){
- this.age=age;
- }
- publicList<Child>getChildren(){
- returnchildren;
- }
- publicvoidsetChildren(List<Child>children){
- this.children=children;
- }
- publicMap<String,Integer>getPhones(){
- returnphones;
- }
- publicvoidsetPhones(Map<String,Integer>phones){
- this.phones=phones;
- }
- publicAddressgetAddress(){
- returnaddress;
- }
- publicvoidsetAddress(Addressaddress){
- this.address=address;
- }
- }
- packagetest;
- publicclassChild{
- Stringname;
- intgender;
- publicStringgetName(){
- returnname;
- }
- publicvoidsetName(Stringname){
- this.name=name;
- }
- publicintgetGender(){
- returngender;
- }
- publicvoidsetGender(intgender){
- this.gender=gender;
- }
- }
- packagetest;
- publicclassAddress{
- Stringroad;
- Stringstreet;
- inthouseNo;
- publicStringgetRoad(){
- returnroad;
- }
- publicvoidsetRoad(Stringroad){
- this.road=road;
- }
- publicStringgetStreet(){
- returnstreet;
- }
- publicvoidsetStreet(Stringstreet){
- this.street=street;
- }
- publicintgetHouseNo(){
- returnhouseNo;
- }
- publicvoidsetHouseNo(inthouseNo){
- this.houseNo=houseNo;
- }
- }
有了这个嵌套的POJO对象以后就和上篇博客的操纵一样了,就是开启引擎,誊写响应的营业EPL语句举行事务监听。
- classAppleListenerimplementsUpdateListener{
- @Override
- publicvoidupdate(EventBean[]newEvents,EventBean[]oldEvents){
- if(newEvents!=null){
- Integerage=(Integer)newEvents[0].get("age");
- //List<Child>children=(List<Child>)newEvents[0].get("children");
- //Addressaddress=(Address)newEvents[0].get("address");
- System.out.println("ageis:"+age);
- /*for(inti=0;i<children.size();i++){
- }
- System.out.println(age);*/
- }
- }
- }
- Stringepl="selectage,children,addressfrom"+person
- +"wherename=cjq";
这时候候运转以后把持台就会输入,
详细的POJO嵌套对象进进监听代码以下:
- publicstaticvoidmain(String[]args){
- EPServiceProviderepService=EPServiceProviderManager
- .getDefaultProvider();
- EPAdministratoradmin=epService.getEPAdministrator();
- Stringperson=Person.class.getName();
- Stringepl="selectage,children,addressfrom"+person
- +"wherename=cjq";
- EPStatementstate=admin.createEPL(epl);
- state.addListener(newAppleListener());
- EPRuntimeruntime=epService.getEPRuntime();
- Personperson1=newPerson();
- Addressaddress1=newAddress();
- address1.setHouseNo(1);
- address1.setRoad("shangdi30");
- address1.setStreet("shangdi30");
- person1.setAddress(address1);
- person1.setAge(7);
- List<Child>children1=newArrayList<Child>();
- Childchild11=newChild();
- child11.setGender(1);
- child11.setName("x");
- Childchild12=newChild();
- child12.setGender(2);
- child12.setName("y");
- Childchild13=newChild();
- child13.setGender(3);
- child13.setName("z");
- children1.add(child11);
- children1.add(child12);
- children1.add(child13);
- person1.setChildren(children1);
- person1.setName("cjq");
- Map<String,Integer>phones1=newHashMap<String,Integer>();
- phones1.put("zhuzhai",1234567);
- phones1.put("jiating",2345678);
- person1.setPhones(phones1);
- runtime.sendEvent(person1);
- Personperson2=newPerson();
- Addressaddress2=newAddress();
- address2.setHouseNo(1);
- address2.setRoad("shangdi30");
- address2.setStreet("shangdi30");
- person2.setAddress(address2);
- person2.setAge(11);
- List<Child>children2=newArrayList<Child>();
- Childchild21=newChild();
- child21.setGender(1);
- child21.setName("x");
- Childchild22=newChild();
- child22.setGender(2);
- child22.setName("y");
- Childchild23=newChild();
- child23.setGender(3);
- child23.setName("z");
- children2.add(child21);
- children2.add(child22);
- children2.add(child23);
- person2.setChildren(children2);
- person2.setName("cjq");
- Map<String,Integer>phones2=newHashMap<String,Integer>();
- phones2.put("zhuzhai",1234567);
- phones2.put("jiating",2345678);
- person2.setPhones(phones2);
- runtime.sendEvent(person2);
- Personperson3=newPerson();
- Addressaddress3=newAddress();
- address3.setHouseNo(1);
- address3.setRoad("shangdi30");
- address3.setStreet("shangdi30");
- person3.setAddress(address3);
- person3.setAge(12);
- List<Child>children3=newArrayList<Child>();
- Childchild31=newChild();
- child31.setGender(1);
- child31.setName("x");
- Childchild32=newChild();
- child32.setGender(2);
- child32.setName("y");
- Childchild33=newChild();
- child33.setGender(3);
- child33.setName("z");
- children3.add(child31);
- children3.add(child32);
- children3.add(child33);
- person3.setChildren(children3);
- person3.setName("cjq2");
- Map<String,Integer>phones3=newHashMap<String,Integer>();
- phones3.put("zhuzhai",1234567);
- phones3.put("jiating",2345678);
- person3.setPhones(phones3);
- runtime.sendEvent(person3);
- }
实在到这里应当对esper处置事务加倍明晰了然了,下篇先容Map事务的esper引擎处置。
轮性能微软曾做过一个例子,就是同一个项目用java和.net网页编程来作,结果开发周期,.net网页编程是java的一半,性能java是.net网页编程的十分之一,代码量java是.net网页编程的三倍。呵呵,这说明了什么,.net网页编程的全方位比java好。但是有的人说.net网页编程不能跨平台,这个问题我和我同学曾讨论过,都认为微软的.net网页编程很可能早都可以跨平台了,但是微软为了保护他们的操作系统,所以才没有推出跨平台的.net网页编程,只是推出了跨语言的.net网页编程, |
|