01: package dinamica;
02:
03: import javax.sql.*;
04: import java.sql.*;
05:
06: /**
07: * Base class to create your own Transaction classes
08: * for master/detail reports. You can use an instance
09: * 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: * Publish recordset used for the master and subtotal
23: */
24: public int service(Recordset inputParams) throws Throwable {
25:
26: int rc = 0;
27:
28: //reuse superclass code
29: super .service(inputParams);
30:
31: //create master recordset and publish it
32: //with the ID "master"
33: Db db = getDb();
34: String sql = getResource(getConfig().getConfigValue(
35: "query-master"));
36: sql = getSQL(sql, inputParams);
37: Recordset rs = db.get(sql);
38: publish("master", rs);
39:
40: return rc;
41:
42: }
43:
44: /**
45: * Return recordset for detail section
46: * @param master Master recordset positioned on the current record
47: * @return
48: * @throws Throwable
49: */
50: public Recordset getDetail(Recordset master) throws Throwable {
51:
52: //get datasource and DB connection
53: DataSource ds = getDataSource();
54: Connection conn = ds.getConnection();
55: this .setConnection(conn);
56:
57: try {
58:
59: //get db channel
60: Db db = getDb();
61:
62: //build sql
63: String sql = getResource(getConfig().getConfigValue(
64: "query-detail"));
65: sql = getSQL(sql, master);
66:
67: //get menu items
68: Recordset items = db.get(sql);
69:
70: return items;
71:
72: } catch (Throwable e) {
73: throw e;
74: } finally {
75: if (conn != null)
76: conn.close();
77: }
78:
79: }
80:
81: }
|