tech gibberish

by Paweł Chudzik

Poor man's batch processing in JPA


Working with a lot of data using plain JPA or hibernate or spring-data is possible, it does work and usually it doesn’t require a lot of extra codding. Starting small is the fastest way of getting things done but you must be aware of few things that might shoot you in the foot.

16 May 2017

Optimistic locking pitfalls


Optimistic locking is concurrency control method that allows to execute multiple transactions simultaneously as long as they don’t interfere which each other. That’s definition from wikipedia. You probably already know that hibernate supports optimistic locking and all you have to do in order to implement optimistic locking in you app is to add @Version on number or timestamp field and you are good to go. Right?

27 Apr 2017

Immutable dto in jackson


Immutability and functional programming are hot right now. But how to achieve immutability with objects deserialized from json? Luckily there is pretty old feature introduced in jackson 2.7.0 which uses constructor based object creation and uses @ConstructorProperties (introduced in java7).

15 Apr 2017

Keep your stuff up to date

best practices

Every codebase depends on multiple external libraries. It is good idea to stay up to date with external dependencies. It is important to update all security related stuff and it might be helpful or fun to use latest features. I’m going to share my way of staying up to date with external dependencies in maven, gradle and npm.

30 Mar 2017

Page object pattern for javascript components testing


Page object pattern is common practice when writing automated tests using selenium. It allows to gather all possible operations on page in one place and hide page implementation details from test case. Page object pattern can be used in the same way for angular directives, react and [put framework name here] components.

23 Feb 2017

Spock tests grouping using @Category from junit


When project gets bigger and bigger there should be more and more tests. In perfect world all tests should be executed really fast, but life is far from perfect and sometimes some tests are slow. When using gradle + spock combination we have few ways on deciding how to group tests. I’m going to explore junit @Category in combination with spock and gradle.

14 Jan 2017

Final fields


Private final field modification is possible and it doesn’t require a lot of work. Since you should not use this mechanism in real life there are cases when it is useful. For example how is hibernate using this to hydrate final entity fields.

But when using final fields with hibernate you should be extra careful how you declare them.

3 Dec 2016

Java repositories testing


Few days ago I’ve stumbled upon sql query performance issue. Git claims that I was the author so maybe that’s the reason I remember this feature. There was like 3 classes, everything was super easy and super fast all I needed to do was to let hibernate do it’s thing. Then time passed, new features were requested, model become more complex, number of rows increased to ~4 millions and original query became too slow.

When working on query optimisation I was really happy to find that detailed tests are in place. With proper test setup I was able to test my new query to make sure all requirements are met and then quickly copy paste query to sqldeveloper run it on test environment and verify if performance is acceptable. It wasn’t simple query and it took me some time to figure out how to make it quick and work exactly as old one. That was the time I was really glad that we invested in detailed unit tests in the beginning.

6 Nov 2016

Test methods coupling


Sometimes when unit tests setup is complex we are tempted to take shortcuts and write single setup for all tests which will save as few keystrokes. In the time of writing the test it might feel like good idea to configure complex unit test setup and reuse it in all test. This way we avoid code duplication and we create more condensed test.

This approach looks good only in the time of the writing tests. Then there is a time when unit tests must be maintained. This is the time when you usually realise that saving few keystrokes wasn’t such a good idea.

29 Oct 2016