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

io.tarantool.driver.proxy.InsertProxyOperation Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.proxy;


import io.tarantool.driver.TarantoolClientConfig;
import io.tarantool.driver.api.TarantoolClient;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.mappers.TarantoolCallResultMapper;
import io.tarantool.driver.utils.Assert;

import java.util.Arrays;
import java.util.List;

/**
 * Proxy operation for insert
 *
 * @param  tuple result type
 * @author Sergey Volgin
 */
public final class InsertProxyOperation extends AbstractProxyOperation {

    private InsertProxyOperation(TarantoolClient client,
                                 String functionName,
                                 List arguments,
                                 TarantoolCallResultMapper resultMapper) {
        super(client, functionName, arguments, resultMapper);
    }

    /**
     * The builder for this class.
     */
    public static final class Builder {
        private TarantoolClient client;
        private String spaceName;
        private String functionName;
        private TarantoolTuple tuple;
        private TarantoolCallResultMapper resultMapper;

        public Builder() {
        }

        public Builder withClient(TarantoolClient client) {
            this.client = client;
            return this;
        }

        public Builder withSpaceName(String spaceName) {
            this.spaceName = spaceName;
            return this;
        }

        public Builder withFunctionName(String functionName) {
            this.functionName = functionName;
            return this;
        }

        public Builder withTuple(TarantoolTuple tuple) {
            this.tuple = tuple;
            return this;
        }

        public Builder withResultMapper(TarantoolCallResultMapper resultMapper) {
            this.resultMapper = resultMapper;
            return this;
        }

        public InsertProxyOperation build() {
            Assert.notNull(client, "Tarantool client should not be null");
            Assert.notNull(spaceName, "Tarantool spaceName should not be null");
            Assert.notNull(functionName, "Proxy delete function name should not be null");
            Assert.notNull(tuple, "Tarantool tuple should not be null");
            Assert.notNull(resultMapper, "Result tuple mapper should not be null");

            TarantoolClientConfig config = client.getConfig();
            CRUDOperationOptions options = CRUDOperationOptions.builder()
                    .withTimeout(config.getRequestTimeout())
                    .build();

            List arguments = Arrays.asList(spaceName, tuple.getFields(), options.asMap());

            return new InsertProxyOperation(this.client, this.functionName, arguments, this.resultMapper);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy