Onyx Database: Find Tutorial

You can download the code for this example here:

OnyxDevTools/onyx-database-examples/querying/FindExample.

The find method is a handy way of retrieving a single object stored in Onyx Database. This tutorial assumes that you have already stored a hierarchy of related data in an embedded local Onyx Database. In this case, the data stores the stats for all of the team leaders for each team in the NFL for the 2015 season. To see how the data was seeded for this example, see Main.java.

  1. Get an Instance of the PersistenceManager.
  2. Create a new entity variable to hold the entity.
    Notes:
    The entity is just an empty shell.
    Make sure to set the Identifier field so that the manager knows which record to find.
  3. Invoke the PersistenceManager#find method

    This will retrieve the entity object you looking for

    Notes:
    Notice that the league variable was re-assigned to the value returned by the Find method; this is not required, you can simply use the find method to hydrate the entity.
    If the resource you are requesting does not exist, a com.onyx.exception.NoResultsException is thrown.
  4. Now, lets confirm that the other fields of this entity were populated.
  5. Make sure to close the factory when you are done with it.
  6. Find By ID