It´s just about caching, honey!

Sometimes we want to read data once from a store and cache it in memory because retrieving it from the source is rather expensive. There are two strategies to achieve that:

The first way of caching is achieved by loading the entire data of a given type from some source at once and access it from the cache. This is suitable for small caches or if most cache entries are likely to be read.

An alternative is a growing cache. Whenever data is requested from the cache the first time the cache will load it from the given source, cache it and finally, return it to the client. If data is requested from the second time on it will be returned from the cache without accessing the source.

Continue reading “It´s just about caching, honey!”

Using value object properties in JPA entities

Motivation

Most of the time, when we design basic properties of a JPA entity we use easy-to-map types like java.lang.String, java.math.BigDecimal, etc.. In this post, I will discuss the the usage of value objects​1​ instead which are known from the concept of domain driven design​2​.

I will explain the benefits of using value objects and how to integrate them into JPA entities. Furthermore, this post provides useful hints for DbUnit tests of such entities.

Continue reading “Using value object properties in JPA entities”

Handling multiple resource bundles in Java

The standard Java way to handle internationalization is to use resource bundles. It is considered to be a good practice to have many resource bundles containing only a few entries rather than having one huge resource bundle which is hard to maintain.

On the other hand, the developer who wants to use the resources must know every resource bundle he needs. Furthermore, he also needs to know which resource bundle is containing the particular resource he is currently trying to access. Continue reading “Handling multiple resource bundles in Java”