Goldman Sachs collections – nearly everything you want from collections in Java

Java collection framework is not that powerful as experienced Java developer would expect. For example, how do you sort a list? Simple answer would be to use java.util.Collections.sort() method with some kind of java.util.Comparator implementation. Additionally Guava Ordering support can be used. However, the solution is not exactly what object oriented developer looks for. Similarly to … Read more

Measure and find bottlenecks before they affect your users 1/2

Inspired by a few talks during the last 33rd Degree conference I decided to implement, in one of the applications I develop, metrics which allow developers or operation team monitor running application and possibly detect potential problems early on. After a quick investigation I decided to use the Metrics framework. What I expected was exposing at least some statistics … Read more

Hibernate + 2nd level cache bug

Recently, I have come across a nasty bug. When Hibernate executes a cacheable query and applying a ResultTransformer on a result of that query, java.lang.ClassCastException is thrown. session.createCriteria(RateEntity.class) .add(Restrictions.eq(CURR_ID, criteria.getCurrency())) .add(Restrictions.eq(TYPE, criteria.getRateType().name())) .add(Restrictions.gt(TS_CRT, criteria.getFromTime().toDate())) .setProjection(Projections.projectionList() .add(Projections.property(TS_CRT), TIME_DTO_PROPERTY) .add(Projections.property(RATE), RATE_DTO_PROPERTY)) .addOrder(Order.asc(TS_CRT)) .setCacheable(true) .setResultTransformer(Transformers.aliasToBean(RateDTO.class)) .list(); It seems that the ResultTransformer is applied on the result before putting … Read more

Java enums + template method design pattern

Let’s consider the following code snippets: public enum Currency { EUR, USD }   String currency = “EUR”; if(Currency.EUR.name().equals(currency)){ System.out.println(“Transfer permitted”); } How often do we see much the same scenario? It is not completely wrong since there is a try to use enums so it is not entirely “string driven” programming. However there is … Read more

JPA EntityManager operations order

I have run into interesting issue recently. I use in the project JPA + Hibernate + EJB. The issue concerns saving and deleting entities in the same transaction. Database table which is used has an unique constraint defined on two columns. What I have done was removing entity calling entityManager.remove(); then the new entity has … Read more

Spring Integration

I have been really impressed by the Spring Integration project recently so I decided to write a few words about it. Just to make a quick introduction: Spring Integration can be described as an extension of the Spring programming model which supports Enterprise Integration Patterns. It enables lightweight messaging within Spring-based applications and supports integration … Read more