Skip to content

Commit

Permalink
#325 simple optimistic lock, without error page customization
Browse files Browse the repository at this point in the history
  • Loading branch information
mpostelnicu authored and developster committed Oct 23, 2020
1 parent b15bd17 commit 5c8d64d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ public SaveEditPageButton getSaveEditPageButton() {

@Override
protected void onSubmit(final AjaxRequestTarget target) {
super.onSubmit(target);

final Person person = editForm.getModelObject();
// encode the password
if (person.getChangeProfilePassword()) {
Expand All @@ -218,7 +216,7 @@ protected void onSubmit(final AjaxRequestTarget target) {
person.setChangePasswordNextSignIn(false);
}

jpaService.save(person);
super.onSubmit(target);
setResponsePage(EditUserPage.this.getResponsePage());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@
import nl.dries.wicket.hibernate.dozer.proxy.Proxied;
import org.springframework.data.jpa.domain.AbstractPersistable;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;

/**
* @author mpostelnicu
*
*/
@MappedSuperclass
public class GenericPersistable extends AbstractPersistable<Long> implements Serializable {

@Version
@Column(name = "optlock")
private Integer version;

/**
* Custom serialization for id is needed since Spring Data JPA 2.x AbstractPersistable no longer implements
* Serializable.
Expand All @@ -48,4 +57,8 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot

in.defaultReadObject();
}

public Integer getVersion() {
return version;
}
}
42 changes: 42 additions & 0 deletions persistence/src/main/resources/liquibase-changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,46 @@
<sqlFile path="Person_roles.sql" />
</changeSet>

<changeSet id="#325-optlock" author="mpostelnicu">
<preConditions onFail="CONTINUE">
<columnExists tableName="ADMIN_SETTINGS" columnName="optlock"/>
<columnExists tableName="CATEGORY" columnName="optlock"/>
<columnExists tableName="FILE_CONTENT" columnName="optlock"/>
<columnExists tableName="FILE_METADATA" columnName="optlock"/>
<columnExists tableName="PERSON" columnName="optlock"/>
<columnExists tableName="ROLE" columnName="optlock"/>
<columnExists tableName="STATUS_CHANGED_COMMENT" columnName="optlock"/>
<columnExists tableName="TEST_FORM" columnName="optlock"/>
<columnExists tableName="TEST_FORM_CHILD" columnName="optlock"/>
</preConditions>

<update tableName="ADMIN_SETTINGS">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="CATEGORY">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="FILE_CONTENT">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="FILE_METADATA">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="PERSON">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="ROLE">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="STATUS_CHANGED_COMMENT">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="TEST_FORM">
<column name="optlock" valueNumeric="0"/>
</update>
<update tableName="TEST_FORM_CHILD">
<column name="optlock" valueNumeric="0"/>
</update>
</changeSet>

</databaseChangeLog>

0 comments on commit 5c8d64d

Please sign in to comment.