[Java programming language only]

Developing client-based JPA loaders

You can implement preloading and reloading of data in your application with a Java Persistence API (JPA) utility. This capability can simplify loading the maps when the queries to the database cannot be partitioned.

Before you begin

  • You must be using a JPA provider with a supported database.
  • Before you preload or reload maps, you must set the availability state of the ObjectGrid to PRELOAD. You can set the availability state with the setObjectGridState method of the StateManager interface. The StateManager interface prevents other clients from accessing the ObjectGrid when it is not yet online. After you preload or reload the map, you can set the state back to ONLINE.
  • When you are preloading different maps in one ObjectGrid, set the ObjectGrid state to PRELOAD one time and set the value back to ONLINE after all maps finish data loading. This coordination can be done by the ClientLoadCallback interface. Set the ObjectGrid state to PRELOAD after the first preStart notification from the ObjectGrid instance, and set it back to ONLINE after the last postFinish notification.
  • If you need to preload maps from different Java™ virtual machines, you have to coordinate between multiple Java virtual machines. Set the ObjectGrid state to PRELOAD one time before the first map is being preloaded in any of the Java virtual machines, and set the value back to ONLINE after all maps finish data loading in all the Java virtual machines. For more information, see Managing ObjectGrid availability.

About this task

When you run a preload or reload operation on your map, the following actions occur:
  1. The initial action that is taken depends on if you are running a preload or reload operation.
    • Preload operation: The map to be preloaded is cleared. For an entity map, if any relation is configured as cascade-remove, any related maps are cleared.
    • Reload operation: The provided query is run on the map and the results are invalidated. For an entity map, if any relation is configured with the CascadeType.INVALIDATE option, the related entities are also invalidated from their maps.
  2. Run the query to JPA for the entities in a batch.
  3. For each batch, a key list and value list for each partition is built.
  4. For each partition, the data grid agent is called to insert or update the data on the server side directly if it is an eXtreme Scale client. If the data grid is a local instance, the data in the maps is directly inserted or updated.