FileDocCategorySizeDatePackage
Client.javaAPI DocJBoss 4.2.13345Fri Jul 13 20:55:02 BST 2007org.jboss.tutorial.extended.client

Client

public class Client extends Object
Sample client for the jboss container.
author
Bill Burke
version
$Id: Client.java 60233 2007-02-03 10:13:23Z wolfc $

Fields Summary
Constructors Summary
Methods Summary
public static javax.naming.InitialContextgetInitialContext()

      return new InitialContext();
   
public static voidmain(java.lang.String[] args)

      testWithFlushMode();
      testLongLivedSession();
   
public static voidtestLongLivedSession()

      ShoppingCart test = (ShoppingCart) getInitialContext().lookup("ShoppingCartBean/remote");
      StatelessRemote remote = (StatelessRemote) getInitialContext().lookup("StatelessSessionBean/remote");
      Customer c;

      long id = test.createCustomer();
      c = remote.find(id);
      System.out.println("Created customer: " + c.getName());

      test.update();
      c = remote.find(id);
      System.out.println("ShoppingCartBean.customer should stay managed because we're in an extended PC: Customer.getName() == " + c.getName());

      test.update3();
      c = remote.find(id);
      System.out.println("Extended persistence contexts are propagated to nested EJB calls: Customer.getName() == " + c.getName());
      test.checkout();
   
public static voidtestWithFlushMode()

      ShoppingCart cart = (ShoppingCart) getInitialContext().lookup("ShoppingCartBean/remote");
      StatelessRemote dao = (StatelessRemote) getInitialContext().lookup("StatelessSessionBean/remote");
      Customer c;
      long id;


      id = cart.createCustomer();
      c = dao.find(id);
      System.out.println("Created customer: " + c.getName());

      cart.never();
      c = dao.find(id);
      System.out.println("Customer's name should still be William as pc was not yet flushed:  Customer.getName() == " + c.getName());

      cart.checkout();
      c = dao.find(id);
      System.out.println("Now that the pc has been flushed name should be 'Bob': Customer.getName() == " + c.getName());