KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/event/datalist/NavPrevEvent.java,v 1.18 2004/10/20 10:51:49 hkollmann Exp $
3  * $Revision: 1.18 $
4  * $Date: 2004/10/20 10:51:49 $
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.DbEventInterceptorData;
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.NavigationEvent;
34 import org.dbforms.event.datalist.dao.DataSourceFactory;
35 import org.dbforms.event.datalist.dao.DataSourceSessionList;
36
37 import java.sql.SQLException JavaDoc;
38
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40
41
42
43 /**
44  * This event scrolls the current ResultSet to the previous row of data. <br>
45  * Provides bounded navigation. <br>
46  * Works with new factory classes
47  *
48  * @author Henner Kollmann
49  */

50 public class NavPrevEvent extends NavigationEvent {
51    // logging category for this class
52
private static Log logCat = LogFactory.getLog(NavPrevEvent.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 NavPrevEvent(String JavaDoc action, HttpServletRequest JavaDoc request,
62       DbFormsConfig config) {
63       super(action, request, config);
64    }
65
66
67    /**
68     * Constructor used for call from localevents.
69     *
70     * @param table the Table object
71     * @param request DOCUMENT ME!
72     * @param config the config object
73     */

74    public NavPrevEvent(Table table, HttpServletRequest JavaDoc 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    public ResultSetVector processEvent(FieldValue[] filterFieldValues,
101       FieldValue[] orderConstraint, String JavaDoc sqlFilter,
102       FieldValue[] sqlFilterParams, int count, String JavaDoc firstPosition,
103       String JavaDoc lastPosition, DbEventInterceptorData interceptorData)
104       throws SQLException JavaDoc {
105       logCat.info("==>NavPrevEvent.processEvent");
106
107       DataSourceSessionList ds = DataSourceSessionList.getInstance(getRequest());
108       DataSourceFactory qry = ds.get(getTable(), getRequest());
109
110       if (qry == null) {
111          qry = new DataSourceFactory((String JavaDoc) interceptorData.getAttribute(
112                   DbEventInterceptorData.CONNECTIONNAME),
113                interceptorData.getConnection(), getTable());
114          qry.setSelect(filterFieldValues, orderConstraint, sqlFilter,
115             sqlFilterParams);
116          ds.put(getTable(), getRequest(), qry);
117       }
118
119       String JavaDoc position = getTable().getKeyPositionString(getTable()
120                                                                     .getFieldValues(firstPosition));
121       ResultSetVector res = qry.getPrev(interceptorData, position, count);
122
123       // change behavior to navFirst if navPrev finds no data
124
if (ResultSetVector.isNull(res)) {
125          res = qry.getFirst(interceptorData, count);
126       }
127
128       return res;
129    }
130 }
131
Popular Tags