Skip to main content
Version: Current

Types of API - RxEntityDb

RxJava is a Java implementation of reactive extensions. The Genesis database uses this library to represent asynchronous database operations in java.

If you are using Java. RxJava API is the only way of accessing the database. For Kotlin, the async API is preferred (although the RxJava API is also supported).

Subscription

It is important to note that any database operation with RxJava return type is cold until it is subscribed to. This means that the operation is not sent to the database until that time.

RxJava return types

The Genesis database uses three RxJava return types:

Return typeminimum returnsmaximum returns
Single11
Maybe01
Flowable0

Single

In the RxJava API, a Single represents an asynchronous operation that has two possible outcomes:

  • a success with result, or
  • a failure

For example, on the database, delete returns a Single, with the following possible outcomes:

  • the record was deleted; it provides a write result
  • the operation was not successful; for example, the record was not found

Maybe

In the RxJava API, a Maybe represents an asynchronous operation that has three possible outcomes:

  • a success with result
  • a success with no result
  • a failure

For example, on the database, get returns a Maybe, with the following possible outcomes:

  • a record is found
  • no record is found
  • the operation was not successful, for example the index was incorrect

Flowable

In the RxJava API, a Flowable represents an asynchronous operation that has an undefined number of outputs.