Skip to content

Commit a7e679d

Browse files
committed
Make Spring lockVersion field more explicits to avoid conflicts. Removed a TODO comment that was done already, Also Make the jacoco verison compatible with Java 25
1 parent 63fc8af commit a7e679d

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

memex/src/main/java/com/johnlpage/memex/VehicleInspection/model/VehicleInspection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public class VehicleInspection {
3636
@Id
3737
Long testid;
3838

39-
@Field("version_field")
39+
@Field("lock_version")
4040
@Version
41-
Long version;
41+
Long lockVersion;
4242

4343
Date testdate;
4444
String testclass;

memex/src/main/java/com/johnlpage/memex/generics/repository/OptimizedMongoLoadRepositoryImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,11 @@ public BulkWriteResult writeMany(
151151
addVersionField(item);
152152
ops.insert(item); // This will throw exceptions on duplicates
153153
} else if (updateStrategy == UpdateStrategy.UPDATE) {
154-
155-
// useSimpleUpdate(item, ops, query); // Unwinds and uses $set - smaller oplog, less
156-
// network
154+
// useSimpleUpdate(item, ops, query);
155+
// Unwinds and uses $set - smaller oplog, less network
157156
// Left in for comparison after we moved to always smart updates
158157
useSmartUpdate(item, ops, query, updateBatchId, false);
159158
} else if (updateStrategy == UpdateStrategy.UPDATEWITHHISTORY) {
160-
// TODO - Version field
161159
useSmartUpdate(item, ops, query, updateBatchId, true);
162160
} else {
163161
// Basic full overwrite can be a little less CPU, but more network/disk
@@ -166,8 +164,9 @@ public BulkWriteResult writeMany(
166164
// If a @Version annotation is in the model, then make sure we set it to 1
167165
// This means that save() will work with it properly
168166
// When we replace we always set version back to 1, this means that a replace
169-
// with the same upstream is a no-op, you really shoudlnt be using save() to update
170-
// somethign you replace from upstream
167+
// with the same upstream is a no-op.
168+
// If someone uses save() to modify then tries to overwrite from
169+
// upstream with Replace that should fail as would cause data loss.
171170

172171
addVersionField(item);
173172
ops.replaceOne(query, item, FindAndReplaceOptions.options().upsert());

memex/templates/model/Model.java.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public class __className__ {
2828
@Id
2929
private __idType__ __idFieldName__;
3030

31-
@Field("version_field")
31+
@Field("lock_version")
3232
@Version
33-
Long version;
33+
Long lockVersion;
3434

3535

3636
/* Use this to flag from the JSON we want to remove the record */

memex/templates/scripts/generate-models-from-json.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ def generateClassContent = { Map classInfo, String pkgName, String collectionNam
574574
sb.append(" * Optimistic locking version field.\n")
575575
sb.append(" * Automatically incremented by Spring Data MongoDB on each save.\n")
576576
sb.append(" */\n")
577-
sb.append(" @Field(\"version_field\")")
577+
sb.append(" @Field(\"lock_version\")")
578578
sb.append(" @Version\n")
579-
sb.append(" private Long version;\n\n")
579+
sb.append(" private Long lockVersion;\n\n")
580580
}
581581

582582
// Regular fields (skip _id as we handle it separately for root)

0 commit comments

Comments
 (0)