1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.dbforms.event.datalist;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import org.dbforms.config.DbFormsConfig;
28 import org.dbforms.config.FieldValue;
29 import org.dbforms.config.ResultSetVector;
30 import org.dbforms.config.Table;
31
32 import org.dbforms.event.AbstractNavigationEvent;
33 import org.dbforms.event.datalist.dao.DataSourceFactory;
34 import org.dbforms.event.datalist.dao.DataSourceSessionList;
35 import org.dbforms.interfaces.DbEventInterceptorData;
36
37 import java.sql.SQLException;
38
39 import javax.servlet.http.HttpServletRequest;
40
41
42
43 /***
44 * This event scrolls the current ResultSet to the next row of data. Provides
45 * bounded navigation. <br>
46 * Works with new factory classes
47 *
48 * @author Henner Kollmann
49 */
50 public class NavNextEvent extends AbstractNavigationEvent {
51
52 private static Log logCat = LogFactory.getLog(NavNextEvent.class.getName());
53
54 /***
55 * Constructor.
56 *
57 * @param action the action string
58 * @param request the request object
59 * @param config the config object
60 */
61 public NavNextEvent(String action, HttpServletRequest request,
62 DbFormsConfig config) {
63 super(action, request, config);
64 }
65
66
67 /***
68 * Constructor used for call from localevent.
69 *
70 * @param table the Table object
71 * @param request the request object
72 * @param config the config object
73 */
74 public NavNextEvent(Table table, HttpServletRequest request,
75 DbFormsConfig config) {
76 super(table, request, config);
77 }
78
79 /***
80 * Process the current event.
81 *
82 * @param filterFieldValues FieldValue array used to restrict a set of data
83 * @param orderConstraint FieldValue array used to build a cumulation of
84 * rules for ordering (sorting) and restricting fields to the actual
85 * block of data
86 * @param sqlFilter DOCUMENT ME!
87 * @param sqlFilterParams DOCUMENT ME!
88 * @param count record count
89 * @param firstPosition a string identifying the first resultset position
90 * @param lastPosition a string identifying the last resultset position
91 * @param dbConnectionName name of the used db connection. Can be used to
92 * get an own db connection, e.g. to hold it during the session (see
93 * DataSourceJDBC for example!)
94 * @param con the JDBC Connection object
95 *
96 * @return a ResultSetVector object
97 *
98 * @exception SQLException if any error occurs
99 *
100 * @todo make a option to allow original "navNew" behavior if desired
101 */
102 public ResultSetVector processEvent(FieldValue[] filterFieldValues,
103 FieldValue[] orderConstraint, String sqlFilter,
104 FieldValue[] sqlFilterParams, int count, String firstPosition,
105 String lastPosition, DbEventInterceptorData interceptorData)
106 throws SQLException {
107 logCat.info("==>NavNextEvent.processEvent");
108
109 DataSourceSessionList ds = DataSourceSessionList.getInstance(getRequest());
110 DataSourceFactory qry = null;
111 boolean force = getRequest().getAttribute("forceUpdate") != null;
112 if (force) {
113 ds.remove(getTable(), getRequest());
114 } else {
115 qry = ds.get(getTable(), getRequest());
116 }
117
118 if (qry == null) {
119 qry = new DataSourceFactory((String) interceptorData.getAttribute(
120 DbEventInterceptorData.CONNECTIONNAME),
121 interceptorData.getConnection(), getTable());
122 qry.setSelect(filterFieldValues, orderConstraint, sqlFilter,
123 sqlFilterParams);
124 ds.put(getTable(), getRequest(), qry);
125 }
126
127 String position = getTable().getKeyPositionString(getTable()
128 .getFieldValues(lastPosition));
129 ResultSetVector res = qry.getNext(interceptorData, position, count);
130
131 if (ResultSetVector.isNull(res)) {
132 res = qry.getLast(interceptorData, count);
133 }
134
135 return res;
136 }
137 }