View Javadoc

1   /*
2    * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/datalist/NavLastEvent.java,v 1.18 2005/11/30 20:31:17 hkollmann Exp $
3    * $Revision: 1.18 $
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 its last row of data. <br>
45   * Works with new factory classes
46   *
47   * @author Henner Kollmann
48   */
49  public class NavLastEvent extends AbstractNavigationEvent {
50     // logging category for this class
51     private static Log logCat = LogFactory.getLog(NavLastEvent.class.getName());
52  
53     /***
54      * Creates a new NavLastEvent object.
55      *
56      * @param action the action string
57      * @param request the request object
58      * @param config the config object
59      */
60     public NavLastEvent(String action, HttpServletRequest request,
61        DbFormsConfig config) {
62        super(action, request, config);
63     }
64  
65  
66     /***
67      * Creates a new NavLastEvent object.
68      *
69      * @param table the input table object
70      * @param request the request object
71      * @param config the config object
72      */
73     public NavLastEvent(Table table, HttpServletRequest request,
74        DbFormsConfig config) {
75        super(table, request, config);
76     }
77  
78     /***
79      * Process the current event.
80      *
81      * @param filterFieldValues FieldValue array used to restrict a set of data
82      * @param orderConstraint FieldValue array used to build a cumulation of
83      *        rules for ordering (sorting) and restricting fields to the actual
84      *        block of data
85      * @param sqlFilter DOCUMENT ME!
86      * @param sqlFilterParams DOCUMENT ME!
87      * @param count record count
88      * @param firstPosition a string identifying the first resultset position
89      * @param lastPosition a string identifying the last resultset position
90      * @param dbConnectionName name of the used db connection. Can be used to
91      *        get an own db connection, e.g. to hold it during the session (see
92      *        DataSourceJDBC for example!)
93      * @param con the JDBC Connection object
94      *
95      * @return a ResultSetVector object
96      *
97      * @exception SQLException if any error occurs
98      */
99     public ResultSetVector processEvent(FieldValue[] filterFieldValues,
100       FieldValue[] orderConstraint, String sqlFilter,
101       FieldValue[] sqlFilterParams, int count, String firstPosition,
102       String lastPosition, DbEventInterceptorData interceptorData)
103       throws SQLException {
104       logCat.info("==>NavLastEvent.processEvent");
105 
106       DataSourceSessionList ds  = DataSourceSessionList.getInstance(getRequest());
107       DataSourceFactory     qry = null;
108       boolean force = getRequest().getAttribute("forceUpdate") != null;
109 		if (force) {
110 			ds.remove(getTable(), getRequest());
111 		} else {
112 			qry = ds.get(getTable(), getRequest());
113 		}
114 
115       if (qry == null) {
116          qry = new DataSourceFactory((String) interceptorData.getAttribute(
117                   DbEventInterceptorData.CONNECTIONNAME),
118                interceptorData.getConnection(), getTable());
119          qry.setSelect(filterFieldValues, orderConstraint, sqlFilter,
120             sqlFilterParams);
121          ds.put(getTable(), getRequest(), qry);
122       }
123 
124       return qry.getLast(interceptorData, count);
125    }
126 }