IBM®
Skip to main content
    Country/region [select]      Terms of use
 
 
    
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerworks > My developerWorks >  Dashboard > WebSphere eXtreme Scale V6.1 User Guide > ... > Introduction to the EntityManager API > EntityManager interface
developerWorks
Log In   View a printable version of the current page.
Overview Connect Spaces Forums Wikis
EntityManager interface
Added by RKATARYA, last edited by Chris.D.Johnson on Jan 07, 2008  (view change)
Labels: 

Getting Started Examples Reference API documentation

See the WebSphere eXtreme Scale Wiki for links to eXtreme Scale Version 7.0 documentation.
If you log in with your developerWorks ID, you can leave comments and feedback for the development team.

Use the EntityManager interface to interact with entitites. The major operations include persist, remove, find, and create a Query. EntityManger interface is available from the ObjectGrid Session, and a one-to-one relationship exists between the ObjectGrid Session instance and the EntityManager instance. See EntityManager API Documentation for more information.

The following example demonstrates how to retrieve the EntityManager Object:

ObjectGridManager ogManager = ObjectGridManagerFactory.getObjectGridManager();
ObjectGrid objectGrid=ogManager.getObjectGrid("objectGridName");
EntityManager entityManager = objectGrid.getSession().getEntityManager();

EntityManager is contained in package com.ibm.websphere.objectgrid.em. The following methods are defined on the interface:

public void persist(Object entity)

Use this method to persist new entities only. EntityManager tracks the state of the new entity instance. Before the transaction ends, the instance is in persistent and managed state.

When the transaction is committed, the entity is persisted in the ObjectGrid cache. Alternatively, if the transaction is rolledback, changes are not persisted. At the end of the transaction boundary, the entity is in the detached state.

The EntityManager interface honors cascade operation, as specified for the entity. For example, If CascadeType is either PERSIST or ALL, the persist operation is cascaded to all entity associations. By default, cascading is turned off.

The method will throw com.ibm.websphere.objectgrid.em.TransactionRequiredException if it is invoked in absense of an active Transaction.

com.ibm.websphere.objectgrid.em.EntityExistsException exception is thrown, if the entity already exists.

This method is a not available for a Managed entity unless it requires updates, in which case the entity is updated in the ObjectGrid cache after a sucessful transaction commits. If the CascadeType is PERSIST or ALL, any new established associations cascade.

public void remove(Object entity)

This method removes the entity instance from the ObjectGrid cache if it is invoked on a Managed entity. If CascasdeType is set to REMOVE or ALL, the operation is cascaded to all associations.
On a non-managed or detached entity, an IllegalArgumentException occurs.

public Object find(Class entityClass, Object primaryKey);

After the entity is already located in the cache, it can be found using this method. If the entity is not found, a null value is returned. This method can be invoked within a transaction demarcation, in which case the entity is in the managed state. If invoked, without the transaction demarcation, a detached entity instance is returned.
Semantics of locking are same as provided by the get() method on the ObjectMap interface, as it delegates to the Session Interface.

public Object findForUpdate(Class entityClass, Object primaryKey);

This object is similar to the find method that is described in the previous section, except it contains different locking semantics.
Semantics of locking are the same as those that are provided by the getForUpdate() method on the ObjectMap interface. If the Map is configured to use PESSIMISTIC locking, instead of getting an S lock, a U lock is obtained.

public void flush();

Similar to Session.flush(). It forces the current changes in the Session to the Loader or ObjectGrid server. This method does not commit the changes, it just applies the changes.

public FlushModeType setFlushMode(FlushModeType flushMode);

Sets the FlushMode. See java docs for FlushModeType

public FlushModeType getFlushMode();

Return the current FlushModeType

public EntityTransaction getTransaction();

Returns the EntityTransaction . See the API documentation for details

public Query createQuery(String qlString);

Create a Query instance for executing an ObjectGrid query language statement. See the Using EntityManager query topic for more details.

public QueryQueue createQueryQueue(String qlString, Class entityClass);

Create a QueryQueue instance. See the Entity query queues topic and the API documentation for more details.

public void clear();

Clear the EntityManager's context.

Causes all managed entities to become detached. Any changes made to entities that have not been flushed to the cache will not be persisted.

Wiki Disclaimer and License
© Copyright IBM Corporation 2007,2009. All Rights Reserved.


 
    About IBM Privacy Contact