Skip to content

Commit bdac855

Browse files
authored
Support for row metadata
Add support for RowMetadata. Add new API in PutRequest, PutResponse, GetResponse, DeleteRequest, DeleteResult, QueryRequest.
1 parent 8f748c0 commit bdac855

File tree

11 files changed

+248
-2
lines changed

11 files changed

+248
-2
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ public DeleteRequest setNamespace(String namespace) {
259259
return this;
260260
}
261261

262+
/**
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.
267+
*
268+
* @param rowMetadata the row metadata
269+
* @throws IllegalArgumentException if rowMetadata not null and invalid
270+
* JSON Object format
271+
*
272+
* @since 5.4.18
273+
* @return this
274+
*/
275+
public DeleteRequest setRowMetadata(String rowMetadata) {
276+
super.setRowMetadata(rowMetadata);
277+
return this;
278+
}
279+
262280
/**
263281
* @hidden
264282
*/

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public long getExistingModificationTime() {
6969
return super.getExistingModificationTimeInternal();
7070
}
7171

72+
73+
/**
74+
* Returns the metadata of the returned row, or null if the row does not
75+
* exist or metadata was not set.
76+
*
77+
* @return the metadata of the row, or null if row does not exist or not set
78+
* @since 5.4.18
79+
*/
80+
public String getExistingRowMetadata() {
81+
return super.getExistingRowMetadataInternal();
82+
}
83+
7284
/* from Result */
7385

7486
/**

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class GetResult extends Result {
2929
private long expirationTime;
3030
private long modificationTime;
3131
private Client client;
32+
private String rowMetadata;
3233

3334
/**
3435
* Returns the value of the returned row, or null if the row does not exist
@@ -105,6 +106,35 @@ public GetResult setValue(MapValue value) {
105106
return this;
106107
}
107108

109+
/**
110+
* Returns the metadata of the returned row, or null if the row does not
111+
* exist or metadata was not set.
112+
*
113+
* @return the metadata of the row, or null if row does not exist or not set
114+
*
115+
* @since 5.4.18
116+
*/
117+
public String getRowMetadata() {
118+
return rowMetadata;
119+
}
120+
121+
/**
122+
* Internal use only.
123+
*
124+
* Sets the rowMetadata of this object.
125+
*
126+
* @param rowMetadata the row metadata
127+
*
128+
* @return this
129+
*
130+
* @since 5.4.18
131+
* @hidden
132+
*/
133+
public GetResult setRowMetadata(String rowMetadata) {
134+
this.rowMetadata = rowMetadata;
135+
return this;
136+
}
137+
108138
/**
109139
* Internal use only.
110140
*

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public PutRequest setValue(MapValue value) {
127127
return this;
128128
}
129129

130-
/**
130+
/**
131131
* Sets the value to use for the put operation based on a JSON string.
132132
* The string is parsed for validity and stored internally as a
133133
* {@link MapValue}.
@@ -437,6 +437,24 @@ public int getIdentityCacheSize() {
437437
return identityCacheSize;
438438
}
439439

440+
/**
441+
* 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.
445+
*
446+
* @param rowMetadata the row metadata
447+
* @throws IllegalArgumentException if rowMetadata not null and invalid
448+
* JSON Object format
449+
*
450+
* @since 5.4.18
451+
* @return this
452+
*/
453+
public PutRequest setRowMetadata(String rowMetadata) {
454+
super.setRowMetadata(rowMetadata);
455+
return this;
456+
}
457+
440458
/**
441459
* Internal use only
442460
*

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public long getExistingModificationTime() {
8383
return super.getExistingModificationTimeInternal();
8484
}
8585

86+
/**
87+
* Returns the metadata of the returned row, or null if the row does not
88+
* exist or metadata was not set.
89+
*
90+
* @return the metadata of the row, or null if row does not exist or not set
91+
*
92+
* @since 5.4.18
93+
*/
94+
public String getExistingRowMetadata() {
95+
return super.getExistingRowMetadataInternal();
96+
}
97+
8698
/* from Result */
8799

