Source Code Cross Referenced for DeleteRecord.java in  » Portal » stringbeans-3.5 » com » nabhinc » portlet » mvcportlet » actionprocessor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » stringbeans 3.5 » com.nabhinc.portlet.mvcportlet.actionprocessor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright 2004 Nabh Information Systems, Inc.
003:         *
004:         * All copyright notices regarding Nabh's products MUST remain
005:         * intact in the scripts and in the outputted HTML.
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public License
008:         * as published by the Free Software Foundation; either version 2.1 
009:         * of the License, or (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014:         * GNU Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:        package com.nabhinc.portlet.mvcportlet.actionprocessor;
022:
023:        import java.io.IOException;
024:        import java.sql.Connection;
025:        import java.sql.PreparedStatement;
026:        import java.sql.ResultSet;
027:        import java.sql.SQLException;
028:        import java.text.ParseException;
029:
030:        import javax.portlet.ActionRequest;
031:        import javax.portlet.ActionResponse;
032:        import javax.portlet.PortletException;
033:
034:        import org.w3c.dom.Element;
035:
036:        import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
037:        import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
038:        import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
039:        import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
040:        import com.nabhinc.util.db.DBConfigUtil;
041:        import com.nabhinc.util.db.DBParamUtil;
042:        import com.nabhinc.util.StringUtil;
043:        import com.nabhinc.util.XMLUtil;
044:        import com.nabhinc.util.db.DBUtil;
045:
046:        /**
047:         * Deletes a database record if an optional
048:         * SQL condition is satisfied.<p>
049:         * Required configuration parameters
050:         * <ul>
051:         * <li>sql - SQL used to delete desired record.</li>
052:         * </ul>
053:         * Optional configuration parameters
054:         * <ul>
055:         * <li>check-sql - If this sql returns a record then the delete
056:         * sql will not be executed.</li>
057:         * <li>params - Comma separated list of names of SQL parameters to be 
058:         * inserted. In general, these are the request parameter names. The 
059:         * following specialtokens are used to insert other values:
060:         * <ul>
061:         * <li>$userName - Current user name returned by request.getRemoteUser()</li>
062:         * <li>$currentDate - Today's date</li>
063:         * <li>$$currentTimestamp - Current time</li>
064:         * </ul>
065:         * </li>
066:         * <li>param-types - Comma separated list of SQL parameter types. This 
067:         * parameter must be specified if "params" are specified. Possible parameter 
068:         * types are: VARCHAR, INTEGER, DECIMAL, BOOLEAN, SMALLINT, DATE,
069:         * TIME, TIMESTAMP, FLOAT, DOUBLE, ARRAY, BIGINT, BINARY, BIT, 
070:         * BLOB, CHAR, CLOB, LONGVARBINARY, LONGVARCHAR, JAVA_OBJECT
071:         * </li>
072:         * </ul>
073:         * 
074:         * @author Padmanabh Dabke
075:         * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
076:         */
077:        public class DeleteRecord extends BaseRequestProcessor implements 
078:                ActionProcessor {
079:            private String irSQL = null;
080:            private String[] irParams = null;
081:            private int[] irParamTypes = null;
082:            private String irCheckSQL = null;
083:
084:            /**
085:             * Initialization.
086:             * @param config XML configuration element
087:             * @throws PortletException Thrown if sql parameter is not specified,
088:             * "params" parameter is specified but corresponding "param-types"
089:             * are not specified.
090:             */
091:            public void init(Element config, ControllerPortletConfig cpConfig)
092:                    throws PortletException {
093:                super .init(config, cpConfig);
094:                irSQL = XMLUtil.getSubElementText(config, "sql");
095:                if (irSQL == null) {
096:                    throw new PortletException(
097:                            "Missing required parameter: sql");
098:                }
099:
100:                irCheckSQL = XMLUtil.getSubElementText(config, "check-sql");
101:                String params = XMLUtil.getSubElementText(config, "params");
102:                if (params != null) {
103:                    irParams = StringUtil.split(params, ",");
104:                    String paramTypes = XMLUtil.getSubElementText(config,
105:                            "param-types");
106:                    if (paramTypes == null) {
107:                        throw new PortletException(
108:                                "You must specify param-types if you specify params.");
109:                    }
110:                    String[] typeArray = StringUtil.split(paramTypes, ",");
111:                    if (typeArray.length != irParams.length) {
112:                        throw new PortletException(
113:                                "Number of param-types must be equal to number of params.");
114:                    }
115:                    irParamTypes = new int[typeArray.length];
116:                    for (int i = 0; i < typeArray.length; i++) {
117:                        try {
118:                            irParamTypes[i] = DBConfigUtil
119:                                    .getSQLType(typeArray[i]);
120:                        } catch (Exception ex) {
121:                            throw new PortletException(
122:                                    "Failed to parse sql type.", ex);
123:                        }
124:                    }
125:                }
126:            }
127:
128:            /**
129:             * Deletes a database record if an optional
130:             * SQL condition is satisfied.<p>
131:             * @param request Action request
132:             * @param response Action response
133:             * @param config Action config
134:             * @return "check_error" if check-sql returns a record, "success" otherwise.
135:             * @throws PortletException
136:             * @throws IOException
137:             */
138:            public String process(ActionRequest request,
139:                    ActionResponse response, ActionConfig config)
140:                    throws PortletException, IOException {
141:
142:                Connection conn = null;
143:                PreparedStatement st = null;
144:                ResultSet results = null;
145:                try {
146:                    conn = brpConfig.getDataSource().getConnection();
147:                    if (irCheckSQL != null) {
148:                        st = conn.prepareStatement(irCheckSQL);
149:                        if (irParams != null) {
150:                            for (int i = 0; i < irParams.length; i++) {
151:                                DBParamUtil.setSQLParam(st, i, irParams[i],
152:                                        irParamTypes[i], request, -1);
153:                            }
154:                        }
155:                        results = st.executeQuery();
156:                        if (results.next()) {
157:                            return "check-error";
158:                        }
159:                    }
160:                    st = conn.prepareStatement(irSQL);
161:                    if (irParams != null) {
162:                        for (int i = 0; i < irParams.length; i++) {
163:                            DBParamUtil.setSQLParam(st, i, irParams[i],
164:                                    irParamTypes[i], request, -1);
165:                        }
166:                    }
167:                    st.execute();
168:                    return "success";
169:                } catch (SQLException sqe) {
170:                    throw new PortletException("Database exception.", sqe);
171:                } catch (ParseException pex) {
172:                    throw new PortletException("Malformed request parameter.",
173:                            pex);
174:                } finally {
175:                    DBUtil.close(results);
176:                    DBUtil.close(st);
177:                    DBUtil.close(conn);
178:                }
179:            }
180:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.