I decided to (temporarily) convert my skeleton webapp to use JTA. Being Spring-based, it was a simple matter of editing the application context config... or so I thought. Apparently, for distributed transaction support, it has to be supported by not only the application and container, but also the connector and database driver.
Doing some research, I found out I needed an XA compliant connector... which are apparently vendor-specific. I searched
tranql's site and surprisingly, there is no PostgreSQL support. "Why is this?" I asked and the answer (through Googling) turned out to be because PostgreSQL itself doesn't have XA Resource support... let alone two phase commit.
Or so I thought. All the various blogs/articles stating the fact were apparently out of date. PostgreSQL has had 2PC support
for over a year. And the JDBC driver has also supported XA
for some time.
So great... I just needed a PostgreSQL-specific tranql connector. (Again, very odd that one doesn't already exist.) After a minor struggle searching for tranql's source (note that the CVS info at their site is outdated... I used Codehaus'
FishEye repository browser instead), I managed to see what was involved in creating a vendor-specific connector.
Very little, it seemed. So using the Derby connector as a starting point, I went ahead and created PostgreSQL tranql connectors, in both local and XA flavors. It was so utterly simple, I don't know why it wasn't done before. (And I've googled around...) I don't know if I should even bother contributing it back? It was literally a matter of changing a few package/class names and deleting some unused setters/getters...
Anyhow, the tranql connectors for PostgreSQL can be found
here for now. You'll need to use a PostgreSQL JDBC driver that supports XA (like 8.1-407).
As far as I know, it works (but that doesn't really say much). Someday I'll have to create a simple app that uses two or more datasources and play around with it more.
Edit: Maybe I spoke too soon. For whatever reason, rollbacks are still committing. The XA connector looks to be written ok, and after enabling debug logging, I see rollback being called on the XAResource... so maybe it's a driver problem?
Edit2: Found it. Looks like tranql commits by calling setAutoCommit(true). The connection then becomes stuck with autoCommit on. (Which is odd, since beginning a transaction sets it to false... maybe the Geronimo transaction manager doesn't normally do a begin?) I fixed it by patching the PostgreSQL driver, namely the XAConnection implementation. Seemed the cleanest approach for now. Will have to investigate the begin issue another time...