Source Code Cross Referenced for SqlExprBuilder.java in  » RSS-RDF » sesame » org » openrdf » sail » rdbms » evaluation » 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 » RSS RDF » sesame » org.openrdf.sail.rdbms.evaluation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
003:         *
004:         * Licensed under the Aduna BSD-style license.
005:         */
006:        package org.openrdf.sail.rdbms.evaluation;
007:
008:        import java.util.ArrayList;
009:        import java.util.List;
010:
011:        import org.openrdf.query.algebra.MathExpr;
012:        import org.openrdf.sail.rdbms.algebra.SqlCompare;
013:
014:        /**
015:         * Assemblies an SQL expression.
016:         * 
017:         * @author James Leigh
018:         * 
019:         */
020:        public class SqlExprBuilder {
021:            protected class Mark {
022:                int length;
023:                int size;
024:
025:                Mark(int length, int size) {
026:                    this .length = length;
027:                    this .size = size;
028:                }
029:            }
030:
031:            private static final String NULL = " NULL ";
032:            private QueryBuilderFactory factory;
033:            private List<Object> parameters = new ArrayList<Object>();
034:            private StringBuilder where = new StringBuilder();
035:
036:            public SqlExprBuilder(QueryBuilderFactory factory) {
037:                super ();
038:                this .factory = factory;
039:            }
040:
041:            public SqlBracketBuilder abs() {
042:                where.append(" ABS");
043:                return open();
044:            }
045:
046:            public SqlExprBuilder and() {
047:                if (!isEmpty()) {
048:                    where.append("\n AND ");
049:                }
050:                return this ;
051:            }
052:
053:            public SqlExprBuilder append(CharSequence sql) {
054:                where.append(sql);
055:                return this ;
056:            }
057:
058:            public void appendBoolean(boolean booleanValue) {
059:                if (booleanValue) {
060:                    where.append(" 1=1 ");
061:                } else {
062:                    where.append(" 0=1 ");
063:                }
064:            }
065:
066:            public SqlExprBuilder appendNull() {
067:                where.append(getSqlNull());
068:                return this ;
069:            }
070:
071:            public SqlExprBuilder appendNumeric(double doubleValue) {
072:                where.append(" ? ");
073:                parameters.add(doubleValue);
074:                return this ;
075:            }
076:
077:            public void appendOperator(SqlCompare.Operator op) {
078:                switch (op) {
079:                case GE:
080:                    where.append(" >= ");
081:                    break;
082:                case GT:
083:                    where.append(" > ");
084:                    break;
085:                case LE:
086:                    where.append(" <= ");
087:                    break;
088:                case LT:
089:                    where.append(" < ");
090:                    break;
091:                }
092:            }
093:
094:            public void as(String column) {
095:                where.append(" AS ").append(column);
096:            }
097:
098:            public SqlExprBuilder number(Number time) {
099:                where.append(" ? ");
100:                parameters.add(time);
101:                return this ;
102:            }
103:
104:            public SqlCaseBuilder caseBegin() {
105:                return new SqlCaseBuilder(this );
106:            }
107:
108:            public SqlExprBuilder column(String alias, String column) {
109:                where.append(alias).append(".").append(column);
110:                return this ;
111:            }
112:
113:            public SqlExprBuilder columnEquals(String alias, String column,
114:                    Number id) {
115:                return column(alias, column).eq().number(id);
116:            }
117:
118:            public SqlExprBuilder columnEquals(String alias, String column,
119:                    String label) {
120:                return column(alias, column).eq().varchar(label);
121:            }
122:
123:            public SqlExprBuilder columnIn(String alias, String column,
124:                    Number[] ids) {
125:                if (ids.length == 1) {
126:                    return columnEquals(alias, column, ids[0]);
127:                }
128:                SqlBracketBuilder open = open();
129:                for (int i = 0; i < ids.length; i++) {
130:                    if (i > 0) {
131:                        open.or();
132:                    }
133:                    open.column(alias, column);
134:                    open.eq();
135:                    open.number(ids[i]);
136:                }
137:                open.close();
138:                return this ;
139:            }
140:
141:            public SqlExprBuilder columnsEqual(String al1, String col1,
142:                    String al2, String col2) {
143:                return column(al1, col1).eq().column(al2, col2);
144:            }
145:
146:            public void concat() {
147:                append(" || ");
148:            }
149:
150:            public SqlExprBuilder eq() {
151:                where.append(" = ");
152:                return this ;
153:            }
154:
155:            public List<Object> getParameters() {
156:                return parameters;
157:            }
158:
159:            public boolean isEmpty() {
160:                return where.length() == 0;
161:            }
162:
163:            public SqlExprBuilder isNotNull() {
164:                where.append(" IS NOT NULL ");
165:                return this ;
166:            }
167:
168:            public SqlExprBuilder isNull() {
169:                where.append(" IS NULL ");
170:                return this ;
171:            }
172:
173:            public void like() {
174:                where.append(" LIKE ");
175:            }
176:
177:            public SqlBracketBuilder lowerCase() {
178:                where.append(" lower");
179:                return open();
180:            }
181:
182:            public void math(MathExpr.MathOp op) {
183:                append(" ").append(op.getSymbol()).append(" ");
184:            }
185:
186:            public SqlBracketBuilder mod(int value) {
187:                where.append(" MOD");
188:                SqlBracketBuilder open = open();
189:                open.setClosing("," + value + open.getClosing());
190:                return open;
191:            }
192:
193:            public SqlBracketBuilder not() {
194:                where.append(" NOT");
195:                return open();
196:            }
197:
198:            public SqlExprBuilder notEqual() {
199:                where.append(" != ");
200:                return this ;
201:            }
202:
203:            public SqlBracketBuilder open() {
204:                return factory.createSqlBracketBuilder(this );
205:            }
206:
207:            public SqlExprBuilder or() {
208:                append(" OR ");
209:                return this ;
210:            }
211:
212:            public void plus(int range) {
213:                where.append(" + " + range);
214:            }
215:
216:            public SqlRegexBuilder regex() {
217:                return factory.createSqlRegexBuilder(this );
218:            }
219:
220:            public void rightShift(int rightShift) {
221:                where.append(" >> " + rightShift);
222:            }
223:
224:            public CharSequence toSql() {
225:                return where;
226:            }
227:
228:            @Override
229:            public String toString() {
230:                return where.toString();
231:            }
232:
233:            public SqlExprBuilder varchar(String stringValue) {
234:                if (stringValue == null) {
235:                    appendNull();
236:                } else {
237:                    where.append(" ? ");
238:                    parameters.add(stringValue);
239:                }
240:                return this ;
241:            }
242:
243:            protected void addParameters(List<Object> params) {
244:                parameters.addAll(params);
245:            }
246:
247:            protected String getSqlNull() {
248:                return NULL;
249:            }
250:
251:            protected Mark mark() {
252:                return new Mark(where.length(), parameters.size());
253:            }
254:
255:            protected void reset(Mark mark) {
256:                where.delete(mark.length, where.length());
257:                for (int i = parameters.size() - 1; i >= mark.size; i--) {
258:                    parameters.remove(i);
259:                }
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.