KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hessian > demo > server > Customer


1 package hessian.demo.server;
2
3 import hessian.demo.ICustomer;
4 import dinamica.*;
5 import dinamica.hessian.BasicService;
6 import java.sql.*;
7
8 /**
9  * Customer Web Service (Hessian protocol)<br>
10  * Returns customer information
11  * <br><br>
12  * <br>Creation date: 01/06/2004
13  * <br>(c) 2004 Martin Cordova y Asociados
14  * <br>http://www.martincordova.com
15  * @author Martin Cordova dinamica@martincordova.com
16  */

17 public class Customer extends BasicService implements ICustomer
18 {
19
20     /* (non-Javadoc)
21      * @see hessian.demo.ICustomer#getCustomer(java.lang.String)
22      */

23     public Recordset getCustomer(String JavaDoc custID) throws Throwable JavaDoc
24     {
25
26         //get connection from pool
27
Connection conn = getDataSource().getConnection();
28         
29         try
30         {
31             //assemble sql command
32
String JavaDoc sql = StringUtil.replace(getResource("customer.sql"), "{id}", custID);
33             String JavaDoc sql1 = StringUtil.replace(getResource("orders.sql"), "{id}", custID);
34             String JavaDoc sql2 = getResource("details.sql");
35             
36             //execute database logic
37
Db db = new Db( conn );
38             Recordset rs = db.get(sql);
39             
40             //get customer orders
41
Recordset rsOrders = db.get(sql1);
42             
43             //save orders into customer recordset
44
rs.first();
45             rs.setChildrenRecordset(rsOrders);
46             
47             //for each order get details
48
while (rsOrders.next())
49             {
50                 String JavaDoc cmd = StringUtil.replace(sql2, "{id}", rsOrders.getString("orderid"));
51                 Recordset rsDetail = db.get(cmd);
52                 rsOrders.setChildrenRecordset(rsDetail);
53             }
54             
55             //return result
56
return rs;
57         }
58         catch (Throwable JavaDoc e)
59         {
60             throw e;
61         }
62         finally
63         {
64         if (conn!=null)
65             conn.close();
66         }
67
68     }
69
70 }
71
Popular Tags