Source Code Cross Referenced for OracleQueryStatement.java in  » Database-ORM » TJDO » com » triactive » jdo » store » 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 » TJDO » com.triactive.jdo.store 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002 (C) TJDO.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the TJDO License version 1.0.
006:         * See the terms of the TJDO License in the documentation provided with this software.
007:         *
008:         * $Id: OracleQueryStatement.java,v 1.7 2003/08/11 16:01:52 pierreg0 Exp $
009:         */
010:
011:        package com.triactive.jdo.store;
012:
013:        import javax.jdo.JDOFatalInternalException;
014:        import java.util.Iterator;
015:
016:        class OracleQueryStatement extends QueryStatement {
017:            /**
018:             * The system property that selects the "linguistic definition" to be used
019:             * for native language sorting of String fields.  This is the string
020:             * "com.triactive.jdo.oracle.nlsSortOrder".  The default value is "LATIN".
021:             * A value of "BINARY" disables native language sorting.
022:             */
023:            public static final String NLS_SORT_ORDER_PROPERTY = "com.triactive.jdo.oracle.nlsSortOrder";
024:
025:            private final String nlsSortOrder = System.getProperty(
026:                    NLS_SORT_ORDER_PROPERTY, "LATIN").toUpperCase();
027:
028:            public OracleQueryStatement(Table initialTable) {
029:                super (initialTable);
030:            }
031:
032:            public OracleQueryStatement(Table initialTable,
033:                    SQLIdentifier initialRangeVar) {
034:                super (initialTable, initialRangeVar);
035:            }
036:
037:            public void setOrdering(SQLExpression[] exprs, boolean[] descending) {
038:                assertNotFrozen();
039:
040:                boolean needsSelect = dba.includeOrderByColumnsInSelect();
041:
042:                orderByList = new StatementText();
043:
044:                for (int i = 0; i < exprs.length; ++i) {
045:                    if (i > 0)
046:                        orderByList.append(',');
047:
048:                    if (exprs[i] instanceof  CharacterExpression
049:                            && !nlsSortOrder.equals("BINARY"))
050:                        orderByList.append("NLSSORT(").append(exprs[i]).append(
051:                                ", 'NLS_SORT = ").append(nlsSortOrder).append(
052:                                "')");
053:                    else {
054:                        String exprText = exprs[i].toStatementText().toString();
055:
056:                        if (exprs[i] instanceof  BooleanExpression) {
057:                            if (false == (exprs[i] instanceof  BooleanCharColumnExpression)) {
058:                                throw new JDOFatalInternalException(
059:                                        "OracleAdapter only supports boolean char expressions.");
060:                            }
061:
062:                            exprText = stripTruthTest((BooleanCharColumnExpression) exprs[i]);
063:                        }
064:
065:                        orderByList.append(exprText);
066:                    }
067:
068:                    if (descending[i])
069:                        orderByList.append(" DESC");
070:
071:                    if (needsSelect) {
072:                        Iterator j = exprs[i].toStatementText()
073:                                .getReferencedColumns().iterator();
074:
075:                        while (j.hasNext()) {
076:                            String columnRef = j.next().toString();
077:
078:                            if (!selected.contains(columnRef))
079:                                selected.add(columnRef);
080:                        }
081:                    }
082:                }
083:            }
084:
085:            /**
086:             * Return the StatementText as a String with the truth test stripped off.
087:             * This is a hack to account for the fact that Oracle does't support boolean
088:             * expressions in ORDER BY clauses.
089:             * @param   expr  The BooleanCharColumnExpression to strip to truth test from.
090:             * @return  The StatementText as a String with the truth test stripped off.
091:             */
092:            private static String stripTruthTest(
093:                    BooleanCharColumnExpression expr) {
094:                String text = expr.toStatementText().toString();
095:
096:                if (null != text) {
097:                    text = text.substring(0, text.lastIndexOf(" = '"));
098:                }
099:
100:                return text;
101:            }
102:
103:            private void join(TableExpression te, ObjectExpression fromExpr,
104:                    ObjectExpression toExpr) {
105:                joins.add(te);
106:                andCondition(fromExpr.eq(toExpr));
107:            }
108:
109:            public void innerJoin(QueryColumn from, QueryColumn to) {
110:                assertNotFrozen();
111:
112:                ObjectExpression fromExpr = new ObjectExpression(this , from);
113:                ObjectExpression toExpr = new ObjectExpression(this , to);
114:
115:                join(to.te, fromExpr, toExpr);
116:            }
117:
118:            public void leftOuterJoin(QueryColumn from, QueryColumn to) {
119:                assertNotFrozen();
120:
121:                ObjectExpression fromExpr = new ObjectExpression(this , from);
122:                ObjectExpression toExpr = new ObjectExpression(this , to, "(+)");
123:
124:                join(to.te, fromExpr, toExpr);
125:            }
126:
127:            public void rightOuterJoin(QueryColumn from, QueryColumn to) {
128:                assertNotFrozen();
129:
130:                ObjectExpression fromExpr = new ObjectExpression(this , from,
131:                        "(+)");
132:                ObjectExpression toExpr = new ObjectExpression(this , to);
133:
134:                join(to.te, fromExpr, toExpr);
135:            }
136:
137:            public StatementText toStatementText() {
138:                if (stmtText == null) {
139:                    stmtText = new StatementText("SELECT ");
140:
141:                    if (distinctResults)
142:                        stmtText.append("DISTINCT ");
143:
144:                    Iterator i = selected.iterator();
145:
146:                    while (i.hasNext()) {
147:                        stmtText.append(i.next());
148:
149:                        if (i.hasNext())
150:                            stmtText.append(',');
151:                    }
152:
153:                    stmtText.append(" FROM ").append(initialTableExpr);
154:
155:                    i = joins.iterator();
156:
157:                    while (i.hasNext())
158:                        stmtText.append(',').append(i.next());
159:
160:                    if (whereExpr != null)
161:                        stmtText.append(" WHERE ").append(whereExpr);
162:
163:                    if (orderByList != null)
164:                        stmtText.append(" ORDER BY ").append(orderByList);
165:                }
166:
167:                return stmtText;
168:            }
169:
170:            public String toString() {
171:                return toStatementText().toString();
172:            }
173:
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.