1 8 9 package org.jboss.tutorial.extended.client; 10 11 import javax.naming.InitialContext ; 12 import org.jboss.tutorial.extended.bean.Customer; 13 import org.jboss.tutorial.extended.bean.ShoppingCart; 14 import org.jboss.tutorial.extended.bean.StatelessRemote; 15 16 18 19 25 26 public class Client 27 { 28 public static InitialContext getInitialContext() throws Exception 29 { 30 return new InitialContext (); 31 } 32 33 public static void testLongLivedSession() throws Exception 34 { 35 ShoppingCart test = (ShoppingCart) getInitialContext().lookup(ShoppingCart.class.getName()); 36 StatelessRemote remote = (StatelessRemote) getInitialContext().lookup(StatelessRemote.class.getName()); 37 Customer c; 38 39 long id = test.createCustomer(); 40 c = remote.find(id); 41 System.out.println("Created customer: " + c.getName()); 42 43 test.update(); 44 c = remote.find(id); 45 System.out.println("ShoppingCartBean.customer should stay managed because we're in an extended PC: Customer.getName() == " + c.getName()); 46 47 test.update3(); 48 c = remote.find(id); 49 System.out.println("Extended persistence contexts are propagated to nested EJB calls: Customer.getName() == " + c.getName()); 50 test.checkout(); 51 } 52 53 public static void testWithFlushMode() throws Exception 54 { 55 ShoppingCart cart = (ShoppingCart) getInitialContext().lookup(ShoppingCart.class.getName()); 56 StatelessRemote dao = (StatelessRemote) getInitialContext().lookup(StatelessRemote.class.getName()); 57 Customer c; 58 long id; 59 60 61 id = cart.createCustomer(); 62 c = dao.find(id); 63 System.out.println("Created customer: " + c.getName()); 64 65 cart.never(); 66 c = dao.find(id); 67 System.out.println("Customer's name should still be William as pc was not yet flushed: Customer.getName() == " + c.getName()); 68 69 cart.checkout(); 70 c = dao.find(id); 71 System.out.println("Now that the pc has been flushed name should be 'Bob': Customer.getName() == " + c.getName()); 72 73 } 74 75 public static void main(String [] args) throws Exception 76 { 77 testWithFlushMode(); 78 testLongLivedSession(); 79 } 80 } 81 | Popular Tags |