Home » Author Archives: Alex Staveley

Author Archives: Alex Staveley

Postgres indexes

postgresql-logo

Recently, I had a situation where I needed to think how I was using Postgres indexes. I had a simple Book table with the following schema… >\d book Table "shopping.book" Column | Type | Modifiers ---------------------+------------------------+----------- id | uuid | not null version | bigint | not null amount_minor_units | integer | not null currency | character varying(255) | not ...

Read More »

Problems with Cobertura and Sonar 5.1

sonar-logo

Recently, I was having some bother trying to use Sonar 5.1 with my Grails 2.4.4 project. I was using the usual Groovy stuff:Gmetrics, Codenarc and Cobertura. For the Sonar database I was using Postgres 9.4. The logfile for the Sonar runner just gave me this: build 22-Jun-2015 07:44:30 INFO: ------------------------------------------------------------------------ build 22-Jun-2015 07:44:30 INFO: EXECUTION FAILURE build 22-Jun-2015 07:44:30 INFO: ...

Read More »

Using separate Postgres Schemas for the same database in a Grails App

grails-logo

Recently, I wanted to use the same Postgres Database but split my persistence layer into separate components which used separate schemas. The motivation was to promote modular design, separate concerns and stop developers tripping up over each other. Vertical domain models can be difficult to achieve but not impossible. In my shopping application, I had a user component, a shopping ...

Read More »

MongoDB and Grails

groovy-logo

So recently, I had a requirement to store unstructured JSON data that was coming back from a web service. The web service was returning back various soccer teams from around the world. Amongst the data contained in most of the soccer teams was a list of soccer players, who were part of the team. Some of the teams had 12 ...

Read More »

Grails tip: refactoring your URLs

grails-logo

On the current project I am working we use a lot of integration tests. For you non-Grails users out there, Integration tests test your Controller APIs, your Services and any persistence that might happen all very neatly. The only slice of the cake they don’t test from a back end perspective are your Grails filters for which you’d need something ...

Read More »

Groovy Closures: this, owner, delegate let’s make a DSL

groovy-logo

Groovy closures are super cool. To fully understand them, I think it’s really important to understand the meaning of this, owner and delegate. In general: this: refers to the instance of the class that the closure was defined in. owner: is the same as this, unless the closure was defined inside another closure in which case the owner refers to ...

Read More »

Good use of Closures

java-logo

Not long ago, in a blog post, I explained what Closure were in Groovy. This blog post will explain one good example of using them. I recently found myself having to write the same exception handling logic for a bunch of back-end Controller APIs which were serving AJAX requests. It was like this:         class ApiRugbyPlayerController { ...

Read More »

Closures in Groovy

groovy-logo

The simpliest explanation of a closure in Groovy is that it is anonymous function.                   def closure = { println "I am a closure" } closure() // Prints I am a closure Ok, so first point here is that I am a closure is not printed when the closure is defined but ...

Read More »

Groovy’s Smooth Operators

groovy-logo

Take a trip back to 1984.  Apple release the Macintosh, ‘The Final Battle‘ is about to commence in V and Scotland win the Five Nations completing a grand slam in the process.  Right in the middle of miners’ strike in the UK, English pop group Sade release the catchy number: Smooth Operator.  It was chart success in the UK and in ...

Read More »

Grails: Applying build information to your builds

grails-logo

Occasionally, when I buy some food I check the label to see how unhealthy it is in an effort to remind myself to eat better. I probably should do this more often but that’s another story. With software, I take a more strict approach. I like to know exactly what version of what I am using and if it pertains ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.