Program guide > Access data with client applications
Cache objects and their relationships (EntityManager API)
Most cache products use map-based APIs to store data as key-value pairs. The ObjectMap API and the dynamic cache in WAS, among others, use this approach. However, map-based APIs have limitations. The EntityManager API simplifies the interaction with the eXtreme Scale cache by providing an easy way to declare and interact with a complex graph of related objects.
Map-based API limitations
If you are using a map-based API, such as the dynamic cache in WAS or the ObjectMap API, you have to take the following limitations into consideration:
- The cache must use reflection to extract data from the objects in the cache, which has performance implications.
- Two applications cannot share a cache if they use different objects for the same data.
- You cannot use data evolution because you cannot add an attribute to a cached Java™ object.
- It is difficult to work with graphs of objects. The application has to store artificial references between objects and manually join them together.
The EntityManager API uses the existing Map-based infrastructure, but it converts entity objects to and from tuples before storing or reading them from the Map. An entity object is transformed into a key tuple and a value tuple, which are then stored as key-value pairs. A tuple is an array of primitive attributes.
This set of APIs significantly eases the use of eXtreme Scale by following the Plain Old Java Object (POJO) style of programming that is adopted by most frameworks.
- Define an entity schema
An ObjectGrid can have any number of logical entity schemas. Entities are defined using annotated Java classes, XML, or a combination of both XML and Java classes. Defined entities are then registered with an eXtreme Scale server and bound to BackingMaps, indexes and other plug-ins.
- EntityManager in a distributed environment
Use EntityManager with a local ObjectGrid or in a distributed eXtreme Scale environment. The main difference is how you connect to this remote environment. After you establish a connection, there is no difference between using a Session object or using the EntityManager API.
- Interacting with EntityManager
Applications typically first obtain an ObjectGrid reference, and then a Session from that reference for each thread. Sessions cannot be shared between threads. An extra method on Session, the getEntityManager method, is available. This method returns a reference to an entity manager to use for this thread. The EntityManager interface can replace the Session and ObjectMap interfaces for all applications. Use these EntityManager APIs if the client has access to the defined entity classes.
- EntityManager fetch plan support
A FetchPlan is the strategy that the entity manager uses for retrieving associated objects if the application needs to access relationships.
- EntityManager interface performance impact
An environment requiring every application to use the same data access objects for a given datastore would be highly impractical. In contrast, the EntityManager interface that is provided with WebSphere eXtreme Scale separates applications from the state held in its server grid datastore.
- Entity query queues
Query queues allow applications to create a queue qualified by a query in the server-side or local eXtreme Scale over an entity. Entities from the query result are stored in this queue. Currently, query queue is only supported in a map that is using the pessimistic lock strategy.
- EntityTransaction interface
Use the EntityTransaction interface to demarcate transactions.
- Entity manager tutorial: Overview
The tutorial for the entity manager shows you how to use WebSphere eXtreme Scale to store order information on a Web site. You can create a simple Java Platform, Standard Edition 5 application that uses an in-memory, local eXtreme Scale. The entities use Java SE 5 annotations and generics.
Parent topic:Access data with client applications
Interacting with an ObjectGrid using ObjectGridManager
Data access with indexes (Index API)
Access data in WebSphere eXtreme Scale
Use Sessions to access data in the grid
Cache objects with no relationships involved (ObjectMap API)
Retrive entities and objects (Query API)
Configure clients with WebSphere eXtreme Scale
Java object caching concepts
Program for transactions
Connect to a distributed ObjectGrid