Source Code Cross Referenced for EJBQuery.java in  » Search-Engine » Jofti » com » jofti » query » 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 » Search Engine » Jofti » com.jofti.query 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on 13-Jul-2005
003:         *
004:         */
005:        package com.jofti.query;
006:
007:        import java.util.HashMap;
008:        import java.util.Map;
009:
010:        import com.jofti.api.IndexQuery;
011:        import com.jofti.core.QueryId;
012:        import com.jofti.core.QueryType;
013:
014:        /**
015:         * 
016:         *
017:         * Basic usage is:<br> "select ${identifier} from ${classname} AS ${identifier} where ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter]"
018:         * 
019:         * <p></p>
020:         * multiproperty queries are of the form<br>
021:         * "select ${identifier} from ${classname} AS ${identifier} where  ${identifier}.${propertyname}  [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] [and,or] ${identifier}.${propertyname} 
022:         * [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter]"
023:         * <p>
024:         * compound queries are supported as ${query} [and,or] ${query}
025:         * <p>
026:         * ordering for compound queries is achieved through use of bracket groups<br>
027:         * "... where ( ${identifier}.${propertyname}   [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter]  [and,or] ${identifier}.${propertyname} [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] ) 
028:         * [and,or]  ${identifier}.${propertyname}  [=,<,>,!=,>=,<=, LIKE, IN] ['value',:namedParameter,?positionalParameter] "
029:         <p>
030:         * 
031:         * multiclass queries are of the form
032:         * <p>
033:         * select ${identifierA}, ${identifierB} From ${classname} AS ${identifierA}, ${classname} AS ${identifierB} where ${identifierA}.${propertyname} [=,<,>,!=,>=,<=] 'value' [and.or] ${identifierB}.${propertyname}  [=,<,>,!=,>=,<=] 'value'"
034:         * <p>
035:         * 
036:         * All values are created using a reflective String constructor .So if you want to Compare an Integer(22) you just specify
037:         * value=22  - the value type is chosen based on the declared type of the field.
038:         * <p>
039:         * For primitives, primitive wrappers or some natively comparable classes in the JVM the propertyname is always the literal string 'VALUE' (case insensitive)
040:         * * 		<ul>
041:         * 			<li>java.lang.String.class,
042:         <li>java.lang.Integer.class,
043:         <li>java.lang.Double.class,
044:         <li>java.lang.Float.class,
045:         <li>java.lang.Long.class,
046:         <li>java.lang.Short.class,
047:         <li>java.math.BigInteger.class,
048:         <li>java.math.BigDecimal.class,
049:         <li>java.util.Date.class,
050:         <li>java.net.URI.class 
051:         <li>java.lang.Byte.class
052:         <li>java.lang.Character.class
053:         <li>java.sql.Timestamp.class
054:         </ul>  
055:         * <p>
056:         * For example to query an integer you would write
057:         * <p>
058:         * select i from java.lang.Integer i  where i.VALUE = 20
059:         * <p>
060:         * or <br>
061:         * select i from java.lang.Integer as i where i.VALUE =20
062:         * <p>
063:         * 
064:         * Dates are constructed using the default encoding of the JVM. So a UK encoding would be:
065:         * <p>
066:         * select d from java.util.Date d where d.value <='4/10/1901 00:00:00' 
067:         * <p>
068:         * For user defined classes in order to query the property type must have a String constructor and must 
069:         * implement equals and hashCode correctly.
070:         * 
071:         *  <p>
072:         * 
073:         * For those classes that do not support String constructors or if you wish to use already existing values then you can use either 
074:         * the Named parameter or Positional parameter format.
075:         * </p>
076:         * 
077:         * <p>
078:         * For instance to query for an integer as above we can use:<br>
079:         * new EJBQuery("select i from java.lang.Integer as i where i.value =:intVal").setParameter("intVal", new Integer(20));
080:         *  <br>
081:         * or<br>
082:         * new EJBQuery("select i from java.lang.Integer as i where i.value =?1").setParameter(1, new Integer(20));
083:         * </p>
084:         * 
085:         * 
086:         *  @author Steve Woodcock
087:         *  @version 1.0
088:         */
089:        public class EJBQuery implements  IndexQuery, QueryId {
090:
091:            String query = null;
092:
093:            int hashCode = 0;
094:            Map parameterMap = new HashMap();
095:
096:            int maxResults;
097:            int firstResult;
098:
099:            static final QueryType QUERY_ID = QueryType.UNPARSED_QUERY;
100:
101:            private static final String TERMINATOR = ";";
102:
103:            public EJBQuery(String query) {
104:                this .query = query + TERMINATOR;
105:            }
106:
107:            public String getQuery() {
108:                return this .query;
109:            }
110:
111:            public QueryType getQueryType() {
112:
113:                return QUERY_ID;
114:            }
115:
116:            /**
117:             * Sets a parameter that must match a named parameter in the query string.<br>
118:             * The nameParameter in the Query is in the form :name and the parameter is set as "name" 
119:             * without the leading ':'. The value can be any object but its type must be assignable to the parameter 
120:             * type using normal Java assignability rules. So if the parameter is a String we cannot set an Integer 
121:             * and expect the type to be correctly coerced.<p>
122:             * @param name - the name of the parameter
123:             * @param value - the value the query should compare against
124:             * @return - itself to allow method chaining.
125:             */
126:            public IndexQuery setParameter(String name, Object value) {
127:                parameterMap.put(name, value);
128:                return this ;
129:            }
130:
131:            /**
132:             * Sets a parameter that must match a poitional parameter in the query string.<br>
133:             * The positional Parameter in the Query is in the form ?number and the parameter is set as an int. The value can be any object but its type must be assignable to the parameter 
134:             * type using normal Java assignability rules. So if the parameter is a String we cannot set an Integer 
135:             * and expect the type to be correctly coerced.<p>
136:             * @param parameter - the position of the parameter
137:             * @param value - the value the query should compare against
138:             * @return - itself to allow method chaining.
139:             */
140:            public IndexQuery setParameter(int parameter, Object value) {
141:                parameterMap.put("" + parameter, value);
142:                return this ;
143:            }
144:
145:            /**
146:             * Returns a Map of the parameters set on the query keyed by name and/or position. Positional parameters 
147:             * are stored in the Map as String representation of the int 
148:             * @return - the map of parameters.
149:             */
150:            public Map getParameterMap() {
151:                return parameterMap;
152:            }
153:
154:            public void clearParameters() {
155:                parameterMap.clear();
156:            }
157:
158:            /* (non-Javadoc)
159:             * @see java.lang.Object#hashCode()
160:             */
161:            public int hashCode() {
162:                if (hashCode == 0) {
163:                    hashCode = query.hashCode();
164:                }
165:                return hashCode;
166:            }
167:
168:            /* (non-Javadoc)
169:             * @see java.lang.Object#equals(java.lang.Object)
170:             */
171:            public boolean equals(Object obj) {
172:                return query.equals(obj);
173:            }
174:
175:            public String toString() {
176:                return query;
177:            }
178:
179:            public IndexQuery setFirstResult(int firstResult) {
180:                this .firstResult = firstResult;
181:                return this ;
182:            }
183:
184:            public int getFirstResult() {
185:
186:                return firstResult;
187:            }
188:
189:            public int getMaxResults() {
190:
191:                return maxResults;
192:            }
193:
194:            public IndexQuery setMaxResults(int maxResults) {
195:                this.maxResults = maxResults;
196:                return this;
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.