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

io.quarkus.redis.runtime.datasource.ReactiveTransactionalRedisDataSourceImpl Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package io.quarkus.redis.runtime.datasource;

import static io.smallrye.mutiny.helpers.ParameterValidation.nonNull;

import java.util.Arrays;

import io.quarkus.redis.datasource.ReactiveRedisDataSource;
import io.quarkus.redis.datasource.autosuggest.ReactiveTransactionalAutoSuggestCommands;
import io.quarkus.redis.datasource.bitmap.ReactiveTransactionalBitMapCommands;
import io.quarkus.redis.datasource.bloom.ReactiveTransactionalBloomCommands;
import io.quarkus.redis.datasource.countmin.ReactiveTransactionalCountMinCommands;
import io.quarkus.redis.datasource.cuckoo.ReactiveTransactionalCuckooCommands;
import io.quarkus.redis.datasource.geo.ReactiveTransactionalGeoCommands;
import io.quarkus.redis.datasource.graph.ReactiveTransactionalGraphCommands;
import io.quarkus.redis.datasource.hash.ReactiveTransactionalHashCommands;
import io.quarkus.redis.datasource.hyperloglog.ReactiveTransactionalHyperLogLogCommands;
import io.quarkus.redis.datasource.json.ReactiveTransactionalJsonCommands;
import io.quarkus.redis.datasource.keys.ReactiveTransactionalKeyCommands;
import io.quarkus.redis.datasource.list.ReactiveTransactionalListCommands;
import io.quarkus.redis.datasource.search.ReactiveTransactionalSearchCommands;
import io.quarkus.redis.datasource.set.ReactiveTransactionalSetCommands;
import io.quarkus.redis.datasource.sortedset.ReactiveTransactionalSortedSetCommands;
import io.quarkus.redis.datasource.stream.ReactiveTransactionalStreamCommands;
import io.quarkus.redis.datasource.string.ReactiveTransactionalStringCommands;
import io.quarkus.redis.datasource.timeseries.ReactiveTransactionalTimeSeriesCommands;
import io.quarkus.redis.datasource.topk.ReactiveTransactionalTopKCommands;
import io.quarkus.redis.datasource.transactions.ReactiveTransactionalRedisDataSource;
import io.quarkus.redis.datasource.value.ReactiveTransactionalValueCommands;
import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.redis.client.Command;

public class ReactiveTransactionalRedisDataSourceImpl implements ReactiveTransactionalRedisDataSource {

    private final ReactiveRedisDataSourceImpl reactive;
    private final TransactionHolder tx;

    public ReactiveTransactionalRedisDataSourceImpl(ReactiveRedisDataSource source, TransactionHolder th) {
        this.tx = th;
        this.reactive = (ReactiveRedisDataSourceImpl) source;
    }

    @Override
    public Uni discard() {
        return reactive.execute(Command.DISCARD)
                .invoke(tx::discard)
                .replaceWithVoid();
    }

    @Override
    public boolean discarded() {
        return tx.discarded();
    }

    @Override
    public  ReactiveTransactionalHashCommands hash(Class redisKeyType, Class typeOfField,
            Class typeOfValue) {
        return new ReactiveTransactionalHashCommandsImpl<>(this,
                (ReactiveHashCommandsImpl) this.reactive.hash(redisKeyType, typeOfField, typeOfValue),
                tx);
    }

    @Override
    public  ReactiveTransactionalGeoCommands geo(Class redisKeyType, Class memberType) {
        return new ReactiveTransactionalGeoCommandsImpl<>(this,
                (ReactiveGeoCommandsImpl) this.reactive.geo(redisKeyType, memberType), tx);
    }

    @Override
    public  ReactiveTransactionalSortedSetCommands sortedSet(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalSortedSetCommandsImpl<>(this,
                (ReactiveSortedSetCommandsImpl) this.reactive.sortedSet(redisKeyType, valueType), tx);
    }

    @Override
    public  ReactiveTransactionalValueCommands value(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalStringCommandsImpl<>(this,
                (ReactiveStringCommandsImpl) this.reactive.value(redisKeyType, valueType), tx);
    }

    @Override
    public  ReactiveTransactionalStringCommands string(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalStringCommandsImpl<>(this,
                (ReactiveStringCommandsImpl) this.reactive.value(redisKeyType, valueType), tx);
    }

    @Override
    public  ReactiveTransactionalSetCommands set(Class redisKeyType, Class memberType) {
        return new ReactiveTransactionalSetCommandsImpl<>(this,
                (ReactiveSetCommandsImpl) this.reactive.set(redisKeyType, memberType), tx);
    }

