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

io.tarantool.driver.protocol.requests.TarantoolEvalRequest 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.protocol.requests;

import io.tarantool.driver.mappers.MessagePackObjectMapper;
import io.tarantool.driver.protocol.TarantoolProtocolException;
import io.tarantool.driver.protocol.TarantoolRequest;
import io.tarantool.driver.protocol.TarantoolRequestBody;
import io.tarantool.driver.protocol.TarantoolRequestFieldType;
import io.tarantool.driver.protocol.TarantoolRequestType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Eval request.
 * See 
 *     https://www.tarantool.io/en/doc/latest/dev_guide/internals/box_protocol/#binary-protocol-requests
 *
 * @author Sergey Volgin
 */
public final class TarantoolEvalRequest extends TarantoolRequest {

    private TarantoolEvalRequest(TarantoolRequestBody body) {
        super(TarantoolRequestType.IPROTO_EVAL, body);
    }

    /**
     * Tarantool eval request builder
     */
    public static class Builder {

        Map bodyMap;

        public Builder() {
            this.bodyMap = new HashMap<>(2, 1);
        }

        /**
         * Specify lua expression
         * @param expression lua expression
         * @return builder
         */
        public Builder withExpression(String expression) {
            this.bodyMap.put(TarantoolRequestFieldType.IPROTO_EXPRESSION.getCode(), expression);
            return this;
        }

        /**
         * Specify eval arguments
         * @param arguments eval arguments
         * @return builder
         */
        public Builder withArguments(List arguments) {
            this.bodyMap.put(TarantoolRequestFieldType.IPROTO_TUPLE.getCode(), arguments);
            return this;
        }

        /**
         * Build a {@link TarantoolEvalRequest} instance
         * @param mapper configured {@link MessagePackObjectMapper} instance
         * @return instance of eval request
         * @throws TarantoolProtocolException if some required params is missing
         */
        public TarantoolEvalRequest build(MessagePackObjectMapper mapper) throws TarantoolProtocolException {
            if (!bodyMap.containsKey(TarantoolRequestFieldType.IPROTO_EXPRESSION.getCode())) {
                throw new TarantoolProtocolException("Lua expression must be specified in the eval request");
            }

            return new TarantoolEvalRequest(new TarantoolRequestBody(bodyMap, mapper));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy