Thursday 28 November 2019

AUTO flush

So, to my sorrow, I recently found out that the old product uses hibernate.cfg.xml and the new product we're developing uses persistence.xml.

So, whilst developing for the new product, I ran into issues.

Issues where a query sent to the database, would trigger a flush of all my dirty changes in my Session to the database.

This is because the Session is running with FlushModeType.AUTO, which is the default.

Problem was,... I was at the moment still building an entity to be persisted, and it wasn't ready yet.

Apparently I now have to be very careful in which sequence I do things.

Suffice to say, I am not amused.

Either that, or I switch over to FlushModeType.COMMIT, which means I can query the database all I want, and the flushing of my dirty entities in the session will take place only when I commit.

This is very convenient, unfortunately the disadvantage is that I might not see the dirty data in the database during my queries. But I feel this is well worth it.

References

Vlad Mihalcea - How does AUTO flush strategy work in JPA and Hibernate
https://vladmihalcea.com/how-does-the-auto-flush-work-in-jpa-and-hibernate/
Vlad Mihalcea - How do JPA and Hibernate define the AUTO flush mode
https://vladmihalcea.com/how-do-jpa-and-hibernate-define-the-auto-flush-mode/
GitHub - Jakarta Persistence project
https://github.com/eclipse-ee4j/jpa-api

Thursday 21 November 2019

HTTP Caching Headers

I recently wanted to add some rather aggressive caching, to prevent my server getting hit too often.

Naturally, I wanted this caching to take place on the client, i.e. the webbrowser.

So, there have traditionally been advantages and disadvantages to caching.

Advantage: the server doesn't get hit again, and your website feels more responsive.

Disadvantage: it is possible to see outdated cached data.

Invalidating cache entries is basically an entire study of its own.

In my case I took the obvious route: the data stays the same forever.

This facilitates my caching wonderfully.

response.addHeader("Cache-Control","private, max-age=31536000");

This stores the item in the cache for one year (31536000 seconds).

Private means caching in the client browser, public means that it might also be elligible for caching in all other intermediaries between de browser and the server.

The blogs in the references are very clear.

References

[1] Heroku Dev Center - Increasing Application Performance with HTTP Cache Headers
https://devcenter.heroku.com/articles/increasing-application-performance-with-http-cache-headers
MDN Webdocs - HttpHeaders - Cache Control
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
MDN Webdocs - HTTP caching
https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching

Thursday 14 November 2019

Devoxx 2019 - wrapup

I just thought I'd mention the sessions I saw, and the sessions that are on my "todo" list.

That which is Seen

Rust for Java Developers - by Paul Watson, Andy Bell
It's always a good thing to learn a new programming language. Rust is similar to C, with an interesting take on no-garbage-collectors and all sorts of goodies. Compiles to native.
The Web is on 🔥 F.I.R.E. 🔥 !!! - by Noël Macé
Progressive Web Apps, new standards that are not standard yet, but already available in Chrome or Chrome Canary.
Broken Buildtools and Bad Behaviors; The Maven Story - by Robert Scholte
An interesting take on what to do and what not to do with Maven.
Money, Money, Money, can be funny with JSR 354 - by Werner Keil
A bit boring, but only until you realize what kind of freakish money and money rules there are out there. Already it's available in standard Java, and there's no good reason not to use it.
Solving Memory Leaks in the JVM - by Kirk Pepperdine
just as it says, a very good explanation also about how the memory management in Java works.
Java 9 and Beyond - by Venkat Subramaniam
Hey, it's Venkat, always good.
Evolving a Pragmatic, Clean Architecture - A Craftsman's Guide - by Victor Rentea
a lot of the lessons seem hauntingly familiar. Some pieces were unknown. Some things I had doubts about.
Welcome to LWorld: The current state of value types in Java - by Tobi Ajila
a very good entry-level and advanced lecture about the new value inline types
Collections Corner Cases - by Stuart Marks
An awesome talk about things I didn't know, but have been using for ages.
What's coming in Scala 3 - by Josh Suereth, James Ward
Very interesting and advanced, must be easier for people who have more familiarity with Scala.
Why We Hate Java Serialization And What We're Doing About It - by Stuart Marks, Brian Goetz
Some ideas about extending Serialization to how it should have been. Right now only a rough plan.
A Gentle Introduction to Angular Schematics - by Matt Raible
Basically the stuff you can use to adapt the Angular CLI to what you want it to do. Think "templates" on speed.
The time relativity principle - by Jakub Marchwicki
Useful if only for the fact that we get up to some strange shenanigans when it comes to timezones
Ask the Java Architect - by Brian Goetz, Stuart Marks
Always fascinating to find out the reasons behind the new designs for Java.
Advancements in Angular - by Jeremy Elbourn
Fascinating talk on the internals by a core member of Google Angular team
Is your AI plotting to kill you? Why AI and Machine Learning is dangerous - by Ben Vermeersch
A nice talk for the tin-foil hat people, and people interested in finding out the weaknesses of AI en how to beat AI at their own game.
How to get properly hacked! - by Julien Topçu
informative, but most things I already knew. The xml entities hack was new for me, though.
From Java to Golang, the journey of the nexuzhealth team - by Dylan Meeus
fascinating talk about the pitfalls of moving to Golang. A little short on information on how to convert large legacy systems.
Java Language Futures: Late 2019 Edition - by Brian Goetz
Always a pleasure.

