The Source for Java Technology Collaboration
User: Password:



David Van Couvering 's Blog

April 2007 Archives


JPA and Rollbacks - Not Pretty

Posted by davidvc on April 27, 2007 at 05:03 PM | Permalink | Comments (16)

We all want our interactions with the database to be successful. And most demos and code samples have everything going hunky dory. But what happens if they're not? What if you or the database needs to roll back the transaction? With JPA, if you're not careful, things can get pretty ugly.

Here it is from the horse's mouth:

3.3.2 Transaction Rollback

For both transaction-scoped and extended persistence contexts, transaction rollback causes all pre-existing managed instances and removed instances to become detached. ... Transaction rollback typically causes the persistence context to be in an inconsistent state at the point of rollback. In particular, the state of version attributes and generated state (e.g., generated primary keys) may be inconsistent. Instances that were formerly managed by the persistence context (including new instances that were made persistent in that transaction) may therefore not be reusable in the same manner as other detached objects—for example, they may fail when passed to the merge operation.

So, what the spec says is that on rollback basically you are SOL -- your objects are now detached and broken. A JPA rollback is like a tornado that sweeps through your JPA house and now everything is twisted and ruined, and you have to try and clean it all up.

As someone coming from a database background, where rollbacks are almost synonymous with consistency, this was a bit of a shocker.

Continue Reading...



REST as State Machine - Duh!

Posted by davidvc on April 27, 2007 at 10:19 AM | Permalink | Comments (0)

Years back I took a three week training on OO modeling using the Shlaer-Mellor method, which has now been pretty much subsumed by UML. One thing I spent a lot of time doing was designing the behavior of a system using state diagrams.

Fast forward to 2007, and I'm trying to get my head around REST. I like it, but I don't know why sometimes -- it seems too simplistic to capture rich application semantics.

It looks like I was not the only one. Tim Ewald shared his "aha" moment, and it clicked for me too.

Tim says Here's what I came to understand. Every communication protocol has a state machine. For some protocols they are very simple, for others they are more complex. When you implement a protocol via RPC, you build methods that modify the state of the communication. That state is maintained as a black box at the endpoint.

...

The essence of REST is to make the states of the protocol explicit and addressible by URIs. The current state of the protocol state machine is represented by the URI you just operated on and the state representation you retrieved. You change state by operating on the URI of the state you're moving to, making that your new state. A state's representation includes the links (arcs in the graph) to the other states that you can move to from the current state. This is exactly how browser based apps work, and there is no reason that your app's protocol can't work that way too.

It's not necessarily easy to think this way when defining an application protocol for those of us that aren't used to it, but the benefits are significant.

In a past incarnation I was responsible for architecting a clustering solution for Sun's app server, such that session state is available to every instance in the cluster. Doing this is not easy, and it's not cheap (in terms of performance). With this experience behind me, I find REST very compelling. It defines a way for you to build simple, flexible, scalable apps using HTTP as it was meant to be used, rather than shoving RCP and embedded session state onto it, and this means your web infrastructure can really take advantage of the stateless nature of HTTP to provide high scalability and flexibility.

Of course, I have yet to build a REST-based application, and the devil is in the details. Those of you who are out there in the wild trying to build this stuff -- what is your experience?

The Mystery of the Cursor Arrow Revealed

Posted by davidvc on April 27, 2007 at 10:02 AM | Permalink | Comments (1)

Now we know what is going on when we move our mouse arrow around. A genius Japanese computer programmer has built a magnifying glass web page so we can see for ourselves. Poor fellas...

http://www.1-click.jp

Great blog about JPA SELECTs

Posted by davidvc on April 25, 2007 at 03:42 PM | Permalink | Comments (0)

JPA is generally easier than JDBC, but that doesn't mean it doesn't have "interesting" details and complexity. Michael Bouschen provides some very useful information in the area of SELECT statements and their return types.

Thanks, Michael!

Mapping Entities to REST - Learning from History

Posted by davidvc on April 23, 2007 at 11:56 AM | Permalink | Comments (10)

I'm working with a team that is working on providing tooling in NetBeans that lets you map database entities to REST resources. At first blush it looks like a very nice, simple mapping. REST is about resources. On each resource you can perform basic CRUD (Create, Read, Update, Delete) operations using the basic HTTP verbs POST, GET, PUT and DELETE.

So it seems pretty obvious: map each table in your schema to a REST resource. POST inserts a record into the table. GET with query parameters allows you to perform various types of SELECT operations. PUT does a SQL UPDATE, and DELETE does a SQL DELETE. Very nice, and now you can expose your data to web "mashup" applications.

There are some details on how you handle large data sets using pagination, how you identify individual records, how you handle conflicts, and so on. But this can be worked out, and the Atom Publishing Protocol provides a great framework for a lot of this.

Well, not so fast...

Continue Reading...



Java, Glassfish, NetBeans and Java DB available with Ubuntu

Posted by davidvc on April 19, 2007 at 09:15 AM | Permalink | Comments (11)

I just got the news that, as of today, Java SE 6, Glassfish v1, are all available in the Multiverse component of Ubuntu 7.04 (Feisty Fawn).

