package org.cbioportal.genome_nexus.persistence.internal;

import com.mongodb.BulkWriteOperation;
import com.mongodb.DBObject;
import org.cbioportal.genome_nexus.persistence.GenericMongoRepository;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.List;

public abstract class BaseGenericMongoRepository implements GenericMongoRepository
{
    protected final MongoTemplate mongoTemplate;

    public BaseGenericMongoRepository(MongoTemplate mongoTemplate)
    {
        this.mongoTemplate = mongoTemplate;
    }

    @Override
    public void saveDBObjects(String collection, List<DBObject> dbObjects)
    {
        // nothing to save, abort
        if (dbObjects == null || dbObjects.size() == 0) {
            return;
        }

        BulkWriteOperation bulkWriteOperation =
            this.mongoTemplate.getCollection(collection).initializeUnorderedBulkOperation();

        for (DBObject dbObject: dbObjects) {
            bulkWriteOperation.insert(dbObject);
        }

        bulkWriteOperation.execute();
    }
}

@@ -56,47 +56,8 @@
 l;%0A%0A
-import com.mongodb.BulkWriteOperation;%0A
 impo
@@ -606,404 +606,208 @@
  // 
-nothing to save, abort%0A        if (dbObjects == null %7C%7C dbObjects.size() == 0) %7B%0A            return;%0A        %7D%0A%0A        BulkWriteOperation bulkWriteOperation =%0A            this.mongoTemplate.getCollection(collection).initializeUnorderedBulkOperation();%0A%0A        for (DBObject dbObject: dbObjects) %7B%0A            bulkWriteOperation.insert(dbObject);%0A        %7D%0A%0A        bulkWriteOperation.execute();
+TODO use bulk save instead!%0A        for (DBObject dbObject: dbObjects) %7B%0A            // save the object into the correct repository%0A            this.mongoTemplate.save(dbObject, collection);%0A        %7D
 %0A   

Revert "using bulk save when saving to mongo (fix #174)"