View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/datalist/NavNextEvent.java,v 1.23 2005/11/30 20:31:17 hkollmann Exp $
3    * $Revision: 1.23 $
4    * $Date: 2005/11/30 20:31:17 $
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  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     // logging category for this class
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 }