That which is Unseen

Exploring Collectors - by Venkat Subramaniam
It's Venkat!
Top Tips for Terrible Tech Talks - by Chet Haase
Heard good things about it.
Project Loom: Helping Write Concurrent Applications on the Java Platform - by Ron Pressler
Because Project Loom sounds interesting.
More Than a Query Language: SQL in the 21st Century - by Markus Winand
Learn things about SQL that you didn't know existed.
The 7 biggest mistakes we made in 10 years of running a major open source project. - by Roel Spilker, Reinier Zwitserloot
Colleagues liked it.
The past, present and future of the Java type system - by Alasdair Collinson
As Venkat put it, will we ever see a List<int>?
RSA is Dead. Long Live BB84! - by James Birnie
Because encryption is cool.
Beyond ByteBuffers - by Brian Goetz
ByteBuffers are bad? Really?
Memory footprint of a Java process - by Andrei Pangin
Perhaps could be interesting.

References

YouTube - Devoxx
https://www.youtube.com
Devoxx.be
https://devoxx.be/

Thursday 7 November 2019

Bootstrap and Darkmode

Recently (well, not that recently) an issue was submitted to my hobby project that the background, which was very bright white, was a little off putting. Apparently people are surfing on my website at night.

Since I have a new monitor1, I must say that the new monitors indeed transmit a staggering amount of light.

Of course, this means something has to be done about it (apparently) and it's called Darkmode2.

Personally, I find that a bright screen enables me to keep working in the dead of night without becoming tired, but that's just me. And probably not entirely healthy.

Anyway, I am using Bootstrap3, so I was looking for a Bootstrap Theme to fix this problem.

A lot of really FANTASTIC themes for Bootstrap can be found on Bootswatch4.

I choose Cyborg5 from their selection.

The switching

Next is how to provide the websurfer with a choice between the two modes, normal mode and darkmode.

You can find a lot of different ways of doing it, just surfing around.

Now, obviously, I do not wish to add all sorts of classes to my html pages. I just want to replace the appropriate links to the .css files in my html.

I have two different setups in my current website, static pages through a templating engine and two SPA using Angular.

Static pages

For the static pages, the problem is actually non-existant. I just add the appropriate css- and javascript-links in my webpage based on a Darkmode cookie setting, and away we go.

Angular

For Angular, I must confess I used a very low-tech solution, that some of you might not like.

Basically there is a index.html in my Angular app, that contains the link to the css file and I just replace the link using javascript.

I do this in the ngOnInit() of the central Angular component.

As follows:

References

[1] My new monitor
https://randomthoughtsonjavaprogramming.blogspot.com/2019/07/a-new-monitor.html
[2] Wikipedia - Light-on-dark color scheme
https://en.wikipedia.org/wiki/Light-on-dark_color_scheme
[3] Bootstrap
https://getbootstrap.com/
[4] Bootswatch
https://bootswatch.com/
[5] Bootswatch - Cyborg
https://bootswatch.com/cyborg/

Monday 4 November 2019

Devoxx 2019

Hello, there!

I am currently at Devoxx 2019, in Antwerpen for the entire week.

I'll try and write some blogposts on it.