Table.checkAndMutate()
Applies changes from a DocumentMutation
object to a document, if the
document satisfies conditions that are specified in a QueryCondition
object.
Operations Performed
- Verifies that the document with the specified ID exists.
- If the ID does not exist, returns false.
- If the ID does exist, proceeds to step 2.
- Evaluates the specified condition on the document.
- If the evaluation returns false, returns false.
- If the evaluation returns true, applies a mutation to the document.
Example Document and Code
- Original document
-
{ "_id" : "movie0000001", "title" : "OJAI -- The Documentary", "studio" : "MapR Technologies, Inc.", "release_date" : "2015-09-29", "trailers" : { "teaser" : "https://10.10.21.90/trailers/teaser", "theatrical" : "https://10.10.21.90/trailers/theatrical" }, "characters" : [ "Heroic Developer", "Evil Release Manager", "Mad Development Manager" ], "box_office_gross" : 1000000000L }
- Example code
-
public QueryCondition buildQueryCondition() { return MapRDB.newCondition() .is("title", Op.EQUAL, "OJAI -- The Documentary") .close() .build(); } public DocumentMutation buildDocumentMutation() { return MapRDB.newDocumentMutation() .increment("box_office_gross", 1000000000L); } public void mutateIfTrue(String tablePath, QueryCondition condition, DocumentMutation mutation, String _id) { try(Table table = MapRDB.getTable(tablePath)) { if (table.checkAndMutate(_id, condition, mutation)) { System.out.println("Condition matched, mutation succeeded"); } else { System.out.println("Condition did not match, mutation failed"); } } }
Parameter Description _id
The value of the document's _id
field.condition
The query condition to evaluate on the row. mutation
The mutation to apply on the row. - Revised document with change in bold
-
{ "_id" : "movie0000001", "title" : "OJAI -- The Documentary", "studio" : "MapR Technologies, Inc.", "release_date" : "2015-09-29", "trailers" : { "teaser" : "https://10.10.21.90/trailers/teaser", "theatrical" : "https://10.10.21.90/trailers/theatrical" }, "characters" : [ "Heroic Developer", "Evil Release Manager", "Mad Development Manager" ], "box_office_gross" : 2000000000L }
Permissions Required
- The
readAce
andwriteAce
permissions on the volumes where the JSON tables that contain the documents are located. For information about how to set permissions on volumes, see Setting/Modifying Whole Volume ACEs. readperm
andwriteperm
on the column families in the row.
QueryCondition
includes a condition on the _id
field, the user ID calling Table.checkAndMutate()
must have the
readperm
permission on all column families in the documents that meet the
condition.