Class Transactional<T,​C>

    • Method Detail

      • get

        public T get()
        Returns the result acquired by performing the contained procedure in a transactional scope. If an exception is thrown during the procedure, the transaction is rolled back and the exception is rethrown. Otherwise the transaction is committed and the result is returned.
        Returns:
        the acquired result
      • bypass

        public T bypass()
        Returns the result acquired by performing the contained procedure without the transactional scope. The TransactionProvider implementation may not necessarily support this operation and can throw a UnsupportedOperationException.
        Returns:
        the acquired result.
      • map

        public <U> Transactional<U,​C> map​(Function<T,​U> mapper)
        Returns a Transactional describing the result of applying the given mapping function to the result of the contained procedure. If the mapping function throws an Exception, the transaction will be rolled back as if the procedure had failed.
        Type Parameters:
        U - the type of the result returned from the mapping function
        Parameters:
        mapper - the mapping function
        Returns:
        the new Transactional
      • flatMap

        public <U> Transactional<U,​C> flatMap​(Function<T,​Transactional<U,​C>> mapper)
        Returns a Transactional describing the result acquired by chaining two transactional procedures together. The resulting procedure will call the mapping function with the result of the contained procedure and then it will perform the procedure returned by the mapping function.
        Type Parameters:
        U - the type of the result of the Transactional returned from the mapping function
        Parameters:
        mapper - the mapping function
        Returns:
        the new Transactional
      • peek

        public Transactional<T,​C> peek​(Consumer<T> action)
        Returns a new Transactional describing the result of this transaction, additionally performing the provided action on the result.
        Parameters:
        action - A non-interfering action to be performed on the result before yielding it
        Returns:
        the new Transactional
      • peekMap

        public Transactional<T,​C> peekMap​(Function<T,​Transactional<Void,​C>> procedure)
        Returns a new Transactional describing the result of this transaction, additionally performing the provided procedure on the result and appending the Transactional returned from the procedure to the new procedure chain.
        Parameters:
        procedure - the procedure to be applied to the procedure chain
        Returns:
        the new Transactional
      • of

        public static <T,​C> Transactional<T,​C> of​(Function<C,​T> materialize,
                                                              TransactionProvider<C> provider)
        Returns a Transactional describing the result of the given procedure performed in a transactional scope provided by the TransactionProvider.
        Type Parameters:
        T - the type of the result of the contained procedure
        C - the type of the transaction context
        Parameters:
        materialize - the contained procedure
        provider - the provider for the procedure's transaction context.
        Returns:
        the new Transactional
      • of

        public static <T> Transactional<T,​Void> of​(Supplier<T> materialize,
                                                         TransactionProvider<Void> provider)
        Returns a Transactional describing the result fo the given procedure performed in a transactional scope of the thread calling get().

        This is a helper creator intended to be used with thread context TransactionProviders.

        Type Parameters:
        T - the type of the result of the contained procedure
        Parameters:
        materialize - the contained procedure
        provider - the thread context transaction context provider
        Returns:
        the new Transactional
      • all

        public static <T1,​T2,​C> Transactional2<T1,​T2,​C> all​(Transactional<T1,​C> t1,
                                                                                    Transactional<T2,​C> t2)
        A utility method for combining multiple Transactional results. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
      • all

        public static <T1,​T2,​T3,​C> Transactional3<T1,​T2,​T3,​C> all​(Transactional<T1,​C> t1,
                                                                                                      Transactional<T2,​C> t2,
                                                                                                      Transactional<T3,​C> t3)
        A utility method for combining multiple Transactional results. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
      • all

        public static <T1,​T2,​T3,​T4,​C> Transactional4<T1,​T2,​T3,​T4,​C> all​(Transactional<T1,​C> t1,
                                                                                                                        Transactional<T2,​C> t2,
                                                                                                                        Transactional<T3,​C> t3,
                                                                                                                        Transactional<T4,​C> t4)
        A utility method for combining multiple Transactional results. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
      • all

        public static <T1,​T2,​T3,​T4,​T5,​C> Transactional5<T1,​T2,​T3,​T4,​T5,​C> all​(Transactional<T1,​C> t1,
                                                                                                                                          Transactional<T2,​C> t2,
                                                                                                                                          Transactional<T3,​C> t3,
                                                                                                                                          Transactional<T4,​C> t4,
                                                                                                                                          Transactional<T5,​C> t5)
        A utility method for combining multiple Transactional results. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.
      • all

        public static <T1,​T2,​T3,​T4,​T5,​T6,​C> Transactional6<T1,​T2,​T3,​T4,​T5,​T6,​C> all​(Transactional<T1,​C> t1,
                                                                                                                                                            Transactional<T2,​C> t2,
                                                                                                                                                            Transactional<T3,​C> t3,
                                                                                                                                                            Transactional<T4,​C> t4,
                                                                                                                                                            Transactional<T5,​C> t5,
                                                                                                                                                            Transactional<T6,​C> t6)
        A utility method for combining multiple Transactional results. The procedures are executed sequentially. If any of the procedures throws, the transaction will be rolled back.