88100
/**

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import oracle.nosql.driver.ops.serde.SerializerFactory;
2323
import oracle.nosql.driver.query.QueryDriver;
2424
import oracle.nosql.driver.query.VirtualScan;
25+
import oracle.nosql.driver.values.JsonUtils;
2526

2627
/**
2728
* A request that represents a query. A query may be specified as either a
@@ -155,6 +156,8 @@ public class QueryRequest extends DurableRequest implements AutoCloseable {
155156

156157
private Consistency consistency;
157158

159+
private String rowMetadata;
160+
158161
private String statement;
159162

160163
private PreparedStatement preparedStatement;
@@ -225,6 +228,7 @@ public QueryRequest copyInternal() {
225228
internalReq.maxServerMemoryConsumption = maxServerMemoryConsumption;
226229
internalReq.mathContext = mathContext;
227230
internalReq.consistency = consistency;
231+
internalReq.rowMetadata = rowMetadata;
228232
internalReq.preparedStatement = preparedStatement;
229233
internalReq.isInternal = true;
230234
internalReq.driver = driver;
@@ -243,6 +247,7 @@ public QueryRequest copyInternal() {
243247
public QueryRequest copy() {
244248
QueryRequest internalReq = copyInternal();
245249
internalReq.statement = statement;
250+
internalReq.rowMetadata = rowMetadata;
246251
internalReq.isInternal = false;
247252
internalReq.shardId = -1;
248253
internalReq.driver = null;
@@ -919,6 +924,41 @@ public Consistency getConsistency() {
919924
return consistency;
920925
}
921926

927+
/**
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.
933+
*
934+
* @param rowMetadata the row metadata
935+
* @throws IllegalArgumentException if rowMetadata not null and invalid
936+
* JSON Object format
937+
*
938+
* @return this
939+
* @since 5.4.18
940+
*/
941+
public QueryRequest setRowMetadata(String rowMetadata) {
942+
if (rowMetadata == null) {
943+
this.rowMetadata = null;
944+
return this;
945+
}
946+
947+
JsonUtils.validateJsonObject(rowMetadata);
948+
this.rowMetadata = rowMetadata;
949+
return this;
950+
}
951+
952+
/**
953+
* Returns the consistency set for this request, or null if not set.
954+
*
955+
* @return the consistency
956+
* @since 5.4.18
957+
*/
958+
public String getRowMetadata() {
959+
return rowMetadata;
960+
}
961+
922962
/**
923963
* Sets the request timeout value, in milliseconds. This overrides any
924964
* default value set with {@link NoSQLHandleConfig#setRequestTimeout}.

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import oracle.nosql.driver.NoSQLHandle;
1111
import oracle.nosql.driver.NoSQLHandleConfig;
12+
import oracle.nosql.driver.values.JsonUtils;
1213

1314
/**
1415
* Represents a base class for the single row modifying operations
@@ -17,6 +18,7 @@
1718
public abstract class WriteRequest extends DurableRequest {
1819

1920
private boolean returnRow;
21+
private String rowMetadata;
2022

2123
protected WriteRequest() {}
2224

@@ -51,4 +53,39 @@ protected void validateWriteRequest(String requestName) {
5153
" requires table name"));
5254
}
5355
}
56+
57+
/**
58+
* Returns the row metadata to be used for this request.
59+
*
60+
* @return the metadata, or null if not set
61+
*
62+
* @since 5.4.18
63+
*/
64+
public String getRowMetadata() {
65+
return rowMetadata;
66+
}
67+
68+
/**
69+
* 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,
72+
* otherwise an IllegalArgumentException is thrown.
73+
*
74+
* @param rowMetadata the row metadata
75+
* @throws IllegalArgumentException if rowMetadata not null and invalid
76+
* JSON Object format
77+
*
78+
* @since 5.4.18
79+
* @return this
80+
*/
81+
public WriteRequest setRowMetadata(String rowMetadata) {
82+
if (rowMetadata == null) {
83+
this.rowMetadata = null;
84+
return this;
85+
}
86+
87+
JsonUtils.validateJsonObject(rowMetadata);
88+
this.rowMetadata = rowMetadata;
89+
return this;
90+
}
5491
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class WriteResult extends Result {
1919
private Version existingVersion;
2020
private MapValue existingValue;
2121
private long existingModificationTime;
22+
private String existingRowMetadata;
2223
private Client client;
2324

2425
protected WriteResult() {}
@@ -32,6 +33,16 @@ public Version getExistingVersionInternal() {
3233
return existingVersion;
3334
}
3435

36+
/**
37+
* Returns the associated row metadata
38+
* @return the row metadata or null
39+
* @since 5.4.18
40+
* @hidden
41+
*/
42+
public String getExistingRowMetadataInternal() {
43+
return existingRowMetadata;
44+
}
45+
3546
/**
3647
* internal use only
3748
* @return the value or null
@@ -93,6 +104,19 @@ public WriteResult setExistingModificationTime(
93104
return this;
94105
}
95106

107+
/**
108+
* Internal use only.
109+
*
110+
* @param existingRowMetadata the row metadata
111+
* @return this
112+
* @since 5.4.18
113+
* @hidden
114+
*/
115+
public WriteResult setExistingRowMetadata(String existingRowMetadata) {
116+
this.existingRowMetadata = existingRowMetadata;
117+
return this;
118+
}
119+
96120
/**
97121
* for internal use
98122
* @param client the client

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,14 @@ public class NsonProtocol {
165165
public static String EXPIRATION = "xp";
166166
public static String MODIFIED = "md";
167167
public static String ROW = "r";
168+
public static String ROW_METADATA = "mt";
168169
public static String ROW_VERSION = "rv";
169170

170171
/* operation metadata */
171172
public static String EXISTING_MOD_TIME = "em";
172173
public static String EXISTING_VALUE = "el";
173174
public static String EXISTING_VERSION = "ev";
175+
public static String EXISTING_ROW_METADATA = "ed";
174176
public static String GENERATED = "gn";
175177
public static String RETURN_INFO = "ri";
176178

@@ -326,10 +328,12 @@ public class NsonProtocol {
326328
{EXPIRATION,"EXPIRATION"},
327329
{MODIFIED,"MODIFIED"},
328330
{ROW,"ROW"},
331+
{ROW_METADATA,"ROW_METADATA"},
329332
{ROW_VERSION,"ROW_VERSION"},
330333
{EXISTING_MOD_TIME,"EXISTING_MOD_TIME"},
331334
{EXISTING_VALUE,"EXISTING_VALUE"},
332335
{EXISTING_VERSION,"EXISTING_VERSION"},
336+
{EXISTING_ROW_METADATA,"EXISTING_ROW_METADATA"},
333337
{GENERATED,"GENERATED"},
334338
{RETURN_INFO,"RETURN_INFO"},
335339
{DRIVER_QUERY_PLAN,"DRIVER_QUERY_PLAN"},

0 commit comments

Comments
 (0)