Navigation

RSS 2.0 New Entries Syndication Feed Atom 0.3 New Entries Syndication Feed

Show blog menu v

 

General

Use it

Documentation

Support

Sibling projects

RIFE powered

Valid XHTML 1.0 Transitional

Valid CSS!

Blogs : Latest entries

avatar
Closing several JDBC statements cleanly

It's been a while since I wrote some raw JDBC code. I didn't remember that it was so tedious to manually close a series of PreparedStatement objects and make sure that any exception was properly handled and reported.

Note that the ARM blocks or BGGA closures proposals don't make this easier since this cleanup should be done after the prepared statements have been used for a while in various other methods, it doesn't automatically have to be done at the end of a lexical scope.

This is what I came up with.

Of course, you could write an alternative implementation that creates some kind of repository for the prepared statements in a map and then provide a method that closes them all by going over the entries of the map while preserving the exceptions in a similar manner. Any other suggestions or comments for this to be done better?

private PreparedStatement psStmt1;
private PreparedStatement psStmt2;
private PreparedStatement psStmt3;
 
public void cleanup() throws SQLException {
  SQLException exception = null;
  if (psStmt1 != null) {
    try {
      psStmt1.close();
    } catch (SQLException e) {
      exception = e;
    } finally {
      psStmt1 = null;
    }
  }
 
  if (psStmt2 != null) {
    try {
      psStmt2.close();
    } catch (SQLException e) {
      if (exception != null) e.setNextException(exception);
      exception = e;
    } finally {
      psStmt2 = null;
    }
  }
 
  if (psStmt3 != null) {
    try {
      psStmt3.close();
    } catch (SQLException e) {
      if (exception != null) e.setNextException(exception);
      exception = e;
    } finally {
      psStmt3 = null;
    }
  }
 
  if (exception != null) {
    throw exception;
  }
}
posted by Geert Bevin in Java on Jan 30, 2008 6:11 PM : 5 comments [permalink]
 
Custom constraints and validation in RIFE

Joshua Hansen wrote a nice example of how to create custom meta data constraints and display dedicated validation error messages with RIFE. He also shows how easy it is to make RIFE/Crud display your validation errors for beans that use your custom constraints.

Read the article in the RIFE wiki.

posted by Geert Bevin in RIFE on Jan 29, 2008 5:52 PM : 0 comments [permalink]
 
Java Champions interviews at JavaPolis 2007

At JavaPolis 2007, Aaron Houston the coordinator of the Sun Java Champions program, recorded a whole collection of short interviews with the Java Champions that were present at the conference (2-8 mins).

If you're wondering what the Java Champions are up to, or even who or what they are, this is a easy and quick way to find out.

The interviews can be found on the Java Champions homepage and will eventually move to the library section.

You can listen to my interview directly here (6 min 12 MB):

https://java-champions.dev.java.net/mp3/JP07-geert-bevin.mp3

posted by Geert Bevin in Java on Jan 4, 2008 7:20 PM : 0 comments [permalink]
 
Back in the saddle, happy New-Year!

Some people might have been wondering why it has been so quiet on the RIFE front and also why I haven't been blogging more regularly for almost half a year.

First of all, I started working at Terracotta in April 2007 and it has taken me a few months to get comfortable with the code-base, the concepts and the architecture. The technology is truly amazing and my colleagues are extremely smart and friendly. I've been learning a lot about concurrency and clustering and made a couple of friends that are already very close to my heart.

Then, in fall last year, it seems that fate decided to show us that life can't always be smooth sailing. I'm not complaining, we have been surprisingly fortunate for many years but this series of unfortunate events followed up on each-other so quickly that for the first time in history I truly took an effort to write sincere New-Year wishes to my friends and family. Wishing someone 'good health' and 'joy' got a whole new meaning.

First, I had a motorcycle accident and my girlfriend did so too a couple of weeks later. We weren't significantly hurt, but it does shake you up for a while.

After that, our youngest daughter almost lost her eye after hitting her head against the table corner. She has nothing permanent except for a small scar in the corner of her left eye.

A few weeks later, we were all evacuated out of our house with carbon-monoxide poisoning. Our oldest daughter escaped death by a couple of minutes and we had to get intense oxygen treatment to reduce the CO levels in our blood. People, really, get CO detectors! CO poisoning is NOT something that only happens to others! You can die from it in a matter of minutes! I installed the detectors now and had the source of the CO leak fixed.

Just after that, my father was found on the floor of his kitchen by the police. They forcibly entered his house at my request, since he hadn't been seen by anyone for several days. He's got permanent brain damage due to many years of alcohol abuse and will most certainly live the rest of his life in an institution, not remembering 99% of his life and constantly confusing dreams and reality.

Finally, I lost my dog after she escaped from the enclosed field at the back of our house. After calling all animals shelters in the area, alerting the police and putting up many posters, someone finally contacted us saying that they had found her.

All in all, after looking back, I actually consider ourselves lucky. All of these events could have had severe consequences, but finally the outcomes were all much more positive than what they could have been.

Happy New-Year to everyone! I wish you a soothing 2008 with lots of joy and pleasant surprises, and also an excellent health for you and your loved ones!

I'm getting back in the saddle. I will be working on RIFE again and will be blogging more frequently.

posted by Geert Bevin in Life on Jan 4, 2008 4:02 PM : 5 comments [permalink]
 

 
 
 
Google
rifers.org web