Skip to content

Commit

Permalink
#19 Optimistic locking adding version to other data objects
Browse files Browse the repository at this point in the history
  • Loading branch information
spuliaiev-sfdc committed Jul 12, 2018
1 parent 4030c8d commit 3981bd0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
Expand Down Expand Up @@ -64,10 +65,13 @@ public class FileInformation implements Comparable<FileInformation> {
private Set<String> indexProcessIds = new HashSet<>();

@CreatedDate
private DateTime indexed;
private DateTime created;
@LastModifiedDate
private DateTime updated;

@Version
private long version = 0;

public void updateTimestamp() {
if (CollectionUtils.isEmpty(timestamps)) {
this.timestamp = null;
Expand Down Expand Up @@ -134,7 +138,7 @@ public <FI extends FileInformation> void copyFrom(FI sourceToMatch) {
indexProcessIds = new HashSet<>();
indexProcessIds.addAll(sourceToMatch.getIndexProcessIds());

indexed = sourceToMatch.getIndexed();
created = sourceToMatch.getCreated();
updated = sourceToMatch.getUpdated();
}

Expand Down
12 changes: 12 additions & 0 deletions core/beans/src/main/java/gallerymine/model/GeoCodePlace.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package gallerymine.model;

import lombok.Data;
import org.joda.time.DateTime;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.geo.GeoJsonPolygon;
import org.springframework.data.mongodb.core.mapping.Document;
Expand Down Expand Up @@ -29,6 +33,14 @@ public class GeoCodePlace {
/** 0- Country, 1-State, 2-county, 3-city */
public int level = 0;

@CreatedDate
private DateTime created;
@LastModifiedDate
private DateTime updated;

@Version
private long version = 0;

public GeoCodePlace() {

}
Expand Down
4 changes: 4 additions & 0 deletions core/beans/src/main/java/gallerymine/model/Process.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.ArrayList;
Expand Down Expand Up @@ -41,6 +42,9 @@ public class Process {
@LastModifiedDate
private DateTime updated;

@Version
private long version = 0;


public String addError(String error, Object... params) {
if (params!= null && params.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import gallerymine.model.GeoPoint;
import lombok.Data;
import org.joda.time.DateTime;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
Expand Down Expand Up @@ -30,6 +34,14 @@ public enum RequestStatus {
@Indexed
private RequestStatus status = FOUND;

@CreatedDate
private DateTime created;
@LastModifiedDate
private DateTime updated;

@Version
private long version = 0;

public GeoCodeRequest() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.joda.time.DateTime;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
Expand All @@ -28,6 +30,11 @@ public class ThumbRequest {

@CreatedDate
private DateTime created;
@LastModifiedDate
private DateTime updated;

@Version
private long version = 0;

public ThumbRequest() {
}
Expand Down

0 comments on commit 3981bd0

Please sign in to comment.