9.2. JPA Extensions

9.2.1. KodoEntityManagerFactory
9.2.2. KodoEntityManager
9.2.3. KodoQuery
9.2.4. Extent
9.2.5. StoreCache
9.2.6. QueryResultCache
9.2.7. FetchPlan
9.2.8. KodoPersistence

The following sections outline the runtime interfaces you can use to access Kodo-specific functionality from JPA. Each interface contains services and convenience methods missing from the JPA specification. Kodo strives to use the same naming conventions and API patterns as standard JPA methods in all extensions, so that Kodo JDO APIs feel as much as possible like standard JPA.

You may have noticed the examples throughout this document using the KodoPersistence.cast methods to cast from standard JPA interfaces to Kodo extended interfaces. This is the recommended practice. Some application server vendors may proxy Kodo's JPA implementation, preventing a straight cast. KodoPersistence's cast methods work around these proxies.

 
public static KodoEntityManagerFactory cast (EntityManagerFactory emf);
public static KodoEntityManager cast (EntityManager em);
public static KodoQuery cast (Query q);

We provide additional information on the KodoPersistence helper below.

9.2.1. KodoEntityManagerFactory

The kodo.persistence.KodoEntityManagerFactory interface extends the basic javax.persistence.EntityManagerFactory with Kodo-specific features. The KodoEntityManagerFactory offers APIs to obtain managed and unmanaged EntityManagers from the same factory, to access the Kodo data and query caches, and to perform other Kodo-specific operations. See the interface Javadoc for details.

9.2.2. KodoEntityManager

All Kodo EntityManagers implement the kodo.persistence.KodoEntityManager interface. This interface extends the standard javax.persistence.EntityManager. Just as the standard EntityManager is the primary window into JPA services, the KodoEntityManager is the primary window from JPA into Kodo-specific functionality. We strongly encourage you to investigate the API extensions this interface contains.

9.2.3. KodoQuery

Kodo extends JPA's standard query functionality with the kodo.persistence.KodoQuery interface. See its Javadoc for details on the convenience methods it provides.

9.2.4. Extent

An Extent is a logical view of all persistent instances of a given entity class, possibly including subclasses. Kodo adds the kodo.persistence.Extent class to the set of Java Persistence APIs. The following code illustrates iterating over all instances of the Magazine entity, without subclasses:

Example 9.3. Using a JPA Extent

import kodo.persistence.*;

...

KodoEntityManager kem = KodoPersistence.cast (em);
Extent<Magazine> mags = kem.getExtent (Magazine.class, false);
for (Magazine m : mags)
    processMagazine (m);

9.2.5. StoreCache

In addition to the EntityManager object cache mandated by the JPA specification, Kodo includes a flexible datastore-level cache. You can access this cache from your JPA code using the kodo.persistence.StoreCache facade. Section 10.1, “Data Cache” has detailed information on Kodo's data caching system, including the StoreCache facade.

9.2.6. QueryResultCache

Kodo can cache query results as well as persistent object data. The kodo.persistence.QueryResultCache is an JPA-flavored facade to Kodo's internal query cache. See Section 10.1.3, “Query Cache” for details on query caching in Kodo.

9.2.7. FetchPlan

Many of the aforementioned Kodo interfaces give you access to a kodo.persistence.FetchPlan instance. The FetchPlan allows you to exercise some control over how objects are fetched from the datastore, including large result set support, custom fetch groups, and lock levels.

Kodo goes one step further, extending FetchPlan with kodo.persistence.jdbc.JDBCFetchPlan to add additional JDBC-specific tuning methods. Unless you have customized Kodo to use a non-relational back-end (see Section 9.9, “Non-Relational Stores”), all FetchPlans in Kodo implement JDBCFetchPlan, so feel free to cast to this interface.

Fetch plans pass on from parent components to child components. The EntityManagerFactory settings (via your configuration properties) for things like the fetch size, result set type, and custom fetch groups are passed on to the fetch plan of the EntityManagers it produces. The settings of each EntityManager, in turn, are passed on to each Query and Extent it returns. Note that the opposite, however, is not true. Modifying the fetch plan of a Query or Extent does not affect the EntityManager's configuration. Likewise, modifying an EntityManager's configuration does not affect the EntityManagerFactory.

Section 5.6, “Fetch Groups” includes examples using FetchPlans.

9.2.8. KodoPersistence

kodo.persistence.KodoPersistence is a static helper class that adds Kodo-specific utility methods to javax.persistence.Persistence.

 

Skip navigation bar   Back to Top