View Javadoc

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