01: /*
02: * (C) Copyright 2004 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19: package com.nabhinc.portlet.survey;
20:
21: import java.io.IOException;
22: import java.sql.Connection;
23: import java.sql.PreparedStatement;
24: import java.sql.ResultSet;
25: import java.sql.SQLException;
26:
27: import javax.portlet.ActionRequest;
28: import javax.portlet.ActionResponse;
29: import javax.portlet.PortletException;
30:
31: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
32: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
33: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
34: import com.nabhinc.util.db.DBUtil;
35:
36: /**
37: * Edit Survey Action processor.
38: *
39: * @author Padmanabh Dabke
40: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
41: */
42: public class EditSurveyActionProcessor extends BaseRequestProcessor
43: implements ActionProcessor {
44:
45: /* (non-Javadoc)
46: * @see com.nabhinc.portlet.mvcportlet.core.ActionProcessor#process(javax.portlet.ActionRequest, javax.portlet.ActionResponse, com.nabhinc.portlet.mvcportlet.core.ActionConfig)
47: */
48: public String process(ActionRequest request,
49: ActionResponse response, ActionConfig actionConfig)
50: throws PortletException, IOException {
51:
52: String optionSQL = "SELECT optionnum, optiontext FROM SB_SURVEY_DATA WHERE surveyid = ?";
53: int surveyID = Integer.parseInt(request
54: .getParameter("survey_id"));
55: Connection conn = null;
56: PreparedStatement st = null;
57: ResultSet results = null;
58: try {
59: // Get database connection
60: conn = brpConfig.getDataSource().getConnection();
61:
62: // Retrieve survey options
63: st = conn.prepareStatement(optionSQL);
64: st.setInt(1, surveyID);
65: results = st.executeQuery();
66: while (results.next()) {
67: int optionNum = results.getInt(1);
68: String optionText = results.getString(2);
69: response.setRenderParameter("survey_option_"
70: + optionNum, optionText);
71: }
72: return "success";
73: } catch (SQLException sqlex) {
74: try {
75: conn.rollback();
76: } catch (Exception ex) {
77: // Ignore
78: }
79: throw new PortletException("Database exception.", sqlex);
80: } catch (Exception ex) {
81: try {
82: conn.rollback();
83: } catch (Exception ex1) {
84: // Ignore
85: }
86: throw new PortletException(ex);
87: } finally {
88: DBUtil.close(results);
89: DBUtil.close(st);
90: DBUtil.close(conn);
91: }
92:
93: }
94:
95: }
|