Groovy
Groovy Ref Card
I downloaded and saved to my Evernote the Groovy reference card PDF created by @mittie. Next time you want to check something fast it will come handy.
Road from Java to Groovy
@jackfrosch compares Java to Groovy in three different angles: interoperability, language differences and Groovy add-ons.
how to keep Java 8 compatibility:
Wherever you find a Java 8 method reference or Lambda you can replace it with a closure
What Groovy brings to the table: ASTs, Traits, Multiline Strings, operator override.
Several topics (equality, method dispatching and truth evaluation ... ) to highlight the difference between both languages.
â–¶ Groovy Exercises
I found this collection of 60 videos put together by Hugo. It contains exercises ( Math, collection manipulation, string manipulation) ... to keep your knowledge sharp.
Grails
Unit of work, Transactions and Grails
Great post by @cyrilpicat to better understand transactions in Grails.
Key takeaways:
- use services to factor common business logic AND handle correct transaction behavior
- always use injection to call a service
- do not use closures to define a service method
- use runtime exceptions if you want to roll back a transaction
- Stick to Grails paradigm of putting transactional code in the services
- Always put your unit of work in a top-level service, aka don’t call two services in a controller action
Read it.
Don't do flush:true when you actually want a transaction
@marioggar goes deep in explaining the perils of flush:true. He advocates to move your code to services and use the transactional capabilities there.
Using transactional behaviour with Gorm
This post by Puneet gives me the chance to talk about withTransaction; a method Grails Domain classes get injected. You can always call DomainClassName.withTransaction {}. Code inside that closure will be wrapped in a transaction.
Please don't miss @burtbeckwith's comment:
Checked exceptions do not automatically roll back transactions since in Java you have to catch them or add them to the throws declaration. Only unhandled runtime exceptions and errors automatically rollback transactions since it’s assumed that you didn’t use a try/catch.
GORM Transactions Annotations
@simonhobbs goes over the different GORM transactions annotations and what we can expect. He follows with several examples which may surprise you.
Comment
Grails simplifies persistence development while creating a web application a lot. GORM, Domain Classes convention, Constraints ...
This issue talks about Transactions. Understanding them will help us create more robust code and improve how we code persistence.
Plus, Groovy Calamari has a new logo 💄
Groovy Calamari