Table.checkAndDelete()

Deletes a document, if that document satisfies the conditions that are specified in a QueryCondition object.

Operations Performed

  1. 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.
  2. Evaluates the specified condition on the document.
    • If the evaluation returns false, returns false.
    • If the evaluation returns true, deletes the document.

Example Document and Code

Example 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()
        .and()
          .is("studio", Op.EQUAL, "MapR Technologies, Inc.",
          .is("release_date", Op.GREATER_OR_EQUAL, Values.parseDate("2015-01-01"))
          .is("release_date", Op.LESS_OR_EQUAL, Values.parseDate("2015-12-31"))
        .close()
      .build();
  }


  public Document buildDocument() {
    return MapRDB.newDocument()
        .setId("movie0000001")
        .set("title", "OJAI -- The Documentary")
        .set("studio", "MapR Technologies, Inc.")
        .set("release_date", Values.parseDate("2015-09-29"))
        .set("trailers.teaser", "https://10.10.21.90/trailers/teaser")
        .set("trailers.theatrical", "https://10.10.21.90/trailers/theatrical")
        .setArray("characters", ImmutableList.of("Heroic Developer", "Evil Release Manager", "Mad Development Manager"))
        .set("box_office_gross", 1000000000L);
  }

  public void replaceIfTrue(String tablePath, 
      QueryCondition condition, String _id) {
    try(Table table = MapRDB.getTable(tablePath)) {
      if (table.checkAndDelete(_id, condition)) {
        System.out.println("Condition matched, delete succeeded");
      } else {
        System.out.println("Condition did not match, delete failed");
      }
    }
  }
Parameter Description
_id The value of the document's _id field.
condition The query condition to evaluate on the row.

Permissions Required

  • The readAce and writeAce 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 and writeperm on the column families in the row.

Link to Javadoc

MapR-DB JSON Java API