Author Archives: hedleyproctor

Writing a custom spliterator in Java 8

In this article I’m going to give two examples of writing a custom spliterator in Java 8. What is a spliterator and why would you need to write your own? Well, a spliterator is used by the Java streams code … Continue reading

Posted in Java, Uncategorized | Leave a comment

Using Optional in Java 8

“The introduction of null references was my billion dollar mistake” – Tony Hoare Optional is a (typed) container object. It may contain a single object, or it may be empty. It allows you to avoid null pointer exceptions. In this … Continue reading

Posted in Java | Tagged | Leave a comment

Maven offline build fails to resolve artifacts in your local repository

Recently I’ve been trying to set up a new machine with a maven build that can work offline. My first instinct was to do the following: Configure maven with a ~/.m2/settings.xml file with our set of Nexus repos (we use … Continue reading

Posted in Maven | Tagged | Leave a comment

Java 8 Streams Tutorial

In this tutorial, I’m going to start by explaining some of the basics of streams. Viz: What streams are Terminal and non-terminal operations Their “lazy” nature Their read-once nature Why they were introduced i.e. how they enable easy parallel operations … Continue reading

Posted in Java | Tagged , | Leave a comment

Yet another Java 8 custom collector example

Java 8 introduces a number of functional programming techniques to the language. Collections can be turned into streams which allows you to perform standard functional operations on them, such as filtering, mapping, reducing and collecting. In this post I’m going … Continue reading

Posted in Java | Tagged | Leave a comment

Finding slow queries in SQL Server

When you want to optimise your app, one of the most important things is to find your slowest database queries, to see if indexes are missing, or the queries should be rewritten. SQL Server stores statistics for its queries in … Continue reading

Posted in Performance, SQL Server | Tagged , | Leave a comment

Writing a DSL with Scala Parser Combinators

Scala parser combinators provide a very easy way to construct your own domain specific languages (DSLs). Let’s look at a simple example. Suppose that you work on a large application which produces various report files on a scheduled basis. You … Continue reading

Posted in Scala | Tagged | 2 Comments

Optimistic locking and versioning with Hibernate

Just put a small example of Hibernate optimistic locking and versioning on github: https://github.com/hedleyproctor/HibernateVersioningExample Hibernate uses an optimistic locking strategy, based on versioning. This means it tries to avoid taking a lock on data and instead relies on having a … Continue reading

Posted in Hibernate | Tagged | Leave a comment

Distinct, order by and Hibernate HQL

Recently someone posted a question on stackoverflow explaining that they were having a problem with a Hibernate HQL query that involved both order by and a distinct in the select. The query was across five linked entities – a many … Continue reading

Posted in Hibernate | Tagged | 1 Comment

Understanding the Hibernate session cache

When you use Hibernate, you do so via a session. It is well known that the session acts as a first level cache, but sometimes this can cause confusing behaviour. Let’s look at a simple example. Suppose I have Customer … Continue reading

Posted in Hibernate | Tagged | Leave a comment