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

com.firefly.reactive.adapter.db.ReactiveSQLClientAdapter Maven / Gradle / Ivy

There is a newer version: 5.0.0-dev6
Show newest version
package com.firefly.reactive.adapter.db;

import com.firefly.db.SQLClient;
import com.firefly.utils.concurrent.Promise;
import com.firefly.utils.function.Func1;
import reactor.core.publisher.Mono;

/**
 * @author Pengtao Qiu
 */
public class ReactiveSQLClientAdapter implements ReactiveSQLClient {

    private final SQLClient sqlClient;

    public ReactiveSQLClientAdapter(SQLClient sqlClient) {
        this.sqlClient = sqlClient;
    }

    @Override
    public Mono getConnection() {
        return Mono.fromCompletionStage(sqlClient.getConnection().thenApply(ReactiveSQLConnectionAdapter::new));
    }

    @Override
    public  Mono newTransaction(Func1> func1) {
        return Mono.fromCompletionStage(sqlClient.newTransaction(conn -> {
            Promise.Completable completable = new Promise.Completable<>();
            func1.call(new ReactiveSQLConnectionAdapter(conn))
                 .subscribe(completable::succeeded, completable::failed);
            return completable;
        }));
    }

    @Override
    public SQLClient getSQLClient() {
        return sqlClient;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy