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

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

import io.tarantool.driver.mappers.converters.ValueConverter;
import io.tarantool.driver.mappers.converters.ValueConverterWithInputTypeWrapper;
import org.msgpack.value.Value;
import org.msgpack.value.ValueType;

import java.util.List;
import java.util.Optional;

/**
 * Base class for result tuple mappers
 *
 * @param  target result type
 * @author Alexey Kuzin
 * @author Artyom Dubinin
 */
public abstract class AbstractResultMapper implements MessagePackValueMapper {

    protected final MessagePackValueMapper valueMapper;

    /**
     * Basic constructor
     *
     * @param valueMapper     MessagePack value-to-object mapper for result contents
     * @param resultConverter converter from MessagePack result array to result type
     * @param resultClass     target result class
     */
    public AbstractResultMapper(
        MessagePackValueMapper valueMapper,
        ValueConverter resultConverter,
        Class resultClass) {
        this.valueMapper = valueMapper;
        valueMapper.registerValueConverter(ValueType.ARRAY, resultClass, resultConverter);
    }

    public AbstractResultMapper(
        MessagePackValueMapper valueMapper,
        ValueConverter resultConverter) {
        this.valueMapper = valueMapper;
        valueMapper.registerValueConverterWithoutTargetClass(ValueType.ARRAY, resultConverter);
    }

    public AbstractResultMapper(
        MessagePackValueMapper valueMapper,
        ValueType valueType,
        ValueConverter resultConverter,
        Class resultClass) {
        this.valueMapper = valueMapper;
        valueMapper.registerValueConverter(valueType, resultClass, resultConverter);
    }

    public AbstractResultMapper(
        MessagePackValueMapper valueMapper,
        ValueType valueType,
        ValueConverter resultConverter) {
        this.valueMapper = valueMapper;
        valueMapper.registerValueConverterWithoutTargetClass(valueType, resultConverter);
    }

    public AbstractResultMapper(
        MessagePackValueMapper valueMapper,
        List> converters,
        Class resultClass) {
        this.valueMapper = valueMapper;
        for (ValueConverterWithInputTypeWrapper converter :
            converters) {
            valueMapper.registerValueConverter(
                converter.getValueType(),
                resultClass,
                converter.getValueConverter());
        }
    }

    public AbstractResultMapper(
        MessagePackValueMapper valueMapper,
        List> converters) {
        this.valueMapper = valueMapper;
        for (ValueConverterWithInputTypeWrapper converter :
            converters) {
            valueMapper.registerValueConverterWithoutTargetClass(
                converter.getValueType(),
                converter.getValueConverter());
        }
    }

    @Override
    public  O fromValue(V v) throws MessagePackValueMapperException {
        return valueMapper.fromValue(v);
    }

    @Override
    public  O fromValue(V v, Class targetClass) throws MessagePackValueMapperException {
        return valueMapper.fromValue(v, targetClass);
    }

    @Override
    public  void registerValueConverter(
        ValueType valueType,
        Class objectClass,
        ValueConverter converter) {
        valueMapper.registerValueConverter(valueType, objectClass, converter);
    }

    @Override
    public  void registerValueConverterWithoutTargetClass(
        ValueType valueType, ValueConverter converter) {
        valueMapper.registerValueConverterWithoutTargetClass(valueType, converter);
    }

    @Override
    public  Optional> getValueConverter(
        ValueType valueType,
        Class objectClass) {
        return valueMapper.getValueConverter(valueType, objectClass);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy