Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
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.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mongodb.MongoException;
import com.mongodb.BasicDBObject;
import com.mongodb.BulkWriteError;
import com.mongodb.BulkWriteException;
import com.mongodb.BulkWriteOperation;
import com.mongodb.BulkWriteResult;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.WriteConcern;
import com.mongodb.ReadPreference;
import com.redhat.lightblue.crud.ListDocumentStream;
import com.redhat.lightblue.crud.CRUDDeleteResponse;
import com.redhat.lightblue.crud.CRUDOperation;
import com.redhat.lightblue.crud.CRUDOperationContext;
import com.redhat.lightblue.crud.DocCtx;
import com.redhat.lightblue.interceptor.InterceptPoint;
import com.redhat.lightblue.util.Error;
/**
* Basic document deletion with no transaction support
*/
public class BasicDocDeleter implements DocDeleter {
private static final Logger LOGGER = LoggerFactory.getLogger(BasicDocDeleter.class);
// TODO: move this to a better place
public final int batchSize;
// Use in tests. Set to false to test deletion with bulk operations
public boolean hookOptimization=true;
private final DocTranslator translator;
private final WriteConcern writeConcern;
public BasicDocDeleter(DocTranslator translator, WriteConcern writeConcern, int batchSize) {
super();
this.translator = translator;
this.writeConcern = writeConcern;
this.batchSize = batchSize;
}
@Override
public void delete(CRUDOperationContext ctx,
DBCollection collection,
DBObject mongoQuery,
CRUDDeleteResponse response) {
LOGGER.debug("Removing docs with {}", mongoQuery);
int numDeleted = 0;
if(!hookOptimization||ctx.getHookManager().hasHooks(ctx,CRUDOperation.DELETE)) {
LOGGER.debug("There are hooks, retrieve-delete");
try (DBCursor cursor = collection.find(mongoQuery, null)) {
// Set read preference to primary for read-for-update operations
cursor.setReadPreference(ReadPreference.primary());
// All docs, to be put into the context
ArrayList contextDocs=new ArrayList<>();
// ids to delete from the db
List