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
© Copyright IBM Corporation 2007,2009. All Rights Reserved.