Source Code Cross Referenced for Query.java in  » Database-ORM » Ammentos » it » biobytes » ammentos » 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 » Database ORM » Ammentos » it.biobytes.ammentos.query 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   Copyright 2006 Davide Deidda
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:         */
016:
017:        /*
018:         * QueryFilterClause.java
019:         *
020:         * Created on 4 ottobre 2003, 10.37
021:         */
022:
023:        package it.biobytes.ammentos.query;
024:
025:        import java.util.*;
026:        import java.util.logging.*;
027:        import java.sql.*;
028:
029:        /**
030:         *
031:         * @author  davide
032:         */
033:        public class Query implements  Cloneable {
034:            private List m_filters;
035:            private List m_orderFields;
036:            private int m_orderingDir;
037:            private int m_maxResults;
038:            private int m_offset;
039:            private String m_domain; // Query domain
040:            private Logger m_logger = Logger.getLogger("ammentos");
041:
042:            public static final int ORDERING_ASC = 0;
043:            public static final int ORDERING_DESC = 1;
044:
045:            /** Creates a new instance of QueryFilterClause */
046:            public Query() {
047:                m_filters = new ArrayList();
048:                m_orderFields = new ArrayList();
049:            }
050:
051:            public Query(String domain) {
052:                this ();
053:                m_domain = domain;
054:            }
055:
056:            public Query(QueryFilter filter) {
057:                this ();
058:                appendFilter(filter);
059:            }
060:
061:            public void reverseOrderingDir() {
062:                if (m_orderingDir == ORDERING_ASC)
063:                    m_orderingDir = ORDERING_DESC;
064:                else
065:                    m_orderingDir = ORDERING_ASC;
066:            }
067:
068:            public void setOrderingDir(int direction) {
069:                m_orderingDir = direction;
070:            }
071:
072:            public int getOrderingDir() {
073:                return m_orderingDir;
074:            }
075:
076:            public String getOrderFilterAt(int pos) {
077:                String res = null;
078:                try {
079:                    res = (String) m_orderFields.get(pos);
080:                } catch (Exception e) {
081:                }
082:                return res;
083:            }
084:
085:            public void appendOrderFilter(String fieldName) {
086:                m_orderFields.add(fieldName);
087:            }
088:
089:            public void clearOrderFilters() {
090:                m_orderFields.clear();
091:            }
092:
093:            public QueryFilter appendFilter(QueryFilter filter) {
094:                m_filters.add(filter);
095:                return filter;
096:            }
097:
098:            public QueryFilter appendFilter(String fieldName) {
099:                return appendFilter(QueryFilter.APP_AND, fieldName);
100:            }
101:
102:            public QueryFilter appendFilter(int previousAppender,
103:                    String fieldName) {
104:                return (appendFilter(new SimpleQueryFilter(previousAppender,
105:                        fieldName)));
106:            }
107:
108:            public QueryFilter getFilterAt(int index) {
109:                return (QueryFilter) m_filters.get(index);
110:            }
111:
112:            public int getFiltersCount() {
113:                return m_filters.size();
114:            }
115:
116:            public String getWhereClauseSql() {
117:                StringBuffer res = new StringBuffer();
118:                Iterator it = m_filters.iterator();
119:
120:                // building where clause
121:                if (!m_filters.isEmpty()) {
122:                    res.append(" WHERE (");
123:
124:                    int i = 0;
125:                    while (it.hasNext()) {
126:                        QueryFilter filter = (QueryFilter) it.next();
127:                        if (filter != null) {
128:                            if (i != 0) {
129:                                res.append(filter.getPreviousAppender());
130:                            }
131:                            res.append(filter.getSql());
132:                        }
133:                        i++;
134:                    }
135:                    res.append(")");
136:                }
137:                return res.toString();
138:            }
139:
140:            public String getSql() {
141:                StringBuffer res = new StringBuffer();
142:
143:                res.append(getWhereClauseSql());
144:
145:                // building order by clause
146:                if (!m_orderFields.isEmpty()) {
147:                    res.append(" ORDER BY ");
148:                    Iterator fieldsIt = m_orderFields.iterator();
149:                    while (fieldsIt.hasNext()) {
150:                        res.append(fieldsIt.next().toString());
151:                        if (fieldsIt.hasNext())
152:                            res.append(", ");
153:                    }
154:
155:                    if (m_orderingDir == ORDERING_DESC)
156:                        res.append(" DESC");
157:                }
158:
159:                m_logger.info("query: " + res.toString());
160:                return res.toString();
161:            }
162:
163:            public int setParamValues(PreparedStatement pstmt, int initialIndex)
164:                    throws SQLException {
165:                Iterator it = m_filters.iterator();
166:                while (it.hasNext()) {
167:                    QueryFilter filter = (QueryFilter) it.next();
168:                    initialIndex = filter.setParamValues(pstmt, initialIndex);
169:                }
170:
171:                return initialIndex;
172:            }
173:
174:            public void removeFilterAt(int index) {
175:                m_filters.remove(index);
176:            }
177:
178:            public void removeAllFilters() {
179:                m_filters.clear();
180:            }
181:
182:            public void setFilterAt(int index, QueryFilter filter) {
183:                m_filters.set(index, filter);
184:            }
185:
186:            public boolean isEmpty() {
187:                return m_filters.isEmpty() && m_orderFields.isEmpty();
188:            }
189:
190:            public void setMaxResults(int number) {
191:                m_maxResults = number;
192:            }
193:
194:            public int getMaxResults() {
195:                return m_maxResults;
196:            }
197:
198:            public void setOffset(int offset) {
199:                m_offset = offset;
200:            }
201:
202:            public int getOffset() {
203:                return m_offset;
204:            }
205:
206:            public String getDomain() {
207:                return m_domain;
208:            }
209:
210:            public void setDomain(String m_domain) {
211:                this.m_domain = m_domain;
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.