io.tarantool.driver.mappers.AbstractResultMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartridge-driver Show documentation
Show all versions of cartridge-driver Show documentation
Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework
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 extends Value, ? extends T> resultConverter,
Class extends T> resultClass) {
this.valueMapper = valueMapper;
valueMapper.registerValueConverter(ValueType.ARRAY, resultClass, resultConverter);
}
public AbstractResultMapper(
MessagePackValueMapper valueMapper,
ValueConverter extends Value, ? extends T> resultConverter) {
this.valueMapper = valueMapper;
valueMapper.registerValueConverterWithoutTargetClass(ValueType.ARRAY, resultConverter);
}
public AbstractResultMapper(
MessagePackValueMapper valueMapper,
ValueType valueType,
ValueConverter extends Value, ? extends T> resultConverter,
Class extends T> resultClass) {
this.valueMapper = valueMapper;
valueMapper.registerValueConverter(valueType, resultClass, resultConverter);
}
public AbstractResultMapper(
MessagePackValueMapper valueMapper,
ValueType valueType,
ValueConverter extends Value, ? extends T> resultConverter) {
this.valueMapper = valueMapper;
valueMapper.registerValueConverterWithoutTargetClass(valueType, resultConverter);
}
public AbstractResultMapper(
MessagePackValueMapper valueMapper,
List> converters,
Class extends T> 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 extends O> 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