java - Execute code before and after method? -


In the service level, I have classes that look like this:

  class MyService {html> 

public doSomething () {telnet session session = new telnet session (); Session.open ("username", "password"); Session.execute ("blah"); Session.close (); }}

In many sections, I have to declare and open the session and then finally have to close it. I want to do something with annotation but I do not know where to start with how other people do something like this:

  class MyService {@TellnetTransaction public doSomething () {session. Execute ("blah"); }}  

Where a method is annotated with @TelnetTransaction , instant, opens and passes in the TelnetSession object .

> Thank you,

Aspects before and after What is oriented programming.

Transactions with spring aspects handles take a look at Spring AOP or Eptex.


Comments