com.github.lontime.shaded.org.redisson.rx.RedissonTransactionRx Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2013-2021 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 com.github.lontime.shaded.org.redisson.rx;
import com.github.lontime.shaded.org.redisson.api.RBucketRx;
import com.github.lontime.shaded.org.redisson.api.RMap;
import com.github.lontime.shaded.org.redisson.api.RMapCache;
import com.github.lontime.shaded.org.redisson.api.RMapCacheRx;
import com.github.lontime.shaded.org.redisson.api.RMapRx;
import com.github.lontime.shaded.org.redisson.api.RSet;
import com.github.lontime.shaded.org.redisson.api.RSetCache;
import com.github.lontime.shaded.org.redisson.api.RSetCacheRx;
import com.github.lontime.shaded.org.redisson.api.RSetRx;
import com.github.lontime.shaded.org.redisson.api.RTransaction;
import com.github.lontime.shaded.org.redisson.api.RTransactionRx;
import com.github.lontime.shaded.org.redisson.api.TransactionOptions;
import com.github.lontime.shaded.org.redisson.client.codec.Codec;
import com.github.lontime.shaded.org.redisson.reactive.RedissonSetReactive;
import com.github.lontime.shaded.org.redisson.transaction.RedissonTransaction;
import io.reactivex.rxjava3.core.Completable;
/**
*
* @author Nikita Koksharov
*
*/
public class RedissonTransactionRx implements RTransactionRx {
private final RTransaction transaction;
private final CommandRxExecutor executorService;
public RedissonTransactionRx(CommandRxExecutor executorService, TransactionOptions options) {
this.transaction = new RedissonTransaction(executorService, options);
this.executorService = executorService;
}
@Override
public RBucketRx getBucket(String name) {
return RxProxyBuilder.create(executorService, transaction.getBucket(name), RBucketRx.class);
}
@Override
public RBucketRx getBucket(String name, Codec codec) {
return RxProxyBuilder.create(executorService, transaction.getBucket(name, codec), RBucketRx.class);
}
@Override
public RMapRx getMap(String name) {
RMap map = transaction.getMap(name);
return RxProxyBuilder.create(executorService, map,
new RedissonMapRx(map, null), RMapRx.class);
}
@Override
public RMapRx getMap(String name, Codec codec) {
RMap map = transaction.getMap(name, codec);
return RxProxyBuilder.create(executorService, map,
new RedissonMapRx(map, null), RMapRx.class);
}
@Override
public RMapCacheRx getMapCache(String name, Codec codec) {
RMapCache map = transaction.getMapCache(name, codec);
return RxProxyBuilder.create(executorService, map,
new RedissonMapCacheRx(map, executorService), RMapCacheRx.class);
}
@Override
public RMapCacheRx getMapCache(String name) {
RMapCache map = transaction.getMapCache(name);
return RxProxyBuilder.create(executorService, map,
new RedissonMapCacheRx(map, executorService), RMapCacheRx.class);
}
@Override
public RSetRx getSet(String name) {
RSet set = transaction.getSet(name);
return RxProxyBuilder.create(executorService, set,
new RedissonSetReactive(set, null), RSetRx.class);
}
@Override
public RSetRx getSet(String name, Codec codec) {
RSet set = transaction.getSet(name, codec);
return RxProxyBuilder.create(executorService, set,
new RedissonSetRx(set, null), RSetRx.class);
}
@Override
public RSetCacheRx getSetCache(String name) {
RSetCache set = transaction.getSetCache(name);
return RxProxyBuilder.create(executorService, set,
new RedissonSetCacheRx(set, null), RSetCacheRx.class);
}
@Override
public RSetCacheRx getSetCache(String name, Codec codec) {
RSetCache set = transaction.getSetCache(name, codec);
return RxProxyBuilder.create(executorService, set,
new RedissonSetCacheRx(set, null), RSetCacheRx.class);
}
@Override
public Completable commit() {
return executorService.flowable(() -> transaction.commitAsync().toCompletableFuture()).ignoreElements();
}
@Override
public Completable rollback() {
return executorService.flowable(() -> transaction.rollbackAsync().toCompletableFuture()).ignoreElements();
}
}