Source Code Cross Referenced for SqlStatement.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » backend » list » helper » 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 » Web Framework » aranea mvc 1.1.1 » org.araneaframework.backend.list.helper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *  http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.backend.list.helper;
016:
017:        import java.io.Serializable;
018:        import java.sql.PreparedStatement;
019:        import java.sql.SQLException;
020:        import java.util.ArrayList;
021:        import java.util.List;
022:
023:        /**
024:         * @author <a href="mailto:rein@araneaframework.org">Rein Raudjärv</a>
025:         */
026:        public class SqlStatement implements  Serializable, Cloneable {
027:
028:            private static final long serialVersionUID = 1L;
029:
030:            protected String query;
031:            protected List parameters;
032:
033:            public SqlStatement(String query, List parameters) {
034:                this .query = query;
035:                this .parameters = parameters;
036:            }
037:
038:            public SqlStatement(String query) {
039:                this (query, new ArrayList());
040:            }
041:
042:            public SqlStatement() {
043:                this (null);
044:            }
045:
046:            public List getParams() {
047:                return this .parameters;
048:            }
049:
050:            public void setParams(List params) {
051:                if (params == null) {
052:                    throw new RuntimeException(
053:                            "Parameters list can not be NULL, use an empty list instead");
054:                }
055:                this .parameters = params;
056:            }
057:
058:            public String getQuery() {
059:                return this .query;
060:            }
061:
062:            public void setQuery(String query) {
063:                this .query = query;
064:            }
065:
066:            /**
067:             * Adds a parameter at the specified position.
068:             * 
069:             * @param index
070:             *            index at witch the specified parameter will be inserted.
071:             * @param param
072:             *            a parameter.
073:             */
074:            public void addParam(int index, Object param) {
075:                this .parameters.add(index, param);
076:            }
077:
078:            /**
079:             * Adds a <code>NULL</code> parameter at the specified position.
080:             * 
081:             * @param index
082:             *            index at witch the specified parameter will be inserted.
083:             * @param valueType
084:             *            the type of the NULL value.
085:             */
086:            public void addNullParam(int index, int valueType) {
087:                this .addParam(index, new NullValue(valueType));
088:            }
089:
090:            /**
091:             * Adds parameters at the specified position.
092:             * 
093:             * @param index
094:             *            index at witch the specified parameters will be inserted.
095:             * @param params
096:             *            parameters.
097:             */
098:            public void addAllParams(int index, List params) {
099:                this .parameters.addAll(index, params);
100:            }
101:
102:            /**
103:             * Counts all parameters.
104:             * 
105:             * @return paramaetrs count.
106:             */
107:            public int countParams() {
108:                return this .parameters.size();
109:            }
110:
111:            /**
112:             * Adds a parameter.
113:             * 
114:             * @param param
115:             *            a parameter.
116:             */
117:            public void addParam(Object param) {
118:                addParam(countParams(), param);
119:            }
120:
121:            /**
122:             * Adds a <code>NULL</code> parameter.
123:             * 
124:             * @param valueType
125:             *            the type of the NULL value.
126:             */
127:            public void addNullParam(int valueType) {
128:                addNullParam(countParams(), valueType);
129:            }
130:
131:            /**
132:             * Adds parameters.
133:             * 
134:             * @param params
135:             *            parameters.
136:             */
137:            public void addAllParams(List params) {
138:                addAllParams(countParams(), params);
139:            }
140:
141:            /**
142:             * Clears all parameters.
143:             */
144:            public void clearParams() {
145:                this .parameters.clear();
146:            }
147:
148:            /**
149:             * Constructs a new <code>SqlStatement</code> with the same
150:             * <code>Query</code> and <code>Parameters</code>.
151:             * 
152:             * @see java.lang.Object#clone()
153:             */
154:            public Object clone() {
155:                return new SqlStatement(this .query, new ArrayList(
156:                        this .parameters));
157:            }
158:
159:            // *********************************************************************
160:            // * PREPARED STATEMENT PROPAGATION
161:            // *********************************************************************
162:
163:            /**
164:             * Helper method that sets the parameters to the
165:             * <code>PreparedStatement</code>.
166:             * 
167:             * @param pstmt <code>PreparedStatement</code> which parameters will be set.
168:             * @throws SQLException
169:             */
170:            protected void propagateStatementWithParams(PreparedStatement pstmt)
171:                    throws SQLException {
172:                for (int i = 1; i <= this .parameters.size(); i++) {
173:                    Object parameter = this .parameters.get(i - 1);
174:                    if (parameter instanceof  NullValue) {
175:                        pstmt.setNull(i, ((NullValue) parameter).getType());
176:                    } else {
177:                        // converting java.util.Date into java.sql.Date (java.sql.Timestamp is not changed)
178:                        if (parameter != null
179:                                && parameter.getClass().equals(
180:                                        java.util.Date.class)) {
181:                            parameter = new java.sql.Date(
182:                                    ((java.util.Date) parameter).getTime());
183:                        }
184:                        pstmt.setObject(i, parameter);
185:                    }
186:                }
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.