For more information see http://www.sun.com/software/linux/developer.xml. From the press release, Mark Shuttleworth says "Developers who are interested in Sun's latest Java technology can install it instantly if they are running Ubuntu."

This is pretty cool. For the longest time there has been this issue over distributing Java in Linux distributions because of license incompatibilities, and now not just Java SE but a full stack is available. Of course I particularly like seeing Java DB there because, well, I like Java DB. But when you combine Java DB with the NetBeans IDE and the Glassfish app server and, of course, the Java SDK, well, now you have a complete Java development environment and runtime environment for folks using the most popular Linux distro out there.

Congratulations to the teams at Sun, Canonical and Ubuntu for making this happen!

Keep Derby Open

Posted by davidvc on April 18, 2007 at 11:01 AM | Permalink | Comments (1)

On one of my walks through Berkeley (the bumper sticker capital of the world) I encountered this bumper sticker:

Keep Derby Open: Multi-Use Fields Now

That seems very strange - having a single field with multiple uses goes completely against the relational model. And how does that keep Derby open?

I suspect maybe they're talking about a different Derby... :)

Call me a Luddite...

Posted by davidvc on April 17, 2007 at 04:27 PM | Permalink | Comments (8)

I just returned from a week in Mexico, a wonderful time with my family where we lived very simply - food, rest, physical fun. No TV, no movies, no cell phones, no computers. Bright sunshine, beautiful beaches, very friendly people wherever we went.

Then I came home to San Francisco and straight to the Web 2.0 Expo. The contrast has been a bit disorienting. I don't think it's a surprise that my one year old son learned to say "Hi" in Mexico - people actually greeted him there and interacted with him. Here in the conference, on the BART train, on the street, we are all in our own world. We are on our laptops, our phones, our iPods.

Continue Reading...



Firefox 2.0 saves the day

Posted by davidvc on April 06, 2007 at 02:41 PM | Permalink | Comments (5)

I am working on a blog entry about Sun SPOTs. I had gotten about ten minutes into it when BAM Firefox crashed.

I restarted Firefox. I recently upgraded to 2.0, so it asked me if I wanted to restore my old session. Sure, I said. Was I surprised to find out that not only did it bring up my blog entry page, but it also remembered *every word* I had typed before the crash. Wow. It's these kinds of little things that engender passionate loyalty.

Crash-Proof

Posted by davidvc on April 02, 2007 at 11:36 AM | Permalink | Comments (6)

Last month was a miserable month for me in terms of my working environment. I like to work at cafes, and one day I got up, tripped over my power cord, and pulled my entire laptop down BANG upon a nice hard cement floor.

Heads turned, sharp inturns of breath all around. As I picked it gently up and took a look at the screen, my poor little PC made the computer equivalent sounds of a death rattle: "bad sector encountered", "write failed" over and over again. No amount of CPR could save it from its fatal fall.

New hard drive, up and running again, and then I realized my computer had worse problems than a hard disk failure. It had encountered some kind of stroke, and would instantaneously power off at various inopportune moments. I knew I had to say goodbye to this machine when I lost an entire afternoon's work when it powered off and corrupted my source file. I even tried installing Ubuntu on it to see if that was the problem, but no such luck.

After much discussion and thought, I decided to go for a new MacBook Pro. If I need Windows, I can use Parallels to put Windows on it. If I want Solaris, ditto. Of course, I had to order my new machine through Sun, and this had to go through various levels of approval. Meanwhile I was working on my desktop machine at home I got through craigslist. Slow as a dog, and it also Blue Screen'd me about three times a day (it runs Windows 2000 server).

So I borrowed a loaner PowerBook G3. This poor beast just couldn't handle NetBeans 6, and I had to do everything in 'vi'. When you're working with a codebase like NetBeans, which is just massive, this is Such A Pain. I don't know how I ever did this - no code completion, no syntax highlighting, no refactoring, no "find usages". Ack!

Finally, finally, my new MacBook Pro showed up. 17" wide, dual-core Intel chip. 3GB of memory (I wanted 4, but it only handles 3). As far as the operating system, it's OK, I can get my work done. I *do* like that generally an application is just a directory - if I want to uninstall, I just remove the directory. So un-Windows, which scatters an installation through your hard disk like grapeshot. Spotlight, cool. But, really, I just do NetBeans, Firefox, Thunderbird, and some kind of calendar tool, and that's about it. So, no big "wow" here.

But it's those little things. Like the keyboard that lights up when you're in the dark, instant recognition of my printer with no install, a little video camera embedded in the top flap, and a little photo tool with effects (here I am after my last laptop crashed :))

Photo 1.jpg

But here is what really takes the cake for me: the power adapter.

MacBook Power Adapter

I was surprised at the way it connects to my laptop - it snaps in place with a magnet. Well, it's got a cool factor, but the Mac has a lot of fluff like this that's really neither here nor there for me. That was until I tripped on my power cord again today. And rather than my nice new laptop crashing to the ground, the power cord just snapped out with a little "pop" and I plugged it back in.

OK, now I'm sold...



Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds