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

io.tarantool.driver.mappers.factories.MultiValueResultMapperFactory 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.mappers.factories;

import io.tarantool.driver.api.MultiValueCallResult;
import io.tarantool.driver.mappers.CallResultMapper;
import io.tarantool.driver.mappers.MessagePackMapper;
import io.tarantool.driver.mappers.MessagePackValueMapper;
import io.tarantool.driver.mappers.converters.ValueConverter;
import io.tarantool.driver.mappers.converters.value.ArrayValueToMultiValueCallResultConverter;
import io.tarantool.driver.mappers.converters.value.ArrayValueToMultiValueCallResultSimpleConverter;
import org.msgpack.value.ArrayValue;

import java.util.List;

/**
 * Factory for {@link CallResultMapper} instances used for handling Lua call multi-return result which is
 * treated as a list of values
 *
 * @author Alexey Kuzin
 * @author Artyom Dubinin
 */
public class MultiValueResultMapperFactory> extends
    TarantoolCallResultMapperFactory> {

    private final MessagePackMapper messagePackMapper;

    /**
     * Basic constructor
     */
    public MultiValueResultMapperFactory() {
        this(DefaultMessagePackMapperFactory.getInstance().emptyMapper());
    }

    /**
     * Basic constructor with mapper
     *
     * @param messagePackMapper MessagePack-to-entity mapper for result contents conversion
     */
    public MultiValueResultMapperFactory(MessagePackMapper messagePackMapper) {
        super();
        this.messagePackMapper = messagePackMapper;
    }

    /**
     * Get result mapper for the Lua function call with multi-return result
     *
     * @param valueMapper    MessagePack-to-entity mapper for result contents conversion
     * @param itemsConverter the result list converter
     * @return call result mapper
     */
    public CallResultMapper> withMultiValueResultConverter(
        MessagePackValueMapper valueMapper,
        ValueConverter itemsConverter) {
        return withConverter(valueMapper, new ArrayValueToMultiValueCallResultSimpleConverter<>(itemsConverter));
    }

    /**
     * Get result mapper for the Lua function call with multi-return result
     *
     * @param itemsConverter the result list converter
     * @return call result mapper
     */
    public CallResultMapper> withMultiValueResultConverter(
        ValueConverter itemsConverter) {
        return withConverter(messagePackMapper.copy(),
            new ArrayValueToMultiValueCallResultSimpleConverter<>(itemsConverter));
    }

    /**
     * Get result mapper for the Lua function call with multi-return result
     *
     * @param valueMapper    MessagePack-to-entity mapper for result contents conversion
     * @param itemsConverter result list converter
     * @param resultClass    full result type class
     * @return call result mapper
     */
    public CallResultMapper> withMultiValueResultConverter(
        MessagePackValueMapper valueMapper,
        ValueConverter itemsConverter,
        Class> resultClass) {
        return withConverter(valueMapper, new ArrayValueToMultiValueCallResultSimpleConverter<>(itemsConverter),
            resultClass);
    }

    /**
     * Get result mapper for the Lua function call with multi-return result
     *
     * @param itemsConverter result list converter
     * @param resultClass    full result type class
     * @return call result mapper
     */
    public CallResultMapper> withMultiValueResultConverter(
        ValueConverter itemsConverter,
        Class> resultClass) {
        return withConverter(
            messagePackMapper.copy(), new ArrayValueToMultiValueCallResultSimpleConverter<>(itemsConverter),
            resultClass);
    }

    public CallResultMapper> withMultiValueResultConverter(
        MessagePackValueMapper structureValueMapper) {
        return withConverter(
            messagePackMapper.copy(), new ArrayValueToMultiValueCallResultConverter<>(structureValueMapper));
    }

    public CallResultMapper> withMultiValueResultConverter(
        MessagePackValueMapper valueMapper,
        MessagePackValueMapper structureValueMapper) {
        return withConverter(
            valueMapper, new ArrayValueToMultiValueCallResultConverter<>(structureValueMapper));
    }

    public CallResultMapper> withMultiValueResultConverter(
        MessagePackValueMapper structureValueMapper,
        Class> resultClass) {
        return withMultiValueResultConverter(
            messagePackMapper.copy(), structureValueMapper, resultClass);
    }

    public CallResultMapper> withMultiValueResultConverter(
        MessagePackValueMapper valueMapper,
        MessagePackValueMapper structureValueMapper,
        Class> resultClass) {
        return withConverter(
            valueMapper, new ArrayValueToMultiValueCallResultConverter<>(structureValueMapper), resultClass);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy