Entering content frame

Object documentation Extent Locate the document in its SAP Library structure

Definition

An instance of the javax.jdo.Extent interface represents a set of all persistent instances of a candidate class, optionally including the subclasses as well.

Use

Extents are generally used to specify the set of instances of the candidate class that are to be filtered by the query. They can be also used to iterate over the included instances of the candidate class.

The extent differs from a collection in that it can identify the instances in the datastore, which enables the objects to be instantiated in the memory only after they have been accessed by an iterator.

Creating an Extent

To create an extent, use the getExtent(Class persistenceCapableClass, boolean subclasses) method of the PersistenceManager interface:

Example

Extent employeeExtent = pm.getExtent(Employee, true);

The example creates an extent for the Employee class including all subclasses.

Iterating an Extent

You can iterate over the elements of an extent using an iterator, which is obtained by invoking the Extent.iterator() method:

Example

Iterator iter = employeeExtent.iterator();

while(iter.hasNext()) {

   Employee emp = (Employee)iter.next();

   doSomething(emp.getFirstName()+" "+emp.getLastName());

}

The example creates an iterator from the employeeExtent, iterates over all elements, and calls the doSomething() method for each employee.

 

 

Leaving content frame