Skip to content

Commit 93d0b0a

Browse files
authored
Added Version.createVersion(byte[]) to create Version from query results
1 parent 8178fcf commit 93d0b0a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ query in an iterable/iterator format. The returned QueryIterableResult should
1010
be used in a try-with-resources statement to ensure proper closing of
1111
resources.
1212
- updated NoSQLHandle and QueryRequest interfaces to extend AutoClosable
13+
- added Version.createVersion(byte[]) to allow creation of a Version object from a
14+
query that returns row_version() as a BinaryValue. The Version can be used for
15+
conditional put and delete operations
1316
- added support for setting an extension to the User Agent http header by
1417
setting the ExtensionUserAgent property on NoSQLHandlerConfig.
1518

driver/src/main/java/oracle/nosql/driver/Version.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public byte[] getBytes() {
3737
}
3838

3939
/**
40-
* @hidden
40+
* Creates a Version instance from a byte[] which may have been acquired
41+
* from a query using the row_version() function which returns a FieldValue
42+
* of type BINARY.
43+
*
4144
* @param version the version to use
4245
* @return a new Version instance
4346
*/

driver/src/test/java/oracle/nosql/driver/BasicTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,27 @@ public void testPutGetDelete() {
797797
(serialVersion > 2), /* modtime should be recent */
798798
recordKB);
799799

800+
/* save this for comparison below */
801+
Version version = getRes.getVersion();
802+
803+
/*
804+
* get the row version of the same row using a query and assert
805+
* that the versions are the same. A test could be created to use this
806+
* in a condition put/delete operation but that functionality is already
807+
* tested. This just ensures that the versions acquired from get()
808+
* and from row_version are identical
809+
*/
810+
try (QueryRequest queryReq = new QueryRequest()) {
811+
final String versionQuery = "select row_version($t) as version " +
812+
"from " + tableName + " $t where id = 10";
813+
queryReq.setStatement(versionQuery);
814+
QueryResult queryRet = handle.query(queryReq);
815+
MapValue result = queryRet.getResults().get(0);
816+
Version qVersion = Version.createVersion(
817+
result.get("version").asBinary().getValue());
818+
assertArrayEquals(version.getBytes(), qVersion.getBytes());
819+
}
820+
800821
/* Get a row with ABSOLUTE consistency */
801822
getReq.setConsistency(Consistency.ABSOLUTE);
802823
getRes = handle.get(getReq);

0 commit comments

Comments
 (0)