Insane Programming Java ramblings and finds on the net

14Oct/090

The danger of nested exceptions in Java Webstart applications

Everyone knows the following snippet:

try
{
   // snip
}
catch(SomeCheckedException ex)
{
   throw new RuntimeException("Hey, some exception occurred", ex)
}

It's your standard 'I hate checked exceptions, let's transform them into unchecked ones'. Sometimes, you won't even notice it happening. Using Spring and Hibernate, checked exceptions are a rare thing to encounter, since the framework nicely encapsulates them into unchecked ones. But there's a hidden danger lurking within these exceptions. See that second parameter in the exception? It's that one that can cause some problems when dealing with WebStart applications connecting to a remoted back-end somewhere.

14Oct/090

Atlassian, you are my hero

Today, I stumbled once again on to the Atlassian website. I love working with Atlassian's product, especially Jira and Fisheye.

I knew Atlassian started with the Personal licensing, but unfortunately, you couldn't use them in a work environment. Now, Atlassian has given about every other issue tracking systeem a real kick in the groin: all products start from 10$ now. For that 10$ for example you can get a 10-user commercial License for Jira, a 10-user license for Greenhopper, ... I don't know who does marketing at Atlassian, but they deserve a big fat bonus this year.

Thank you, Atlassian!!!

14Oct/090

Implementing the Circuit Breaker pattern in Spring with AOP

This is one of my earlier articles

Intro

Most of you are probably wondering right now what a circuit breaker is. Well, it's a pattern I picked up while reading Release It!, a Pragmatic Bookshelf jewel. For those of you who haven't read this book yet, go to the bookstore and get it. It's one of my favorites and it has helped me to become a better developer.

Quoting the book, a circuit breaker 'is a component designed to fail first, thereby controlling the overall failure mode' . Put shortly, it allows you to circumvent a certain subsystem when that subsystem is not healthy.

It can be a very handy component when your system is communicating with several outside systems. When a certain system is failing over and over, you probably don't want your system to keep trying, hoping it will go up again. Using a circuit breaker, you can stop your system, failing fast and more importantly, gracefully.

13Oct/090

Combining Liquibase with Spring and JPA

Managing change on source code is easy. Managing change on database schemas is less so. Especially if your application can be used across many database backend (Oracle, MySQL, SQL Server, ...).

Liquibase provides a database agnostic way of managing changes to a database structure. It uses an XML format which contains various changesets for all the changes made to a schema. Ideally, you'll have a changeset per atomic change (adding a column, creating a table, changing an index,...). The beauty of Liquibase is that the database itself is aware about its state. Liquibase implants a versioning table into your schema and uses this table to do the necessary updating.

When using it in combination with Spring and JPA, there are some things you do need to look out for. First of all, the Spring support for Liquibase isn't very big. There's an initiializing bean that updates a schema based on a changelog xml, but that's about it. For example, I wanted to change the names of the tables Liquibase creates for its versioning. The Spring class in Liquibase does not support this feature. Luckily, using the Spring support in Liquibase as a baseline, it's not that hard.

12Oct/098

I Do Code in my Free Time

Recently, I found this article on DZone, one of the feeds I read the most.

The article is, in it's essence, probably a rant against the hiring mechanism in Silicon Valley. Perhaps the author encountered a hiring process like the article stated and had a really bad experience. It states that expecting a programmer to do some coding in his spare time is blissfully naive. There isn't a day that goes by that I don't do something new. And yes, I do have responsibilities aside from work. But that doesn't prevent me to try to grow at any possible opportunity. It's called planning. I would really suggest that the author of the article go and buy a copy of the Passionate Programmer. For the record, I have no experience in hiring.

12Oct/094

Designing Swing applications: Choosing the right look

Developing Swing applications is fun. Developing enterprise Swing application is even more fun. But apart from the functional requirement such an application brings, you also need to take into account the aesthetic part of your application. You're application won't be a real success if your users can bear the sight of it, or the general look of the application is so different from the other applications they use on a daily basis that they use it inefficiently.

Filed under: Swing Continue reading
10Oct/090

Hibernate Search, JPA and DBUnit

Currently I'm doing a project involving HIbernate Search and JPA. As any good programmer would do, there is a battery of unit tests (better term here is integration tests) for testing my services. To get some managed test data into the database, I'm also using DBUnit.

This combination works perfectly until you start using Hibernate Search and JPA. For example, Lucene (the full text engine behind Search) will only index entities persisted through the entity manager. Since you're loading the data through DBUnit, Lucene won't index any entities. Result: full text searches won't work. Luckily, the solution is quite simple. I'm also using Spring and my DBUnit dataset is already being loaded by the context. The reason for this I explained in the previous post. This gave me the idea to build another class specifically for re-indexing purposes. So I came up with this.

10Oct/093

DBUnit, JUnit4 and Spring

Using JUnit with DBUnit is bliss for anyone doing database integration tests. Having a reproducible dataset in your database is vital for writing good integration tests. The problem is, using DBUnit effectively with JUnit 4's annotation based unit testing and Spring can be a pain.

Say you want to have the following:
- load the database once per testcase (not per test, as all your tests rollback the changes they do)
- use the datasource defined in your spring context with DBUnit
Can't that hard, can it?