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

io.tarantool.driver.core.proxy.TruncateProxyOperation 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.core.proxy;

import io.tarantool.driver.api.TarantoolCallOperations;
import io.tarantool.driver.api.TarantoolVoidResult;
import io.tarantool.driver.api.space.options.OperationWithTimeoutOptions;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * Proxy operation for truncate
 *
 * @author Ivan Dneprov
 * @author Artyom Dubinin
 */
public final class TruncateProxyOperation implements ProxyOperation {

    private final TarantoolCallOperations client;
    private final String functionName;
    private final List arguments;

    private TruncateProxyOperation(
        TarantoolCallOperations client,
        String functionName,
        List arguments) {
        this.client = client;
        this.arguments = arguments;
        this.functionName = functionName;
    }

    public TarantoolCallOperations getClient() {
        return client;
    }

    public String getFunctionName() {
        return functionName;
    }

    public List getArguments() {
        return arguments;
    }

    @Override
    public CompletableFuture execute() {
        return client.callForSingleResult(functionName, arguments, Boolean.class)
            .thenApply(v -> TarantoolVoidResult.INSTANCE.value());
    }

    /**
     * Create a builder instance.
     *
     * @return a builder
     */
    public static Builder builder() {
        return new Builder();
    }

    public static final class Builder
        extends AbstractProxyOperation.GenericOperationsBuilder {

        public Builder() {
        }

        @Override
        Builder self() {
            return this;
        }

        /**
         * Prepare request of truncate operation to Tarantool server
         *
         * @return TruncateProxyOperation instance
         */
        public TruncateProxyOperation build() {
            CRUDBaseOptions requestOptions = new CRUDBaseOptions.Builder()
                .withTimeout(options.getTimeout())
                .build();

            List arguments = Arrays.asList(spaceName, requestOptions.asMap());

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy