aop - Convert Inter-Type declaraton from .aj to .java with Aspect annotations -


i have situation. village.java:

public class village{      private integer vid;     private string villagename;     private string district;      public integer getvid() {         return vid;     }     public void setvid(integer vid) {         this.vid = vid;     }     public string getvillagename() {         return villagename;     }     public void setvillagename(string villagename) {         this.villagename = villagename;     }     public string getdistrict() {         return district;     }     public void setdistrict(string district) {         this.district = district;     } } 

this dao.java interface:

public interface dao<t> {     public void insert();     public void update();     public void delete(); } 

this aspect village_dao.aj (you can ignore static methods logic):

import org.apache.ibatis.session.sqlsession; import com.madx.finance.data.utils.persistence.dao; import com.madx.finance.data.utils.factory.connectionfactory;  public aspect village_dao {     declare parents: village implements dao<village>;      public void village.insert() {         village.insertvillage(this);     }      public void village.update() {         village.updatevillage(this);     }      public void village.delete() {         village.deletevillage(this.getvid());     }      public village village.getdata() {         return village.getdatavillage(this.getvid());     }      public static void village.insertvillage(village village) {         sqlsession session = connectionfactory.getsqlsessionfactory().opensession();         villagemapper mapper = session.getmapper(villagemapper.class);         mapper.insertvillage(village);         session.commit();         session.close();     }      public static void village.updatevillage(village village) {         sqlsession session = connectionfactory.getsqlsessionfactory().opensession();         villagemapper mapper = session.getmapper(villagemapper.class);         mapper.updatevillage(village);         session.commit();         session.close();     }      public static void village.deletevillage(integer id) {         sqlsession session = connectionfactory.getsqlsessionfactory().opensession();         villagemapper mapper = session.getmapper(villagemapper.class);         mapper.deletevillage(id);         session.commit();         session.close();     }      public static village village.getdatavillage(integer id) {         sqlsession session = connectionfactory.getsqlsessionfactory().opensession();         villagemapper mapper = session.getmapper(villagemapper.class);         village village = mapper.selectvillage(id);         session.close();         return village;     } } 

i'm trying without success convert village_dao.aj annotated version village_dao_java.java. managed make class implements dao can't manage write methods (insert, update e delete separately in file village_dao_java.java).

this version (still not complete) of village_dao_java.java (i read link couldn't work case):

import org.aspectj.lang.annotation.aspect; import org.aspectj.lang.annotation.declareparents;  import com.madx.finance.data.utils.persistence.dao;  @aspect public class village_dao_java {      @declareparents("com.madx.demo.village")     private dao<village> implementedinterface; } 

what want not possible @aspectj style, need use more powerful native syntax. (why want switch anyway?)

the reason behind java compiler can convert @declareparents form in village subclass of whatever interface implementation define in aspect, example this:

@aspect public class village_dao_java {     public static class villagedao implements dao<village> {         @override         public void insert() {             village.insertvillage(this);         }          @override         public void update() {             village.updatevillage(this);         }          @override         public void delete() {             village.deletevillage(this.getvid());         }          public village getdata() {             return getdatavillage(this.getvid());         }      }      @declareparents(         value = "de.scrum_master.app.village",         defaultimpl = villagedao.class     )     private dao<village> villagedao; } 

but approach has several problems:

  • the methods try access static methods future villagedao subclass village, cannot declare static methods in villagedao have declare them in village directly.
  • if instead declare them directly in villagedao call them e.g. via villagedao.insertvillage(this), signature public static void insertvillage(village village) no longer fit because this villagedao, not own subclass village.
  • for similar reasons cannot call this.getvid() because this villagedao , not village, getter method has fixed signature in original village class.

and forth. java compiler not powerful enough aspectj compiler does: weave code right original class files.

ergo: please stick native syntax. not more powerful imo more readable. never understood why many people try coax powerful aspectj poor alternative @aspectj syntax. somehow seem believe tey gain pure java syntax. disagree. degradation of technical means , bad syntax never meant used full-fledged aop.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -