Extent Access

An extent provides you with access to all the persistent instances of a class and, optionally, its subclasses. You can iterate over the elements of the extent or perform a query on the extent. The JDO Extent interface represents the extent of a class. Later in this chapter, we will discuss the IgnoreCache flag, which controls whether instances made persistent or deleted during the current transaction are contained in the extent.

You control whether an extent is maintained for a class in the metadata. You use the metadata class element’s requires-extent attribute to indicate whether the persistent class has an extent. It has a default value of "true“.

If your application does not need to iterate over the instances of a class or perform a query on the extent, you can set the requires-extent attribute to "false" explicitly. Even if a class does not have an extent, you can still make instances persistent, establish references to them, and navigate to them in your application and queries.

JDO 1.0.1 requires that if a class has a requires-extent set to "true“, none of its subclasses can set requires-extent to "false“. If your application specifies the subclass’s parameter to be true when calling the getExtent( ) method for a base class, all subclass instances are included in the iteration of the extent.

Accessing an Extent

You access the Extent associated with a class by calling the following PersistenceManager method:

Extent getExtent(Class persistentClass, boolean subclasses); ...

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.