KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > event > datalist > ReloadEvent


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/datalist/ReloadEvent.java,v 1.13 2005/02/19 21:26:30 hkollmann Exp $
3  * $Revision: 1.13 $
4  * $Date: 2005/02/19 21:26:30 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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.DbEventInterceptorData;
29 import org.dbforms.config.DbFormsConfig;
30 import org.dbforms.config.FieldValue;
31 import org.dbforms.config.ResultSetVector;
32 import org.dbforms.config.Table;
33
34 import org.dbforms.event.NavigationEvent;
35 import org.dbforms.event.datalist.dao.DataSourceFactory;
36 import org.dbforms.event.datalist.dao.DataSourceSessionList;
37 import org.dbforms.event.eventtype.EventType;
38
39 import java.sql.SQLException JavaDoc;
40
41 import javax.servlet.http.HttpServletRequest JavaDoc;
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 NavigationEvent {
50     private static Log logCat = LogFactory.getLog(ReloadEvent.class.getName()); // logging
51

52     // category
53
// for
54
// this
55
// class
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 JavaDoc action, HttpServletRequest JavaDoc 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 JavaDoc 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 JavaDoc sqlFilter,
125             FieldValue[] sqlFilterParams, int count, String JavaDoc firstPosition,
126             String JavaDoc lastPosition, DbEventInterceptorData interceptorData)
127             throws SQLException JavaDoc {
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 JavaDoc 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 JavaDoc) 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 }
166
Popular Tags