    @Override
    public  ReactiveTransactionalListCommands list(Class redisKeyType, Class memberType) {
        return new ReactiveTransactionalListCommandsImpl<>(this,
                (ReactiveListCommandsImpl) this.reactive.list(redisKeyType, memberType), tx);
    }

    @Override
    public  ReactiveTransactionalHyperLogLogCommands hyperloglog(Class redisKeyType, Class memberType) {
        return new ReactiveTransactionalHyperLogLogCommandsImpl<>(this,
                (ReactiveHyperLogLogCommandsImpl) this.reactive.hyperloglog(redisKeyType, memberType), tx);
    }

    @Override
    public  ReactiveTransactionalBitMapCommands bitmap(Class redisKeyType) {
        return new ReactiveTransactionalBitMapCommandsImpl<>(this,
                (ReactiveBitMapCommandsImpl) this.reactive.bitmap(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalStreamCommands stream(Class redisKeyType, Class typeOfField,
            Class typeOfValue) {
        return new ReactiveTransactionalStreamCommandsImpl<>(this,
                (ReactiveStreamCommandsImpl) this.reactive.stream(redisKeyType, typeOfField, typeOfValue), tx);
    }

    @Override
    public  ReactiveTransactionalJsonCommands json(Class redisKeyType) {
        return new ReactiveTransactionalJsonCommandsImpl<>(this,
                (ReactiveJsonCommandsImpl) this.reactive.json(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalBloomCommands bloom(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalBloomCommandsImpl<>(this,
                (ReactiveBloomCommandsImpl) this.reactive.bloom(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalCuckooCommands cuckoo(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalCuckooCommandsImpl<>(this,
                (ReactiveCuckooCommandsImpl) this.reactive.cuckoo(redisKeyType, valueType), tx);
    }

    @Override
    public  ReactiveTransactionalCountMinCommands countmin(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalCountMinCommandsImpl<>(this,
                (ReactiveCountMinCommandsImpl) this.reactive.countmin(redisKeyType, valueType), tx);
    }

    @Override
    public  ReactiveTransactionalTopKCommands topk(Class redisKeyType, Class valueType) {
        return new ReactiveTransactionalTopKCommandsImpl<>(this,
                (ReactiveTopKCommandsImpl) this.reactive.topk(redisKeyType, valueType), tx);
    }

    @Override
    public  ReactiveTransactionalGraphCommands graph(Class redisKeyType) {
        return new ReactiveTransactionalGraphCommandsImpl<>(this,
                (ReactiveGraphCommandsImpl) this.reactive.graph(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalKeyCommands key(Class redisKeyType) {
        return new ReactiveTransactionalKeyCommandsImpl<>(this,
                (ReactiveKeyCommandsImpl) this.reactive.key(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalSearchCommands search(Class redisKeyType) {
        return new ReactiveTransactionalSearchCommandsImpl<>(this,
                (ReactiveSearchCommandsImpl) this.reactive.search(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalAutoSuggestCommands autosuggest(Class redisKeyType) {
        return new ReactiveTransactionalAutoSuggestCommandsImpl<>(this,
                (ReactiveAutoSuggestCommandsImpl) this.reactive.autosuggest(redisKeyType), tx);
    }

    @Override
    public  ReactiveTransactionalTimeSeriesCommands timeseries(Class redisKeyType) {
        return new ReactiveTransactionalTimeSeriesCommandsImpl<>(this,
                (ReactiveTimeSeriesCommandsImpl) this.reactive.timeseries(redisKeyType), tx);
    }

    @Override
    public Uni execute(String command, String... args) {
        nonNull(command, "command");
        return execute(CommandMap.normalize(Command.create(command)), args);
    }

    @Override
    public Uni execute(Command command, String... args) {
        nonNull(command, "command");
        tx.enqueue(r -> r); // identity

        command = CommandMap.normalize(command);
        RedisCommand c = RedisCommand.of(command).putAll(Arrays.asList(args));

        return reactive.execute(c.toRequest())
                .map(r -> {
                    if (r == null || !r.toString().equals("QUEUED")) {
                        this.tx.discard();
                        throw new IllegalStateException("Unable to enqueue command into the current transaction");
                    }
                    return r;
                })
                .replaceWithVoid();
    }

    @Override
    public Uni execute(io.vertx.redis.client.Command command, String... args) {
        nonNull(command, "command");
        command = CommandMap.normalize(command);
        return execute(new Command(command), args);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy