Onyx Database: Delete Tutorial

You can download the code for this example here:

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

This tutorial demonstrates easy it is to bulk delete entities that meet a given criteria. To demonstrate this we will delete all Player entities that have the active attribute set to 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

    Internally, Onyx Database will delete all off the entities applicable to the criteria.

  3. Before executing the delete, confirm that there are entities there to delete
  4. Invoke the PersistenceManager#executeDelete method

    This will execute the delete action

    Notes:
    The executeDelete method supports the following argument:
    Query: The query used to find the entities you want to delete
    Alternatively, you can use the following methods to delete entities:
    deleteEntity(Entity entity) Deletes the provided entity. Only the identifier attribute needs to be set for the entity passed.
    deleteEntites(List<Entity> entities) Deletes a List of entities.
  5. Now, lets re-execute the query to verify that the entities were deleted.
  6. Make sure to close the factory when you are done with it.
  7. Update Query