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 > ... > Basic EntityManager tutorial > Basic EntityManager tutorial step 4
developerWorks
Log In   View a printable version of the current page.
Overview Connect Spaces Forums Wikis
Basic EntityManager tutorial step 4
Added by Chris.D.Johnson, last edited by saif.patel@us.ibm.com on Jan 12, 2009  (view change)
Labels: 
(None)

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.

This tutorial illustrates how to develop a local, in-memory ObjectGrid that stores order information for an online retail store.

Step 4 expands on the previous step to demonstrate how to update an entity.

The following example demonstrates how to find the Order instance, change it and any referenced entities, and commit the transaction.

public static void updateCustomerOrder(EntityManager em) {
    em.getTransaction().begin();
    Order order = (Order) em.find(Order.class, "ORDER_1");
    processDiscount(order, 10);
    Customer cust = order.customer;
    cust.phoneNumber = "5075551234";
    em.getTransaction().commit();        
}
   
public static void processDiscount(Order order, double discountPct) {
    for(OrderLine line : order.lines) {
        line.price = line.price * ((100-discountPct)/100);
    }
}

Flushing the transaction synchronizes all managed entities with the ObjectGrid cache. When a transaction is commited, a flush automatically occurs. In this case, the Order becomes a Managed entity, as well as any entities that are referenced from the Order, Customer, and OrderLine. When the transaction is flushed, each of the entities are checked to determine if they have been modified. Those that are modified are updated in the cache. After the transaction completes, by either being committed or rolled back, the entities become detached and any changes made to them will not be reflected in the cache.

Previous Step Next Step

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


 
    About IBM Privacy Contact