io.tarantool.driver.mappers.factories.ResultMapperFactoryFactoryImpl 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.MultiValueCallResult;
import io.tarantool.driver.api.SingleValueCallResult;
import io.tarantool.driver.api.TarantoolResult;
import io.tarantool.driver.exceptions.TarantoolClientException;
import io.tarantool.driver.mappers.CallResultMapper;
import io.tarantool.driver.mappers.DefaultMultiValueResultMapper;
import io.tarantool.driver.mappers.DefaultSingleValueResultMapper;
import io.tarantool.driver.mappers.MessagePackMapper;
import io.tarantool.driver.mappers.TarantoolTupleResultMapperFactory;
import io.tarantool.driver.mappers.TarantoolTupleResultMapperFactoryImpl;
import io.tarantool.driver.mappers.converters.ValueConverter;
import io.tarantool.driver.mappers.converters.value.ArrayValueToMultiValueListConverter;
import org.msgpack.value.Value;
import org.msgpack.value.ValueType;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
/**
* Manages instantiation of the operation result factories
*
* @author Alexey Kuzin
* @author Artyom Dubinin
*/
public final class ResultMapperFactoryFactoryImpl implements ResultMapperFactoryFactory {
/**
* Basic constructor.
*/
public ResultMapperFactoryFactoryImpl() {
}
@Override
public ArrayValueToTarantoolTupleResultMapperFactory arrayTupleResultMapperFactory() {
return new ArrayValueToTarantoolTupleResultMapperFactory();
}
@Override
public TarantoolTupleResultMapperFactory getTarantoolTupleResultMapperFactory() {
return TarantoolTupleResultMapperFactoryImpl.getInstance();
}
@Override
public RowsMetadataToTarantoolTupleResultMapperFactory rowsMetadataTupleResultMapperFactory() {
return new RowsMetadataToTarantoolTupleResultMapperFactory();
}
@Override
public SingleValueWithTarantoolTupleResultMapperFactory singleValueTupleResultMapperFactory() {
return new SingleValueWithTarantoolTupleResultMapperFactory();
}
@Override
public MultiValueWithTarantoolTupleResultMapperFactory multiValueTupleResultMapperFactory() {
return new MultiValueWithTarantoolTupleResultMapperFactory();
}
@Override
public ArrayValueToTarantoolResultMapperFactory rowsMetadataStructureResultMapperFactory() {
return new ArrayValueToTarantoolResultMapperFactory<>();
}
@Override
public SingleValueResultMapperFactory singleValueResultMapperFactory() {
return new SingleValueResultMapperFactory<>();
}
@Override
public SingleValueWithTarantoolResultMapperFactory singleValueTarantoolResultMapperFactory() {
return new SingleValueWithTarantoolResultMapperFactory<>();
}
@Override
public > MultiValueResultMapperFactory multiValueResultMapperFactory() {
return new MultiValueResultMapperFactory<>();
}
@Override
public MultiValueWithTarantoolResultMapperFactory multiValueTarantoolResultMapperFactory() {
return new MultiValueWithTarantoolResultMapperFactory<>();
}
public CallResultMapper>
getSingleValueResultMapper(ValueConverter valueConverter) {
return this.singleValueResultMapperFactory().withSingleValueResultConverter(
valueConverter, (Class>) (Class>) SingleValueCallResult.class);
}
public > CallResultMapper>
getMultiValueResultMapper(Supplier containerSupplier, ValueConverter valueConverter) {
return this.multiValueResultMapperFactory().withMultiValueResultConverter(
new ArrayValueToMultiValueListConverter<>(valueConverter, containerSupplier),
(Class>) (Class>) MultiValueCallResult.class);
}
public CallResultMapper, SingleValueCallResult>>
getTarantoolResultMapper(MessagePackMapper mapper, Class tupleClass) {
return this.singleValueTarantoolResultMapperFactory()
.withSingleValueArrayTarantoolResultConverter(getConverter(mapper, ValueType.ARRAY, tupleClass));
}
public > CallResultMapper>
getDefaultMultiValueMapper(MessagePackMapper mapper, Class tupleClass) {
return new DefaultMultiValueResultMapper<>(mapper, tupleClass);
}
public CallResultMapper>
getDefaultSingleValueMapper(MessagePackMapper mapper, Class tupleClass) {
return new DefaultSingleValueResultMapper<>(mapper, tupleClass);
}
private ValueConverter getConverter(
MessagePackMapper mapper, ValueType valueType, Class tupleClass) {
Optional extends ValueConverter> converter = mapper.getValueConverter(valueType, tupleClass);
if (!converter.isPresent()) {
throw new TarantoolClientException(
"No converter for value type %s and type %s is present", valueType, tupleClass);
}
return converter.get();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy