Friday, December 27, 2013

Design patterns in validation

    Validation is a pretty common business requirement. We need to be sure that the input data is valid and remember that: junk in -> junk out. Let's say that we want to validate a request object. The easiest way is to produce a big chunk of IF statements. Do you like that IF ... IF ... IF ... blocks one after another? I hate them. So how to deal with validation?

Saturday, December 7, 2013

Are connectTimeout and readTimeout enough for a good night's sleep?

    When it comes to communication with external resources we need to be sure that reasonable timeouts were set. Network is like a black hole - we send a request and many bad things can happen. Without timeouts our thread pool can saturate because of threads stuck deep inside socket read method. It is usual to set connect timeout and read timeout. But is it enough? Can we have a good night's sleep when connect and read timeouts are set in our application? Let's check!

Monday, November 25, 2013

Oracle's XMLTYPE with Hibernate 4

    XML is quite popular nowadays. You can store XML as a VARCHAR type in a DB. However, it has some limitations, e.g. you cannot perform XPath DB queries on a VARCHAR. Oracle DB comes with XML dedicated type - XMLTYPE that allows to perform XPath queries, has XML validation logic built-in and some storage optimizations. On the contrary, Hibernate does not support XMLTYPE out of the box. We need to define our custom UserType.

Tuesday, November 5, 2013

Robust DB connection pool configuration

    Martin Fowler claims: 'Any fool can write code that a computer can understand. Good programmers write code that humans can understand'. I would add: 'Any fool can write code that survives a happy path'. Some time ago I posted a data source configuration for H2 DB. Was the configuration really robust?

Monday, October 14, 2013

Error codes - underscore in numeric literals

    Java 7 introduced a bunch of language improvements (known as Project Coin). One of the improvement that I want to focus on is an underscore in numeric literals.

Friday, October 11, 2013

Can the 'new' keyword be harmful?

    I've heard somewhere that nowadays the object creation in Java is cheap. Every Java Developer knows the 'new' keyword and its purpose. However, does every Java Developer think about the consequences that are related to that keyword?

Friday, September 27, 2013

The Law of Demeter will tell you the truth

    The Law of Demeter (LoD) is well-known in object oriented programming. Can we get to know something unusual from that principle?

Tuesday, September 3, 2013

Hibernate configuration example with in-memory H2 DB for ad-hoc testing

    Sometimes I like to play a little bit with Hibernate. I do not want to spend much time on configuration or DB schema creation so I keep prepared piece of code.

Saturday, August 31, 2013

@PrePersist and @PreUpdate - not working with Hibernate 4 Session and Spring

    @PrePersist and @PreUpdate annotations have their roots in JPA specification. Hibernate implements JPA specification. However, if we decide to use SessionFactory and Session instead of EntityManagerFactory and EntityManager, we will realize that mentioned annotations are ignored. Is there a way to solve the problem?

Saturday, August 10, 2013

IntelliJ - GIT push problem

    IntelliJ seems to be an interesting IDE, however recently I had an issue related to it's GIT plugin.