org.redisson.reactive.RedissonTransactionReactive Maven / Gradle / Ivy
/**
* Copyright 2018 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 java.util.function.Supplier;
import org.redisson.api.RBucketReactive;
import org.redisson.api.RFuture;
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), RMapCacheReactive.class);
}
@Override
public RMapCacheReactive getMapCache(String name) {
RMapCache map = transaction.getMapCache(name);
return ReactiveProxyBuilder.create(executorService, map,
new RedissonMapCacheReactive(map), 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(new Supplier>() {
@Override
public RFuture get() {
return transaction.commitAsync();
}
});
}
@Override
public Mono rollback() {
return executorService.reactive(new Supplier>() {
@Override
public RFuture get() {
return transaction.rollbackAsync();
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy