WebSphere eXtreme Scale Programming Guide > Access data in WebSphere eXtreme Scale
EntityManager API introduction
Most cache products use map-based APIs to store data as key-value pairs. The ObjectMap API and the dynamic cache in WebSphere Application Server, 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 WebSphere Application Server 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.
Use EntityManager
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
You can 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. You can use these EntityManager APIs if the client has access to the defined entity classes.- EntityManager fetch plan support
A FetchPlan is the strategy the eXtreme Scale EntityManager 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
You can use the EntityTransaction interface to demarcate transactions.
Parent topic
Access data in WebSphere eXtreme ScaleRelated reference
API documentation: EntityManager interface