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