KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > MasterDetailReader


1 package dinamica;
2
3 import javax.sql.*;
4 import java.sql.*;
5
6 /**
7  * Base class to create your own Transaction classes
8  * for master/detail reports. You can use an instance
9  * of this class if your report requirements are simple
10  * to configure, otherwise you should subclass and redefine
11  * service() to publish a recordset called "master" and
12  * redefine the getDetail() method too.
13  * <br><br>
14  * (c) 2004 Martin Cordova<br>
15  * This code is released under the LGPL license<br>
16  * Dinamica Framework - http://www.martincordova.com
17  * @author Martin Cordova (dinamica@martincordova.com)
18  * */

19 public class MasterDetailReader extends GenericTransaction
20 {
21
22     /**
23      * Publish recordset used for the master and subtotal
24      */

25     public int service(Recordset inputParams) throws Throwable JavaDoc
26     {
27
28         int rc = 0;
29         
30         //reuse superclass code
31
super.service(inputParams);
32         
33         //create master recordset and publish it
34
//with the ID "master"
35
Db db = getDb();
36         String JavaDoc sql = getResource(getConfig().getConfigValue("query-master"));
37         sql = getSQL(sql, inputParams);
38         Recordset rs = db.get(sql);
39         publish("master", rs);
40         
41         return rc;
42         
43     }
44
45     /**
46      * Return recordset for detail section
47      * @param master Master recordset positioned on the current record
48      * @return
49      * @throws Throwable
50      */

51     public Recordset getDetail(Recordset master) throws Throwable JavaDoc
52     {
53
54         //get datasource and DB connection
55
DataSource ds = getDataSource();
56         Connection conn = ds.getConnection();
57         this.setConnection(conn);
58
59         try
60         {
61             
62             //get db channel
63
Db db = getDb();
64             
65             //build sql
66
String JavaDoc sql = getResource(getConfig().getConfigValue("query-detail"));
67             sql = getSQL(sql, master);
68             
69             //get menu items
70
Recordset items = db.get(sql);
71             
72             return items;
73             
74         }
75         catch (Throwable JavaDoc e)
76         {
77             throw e;
78         }
79         finally
80         {
81             if (conn!=null)
82                 conn.close();
83         }
84         
85     }
86
87 }
88
Popular Tags