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

org.redisson.reactive.RedissonTransactionReactive Maven / Gradle / Ivy

Go to download

Easy Redis Java client and Real-Time Data Platform. Valkey compatible. Sync/Async/RxJava3/Reactive API. Client side caching. Over 50 Redis based Java objects and services: JCache API, Apache Tomcat, Hibernate, Spring, Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Scheduler, RPC

There is a newer version: 3.40.2
Show newest version
/**
 * Copyright (c) 2013-2024 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.reactive;

import org.redisson.api.RBucketReactive;
import org.redisson.api.RMap;
import org.redisson.api.RMapCache;
import org.redisson.api.RMapCacheReactive;
import org.redisson.api.RMapReactive;
import org.redisson.api.RSet;
import org.redisson.api.RSetCache;
import org.redisson.api.RSetCacheReactive;
import org.redisson.api.RSetReactive;
import org.redisson.api.RTransaction;
import org.redisson.api.RTransactionReactive;
import org.redisson.api.TransactionOptions;
import org.redisson.client.codec.Codec;
import org.redisson.transaction.RedissonTransaction;

import reactor.core.publisher.Mono;

/**
 * 
 * @author Nikita Koksharov
 *
 */
public class RedissonTransactionReactive implements RTransactionReactive {

    private final RTransaction transaction;
    private final CommandReactiveExecutor executorService;
    
    public RedissonTransactionReactive(CommandReactiveExecutor executorService, TransactionOptions options) {
        this.transaction = new RedissonTransaction(executorService, options);
        this.executorService = executorService;
    }

    @Override
    public  RBucketReactive getBucket(String name) {
        return ReactiveProxyBuilder.create(executorService, transaction.getBucket(name), RBucketReactive.class);
    }

    @Override
    public  RBucketReactive getBucket(String name, Codec codec) {
        return ReactiveProxyBuilder.create(executorService, transaction.getBucket(name, codec), RBucketReactive.class);
    }

    @Override
    public  RMapReactive getMap(String name) {
        RMap map = transaction.getMap(name);
        return ReactiveProxyBuilder.create(executorService, map, 
                new RedissonMapReactive(map, null), RMapReactive.class);
    }

    @Override
    public  RMapReactive getMap(String name, Codec codec) {
        RMap map = transaction.getMap(name, codec);
        return ReactiveProxyBuilder.create(executorService, map,
                new RedissonMapReactive<>(map, null), RMapReactive.class);
    }

    @Override
    public  RMapCacheReactive getMapCache(String name, Codec codec) {
        RMapCache map = transaction.getMapCache(name, codec);
        return ReactiveProxyBuilder.create(executorService, map,
                new RedissonMapCacheReactive<>(map, executorService), RMapCacheReactive.class);
    }

    @Override
    public  RMapCacheReactive getMapCache(String name) {
        RMapCache map = transaction.getMapCache(name);
        return ReactiveProxyBuilder.create(executorService, map,
                new RedissonMapCacheReactive<>(map, executorService), RMapCacheReactive.class);
    }

    @Override
    public  RSetReactive getSet(String name) {
        RSet set = transaction.getSet(name);
        return ReactiveProxyBuilder.create(executorService, set, 
                new RedissonSetReactive(set, null), RSetReactive.class);
    }

    @Override
    public  RSetReactive getSet(String name, Codec codec) {
        RSet set = transaction.getSet(name, codec);
        return ReactiveProxyBuilder.create(executorService, set, 
                new RedissonSetReactive(set, null), RSetReactive.class);
    }

    @Override
    public  RSetCacheReactive getSetCache(String name) {
        RSetCache set = transaction.getSetCache(name);
        return ReactiveProxyBuilder.create(executorService, set, 
                new RedissonSetCacheReactive(set, null), RSetCacheReactive.class);
    }

    @Override
    public  RSetCacheReactive getSetCache(String name, Codec codec) {
        RSetCache set = transaction.getSetCache(name, codec);
        return ReactiveProxyBuilder.create(executorService, set, 
                new RedissonSetCacheReactive(set, null), RSetCacheReactive.class);
    }

    @Override
    public Mono commit() {
        return executorService.reactive(() -> transaction.commitAsync());
    }

    @Override
    public Mono rollback() {
        return executorService.reactive(() -> transaction.rollbackAsync());
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy