Add-on to create the JPA extension that enables versioning by comparing the old and new entity state without the need to alter legacy database tables with version columns.
The bundle symbolic name for this add-on is org.gvnix.occ.roo.addon . To install it, read the installation guide.
Introduction
Concurrency is a critical or at least a very important issue for most enterprise applications. For example, two users read the same row from the Invoice table, they both change the data, and then they both try to write their new versions back to the database. Whose changes should be saved?
JPA uses versioning to control concurrent data access optimistically. However, to enable versioning for a particular entity, you have to add a version property and related column to database table.
Unfortunately, enterprise database schemas are often static and cannot be modified. This situation is a serious problem for JPA-based application because the JPA standard doesn't cover optimistic versioning without a version attribute.
Use gvNIX OCC addon to solve this problem, it will create the JPA extension that enables versioning by comparing the old and new entity state without the need to alter legacy databases.
Use case: OCC support in Pet clinic
Create a new directory for the project:
Bash shell:
Code:
mkdir clinic
cd clinic
Start gvNIX:
Code:
clinic$ gvnix.sh
____ ____ ____
/ __ \/ __ \/ __ \
/ /_/ / / / / / / /
/ _, _/ /_/ / /_/ / X.X.X.RELEASE [rev xxxxxxx]
/_/ |_|\____/\____/ gvNIX distribution X.X.X
Welcome to Spring Roo. For assistance press TAB or type "hint" then hit ENTER.
roo>
Create the project:
Code:
roo> script clinic.roo
Set concurrency control on Pet entity:
Code:
roo> occ checksum set --entity ~.domain.Pet
Updated ROOT/pom.xml [Added dependency org.gvnix:org.gvnix.occ.roo.addon:X.X.X]
Updated SRC_MAIN_JAVA/com/springsource/petclinic/domain/Pet.java
Created SRC_MAIN_JAVA/com/springsource/petclinic/domain/Pet_Roo_gvNIX_occChecksum.aj
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/list.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/show.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/create.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/update.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/i18n/application.properties
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/list.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/show.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/create.jspx
Updated SRC_MAIN_WEBAPP/WEB-INF/views/pets/update.jspx
Updated SRC_MAIN_JAVA/com/springsource/petclinic/domain/Pet_Roo_Entity.aj
Updated SRC_MAIN_JAVA/com/springsource/petclinic/domain/Pet_Roo_ToString.aj
Updated SRC_TEST_JAVA/com/springsource/petclinic/domain/PetIntegrationTest_Roo_IntegrationTest.aj
[Spring Roo Process Manager Background Polling Thread] Updated SRC_MAIN_JAVA/com/springsource/petclinic/domain/Pet_Roo_ToString.aj
Be aware some tests no longer will work. This will be an enhancement in next gvNIX versions.
To test application:
- Run with mvn tomcat:run
- Create a Pet
- Open new Pet update page into two tabs
- Update Pet name into first tab
- Update Pet name into first tab
You obtain a message error: Pet has been changed (id: 1).
More info at:
- English: http://gvnix.googlecode.com
- Spanish: http://www.gvnix.org