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

io.lettuce.core.dynamic.ConvertingCommand Maven / Gradle / Ivy

Go to download

Advanced and thread-safe Java Redis client for synchronous, asynchronous, and reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs and much more.

The newest version!
package io.lettuce.core.dynamic;

import java.util.concurrent.ExecutionException;

/**
 * A {@link ExecutableCommand} that uses {@link ConversionService} to convert the result of a decorated
 * {@link ExecutableCommand}.
 *
 * @author Mark Paluch
 * @since 5.0
 */
class ConvertingCommand implements ExecutableCommand {

    private final ConversionService conversionService;

    private final ExecutableCommand delegate;

    public ConvertingCommand(ConversionService conversionService, ExecutableCommand delegate) {
        this.conversionService = conversionService;
        this.delegate = delegate;
    }

    @Override
    public Object execute(Object[] parameters) throws ExecutionException, InterruptedException {

        Object result = delegate.execute(parameters);

        if (delegate.getCommandMethod().getReturnType().isAssignableFrom(result.getClass())) {
            return result;
        }

        return conversionService.convert(result, delegate.getCommandMethod().getReturnType().getRawClass());
    }

    @Override
    public CommandMethod getCommandMethod() {
        return delegate.getCommandMethod();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy