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

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

import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.api.tuple.TarantoolTuple;
import io.tarantool.driver.exceptions.TarantoolTupleConversionException;
import io.tarantool.driver.mappers.converters.value.ArrayValueToTarantoolTupleConverter;
import org.msgpack.core.MessageTypeCastException;
import org.msgpack.value.ArrayValue;
import org.msgpack.value.Value;

import java.util.stream.Collectors;

/**
 * Specific TarantoolResult implementation especially for TarantoolTuple input
 *
 * @author Artyom Dubinin
 */
public class TarantoolTupleResultImpl extends TarantoolResultImpl {

    public TarantoolTupleResultImpl(
        ArrayValue rawTuples, TarantoolSpaceMetadata metadata,
        ArrayValueToTarantoolTupleConverter tupleConverter) {
        setItems(rawTuples, metadata, tupleConverter);
    }

    public TarantoolTupleResultImpl(Value value, ArrayValueToTarantoolTupleConverter tupleConverter) {
        setItems(value.asArrayValue(), tupleConverter);
    }

    private void setItems(
        ArrayValue tupleArray, TarantoolSpaceMetadata responseMetadata,
        ArrayValueToTarantoolTupleConverter tupleConverter) {
        this.tuples = tupleArray.list().stream()
            .map(v -> {
                try {
                    return tupleConverter.fromValue(v.asArrayValue(), responseMetadata);
                } catch (MessageTypeCastException e) {
                    throw new TarantoolTupleConversionException(v, e);
                }
            })
            .collect(Collectors.toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy