-
-
Save masanobuimai/65645 to your computer and use it in GitHub Desktop.
Grails:楽観ロックのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
String name | |
Long lock_version | |
static transients = [ 'lock_version' ] | |
static constraints = { | |
version validator: { v, o -> !o.lock_version ?: o.lock_version == v } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<g:form method="post"> | |
<input type="hidden" name="id" value="${personInstance?.id}"/> | |
<input type="hidden" name="version" value="${personInstance?.version}"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update = { | |
def personInstance = Person.get(params.id) | |
if (personInstance) { | |
personInstance.properties = params | |
if (!personInstance.hasErrors() && personInstance.save()) { | |
flash.message = "Person ${params.id} updated" | |
redirect(action: show, id: personInstance.id) | |
} | |
else { | |
render(view: 'edit', model: [personInstance: personInstance]) | |
} | |
} | |
else { | |
flash.message = "Person not found with id ${params.id}" | |
redirect(action: edit, id: params.id) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment