Skip to content

Commit bcb0416

Browse files
authored
Add rowMetadat to multi delete request
* Fix rowMetadata on a multiDelete operation. * Allow JSON constructs rather than only JSON Object. * Fixed warnings, removed unused code/comments.
1 parent 35670c9 commit bcb0416

File tree

9 files changed

+98
-33
lines changed

9 files changed

+98
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1313
- QueryRequest.get/setNumberOfOperations()
1414
- QueryRequest.get/setOperationNumber()
1515
- Added new cloud region codes: hsg, abl, dfw, pbv, nbq, ibg, pcz, mez, den, kal
16-
- Added rowMetadata support, new API for Get/Put/Delete request and result
16+
- Added rowMetadata support, new API for Get/Put/Delete/MultiDelete request and result
1717
get/set RomMetadata.
1818
- Added row creation time support, new API: GetResult getCreationTime(),
1919
Put/Delete/Write/WriteMultiple Result getExistingCreationTime().

driver/src/main/java/oracle/nosql/driver/ops/DeleteRequest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,20 @@ public DeleteRequest setNamespace(String namespace) {
260260
}
261261

262262
/**
263-
* Sets the row metadata to use for this request.
264-
* This is an optional parameter.
265-
* The @parameter rowMetadata must be in a JSON Object format or null,
266-
* otherwise an IllegalArgumentException is thrown.
263+
* Sets the row metadata to use for this request. This is an optional
264+
* parameter.<p>
265+
*
266+
* Row metadata is associated to a certain version of a row. Any subsequent
267+
* write operation will use its own row metadata value. If not specified
268+
* null will be used by default.<p>
269+
*
270+
* The @parameter rowMetadata must be null or a valid JSON construct:
271+
* object, array, string, number, true, false or null, otherwise an
272+
* IllegalArgumentException is thrown.
267273
*
268274
* @param rowMetadata the row metadata
269275
* @throws IllegalArgumentException if rowMetadata not null and invalid
270-
* JSON Object format
276+
* JSON construct
271277
*
272278
* @since 5.4.18
273279
* @return this

driver/src/main/java/oracle/nosql/driver/ops/DurableRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected void setDurabilityInternal(Durability durability) {
2727
* Returns the durability setting for this operation.
2828
* On-prem only.
2929
*
30-
* @return durability, if set. Otherwise null.
30+
* @return durability, if set, otherwise null.
3131
*/
3232
public Durability getDurability() {
3333
return durability;

driver/src/main/java/oracle/nosql/driver/ops/MultiDeleteRequest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import oracle.nosql.driver.iam.SignatureProvider;
1414
import oracle.nosql.driver.ops.serde.Serializer;
1515
import oracle.nosql.driver.ops.serde.SerializerFactory;
16+
import oracle.nosql.driver.values.JsonUtils;
1617
import oracle.nosql.driver.values.MapValue;
1718

1819
/**
@@ -22,7 +23,7 @@
2223
* <p>
2324
* A range is specified using a partial key plus a range based on the
2425
* portion of the key that is not provided. For example if a table's primary key
25-
* is &lt;id, timestamp&gt; and the its shard key is the id, it is possible
26+
* is &lt;id, timestamp&gt; and its shard key is the id, it is possible
2627
* to delete a range of timestamp values for a specific id by providing an id
2728
* but no timestamp in the value used for {@link #setKey} and providing a range
2829
* of timestamp values in the {@link FieldRange} used in {@link #setRange}.
@@ -41,6 +42,7 @@ public class MultiDeleteRequest extends DurableRequest {
4142
private byte[] continuationKey;
4243
private FieldRange range;
4344
private int maxWriteKB;
45+
private String rowMetadata;
4446

4547
/**
4648
* Cloud service only.
@@ -232,6 +234,46 @@ public MultiDeleteRequest setNamespace(String namespace) {
232234
return this;
233235
}
234236

237+
/**
238+
* Sets the row metadata to use for the operation. This is an optional
239+
* parameter.<p>
240+
*
241+
* Row metadata is associated to a certain version of a row. Any subsequent
242+
* write operation will use its own row metadata value. If not specified
243+
* null will be used by default.<p>
244+
*
245+
* The @parameter rowMetadata must be null or a valid JSON construct:
246+
* object, array, string, number, true, false or null, otherwise an
247+
* IllegalArgumentException is thrown.
248+
*
249+
* @param rowMetadata the row metadata
250+
* @throws IllegalArgumentException if rowMetadata not null and invalid
251+
* JSON construct
252+
*
253+
* @return this
254+
* @since 5.4.18
255+
*/
256+
public MultiDeleteRequest setRowMetadata(String rowMetadata) {
257+
if (rowMetadata == null) {
258+
this.rowMetadata = null;
259+
return this;
260+
}
261+
262+
JsonUtils.validateJsonConstruct(rowMetadata);
263+
this.rowMetadata = rowMetadata;
264+
return this;
265+
}
266+
267+
/**
268+
* Returns the row metadata set for this request, or null if not set.
269+
*
270+
* @return the row metadata
271+
* @since 5.4.18
272+
*/
273+
public String getRowMetadata() {
274+
return rowMetadata;
275+
}
276+
235277
/**
236278
* @hidden
237279
*/

driver/src/main/java/oracle/nosql/driver/ops/PutRequest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,19 @@ public int getIdentityCacheSize() {
439439

440440
/**
441441
* Sets the row metadata to use for this request.
442-
* This is an optional parameter.
443-
* The @parameter rowMetadata must be in a JSON Object format or null,
444-
* otherwise an IllegalArgumentException is thrown.
442+
* This is an optional parameter.<p>
443+
*
444+
* Row metadata is associated to a certain version of a row. Any subsequent
445+
* write operation will use its own row metadata value. If not specified
446+
* null will be used by default.<p>
447+
*
448+
* The @parameter rowMetadata must be null or a valid JSON construct:
449+
* object, array, string, number, true, false or null, otherwise an
450+
* IllegalArgumentException is thrown.
445451
*
446452
* @param rowMetadata the row metadata
447453
* @throws IllegalArgumentException if rowMetadata not null and invalid
448-
* JSON Object format
454+
* JSON construct
449455
*
450456
* @since 5.4.18
451457
* @return this

driver/src/main/java/oracle/nosql/driver/ops/QueryRequest.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -925,15 +925,22 @@ public Consistency getConsistency() {
925925
}
926926

927927
/**
928-
* Sets the row metadata to use for the operation. This setting only applies
929-
* if the query modifies any rows using an INSERT, UPDATE or UPSERT statement.
930-
* If the query is read-only this option is ignored.
931-
* The @parameter rowMetadata must be in a JSON Object format or null,
932-
* otherwise an IllegalArgumentException is thrown.
928+
* Sets the row metadata to use for the operation. This setting is optional
929+
* and only applies if the query modifies or deletes any rows using an
930+
* INSERT, UPDATE, UPSERT or DELETE statement. If the query is read-only
931+
* this setting is ignored.<p>
932+
*
933+
* Row metadata is associated to a certain version of a row. Any subsequent
934+
* write operation will use its own row metadata value. If not specified
935+
* null will be used by default.<p>
936+
*
937+
* The @parameter rowMetadata must be null or a valid JSON construct:
938+
* object, array, string, number, true, false or null, otherwise an
939+
* IllegalArgumentException is thrown.
933940
*
934941
* @param rowMetadata the row metadata
935942
* @throws IllegalArgumentException if rowMetadata not null and invalid
936-
* JSON Object format
943+
* JSON construct
937944
*
938945
* @return this
939946
* @since 5.4.18
@@ -944,15 +951,15 @@ public QueryRequest setRowMetadata(String rowMetadata) {
944951
return this;
945952
}
946953

947-
JsonUtils.validateJsonObject(rowMetadata);
954+
JsonUtils.validateJsonConstruct(rowMetadata);
948955
this.rowMetadata = rowMetadata;
949956
return this;
950957
}
951958

952959
/**
953-
* Returns the consistency set for this request, or null if not set.
960+
* Returns the row metadata set for this request, or null if not set.
954961
*
955-
* @return the consistency
962+
* @return the row metadata
956963
* @since 5.4.18
957964
*/
958965
public String getRowMetadata() {

driver/src/main/java/oracle/nosql/driver/ops/WriteRequest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ public String getRowMetadata() {
6767

6868
/**
6969
* Sets the row metadata to use for this request.
70-
* This is an optional parameter.
71-
* The @parameter rowMetadata must be in a JSON Object format or null,
70+
* This is an optional parameter.<p>
71+
*
72+
* Row metadata is associated to a certain version of a row. Any subsequent
73+
* write operation will use its own row metadata value. If not specified
74+
* null will be used by default.<p>
75+
*
76+
* The @parameter rowMetadata must be null or in a valid JSON construct:
77+
* object, array, string, number, true, false or null,
7278
* otherwise an IllegalArgumentException is thrown.
7379
*
7480
* @param rowMetadata the row metadata
@@ -84,7 +90,7 @@ public WriteRequest setRowMetadata(String rowMetadata) {
8490
return this;
8591
}
8692

87-
JsonUtils.validateJsonObject(rowMetadata);
93+
JsonUtils.validateJsonConstruct(rowMetadata);
8894
this.rowMetadata = rowMetadata;
8995
return this;
9096
}

driver/src/main/java/oracle/nosql/driver/ops/serde/nson/NsonSerializerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ public void serialize(Request request,
646646
writeContinuationKey(ns, rq.getContinuationKey());
647647
writeFieldRange(ns, rq.getRange());
648648
writeKey(ns, rq);
649+
writeMapField(ns, ROW_METADATA, rq.getRowMetadata());
649650
endMap(ns, PAYLOAD);
650651
ns.endMap(0); // top level object
651652
}

driver/src/main/java/oracle/nosql/driver/values/JsonUtils.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,34 +760,31 @@ public static String convertBytesToHex(byte[] byteArray) {
760760
}
761761

762762
/**
763-
* Validates input is a valid jsonObject. Throws IllegalArgumentException if
764-
* not. Number, string, null, boolean or array alone are not allowed.
763+
* Validates input is a valid JSON construct: object, array, string, number,
764+
* true, false or null. Throws IllegalArgumentException if not valid.
765765
* Multiple JSON Objects are not allowed. Strings must use only double
766766
* quotes (").
767767
*/
768-
public static void validateJsonObject(String jsonInput) {
768+
public static void validateJsonConstruct(String jsonInput) {
769769
try (JsonParser jp = createParserWithOptions(jsonInput, null)) {
770770
JsonToken token = jp.nextToken();
771-
if (token == null || !JsonToken.START_OBJECT.equals(token)) {
772-
throw new IllegalArgumentException("Not a JSON Object");
771+
if (token == null) {
772+
throw new IllegalArgumentException("Value is not a valid JSON construct.");
773773
}
774774
int s = 1;
775775
while (!jp.isClosed()) {
776776
token = jp.nextToken();
777777
if (token != null && JsonToken.START_OBJECT.equals(token)) {
778778
if (s == 0) {
779779
throw new IllegalArgumentException("Multiple JSON " +
780-
"Objects not allowed");
780+
"Objects not allowed.");
781781
}
782782
s++;
783783
}
784784
if (token != null && JsonToken.END_OBJECT.equals(token)) {
785785
s--;
786786
}
787787
}
788-
if (token != null && !JsonToken.END_OBJECT.equals(token)) {
789-
throw new IllegalArgumentException("Not a JSON Object end");
790-
}
791788
} catch (IOException ioe) {
792789
throw new IllegalArgumentException("JSON parse failed: " + ioe);
793790
} catch (JsonParseException jpe) {

0 commit comments

Comments
 (0)