KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > extended > client > Client


1 /*
2  *
3  * JBoss, the OpenSource J2EE webOS
4  *
5  * Distributable under LGPL license.
6  * See terms of license at gnu.org.
7  */

8
9 package org.jboss.tutorial.extended.client;
10
11 import javax.naming.InitialContext JavaDoc;
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 //import java.rmi.*;
17

18
19 /**
20  * Sample client for the jboss container.
21  *
22  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
23  * @version $Id: Client.java,v 1.1.2.2 2005/06/24 05:26:28 bill Exp $
24  */

25
26 public class Client
27 {
28    public static InitialContext JavaDoc getInitialContext() throws Exception JavaDoc
29    {
30       return new InitialContext JavaDoc();
31    }
32
33    public static void testLongLivedSession() throws Exception JavaDoc
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 JavaDoc
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 JavaDoc[] args) throws Exception JavaDoc
76    {
77       testWithFlushMode();
78       testLongLivedSession();
79    }
80 }
81
Popular Tags