io.tarantool.driver.mappers.factories.SingleValueResultMapperFactory 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.factories;
import io.tarantool.driver.api.SingleValueCallResult;
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.ArrayValueToSingleValueCallResultConverter;
import io.tarantool.driver.mappers.converters.value.ArrayValueToSingleValueCallResultSimpleConverter;
import org.msgpack.value.Value;
/**
* Factory for {@link CallResultMapper} instances used for handling Lua call results resulting in two possible
* values -- result and error
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public class SingleValueResultMapperFactory extends TarantoolCallResultMapperFactory> {
private final MessagePackMapper messagePackMapper;
/**
* Basic constructor
*/
public SingleValueResultMapperFactory() {
this(DefaultMessagePackMapperFactory.getInstance().emptyMapper());
}
/**
* Basic constructor with mapper
*
* @param messagePackMapper mapper for MessagePack entities in tuple fields to Java objects
*/
public SingleValueResultMapperFactory(MessagePackMapper messagePackMapper) {
super();
this.messagePackMapper = messagePackMapper;
}
/**
* Get result mapper for the Lua function call with single result
*
* @param valueMapper MessagePack-to-object mapper for result contents
* @param valueConverter the result content converter
* @return call result mapper
*/
public CallResultMapper> withSingleValueResultConverter(
MessagePackValueMapper valueMapper,
ValueConverter valueConverter) {
return withConverter(valueMapper, new ArrayValueToSingleValueCallResultSimpleConverter<>(valueConverter));
}
/**
* Get result mapper for the Lua function call with single result
*
* @param valueConverter the result content converter
* @return call result mapper
*/
public CallResultMapper> withSingleValueResultConverter(
ValueConverter valueConverter) {
return withConverter(messagePackMapper.copy(),
new ArrayValueToSingleValueCallResultSimpleConverter<>(valueConverter));
}
/**
* Get result mapper for the Lua function call with single result
*
* @param valueMapper MessagePack-to-object mapper for result contents
* @param valueConverter the result content converter
* @param resultClass full result type class
* @return call result mapper
*/
public CallResultMapper> withSingleValueResultConverter(
MessagePackValueMapper valueMapper,
ValueConverter valueConverter,
Class extends SingleValueCallResult> resultClass) {
return withConverter(valueMapper, new ArrayValueToSingleValueCallResultSimpleConverter<>(valueConverter),
resultClass);
}
/**
* Get result mapper for the Lua function call with single result
*
* @param valueConverter the result content converter
* @param resultClass full result type class
* @return call result mapper
*/
public CallResultMapper> withSingleValueResultConverter(
ValueConverter valueConverter,
Class extends SingleValueCallResult> resultClass) {
return withConverter(
messagePackMapper.copy(), new ArrayValueToSingleValueCallResultSimpleConverter<>(valueConverter),
resultClass);
}
public CallResultMapper> withSingleValueResultConverter(
MessagePackValueMapper structureValueMapper) {
return withConverter(
messagePackMapper.copy(), new ArrayValueToSingleValueCallResultConverter<>(structureValueMapper));
}
public CallResultMapper> withSingleValueResultConverter(
MessagePackValueMapper structureValueMapper,
Class extends SingleValueCallResult> resultClass) {
return withConverter(
messagePackMapper.copy(), new ArrayValueToSingleValueCallResultConverter<>(structureValueMapper),
resultClass);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy