import-bot (20211) [Avatar] Offline
#1
can I capture methods have common characteristi/">
[Originally posted 9/26/03 by Anonymous]
public boolean insertTopic(Topic topic){
  Connection conn = null;
  Statement st = null;
  try{
    conn = ..;st=conn..;
  }catch(Exception e){}
  finally{...}
}
public ArrayList getAllTopics(){
Connection conn = null;Statement st = null;ResultSet rst = null;ArrayList=null;
try{conn=...;st=...;rst=st.executeQuery();arraylist=new ArrayList();
while(rst.next()){
    arrayList.add(new Topic(rst.getInt("id"),rst.getString("name")...);
}catch(Exception e) {...}
finally{...}
return arraylist;
}
public Topic getTopic(int id) {
  Connection conn = null;
  Statement st = null;ResultSet rst=null;Topic topic = null;
try{conn=...;st=...;rst=...;if(rst.next()){
 topic = new Topic(rst.getInt("id"),...);
}
}catch(Exception e) {...}finally{..}
return topic;
}


Sometimes I want to log methods interact with database,like the above three methods,all open a connection and close a connection,But I have no idea to do this.
import-bot (20211) [Avatar] Offline
#2
Re: can I capture methods have common characteristi/">
[Originally posted 9/26/03 by ramnivas]

Good question.

Currently, it isn?'t possible to implement this requirement directly in AspectJ 1.1. There is a proposed language feature that would allow capturing the join point that surrounds another join point.

Meanwhile you have two choices:
1. Advice common database access methods and use thisJoinPointEnclosingContext to obtain and log information corresponding to callers of those method.
2. Use the participant pattern (chapter 8, AspectJ in Action) if your need go beyond simple logging.

-Ramnivas
import-bot (20211) [Avatar] Offline
#3
Re: can I capture methods have common characteristi/">
[Originally posted 9/26/03 by Anonymous]

thank you for your help.