View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.isql; 22 23 import javax.servlet.http.HttpServletRequest; 24 import javax.servlet.http.HttpServletResponse; 25 26 import org.apache.log4j.Logger; 27 import org.apache.struts.action.Action; 28 import org.apache.struts.action.ActionError; 29 import org.apache.struts.action.ActionErrors; 30 import org.apache.struts.action.ActionForm; 31 import org.apache.struts.action.ActionForward; 32 import org.apache.struts.action.ActionMapping; 33 import org.enableit.db.isql.biz.Isql; 34 import org.enableit.db.isql.biz.IsqlModel; 35 36 37 /*** 38 * Implementation of Action for simple SQL console. 39 * 40 * @struts:action path="/exec" scope="request" 41 * name="IsqlForm" input="isql.jsp" 42 * validate="true" 43 * @struts:action-forward name="success" path="/isql.jsp" 44 * @web:resource-ref name="jdbc/DefaultDS" type="javax.sql.DataSource" 45 * auth="Container" 46 */ 47 public class IsqlAction extends Action { 48 /*** 49 * Define a static Logger variable for logging. 50 */ 51 private static Logger logger = Logger.getLogger(IsqlAction.class); 52 53 /*** 54 * Default constructor. 55 */ 56 public IsqlAction() { 57 } 58 59 /*** 60 * Process the sql request and display the results. 61 * 62 * @param mapping The ActionMapping used to select this instance 63 * @param form The optional ActionForm bean for this request (if any) 64 * @param request The HTTP request we are processing 65 * @param response The HTTP response we are creating 66 * @return Struts forward information. 67 * @exception Exception An application exception. 68 */ 69 public ActionForward execute(ActionMapping mapping, ActionForm form, 70 HttpServletRequest request, HttpServletResponse response) 71 throws Exception { 72 logger.info("METHOD_ENTRY: execute"); 73 74 IsqlForm isqlForm = (IsqlForm) form; 75 ActionErrors errors = (ActionErrors) request.getAttribute(Action.ERROR_KEY); 76 77 logger.warn("Using data source named: " + isqlForm.getDataSource()); 78 79 try { 80 Isql isql = new Isql(); 81 IsqlModel model = isql.execute(new IsqlModel(isqlForm)); 82 83 isqlForm.setResults(model.getResults()); 84 isqlForm.setResponse(model.getResponse()); 85 } catch (org.enableit.db.DBException e) { 86 logger.warn(e.getMessage()); 87 88 if (errors == null) { 89 errors = new ActionErrors(); 90 } 91 92 ActionError error = new ActionError("isql.db.error", e.getMessage()); 93 94 errors.add(ActionErrors.GLOBAL_ERROR, error); 95 saveErrors(request, errors); 96 } catch (Exception e) { 97 logger.error(e.getMessage(), e); 98 } 99 100 // Forward control to the specified success URI 101 logger.info("METHOD_EXIT: execute"); 102 103 return (mapping.findForward("success")); 104 } 105 }

This page was automatically generated by Maven