All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nosqlbench.adapter.mongodb.dispensers.MongoDbUpdateOpDispenser Maven / Gradle / Ivy

/*
 * Copyright (c) 2022 nosqlbench
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.nosqlbench.adapter.mongodb.dispensers;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import io.nosqlbench.adapter.mongodb.core.MongoSpace;
import io.nosqlbench.adapter.mongodb.core.MongodbDriverAdapter;
import io.nosqlbench.engine.api.activityimpl.BaseOpDispenser;
import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.Op;
import io.nosqlbench.engine.api.templating.ParsedOp;

import java.util.function.LongFunction;

/**
 * https://www.mongodb.com/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update
 * https://www.mongodb.com/docs/drivers/java/sync/current/usage-examples/updateOne/
 */
public class MongoDbUpdateOpDispenser extends BaseOpDispenser {
    private final LongFunction spaceF;
    private final LongFunction opF;
    private LongFunction collectionF;

    public MongoDbUpdateOpDispenser(MongodbDriverAdapter adapter, ParsedOp pop, LongFunction collectionF) {
        super(adapter, pop);
        this.collectionF = collectionF;
        this.spaceF = adapter.getSpaceFunc(pop);
        this.opF = createOpF(pop);
    }

    private LongFunction createOpF(ParsedOp pop) {
        LongFunction clientF = cycle -> spaceF.apply(cycle).getClient();

        LongFunction docF = l -> clientF.apply(l).getDatabase(collectionF.apply(l));
//        docF.apply(1).getCollection()
//        LongFunctionclientF.apply(l).getDatabase()

        return l -> new Op() {};
    }

    @Override
    public Op apply(long value) {
        Op op = opF.apply(value);
        return op;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy