Explicit Management of Instances in the Cache
Normally, a persistent instance is managed in the cache automatically and this management is completely transparent to the application. When you query instances, navigate to instances, or modify instances, the instances are instantiated and their field values are fetched from the datastore. The implementation determines when to fetch a field’s value from the datastore, which can occur at any time prior to the application’s access of the field.
Instances that are no longer referenced in memory are
garbage-collected without requiring your application to perform any
explicit action. When you commit a transaction in which persistent
instances were created, deleted, or modified, the transaction-completion
mechanisms automatically handle the eviction of instances from the
cache. So, you usually do not need to evict instances explicitly. By
eviction, we mean that the PersistenceManager
no longer holds a strong
reference to the instances, allowing them to be garbage-collected. The
JVM is still responsible for reclaiming the memory held by the
instances.
Refreshing Instances
JDO provides a means to refresh instances in the cache with their current values in the datastore. This can be useful outside of a transaction (Chapter 14 covers nontransactional access). It is also useful when you use optimistic transactions (covered in Chapter 15). Refreshing an instance can also be used with datastore transactions. If you use a transaction-isolation level ...
Get Java Data Objects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.