Skip to content

Instantly share code, notes, and snippets.

@arcesino
arcesino / Grails-withOptimisticLocking
Created March 22, 2014 22:16
A dynamic method for deal with Optimistic Locking in Grails with retries & timeout. Please consider the following for a correct usage: 1) Call withOptimisticLocking outside any transaction, 2) Ensure only one transaction is created inside withOptimisticLocking
grailsClass.metaClass.withOptimisticLocking = { Long timeout = 3000L, Closure cls ->
def startTime = new Date().time
def duration = 0
def attempts = 0
while (true) {
try {
attempts++
cls.call()
break
} catch (OptimisticLockingFailureException e) {
@arcesino
arcesino / sublime-text-3-key-bindings
Last active August 29, 2015 13:57
My own Sublime Text key bindings
[
{ "keys": ["super+shift+k"], "command": "reveal_in_side_bar"}
]
@arcesino
arcesino / subime-text-3-settings
Last active August 29, 2015 13:57
My own Sublime Text settings
{
"color_scheme": "Packages/User/Solarized (Dark) (SL).tmTheme",
"ensure_newline_at_eof_on_save": true,
"ignored_packages":
[
"Vintage"
],
"save_on_focus_lost": true,
"tab_size": 2,
"translate_tabs_to_spaces": true,
@arcesino
arcesino / gist:5775620
Last active December 18, 2015 11:29
Projections + join with HQL query
/* Why HQL?
Cause:
* Criteria + projections + join = "joins are ignored"
* Criteria + projections + forced join = "joins not ignored but joined tables are fetched lazy"
* HQL do not need explicit join clauses; joins are inferred automatically for one-to-one & many-to-one associations
* GORM criteria is buggy
*/
@arcesino
arcesino / SkuProfilesController.groovy
Last active May 3, 2017 16:39
Grails: Split & bind comma separated string to List<String>
class SkuProfilesController {
def skuProfileService
def show() {
paramsSplit(['ids', 'fields'])
def cmd = bindData(new ListSkuProfilesCommand(), params)
if (!cmd.validate()) {
throw new EntityValidationException(cmd.errors)
}