Source Code Cross Referenced for AbstractOutParameterResultSetHandler.java in  » Testing » mockrunner-0.4 » com » mockrunner » jdbc » 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 » Testing » mockrunner 0.4 » com.mockrunner.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.mockrunner.jdbc;
002:
003:        import java.util.ArrayList;
004:        import java.util.Arrays;
005:        import java.util.HashMap;
006:        import java.util.List;
007:        import java.util.Map;
008:        import java.util.TreeMap;
009:
010:        /**
011:         * Abstract base class for all statement types
012:         * that support out parameters, i.e. <code>CallableStatement</code>.
013:         */
014:        public abstract class AbstractOutParameterResultSetHandler extends
015:                AbstractParameterResultSetHandler {
016:            private boolean mustRegisterOutParameters = false;
017:            private Map globalOutParameter = null;
018:            private Map outParameterForStatement = new TreeMap();
019:            private Map outParameterForStatementParameters = new TreeMap();
020:
021:            /**
022:             * Set if out parameters must be registered to be returned.
023:             * The default is <code>false</code>, i.e. if there are matching
024:             * out parameters prepared, they are returned even if the
025:             * <code>registerOutParameter</code> methods of <code>CallableStatement</code>
026:             * have not been called. If set to <code>true</code>, <code>registerOutParameter</code>
027:             * must be called.
028:             * @param mustOutParameterBeRegistered must out parameter be registered
029:             */
030:            public void setMustRegisterOutParameters(
031:                    boolean mustOutParameterBeRegistered) {
032:                this .mustRegisterOutParameters = mustOutParameterBeRegistered;
033:            }
034:
035:            /**
036:             * Get if out parameter must be registered to be returned.
037:             * @return must out parameter be registered
038:             */
039:            public boolean getMustRegisterOutParameters() {
040:                return mustRegisterOutParameters;
041:            }
042:
043:            /**
044:             * Returns the first out parameter <code>Map</code> that matches 
045:             * the specified SQL string.
046:             * Please note that you can modify the match parameters with 
047:             * {@link #setCaseSensitive}, {@link #setExactMatch} and 
048:             * {@link #setUseRegularExpressions}.
049:             * @param sql the SQL string
050:             * @return the corresponding out parameter <code>Map</code>
051:             */
052:            public Map getOutParameter(String sql) {
053:                SQLStatementMatcher matcher = new SQLStatementMatcher(
054:                        getCaseSensitive(), getExactMatch(),
055:                        getUseRegularExpressions());
056:                List list = matcher.getMatchingObjects(
057:                        outParameterForStatement, sql, true, true);
058:                if (null != list && list.size() > 0) {
059:                    return (Map) list.get(0);
060:                }
061:                return null;
062:            }
063:
064:            /**
065:             * Returns the first out parameter <code>Map</code> that matches 
066:             * the specified SQL string and the specified parameters. 
067:             * Please note that you can modify the match parameters with 
068:             * {@link #setCaseSensitive}, {@link #setExactMatch} and 
069:             * {@link #setUseRegularExpressions} and the match parameters for the 
070:             * specified parameter list with {@link #setExactMatchParameter}.
071:             * @param sql the SQL string
072:             * @param parameters the parameters
073:             * @return the corresponding out parameter <code>Map</code>
074:             */
075:            public Map getOutParameter(String sql, Map parameters) {
076:                MockOutParameterWrapper wrapper = (MockOutParameterWrapper) getMatchingParameterWrapper(
077:                        sql, parameters, outParameterForStatementParameters);
078:                if (null != wrapper) {
079:                    return wrapper.getOutParameter();
080:                }
081:                return null;
082:            }
083:
084:            /**
085:             * Clears the out parameters.
086:             */
087:            public void clearOutParameter() {
088:                outParameterForStatement.clear();
089:                outParameterForStatementParameters.clear();
090:            }
091:
092:            /**
093:             * Returns the global out parameter <code>Map</code>.
094:             * @return the global out parameter <code>Map</code>
095:             */
096:            public Map getGlobalOutParameter() {
097:                return globalOutParameter;
098:            }
099:
100:            /**
101:             * Prepares the global out parameter <code>Map</code>.
102:             * @param outParameters the global out parameter <code>Map</code>
103:             */
104:            public void prepareGlobalOutParameter(Map outParameters) {
105:                globalOutParameter = new HashMap(outParameters);
106:            }
107:
108:            /**
109:             * Prepare an out parameter <code>Map</code> for a specified 
110:             * SQL string.
111:             * Please note that you can modify the match parameters with 
112:             * {@link #setCaseSensitive}, {@link #setExactMatch} and 
113:             * {@link #setUseRegularExpressions}.
114:             * @param sql the SQL string
115:             * @param outParameters the out parameter <code>Map</code>
116:             */
117:            public void prepareOutParameter(String sql, Map outParameters) {
118:                outParameterForStatement.put(sql, new HashMap(outParameters));
119:            }
120:
121:            /**
122:             * Prepare an out parameter <code>Map</code> for a specified SQL string and
123:             * the specified parameters. The specified parameters array
124:             * must contain the parameters in the correct order starting with index 0 for
125:             * the first parameter. Please keep in mind that parameters in
126:             * <code>CallableStatement</code> objects start with 1 as the first
127:             * parameter. So <code>parameters[0]</code> maps to the
128:             * parameter with index 1.
129:             * Please note that you can modify the match parameters with 
130:             * {@link #setCaseSensitive}, {@link #setExactMatch} and 
131:             * {@link #setUseRegularExpressions} and the match parameters for the 
132:             * specified parameter list with {@link #setExactMatchParameter}.
133:             * @param sql the SQL string
134:             * @param outParameters the corresponding out parameter <code>Map</code>
135:             * @param parameters the parameters
136:             */
137:            public void prepareOutParameter(String sql, Map outParameters,
138:                    Object[] parameters) {
139:                prepareOutParameter(sql, outParameters, Arrays
140:                        .asList(parameters));
141:            }
142:
143:            /**
144:             * Prepare an out parameter <code>Map</code> for a specified SQL string and
145:             * the specified parameters. The specified parameters array
146:             * must contain the parameters in the correct order starting with index 0 for
147:             * the first parameter. Please keep in mind that parameters in
148:             * <code>CallableStatement</code> objects start with 1 as the first
149:             * parameter. So <code>parameters.get(0)</code> maps to the
150:             * parameter with index 1.
151:             * Please note that you can modify the match parameters with 
152:             * {@link #setCaseSensitive}, {@link #setExactMatch} and 
153:             * {@link #setUseRegularExpressions} and the match parameters for the 
154:             * specified parameter list with {@link #setExactMatchParameter}.
155:             * @param sql the SQL string
156:             * @param outParameters the corresponding out parameter <code>Map</code>
157:             * @param parameters the parameters
158:             */
159:            public void prepareOutParameter(String sql, Map outParameters,
160:                    List parameters) {
161:                Map params = new HashMap();
162:                for (int ii = 0; ii < parameters.size(); ii++) {
163:                    params.put(new Integer(ii + 1), parameters.get(ii));
164:                }
165:                prepareOutParameter(sql, outParameters, params);
166:            }
167:
168:            /**
169:             * Prepare an out parameter <code>Map</code> for a specified SQL string
170:             * and the specified parameters. The specified parameters <code>Map</code>
171:             * must contain the parameters by mapping <code>Integer</code> or
172:             * <code>String</code> objects to the corresponding parameter. 
173:             * An <code>Integer</code> object is the index of the parameter.
174:             * A <code>String</code> is the name of the parameter.
175:             * Please note that you can modify the match parameters with 
176:             * {@link #setCaseSensitive}, {@link #setExactMatch} and 
177:             * {@link #setUseRegularExpressions} and the match parameters for the 
178:             * specified parameter list with {@link #setExactMatchParameter}.
179:             * @param sql the SQL string
180:             * @param outParameters the corresponding out parameter <code>Map</code>
181:             * @param parameters the parameters
182:             */
183:            public void prepareOutParameter(String sql, Map outParameters,
184:                    Map parameters) {
185:                List list = (List) outParameterForStatementParameters.get(sql);
186:                if (null == list) {
187:                    list = new ArrayList();
188:                    outParameterForStatementParameters.put(sql, list);
189:                }
190:                list.add(new MockOutParameterWrapper(
191:                        new HashMap(outParameters), new HashMap(parameters)));
192:            }
193:
194:            private class MockOutParameterWrapper extends ParameterWrapper {
195:                private Map outParameter;
196:
197:                public MockOutParameterWrapper(Map outParameter, Map parameters) {
198:                    super (parameters);
199:                    this .outParameter = outParameter;
200:                }
201:
202:                public Map getOutParameter() {
203:                    return outParameter;
204:                }
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.