From 3981bd0380b162aaaf43f6474215ce0309fbe542 Mon Sep 17 00:00:00 2001 From: Sergii Date: Wed, 11 Jul 2018 21:48:06 -0700 Subject: [PATCH] #19 Optimistic locking adding version to other data objects --- .../main/java/gallerymine/model/FileInformation.java | 8 ++++++-- .../main/java/gallerymine/model/GeoCodePlace.java | 12 ++++++++++++ .../src/main/java/gallerymine/model/Process.java | 4 ++++ .../gallerymine/model/importer/GeoCodeRequest.java | 12 ++++++++++++ .../gallerymine/model/importer/ThumbRequest.java | 7 +++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/core/beans/src/main/java/gallerymine/model/FileInformation.java b/core/beans/src/main/java/gallerymine/model/FileInformation.java index 2d0cdc2..50f0cf4 100644 --- a/core/beans/src/main/java/gallerymine/model/FileInformation.java +++ b/core/beans/src/main/java/gallerymine/model/FileInformation.java @@ -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; @@ -64,10 +65,13 @@ public class FileInformation implements Comparable { private Set 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; @@ -134,7 +138,7 @@ public void copyFrom(FI sourceToMatch) { indexProcessIds = new HashSet<>(); indexProcessIds.addAll(sourceToMatch.getIndexProcessIds()); - indexed = sourceToMatch.getIndexed(); + created = sourceToMatch.getCreated(); updated = sourceToMatch.getUpdated(); } diff --git a/core/beans/src/main/java/gallerymine/model/GeoCodePlace.java b/core/beans/src/main/java/gallerymine/model/GeoCodePlace.java index 039a90f..4b550b1 100644 --- a/core/beans/src/main/java/gallerymine/model/GeoCodePlace.java +++ b/core/beans/src/main/java/gallerymine/model/GeoCodePlace.java @@ -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; @@ -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() { } diff --git a/core/beans/src/main/java/gallerymine/model/Process.java b/core/beans/src/main/java/gallerymine/model/Process.java index 5d434c0..4fcec4a 100644 --- a/core/beans/src/main/java/gallerymine/model/Process.java +++ b/core/beans/src/main/java/gallerymine/model/Process.java @@ -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; @@ -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) { diff --git a/core/beans/src/main/java/gallerymine/model/importer/GeoCodeRequest.java b/core/beans/src/main/java/gallerymine/model/importer/GeoCodeRequest.java index 38f0a79..3e8af73 100644 --- a/core/beans/src/main/java/gallerymine/model/importer/GeoCodeRequest.java +++ b/core/beans/src/main/java/gallerymine/model/importer/GeoCodeRequest.java @@ -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; @@ -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() { } diff --git a/core/beans/src/main/java/gallerymine/model/importer/ThumbRequest.java b/core/beans/src/main/java/gallerymine/model/importer/ThumbRequest.java index 3e0c51c..75e4821 100644 --- a/core/beans/src/main/java/gallerymine/model/importer/ThumbRequest.java +++ b/core/beans/src/main/java/gallerymine/model/importer/ThumbRequest.java @@ -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; @@ -28,6 +30,11 @@ public class ThumbRequest { @CreatedDate private DateTime created; + @LastModifiedDate + private DateTime updated; + + @Version + private long version = 0; public ThumbRequest() { }