Source Code Cross Referenced for SqlExprSupport.java in  » RSS-RDF » sesame » org » openrdf » sail » rdbms » algebra » base » 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.algebra.base 
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.algebra.base;
007:
008:        import org.openrdf.model.URI;
009:        import org.openrdf.model.vocabulary.XMLSchema;
010:        import org.openrdf.query.algebra.MathExpr;
011:        import org.openrdf.query.algebra.Compare.CompareOp;
012:        import org.openrdf.sail.rdbms.algebra.DoubleValue;
013:        import org.openrdf.sail.rdbms.algebra.FalseValue;
014:        import org.openrdf.sail.rdbms.algebra.SqlAbs;
015:        import org.openrdf.sail.rdbms.algebra.SqlAnd;
016:        import org.openrdf.sail.rdbms.algebra.SqlCase;
017:        import org.openrdf.sail.rdbms.algebra.SqlCompare;
018:        import org.openrdf.sail.rdbms.algebra.SqlConcat;
019:        import org.openrdf.sail.rdbms.algebra.SqlEq;
020:        import org.openrdf.sail.rdbms.algebra.SqlIsNull;
021:        import org.openrdf.sail.rdbms.algebra.SqlLike;
022:        import org.openrdf.sail.rdbms.algebra.SqlLowerCase;
023:        import org.openrdf.sail.rdbms.algebra.SqlMathExpr;
024:        import org.openrdf.sail.rdbms.algebra.SqlNot;
025:        import org.openrdf.sail.rdbms.algebra.SqlNull;
026:        import org.openrdf.sail.rdbms.algebra.SqlOr;
027:        import org.openrdf.sail.rdbms.algebra.SqlRegex;
028:        import org.openrdf.sail.rdbms.algebra.StringValue;
029:        import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException;
030:
031:        /**
032:         * Support method to create SQL expressions.
033:         * 
034:         * @author James Leigh
035:         * 
036:         */
037:        public class SqlExprSupport {
038:
039:            public static SqlExpr abs(SqlExpr arg) {
040:                return new SqlAbs(arg);
041:            }
042:
043:            public static SqlExpr and(SqlExpr left, SqlExpr right) {
044:                return new SqlAnd(left, right);
045:            }
046:
047:            public static SqlExpr cmp(SqlExpr left, CompareOp op, SqlExpr right) {
048:                return new SqlCompare(left, op, right);
049:            }
050:
051:            public static SqlExpr coalesce(SqlExpr... exprs) {
052:                SqlCase sqlCase = new SqlCase();
053:                for (SqlExpr expr : exprs) {
054:                    sqlCase.when(isNotNull(expr.clone()), expr);
055:                }
056:                return sqlCase;
057:            }
058:
059:            public static SqlExpr concat(SqlExpr left, SqlExpr right) {
060:                return new SqlConcat(left, right);
061:            }
062:
063:            public static SqlExpr eq(SqlExpr left, SqlExpr right) {
064:                return new SqlEq(left, right);
065:            }
066:
067:            public static SqlExpr eqComparingNull(SqlExpr left, SqlExpr right) {
068:                SqlExpr leftIsNull = isNull(left.clone());
069:                SqlExpr rightIsNull = isNull(right.clone());
070:                SqlExpr bothNull = and(leftIsNull, rightIsNull);
071:                SqlExpr bothNotNull = and(not(leftIsNull), not(rightIsNull));
072:                return or(bothNull, and(bothNotNull, eq(left, right)));
073:            }
074:
075:            public static SqlExpr eqIfNotNull(SqlExpr left, SqlExpr right) {
076:                SqlExpr leftIsNotNull = isNotNull(left.clone());
077:                SqlExpr rightIsNotNull = isNotNull(right.clone());
078:                SqlExpr bothNotNull = and(leftIsNotNull, rightIsNotNull);
079:                return and(bothNotNull, eq(left, right));
080:            }
081:
082:            public static SqlExpr eqOrBothNull(SqlExpr left, SqlExpr right) {
083:                SqlExpr leftIsNull = isNull(left.clone());
084:                SqlExpr rightIsNull = isNull(right.clone());
085:                SqlExpr bothNull = and(leftIsNull, rightIsNull);
086:                return or(bothNull, eq(left, right));
087:            }
088:
089:            public static SqlExpr eqOrSimpleType(SqlExpr left, SqlExpr right) {
090:                SqlExpr bothSimple = and(simple(left), simple(right));
091:                return or(eq(left.clone(), right.clone()), bothSimple);
092:            }
093:
094:            public static SqlExpr ge(SqlExpr left, SqlExpr right) {
095:                return new SqlCompare(left, CompareOp.GE, right);
096:            }
097:
098:            public static SqlExpr gt(SqlExpr left, SqlExpr right) {
099:                return new SqlCompare(left, CompareOp.GT, right);
100:            }
101:
102:            public static SqlExpr in(SqlExpr compare, SqlExpr... values) {
103:                SqlExpr expr = null;
104:                for (SqlExpr value : values) {
105:                    if (expr == null) {
106:                        expr = new SqlEq(compare, value);
107:                    } else {
108:                        expr = or(expr, new SqlEq(compare.clone(), value));
109:                    }
110:                }
111:                if (expr == null)
112:                    return new FalseValue();
113:                return expr;
114:            }
115:
116:            public static SqlExpr isNotNull(SqlExpr arg) {
117:                return not(isNull(arg));
118:            }
119:
120:            public static SqlExpr isNull(SqlExpr arg) {
121:                return new SqlIsNull(arg);
122:            }
123:
124:            public static SqlExpr le(SqlExpr left, SqlExpr right) {
125:                return new SqlCompare(left, CompareOp.LE, right);
126:            }
127:
128:            public static SqlExpr like(SqlExpr left, SqlExpr right) {
129:                return new SqlLike(left, right);
130:            }
131:
132:            public static SqlExpr lowercase(SqlExpr arg) {
133:                return new SqlLowerCase(arg);
134:            }
135:
136:            public static SqlExpr lt(SqlExpr left, SqlExpr right) {
137:                return new SqlCompare(left, CompareOp.LT, right);
138:            }
139:
140:            public static SqlExpr neq(SqlExpr left, SqlExpr right) {
141:                return new SqlNot(new SqlEq(left, right));
142:            }
143:
144:            public static SqlExpr neqComparingNull(SqlExpr left, SqlExpr right) {
145:                SqlExpr leftIsNull = isNull(left.clone());
146:                SqlExpr rightIsNull = isNull(right.clone());
147:                SqlExpr onlyLeftIsNull = and(not(leftIsNull), rightIsNull
148:                        .clone());
149:                SqlExpr onlyRightIsNull = and(leftIsNull.clone(),
150:                        not(rightIsNull));
151:                SqlExpr compareNull = or(onlyRightIsNull, onlyLeftIsNull);
152:                return or(not(eq(left, right)), compareNull);
153:            }
154:
155:            public static SqlExpr not(SqlExpr arg) {
156:                return new SqlNot(arg);
157:            }
158:
159:            public static SqlExpr num(double value) {
160:                return new DoubleValue(value);
161:            }
162:
163:            public static SqlExpr or(SqlExpr left, SqlExpr right) {
164:                return new SqlOr(left, right);
165:            }
166:
167:            public static SqlExpr regex(SqlExpr value, SqlExpr pattern) {
168:                return new SqlRegex(value, pattern);
169:            }
170:
171:            public static SqlExpr regex(SqlExpr value, SqlExpr pattern,
172:                    SqlExpr flags) {
173:                return new SqlRegex(value, pattern, flags);
174:            }
175:
176:            public static SqlExpr simple(SqlExpr arg) {
177:                SqlExpr isString = eq(arg.clone(), str(XMLSchema.STRING));
178:                return or(isNull(arg.clone()), isString);
179:            }
180:
181:            public static SqlExpr sqlNull() {
182:                return new SqlNull();
183:            }
184:
185:            public static SqlExpr str(String str) {
186:                if (str == null)
187:                    return sqlNull();
188:                return new StringValue(str);
189:            }
190:
191:            public static SqlExpr str(URI uri) {
192:                return new StringValue(uri.stringValue());
193:            }
194:
195:            public static SqlExpr sub(SqlExpr left, SqlExpr right) {
196:                return new SqlMathExpr(left, MathExpr.MathOp.MINUS, right);
197:            }
198:
199:            public static UnsupportedRdbmsOperatorException unsupported(
200:                    Object arg) {
201:                return new UnsupportedRdbmsOperatorException(arg.toString());
202:            }
203:
204:            private SqlExprSupport() {
205:                // no constructor
206:            }
207:
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.