Program guide > Access data with client applications > Cache objects and their relationships (EntityManager API)

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.

The cost of using the EntityManager interface is not high and depends on the type of work being performed. Always use the EntityManager interface and optimize the crucial business logic after the application is complete. You can rework any code that uses EntityManager interfaces to use maps and tuples. Generally, this code rework might be necessary for ten percent of the code.

If you use relationships between objects, then the performance impact is lower because an application that is using maps needs to manage those relationships similarly to the EntityManager interface.

Applications that use the EntityManager interface do not need to provide an ObjectTransformer because it is optimized automatically.

Reworking EntityManager code for maps

A sample entity follows:

public class Person 
    String ssn;
    String firstName;
    String middleName;
    String surname;

Some code to find the entity and update the entity follows:

Person p = null;
p = (Person)em.find(Person.class, "1234567890");
p.middleName = String.valueOf(inner);

The same code using Maps and Tuples follows:

Tuple key = null;
key = map.getEntityMetadata().getKeyMetadata().createTuple();
key.setAttribute(0, "1234567890");

// The Copy Mode is always NO_COPY for entity maps if not using COPY_TO_BYTES.
// Either we need to copy the tuple or we can ask the ObjectGrid to do it for us:
Tuple value = (Tuple)map.get(key);
value.setAttribute(1, String.valueOf(inner));
map.update(key, value);
value = null;

Both of these code snippets have the same result, and an application can use either or both snippets.

The second code snippet shows how to use maps directly and how to work with the tuples (the key and value pairs). The value tuple has three attributes: firstName, middlename, and surname, indexed at 0, 1, and 2 respectively. The key tuple has a single attribute the ID number is indexed at zero. You can see how Tuples are created by using the EntityMetadata#getKeyMetaData or EntityMetadata#getValueMetaData methods. Use these methods to create Tuples for an Entity. You cannot implement the Tuple interface and pass an instance of the Tuple implementation.

Parent topic:

Cache objects and their relationships (EntityManager API)

Related concepts

EntityManager in a distributed environment

Interacting with EntityManager

EntityManager fetch plan support

Entity query queues

Related tasks

Entity manager tutorial: Overview

Related reference

Define an entity schema

EntityTransaction interface


Search Tips   |   Advanced Search