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
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import org.dbforms.config.DbFormsConfig;
29 import org.dbforms.config.FieldValue;
30 import org.dbforms.config.ResultSetVector;
31 import org.dbforms.config.Table;
32
33 import org.dbforms.event.AbstractNavigationEvent;
34 import org.dbforms.event.datalist.dao.DataSourceFactory;
35 import org.dbforms.event.datalist.dao.DataSourceSessionList;
36 import org.dbforms.event.eventtype.EventType;
37 import org.dbforms.interfaces.DbEventInterceptorData;
38
39 import java.sql.SQLException;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 /***
44 * This event reloads the current dataset and moves to the first row of data
45 * Works with new factory classes.
46 *
47 * @author Henner Kollmann
48 */
49 public class ReloadEvent extends AbstractNavigationEvent {
50 private static Log logCat = LogFactory.getLog(ReloadEvent.class.getName());
51
52
53
54
55
56 private boolean isForce = false;
57
58 private boolean isInsert = false;
59
60 /***
61 * Creates a new ReloadEvent object.
62 *
63 * @param action
64 * the action string
65 * @param request
66 * the request object
67 * @param config
68 * the configuration object
69 */
70 public ReloadEvent(String action, HttpServletRequest request,
71 DbFormsConfig config) {
72 super(action, request, config);
73 isForce = action.indexOf("_force_") > 0;
74 isInsert = !isForce && (action.indexOf("_ins_") > 0);
75 }
76
77 /***
78 * Creates a new ReloadEvent object.
79 *
80 * @param table
81 * the input table object
82 * @param request
83 * the request object
84 * @param config
85 * the configuration object
86 */
87 public ReloadEvent(Table table, HttpServletRequest request,
88 DbFormsConfig config) {
89 super(table, request, config);
90 }
91
92 /***
93 * Process the current event.
94 *
95 * @param filterFieldValues
96 * FieldValue array used to restrict a set of data
97 * @param orderConstraint
98 * FieldValue array used to build a cumulation of rules for
99 * ordering (sorting) and restricting fields to the actual block
100 * of data
101 * @param sqlFilter
102 * DOCUMENT ME!
103 * @param sqlFilterParams
104 * DOCUMENT ME!
105 * @param count
106 * record count
107 * @param firstPosition
108 * a string identifying the first resultset position
109 * @param lastPosition
110 * a string identifying the last resultset position
111 * @param dbConnectionName
112 * name of the used db connection. Can be used to get an own db
113 * connection, e.g. to hold it during the session (see
114 * DataSourceJDBC for example!)
115 * @param con
116 * the JDBC Connection object
117 *
118 * @return a ResultSetVector object
119 *
120 * @exception SQLException
121 * if any error occurs
122 */
123 public ResultSetVector processEvent(FieldValue[] filterFieldValues,
124 FieldValue[] orderConstraint, String sqlFilter,
125 FieldValue[] sqlFilterParams, int count, String firstPosition,
126 String lastPosition, DbEventInterceptorData interceptorData)
127 throws SQLException {
128 if (isInsert) {
129 return null;
130 }
131 logCat.info("==>NavCurrentEvent.processEvent");
132
133 DataSourceSessionList ds = DataSourceSessionList
134 .getInstance(getRequest());
135 DataSourceFactory qry = null;
136 String position = null;
137
138 if (isForce) {
139 setType(EventType.EVENT_NAVIGATION_FORCERELOAD);
140 ds.remove(getTable(), getRequest());
141 } else {
142 qry = ds.get(getTable(), getRequest());
143 }
144
145 if (qry == null) {
146 qry = new DataSourceFactory((String) interceptorData
147 .getAttribute(DbEventInterceptorData.CONNECTIONNAME),
148 interceptorData.getConnection(), getTable());
149 qry.setSelect(filterFieldValues, orderConstraint, sqlFilter,
150 sqlFilterParams);
151 ds.put(getTable(), getRequest(), qry);
152 }
153
154 position = (count == 0) ? null : getTable().getKeyPositionString(
155 getTable().getFieldValues(lastPosition));
156
157 ResultSetVector res = qry.getCurrent(interceptorData, position, count);
158
159 if (ResultSetVector.isNull(res)) {
160 res = qry.getLast(interceptorData, count);
161 }
162
163 return res;
164 }
165 }