-
1. Re: Atomic process in Local SSB -Urgent !!!!!!!
kahzoo May 19, 2008 8:26 AM (in response to sankul123)Can you switch to stateful session bean? If yes, you can try the following:
1. Have the stateful sesion bean class implements javax.ejb.SessionSynchronization interface.
2. Make the database operation transactional, so that in the case of JTA rollback the data is not updated in the DB.
2. Within the afterCompletion() notification method, check the transaction status (which is passed as argument). If it is true (meaning transaction is committed), write your data into the file. Otherwise (meaning rollback), do not write your data into the file.
Please note that this is NOT a perfect solution, because the file operation within the afterCompltion() can fail.
You need to provide good error logging, so that the system admin can later fix the inconsistency manually.
Please check the EJB spec for details.
Hope this helps. -
2. Re: Atomic process in Local SSB -Urgent !!!!!!!
sankul123 May 19, 2008 7:58 PM (in response to sankul123)"kahzoo" wrote:
Can you switch to stateful session bean?
Yes I can , but after assessing there is not much hit on performance.
One thing that worries me with Synchronization is that Synch is on whole bean and not the methods :).
Now I need to have more than one Stateful session bean.
This is what I am planning to do , have a SSL and call the Stateful session beans which implement SessionSynchronization.
please let me know , if this is correct ...
Regards,
Sandeep Kulkarni -
3. Re: Atomic process in Local SSB -Urgent !!!!!!!
kahzoo May 19, 2008 9:06 PM (in response to sankul123)One thing that worries me with Synchronization is that Synch is on whole bean and not the methods :).
Now I need to have more than one Stateful session bean.
I'm sorry, but I'm failing to understand what your concern is.
Are you saying that you have to split the logic in two different beans?
That is not the case, and you can implement the logic in one stateful session bean(, in which you will have both your business method and the synchronization methods). You just call the business method and the synchronization methods will be automatically called at appropriate points of the CMT transaction.
If StatefulSessionBean/SessionSynchronization is not satisfactory, the other option would be to switch from CMT to BMT (bean-managed transaction).
With BMT, you need to do the transaction demarcation (begin, commit, rolback) yourself, but since your bean will know the outcome of the transaction, it can decide to write/do-not-write data in the file accordingly.
-
4. Re: Atomic process in Local SSB -Urgent !!!!!!!
sankul123 May 21, 2008 3:57 PM (in response to sankul123)Thank you Khazoo , for your support.
"kahzoo" wrote:
With BMT, you need to do the transaction demarcation (begin, commit, rolback) yourself, but since your bean will know the outcome of the transaction, it can decide to write/do-not-write data in the file accordingly.
This is how I have implemented ,
Used SSB with BMT-void myAtomicProcess(String a, String b)throws MyException{ try{ userTx.begin() //2. update file ... fileOperFlag = true //1. update db... userTx.commit() DBoperFlag = true }catch(){} finally{ if(fileOperFlag && !DBoperFlag){ //Restore the file to its original state } } }
Please let me know if you see any flaw in this.
Regards,
Sandeep Kulkarni