Class SQLClientHelper


  • public class SQLClientHelper
    extends Object
    Utilities for generating observables with a SQLClient.
    Author:
    Thomas Segismont
    • Method Detail

      • txObservableTransformer

        public static <T> rx.Observable.Transformer<T,​T> txObservableTransformer​(SQLConnection sqlConnection)
        Creates a Observable.Transformer decorating an Observable with transaction management for a given SQLConnection.

        If the upstream Observable completes (onComplete), the transaction is committed. If the upstream Observable emits an error (onError), the transaction is rollbacked.

        Eventually, the given SQLConnection is put back in autocommit mode.

        Type Parameters:
        T - the type of the items emitted by the upstream Observable
        Parameters:
        sqlConnection - the SQLConnection used for database operations and transaction management
        Returns:
        a Observable.Transformer decorating an Observable with transaction management
      • inTransactionObservable

        public static <T> rx.Observable<T> inTransactionObservable​(SQLClient client,
                                                                   Function<SQLConnection,​rx.Observable<T>> sourceSupplier)
        Generates a Observable from SQLConnection operations executed inside a transaction.
        Type Parameters:
        T - the type of the items emitted by the Observable
        Parameters:
        client - the SQLClient
        sourceSupplier - a user-provided function returning a Observable generated by interacting with the given SQLConnection
        Returns:
        an Observable generated from SQLConnection operations executed inside a transaction
      • txSingleTransformer

        public static <T> rx.Single.Transformer<T,​T> txSingleTransformer​(SQLConnection sqlConnection)
        Creates a Single.Transformer decorating a Single with transaction management for a given SQLConnection.

        If the upstream Single emits a value (onSuccess), the transaction is committed. If the upstream Single emits an error (onError), the transaction is rollbacked.

        Eventually, the given SQLConnection is put back in autocommit mode.

        Type Parameters:
        T - the type of the item emitted by the upstream Single
        Parameters:
        sqlConnection - the SQLConnection used for database operations and transaction management
        Returns:
        a Single.Transformer decorating a Single with transaction management
      • inTransactionSingle

        public static <T> rx.Single<T> inTransactionSingle​(SQLClient client,
                                                           Function<SQLConnection,​rx.Single<T>> sourceSupplier)
        Generates a Single from SQLConnection operations executed inside a transaction.
        Type Parameters:
        T - the type of the item emitted by the Single
        Parameters:
        client - the SQLClient
        sourceSupplier - a user-provided function returning a Single generated by interacting with the given SQLConnection
        Returns:
        a Single generated from SQLConnection operations executed inside a transaction
      • txCompletableTransformer

        public static rx.Completable.Transformer txCompletableTransformer​(SQLConnection sqlConnection)
        Creates a Completable.Transformer decorating a Completable with transaction management for a given SQLConnection.

        If the upstream Completable completes (onComplete), the transaction is committed. If the upstream Completable emits an error (onError), the transaction is rollbacked.

        Eventually, the given SQLConnection is put back in autocommit mode.

        Parameters:
        sqlConnection - the SQLConnection used for database operations and transaction management
        Returns:
        a Completable.Transformer decorating a Completable with transaction management
      • inTransactionCompletable

        public static rx.Completable inTransactionCompletable​(SQLClient client,
                                                              Function<SQLConnection,​rx.Completable> sourceSupplier)
        Generates a Completable from SQLConnection operations executed inside a transaction.
        Parameters:
        client - the SQLClient
        sourceSupplier - a user-provided function returning a Completable generated by interacting with the given SQLConnection
        Returns:
        a Completable generated from SQLConnection operations executed inside a transaction
      • usingConnectionObservable

        public static <T> rx.Observable<T> usingConnectionObservable​(SQLClient client,
                                                                     Function<SQLConnection,​rx.Observable<T>> sourceSupplier)
        Generates a Observable from SQLConnection operations.
        Type Parameters:
        T - the type of the items emitted by the Observable
        Parameters:
        client - the SQLClient
        sourceSupplier - a user-provided function returning a Observable generated by interacting with the given SQLConnection
        Returns:
        an Observable generated from SQLConnection operations
      • usingConnectionSingle

        public static <T> rx.Single<T> usingConnectionSingle​(SQLClient client,
                                                             Function<SQLConnection,​rx.Single<T>> sourceSupplier)
        Generates a Single from SQLConnection operations.
        Type Parameters:
        T - the type of the item emitted by the Single
        Parameters:
        client - the SQLClient
        sourceSupplier - a user-provided function returning a Single generated by interacting with the given SQLConnection
        Returns:
        a Single generated from SQLConnection operations
      • usingConnectionCompletable

        public static rx.Completable usingConnectionCompletable​(SQLClient client,
                                                                Function<SQLConnection,​rx.Completable> sourceSupplier)
        Generates a Completable from SQLConnection operations.
        Parameters:
        client - the SQLClient
        sourceSupplier - a user-provided function returning a Completable generated by interacting with the given SQLConnection
        Returns:
        a Completable generated from SQLConnection operations