Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [ajdt-dev] Muliple db connection problem

The standard idiom for handling this requirement is to use:

 

pointcut topLevelTransactionPoint(Connection conn) :

    transactionPoint(conn) && !cflowbelow(transactionPoint(*));

 

If you advise topLevelTransactionPoint you should create only a single transaction.

 

See also our Enterprise AOP 2006 tutorial at http://www.newaspects.com/resources.php. In particular slides 24-26 deal with cflowbelow and slide 74 applies it to transactionManagement.  AspectJ in Action chapter 11 covers the topic in more depth. Eclipse AspectJ also covers the topic from what I recall, but I don’t have a copy handy to find where.


From: ajdt-dev-bounces@xxxxxxxxxxx [mailto:ajdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Dimple
Sent: Tuesday, June 27, 2006 1:49 PM
To: ajdt-dev@xxxxxxxxxxx
Subject: [ajdt-dev] Muliple db connection problem

 

Hi all,

My program works fine for me but problem is that with this solution I have multiple database connections.

 

My Aspect Looks like this…….

-------------------------------------------------------------------------------------------

public aspect Transact{

 

  pointcut transactionMethod(Connection conn)

  :call(public static * *.*.*.Store.*(..))

        && args(conn, ..);

 

        Object around(Connection conn)  :transactionMethod(conn){

                Object res = null;

                try{

                  conn = DbUtil.getDBConnection();

                  res = proceed(conn);

                  conn.commit();

                  DbUtil.releaseDBConnection(conn);

                }catch{

               //

 

              }

  return res;

}

-------------------------------------------------------------------------------------------

 

My Methods which this aspect should capture look like this…..

 

public class Store{

public void HandleFirst()

{

 …

….

Connection dbConn = null;

Results = Store.abc(dbConn, str);

..

}

 

public void abc(Connection conn, String str)

{

   //…

   callOther(conn,mystr);

}

 

 

public void HandleSecond()

{

--

….

Connection dbConn = null;

Results = Store.abc1(dbConn,str, str1);

Store.abc2(dbConn, long,str);

Store.abc(dbConn,str)

..

}

}

-------

Whenever HandleFirst method is called it connects to database before going into details of method abc.

But after connecting to database inside abc method other method callOther is called and it is also part of this class called. In callOther again database connection is established which is not correct. I want to correct my PointCut so that database connection is established only once.

In HandleSecond method we can see that multiple methods are being called and every time database connection is established.

Is there way to do it in such a way that multiple connections are not established.

Thanks,

Dimple

 

 

 


Back to the top