Skip to content

Commit 6661207

Browse files
committed
[DE-784] external versioning (#547)
* versionAttribute in document API * tests fix
1 parent 1de6142 commit 6661207

File tree

6 files changed

+825
-0
lines changed

6 files changed

+825
-0
lines changed

Diff for: core/src/main/java/com/arangodb/internal/InternalArangoCollection.java

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public abstract class InternalArangoCollection extends ArangoExecuteable {
5151
private static final String MERGE_OBJECTS = "mergeObjects";
5252
private static final String KEEP_NULL = "keepNull";
5353
private static final String REFILL_INDEX_CACHES = "refillIndexCaches";
54+
private static final String VERSION_ATTRIBUTE = "versionAttribute";
5455
private static final String IGNORE_REVS = "ignoreRevs";
5556
private static final String RETURN_NEW = "returnNew";
5657
private static final String RETURN_OLD = "returnOld";
@@ -103,6 +104,7 @@ private InternalRequest createInsertDocumentRequest(final DocumentCreateOptions
103104
request.putQueryParam(MERGE_OBJECTS, params.getMergeObjects());
104105
request.putQueryParam(KEEP_NULL, params.getKeepNull());
105106
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
107+
request.putQueryParam(VERSION_ATTRIBUTE, params.getVersionAttribute());
106108
request.putHeaderParam(TRANSACTION_ID, params.getStreamTransactionId());
107109
return request;
108110
}
@@ -241,6 +243,7 @@ private InternalRequest createReplaceDocumentRequest(final DocumentReplaceOption
241243
request.putQueryParam(RETURN_OLD, params.getReturnOld());
242244
request.putQueryParam(SILENT, params.getSilent());
243245
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
246+
request.putQueryParam(VERSION_ATTRIBUTE, params.getVersionAttribute());
244247
return request;
245248
}
246249

@@ -303,6 +306,7 @@ private InternalRequest createUpdateDocumentRequest(final DocumentUpdateOptions
303306
request.putQueryParam(RETURN_OLD, params.getReturnOld());
304307
request.putQueryParam(SILENT, params.getSilent());
305308
request.putQueryParam(REFILL_INDEX_CACHES, params.getRefillIndexCaches());
309+
request.putQueryParam(VERSION_ATTRIBUTE, params.getVersionAttribute());
306310
return request;
307311
}
308312

Diff for: core/src/main/java/com/arangodb/model/DocumentCreateOptions.java

+31
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public final class DocumentCreateOptions {
3737
private Boolean mergeObjects;
3838
private Boolean keepNull;
3939
private Boolean refillIndexCaches;
40+
private String versionAttribute;
4041

4142
public DocumentCreateOptions() {
4243
super();
@@ -177,4 +178,34 @@ public DocumentCreateOptions refillIndexCaches(Boolean refillIndexCaches) {
177178
this.refillIndexCaches = refillIndexCaches;
178179
return this;
179180
}
181+
182+
public String getVersionAttribute() {
183+
return versionAttribute;
184+
}
185+
186+
/**
187+
* Only applicable if {@link #overwriteMode(OverwriteMode)} is set to {@link OverwriteMode#update} or
188+
* {@link OverwriteMode#replace}.
189+
* You can use the {@code versionAttribute} option for external versioning support.
190+
* If set, the attribute with the name specified by the option is looked up in the stored document and the attribute
191+
* value is compared numerically to the value of the versioning attribute in the supplied document that is supposed
192+
* to update/replace it.
193+
* If the version number in the new document is higher (rounded down to a whole number) than in the document that
194+
* already exists in the database, then the update/replace operation is performed normally. This is also the case if
195+
* the new versioning attribute has a non-numeric value, if it is a negative number, or if the attribute doesn't
196+
* exist in the supplied or stored document.
197+
* If the version number in the new document is lower or equal to what exists in the database, the operation is not
198+
* performed and the existing document thus not changed. No error is returned in this case.
199+
* The attribute can only be a top-level attribute.
200+
* You can check if _oldRev (if present) and _rev are different to determine if the document has been changed.
201+
*
202+
* @param versionAttribute the attribute name to use for versioning
203+
* @return options
204+
* @since ArangoDB 3.12
205+
*/
206+
public DocumentCreateOptions versionAttribute(String versionAttribute) {
207+
this.versionAttribute = versionAttribute;
208+
return this;
209+
}
210+
180211
}

Diff for: core/src/main/java/com/arangodb/model/DocumentReplaceOptions.java

+29
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final class DocumentReplaceOptions {
3636
private Boolean silent;
3737
private String streamTransactionId;
3838
private Boolean refillIndexCaches;
39+
private String versionAttribute;
3940

4041
public DocumentReplaceOptions() {
4142
super();
@@ -154,4 +155,32 @@ public DocumentReplaceOptions refillIndexCaches(Boolean refillIndexCaches) {
154155
this.refillIndexCaches = refillIndexCaches;
155156
return this;
156157
}
158+
159+
public String getVersionAttribute() {
160+
return versionAttribute;
161+
}
162+
163+
/**
164+
* You can use the {@code versionAttribute} option for external versioning support.
165+
* If set, the attribute with the name specified by the option is looked up in the stored document and the attribute
166+
* value is compared numerically to the value of the versioning attribute in the supplied document that is supposed
167+
* to update/replace it.
168+
* If the version number in the new document is higher (rounded down to a whole number) than in the document that
169+
* already exists in the database, then the update/replace operation is performed normally. This is also the case if
170+
* the new versioning attribute has a non-numeric value, if it is a negative number, or if the attribute doesn't
171+
* exist in the supplied or stored document.
172+
* If the version number in the new document is lower or equal to what exists in the database, the operation is not
173+
* performed and the existing document thus not changed. No error is returned in this case.
174+
* The attribute can only be a top-level attribute.
175+
* You can check if _oldRev (if present) and _rev are different to determine if the document has been changed.
176+
*
177+
* @param versionAttribute the attribute name to use for versioning
178+
* @return options
179+
* @since ArangoDB 3.12
180+
*/
181+
public DocumentReplaceOptions versionAttribute(String versionAttribute) {
182+
this.versionAttribute = versionAttribute;
183+
return this;
184+
}
185+
157186
}

Diff for: core/src/main/java/com/arangodb/model/DocumentUpdateOptions.java

+28
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public final class DocumentUpdateOptions {
3838
private Boolean silent;
3939
private String streamTransactionId;
4040
private Boolean refillIndexCaches;
41+
private String versionAttribute;
4142

4243
public DocumentUpdateOptions() {
4344
super();
@@ -190,4 +191,31 @@ public DocumentUpdateOptions refillIndexCaches(Boolean refillIndexCaches) {
190191
return this;
191192
}
192193

194+
public String getVersionAttribute() {
195+
return versionAttribute;
196+
}
197+
198+
/**
199+
* You can use the {@code versionAttribute} option for external versioning support.
200+
* If set, the attribute with the name specified by the option is looked up in the stored document and the attribute
201+
* value is compared numerically to the value of the versioning attribute in the supplied document that is supposed
202+
* to update/replace it.
203+
* If the version number in the new document is higher (rounded down to a whole number) than in the document that
204+
* already exists in the database, then the update/replace operation is performed normally. This is also the case if
205+
* the new versioning attribute has a non-numeric value, if it is a negative number, or if the attribute doesn't
206+
* exist in the supplied or stored document.
207+
* If the version number in the new document is lower or equal to what exists in the database, the operation is not
208+
* performed and the existing document thus not changed. No error is returned in this case.
209+
* The attribute can only be a top-level attribute.
210+
* You can check if _oldRev (if present) and _rev are different to determine if the document has been changed.
211+
*
212+
* @param versionAttribute the attribute name to use for versioning
213+
* @return options
214+
* @since ArangoDB 3.12
215+
*/
216+
public DocumentUpdateOptions versionAttribute(String versionAttribute) {
217+
this.versionAttribute = versionAttribute;
218+
return this;
219+
}
220+
193221
}

0 commit comments

Comments
 (0)