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.
Get an Instance of the PersistenceManager.
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 entities.
Execute the query and print out the results
The output looks like this :
Matt Cassel: active=true
Create an AttributeUpdate
An AttributeUpdate contains two inputs:
fieldName The attribute you want to update
value The value you want to set that attribute to
Invoke the PersistenceManager#executeUpdate method
This will execute the AttributeUpdate action on all of the results that match your criteria
You can supply the query with a single AttributeUpdate or a List<AttributeUpdate>.
Now, lets re-execute the query to verify that the entities were updated.
The output now look like this :
Matt Cassel: active=false
Make sure to close the factory when you are done with it.