Reactive Requests

In addition to all return types supported by the OSS mapper annotations, The DSE mapper also supports two reactive return types:

  1. MappedReactiveResultSet can be used as a return type for a methods annotated with @Select or @Query. It is a Publisher of mapped entities that also implements ReactiveQueryMetadata. This class is specific to the DSE mapper.
  2. The DSE core driver’s ReactiveResultSet can be used as a return type for methods annotated with @Insert, @Update, @Delete and @Query. Returning a ReactiveResultSet from @Insert, @Update and @Delete methods is mostly useful if you need to inspect returned query metadata in a reactive fashion.

Refer to the DSE driver documentation on reactive queries for more information reactive programming support in the DSE driver.


Consider the following DAO interface:

public interface ProductDao {

  MappedReactiveResultSet<Product> findById(UUID productId);

  ReactiveResultSet saveReactive(Product product);

  ReactiveResultSet updateReactive(Product product);

  ReactiveResultSet deleteReactive(Product product);

  @Query("SELECT * FROM ${qualifiedTableId} WHERE description LIKE :description")
  MappedReactiveResultSet<Product> findByDescription(String description);

Assuming that you are using Reactor as your reactive library, the above DAO can be used as follows:

ProductDao dao = ...;
UUID toFind = ...;

// execute the SELECT query, expect at most 1 item
Optional<Product> maybeFound =
        .doOnNext(p -> System.out.println("Found product: " + p))

assert maybeFound.isPresent();

Product product = maybeFound.get();
product.setDescription("new description");

// execute the UPDATE query and block until it returns
ReactiveResultSet rs = dao.updateReactive(product);
// inspect query metadata and print all query warnings, if any
    .doOnNext(warning -> System.err.println("Query produced warning: " + warning))

// execute the query, print each entity found, then the total number of entites found
Flux.from(dao.findByDescription("new description"))
    .doOnNext(p -> System.out.println("Found product: " + p))
    .doOnSuccess(n -> System.out.println(String.format("Found %d products", n)))

// execute the DELETE query and block until it returns