Onyx Database: Update Tutorial

You can download the code for this example here:

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

This tutorial demonstrates how easy it is to bulk update entities that meet a given criteria. To demonstrate this we will update all quarterbacks that passed for less than 1500 yards and set them to active = false.


To see how the data was seeded for this example, see Main.java.
  1. Get an Instance of the PersistenceManager.
  2. Create a Query and QueryCriteria

    First, lets retrieve all of the data that meets our criteria. This isnt required for the update to work, but is just to demonstrate the initial state of the com.onyxdevtools.entities.

  3. Execute the query and print out the results
    The output looks like this :
    Matt Cassel: active=true
  4. Create an AttributeUpdate
    Notes:
    An AttributeUpdate contains two inputs:
    fieldName The attribute you want to update
    value The value you want to set that attribute to
  5. Invoke the PersistenceManager#executeUpdate method

    This will execute the AttributeUpdate action on all of the results that match your criteria

    Notes:
    You can supply the query with a single AttributeUpdate or a List<AttributeUpdate>.
  6. Now, lets re-execute the query to verify that the entities were updated.
    The output now look like this :
    Matt Cassel: active=false
  7. Make sure to close the factory when you are done with it.
  8. Sorting and Paging