Subject Re: [Firebird-Java] Desktop application -- two phase commit without application server--
If you actually want correct semantics I'd advise you to use someones
existing transaction manager rather than trying to write your own,
which is what you are doing.

Some choices....

- geronimo. This can be set up with or without transaction logging
and recovery. source under https://svn.apache.org/repos/asf/geronimo/components/txmanager/tags/geronimo-txmanager-parent-2.1.1
, available from maven central repo ASL 2.0 licence There are some
adapters for use in spring in the codehaus jencks project.

- Atomikos. I have no personal experience with this but have heard
good things. www.atomikos.com/home.html

- Jboss tm. I have no experience with this but it was formerly a
commercial product and is written by some of the transaction
management experts.

thanks
david jencks

On Sep 18, 2008, at 12:00 AM, Jan Hubeny wrote:

> Adriano dos Santos Fernandes napsal(a):
> >
> > Jan Hubeny escreveu:
> > >
> > > Could you please give me advice how to implement the two phase
> commit
> > > correctly?
> > >
> > There is an example on TestFBXAResource.testDo2XATrans() in Jaybird
> > sources...
> >
> > .
> > This example shows two one phase commits over one database. I need
> to
> > perform two phase commit over two databases.
> I think that I rather should use the skeleton from
> TestXADataSource.testXAConnection() method.
> However, I am confused by exception handling and start-> end ->
> prepare
> --> commit | rollback execution chain.
>
> 1) I don't know when to catch the SQLExceptions throwed by
> stmtA.execute() and stmtB.execute() method calls.
> If I catch them in their own try catch block, the method calls
> xaResA.prepare(xidA);
> xaResB.prepare(xidB);
> did not indicate that the whole global transaction should be rollback.
>
> If I don't modify the try finally block of stmtA.execute() and
> stmtB.execute(), and the stmt execution throws exception, then no
> changes to the both databases are committed. This is, correct.
> However I don't know whether it is correct to start the xaResA and
> xaResB and don't end them with the end -> prepare commit | rollback
> chain. This chain is skipped when the SQLexception from stmt part is
> thrown.
>
>
> 2) I am not sure how the start-> end -> prepare --> commit | rollback
> execution chain should work. I don't know how to correctly build the
> try
> catch block for each
> of start,end prepare commit rollback methods. If I have the simple
> one-phase commit then I can use following skeleton
>
> Connection conn = null;
> try {
> conn = dataSource.getConnection();
> ..... //statement execution
> conn.commit();
> } catch (SQLException ex) {
> if (conn != null) {
> try {
> conn.rollback ();
> } catch (SQLException ex) {
> }
> }
> } finally {
> if (conn != null) {
> try {
> conn.close();
> } catch (SQLException ex) {
> }
> }
> }
>
> Can you provide me some similar skeleton for the two phase commit to
> two
> databases?
>
> Thank you,
>
> Honza Hubeny
>
>
>



[Non-text portions of this message have been removed]