We’re Taking Bets: This Annotation Will Soon Show up in the JDK

This recent Stack Overflow question by Yahor has intrigued me: How to ensure at Java 8 compile time that a method signature “implements” a functional interface. It's a very good question. Let's assume the following nominal type: @FunctionalInterface interface LongHasher { int hash(long x); } The type imposes a crystal clear contract. Implementors must provide … Continue reading We’re Taking Bets: This Annotation Will Soon Show up in the JDK

Type Safe Queries for JPA’s Native Query API

When you're using JPA - sometimes - JPQL won't do the trick and you'll have to resort to native SQL. From the very beginning, ORMs like Hibernate kept an open "backdoor" for these cases and offered a similar API to Spring's JdbcTemplate, to Apache DbUtils, or to jOOQ for plain SQL. This is useful as … Continue reading Type Safe Queries for JPA’s Native Query API

Do Not Make This Mistake When Developing an SPI

Most of your code is private, internal, proprietary, and will never be exposed to public. If that's the case, you can relax - you can refactor all of your mistakes, including those that incur breaking API changes. If you're maintining public API, however, that's not the case. If you're maintaining public SPI (Service Provider Interfaces), … Continue reading Do Not Make This Mistake When Developing an SPI

How to Access a Method’s Result Value From the Finally Block

While the JVM is a stack-based machine, the Java language doesn't really offer you any way to access that Stack. Even if sometimes, in rare occasions, it would be very useful. An example Method result values are put on the stack. If you look at the following example: public int method() { if (something) return … Continue reading How to Access a Method’s Result Value From the Finally Block

Use This Preference to Speed up Your Eclipse m2e Configuration

Who doesn't know them. The good old JFace dialogs in Eclipse that give you a visual representation of what is really a rather simple XML or properties file. In the case of m2e, it looks like this: Unfortunately, this screen is a bit slow to load, and it doesn't offer much value beyond checking version … Continue reading Use This Preference to Speed up Your Eclipse m2e Configuration

Functional Programming in Java 8 with vavr

We're very happy to announce a guest post on the jOOQ Blog written by Daniel Dietrich, Senior Software Engineer at HSH Nordbank, husband and father of three. He currently creates a pricing framework for financial products as project lead and lead developer. Besides his work, he is interested in programming languages, efficient algorithms and data … Continue reading Functional Programming in Java 8 with vavr

Use this Neat Window Function Trick to Calculate Time Differences in a Time Series

Whenever you feel that itch... Can't I calculate this with SQL? The answer is: Yes you can! And you should! Let's see how... Calculating time differences between rows Let's consider the following database containing timestamps (e.g. in a log database). We're using PostgreSQL syntax for this: CREATE TABLE timestamps ( ts timestamp ); INSERT INTO … Continue reading Use this Neat Window Function Trick to Calculate Time Differences in a Time Series

PostgreSQL’s Best-Kept Secret, and how to Use it with jOOQ

PostgreSQL has a lot of secret data types. In recent times, PostgreSQL's JSON and JSONB support was hyped as being the NoSQL on SQL secret (e.g. as advertised by ToroDB) that allows you to get the best out of both worlds. But there are many other useful data types, among which the range type. How … Continue reading PostgreSQL’s Best-Kept Secret, and how to Use it with jOOQ

How SQL GROUP BY Should Have Been Designed – Like Neo4j’s Implicit GROUP BY

In the recent past, we've explained the syntactic implications of the SQL GROUP BY clause. If you haven't already, you should read our article "Do You Really Understand SQL’s GROUP BY and HAVING clauses?". In essence, adding a GROUP BY clause to your query transforms your query on very implicit levels. The following reminder summarises … Continue reading How SQL GROUP BY Should Have Been Designed – Like Neo4j’s Implicit GROUP BY