com.redhat.lightblue.mongo.crud.UpdateIfSameProtocol Maven / Gradle / Ivy
/*
Copyright 2013 Red Hat, Inc. and/or its affiliates.
This file is part of lightblue.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
package com.redhat.lightblue.mongo.crud;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mongodb.DBObject;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.WriteConcern;
import com.mongodb.BulkWriteOperation;
import com.mongodb.BulkWriteResult;
import com.mongodb.BulkWriteException;
import com.mongodb.BulkWriteError;
import org.bson.types.ObjectId;
import com.redhat.lightblue.util.Error;
/**
* Updates documents in a batch only if they are unmodified from the
* version they were read.
*/
public class UpdateIfSameProtocol implements BatchUpdate {
private static final Logger LOGGER=LoggerFactory.getLogger(MongoSafeUpdateProtocol.class);
/**
* The document version to be assigned to the documents modified by this updater
*/
public final ObjectId docVer=new ObjectId();
/**
* Set of documents and their versions to be updated.
*/
private final Set versions=new HashSet<>();
/**
* A map with docId key, and its corresponding version the value
*/
private final Map