2013-12-31

Handling exceptions with Guava

Some time ago, while reading Java Concurrency In Practice, I encountered the following utility method:
public static RuntimeException launderThrowable(Throwable t) {
  if (t instanceof RuntimeException)
    return (RuntimeException) t;
  else if (t instanceof Error)
    throw (Error) t;
  else
    throw new IllegalStateException("Not unchecked", t);
}
At first it looks quite strange, so let's see how it can be used.

2013-12-10

Yet another guide to Spring Data JPA

I've been learning Spring Data JPA recently and I am really impressed by its features and ease of use. It allows to create JPA based data access layer very quickly. In a basic usage scenario you only need to create interfaces which extend specific Spring interfaces and which have methods named according to appropriate convention - and that's it. Spring Data JPA will automatically provide implementations of those interfaces.

I created a simple project, which demonstrates basic features of Spring Data JPA. The source code can be downloaded here and the most interesting parts are described below.