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

org.nutz.mongo.interceptor.ZOperationExecutor Maven / Gradle / Ivy

package org.nutz.mongo.interceptor;

import java.util.ArrayList;
import java.util.List;

import com.mongodb.ReadPreference;
import com.mongodb.operation.OperationExecutor;
import com.mongodb.operation.ReadOperation;
import com.mongodb.operation.WriteOperation;

public class ZOperationExecutor implements OperationExecutor {
    
    protected OperationExecutor proxy;
    protected List interceptors;
    
    protected ZOperationExecutor() {}

    public ZOperationExecutor(OperationExecutor proxy, List interceptors) {
        this.proxy = proxy;
        this.interceptors = interceptors;
    }



    public  T execute(ReadOperation operation, ReadPreference readPreference) {
        if (interceptors == null)
            return proxy.execute(operation, readPreference);
        else {
            MongoInterceptorChain chain = new MongoInterceptorChain();
            chain.interceptors = new ArrayList(interceptors);
            chain.proxy = proxy;
            chain.readOperation = operation;
            chain.readPreference = readPreference;
            chain.doChain();
            return chain.result;
        }
    }

    public  T execute(WriteOperation operation) {
        if (interceptors == null)
            return proxy.execute(operation);
        else {
            MongoInterceptorChain chain = new MongoInterceptorChain();
            chain.interceptors = new ArrayList(interceptors);
            chain.proxy = proxy;
            chain.writeOperation = operation;
            chain.doChain();
            return chain.result;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy