news aggregator

TomEE/OpenEJB + PostgreSQL XA DataSources

Allan Saddi's projects blog - Sat, 2012-05-26 16:37
TomEE 1.0 released recently and due to that, I decided to revisit the land of EJBs once again. (Especially what is known as "EJB 3.1 Lite.") I've been a heavy Spring user both with work projects and personal projects, so EJBs have never really been on my radar. And for whatever reason, I always gravitate toward the transaction manager/database side whenever I try out a new container.

Anyway, setting up TomEE/OpenEJB with local transactions is pretty straightforward. What's problematic (and doesn't seem to be well documented at all) is setting up XA datasources.

There are two major problems:
  1. The XADataSource implementation must also implement DataSource. I looked at 3 drivers: PostgreSQL, H2, and briefly, Oracle 11g. PostgreSQL seems to be the only one whose XADataSource does not implement DataSource.

  2. DBCP-356 and DBCP-358. I'm not sure if they're bugs, but they're certainly oddities.
First the easy case, H2, which isn't plagued by either problem. What really isn't evident is that to set up an XA datasource in TomEE/OpenEJB, you must:
  1. Set JdbcDriver to the XADataSource implementation.

  2. Use Definition to set properties for that XADataSource rather than the usual (JdbcUrl, etc.) However, use Username and Password as normal.
So a minimal XA H2 datasource definition would look something like:

<Resource id="myDataSource" type="DataSource">
  JtaManaged true
  JdbcDriver org.h2.jdbcx.JdbcDataSource
  Definition url=jdbc:h2:MyDataBase
  UserName foobar
  Password hunter2
</Resource>

Fairly easy. And to set more properties in Definition, simply use semi-colons to delimit multiple properties.

Now, to use PostgreSQL with TomEE/OpenEJB you have to first create a dummy class that extends PGXADataSource and implements javax.sql.DataSource. If you're using JDK 6/JDBC4, you will most likely have to implement a few more methods as well. For now, it seems ok if the methods simply throw UnsupportedOperationExceptions or similar, since the PostgreSQL JDBC4 classes do the same.

public class MyPGXADataSource extends PGXADataSource implements DataSource {
    public boolean isWrapperFor(Class<?> arg0) throws SQLException {
       throw new UnsupportedOperationException();
    }
    public <T> T unwrap(Class<T> arg0) throws SQLException {
       throw new UnsupportedOperationException();
    }
}

To solve problem #2, you can either use the PostgreSQL 8.4 driver (which doesn't have the problematic interaction with DBCP), or patch up DBCP 1.4 with the patch I attached to DBCP-356. Once that's done, the PostgreSQL XA datasource definition is pretty simple:

<Resource id="myDataSource" type="DataSource">
  JtaManaged true
  JdbcDriver package.to.MyPGXADataSource
  Definition DatabaseName=foodb;ServerName=mydbhost
  UserName foobar
  Password hunter2
</Resource>

The only caveat is that PGXADataSource does not take a URL property, so you will have to pass the database name, server name, port, etc. as separate properties in Definition.

My Life Inside Two Seabags and a Backpack.

Kevin Saddi's blog - Mon, 2008-06-02 05:05

...For the time being at least. Training concluded early May and I took about ten days leave back to Santa Maria to hang out with the folks, my brother, and the dog. Yet again, there just wasn't enough time and timing itself restricted me from seeing some faces that I was eager to catch up with but there's always next time. Drove back to San Diego to check into Naval Base San Diego (you know, the real Navy) and got a room with TPU (Transient Personnel Unit). This is where the Sailors separating or in limbo are assigned to before they get flown to their ships (such as my case) or report to their ships once they pull into the pier.

Didn't really have much trouble figuring out my needs and wants when it came to packing (I had acquired about a year and half of "stuff" from staying at the training base) but I've pretty much narrowed it down to literally, two seabags and a backpack. As some of you may not know, the FNG bachelor Sailor will be required to live aboard their ship for the first couple months. When space is available and the command permits it, they will then be able to move into a barracks on base.

I had no choice but to drive my truck back to Santa Maria because all the on-base vehicle storage was taken (the Reagan Battlegroup recently deployed a couple days before I checked in). Plus when it costs me the price of a new Xbox 360 title to fill it up, I figured this was a positive move. So I traded in my four wheels for two - haven't rode a bike since college! This transition to a lightweight lifestyle is going to be interesting.

Eight days until I hop on a commercial plane and fly out to Panama City. I am stoked. A little nervous about the whole real Navy thing but excited at the same time. And to see South America and its many offerings. Hooyah.

What do you see?

Allan Saddi's blog - Tue, 2007-10-02 22:33

It's been quite a while since I've blogged. So many things have happened, and at the same time, nothing has changed. Such is life. Though I also really haven't felt like sharing my thoughts and feelings for quite some time now. Just the way things have been for me.

Anyhow, I really can't stop thinking about the movie Sunshine... and that's probably because I've been listening to the soundtrack non-stop for the past few days now. With the movie in limited release, I guess it was a stroke of luck that I found that the Palm Theatre in SLO was showing it. (And thanks to Steve for letting me know!) Anyway, after a few abortive attempts to watch it with a certain special friend, I nearly gave up. Until Steve let me know that he was going to watch it again, with a few friends from high school. I met up with them and really enjoyed the movie. And it was also good to see everyone again. Anyway, that was quite a while ago, maybe back in August.

Critics will pan the movie because of its supposed bad science, such as: the premature death of the Sun, vacuum exposure effects, the presence of artificial gravity, and the size of the stellar bomb vs. the Sun. I'm normally a stickler for hard science in science fiction, but I found the movie plausible enough to enjoy. And in fact, I found the depictions of science to be reasonable. It was never mentioned in-movie, but the reason for the premature death of the Sun was due to it capturing a Q-ball... or dark matter. I thought this was a neat explanation because it reminded me of Baxter's Xeelee Sequence, where dark matter beings — the Photino Birds — would take up residence in stars, causing them to age and darken prematurely.

Artificial gravity I just chalked up to technology. Hey, 50 years in the future is quite a bit of time for technological progress, especially at the exponential or near-exponential rate of advance we have going. Same with the bomb. It was obviously not nuclear, despite being constructed of every last bit of fissile material on the Earth. So who knows what principles it operated on. All it takes is a little suspension of disbelief...

Anyway, what fascinated me was the people. Here we have a crew of 8, all alone in space, with the monumental task of saving all life on Earth from extinction. How do they cope with the pressure? Well, of course some do and some don't. A few pick up obsessive hobbies, like sunbathing, reading the same book over and over again, or constantly listening to solar winds. And of course, the movie is about the second attempt. Obviously, the crew of the first ship failed... what lead to their failure? Was it technological? Or some human element?

But what also hooked me was the soundtrack, composed by John Murphy and Underworld. The music that played during the first climactic scene (with Captain Kaneda on the solar shield) left my jaw on the floor when the scene concluded. It was just so intense and so epic. (It's entitled "What do you see?")

Anyway, ending this entry with a quote from Jeffrey Sinclair of Babylon 5 seems apt:


“Ask ten different scientists about the environment, population control, genetics, and you'll get ten different answers, but there's one thing every scientist on the planet agrees on. Whether it happens in a hundred years or a thousand years or a million years, eventually our sun will grow cold and go out. When that happens, it won't just take us. It'll take Marilyn Monroe, and Lao-Tzu, and Einstein, and Morobuto, and Buddy Holly, and Aristophanes... and all of this... all of this... was for nothing. Unless we go to the stars.”