Class ExecutorAsyncOperations

  • All Implemented Interfaces:
    AsyncRepositoryOperations

    public class ExecutorAsyncOperations
    extends java.lang.Object
    implements AsyncRepositoryOperations
    An implementation of AsyncRepositoryOperations that delegates to a blocking operations and specified Executor. This can be used in absence of true asynchronous support at the driver level.

    If a backing implementation provides a async API then the backing implementation should not use this class and instead directly implement the AsyncRepositoryOperations interface.

    Since:
    1.0.0
    Author:
    graemerocher
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> java.util.concurrent.CompletableFuture<java.lang.Long> count​(PagedQuery<T> pagedQuery)
      Counts all results for the given query.
      <T> java.util.concurrent.CompletableFuture<java.lang.Number> delete​(DeleteOperation<T> operation)
      Deletes the entity.
      <T> java.util.concurrent.CompletableFuture<java.lang.Number> deleteAll​(DeleteBatchOperation<T> operation)
      Deletes all the entities of the given type.
      java.util.concurrent.CompletionStage<java.lang.Number> executeDelete​(PreparedQuery<?,​java.lang.Number> preparedQuery)
      Executes a delete batch for the given query and parameter values.
      java.util.concurrent.CompletableFuture<java.lang.Number> executeUpdate​(PreparedQuery<?,​java.lang.Number> preparedQuery)
      Executes an update for the given query and parameter values.
      <T> java.util.concurrent.CompletableFuture<java.lang.Boolean> exists​(PreparedQuery<T,​java.lang.Boolean> preparedQuery)
      Check with an record exists for the given query.
      <T> java.util.concurrent.CompletableFuture<java.lang.Iterable<T>> findAll​(PagedQuery<T> pagedQuery)
      Finds all results for the given query.
      <T,​R>
      java.util.concurrent.CompletableFuture<java.lang.Iterable<R>>
      findAll​(PreparedQuery<T,​R> preparedQuery)
      Finds all results for the given query.
      <T,​R>
      java.util.concurrent.CompletableFuture<R>
      findOne​(PreparedQuery<T,​R> preparedQuery)
      Find one by Query.
      <T> java.util.concurrent.CompletableFuture<T> findOne​(java.lang.Class<T> type, java.io.Serializable id)
      Find one by ID.
      <T,​R>
      java.util.concurrent.CompletableFuture<R>
      findOptional​(PreparedQuery<T,​R> preparedQuery)
      Find one by Query.
      <T> java.util.concurrent.CompletableFuture<T> findOptional​(java.lang.Class<T> type, java.io.Serializable id)
      Find one by ID.
      <R> java.util.concurrent.CompletableFuture<Page<R>> findPage​(PagedQuery<R> pagedQuery)
      Find a page for the given entity and pageable.
      java.util.concurrent.Executor getExecutor()  
      <T> java.util.concurrent.CompletableFuture<T> persist​(InsertOperation<T> entity)
      Persist the entity returning a possibly new entity.
      <T> java.util.concurrent.CompletableFuture<java.lang.Iterable<T>> persistAll​(InsertBatchOperation<T> operation)
      Persist all the given entities.
      <T> java.util.concurrent.CompletableFuture<T> update​(UpdateOperation<T> operation)
      Updates the entity returning a possibly new entity.
      <T> java.util.concurrent.CompletableFuture<java.lang.Iterable<T>> updateAll​(UpdateBatchOperation<T> operation)
      Updates the entities for the given operation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ExecutorAsyncOperations

        public ExecutorAsyncOperations​(@NonNull
                                       RepositoryOperations operations,
                                       @NonNull
                                       java.util.concurrent.Executor executor)
        Default constructor.
        Parameters:
        operations - The target operations
        executor - The executor to use.
    • Method Detail

      • getExecutor

        public java.util.concurrent.Executor getExecutor()
        Specified by:
        getExecutor in interface AsyncRepositoryOperations
        Returns:
        The executor used by this async operations
      • findOne

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<T> findOne​(@NonNull
                                                                     java.lang.Class<T> type,
                                                                     @NonNull
                                                                     java.io.Serializable id)
        Description copied from interface: AsyncRepositoryOperations
        Find one by ID.
        Specified by:
        findOne in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        type - The type
        id - The id
        Returns:
        A completion stage that emits the result
      • exists

        public <T> java.util.concurrent.CompletableFuture<java.lang.Boolean> exists​(@NonNull
                                                                                    PreparedQuery<T,​java.lang.Boolean> preparedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Check with an record exists for the given query.
        Specified by:
        exists in interface AsyncRepositoryOperations
        Type Parameters:
        T - The declaring type
        Parameters:
        preparedQuery - The query
        Returns:
        True if it exists
      • findOne

        @NonNull
        public <T,​R> java.util.concurrent.CompletableFuture<R> findOne​(@NonNull
                                                                             PreparedQuery<T,​R> preparedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Find one by Query.
        Specified by:
        findOne in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic resultType
        R - The result type
        Parameters:
        preparedQuery - The prepared query
        Returns:
        A completion stage that emits the result
      • findOptional

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<T> findOptional​(@NonNull
                                                                          java.lang.Class<T> type,
                                                                          @NonNull
                                                                          java.io.Serializable id)
        Description copied from interface: AsyncRepositoryOperations
        Find one by ID.
        Specified by:
        findOptional in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        type - The type
        id - The id
        Returns:
        A completion stage that emits the result or null if there is no result
      • findOptional

        @NonNull
        public <T,​R> java.util.concurrent.CompletableFuture<R> findOptional​(@NonNull
                                                                                  PreparedQuery<T,​R> preparedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Find one by Query.
        Specified by:
        findOptional in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic resultType
        R - The result type
        Parameters:
        preparedQuery - The prepared query
        Returns:
        A completion stage that emits the result or null if there is no result
      • findAll

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<java.lang.Iterable<T>> findAll​(@NonNull
                                                                                         PagedQuery<T> pagedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Finds all results for the given query.
        Specified by:
        findAll in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        pagedQuery - The paged query
        Returns:
        A completion stage that emits the results
      • count

        public <T> java.util.concurrent.CompletableFuture<java.lang.Long> count​(@NonNull
                                                                                PagedQuery<T> pagedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Counts all results for the given query.
        Specified by:
        count in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        pagedQuery - The paged query
        Returns:
        A completion stage that emits the count as a long
      • findAll

        @NonNull
        public <T,​R> java.util.concurrent.CompletableFuture<java.lang.Iterable<R>> findAll​(@NonNull
                                                                                                 PreparedQuery<T,​R> preparedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Finds all results for the given query.
        Specified by:
        findAll in interface AsyncRepositoryOperations
        Type Parameters:
        T - The entity type
        R - The result type
        Parameters:
        preparedQuery - The prepared query
        Returns:
        A completion stage that emits an iterable with all results
      • persist

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<T> persist​(@NonNull
                                                                     InsertOperation<T> entity)
        Description copied from interface: AsyncRepositoryOperations
        Persist the entity returning a possibly new entity.
        Specified by:
        persist in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        entity - The entity operation
        Returns:
        A completion stage that emits the entity
      • update

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<T> update​(@NonNull
                                                                    UpdateOperation<T> operation)
        Description copied from interface: AsyncRepositoryOperations
        Updates the entity returning a possibly new entity.
        Specified by:
        update in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        operation - The entity operation
        Returns:
        A completion stage that emits the entity
      • updateAll

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<java.lang.Iterable<T>> updateAll​(@NonNull
                                                                                           UpdateBatchOperation<T> operation)
        Description copied from interface: AsyncRepositoryOperations
        Updates the entities for the given operation.
        Specified by:
        updateAll in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        operation - The operation
        Returns:
        The updated entities
      • delete

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<java.lang.Number> delete​(@NonNull
                                                                                   DeleteOperation<T> operation)
        Description copied from interface: AsyncRepositoryOperations
        Deletes the entity.
        Specified by:
        delete in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        operation - The batch operation
        Returns:
        A publisher that emits the number of entities deleted
      • persistAll

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<java.lang.Iterable<T>> persistAll​(@NonNull
                                                                                            InsertBatchOperation<T> operation)
        Description copied from interface: AsyncRepositoryOperations
        Persist all the given entities.
        Specified by:
        persistAll in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        operation - The batch operation
        Returns:
        The entities, possibly mutated
      • executeUpdate

        @NonNull
        public java.util.concurrent.CompletableFuture<java.lang.Number> executeUpdate​(@NonNull
                                                                                      PreparedQuery<?,​java.lang.Number> preparedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Executes an update for the given query and parameter values. If it is possible to return the number of objects updated, then do so.
        Specified by:
        executeUpdate in interface AsyncRepositoryOperations
        Parameters:
        preparedQuery - The prepared query
        Returns:
        A completion that emits a boolean true if successful
      • executeDelete

        public java.util.concurrent.CompletionStage<java.lang.Number> executeDelete​(PreparedQuery<?,​java.lang.Number> preparedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Executes a delete batch for the given query and parameter values. If it is possible to return the number of objects updated, then do so.
        Specified by:
        executeDelete in interface AsyncRepositoryOperations
        Parameters:
        preparedQuery - The prepared query
        Returns:
        A completion that emits a boolean true if successful
      • deleteAll

        @NonNull
        public <T> java.util.concurrent.CompletableFuture<java.lang.Number> deleteAll​(@NonNull
                                                                                      DeleteBatchOperation<T> operation)
        Description copied from interface: AsyncRepositoryOperations
        Deletes all the entities of the given type.
        Specified by:
        deleteAll in interface AsyncRepositoryOperations
        Type Parameters:
        T - The generic type
        Parameters:
        operation - The batch operation
        Returns:
        A completion that emits a boolean true if successful
      • findPage

        public <R> java.util.concurrent.CompletableFuture<Page<R>> findPage​(@NonNull
                                                                            PagedQuery<R> pagedQuery)
        Description copied from interface: AsyncRepositoryOperations
        Find a page for the given entity and pageable.
        Specified by:
        findPage in interface AsyncRepositoryOperations
        Type Parameters:
        R - The entity generic type
        Parameters:
        pagedQuery - The paged query
        Returns:
        The page type