Source Code Cross Referenced for SQLStatementMatcher.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.Collection;
005:        import java.util.Iterator;
006:        import java.util.List;
007:        import java.util.Map;
008:
009:        import com.mockrunner.util.common.StringUtil;
010:
011:        /**
012:         * Helper class for finding matching SQL statements based on various
013:         * search parameters. The search parameters are:
014:         * <br>
015:         * <code>caseSensitive</code> do a case sensitive match (default is <code>false</code>)
016:         * <br>
017:         * <code>exactMatch</code> the strings must match exactly, the parameter <code>caseSensitive</code>
018:         *                         is recognized, but <code>useRegularExpression</code> is irrelevant,
019:         *                         if <code>exactMatch</code> is <code>true</code> (default is <code>false</code>)
020:         * <br>
021:         * <code>useRegularExpression</code> use regular expressions for matching, if this parameter is
022:         *                                   <code>false</code>, strings match, if one string starts with the other
023:         *                                   (default is <code>false</code>)
024:         */
025:        public class SQLStatementMatcher {
026:            private boolean caseSensitive = false;
027:            private boolean exactMatch = false;
028:            private boolean useRegularExpressions = false;
029:
030:            public SQLStatementMatcher(boolean caseSensitive, boolean exactMatch) {
031:                this (caseSensitive, exactMatch, false);
032:            }
033:
034:            public SQLStatementMatcher(boolean caseSensitive,
035:                    boolean exactMatch, boolean useRegularExpressions) {
036:                this .caseSensitive = caseSensitive;
037:                this .exactMatch = exactMatch;
038:                this .useRegularExpressions = useRegularExpressions;
039:            }
040:
041:            /**
042:             * Compares all keys in the specified <code>Map</code> with the
043:             * specified query string using the method {@link #doStringsMatch}.
044:             * If the strings match, the corresponding object from the <code>Map</code>
045:             * is added to the resulting <code>List</code>.
046:             * @param dataMap the source <code>Map</code>
047:             * @param query the query string that must match the keys in <i>dataMap</i>
048:             * @param queryContainsMapData only matters if <i>isExactMatch</i> is <code>false</code>,
049:             *        specifies if query must be contained in the <code>Map</code> keys (<code>false</code>)
050:             *        or if query must contain the <code>Map</code> keys (<code>true</code>)
051:             * @return the result <code>List</code>
052:             */
053:            public List getMatchingObjects(Map dataMap, String query,
054:                    boolean resolveCollection, boolean queryContainsMapData) {
055:                if (null == query)
056:                    query = "";
057:                Iterator iterator = dataMap.keySet().iterator();
058:                ArrayList resultList = new ArrayList();
059:                while (iterator.hasNext()) {
060:                    String nextKey = (String) iterator.next();
061:                    String source, currentQuery;
062:                    if (queryContainsMapData) {
063:                        source = query;
064:                        currentQuery = nextKey;
065:                    } else {
066:                        source = nextKey;
067:                        currentQuery = query;
068:                    }
069:                    if (doStringsMatch(source, currentQuery)) {
070:                        Object matchingObject = dataMap.get(nextKey);
071:                        if (resolveCollection
072:                                && (matchingObject instanceof  Collection)) {
073:                            resultList.addAll((Collection) matchingObject);
074:                        } else {
075:                            resultList.add(dataMap.get(nextKey));
076:                        }
077:                    }
078:                }
079:                return resultList;
080:            }
081:
082:            /**
083:             * Compares all elements in the specified <code>Collection</code> with the
084:             * specified query string using the method {@link #doStringsMatch}.
085:             * @param col the <code>Collections</code>
086:             * @param query the query string that must match the keys in <i>col</i>
087:             * @param queryContainsData only matters if <i>exactMatch</i> is <code>false</code>,
088:             *        specifies if query must be contained in the <code>Collection</code> data (<code>false</code>)
089:             *        or if query must contain the <code>Collection</code> data (<code>true</code>)
090:             * @return <code>true</code> if <i>col</i> contains <i>query</i>, false otherwise
091:             */
092:            public boolean contains(Collection col, String query,
093:                    boolean queryContainsData) {
094:                Iterator iterator = col.iterator();
095:                while (iterator.hasNext()) {
096:                    String nextKey = (String) iterator.next();
097:                    String source, currentQuery;
098:                    if (queryContainsData) {
099:                        source = query;
100:                        currentQuery = nextKey;
101:                    } else {
102:                        source = nextKey;
103:                        currentQuery = query;
104:                    }
105:                    if (doStringsMatch(source, currentQuery))
106:                        return true;
107:                }
108:                return false;
109:            }
110:
111:            /**
112:             * Compares two strings and returns if they match. 
113:             * @param query the query string that must match source
114:             * @param source the source string
115:             * @return <code>true</code> of the strings match, <code>false</code> otherwise
116:             */
117:            public boolean doStringsMatch(String source, String query) {
118:                if (null == source)
119:                    source = "";
120:                if (null == query)
121:                    query = "";
122:                if (useRegularExpressions && !exactMatch) {
123:                    return doPerl5Match(source, query);
124:                } else {
125:                    return doSimpleMatch(source, query);
126:                }
127:            }
128:
129:            private boolean doSimpleMatch(String source, String query) {
130:                if (exactMatch) {
131:                    return StringUtil
132:                            .matchesExact(source, query, caseSensitive);
133:                } else {
134:                    return StringUtil.matchesContains(source, query,
135:                            caseSensitive);
136:                }
137:            }
138:
139:            private boolean doPerl5Match(String source, String query) {
140:                return StringUtil.matchesPerl5(source, query, caseSensitive);
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.