You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by cl...@apache.org on 2021/05/07 23:12:39 UTC
[db-jdo] 05/06: Clean up 2.0-rc1
This is an automated email from the ASF dual-hosted git repository.
clr pushed a commit to branch origin/2.0-rc1
in repository https://gitbox.apache.org/repos/asf/db-jdo.git
commit 7ad160f34bce8e414cee11ae06bb7138d2d7a18f
Author: Craig L Russell <cl...@apache.org>
AuthorDate: Thu Feb 23 01:31:23 2006 +0000
Clean up 2.0-rc1
---
query20/LICENSE.txt | 202 --
query20/maven.xml | 99 -
query20/project.properties | 25 -
query20/project.xml | 82 -
query20/src/conf/commons-logging.properties | 44 -
query20/src/conf/logging.properties | 66 -
query20/src/conf/simplelog.properties | 56 -
.../org/apache/jdo/impl/jdoql/Bundle.properties | 225 --
.../jdo/impl/jdoql/JDOQLQueryFactoryImpl.java | 116 -
.../org/apache/jdo/impl/jdoql/MemoryQuery.java | 1484 -----------
.../apache/jdo/impl/jdoql/OrderingComparator.java | 125 -
.../java/org/apache/jdo/impl/jdoql/QueryImpl.java | 994 --------
.../jdo/impl/jdoql/QueryResultHelperImpl.java | 226 --
.../org/apache/jdo/impl/jdoql/jdoqlc/ErrorMsg.java | 143 --
.../java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQL.g | 843 -------
.../org/apache/jdo/impl/jdoql/jdoqlc/JDOQLAST.java | 220 --
.../jdo/impl/jdoql/jdoqlc/JDOQLASTFactory.java | 95 -
.../org/apache/jdo/impl/jdoql/jdoqlc/JDOQLC.java | 326 ---
.../org/apache/jdo/impl/jdoql/jdoqlc/Optimizer.g | 1313 ----------
.../org/apache/jdo/impl/jdoql/jdoqlc/Semantic.g | 1727 -------------
.../jdo/impl/jdoql/jdoqlc/SimpleFieldManager.java | 189 --
.../apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java | 440 ----
.../jdo/impl/jdoql/jdoqlc/VariableChecker.java | 290 ---
.../jdo/impl/jdoql/scope/AbstractValueTable.java | 175 --
.../jdo/impl/jdoql/scope/ParameterTable.java | 173 --
.../apache/jdo/impl/jdoql/scope/SymbolTable.java | 87 -
.../org/apache/jdo/impl/jdoql/scope/TypeNames.java | 156 --
.../org/apache/jdo/impl/jdoql/scope/UNDEFINED.java | 62 -
.../apache/jdo/impl/jdoql/scope/VariableTable.java | 66 -
.../org/apache/jdo/impl/jdoql/tree/AndExpr.java | 94 -
.../jdo/impl/jdoql/tree/AscendingOrderingExpr.java | 79 -
.../org/apache/jdo/impl/jdoql/tree/BinaryExpr.java | 166 --
.../jdo/impl/jdoql/tree/BooleanLiteralExpr.java | 93 -
.../jdo/impl/jdoql/tree/ByteLiteralExpr.java | 92 -
.../jdo/impl/jdoql/tree/CandidateClassImpl.java | 94 -
.../org/apache/jdo/impl/jdoql/tree/CastExpr.java | 116 -
.../jdo/impl/jdoql/tree/CharLiteralExpr.java | 92 -
.../apache/jdo/impl/jdoql/tree/ComplementExpr.java | 78 -
.../jdo/impl/jdoql/tree/ConditionalAndExpr.java | 96 -
.../jdo/impl/jdoql/tree/ConditionalOrExpr.java | 96 -
.../apache/jdo/impl/jdoql/tree/ConstantExpr.java | 127 -
.../jdo/impl/jdoql/tree/ContainsCallExpr.java | 121 -
.../java/org/apache/jdo/impl/jdoql/tree/Decl.java | 87 -
.../impl/jdoql/tree/DescendingOrderingExpr.java | 79 -
.../org/apache/jdo/impl/jdoql/tree/DivideExpr.java | 95 -
.../jdo/impl/jdoql/tree/DoubleLiteralExpr.java | 92 -
.../jdo/impl/jdoql/tree/EndsWithCallExpr.java | 119 -
.../org/apache/jdo/impl/jdoql/tree/EqualsExpr.java | 94 -
.../java/org/apache/jdo/impl/jdoql/tree/Expr.java | 50 -
.../jdo/impl/jdoql/tree/FieldAccessExpr.java | 204 --
.../impl/jdoql/tree/FilterExpressionDumper.java | 497 ----
.../jdo/impl/jdoql/tree/FloatLiteralExpr.java | 92 -
.../jdo/impl/jdoql/tree/GreaterThanEqualsExpr.java | 96 -
.../jdo/impl/jdoql/tree/GreaterThanExpr.java | 95 -
.../apache/jdo/impl/jdoql/tree/IdentifierExpr.java | 100 -
.../apache/jdo/impl/jdoql/tree/IntLiteralExpr.java | 92 -
.../jdo/impl/jdoql/tree/IsEmptyCallExpr.java | 89 -
.../jdo/impl/jdoql/tree/LessThanEqualsExpr.java | 96 -
.../apache/jdo/impl/jdoql/tree/LessThanExpr.java | 94 -
.../jdo/impl/jdoql/tree/LongLiteralExpr.java | 92 -
.../apache/jdo/impl/jdoql/tree/MethodCallExpr.java | 114 -
.../org/apache/jdo/impl/jdoql/tree/MinusExpr.java | 94 -
.../org/apache/jdo/impl/jdoql/tree/NodeImpl.java | 259 --
.../apache/jdo/impl/jdoql/tree/NotEqualsExpr.java | 96 -
.../org/apache/jdo/impl/jdoql/tree/NotExpr.java | 77 -
.../org/apache/jdo/impl/jdoql/tree/OrExpr.java | 94 -
.../apache/jdo/impl/jdoql/tree/OrderingExpr.java | 64 -
.../jdo/impl/jdoql/tree/ParameterAccessExpr.java | 81 -
.../apache/jdo/impl/jdoql/tree/ParameterDecl.java | 77 -
.../org/apache/jdo/impl/jdoql/tree/PlusExpr.java | 94 -
.../jdo/impl/jdoql/tree/ShortLiteralExpr.java | 92 -
.../jdo/impl/jdoql/tree/StartsWithCallExpr.java | 119 -
.../jdo/impl/jdoql/tree/StaticFieldAccessExpr.java | 166 --
.../org/apache/jdo/impl/jdoql/tree/ThisExpr.java | 76 -
.../org/apache/jdo/impl/jdoql/tree/TimesExpr.java | 95 -
.../java/org/apache/jdo/impl/jdoql/tree/Tree.java | 1021 --------
.../org/apache/jdo/impl/jdoql/tree/TypeImpl.java | 93 -
.../org/apache/jdo/impl/jdoql/tree/UnaryExpr.java | 64 -
.../apache/jdo/impl/jdoql/tree/UnaryMinusExpr.java | 77 -
.../apache/jdo/impl/jdoql/tree/UnaryPlusExpr.java | 76 -
.../jdo/impl/jdoql/tree/VariableAccessExpr.java | 81 -
.../apache/jdo/impl/jdoql/tree/VariableDecl.java | 77 -
.../org/apache/jdo/jdoql/JDOQLQueryFactory.java | 151 --
.../org/apache/jdo/jdoql/JDOQueryException.java | 61 -
query20/src/java/org/apache/jdo/jdoql/package.html | 27 -
.../apache/jdo/jdoql/tree/AbstractNodeVisitor.java | 1586 ------------
.../org/apache/jdo/jdoql/tree/AndExpression.java | 29 -
.../jdoql/tree/AscendingOrderingExpression.java | 29 -
.../apache/jdo/jdoql/tree/BinaryExpression.java | 52 -
.../jdo/jdoql/tree/BooleanLiteralExpression.java | 32 -
.../jdo/jdoql/tree/ByteLiteralExpression.java | 31 -
.../org/apache/jdo/jdoql/tree/CandidateClass.java | 29 -
.../org/apache/jdo/jdoql/tree/CastExpression.java | 39 -
.../jdo/jdoql/tree/CharLiteralExpression.java | 31 -
.../jdo/jdoql/tree/ComplementExpression.java | 28 -
.../jdo/jdoql/tree/ConditionalAndExpression.java | 28 -
.../jdo/jdoql/tree/ConditionalOrExpression.java | 28 -
.../apache/jdo/jdoql/tree/ConstantExpression.java | 33 -
.../jdo/jdoql/tree/ContainsCallExpression.java | 29 -
.../org/apache/jdo/jdoql/tree/Declaration.java | 41 -
.../jdoql/tree/DescendingOrderingExpression.java | 29 -
.../apache/jdo/jdoql/tree/DivideExpression.java | 28 -
.../jdo/jdoql/tree/DoubleLiteralExpression.java | 31 -
.../jdo/jdoql/tree/EndsWithCallExpression.java | 29 -
.../apache/jdo/jdoql/tree/EqualsExpression.java | 28 -
.../java/org/apache/jdo/jdoql/tree/Expression.java | 29 -
.../apache/jdo/jdoql/tree/ExpressionFactory.java | 330 ---
.../jdo/jdoql/tree/FieldAccessExpression.java | 52 -
.../jdo/jdoql/tree/FloatLiteralExpression.java | 31 -
.../jdoql/tree/GreaterThanEqualsExpression.java | 28 -
.../jdo/jdoql/tree/GreaterThanExpression.java | 28 -
.../jdo/jdoql/tree/IdentifierExpression.java | 40 -
.../jdo/jdoql/tree/IntLiteralExpression.java | 31 -
.../jdo/jdoql/tree/IsEmptyCallExpression.java | 28 -
.../jdo/jdoql/tree/LessThanEqualsExpression.java | 28 -
.../apache/jdo/jdoql/tree/LessThanExpression.java | 28 -
.../jdo/jdoql/tree/LongLiteralExpression.java | 31 -
.../jdo/jdoql/tree/MethodCallExpression.java | 50 -
.../org/apache/jdo/jdoql/tree/MinusExpression.java | 27 -
.../src/java/org/apache/jdo/jdoql/tree/Node.java | 119 -
.../org/apache/jdo/jdoql/tree/NodeVisitor.java | 1676 -------------
.../apache/jdo/jdoql/tree/NotEqualsExpression.java | 28 -
.../org/apache/jdo/jdoql/tree/NotExpression.java | 28 -
.../org/apache/jdo/jdoql/tree/OrExpression.java | 29 -
.../apache/jdo/jdoql/tree/OrderingExpression.java | 33 -
.../jdo/jdoql/tree/ParameterAccessExpression.java | 27 -
.../jdo/jdoql/tree/ParameterDeclaration.java | 27 -
.../org/apache/jdo/jdoql/tree/PlusExpression.java | 27 -
.../java/org/apache/jdo/jdoql/tree/QueryTree.java | 127 -
.../jdo/jdoql/tree/ShortLiteralExpression.java | 31 -
.../jdo/jdoql/tree/StartsWithCallExpression.java | 29 -
.../jdoql/tree/StaticFieldAccessExpression.java | 43 -
.../org/apache/jdo/jdoql/tree/ThisExpression.java | 27 -
.../org/apache/jdo/jdoql/tree/TimesExpression.java | 28 -
.../java/org/apache/jdo/jdoql/tree/TreeWalker.java | 69 -
.../src/java/org/apache/jdo/jdoql/tree/Type.java | 41 -
.../org/apache/jdo/jdoql/tree/UnaryExpression.java | 33 -
.../jdo/jdoql/tree/UnaryMinusExpression.java | 28 -
.../apache/jdo/jdoql/tree/UnaryPlusExpression.java | 28 -
.../java/org/apache/jdo/jdoql/tree/ValueTable.java | 63 -
.../jdo/jdoql/tree/VariableAccessExpression.java | 27 -
.../apache/jdo/jdoql/tree/VariableDeclaration.java | 27 -
.../java/org/apache/jdo/jdoql/tree/package.html | 26 -
runtime20/maven.xml | 56 -
runtime20/project.properties | 18 -
runtime20/project.xml | 85 -
runtime20/src/conf/commons-logging.properties | 42 -
runtime20/src/conf/logging.properties | 62 -
runtime20/src/conf/simplelog.properties | 52 -
.../src/java/org/apache/jdo/ejb/EJBHelper.java | 130 -
.../src/java/org/apache/jdo/ejb/EJBImplHelper.java | 138 --
runtime20/src/java/org/apache/jdo/ejb/package.html | 26 -
.../jdo/impl/model/java/runtime/Bundle.properties | 59 -
.../model/java/runtime/RegisterClassListener.java | 178 --
.../impl/model/java/runtime/RuntimeJavaModel.java | 172 --
.../java/runtime/RuntimeJavaModelFactory.java | 147 --
.../impl/model/java/runtime/RuntimeJavaType.java | 70 -
.../java/runtime/jdk5/ComponentTypeHelper.java | 107 -
.../java/runtime/jdk5/JDK5RuntimeJavaField.java | 71 -
.../java/runtime/jdk5/JDK5RuntimeJavaMethod.java | 59 -
.../java/runtime/jdk5/JDK5RuntimeJavaModel.java | 58 -
.../runtime/jdk5/JDK5RuntimeJavaModelFactory.java | 88 -
.../java/runtime/jdk5/JDK5RuntimeJavaProperty.java | 74 -
.../java/runtime/jdk5/JDK5RuntimeJavaType.java | 84 -
.../jdo/impl/model/java/runtime/package.html | 27 -
.../apache/jdo/impl/model/jdo/xml/XMLExists.java | 268 --
.../java/org/apache/jdo/impl/pm/Bundle.properties | 102 -
.../org/apache/jdo/impl/pm/CacheManagerImpl.java | 631 -----
.../jdo/impl/pm/PersistenceManagerFactoryImpl.java | 1791 --------------
.../apache/jdo/impl/pm/PersistenceManagerImpl.java | 2573 -------------------
.../jdo/impl/pm/PersistenceManagerWrapper.java | 1140 ---------
.../org/apache/jdo/impl/pm/TransactionImpl.java | 1181 ---------
.../jdo/impl/pm/TransactionSynchronization.java | 60 -
.../src/java/org/apache/jdo/impl/pm/package.html | 28 -
.../java/org/apache/jdo/impl/sco/ArrayList.java | 605 -----
.../java/org/apache/jdo/impl/sco/Bundle.properties | 34 -
.../src/java/org/apache/jdo/impl/sco/Date.java | 247 --
.../src/java/org/apache/jdo/impl/sco/Freezer.java | 403 ---
.../src/java/org/apache/jdo/impl/sco/HashMap.java | 607 -----
.../src/java/org/apache/jdo/impl/sco/HashSet.java | 589 -----
.../java/org/apache/jdo/impl/sco/Hashtable.java | 614 -----
.../java/org/apache/jdo/impl/sco/LinkedList.java | 669 -----
.../java/org/apache/jdo/impl/sco/SCOHelper.java | 206 --
.../src/java/org/apache/jdo/impl/sco/SqlDate.java | 203 --
.../src/java/org/apache/jdo/impl/sco/SqlTime.java | 204 --
.../java/org/apache/jdo/impl/sco/SqlTimestamp.java | 288 ---
.../src/java/org/apache/jdo/impl/sco/TreeMap.java | 603 -----
.../src/java/org/apache/jdo/impl/sco/TreeSet.java | 596 -----
.../src/java/org/apache/jdo/impl/sco/Vector.java | 737 ------
.../src/java/org/apache/jdo/impl/sco/package.html | 27 -
.../apache/jdo/impl/state/AutoPersistentNew.java | 118 -
.../jdo/impl/state/AutoPersistentNewFlushed.java | 118 -
.../impl/state/AutoPersistentNewFlushedDirty.java | 101 -
.../jdo/impl/state/AutoPersistentPending.java | 88 -
.../org/apache/jdo/impl/state/Bundle.properties | 67 -
.../src/java/org/apache/jdo/impl/state/Hollow.java | 219 --
.../org/apache/jdo/impl/state/LifeCycleState.java | 573 -----
.../org/apache/jdo/impl/state/PersistentClean.java | 148 --
.../impl/state/PersistentCleanTransactional.java | 70 -
.../apache/jdo/impl/state/PersistentDeleted.java | 110 -
.../jdo/impl/state/PersistentDeletedFlushed.java | 58 -
.../org/apache/jdo/impl/state/PersistentDirty.java | 110 -
.../jdo/impl/state/PersistentDirtyFlushed.java | 92 -
.../org/apache/jdo/impl/state/PersistentNew.java | 108 -
.../jdo/impl/state/PersistentNewDeleted.java | 105 -
.../jdo/impl/state/PersistentNewFlushed.java | 92 -
.../impl/state/PersistentNewFlushedDeleted.java | 68 -
.../jdo/impl/state/PersistentNewFlushedDirty.java | 70 -
.../jdo/impl/state/PersistentNonTransactional.java | 282 ---
.../apache/jdo/impl/state/ReachabilityHandler.java | 255 --
.../org/apache/jdo/impl/state/SCOProcessor.java | 438 ----
.../apache/jdo/impl/state/SimpleFieldManager.java | 212 --
.../apache/jdo/impl/state/StateFieldManager.java | 207 --
.../apache/jdo/impl/state/StateManagerFactory.java | 66 -
.../apache/jdo/impl/state/StateManagerImpl.java | 2599 --------------------
.../org/apache/jdo/impl/state/TransientClean.java | 127 -
.../org/apache/jdo/impl/state/TransientDirty.java | 96 -
runtime20/src/java/org/apache/jdo/pm/Accessor.java | 37 -
.../jdo/pm/PersistenceManagerFactoryInternal.java | 78 -
.../apache/jdo/pm/PersistenceManagerInternal.java | 265 --
runtime20/src/java/org/apache/jdo/pm/package.html | 27 -
.../org/apache/jdo/query/BasicQueryResult.java | 310 ---
.../java/org/apache/jdo/query/Bundle.properties | 28 -
.../src/java/org/apache/jdo/query/QueryResult.java | 42 -
.../org/apache/jdo/query/QueryResultHelper.java | 83 -
.../org/apache/jdo/query/QueryResultIterator.java | 40 -
runtime20/src/java/org/apache/jdo/sco/SCO.java | 64 -
.../src/java/org/apache/jdo/sco/SCOCollection.java | 116 -
runtime20/src/java/org/apache/jdo/sco/SCODate.java | 36 -
runtime20/src/java/org/apache/jdo/sco/SCOMap.java | 142 --
runtime20/src/java/org/apache/jdo/sco/package.html | 26 -
.../java/org/apache/jdo/state/FieldManager.java | 137 --
.../org/apache/jdo/state/StateManagerInternal.java | 283 ---
.../src/java/org/apache/jdo/state/package.html | 26 -
.../java/org/apache/jdo/store/Bundle.properties | 30 -
.../src/java/org/apache/jdo/store/Connector.java | 85 -
.../java/org/apache/jdo/store/StoreManager.java | 269 --
.../org/apache/jdo/store/StoreManagerImpl.java | 124 -
.../src/java/org/apache/jdo/store/Transcriber.java | 26 -
.../org/apache/jdo/store/TranscriberFactory.java | 26 -
.../src/java/org/apache/jdo/store/package.html | 26 -
241 files changed, 47586 deletions(-)
diff --git a/query20/LICENSE.txt b/query20/LICENSE.txt
deleted file mode 100644
index d645695..0000000
--- a/query20/LICENSE.txt
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
diff --git a/query20/maven.xml b/query20/maven.xml
deleted file mode 100644
index 89f80fb..0000000
--- a/query20/maven.xml
+++ /dev/null
@@ -1,99 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright 2005 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<project default="default"
- xmlns:j="jelly:core"
- xmlns:ant="jelly:ant"
- xmlns:maven="jelly:maven"
- >
-
- <!-- ==================== -->
- <!-- Default Global Goals -->
- <!-- ==================== -->
-
- <goal name="default">
- <attainGoal name="jar:install"/>
- </goal>
-
- <goal name="build">
- <attainGoal name="default"/>
- </goal>
-
- <goal name="rebuild">
- <attainGoal name="clean"/>
- <attainGoal name="build"/>
- </goal>
-
- <preGoal name="java:compile">
- <attainGoal name="antlr.compile"/>
- </preGoal>
-
- <postGoal name="clean:clean">
- <attainGoal name="antlr.clean"/>
- </postGoal>
-
- <goal name="clobber" prereqs="clean">
- <delete>
- <fileset dir="." defaultexcludes="no" includes="**/*~"/>
- </delete>
- </goal>
-
- <!-- ============= -->
- <!-- ANTLR support -->
- <!-- ============= -->
-
- <preGoal name="antlr.compile">
- <condition property="antlr.required">
- <not>
- <and>
- <uptodate targetfile="${jdo.antlr.src.dir}/JDOQLParser.java"
- srcfile="${jdo.antlr.src.dir}/JDOQL.g" />
- <uptodate targetfile="${jdo.antlr.src.dir}/Semantic.java"
- srcfile="${jdo.antlr.src.dir}/Semantic.g" />
- <uptodate targetfile="${jdo.antlr.src.dir}/Optimizer.java"
- srcfile="${jdo.antlr.src.dir}/Optimizer.g" />
- </and>
- </not>
- </condition>
- </preGoal>
-
- <goal name="antlr.compile">
- <j:if test="${antlr.required}">
- <java dir="${jdo.antlr.src.dir}" classname="antlr.Tool" fork="yes">
- <arg value="JDOQL.g"/>
- <classpath refid="maven.dependency.classpath"/>
- </java>
- <java dir="${jdo.antlr.src.dir}" classname="antlr.Tool" fork="yes">
- <arg value="Semantic.g"/>
- <classpath refid="maven.dependency.classpath"/>
- </java>
- <java dir="${jdo.antlr.src.dir}" classname="antlr.Tool" fork="yes">
- <arg value="Optimizer.g"/>
- <classpath refid="maven.dependency.classpath"/>
- </java>
- </j:if>
- </goal>
-
- <goal name="antlr.clean">
- <delete>
- <fileset dir="${jdo.antlr.src.dir}"
- includes="JDOQLLexer.java, JDOQLParser.java, Semantic*.java,
- Optimizer*.java, *TokenTypes.*"/>
- </delete>
- </goal>
-
-</project>
diff --git a/query20/project.properties b/query20/project.properties
deleted file mode 100644
index 49a7a03..0000000
--- a/query20/project.properties
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-# Copyright 2005 The Apache Software Foundation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# checkstyle settings
-maven.checkstyle.properties = ${basedir}/../jdo_checks.xml
-maven.checkstyle.excludes = \
-org/apache/jdo/impl/jdoql/jdoqlc/*TokenTypes.java,\
-org/apache/jdo/impl/jdoql/jdoqlc/JDOQLParser.java, \
-org/apache/jdo/impl/jdoql/jdoqlc/JDOQLLexer.java, \
-org/apache/jdo/impl/jdoql/jdoqlc/Semantic.java, \
-org/apache/jdo/impl/jdoql/jdoqlc/Optimizer.java
-
-jdo.antlr.src.dir = ${basedir}/src/java/org/apache/jdo/impl/jdoql/jdoqlc
diff --git a/query20/project.xml b/query20/project.xml
deleted file mode 100644
index 40f2299..0000000
--- a/query20/project.xml
+++ /dev/null
@@ -1,82 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- Copyright 2005 The Apache Software Foundation
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<project>
- <pomVersion>3</pomVersion>
- <extend>../project.xml</extend>
- <!-- ============== -->
- <!-- Identification -->
- <!-- ============== -->
- <name>JDO2 Implementation (Query)</name>
- <groupId>org.apache.jdo</groupId>
- <artifactId>jdo2-query</artifactId>
- <currentVersion>2.0-rc1</currentVersion>
- <package>org.apache.jdo</package>
- <shortDescription>Java Data Object 2.0 (JDO) Core</shortDescription>
- <description>The Java Data Objects 2.0 (JDO) API is a standard interface-based
-Java model abstraction of persistence, developed as Java Specification
-Request JSR 243 under the auspices of the Java Community Process.</description>
- <repository />
- <!-- ============ -->
- <!-- Dependencies -->
- <!-- ============ -->
- <dependencies>
- <dependency>
- <groupId>javax.jdo</groupId>
- <artifactId>jdo2-api</artifactId>
- <version>2.0-rc1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.jdo</groupId>
- <artifactId>jdo2-core</artifactId>
- <version>2.0-rc1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.jdo</groupId>
- <artifactId>jdo2-runtime</artifactId>
- <version>2.0-rc1</version>
- </dependency>
- <dependency>
- <id>commons-logging</id>
- <version>1.0.4</version>
- </dependency>
- <dependency>
- <groupId>antlr</groupId>
- <artifactId>antlr</artifactId>
- <version>2.7.5</version>
- <url>http://www.antlr.org/download.html</url>
- </dependency>
- </dependencies>
- <!-- =================== -->
- <!-- Build Specification -->
- <!-- =================== -->
- <build>
- <sourceDirectory>src/java</sourceDirectory>
- <!-- J A R R E S O U R C E S -->
- <!-- Resources that are packaged up inside the JAR file -->
- <resources>
- <resource>
- <directory>${basedir}/src/java</directory>
- <includes>
- <include>**/*.properties</include>
- </includes>
- </resource>
- </resources>
- </build>
-</project>
-
diff --git a/query20/src/conf/commons-logging.properties b/query20/src/conf/commons-logging.properties
deleted file mode 100644
index 40d8e3d..0000000
--- a/query20/src/conf/commons-logging.properties
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Copyright 2005 The Apache Software Foundation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# This is a sample apache commons logging configuration file defining logging
-# properties for the JDO2 Implementation (Query) sources. It defines what
-# logging implementation the apache commons logging API should use by specifying
-# the property org.apache.commons.logging.Log (see below). Please note, that
-# there are separate property files for each logging implementation to set the
-# log level of the loggers:
-# - SimpleLog: simplelog.properties
-# - JDK1.4 logging: logging.properties
-#
-# The JDO2 Implementation (Query) sources use the following logger instances:
-# org.apache.jdo.impl.jdoql JDOQL query runtime
-# org.apache.jdo.impl.jdoql.jdoqlc JDOQL query compiler
-# Dependent projects:
-# org.apache.jdo.util Utility classes
-# org.apache.jdo.impl.model.jdo JDOModel implementation
-# org.apache.jdo.impl.model.jdo.xml XML parser for JDO metadata files
-# org.apache.jdo.impl.pm PM and PMF implementation
-# org.apache.jdo.impl.sco SCO implementation
-# org.apache.jdo.impl.state StateManager implementation
-# org.apache.jdo.store Generic StoreManager implementation
-#
-
-# Uncomment the next line if you want to use the apache simple logger
-#org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog
-
-# Uncomment the next two lines if you want to use JDK 1.4 logging
-#org.apache.commons.logging.Log = org.apache.jdo.util.JDOJdk14Logger
-
diff --git a/query20/src/conf/logging.properties b/query20/src/conf/logging.properties
deleted file mode 100644
index 0340f7d..0000000
--- a/query20/src/conf/logging.properties
+++ /dev/null
@@ -1,66 +0,0 @@
-#
-# Copyright 2005 The Apache Software Foundation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# This is a sample properties file to configure standard JDK 1.4 logging for
-# the JDO2 Implementation (Query) sources.
-# Below you find an entry for each of the source logger instances.
-# Please uncomment the line and adapt the log level to your needs,
-# in case to want to enable a particular logger.
-#
-# The following describes the mapping between the log level of JDK 1.4 logging
-# and apache commns logging:
-# JDK 1.4 Apache
-# FINEST trace
-# FINE, FINER debug
-# INFO, CONFIG info
-# WARNING warn
-# SEVERE error, fatal
-#
-
-######################
-# Query source logger
-######################
-
-# JDOQL query logger
-#org.apache.jdo.impl.jdoql.level = FINE
-# JDOQL query compiler logger
-#org.apache.jdo.impl.jdoql.jdoqlc.level = FINE
-
-######################
-# Dependent projects
-######################
-
-# Utility class logger
-#org.apache.jdo.util.level = FINE
-# JDOModel logger
-#org.apache.jdo.impl.model.jdo.level = FINE
-# XML parser logger
-#org.apache.jdo.impl.model.jdo.xml.level = FINE
-# PM and PMF logger
-#org.apache.jdo.impl.pm.level = FINE
-# SCO logger
-#org.apache.jdo.impl.sco.level = FINE
-# StateManager logger
-#org.apache.jdo.impl.state.level = FINE
-# Generic StoreManager logger
-#org.apache.jdo.store.level = FINE
-
-######################
-# JDK 1.4 logging properties
-######################
-
-handlers = java.util.logging.ConsoleHandler
-java.util.logging.ConsoleHandler.level = FINEST
diff --git a/query20/src/conf/simplelog.properties b/query20/src/conf/simplelog.properties
deleted file mode 100644
index 280c098..0000000
--- a/query20/src/conf/simplelog.properties
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# Copyright 2005 The Apache Software Foundation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-#
-# This is a sample properties file to configure apache commons logging SimpleLog
-# implementation for the JDO2 Implementation (Query) sources.
-# Below you find an entry for each of the source logger instances.
-# Please uncomment the line and adapt the log level to your needs,
-# in case to want to enable a particular logger.
-#
-
-######################
-# Query source logger
-######################
-
-# JDOQL query logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.jdoql = debug
-# JDOQL query compiler logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.jdoql.jdoqlc = debug
-
-######################
-# Dependent projects
-######################
-
-# Utility class logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.util = debug
-# JDOModel logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.model.jdo = debug
-# XML parser logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.model.jdo.xml = debug
-# PM and PMF logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.pm = debug
-# SCO logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.sco = debug
-# StateManager logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.impl.state = debug
-# Generic StoreManager logger
-#org.apache.commons.logging.simplelog.log.org.apache.jdo.store = debug
-
-######################
-# Default logging level
-######################
-
-org.apache.commons.logging.simplelog.defaultlog = error
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/Bundle.properties b/query20/src/java/org/apache/jdo/impl/jdoql/Bundle.properties
deleted file mode 100644
index 1db7774..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/Bundle.properties
+++ /dev/null
@@ -1,225 +0,0 @@
-#
-# Copyright 2005 The Apache Software Foundation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This file should conform to netbeans standards
-# (http://www.netbeans.org/i18n)
-
-# resource bundle for the messages
-# key consists of: <PREFIX_><description>
-# <PREFIX_> - any valid prefix like MSG_, EXC_, etc.
-# <description> - short description started with the upper case letter and used
-# upper case to represent each next word.
-
-#
-# resource bundle for query messages
-#
-
-#
-# generic
-#
-EXC_MissingCandidateClass=Missing candidate class specification.
-
-#
-# QueryImpl
-#
-EXC_NullQueryInstance=Specified query is null.
-EXC_InvalidCompiledQuery=Invalid compiled query of type ''{0}''.
-EXC_UnboundQuery=Query is not bound to a PersistenceManager.
-EXC_UnknownCandidateClass=Unknown candidate class ''{0}''
-EXC_NoTransaction=No transaction and NontransactionalRead is false.
-
-#
-# main jdoqlc compiler class
-#
-#NOI18N
-ERR_UnexpectedExceptionSemantic=JDOQLC.semanticCheck unexpected exception
-#NOI18N
-ERR_UnexpectedExceptionOptimizer=JDOQLC.optimize unexpected exception
-
-#
-# jdoqlc error message helper class
-#
-EXC_PositionInfoMsg={0}: {1}
-EXC_PositionInfoMsgColumn={0} column({1}): {2}
-EXC_PositionInfoMsgLineColumn={0} line({1}) column({2}): {3}
-
-#
-# jdoqlc syntax error messages
-#
-EXC_SyntaxError=Syntax error.
-EXC_SyntaxErrorAt=Syntax error at ''{0}''.
-EXC_UnexpectedToken=Syntax error unexpected token ''{0}''.
-EXC_UnexpectedChar=Syntax error unexpected char ''{0}''.
-EXC_ExpectedCharFound=Syntax error expected char ''{0}'', found ''{1}''.
-EXC_UnexpectedEOF=Unexpected end of text.
-#NOI18N
-ERR_UnexpectedExceptionUnicode=JDOQLLexer.UNICODE_STR unexpected exception
-
-#
-# jdoqlc semantic error messages (unsupported operations)
-#
-
-#
-# jdoqlc semantic error messages (user errors)
-#
-EXC_CollectionElementTypeMismatch=Collection element type ''{0}'' and argument type ''{1}'' not compatible.
-EXC_ClassTypeExpressionExpected=Expression of class type expected.
-EXC_InvalidStaticReference=Cannot make a static reference to non-static variable ''{0}'' of class ''{1}''.
-EXC_NotSortableType=Operand type ''{0}'' of {1} is not sortable.
-EXC_UndefinedExpression=Undefined expression ''{0}''.
-EXC_BooleanFilterExpected=Boolean expression expected, filter expression has type ''{0}''.
-EXC_CollectionTypeExpected=Collection expression expected, expression has type ''{0}''.
-EXC_StringTypeExpected=String expression expected, expression has type ''{0}''.
-EXC_MultipleDeclaration=Multiple declaration of ''{0}''.
-EXC_MultipleImport=Multiple import of ''{0}''.
-EXC_WrongNumberOfArgs=Wrong number of arguments.
-EXC_ArgumentTypeMismatch=Incompatible type of argument. Cannot convert ''{0}'' to ''{1}''.
-EXC_InvalidArguments=Invalid argument(s) for ''{0}''.
-EXC_InvalidMethodCall=Invalid method call.
-EXC_UnknownField=Field ''{0}'' not defined for class ''{1}''.
-EXC_UnknownType=Unknown type ''{0}''.
-EXC_UndefinedIdentifier=Undefined identifier ''{0}''.
-EXC_InvalidCast=Cannot cast expression of type ''{0}'' to type ''{1}''.
-EXC_NotSortableInOrdering=Type ''{0}'' of ordering expression is not sortable.
-EXC_InvalidParameterAccess=Identifier ''{0}'' used in parameter access node is not declared as parameter
-EXC_InvalidVariableAccess=Identifier ''{0}'' used in variable access node is not declared as variable
-#NOI18N
-ERR_SemanticError=Semantic error:
-#NOI18N
-ERR_MissingChildren=Ivalid node (missing children): ''{0}''
-
-#
-# jdoqlc variable checker
-#
-EXC_UnsupportedMultipleConstraints=Multiple constraints for variable ''{0}''.
-EXC_UnconstraintVariable=Variable ''{0}'' is not constrained by contains call - unconstrained variables not supported.
-EXC_UnusedVariable=Variable ''{0}'' defined but not used.
-EXC_UnsupportedCyclicConstaint=Unsupported cyclic constraint definition for variable ''{0}''.
-EXC_DifferentConstraints=Different constraints for the same variable ''{0}''.
-#NOI18N
-ERR_VariableCheckerUndefinedVariable=VariableChecker.{0}: undefined variable ''{1}''
-#NOI18N
-ERR_VariableCheckerMultipleDependencies=VariableChecker.markUsed: multiple dependencies for variable ''{0}'' old ''{1}'' new ''{2}''
-
-#
-# jdoqlc optimizer messages
-#
-EXC_InvalidLiteral=Invalid {0} literal ''{1}''.
-#NOI18N
-ERR_OptimizerError=Optimizer error:
-#NOI18N
-ERR_OptmizerInvalidType=Optimizer.{0}: invalid type ''{1}''
-#NOI18N
-ERR_OptmizerNumberExpected=Optimizer.{0}: expected number value ''{1}''
-#NOI18N
-ERR_OptmizerCollectionExpected=Optimizer.{0}: expected collection ''{1}''
-
-#
-# jdoqlc JDOQLASTFactory
-#
-#NOI18N
-ERR_UnexpectedExceptionClone=Unexpected exception during clone
-
-#
-# scope.AbstractValueTable
-#
-#NOI18N
-ERR_InvalidTableForExecution=Invalid table ''{0}'' for query execution, value map not initialized.
-#NOI18N
-ERR_UnexpectedCloneProblems=Unexpected problems during clone
-
-#
-# scope.ParameterTable
-#
-EXC_UnboundQueryParameter=Unbound query parameter ''{0}''.
-EXC_UndefinedQueryParameter=Undefined query parameter ''{0}''.
-EXC_WrongNumberOfQueryParameters=Wrong number of query parameter values.
-EXC_IncompatibleTypeOfQueryParameter=Incompatible type of actual query parameter. Cannot convert ''{0}'' to ''{1}''.
-
-#
-# scope.VariableTable
-#
-EXC_UndefinedQueryVariable=Undefined query variable ''{0}''.
-
-#
-# TypeSupport
-#
-EXC_CannotFindField=Cannot find field ''{0}'' of class ''{1}''.
-EXC_CannotAccessField=Cannot access field ''{0}'' of class ''{1}''.
-# {0} - field name
-# {1} - class name
-EXC_CannotChangeAccessibility=A SecurityException was thrown when trying to \
-make field ''{0}'' in class ''{1}'' accessible in order to access its value \
-while executing a query. In order to execute queries on transient instances, \
-you must grant java.lang.reflect.ReflectPermission("suppressAccessChecks") to \
-the codeBase containing the JDOQL implementation.
-EXC_InstanceBoundToDifferentPM=Instance ''{0}'' not bound to the PersistenceManager of the query
-#NOI18N
-ERR_CollectionFieldExpected=Collection field expected; field ''{0}'' of class ''{1}'' has type ''{2}''.
-
-#
-# tree.BinaryExpr
-#
-EXC_IncompatibleTypes=The operands ''{0}'', ''{1}'' for binary expression ''{2}'' have incompatible types. Change one of the operands.
-
-#
-# tree.CastExpr
-#
-EXC_IllegalCast=Cannot cast ''{0}'' to ''{1}''. Change one of the operands for cast expression ''{2}''.
-
-#
-# tree.MethodCallExpr
-#
-EXC_IllegalNumberOfParameters=Illegal number of parameters supplied for method call ''{0}''.
-
-#
-# tree.ContainsCallExpr
-# tree.IsEmptyCallExpr
-#
-EXC_NoCollectionType=The target expression ''{0}'' must have a collection type for method call expression ''{1}''. Change the target expression.
-
-#
-# tree.EndsWithCallExpr
-# tree.StartsWithCallExpr
-#
-EXC_NoStringType=The target expression ''{0}'' must have a string type for method call expression ''{1}''. Change the target expression.
-
-#
-# tree.FieldAccessExpr
-#
-EXC_NoSuchField=The identifier ''{0}'' does neither correspond with a declared parameter/variable nor with a field in class ''{1}''.
-
-#
-# tree.Node
-#
-EXC_CannotProcessNullNodes=Cannot construct node ''{0}'' for children which equal null. Do not use null arguments in any expression factory methods.
-EXC_CannotReuseNodes=The node ''{0}'' is already used in expression ''{1}''. Cannot reuse this node in another expression.
-
-#
-# tree.Tree
-#
-EXC_ParameterVariableCollision=You try to declare a parameter having name ''{0}''. This name is already used by a declared variable.
-EXC_VariableParameterCollision=You try to declare a variable having name ''{0}''. This name is already used by a declared parameter.
-EXC_IllegalTypeForFilterExpression=Cannot set filter expression ''{0}'' as it returns a non boolean type.
-EXC_IllegalIdentifier=You cannot create an identifier expression for Java key word. Do not use ''{0}'' for an identifier.
-EXC_NonSupportedMethodCall=Cannot construct a method call expression for method ''{0}''. This method is not supported.
-EXC_CannotResolveTokenType=Cannot resolve token type ''{0}''.
-
-#
-# MemoryQuery
-#
-EXC_IllegalResultTypeForExpression=Cannot apply operator ''{0}'' for operands of type ''{1}''.
-EXC_CannotAccessUnboundVariables=Cannot access unbound variable ''{0}''. Unbound variables do not have a corresponding contains clause.
-EXC_CannotProcessMultipleContainsClauses=Cannot process two contains clauses for the same binary expression.
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java b/query20/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java
deleted file mode 100644
index 6af0952..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jdo.impl.jdoql;
-
-import java.util.Collection;
-
-import javax.jdo.Extent;
-import javax.jdo.Query;
-
-import org.apache.jdo.impl.jdoql.tree.Tree;
-import org.apache.jdo.jdoql.JDOQLQueryFactory;
-import org.apache.jdo.jdoql.tree.QueryTree;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-
-/**
- * Implements the @link{QueryFactory} interface
- * in order to implement a component which is capable
- * to run together with JDO runtime.
- *
- * @author Michael Watzek
- */
-public class JDOQLQueryFactoryImpl implements JDOQLQueryFactory
-{
-
- /**
- * Returns a new QueryTree instance. This instance allows to specify a
- * query with an API (see {@link org.apache.jdo.jdoql.tree.QueryTree} and
- * {@link org.apache.jdo.jdoql.tree.ExpressionFactory}) rather than as
- * JDOQL strings. To run you create a query object from the QueryTree (see
- * {@link javax.jdo.PersistenceManager#newQuery(Object compiled)})
- * and call the execute method on the Query object.
- * @return new QueryTree instance.
- */
- public QueryTree newTree()
- {
- return new Tree();
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal)
- */
- public Query newQuery(PersistenceManagerInternal pm)
- {
- return new QueryImpl(pm);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Object)
- */
- public Query newQuery(PersistenceManagerInternal pm, Object compiled)
- {
- return new QueryImpl(pm, compiled);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class)
- */
- public Query newQuery(PersistenceManagerInternal pm, Class cls)
- {
- return new QueryImpl(pm, cls);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, javax.jdo.Extent)
- */
- public Query newQuery(PersistenceManagerInternal pm, Extent cln)
- {
- return new QueryImpl(pm, cln);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class, java.util.Collection)
- */
- public Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cln)
- {
- return new QueryImpl(pm, cls, cln);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class, java.lang.String)
- */
- public Query newQuery(PersistenceManagerInternal pm, Class cls, String filter)
- {
- return new QueryImpl(pm, cls, filter);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class, java.util.Collection, java.lang.String)
- */
- public Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cln, String filter)
- {
- return new QueryImpl(pm, cls, cln, filter);
- }
-
- /*
- * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, javax.jdo.Extent, java.lang.String)
- */
- public Query newQuery(PersistenceManagerInternal pm, Extent cln, String filter)
- {
- return new QueryImpl(pm, cln, filter);
- }
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/MemoryQuery.java b/query20/src/java/org/apache/jdo/impl/jdoql/MemoryQuery.java
deleted file mode 100644
index 1cc4ce3..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/MemoryQuery.java
+++ /dev/null
@@ -1,1484 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jdo.impl.jdoql;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Collections;
-
-import javax.jdo.JDOHelper;
-import javax.jdo.PersistenceManager;
-
-import org.apache.jdo.impl.jdoql.scope.ParameterTable;
-import org.apache.jdo.impl.jdoql.scope.UNDEFINED;
-import org.apache.jdo.impl.jdoql.scope.VariableTable;
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.jdoql.tree.AbstractNodeVisitor;
-import org.apache.jdo.jdoql.tree.AndExpression;
-import org.apache.jdo.jdoql.tree.CastExpression;
-import org.apache.jdo.jdoql.tree.ComplementExpression;
-import org.apache.jdo.jdoql.tree.ConditionalAndExpression;
-import org.apache.jdo.jdoql.tree.ConditionalOrExpression;
-import org.apache.jdo.jdoql.tree.ConstantExpression;
-import org.apache.jdo.jdoql.tree.ContainsCallExpression;
-import org.apache.jdo.jdoql.tree.DivideExpression;
-import org.apache.jdo.jdoql.tree.EndsWithCallExpression;
-import org.apache.jdo.jdoql.tree.EqualsExpression;
-import org.apache.jdo.jdoql.tree.Expression;
-import org.apache.jdo.jdoql.tree.FieldAccessExpression;
-import org.apache.jdo.jdoql.tree.GreaterThanEqualsExpression;
-import org.apache.jdo.jdoql.tree.GreaterThanExpression;
-import org.apache.jdo.jdoql.tree.IsEmptyCallExpression;
-import org.apache.jdo.jdoql.tree.LessThanEqualsExpression;
-import org.apache.jdo.jdoql.tree.LessThanExpression;
-import org.apache.jdo.jdoql.tree.MinusExpression;
-import org.apache.jdo.jdoql.tree.NotEqualsExpression;
-import org.apache.jdo.jdoql.tree.NotExpression;
-import org.apache.jdo.jdoql.tree.OrExpression;
-import org.apache.jdo.jdoql.tree.OrderingExpression;
-import org.apache.jdo.jdoql.tree.ParameterAccessExpression;
-import org.apache.jdo.jdoql.tree.PlusExpression;
-import org.apache.jdo.jdoql.tree.StartsWithCallExpression;
-import org.apache.jdo.jdoql.tree.StaticFieldAccessExpression;
-import org.apache.jdo.jdoql.tree.ThisExpression;
-import org.apache.jdo.jdoql.tree.TimesExpression;
-import org.apache.jdo.jdoql.tree.TreeWalker;
-import org.apache.jdo.jdoql.tree.UnaryMinusExpression;
-import org.apache.jdo.jdoql.tree.UnaryPlusExpression;
-import org.apache.jdo.jdoql.tree.VariableAccessExpression;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-import org.apache.jdo.util.I18NHelper;
-
-/**
- * An instance of this class is used to evaluate a
- * query tree in memory. For this purpose this class keeps references
- * to a parameter/variable table and to the current object corresponding
- * with a <code>ThisExpression</code>.
- * It extends <code>AbstractNodeVisitor</code>.
- * To evaluate a query tree, you need to pass the query tree instance and
- * an instance of this class to method <code>walk</code> of a tree walker
- * instance.
- *
- * @author Michael Watzek
- */
-public class MemoryQuery extends AbstractNodeVisitor
-{
- /** I18N support */
- final static I18NHelper msg = I18NHelper.getInstance(MemoryQuery.class);
- final static UNDEFINED undefined = UNDEFINED.getInstance();
-
- final TreeWalker walker = new TreeWalker();
- final List boundVariables = new ArrayList();
- VariableAccessExpression unboundVariableAccess = null;
- BoundVariable removedBoundVariable = null;
-
- final PersistenceManagerInternal pm;
- final ParameterTable parameters;
- final VariableTable variables;
- Object current;
-
- /**
- * Constructs an instance of this class for the specified paramter table
- * and variable table. This query evaluator uses reflection for
- * field accesses.
- * @param parameters the parameter table
- * @param variables the variable table
- */
- public MemoryQuery(ParameterTable parameters, VariableTable variables)
- { this( null, parameters, variables );
- }
-
- /**
- * Constructs an instance of this class for the specified paramter table
- * and variable table.
- * @param pm the persistence manager
- * @param parameters the parameter table
- * @param variables the variable table
- */
- public MemoryQuery(PersistenceManagerInternal pm, ParameterTable parameters, VariableTable variables)
- { this.pm = pm;
- this.parameters = parameters;
- this.variables = variables;
- }
-
- /**
- * Sets the instance returned by leaving an instance if
- * <code>ThisExpression</code>.
- * @param current the instance to set
- */
- public void setCurrent(Object current)
- { this.current = current;
- }
-
- //public methods of NodeVisitor
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non boolean types
- */
- public Object leave(AndExpression node, Object[] results)
- { Class clazz = node.getJavaClass();
- if( clazz==Boolean.class || clazz==boolean.class )
- return logicalAnd( results[0], results[1] );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "&", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the result evaluated
- * by the child of the argument <code>node</code>. The result
- * returned by this method is the same as the result evaluated by the child
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the result evaluated by the node's child
- * @return the result evaluated for node
- * @exception JDOQueryException if the result evaluated by the node's
- * child is not an instance of the type to cast to
- */
- public Object leave(CastExpression node, Object[] results)
- { Object value = results[1];
- if( value==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( value!=null &&
- !clazz.isInstance(value) )
- {
- if( clazz==Byte.class || clazz==byte.class ) {
- if( value instanceof Character )
- return new Byte( (byte)((Character)value).charValue() );
- else
- return new Byte( ((Number)value).byteValue() );
- }
- else if( clazz==Double.class || clazz==double.class ) {
- if( value instanceof Character )
- return new Double( ((Character)value).charValue() );
- else
- return new Double( ((Number)value).doubleValue() );
- }
- else if( clazz==Float.class || clazz==float.class ) {
- if( value instanceof Character )
- return new Float( ((Character)value).charValue() );
- else
- return new Float( ((Number)value).floatValue() );
- }
- else if( clazz==Integer.class || clazz==int.class ) {
- if( value instanceof Character )
- return new Integer( ((Character)value).charValue() );
- else
- return new Integer( ((Number)value).intValue() );
- }
- else if( clazz==Long.class || clazz==long.class ) {
- if( value instanceof Character )
- return new Long( ((Character)value).charValue() );
- else
- return new Long( ((Number)value).longValue() );
- }
- else if( clazz==Short.class || clazz==short.class ) {
- if( value instanceof Character )
- return new Short( (short) ((Character)value).charValue() );
- else
- return new Short( ((Number)value).shortValue() );
- }
- else if( clazz==BigInteger.class ) {
- if( value instanceof Character )
- return BigInteger.valueOf( (long) ((Character)value).charValue() );
- else
- return BigInteger.valueOf( ((Number)value).longValue() );
- }
- else if( clazz==BigDecimal.class ) {
- if( value instanceof Character )
- return new BigDecimal( (double) ((Character)value).charValue() );
- else
- return new BigDecimal( ((Number)value).doubleValue() );
- }
- else if( clazz==Character.class || clazz==char.class ) {
- if (value instanceof Number )
- return new Character((char)((Number)value).intValue());
- else
- return value;
- }
- // value is not null and is not an instance of the type
- // specified in the cast expression => return undefined
- return undefined;
- }
- return value;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the result evaluated
- * by the child of the argument <code>node</code>. The result
- * returned by this method is based on the result evaluated by the child
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the result evaluated by the node's child
- * @return the result evaluated for node
- * @exception JDOQueryException if the result evaluated by the node's
- * child is not a boolean or integral type.
- */
- public Object leave(ComplementExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( clazz==Integer.class || clazz==int.class )
- return new Integer( ~((Number)results[0]).intValue() );
- else if( clazz==Long.class || clazz==long.class )
- return new Long( ~((Number)results[0]).longValue() );
- else if( clazz==BigInteger.class )
- return ((BigInteger)results[0]).not();
- else if( clazz==Byte.class || clazz==byte.class )
- return new Byte( (byte) ~((Number)results[0]).byteValue() );
- else if( clazz==Character.class || clazz==char.class )
- return new Character( (char) ~((Character)results[0]).charValue() );
- else if( clazz==Short.class || clazz==short.class )
- return new Short( (short) ~((Number)results[0]).shortValue() );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "~", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non boolean types
- */
- public Object leave(ConditionalAndExpression node, Object[] results)
- { Class clazz = node.getJavaClass();
- if( clazz==Boolean.class || clazz==boolean.class )
- return logicalAnd( results[0], results[1] );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "&&", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non boolean types
- */
- public Object leave(ConditionalOrExpression node, Object[] results)
- { Class clazz = node.getJavaClass();
- if( clazz==Boolean.class || clazz==boolean.class )
- return logicalOr( results[0], results[1] );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "||", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> is <code>null</code> as the argument
- * <code>node</code> does not have any children. The result
- * returned by this method is the object wrapped by the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results <code>null</code>
- * @return the object wrapped by node
- */
- public Object leave(ConstantExpression node, Object[] results)
- { return node.getValue();
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- */
- public Object leave(ContainsCallExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- { // bind an empty set to the variable, if collection evaluates
- // to null or undefined, otherwise the variable access results
- // in an exception that unbound variables are not supported.
- if( this.unboundVariableAccess!=null )
- { this.boundVariables.add( new BoundVariable(this.unboundVariableAccess.getName(), this.unboundVariableAccess.getJavaClass(), Collections.EMPTY_SET) );
- }
- this.unboundVariableAccess = null;
- return undefined;
- }
- Collection collection = (Collection) results[0];
- boolean result;
- if( this.unboundVariableAccess!=null )
- { this.boundVariables.add( new BoundVariable(this.unboundVariableAccess.getName(), this.unboundVariableAccess.getJavaClass(), collection) );
- result = !collection.isEmpty();
- }
- else
- result = ((Collection)results[0]).contains( results[1] );
- this.unboundVariableAccess = null;
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(DivideExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( clazz==Integer.class || clazz==int.class )
- return new Integer( ((Number)results[0]).intValue() / ((Number)results[1]).intValue() );
- else if( clazz==Long.class || clazz==long.class )
- return new Long( ((Number)results[0]).longValue() / ((Number)results[1]).longValue() );
- else if( clazz==Double.class || clazz==double.class )
- return new Double( ((Number)results[0]).doubleValue() / ((Number)results[1]).doubleValue() );
- else if( clazz==Float.class || clazz==float.class )
- return new Float( ((Number)results[0]).floatValue() / ((Number)results[1]).floatValue() );
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- return left.divide( right, BigDecimal.ROUND_HALF_UP );
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- return left.divide( right );
- }
- else if( clazz==Byte.class || clazz==byte.class )
- return new Byte( (byte) (((Number)results[0]).byteValue() / ((Number)results[1]).byteValue()) );
- else if( clazz==Character.class || clazz==char.class )
- return new Character( (char) (((Character)results[0]).charValue() / ((Character)results[1]).charValue()) );
- else if( clazz==Short.class || clazz==short.class )
- return new Short( (short) (((Number)results[0]).shortValue() / ((Number)results[1]).shortValue()) );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "/", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- */
- public Object leave(EndsWithCallExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- boolean result = ((String)results[0]).endsWith( (String)results[1] );
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- */
- public Object leave(EqualsExpression node, Object[] results)
- { if( results[0]==undefined || results[1]==undefined )
- return undefined;
- boolean result;
- if( results[0]==null && results[1]==null )
- result = true;
- else if( results[0]==null || results[1]==null )
- result = false;
- else
- { Class clazz = node.getCommonOperandType();
- if( clazz==Integer.class || clazz==int.class )
- result = ((Number)results[0]).intValue() == ((Number)results[1]).intValue();
- else if( clazz==Long.class || clazz==long.class )
- result = ((Number)results[0]).longValue() == ((Number)results[1]).longValue();
- else if( clazz==Double.class || clazz==double.class )
- result = ((Number)results[0]).doubleValue() == ((Number)results[1]).doubleValue();
- else if( clazz==Float.class || clazz==float.class )
- result = ((Number)results[0]).floatValue() == ((Number)results[1]).floatValue();
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- result = left.compareTo( right ) == 0;
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- result = left.compareTo( right ) == 0;
- }
- else if( Date.class.isAssignableFrom(clazz) )
- result = ((Date)results[0]).getTime() == ((Date)results[1]).getTime();
- else if( clazz==Byte.class || clazz==byte.class )
- result = ((Number)results[0]).byteValue() == ((Number)results[1]).byteValue();
- else if( clazz==Character.class || clazz==char.class )
- result = ((Character)results[0]).charValue() == ((Character)results[1]).charValue();
- else if( clazz==Short.class || clazz==short.class )
- result = ((Number)results[0]).shortValue() == ((Number)results[1]).shortValue();
- else
- { PersistenceManager leftPM = JDOHelper.getPersistenceManager(results[0]);
- PersistenceManager rightPM = JDOHelper.getPersistenceManager(results[1]);
- if( leftPM!=null && rightPM!=null )
- // use == for persistence instances
- result = results[0] == results[1];
- else if( leftPM==null && rightPM==null )
- // use equals for non persistent instances
- result = results[0].equals( results[1] );
- else
- // comparing persistent with non persistent instance
- result = false;
- }
- }
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children is undefined
- */
- public Object leave(FieldAccessExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- return node.getFieldValue( pm, results[0] );
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(GreaterThanEqualsExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- boolean result;
- Class clazz = node.getCommonOperandType();
- if( clazz==Integer.class || clazz==int.class )
- result = ((Number)results[0]).intValue() >= ((Number)results[1]).intValue();
- else if( clazz==Long.class || clazz==long.class )
- result = ((Number)results[0]).longValue() >= ((Number)results[1]).longValue();
- else if( clazz==Double.class || clazz==double.class )
- result = ((Number)results[0]).doubleValue() >= ((Number)results[1]).doubleValue();
- else if( clazz==Float.class || clazz==float.class )
- result = ((Number)results[0]).floatValue() >= ((Number)results[1]).floatValue();
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- result = left.compareTo(right) >= 0;
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- result = left.compareTo(right) >= 0;
- }
- // Comparable covers Date and String
- else if( Comparable.class.isAssignableFrom(clazz) )
- result = ((Comparable)results[0]).compareTo((Comparable)results[1]) >= 0;
- else if( clazz==Byte.class || clazz==byte.class )
- result = ((Number)results[0]).byteValue() >= ((Number)results[1]).byteValue();
- else if( clazz==Character.class || clazz==char.class )
- result = ((Character)results[0]).charValue() >= ((Character)results[1]).charValue();
- else if( clazz==Short.class || clazz==short.class )
- result = ((Number)results[0]).shortValue() >= ((Number)results[1]).shortValue();
- else
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", ">=", clazz.getName()) ); //NOI18N
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(GreaterThanExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- boolean result;
- Class clazz = node.getCommonOperandType();
- if( clazz==Integer.class || clazz==int.class )
- result = ((Number)results[0]).intValue() > ((Number)results[1]).intValue();
- else if( clazz==Long.class || clazz==long.class )
- result = ((Number)results[0]).longValue() > ((Number)results[1]).longValue();
- else if( clazz==Double.class || clazz==double.class )
- result = ((Number)results[0]).doubleValue() > ((Number)results[1]).doubleValue();
- else if( clazz==Float.class || clazz==float.class )
- result = ((Number)results[0]).floatValue() > ((Number)results[1]).floatValue();
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- result = left.compareTo(right) > 0;
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- result = left.compareTo(right) > 0;
- }
- // Comparable covers Date and String
- else if( Comparable.class.isAssignableFrom(clazz) )
- result = ((Comparable)results[0]).compareTo((Comparable)results[1]) > 0;
- else if( clazz==Byte.class || clazz==byte.class )
- result = ((Number)results[0]).byteValue() > ((Number)results[1]).byteValue();
- else if( clazz==Character.class || clazz==char.class )
- result = ((Character)results[0]).charValue() > ((Character)results[1]).charValue();
- else if( clazz==Short.class || clazz==short.class )
- result = ((Number)results[0]).shortValue() > ((Number)results[1]).shortValue();
- else
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", ">", clazz.getName()) ); //NOI18N
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- */
- public Object leave(IsEmptyCallExpression node, Object[] results)
- { if( results[0]==null )
- return Boolean.TRUE;
- else if( results[0]==undefined )
- return undefined;
- boolean result = ((Collection)results[0]).isEmpty();
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(LessThanEqualsExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- boolean result;
- Class clazz = node.getCommonOperandType();
- if( clazz==Integer.class || clazz==int.class )
- result = ((Number)results[0]).intValue() <= ((Number)results[1]).intValue();
- else if( clazz==Long.class || clazz==long.class )
- result = ((Number)results[0]).longValue() <= ((Number)results[1]).longValue();
- else if( clazz==Double.class || clazz==double.class )
- result = ((Number)results[0]).doubleValue() <= ((Number)results[1]).doubleValue();
- else if( clazz==Float.class || clazz==float.class )
- result = ((Number)results[0]).floatValue() <= ((Number)results[1]).floatValue();
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- result = left.compareTo(right) <= 0;
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- result = left.compareTo(right) <= 0;
- }
- // Comparable covers Date and String
- else if( Comparable.class.isAssignableFrom(clazz) )
- result = ((Comparable)results[0]).compareTo((Comparable)results[1]) <= 0;
- else if( clazz==Byte.class || clazz==byte.class )
- result = ((Number)results[0]).byteValue() <= ((Number)results[1]).byteValue();
- else if( clazz==Character.class || clazz==char.class )
- result = ((Character)results[0]).charValue() <= ((Character)results[1]).charValue();
- else if( clazz==Short.class || clazz==short.class )
- result = ((Number)results[0]).shortValue() <= ((Number)results[1]).shortValue();
- else
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "<=", clazz.getName()) ); //NOI18N
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(LessThanExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- boolean result;
- Class clazz = node.getCommonOperandType();
- if( clazz==Integer.class || clazz==int.class )
- result = ((Number)results[0]).intValue() < ((Number)results[1]).intValue();
- else if( clazz==Long.class || clazz==long.class )
- result = ((Number)results[0]).longValue() < ((Number)results[1]).longValue();
- else if( clazz==Double.class || clazz==double.class )
- result = ((Number)results[0]).doubleValue() < ((Number)results[1]).doubleValue();
- else if( clazz==Float.class || clazz==float.class )
- result = ((Number)results[0]).floatValue() < ((Number)results[1]).floatValue();
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- result = left.compareTo(right) < 0;
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- result = left.compareTo(right) < 0;
- }
- // Comparable covers Date and String
- else if( Comparable.class.isAssignableFrom(clazz) )
- result = ((Comparable)results[0]).compareTo((Comparable)results[1]) < 0;
- else if( clazz==Byte.class || clazz==byte.class )
- result = ((Number)results[0]).byteValue() < ((Number)results[1]).byteValue();
- else if( clazz==Character.class || clazz==char.class )
- result = ((Character)results[0]).charValue() < ((Character)results[1]).charValue();
- else if( clazz==Short.class || clazz==short.class )
- result = ((Number)results[0]).shortValue() < ((Number)results[1]).shortValue();
- else
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "<", clazz.getName()) ); //NOI18N
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(MinusExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( clazz==Integer.class || clazz==int.class )
- return new Integer( ((Number)results[0]).intValue() - ((Number)results[1]).intValue() );
- else if( clazz==Long.class || clazz==long.class )
- return new Long( ((Number)results[0]).longValue() - ((Number)results[1]).longValue() );
- else if( clazz==Double.class || clazz==double.class )
- return new Double( ((Number)results[0]).doubleValue() - ((Number)results[1]).doubleValue() );
- else if( clazz==Float.class || clazz==float.class )
- return new Float( ((Number)results[0]).floatValue() - ((Number)results[1]).floatValue() );
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- return left.subtract( right );
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- return left.subtract( right );
- }
- else if( clazz==Byte.class || clazz==byte.class )
- return new Byte( (byte) (((Number)results[0]).byteValue() - ((Number)results[1]).byteValue()) );
- else if( clazz==Character.class || clazz==char.class )
- return new Character( (char) (((Character)results[0]).charValue() - ((Character)results[1]).charValue()) );
- else if( clazz==Short.class || clazz==short.class )
- return new Short( (short) (((Number)results[0]).shortValue() - ((Number)results[1]).shortValue()) );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "-", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(NotEqualsExpression node, Object[] results)
- { if( results[0]==undefined || results[1]==undefined )
- return undefined;
- boolean result;
- if( results[0]==null && results[1]==null )
- result = false;
- else if( results[0]==null || results[1]==null )
- result = true;
- else
- { Class clazz = node.getCommonOperandType();
- if( clazz==Integer.class || clazz==int.class )
- result = ((Number)results[0]).intValue() != ((Number)results[1]).intValue();
- else if( clazz==Long.class || clazz==long.class )
- result = ((Number)results[0]).longValue() != ((Number)results[1]).longValue();
- else if( clazz==Double.class || clazz==double.class )
- result = ((Number)results[0]).doubleValue() != ((Number)results[1]).doubleValue();
- else if( clazz==Float.class || clazz==float.class )
- result = ((Number)results[0]).floatValue() != ((Number)results[1]).floatValue();
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- result = left.compareTo( right ) != 0;
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- result = left.compareTo( right ) != 0;
- }
- else if( Date.class.isAssignableFrom(clazz) )
- result = ((Date)results[0]).getTime() != ((Date)results[1]).getTime();
- else if( clazz==Byte.class || clazz==byte.class )
- result = ((Number)results[0]).byteValue() != ((Number)results[1]).byteValue();
- else if( clazz==Character.class || clazz==char.class )
- result = ((Character)results[0]).charValue() != ((Character)results[1]).charValue();
- else if( clazz==Short.class || clazz==short.class )
- result = ((Number)results[0]).shortValue() != ((Number)results[1]).shortValue();
- else
- { PersistenceManager leftPM = JDOHelper.getPersistenceManager( results[0] );
- PersistenceManager rightPM = JDOHelper.getPersistenceManager( results[1] );
- if( leftPM!=null && rightPM!=null )
- // use == for persistence instances
- result = results[0] != results[1];
- else if( leftPM==null && rightPM==null )
- // use equals for non persistent instances
- result = !results[0].equals( results[1] );
- else
- // comparing persistent with non persistent instance
- result = true;
- }
- }
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the result evaluated
- * by the child of the argument <code>node</code>. The result
- * returned by this method is based on the result evaluated by the child
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the result evaluated by child of node
- * @return the result evaluated for node
- */
- public Object leave(NotExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- boolean result = !((Boolean)results[0]).booleanValue();
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the result evaluated
- * by the child of the argument <code>node</code>. The result
- * returned by this method is based on the result evaluated by the child
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the result evaluated by child of node
- * @return the result evaluated for node
- */
- public Object leave(OrderingExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- return results[0];
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non boolean types
- */
- public Object leave(OrExpression node, Object[] results)
- { Class clazz = node.getJavaClass();
- if( clazz==Boolean.class || clazz==boolean.class )
- return logicalOr( results[0], results[1] );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "|", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> is <code>null</code> as the argument
- * <code>node</code> does not have any children. The result
- * returned by this method is the instance obtained by the parameter table
- * for for the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results <code>null</code>
- * @return the instance obtained by the parameter table for node
- */
- public Object leave(ParameterAccessExpression node, Object[] results)
- { return this.parameters.getValue( node.getName() );
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(PlusExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( clazz==Integer.class || clazz==int.class )
- return new Integer( ((Number)results[0]).intValue() + ((Number)results[1]).intValue() );
- else if( clazz==Long.class || clazz==long.class )
- return new Long( ((Number)results[0]).longValue() + ((Number)results[1]).longValue() );
- else if( clazz==Double.class || clazz==double.class )
- return new Double( ((Number)results[0]).doubleValue() + ((Number)results[1]).doubleValue() );
- else if( clazz==Float.class || clazz==float.class )
- return new Float( ((Number)results[0]).floatValue() + ((Number)results[1]).floatValue() );
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- return left.add( right );
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- return left.add( right );
- }
- else if( clazz==String.class )
- return (String)results[0] + (String)results[1];
- else if( clazz==Byte.class || clazz==byte.class )
- return new Byte( (byte) (((Number)results[0]).byteValue() + ((Number)results[1]).byteValue()) );
- else if( clazz==Character.class || clazz==char.class )
- return new Character( (char) (((Character)results[0]).charValue() + ((Character)results[1]).charValue()) );
- else if( clazz==Short.class || clazz==short.class )
- return new Short( (short) (((Number)results[0]).shortValue() + ((Number)results[1]).shortValue()) );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "+", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- */
- public Object leave(StartsWithCallExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- boolean result = ((String)results[0]).startsWith( (String)results[1] );
- return result ? Boolean.TRUE : Boolean.FALSE;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- */
- public Object leave(StaticFieldAccessExpression node, Object[] results)
- { return node.getFieldValue( pm );
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> is <code>null</code> as the argument
- * <code>node</code> does not have any children. The result
- * returned by this method is the current instance stored in this node visitor
- * by method <code>setCurrent</code>.
- * @param node the node to be evaluated
- * @param results <code>null</code>
- * @return the current instance stored in this node visitor
- * by method <code>setCurrent</code>
- */
- public Object leave(ThisExpression node, Object[] results)
- { return this.current;
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the results evaluated
- * by the children of the argument <code>node</code>. The result
- * returned by this method is based on the results evaluated by the children
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the results evaluated by children of node
- * @return the result evaluated for node
- * @exception JDOQueryException if the results evaluated by the node's
- * children are non integral types
- */
- public Object leave(TimesExpression node, Object[] results)
- { if( results[0]==null || results[1]==null ||
- results[0]==undefined || results[1]==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( clazz==Integer.class || clazz==int.class )
- return new Integer( ((Number)results[0]).intValue() * ((Number)results[1]).intValue() );
- else if( clazz==Long.class || clazz==long.class )
- return new Long( ((Number)results[0]).longValue() * ((Number)results[1]).longValue() );
- else if( clazz==Double.class || clazz==double.class )
- return new Double( ((Number)results[0]).doubleValue() * ((Number)results[1]).doubleValue() );
- else if( clazz==Float.class || clazz==float.class )
- return new Float( ((Number)results[0]).floatValue() * ((Number)results[1]).floatValue() );
- else if( clazz==BigDecimal.class )
- { BigDecimal left, right;
- if( results[0] instanceof BigDecimal )
- left = (BigDecimal) results[0];
- else
- left = new BigDecimal( results[0].toString() );
- if( results[1] instanceof BigDecimal )
- right = (BigDecimal) results[1];
- else
- right = new BigDecimal( results[1].toString() );
- return left.multiply( right );
- }
- else if( clazz==BigInteger.class )
- { BigInteger left, right;
- if( results[0] instanceof BigInteger )
- left = (BigInteger) results[0];
- else
- left = new BigInteger( results[0].toString() );
- if( results[1] instanceof BigInteger )
- right = (BigInteger) results[1];
- else
- right = new BigInteger( results[1].toString() );
- return left.multiply( right );
- }
- else if( clazz==Byte.class || clazz==byte.class )
- return new Byte( (byte) (((Number)results[0]).byteValue() * ((Number)results[1]).byteValue()) );
- else if( clazz==Character.class || clazz==char.class )
- return new Character( (char) (((Character)results[0]).charValue() * ((Character)results[1]).charValue()) );
- else if( clazz==Short.class || clazz==short.class )
- return new Short( (short) (((Number)results[0]).shortValue() * ((Number)results[1]).shortValue()) );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "*", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the result evaluated
- * by the child of the argument <code>node</code>. The result
- * returned by this method is based on the result evaluated by the child
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the result evaluated by the node's child
- * @return the result evaluated for node
- * @exception JDOQueryException if the result evaluated by the node's
- * child is not an integral type.
- */
- public Object leave(UnaryMinusExpression node, Object[] results)
- { if( results[0]==null ||
- results[0]==undefined )
- return undefined;
- Class clazz = node.getJavaClass();
- if( clazz==Integer.class || clazz==int.class )
- return new Integer( -((Number)results[0]).intValue() );
- else if( clazz==Long.class || clazz==long.class )
- return new Long( -((Number)results[0]).longValue() );
- else if( clazz==Double.class || clazz==double.class )
- return new Double( -((Number)results[0]).doubleValue() );
- else if( clazz==Float.class || clazz==float.class )
- return new Float( -((Number)results[0]).floatValue() );
- else if( clazz==BigInteger.class )
- return ((BigInteger)results[0]).negate();
- else if( clazz==BigDecimal.class )
- return ((BigDecimal)results[0]).negate();
- else if( clazz==Byte.class || clazz==byte.class )
- return new Byte( (byte) -((Number)results[0]).byteValue() );
- else if( clazz==Character.class || clazz==char.class )
- return new Character( (char) -((Character)results[0]).charValue() );
- else if( clazz==Short.class || clazz==short.class )
- return new Short( (short) -((Number)results[0]).shortValue() );
- throw new JDOQueryException( msg.msg("EXC_IllegalResultTypeForExpression", "-", clazz.getName()) ); //NOI18N
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> contains the result evaluated
- * by the child of the argument <code>node</code>. The result
- * returned by this method is the same as the result evaluated by the child
- * of the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results the result evaluated by the node's child
- * @return the result evaluated for node
- */
- public Object leave(UnaryPlusExpression node, Object[] results)
- { return results[0];
- }
-
- /**
- * Returns the result evaluated for the argument <code>node</code>.
- * The argument <code>results</code> is <code>null</code> as the argument
- * <code>node</code> does not have any children. The result
- * returned by this method is the instance obtained by the variable table
- * for for the argument <code>node</code>.
- * @param node the node to be evaluated
- * @param results <code>null</code>
- * @return the instance obtained by the variable table for node
- */
- public Object leave(VariableAccessExpression node, Object[] results)
- { Object result = this.variables.getValue( node.getName() );
- if( result==undefined )
- this.unboundVariableAccess = node;
- return result;
- }
-
- /**
- * Returns <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is undefined and the argument <code>indexOfNextChild</code> is greater
- * than 0.
- * @param node the parent node of the children currently evaluated
- * @param resultOfPreviousChild an array of <code>null</code> instances
- * @param indexOfNextChild the index of the next child to be dumped
- * @return <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is undefined and the argument <code>indexOfNextChild</code> is greater
- * than 0
- */
- public boolean walkNextChild(AndExpression node, Object resultOfPreviousChild, int indexOfNextChild)
- { if( indexOfNextChild>0 )
- { BoundVariable boundVariable = removeBoundVariable();
- if( isIteration(boundVariable, node.getRightExpression()) )
- return false;
- }
- return true;
- }
-
- /**
- * Returns <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is <code>null</code>, undefined or <code>false</code> and the argument <code>indexOfNextChild</code> is greater
- * than 0.
- * @param node the parent node of the children currently evaluated
- * @param resultOfPreviousChild an array of <code>null</code> instances
- * @param indexOfNextChild the index of the next child to be dumped
- * @return <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is <code>null</code>, undefined or <code>false</code> and the argument <code>indexOfNextChild</code> is greater
- * than 0
- */
- public boolean walkNextChild(ConditionalAndExpression node, Object resultOfPreviousChild, int indexOfNextChild)
- { if( indexOfNextChild>0 )
- { BoundVariable boundVariable = removeBoundVariable();
- if ( isIteration(boundVariable, node.getRightExpression()) )
- return false;
- else if ( resultOfPreviousChild==undefined )
- // evaluate second operand, if first is undefined
- return true;
-
- Class clazz = node.getJavaClass();
- if( ((clazz==Boolean.class || clazz==boolean.class) &&
- resultOfPreviousChild!=null &&
- !((Boolean)resultOfPreviousChild).booleanValue()) )
- return false;
- }
- return true;
- }
-
- /**
- * Returns <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is <code>null</code>, undefined or <code>true</code> and the argument <code>indexOfNextChild</code> is greater
- * than 0.
- * @param node the parent node of the children currently evaluated
- * @param resultOfPreviousChild an array of <code>null</code> instances
- * @param indexOfNextChild the index of the next child to be dumped
- * @return <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is <code>null</code>, undefined or <code>true</code> and the argument <code>indexOfNextChild</code> is greater
- * than 0
- */
- public boolean walkNextChild(ConditionalOrExpression node, Object resultOfPreviousChild, int indexOfNextChild)
- { if( indexOfNextChild>0 )
- { BoundVariable boundVariable = removeBoundVariable();
- if( resultOfPreviousChild==undefined )
- // evaluate second operand, if first is undefined
- return true;
-
- Class clazz = node.getJavaClass();
- if ( ((clazz==Boolean.class || clazz==boolean.class) &&
- resultOfPreviousChild!=null &&
- ((Boolean)resultOfPreviousChild).booleanValue()) )
- return false;
- }
- return true;
- }
-
- /**
- * Returns <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is undefined and the argument <code>indexOfNextChild</code> is greater
- * than 0.
- * @param node the parent node of the children currently evaluated
- * @param resultOfPreviousChild an array of <code>null</code> instances
- * @param indexOfNextChild the index of the next child to be dumped
- * @return <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is undefined and the argument <code>indexOfNextChild</code> is greater than 0
- */
- public boolean walkNextChild(ContainsCallExpression node, Object resultOfPreviousChild, int indexOfNextChild)
- { return true;
- }
-
- /**
- * Returns <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is undefined and the argument <code>indexOfNextChild</code> is greater
- * than 0.
- * @param node the parent node of the children currently evaluated
- * @param resultOfPreviousChild an array of <code>null</code> instances
- * @param indexOfNextChild the index of the next child to be dumped
- * @return <code>false</code> if the argument <code>resultOfPreviousChild</code>
- * is undefined and the argument <code>indexOfNextChild</code> is greater
- * than 0
- */
- public boolean walkNextChild(OrExpression node, Object resultOfPreviousChild, int indexOfNextChild)
- { if( indexOfNextChild>0 )
- { BoundVariable boundVariable = removeBoundVariable();
- }
- return true;
- }
-
- //private members
- private class BoundVariable
- { String name;
- Class clazz;
- Collection collection;
- boolean result = false;
-
- BoundVariable(String name, Class clazz, Collection collection)
- { this.name = name;
- this.clazz = clazz;
- this.collection = collection;
- }
- public boolean equals(Object obj)
- { return name.equals( obj );
- }
- public int hashCode()
- { return name.hashCode();
- }
- public String toString()
- { return name.toString();
- }
- }
- private BoundVariable removeBoundVariable()
- { if( this.unboundVariableAccess!=null )
- throw new JDOQueryException( msg.msg("EXC_CannotAccessUnboundVariables", this.unboundVariableAccess.getName()) ); //NOI18N
- int nrOfBoundVariables = this.boundVariables.size();
- if( nrOfBoundVariables>1 )
- throw new JDOQueryException( msg.msg("EXC_CannotProcessMultipleContainsClauses") ); //NOI18N
- BoundVariable boundVariable;
- if( nrOfBoundVariables>0 )
- boundVariable = (BoundVariable) this.boundVariables.remove( nrOfBoundVariables-1 );
- else
- boundVariable = null;
- return boundVariable;
- }
- private boolean isIteration(BoundVariable boundVariable, Expression expr)
- { boolean result = false;
- if( boundVariable!=null )
- { result = true;
- boundVariable.result = false;
- int nrOfBoundVariables = this.boundVariables.size();
- for( Iterator i=boundVariable.collection.iterator(); i.hasNext(); )
- { Object value = i.next();
- if( boundVariable.clazz.isInstance(value) )
- { this.variables.setValue( boundVariable.name, value );
- Object object = walker.walk( expr, this );
- while( nrOfBoundVariables<this.boundVariables.size() )
- removeBoundVariable();
- if( object!=null &&
- object instanceof Boolean &&
- ((Boolean)object).booleanValue() )
- { boundVariable.result = true;
- break;
- } } }
- this.variables.setValue( boundVariable.name, undefined );
- this.removedBoundVariable = boundVariable;
- }
- return result;
- }
- private Object logicalAnd(Object left, Object right)
- { Object result;
- //if the expression has been an iteration then return the iteration result
- if( right==null )
- { if( this.removedBoundVariable!=null )
- { result = this.removedBoundVariable.result ? Boolean.TRUE : Boolean.FALSE;
- this.removedBoundVariable = null;
- }
- else
- result = left;
- }
- else if( right==undefined )
- { // right hand side is undefined =>
- // T AND U -> U
- // F AND U -> F
- // U AND U -> U
- if( (left==undefined) || ((Boolean)left).booleanValue() )
- result = undefined;
- else
- result = Boolean.FALSE;
- }
- else if( left==undefined )
- { // left hand side is undefined
- // U AND T -> U
- // U AND F -> F
- // U AND U -> U (handled above)
- if( ((Boolean)right).booleanValue() )
- result = undefined;
- else
- result = Boolean.FALSE;
- }
- else
- { result = ((Boolean)left).booleanValue() && ((Boolean)right).booleanValue() ?
- Boolean.TRUE : Boolean.FALSE;
- }
- return result;
- }
- private Object logicalOr(Object left, Object right)
- { Object result;
- //if the expression has been an iteration then return the iteration result
- if( right==null )
- { if( this.removedBoundVariable!=null )
- { result = this.removedBoundVariable.result ? Boolean.TRUE : Boolean.FALSE;
- this.removedBoundVariable = null;
- }
- else
- result = left;
- }
- else if( right==undefined )
- { // right hand side is undefined =>
- // T OR U -> T
- // F OR U -> U
- // U OR U -> U
- if( (left==undefined) || !((Boolean)left).booleanValue() )
- result = undefined;
- else
- result = Boolean.TRUE;
- }
- else if( left==undefined )
- { // left hand side is undefined
- // U OR T -> T
- // U OR F -> U
- // U OR U -> U (handled above)
- if ( ((Boolean)right).booleanValue() )
- result = Boolean.TRUE;
- else
- result = undefined;
- }
- else
- { result = ((Boolean)left).booleanValue() || ((Boolean)right).booleanValue() ?
- Boolean.TRUE : Boolean.FALSE;
- }
- return result;
- }
- private void log(String s)
- { System.out.print( s );
- }
- private void logln(String s)
- { System.out.println( s );
- }
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/OrderingComparator.java b/query20/src/java/org/apache/jdo/impl/jdoql/OrderingComparator.java
deleted file mode 100644
index 8c6272b..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/OrderingComparator.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jdo.impl.jdoql;
-
-
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.jdo.impl.jdoql.scope.UNDEFINED;
-import org.apache.jdo.jdoql.tree.DescendingOrderingExpression;
-import org.apache.jdo.jdoql.tree.OrderingExpression;
-import org.apache.jdo.jdoql.tree.QueryTree;
-import org.apache.jdo.jdoql.tree.TreeWalker;
-
-/**
- * An instance of this class is used to compare two instances of
- * <code>Comparable</code> based on the ordering expressions
- * defined by a query tree. This instance holds references to a query tree,
- * a tree walker and a memory query instance for this purpose.
- *
- * @author Michael Watzek
- */
-public class OrderingComparator implements Comparator
-{
- private static final UNDEFINED undefined = UNDEFINED.getInstance();
-
- List orderings;
- final TreeWalker walker;
- final MemoryQuery nodeVisitor;
-
- /**
- * Constructs an ordering comparator for a tree walker and a node visitor.
- * This comparator is not bound to a query tree.
- * It can be bound to a query tree by calling method
- * <code>setQueryTree</code>.
- * @param walker the tree walker
- * @param nodeVisitor the node visitor evaluating the ordering expressions
- */
- public OrderingComparator(TreeWalker walker, MemoryQuery nodeVisitor)
- { this( walker, nodeVisitor, null );
- }
-
- /**
- * Constructs an ordering comparator for a tree walker, a node visitor
- * and a query tree. This comparator is bound to that query tree.
- * @param walker the tree walker
- * @param nodeVisitor the node visitor evaluating the ordering expressions
- * @param queryTree the query tree containing the ordering expressions
- */
- public OrderingComparator(TreeWalker walker, MemoryQuery nodeVisitor, QueryTree queryTree)
- { this.walker = walker;
- this.nodeVisitor = nodeVisitor;
- setQueryTree( queryTree );
- }
-
- /**
- * Sets the query tree for this ordering comparator. Each ordering comparator
- * can be bound to a query tree. The ordering expression list inside
- * that query tree determines the ordering semantics of this comparator.
- * @param queryTree the query tree containing the ordering expression list
- */
- public void setQueryTree(QueryTree queryTree)
- { if( queryTree!=null )
- this.orderings = queryTree.getOrderingExpressions();
- else
- this.orderings = null;
- }
-
- /**
- * Required method for implementing the interface <code>Comparator</code>.
- * This method returns a negative integer, zero, or a positive integer
- * as the first argument is less than, equal to, or greater than the second
- * argument.
- * If this instance is not bound to a query tree or,
- * if the query tree bound to this instance
- * does not have any ordering expression, then argument <code>o1</code>
- * is less than argument <code>o2</code> by definition.
- * @param o1 the first object to be compared
- * @param o2 the second object to be compared
- * @return a negative integer, zero, or a positive integer
- * as the first argument is less than, equal to, or greater than the second
- * @exception ClassCastException if the arguments are not instances of
- * <code>Comparable</code>
- */
- public int compare(Object o1, Object o2)
- { int cmp = -1;
- if( this.orderings!=null )
- for( Iterator i=this.orderings.iterator(); i.hasNext(); )
- { OrderingExpression orderExpr = (OrderingExpression) i.next();
- nodeVisitor.setCurrent( o1 );
- Object result1 = walker.walk( orderExpr, nodeVisitor );
- nodeVisitor.setCurrent( o2 );
- Object result2 = walker.walk( orderExpr, nodeVisitor );
- if( result1!=null ||
- result2!=null )
- { if( !(result1 instanceof Comparable) )
- break;
- else if( !(result2 instanceof Comparable) )
- { cmp = 1;
- break;
- }
- cmp = ((Comparable)result1).compareTo( result2 );
- if( cmp!=0 )
- { if( orderExpr instanceof DescendingOrderingExpression )
- cmp = -cmp;
- break;
- } } }
- return cmp;
- }
-}
\ No newline at end of file
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/QueryImpl.java b/query20/src/java/org/apache/jdo/impl/jdoql/QueryImpl.java
deleted file mode 100644
index 62fa912..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/QueryImpl.java
+++ /dev/null
@@ -1,994 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * QueryImpl.java
- *
- * Created on August 31, 2001
- */
-
-package org.apache.jdo.impl.jdoql;
-
-import java.io.IOException;
-import java.util.*;
-
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Extent;
-import javax.jdo.Transaction;
-import javax.jdo.FetchPlan;
-
-import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLAST;
-import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLC;
-import org.apache.jdo.impl.jdoql.scope.ParameterTable;
-import org.apache.jdo.impl.jdoql.scope.VariableTable;
-import org.apache.jdo.impl.jdoql.tree.Tree;
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.query.QueryResult;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-import org.apache.jdo.store.StoreManager;
-import org.apache.jdo.util.I18NHelper;
-
-
-/**
- * This class implements the JDO query interface
- * (see {@link javax.jdo.Query}).
- *
- * @author Michael Bouschen
- */
-public class QueryImpl
- implements Query
-{
- /** The pm for this query instance. */
- private transient PersistenceManagerInternal pm;
-
- /** The candidate class as specified by setClass. */
- private transient Class candidateClass;
-
- /** The name of the candidate class (Needed for serialization support). */
- private String candidateClassName;
-
- /** The candidates as specified by setCandidates. */
- private transient Object candidates;
-
- /** The import declaration string as specified by declareImports. */
- private String importDeclarations;
-
- /** The parameter declaration string as specified by declareParameters. */
- private String parameterDeclarations;
-
- /** The variable declaration string as specified by declareVariables. */
- private String variableDeclarations;
-
- /** The ordering specification string as specified by setOrdering. */
- private String orderingSpecification;
-
- /** The filter expression string as specified by setFilter. */
- private String filterExpression;
-
- /**
- * The ignoreCache flag as specified by setIgnoreCache. The constructor
- * defaults it to the PM setting.
- */
- private boolean ignoreCache;
-
- /** The internal query representation as compilation result. */
- private transient Tree compiledTree = null;
-
- /**
- * The internal query representation set by the constructor taking a
- * compiled query.
- */
- private Tree queryTree;
-
- /** Represents parameter values. */
- private ParameterTable paramtab;
-
- /** Represents variable values. */
- private VariableTable vartab;
-
- /** Set of open query result instances. */
- private transient Set openQueryResults = new HashSet();
-
- /** I18N support */
- private final static I18NHelper msg =
- I18NHelper.getInstance(QueryImpl.class);
-
- /**
- * Create an empty query instance with no elements.
- */
- public QueryImpl(PersistenceManagerInternal pm)
- {
- // check valid PersistenceManager
- if (pm == null)
- throw new JDOQueryException(msg.msg("EXC_UnboundQuery")); //NOI18N
-
- this.pm = pm;
- this.ignoreCache = pm.getIgnoreCache();
- this.paramtab = new ParameterTable();
- this.vartab = new VariableTable();
- }
-
- /**
- * Create a new Query using elements from another Query. The other Query
- * must have been created by the same JDO implementation. It might be active
- * in a different PersistenceManager or might have been serialized and
- * restored.
- * <P>All of the settings of the other Query are copied to this Query,
- * except for the candidate Collection or Extent.
- * @param compiled another Query from the same JDO implementation
- */
- public QueryImpl(PersistenceManagerInternal pm, Object compiled)
- {
- this(pm);
- if (compiled == null) {
- throw new JDOQueryException(
- msg.msg("EXC_NullQueryInstance")); //NOI18N
- }
-
- if (compiled instanceof QueryImpl) {
- QueryImpl other = (QueryImpl)compiled;
- if (other.candidateClass != null) {
- this.candidateClass = other.candidateClass;
- }
- else if (other.candidateClassName != null) {
- // Support for deserialized query instances:
- // after deserialization other.candidateClass is not set,
- // but other.candidateClassName is set =>
- // use PM algorithm to calculate the candidateClass instance
- try {
- this.candidateClass =
- pm.loadClass(other.candidateClassName, null);
- }
- catch (ClassNotFoundException ex) {
- throw new JDOQueryException(
- msg.msg("EXC_UnknownCandidateClass", //NOI18N
- other.candidateClassName), ex);
- }
- }
- this.importDeclarations = other.importDeclarations;
- this.parameterDeclarations = other.parameterDeclarations;
- this.variableDeclarations = other.variableDeclarations;
- this.orderingSpecification = other.orderingSpecification;
- this.filterExpression = other.filterExpression;
- this.ignoreCache = other.ignoreCache;
- // Set compiled tree to null in order to ensure that this Query
- // instance is compiled prior to execution.
- // A possible optimization might want to reuse compilation results
- // from the other query, but this requires serializing the typeInfo
- // from the JDOQLAST.
- this.compiledTree = null;
- this.queryTree = other.queryTree;
- this.paramtab = other.paramtab;
- this.vartab = other.vartab;
- checkQueryTreeCandidateClass();
- }
- else if (compiled instanceof Tree) {
- this.queryTree = (Tree)compiled;
- // TBD: check compiledTree?
- this.compiledTree = null;
- checkQueryTreeCandidateClass();
- }
- else {
- throw new JDOQueryException(
- msg.msg("EXC_InvalidCompiledQuery", //NOI18N
- compiled.getClass().getName()));
- }
- }
-
- /**
- * Create a new Query specifying the Class of the candidate instances.
- * @param cls the Class of the candidate instances
- */
- public QueryImpl(PersistenceManagerInternal pm, Class cls)
- {
- this(pm);
- setClass(cls);
- }
-
- /**
- * Create a new Query with the candidate Extent; the class
- * is taken from the Extent.
- * @param cln the Extent of candidate instances
- */
- public QueryImpl(PersistenceManagerInternal pm, Extent cln)
- {
- this(pm);
- setClass(cln.getCandidateClass());
- setCandidates(cln);
- }
-
- /**
- * Create a query instance with the candidate class and
- * candidate collection specified.
- * @param cls the Class of the candidate instances.
- * @param cln the Collection of candidate instances.
- */
- public QueryImpl(PersistenceManagerInternal pm, Class cls, Collection cln)
- {
- this(pm);
- setClass(cls);
- setCandidates(cln);
- }
-
- /**
- * Create a new Query with the Class of the candidate instances and Filter.
- * @param cls the Class of results
- * @param filter the filter for candidate instances
- */
- public QueryImpl(PersistenceManagerInternal pm, Class cls, String filter)
- {
- this(pm);
- setClass(cls);
- setFilter(filter);
- }
-
- /**
- * Create a new Query with the Class of the candidate instances,
- * candidate Collection, and filter.
- * @param cls the Class of candidate instances
- * @param cln the Collection of candidate instances
- * @param filter the filter for candidate instances
- */
- public QueryImpl(PersistenceManagerInternal pm, Class cls, Collection cln,
- String filter)
- {
- this(pm);
- setClass(cls);
- setCandidates(cln);
- setFilter(filter);
- }
-
- /**
- * Create a new Query with the
- * candidate Extent and filter; the class
- * is taken from the Extent.
- * @param cln the Extent of candidate instances
- * @param filter the filter for candidate instances
- */
- public QueryImpl(PersistenceManagerInternal pm, Extent cln, String filter)
- {
- this(pm);
- setClass(cln.getCandidateClass());
- setCandidates(cln);
- setFilter(filter);
- }
-
- /** Set the class of the candidate instances of the query.
- * <P>The class specifies the class
- * of the candidates of the query. Elements of the candidate collection
- * that are of the specified class are filtered before being
- * put into the result Collection.
- *
- * @param cls the Class of the candidate instances.
- */
- public void setClass(Class cls)
- {
- synchronized (this.paramtab) {
- this.candidateClass = cls;
- this.compiledTree = null;
- }
- }
-
- /**
- * Set the candidate Extent to query.
- * @param pcs the Candidate Extent.
- */
- public void setCandidates(Extent pcs)
- {
- synchronized (this.paramtab) {
- this.candidates = pcs;
- }
- }
-
- /**
- * Set the candidate Collection to query.
- * @param pcs the Candidate collection.
- */
- public void setCandidates(Collection pcs)
- {
- synchronized (this.paramtab) {
- this.candidates = pcs;
- }
- }
-
- /**
- * Set the filter for the query.
- * @param filter the query filter.
- */
- public void setFilter(String filter)
- {
- synchronized (this.paramtab) {
- this.filterExpression = filter;
- this.compiledTree = null;
- }
- }
-
- /**
- * Set the import statements to be used to identify the fully qualified name
- * of variables or parameters. Parameters and unbound variables might
- * come from a different class from the candidate class, and the names
- * need to be declared in an import statement to eliminate ambiguity.
- * Import statements are specified as a String with semicolon-separated
- * statements.
- * <P>The String parameter to this method follows the syntax of the
- * import statement of the Java language.
- * @param imports import statements separated by semicolons.
- */
- public void declareImports(String imports)
- {
- synchronized (this.paramtab) {
- this.importDeclarations = imports;
- this.compiledTree = null;
- }
- }
-
- /**
- * Declare the list of parameters query execution.
- *
- * The parameter declaration is a String containing one or more query
- * parameter declarations separated with commas. Each parameter named
- * in the parameter declaration must be bound to a value when
- * the query is executed.
- * <P>The String parameter to this method follows the syntax for formal
- * parameters in the Java language.
- * @param parameters the list of parameters separated by commas.
- */
- public void declareParameters(String parameters)
- {
- synchronized (this.paramtab) {
- this.parameterDeclarations = parameters;
- this.compiledTree = null;
- }
- }
-
- /**
- * Declare the unbound variables to be used in the query. Variables
- * might be used in the filter, and these variables must be declared
- * with their type. The unbound variable declaration is a String
- * containing one or more unbound variable declarations separated
- * with semicolons. It follows the syntax for local variables in
- * the Java language.
- * @param variables the variables separated by semicolons.
- */
- public void declareVariables(String variables)
- {
- synchronized (this.paramtab) {
- this.variableDeclarations = variables;
- this.compiledTree = null;
- }
- }
-
- /**
- * Set the ordering specification for the result Collection. The
- * ordering specification is a String containing one or more ordering
- * declarations separated by commas.
- *
- * <P>Each ordering declaration is the name of the field on which
- * to order the results followed by one of the following words:
- * "ascending" or "descending".
- *
- *<P>The field must be declared in the candidate class or must be
- * a navigation expression starting with a field in the candidate class.
- *
- *<P>Valid field types are primitive types except boolean; wrapper types
- * except Boolean; BigDecimal; BigInteger; String; and Date.
- * @param ordering the ordering specification.
- */
- public void setOrdering(String ordering)
- {
- synchronized (this.paramtab) {
- this.orderingSpecification = ordering;
- this.compiledTree = null;
- }
- }
-
- /**
- * Set the ignoreCache option. The default value for this option was
- * set by the PersistenceManagerFactory or the PersistenceManager used
- * to create this Query.
- *
- * The ignoreCache option setting specifies whether the query should execute
- * entirely in the back end, instead of in the cache. If this flag is set
- * to true, an implementation might be able to optimize the query
- * execution by ignoring changed values in the cache. For optimistic
- * transactions, this can dramatically improve query response times.
- * @param ignoreCache the setting of the ignoreCache option.
- */
- public void setIgnoreCache(boolean ignoreCache)
- {
- synchronized (this.paramtab) {
- this.ignoreCache = ignoreCache;
- }
- }
-
- /**
- * Get the ignoreCache option setting.
- * @return the ignoreCache option setting.
- * @see #setIgnoreCache
- */
- public boolean getIgnoreCache()
- {
- return ignoreCache;
- }
-
- /**
- * Verify the elements of the query and provide a hint to the query to
- * prepare and optimize an execution plan.
- */
- public void compile()
- {
- // check valid PersistenceManager
- if (pm == null)
- throw new JDOQueryException(msg.msg("EXC_UnboundQuery")); //NOI18N
-
- synchronized (this.paramtab) {
- if (this.compiledTree == null) {
- JDOQLC jdoqlc = new JDOQLC(pm);
- if (queryTree != null) {
- jdoqlc.setQueryTree(queryTree);
- }
- else {
- // define the query parts including syntax checks
- jdoqlc.setClass(candidateClass);
- jdoqlc.declareImports(importDeclarations);
- jdoqlc.declareParameters(parameterDeclarations);
- jdoqlc.declareVariables(variableDeclarations);
- jdoqlc.setFilter(filterExpression);
- jdoqlc.setOrdering(orderingSpecification);
- }
-
- // call semantic analysis
- JDOQLAST ast = jdoqlc.semanticCheck(paramtab, vartab);
- // call optimizer
- compiledTree = (Tree)jdoqlc.optimize(ast);
- }
- }
- }
-
- /**
- * Execute the query and return the filtered Collection.
- * @return the filtered Collection.
- * @see #executeWithArray(Object[] parameters)
- */
- public Object execute()
- {
- synchronized (this.paramtab) {
- compile();
- pm.assertIsOpen();
- checkTransaction();
- checkCandidates();
- // Each execute call gets its own copy of paramtab and vartab.
- // This allows multiple execution of the same query in parallel.
- ParameterTable params = paramtab.getCopy();
- params.initValueHandling();
- params.checkUnboundParams();
- VariableTable vars = vartab.getCopy();
- vars.initValueHandling();
- StoreManager srm = pm.getStoreManager();
- QueryResult queryResult =
- srm.newQueryResult(new QueryResultHelperImpl(
- pm, compiledTree, candidates, params, vars));
- openQueryResults.add(queryResult);
- return queryResult;
- }
- }
-
- /**
- * Execute the query and return the filtered Collection.
- * @return the filtered Collection.
- * @see #executeWithArray(Object[] parameters)
- * @param p1 the value of the first parameter declared.
- */
- public Object execute(Object p1)
- {
- Object[] params = new Object[1];
- params[0] = p1;
- return executeWithArray(params);
- }
-
- /**
- * Execute the query and return the filtered Collection.
- * @return the filtered Collection.
- * @see #executeWithArray(Object[] parameters)
- * @param p1 the value of the first parameter declared.
- * @param p2 the value of the second parameter declared.
- */
- public Object execute(Object p1, Object p2)
- {
- Object[] params = new Object[2];
- params[0] = p1;
- params[1] = p2;
- return executeWithArray(params);
- }
-
- /**
- * Execute the query and return the filtered Collection.
- * @return the filtered Collection.
- * @see #executeWithArray(Object[] parameters)
- * @param p1 the value of the first parameter declared.
- * @param p2 the value of the second parameter declared.
- * @param p3 the value of the third parameter declared.
- */
- public Object execute(Object p1, Object p2, Object p3)
- {
- Object[] params = new Object[3];
- params[0] = p1;
- params[1] = p2;
- params[2] = p3;
- return executeWithArray(params);
- }
-
- /**
- * Execute the query and return the filtered Collection.
- * @return the filtered Collection.
- * @see #executeWithArray(Object[] parameters)
- * @param parameters the Map containing all of the parameters.
- */
- public Object executeWithMap(Map parameters)
- {
- synchronized (this.paramtab)
- {
- compile();
- pm.assertIsOpen();
- checkTransaction();
- checkCandidates();
- // Each execute call gets its own copy of paramtab and vartab.
- // This allows multiple execution of the same query in parallel.
- ParameterTable params = paramtab.getCopy();
- params.initValueHandling();
- params.setValues(pm, parameters);
- params.checkUnboundParams();
- VariableTable vars = vartab.getCopy();
- vars.initValueHandling();
- StoreManager srm = pm.getStoreManager();
- QueryResult queryResult =
- srm.newQueryResult(new QueryResultHelperImpl(
- pm, compiledTree, candidates, params, vars));
- openQueryResults.add(queryResult);
- return queryResult;
- }
- }
-
- /** Execute the query and return the filtered Collection.
- *
- * <P>The execution of the query obtains the values of the parameters and
- * matches them against the declared parameters in order. The names
- * of the declared parameters are ignored. The type of
- * the declared parameters must match the type of the passed parameters,
- * except that the passed parameters might need to be unwrapped to get
- * their primitive values.
- *
- * <P>The filter, import, declared parameters, declared variables, and
- * ordering statements are verified for consisten1cy.
- *
- * <P>Each element in the candidate Collection is examined to see that it
- * is assignment compatible to the Class of the query. It is then evaluated
- * by the boolean expression of the filter. The element passes the filter
- * if there exist unique values for all variables for which the filter
- * expression evaluates to true.
- * @return the filtered Collection.
- * @param parameters the Object array with all of the parameters.
- */
- public Object executeWithArray(Object[] parameters)
- {
- synchronized (this.paramtab)
- {
- compile();
- pm.assertIsOpen();
- checkTransaction();
- checkCandidates();
- // Each execute call gets its own copy of paramtab and vartab.
- // This allows multiple execution of the same query in parallel.
- ParameterTable params = paramtab.getCopy();
- params.initValueHandling();
- params.setValues(pm, parameters);
- params.checkUnboundParams();
- VariableTable vars = vartab.getCopy();
- vars.initValueHandling();
- StoreManager srm = pm.getStoreManager();
- QueryResult queryResult =
- srm.newQueryResult(new QueryResultHelperImpl(
- pm, compiledTree, candidates, params, vars));
- openQueryResults.add(queryResult);
- return queryResult;
- }
- }
-
- /**
- * Get the PersistenceManager associated with this Query.
- *
- * <P>If this Query was restored from a serialized form, it has no
- * PersistenceManager, and this method returns null.
- * @return the PersistenceManager associated with this Query.
- */
- public PersistenceManager getPersistenceManager()
- {
- return (pm == null) ? null : pm.getCurrentWrapper();
- }
-
- /**
- * Close a query result and release any resources associated with it. The
- * parameter is the return from execute(...) and might have iterators open
- * on it. Iterators associated with the query result are invalidated: they
- * return false to hasNext() and throw NoSuchElementException to next().
- * @param queryResult the result of execute(...) on this Query instance.
- */
- public void close (Object queryResult)
- {
- if (queryResult instanceof QueryResult) {
- openQueryResults.remove(queryResult);
- ((QueryResult)queryResult).close();
- }
- }
-
- /**
- * Close all query results associated with this Query instance, and release
- * all resources associated with them. The query results might have
- * iterators open on them. Iterators associated with the query results are
- * invalidated: they return false to hasNext() and
- * throw NoSuchElementException to next().
- */
- public void closeAll ()
- {
- for(Iterator i = openQueryResults.iterator(); i.hasNext();) {
- QueryResult queryResult = (QueryResult)i.next();
- queryResult.close();
- }
- openQueryResults.clear();
- }
-
- /**
- * Set the grouping expressions, optionally including a "having"
- * clause. When grouping is specified, each result expression
- * must either be an expression contained in the grouping, or an
- * aggregate evaluated once per group.
- *
- * @param group a comma-delimited list of expressions, optionally
- * followed by the "having" keyword and a boolean expression
- * @since 2.0
- */
- public void setGrouping (String group) {
- throw new UnsupportedOperationException(
- "method setGrouping(String) is not yet implemented");
- }
-
- /**
- * Specify that only the first result of the query should be
- * returned, rather than a collection. The execute method will
- * return null if the query result size is 0.
- * @since 2.0
- * @param unique if true, only one element is returned
- */
- public void setUnique (boolean unique) {
- throw new UnsupportedOperationException(
- "method setUnique(boolean) is not yet implemented");
- }
-
- /**
- * Specifies what type of data this query should return. If this
- * is unset or set to <code>null</code>, this query returns
- * instances of the query's candidate class. If set, this query
- * will return expressions, including field values (projections) and
- * aggregate function results.
- * @param data a comma-delimited list of expressions
- * (fields, functions on fields, or aggregate functions)
- * to return from this query
- * @since 2.0
- */
- public void setResult (String data) {
- throw new UnsupportedOperationException(
- "method setResult(String) is not yet implemented");
- }
-
- /**
- * Specify the type of object in which to return each element of
- * the result of invoking {@link #execute} or one of its siblings.
- * If the result is not set or set to null, the result class defaults
- * to the candidate class of the query. If the result consists of one
- * expression, the result class defaults to the type of that expression.
- * If the result consists of more than one expression, the result class
- * defaults to Object[].
- * The result class may be specified to be one of the java.lang classes
- * Character, Boolean, Byte, Short, Integer, Long, Float, Double, String,
- * or Object[]; or one of the java.math classes BigInteger or BigDecimal;
- * or the java.util class Date; or one of the java.sql classes Date,
- * Time, or Timestamp; or a user-defined class.
- * <P>If there are multiple result expressions, the result class
- * must be able to hold all elements of the result specification
- * or a JDOUserException is thrown.
- *<P>If there is only one result expression, the result class must be
- * assignable from the type of the result expression or must be able
- * to hold all elements of the result specification. A single value
- * must be able to be coerced into the specified result class
- * (treating wrapper classes as equivalent to their unwrapped
- * primitive types) or by matching. If the result class does not satisfy
- * these conditions, a JDOUserException is thrown.
- *<P>A constructor of a result class specified in the setResult method
- * will be used if the results specification matches the parameters
- * of the constructor by position and type. If more than one constructor
- * satisfies the requirements, the JDO implementation chooses one of them.
- * If no constructor satisfies the results requirements, or if the result
- * class is specified via the setResultClass method, the following
- * requirements apply:
- * <ul>
- * <li>A user-defined result class must have a no-args constructor and
- * one or more public <code>set</code> or <code>put</code> methods or fields.
- * <li>Each result expression must match one of:
- * <ul>
- * <li>a public field that matches the name of the result expression
- * and is of the type (treating wrapper types equivalent to primitive
- * types) of the result expression;
- * <li>or if no public field matches the name and type, a public
- * <code>set</code method that returns void and matches the name of the
- * result expression and takes a single parameter which is the
- * exact type of the result expression;
- * <li>or if neither of the above applies,a public method must be found
- * with the signature <code>void put(Object, Object)</code>.
- * During processing of the results,
- * the first argument is the name of the result expression and
- * the second argument is the value from the query result.
- * </ul>
- * </ul>
- * Portable result classes do not invoke any persistence behavior
- * during their no-args constructor or <code>set</code methods.
- * @param cls the result class
- * @since 2.0
- */
- public void setResultClass (Class cls) {
- throw new UnsupportedOperationException(
- "method setResultClass(Class) is not yet implemented");
- }
-
- /**
- * Set the range of results to return. The execution of the query is
- * modified to return only a subset of results. If the filter would
- * normally return 100 instances, and fromIncl is set to 50, and
- * toExcl is set to 70, then the first 50 results that would have
- * been returned are skipped, the next 20 results are returned and the
- * remaining 30 results are ignored. An implementation should execute
- * the query such that the range algorithm is done at the data store.
- * @param fromIncl 0-based inclusive start index
- * @param toExcl 0-based exclusive end index, or
- * {@link Long#MAX_VALUE} for no limit.
- * @since 2.0
- */
- public void setRange (long fromIncl, long toExcl) {
- throw new UnsupportedOperationException(
- "method setRange(long. long) is not yet implemented");
- }
-
- /**
- * Set the range of results to return. The parameter is a String
- * containing a comma-separated fromIncl and toExcl. The fromIncl and
- * toExcl can be either String representations of long values, or can
- * be parameters identified with a leading ":". For example,
- * <code>setRange("50, 70");</code> or
- * <code>setRange(":from, :to");</code> or
- * <code>setRange("50, :to");</code>.
- * The execution of the query is
- * modified to return only a subset of results. If the filter would
- * normally return 100 instances, and fromIncl is set to 50, and
- * toExcl is set to 70, then the first 50 results that would have
- * been returned are skipped, the next 20 results are returned and the
- * remaining 30 results are ignored. An implementation should execute
- * the query such that the range algorithm is done at the data store.
- * @param fromInclToExcl comma-separated fromIncl and toExcl values
- * @see #setRange(long, long)
- * @since 2.0
- */
- public void setRange (String fromInclToExcl) {
- throw new UnsupportedOperationException(
- "method setRange(String) is not yet implemented");
- }
-
- /**
- * Add a vendor-specific extension to this query. The key and value
- * are not standard.
- * An implementation must ignore keys that are not recognized.
- * @param key the key of the extension
- * @param value the value of the extension
- * @since 2.0
- */
- public void addExtension (String key, Object value) {
- throw new UnsupportedOperationException(
- "method addExtension(String, Object) is not yet implemented");
- }
-
- /**
- * Set multiple extensions, or use null to clear all extensions.
- * Map keys and values are not standard.
- * An implementation must ignore entries that are not recognized.
- * @param extensions the map of extensions
- * @see #addExtension
- * @since 2.0
- */
- public void setExtensions (Map extensions) {
- throw new UnsupportedOperationException(
- "method setExtensions(Map) is not yet implemented");
- }
-
- /**
- * Returns the <code>FetchPlan</code> used by this
- * <code>Query</code>. Modifications of the returned fetch plan will not
- * cause this query's owning <code>PersistenceManager</code>'s
- * <code>FetchPlan</code> to be modified.
- * @since 2.0
- * @return the fetch plan used by this query
- */
- public FetchPlan getFetchPlan () {
- throw new UnsupportedOperationException(
- "method getFetchPlan() is not yet implemented");
- }
-
- /**
- * Deletes all the instances of the candidate class that pass the
- * filter.
- * @see #deletePersistentAll()
- * @param parameters for the query
- * @return the number of instances of the candidate class that were deleted
- * @since 2.0
- */
- public long deletePersistentAll (Object[] parameters) {
- throw new UnsupportedOperationException(
- "method deletePersistentAll(Object[]) is not yet implemented");
- }
-
- /**
- * Deletes all the instances of the candidate class that pass the
- * filter.
- * @see #deletePersistentAll()
- * @param parameters for the query
- * @return the number of instances of the candidate class that were deleted
- * @since 2.0
- */
- public long deletePersistentAll (Map parameters) {
- throw new UnsupportedOperationException(
- "method deletePersistentAll(Map) is not yet implemented");
- }
-
- /**
- * Deletes all the instances of the candidate class that pass the
- * filter. Returns the number of instances of the candidate
- * class that were deleted, specifically not including the number
- * of dependent and embedded instances.
- * <P>Dirty instances of affected classes in the cache are first
- * flushed to the datastore. Instances in the cache or brought into
- * the cache as a result of executing one of the
- * <code>deletePersistentAll</code>
- * methods undergo life cycle changes as if <code>deletePersistent</code>
- * were called on them.
- * <P>Specifically, if the class of deleted instances implements the
- * delete callback interface, the corresponding callback methods
- * are called on the deleted instances. Similarly, if there are
- * lifecycle listeners registered for delete events on affected
- * classes, the listener is called for each appropriate deleted instance.
- * <P>Before returning control to the application, instances of affected
- * classes in the cache are refreshed to reflect whether they were
- * deleted from the datastore.
- *
- * @return the number of instances of the candidate class that were deleted
- * @since 2.0
- */
- public long deletePersistentAll () {
- throw new UnsupportedOperationException(
- "method deletePersistentAll() is not yet implemented");
- }
-
- /**
- * The unmodifiable flag, when set, disallows further
- * modification of the query, except for specifying the range,
- * result class, and ignoreCache option.
- * The unmodifiable flag can also be set in metadata.
- * @since 2.0
- */
- public void setUnmodifiable() {
- throw new UnsupportedOperationException(
- "method setUnmodifiable() is not yet implemented");
- }
-
- /**
- * The unmodifiable flag, when set, disallows further
- * modification of the query, except for specifying the range,
- * result class, and ignoreCache option.
- * @return the current setting of the flag
- * @since 2.0
- */
- public boolean isUnmodifiable() {
- throw new UnsupportedOperationException(
- "method isUnmodifiable() is not yet implemented");
- }
-
- //========= Internal helper methods ==========
-
- /**
- * This method verifies that if there is no transaction in progress then
- * the NontransactionalRead flag must be set to true.
- */
- private void checkTransaction()
- {
- Transaction tx = pm.currentTransaction();
- if ((!tx.isActive()) & !tx.getNontransactionalRead() )
- throw new JDOQueryException(msg.msg("EXC_NoTransaction")); //NOI18N
- }
-
- /**
- * This method checks a valid candidates setting for this query.
- */
- private void checkCandidates()
- {
- if (candidates == null) {
- if (queryTree != null) {
- candidates = pm.getExtent(queryTree.getCandidateClass(), true);
- }
- else if (candidateClass != null) {
- candidates = pm.getExtent(candidateClass, true);
- }
- else {
- throw new JDOQueryException(msg.msg("EXC_MissingCandidateClass")); //NOI18N
- }
- }
- }
-
- /**
- * This method checks the candidate class of the underlying query
- * tree. If this query instance was created from a query tree, and
- * subsequently serialized and deserialized then The class instance of
- * the candidate class is not set. The class instance of the candidate
- * class is not part of the serialized state of a querty tree; only the
- * name gets stored. In this case the method uses the PM algorithm to
- * calculate the class instance of the candidate class and stores it in
- * the query tree.
- */
- private void checkQueryTreeCandidateClass()
- {
- if (queryTree == null)
- return;
-
- if (queryTree.getCandidateClass() == null) {
- String candidateClassName =
- queryTree.getSerializedCandidateClassName();
- if (candidateClassName != null) {
- try {
- queryTree.setCandidateClass(
- pm.loadClass(candidateClassName, null));
- }
- catch (ClassNotFoundException ex) {
- throw new JDOQueryException(
- msg.msg("EXC_UnknownCandidateClass", //NOI18N
- candidateClassName), ex);
- }
- }
- }
- }
-
- /** Serialization support. */
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException
- {
- in.defaultReadObject();
- this.openQueryResults = new HashSet();
- }
-
- /** Deserialization support. */
- private void writeObject(java.io.ObjectOutputStream out)
- throws IOException
- {
- if (candidateClass != null)
- this.candidateClassName = candidateClass.getName();
- out.defaultWriteObject();
- }
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/QueryResultHelperImpl.java b/query20/src/java/org/apache/jdo/impl/jdoql/QueryResultHelperImpl.java
deleted file mode 100644
index 9e4d51d..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/QueryResultHelperImpl.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * QueryResultHelperImpl.java
- *
- * Created on August 31, 2001
- */
-
-package org.apache.jdo.impl.jdoql;
-
-import java.util.*;
-
-import javax.jdo.Extent;
-import javax.jdo.PersistenceManager;
-import javax.jdo.JDOHelper;
-import javax.jdo.JDOUserException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLAST;
-import org.apache.jdo.impl.jdoql.scope.ParameterTable;
-import org.apache.jdo.impl.jdoql.scope.VariableTable;
-import org.apache.jdo.query.QueryResultHelper;
-import org.apache.jdo.jdoql.tree.Expression;
-import org.apache.jdo.jdoql.tree.QueryTree;
-import org.apache.jdo.jdoql.tree.TreeWalker;
-import org.apache.jdo.jdoql.tree.ValueTable;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-import org.apache.jdo.util.I18NHelper;
-
-/**
- * This class implements the helper interface to support the query
- * execution strategy of the StoreManager. When a query is executed,
- * the filter is parsed. The parsed query, candidate collection or extent,
- * and actual parameters of the execute are stored in the
- * QueryResultHelper.
- *
- * @author Michael Bouschen
- */
-public class QueryResultHelperImpl
- implements QueryResultHelper
-{
- /** The query PM */
- private PersistenceManagerInternal pm;
-
- /** The query tree. */
- private QueryTree queryTree;
-
- /** The candidates for this query evalutaion. */
- private Object candidates;
-
- /** The table of parameter values. */
- private ParameterTable parameters;
-
- /** The table of variable values. */
- private VariableTable variables;
-
- /** The memory query evaluator. */
- private MemoryQuery eval;
-
- /** The tree walker used when applying the filter and do the ordering. */
- private TreeWalker treeWalker;
-
- /** The candidate class taken from the queryTree. */
- private Class candidateClass;
-
- /** The ordering comparator. */
- private OrderingComparator ordering;
-
- /** Logger */
- private static Log logger = LogFactory.getFactory().getInstance(
- "org.apache.jdo.impl.jdoql"); //NOI18N
-
- /** I18N support */
- protected final static I18NHelper msg =
- I18NHelper.getInstance(QueryResultHelperImpl.class);
-
- /**
- *
- */
- public QueryResultHelperImpl(PersistenceManagerInternal pm,
- QueryTree queryTree, Object candidates,
- ParameterTable parameters, VariableTable variables)
- {
- this.pm = pm;
- this.queryTree = queryTree;
- this.candidates = candidates;
- this.parameters = parameters;
- this.variables = variables;
- this.candidateClass = queryTree.getCandidateClass();
- this.eval = new MemoryQuery(pm, parameters, variables);
- this.treeWalker = new TreeWalker();
- this.ordering = new OrderingComparator(treeWalker, eval);
- if (logger.isTraceEnabled()) {
- String repr = null;
- if (queryTree == null)
- repr = "null"; //NOI18N
- else if (queryTree instanceof JDOQLAST)
- repr = ((JDOQLAST)queryTree).treeToString();
- else
- repr = queryTree.toString();
- logger.trace("QueryTree\n" + repr); //NOI18N
- }
- }
-
- /** Return the candidate Collection or Extent specified by
- * the user.
- * @return the candidate Collection or Extent.
- */
- public Object getCandidates()
- {
- return candidates;
- }
-
- /** This method filters the specified collection, removing all elements that
- * are not assignment compatible to the candidate Class specified by the
- * user, and then orders the results according to the ordering expression
- * specified by the user. A new List is returned.
- * @param candidates the collection of instances to be filtered and ordered
- * @return the filtered parameter collection ordered by the ordering
- * expression.
- */
- public List orderCandidates(Collection candidates)
- {
- List list = new ArrayList();
- for (Iterator i = candidates.iterator(); i.hasNext();) {
- Object next = i.next();
- if (candidateClass.isInstance(next))
- list.add(next);
- }
- ordering.setQueryTree(queryTree);
- Collections.sort(list, ordering);
- if (logger.isTraceEnabled())
- logger.trace("orderCandidates -> " + list); //NOI18N
- return list;
- }
-
- /** This method determines whether the specified object is assignment
- * compatible to the candidate Class specified by the user and satisfies
- * the query filter.
- * @return <CODE>true</CODE> if the specified object is of the candidate
- * class and satisfies the query filter; <CODE>false otherwise</CODE>
- * @param obj the candidate object.
- */
- public boolean applyFilter (Object obj)
- {
- boolean satisfies = false;
- if (candidateClass.isInstance(obj)) {
- // check whether obj is bound to the same pm as the one from the query
- checkPM(pm, obj);
- eval.setCurrent(obj);
- Object result = treeWalker.walk(queryTree.getFilter(), eval);
- satisfies = ((result instanceof Boolean) && ((Boolean)result).booleanValue());
- }
- if (logger.isTraceEnabled())
- logger.trace("applyFilter -> " + satisfies + "\t" + obj); //NOI18N
- return satisfies;
- }
-
- /** Return the query tree which is either specified by the user or compiled
- * from a JDOQL query.
- * @return the query tree
- */
- public QueryTree getQueryTree()
- {
- return queryTree;
- }
-
- /** This method returns the parameter values passed by the user
- * in the execute(...) method.
- * @return a ValueTable representing the parameter values
- */
- public ValueTable getParameterValues()
- {
- return parameters;
- }
-
- //========= Helper method ==========
-
- /**
- * Checks the PersistenceManager of the specified value to be
- * identical to the one from the query instance.
- */
- public static void checkPM(PersistenceManagerInternal queryPM, Object value)
- {
- if (value instanceof Collection) {
- // iterate collection and call checkPM for all elements
- for (Iterator i = ((Collection)value).iterator(); i.hasNext();)
- checkPM(queryPM, i.next());
- }
- else if (value instanceof Object[]) {
- // iterate array and call checkPM for all elements
- // No need to check array of primitive types
- Object[] array = (Object[])value;
- for (int i = 0; i < array.length; i++)
- checkPM(queryPM, array[i]);
- }
- else
- {
- PersistenceManager instancePM =
- JDOHelper.getPersistenceManager(value);
- if ((instancePM != null) && !instancePM.equals(queryPM)) {
- // instancePM is NOT the one from the query => exception
- throw new JDOUserException(
- msg.msg("EXC_InstanceBoundToDifferentPM", value)); //NOI18N
- }
- }
- }
-
-}
-
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/ErrorMsg.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/ErrorMsg.java
deleted file mode 100644
index bcda99f..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/ErrorMsg.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * ErrorMsg.java
- *
- * Created on August 28, 2001
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import java.util.ResourceBundle;
-
-import javax.jdo.JDOFatalInternalException;
-import javax.jdo.JDOUnsupportedOptionException;
-
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.util.I18NHelper;
-
-
-/**
- *
- * @author Michael Bouschen
- */
-public class ErrorMsg
-{
- /**
- * The context is included in an error message. It usually defines the query
- * method with the invalid definition (such as declareParameters, setFilter,
- * etc.).
- */
- protected String context = null;
-
- /** I18N support */
- protected final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", ErrorMsg.class.getClassLoader()); //NOI18N
-
- /** Return the current context string */
- public String getContext()
- {
- return context;
- }
-
- /** Set the specified string as the current context string. */
- public void setContext(String name)
- {
- context = name;
- }
-
- /**
- * Indicates an error situation.
- * @param line line number
- * @param col column number
- * @param text error message
- */
- public void error(int line, int col, String text)
- throws JDOQueryException
- {
- if (line > 1) {
- // include line and column info
- Object args[] = {context, new Integer(line), new Integer(col), text};
- throw new JDOQueryException(
- msg.msg("EXC_PositionInfoMsgLineColumn", args)); //NOI18N
- }
- else if (col > 0)
- {
- // include column info
- Object args[] = {context, new Integer(col), text};
- throw new JDOQueryException(
- msg.msg("EXC_PositionInfoMsgColumn", args)); //NOI18N
- }
- else
- {
- Object args[] = {context, text};
- throw new JDOQueryException(
- msg.msg("EXC_PositionInfoMsg", args)); //NOI18N
- }
- }
-
- /**
- * Indicates that a feature is not supported by the current release.
- * @param line line number
- * @param col column number
- * @param text message
- */
- public void unsupported(int line, int col, String text)
- throws JDOUnsupportedOptionException
- {
- if (line > 1)
- {
- // include line and column info
- Object args[] = {context, new Integer(line), new Integer(col), text};
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_PositionInfoMsgLineColumn", args)); //NOI18N
- }
- else if (col > 0)
- {
- // include column info
- Object args[] = {context, new Integer(col), text};
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_PositionInfoMsgColumn", args)); //NOI18N
- }
- else
- {
- Object args[] = {context, text};
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_PositionInfoMsg", args)); //NOI18N
- }
- }
-
- /**
- * Indicates a fatal situation (implementation error).
- * @param text error message
- */
- public void fatal(String text)
- throws JDOFatalInternalException
- {
- throw new JDOFatalInternalException(text);
- }
-
- /**
- * Indicates a fatal situation (implementation error).
- * @param text error message
- */
- public void fatal(String text, Exception nested)
- throws JDOFatalInternalException
- {
- throw new JDOFatalInternalException(text, nested);
- }
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQL.g b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQL.g
deleted file mode 100644
index bd05b5c..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQL.g
+++ /dev/null
@@ -1,843 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * JDOQL.g
- *
- * Created on August 28, 2001
- */
-
-header
-{
- package org.apache.jdo.impl.jdoql.jdoqlc;
-
- import antlr.MismatchedTokenException;
- import antlr.MismatchedCharException;
- import antlr.NoViableAltException;
- import antlr.NoViableAltForCharException;
- import antlr.TokenStreamRecognitionException;
-
- import org.apache.jdo.jdoql.JDOQueryException;
- import org.apache.jdo.impl.jdoql.tree.*;
- import org.apache.jdo.util.I18NHelper;
-}
-
-//===== Lexical Analyzer Class Definitions =====
-
-/**
- * This class defines the lexical analysis for the JDOQL compiler.
- *
- * @author Michael Bouschen
- */
-class JDOQLLexer extends Lexer;
-options
-{
- k = 2;
- exportVocab = JDOQL;
- charVocabulary = '\u0000'..'\uFFFE'; //NOI18N
-}
-
-tokens {
-
- IMPORT = "import" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- IMPORT_ON_DEMAND <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>;
- THIS = "this" <AST=org.apache.jdo.impl.jdoql.tree.ThisExpr>; //NOI18N
- ASCENDING = "ascending" <AST=org.apache.jdo.impl.jdoql.tree.AscendingOrderingExpr>; //NOI18N
- DESCENDING = "descending" <AST=org.apache.jdo.impl.jdoql.tree.DescendingOrderingExpr>; //NOI18N
-
- // types
-
- BOOLEAN = "boolean" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- BYTE = "byte" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- CHAR = "char" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- SHORT = "short" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- INT = "int" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- FLOAT = "float" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- LONG = "long" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
- DOUBLE = "double" <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>; //NOI18N
-
- // literals
-
- NULL = "null" <AST=org.apache.jdo.impl.jdoql.tree.ConstantExpr>; //NOI18N
- TRUE = "true" <AST=org.apache.jdo.impl.jdoql.tree.BooleanLiteralExpr>; //NOI18N
- FALSE = "false" <AST=org.apache.jdo.impl.jdoql.tree.BooleanLiteralExpr>; //NOI18N
-
- // other tokens
-
- EQUAL <AST=org.apache.jdo.impl.jdoql.tree.EqualsExpr>;
- NOT_EQUAL <AST=org.apache.jdo.impl.jdoql.tree.NotEqualsExpr>;
- GE <AST=org.apache.jdo.impl.jdoql.tree.GreaterThanEqualsExpr>;
- GT <AST=org.apache.jdo.impl.jdoql.tree.GreaterThanExpr>;
- LE <AST=org.apache.jdo.impl.jdoql.tree.LessThanEqualsExpr>;
- LT <AST=org.apache.jdo.impl.jdoql.tree.LessThanExpr>;
-
- PLUS <AST=org.apache.jdo.impl.jdoql.tree.PlusExpr>;
- MINUS <AST=org.apache.jdo.impl.jdoql.tree.MinusExpr>;
- STAR <AST=org.apache.jdo.impl.jdoql.tree.TimesExpr>;
- DIV <AST=org.apache.jdo.impl.jdoql.tree.DivideExpr>;
-
- BOR <AST=org.apache.jdo.impl.jdoql.tree.OrExpr>;
- OR <AST=org.apache.jdo.impl.jdoql.tree.ConditionalOrExpr>;
- BAND <AST=org.apache.jdo.impl.jdoql.tree.AndExpr>;
- AND <AST=org.apache.jdo.impl.jdoql.tree.ConditionalAndExpr>;
- LNOT <AST=org.apache.jdo.impl.jdoql.tree.NotExpr>;
- BNOT <AST=org.apache.jdo.impl.jdoql.tree.ComplementExpr>;
-
- INT_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.IntLiteralExpr>;
- LONG_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.IntLiteralExpr>;
- FLOAT_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.FloatLiteralExpr>;
- DOUBLE_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.DoubleLiteralExpr>;
- CHAR_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.CharLiteralExpr>;
- STRING_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.ConstantExpr>;
- IDENT <AST=org.apache.jdo.impl.jdoql.tree.IdentifierExpr>;
-
- DOT <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>;
-
- // lexer only
-
- LPAREN;
- RPAREN;
- COMMA;
- SEMI;
- WS;
- NEWLINE;
- ESC;
- HEX_DIGIT;
- EXPONENT;
- FLOATINGPOINT_SUFFIX;
- UNICODE_ESCAPE;
- UNICODE_CHAR;
-}
-
-{
- /** The error message support class. */
- protected ErrorMsg errorMsg;
-
- /** The width of a tab stop. */
- protected static final int TABSIZE = 4;
-
- /** */
- protected static final int EOF_CHAR = 65535; // = (char) -1 = EOF
-
- /** I18N support. */
- protected static final I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", JDOQLLexer.class.getClassLoader()); //NOI18N
-
- /**
- *
- */
- public void init(ErrorMsg errorMsg)
- {
- this.errorMsg = errorMsg;
- }
-
- /**
- *
- */
- public void tab()
- {
- int column = getColumn();
- int newColumn = (((column-1)/TABSIZE)+1)*TABSIZE+1;
- setColumn(newColumn);
- }
-
- /**
- *
- */
- public void reportError(int line, int column, String s)
- {
- errorMsg.error(line, column, s);
- }
-
- /**
- * Report lexer exception errors caught in nextToken()
- */
- public void reportError(RecognitionException e)
- {
- handleANTLRException(e, errorMsg);
- }
-
- /**
- * Lexer error-reporting function
- */
- public void reportError(String s)
- {
- errorMsg.error(0, 0, s);
- }
-
- /**
- * Lexer warning-reporting function
- */
- public void reportWarning(String s)
- {
- throw new JDOQueryException(s);
- }
-
- /**
- *
- */
- public static void handleANTLRException(ANTLRException ex, ErrorMsg errorMsg)
- {
- if (ex instanceof MismatchedCharException) {
- MismatchedCharException mismatched = (MismatchedCharException)ex;
- if (mismatched.mismatchType == MismatchedCharException.CHAR) {
- if (mismatched.foundChar == EOF_CHAR) {
- errorMsg.error(mismatched.getLine(), mismatched.getColumn(),
- msg.msg("EXC_UnexpectedEOF")); //NOI18N
- }
- else {
- errorMsg.error(mismatched.getLine(), mismatched.getColumn(),
- msg.msg("EXC_ExpectedCharFound", //NOI18N
- String.valueOf((char)mismatched.expecting),
- String.valueOf((char)mismatched.foundChar)));
- }
- return;
- }
- }
- else if (ex instanceof MismatchedTokenException) {
- MismatchedTokenException mismatched = (MismatchedTokenException)ex;
- Token token = mismatched.token;
- if ((mismatched.mismatchType == MismatchedTokenException.TOKEN) &&
- (token != null)) {
- if (token.getType() == Token.EOF_TYPE) {
- errorMsg.error(token.getLine(), token.getColumn(),
- msg.msg("EXC_UnexpectedEOF")); //NOI18N
- }
- else {
- errorMsg.error(token.getLine(), token.getColumn(),
- msg.msg("EXC_SyntaxErrorAt", token.getText())); //NOI18N
- }
- return;
- }
- }
- else if (ex instanceof NoViableAltException) {
- Token token = ((NoViableAltException)ex).token;
- if (token != null) {
- if (token.getType() == Token.EOF_TYPE) {
- errorMsg.error(token.getLine(), token.getColumn(),
- msg.msg("EXC_UnexpectedEOF")); //NOI18N
- }
- else {
- errorMsg.error(token.getLine(), token.getColumn(),
- msg.msg("EXC_UnexpectedToken", token.getText())); //NOI18N
- }
- return;
- }
- }
- else if (ex instanceof NoViableAltForCharException) {
- NoViableAltForCharException noViableAlt = (NoViableAltForCharException)ex;
- errorMsg.error(noViableAlt.getLine(), noViableAlt.getColumn(),
- msg.msg("EXC_UnexpectedChar", String.valueOf((char)noViableAlt.foundChar)));//NOI18N
- }
- else if (ex instanceof TokenStreamRecognitionException) {
- handleANTLRException(((TokenStreamRecognitionException)ex).recog, errorMsg);
- }
-
- // no special handling from aboves matches the exception if this line is reached =>
- // make it a syntax error
- int line = 0;
- int column = 0;
- if (ex instanceof RecognitionException) {
- line = ((RecognitionException)ex).getLine();
- column = ((RecognitionException)ex).getColumn();
- }
- errorMsg.error(line, column, msg.msg("EXC_SyntaxError")); //NOI18N
- }
-}
-
-// OPERATORS
-
-// The following Java operators are included although not supported by JDOQL:
-// ASSIGN, DIV_ASSIGN, PLUS_ASSIGN, INC, MINUS_ASSIGN, DEC, STAR_ASSIGN,
-// SR, SL, BOR_ASSIGN, BAND_ASSIGN
-// The lexer recognizes them, but the parser will result in a syntax error.
-// This gurantees an error message. Othewise the java operator pre-decrement
-// is mapped to two unray minus. Two unray minus are valid in JDOQL, but not
-// indented.
-
-LPAREN : '(' ;
-RPAREN : ')' ;
-COMMA : ',' ;
-//DOT : '.' ;
-ASSIGN : "=" ; //NOI18N
-EQUAL : "==" ; //NOI18N
-LNOT : '!' ;
-BNOT : '~' ;
-NOT_EQUAL : "!=" ; //NOI18N
-DIV : '/' ;
-DIV_ASSIGN : "/=" ; //NOI18N
-PLUS : '+' ;
-PLUS_ASSIGN : "+=" ; //NOI18N
-INC : "++" ; //NOI18N
-MINUS : '-' ;
-MINUS_ASSIGN : "-=" ; //NOI18N
-DEC : "--" ; //NOI18N
-STAR : '*' ;
-STAR_ASSIGN : "*=" ; //NOI18N
-SR : ">>" ; //NOI18N
-GE : ">=" ; //NOI18N
-GT : ">" ; //NOI18N
-SL : "<<" ; //NOI18N
-LE : "<=" ; //NOI18N
-LT : '<' ;
-BOR : '|' ;
-BOR_ASSIGN : "|=" ; //NOI18N
-OR : "||" ; //NOI18N
-BAND : '&' ;
-BAND_ASSIGN : "&=" ; //NOI18N
-AND : "&&" ; //NOI18N
-SEMI : ';' ;
-
-// Whitespace -- ignored
-WS
- : ( ' '
- | '\t'
- | '\f'
- )+
- { _ttype = Token.SKIP; }
- ;
-
-NEWLINE
- : ( "\r\n" //NOI18N
- | '\r'
- | '\n'
- )
- {
- newline();
- _ttype = Token.SKIP;
- }
- ;
-
-// character literals
-CHAR_LITERAL
- : '\'' ( ESC | ~'\'' ) '\''
- ;
-
-// string literals
-STRING_LITERAL
- : '"' ( ESC | ~'"')* '"' //NOI18N
- ;
-
-protected
-ESC
- : '\\'
- ( 'n'
- | 'r'
- | 't'
- | 'b'
- | 'f'
- | '"' //NOI18N
- | '\''
- | '\\'
- | ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
- | ('0'..'3')
- (
- options {
- warnWhenFollowAmbig = false;
- }
- : ('0'..'7')
- (
- options {
- warnWhenFollowAmbig = false;
- }
- : '0'..'7'
- )?
- )?
- | ('4'..'7')
- (
- options {
- warnWhenFollowAmbig = false;
- }
- : ('0'..'9')
- )?
- )
- ;
-
-protected
-HEX_DIGIT
- : ('0'..'9'|'A'..'F'|'a'..'f')
- ;
-
-INT_LITERAL
- {
- boolean isDecimal=false;
- int tokenType = DOUBLE_LITERAL;
- }
- : '.' {_ttype = DOT;}
- (('0'..'9')+ {tokenType = DOUBLE_LITERAL;}
- (EXPONENT)?
- (tokenType = FLOATINGPOINT_SUFFIX)?
- { _ttype = tokenType; })?
- | ( '0' {isDecimal = true;} // special case for just '0'
- ( ('x'|'X')
- (
- options {
- warnWhenFollowAmbig=false;
- }
- : HEX_DIGIT
- )+
- | ('0'..'7')+
- )?
- | ('1'..'9') ('0'..'9')* {isDecimal=true;}
- )
- ( ('l'|'L') { _ttype = LONG_LITERAL; }
- | {isDecimal}?
- {tokenType = DOUBLE_LITERAL;}
- ( '.' ('0'..'9')* (EXPONENT)?
- (tokenType = FLOATINGPOINT_SUFFIX)?
- | EXPONENT (tokenType = FLOATINGPOINT_SUFFIX)?
- | tokenType = FLOATINGPOINT_SUFFIX
- )
- { _ttype = tokenType; }
- )?
- ;
-
-protected
-EXPONENT
- : ('e'|'E') ('+'|'-')? ('0'..'9')+
- ;
-
-protected
-FLOATINGPOINT_SUFFIX returns [int tokenType]
- : 'f' { tokenType = FLOAT_LITERAL; }
- | 'F' { tokenType = FLOAT_LITERAL; }
- | 'd' { tokenType = DOUBLE_LITERAL; }
- | 'D' { tokenType = DOUBLE_LITERAL; }
- ;
-
-IDENT
- options {paraphrase = "an identifier"; testLiterals=true;} //NOI18N
- : ( 'a'..'z'
- | 'A'..'Z'
- | '_'
- | '$'
- | UNICODE_ESCAPE
- | c1:'\u0080'..'\uFFFE'
- {
- if (!Character.isJavaIdentifierStart(c1)) {
- errorMsg.error(getLine(), getColumn(),
- msg.msg("EXC_UnexpectedChar", String.valueOf(c1)));//NOI18N
- }
- }
- )
- ( 'a'..'z'
- | 'A'..'Z'
- | '_'
- | '$'
- | '0'..'9'
- | UNICODE_ESCAPE
- | c2:'\u0080'..'\uFFFE'
- {
- if (!Character.isJavaIdentifierPart(c2)) {
- errorMsg.error(getLine(), getColumn(),
- msg.msg("EXC_UnexpectedChar", String.valueOf(c2)));//NOI18N
- }
- }
- )*
- ;
-
-protected
-UNICODE_ESCAPE
- : '\\' ('u')+ HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
- {
- try {
- String tmp = text.toString();
- char c = (char)Integer.parseInt(tmp.substring(tmp.length() - 4, tmp.length()), 16);
- // problems using ANTLR feature $setText => use generated code
- text.setLength(_begin);
- text.append(new Character(c).toString());
- }
- catch (NumberFormatException ex) {
- errorMsg.fatal(msg.msg("ERR_UnexpectedExceptionUnicode"), ex); //NOI18N
- }
- }
- ;
-
-//===== Parser Class Definitions =====
-
-/**
- * This class defines the syntax analysis (parser) of the JDOQL compiler.
- *
- * @author Michael Bouschen
- */
-class JDOQLParser extends Parser;
-
-options {
- k = 2; // two token lookahead
- exportVocab = JDOQL;
- buildAST = true;
- ASTLabelType = "JDOQLAST"; // NOI18N
-}
-
-tokens
-{
- // "imaginary" tokens, that have no corresponding real input
-
- QUERY_TREE <AST=org.apache.jdo.impl.jdoql.tree.Tree>;
- CANDIDATE_CLASS <AST=org.apache.jdo.impl.jdoql.tree.CandidateClassImpl>;
- PARAMETER_DECL <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>;
- VARIABLE_DECL <AST=org.apache.jdo.impl.jdoql.tree.VariableDecl>;
-
- // operators
- OBJECT_EQUAL <AST=org.apache.jdo.impl.jdoql.tree.EqualsExpr>;
- OBJECT_NOT_EQUAL <AST=org.apache.jdo.impl.jdoql.tree.NotEqualsExpr>;
- COLLECTION_EQUAL <AST=org.apache.jdo.impl.jdoql.tree.EqualsExpr>;
- COLLECTION_NOT_EQUAL <AST=org.apache.jdo.impl.jdoql.tree.NotEqualsExpr>;
- UNARY_MINUS <AST=org.apache.jdo.impl.jdoql.tree.UnaryMinusExpr>;
- UNARY_PLUS <AST=org.apache.jdo.impl.jdoql.tree.UnaryPlusExpr>;
- CONCAT <AST=org.apache.jdo.impl.jdoql.tree.PlusExpr>;
- CAST <AST=org.apache.jdo.impl.jdoql.tree.CastExpr>;
-
- // special dot expressions
- FIELD_ACCESS <AST=org.apache.jdo.impl.jdoql.tree.FieldAccessExpr>;
- STATIC_FIELD_ACCESS <AST=org.apache.jdo.impl.jdoql.tree.FieldAccessExpr>;
- NAVIGATION <AST=org.apache.jdo.impl.jdoql.tree.FieldAccessExpr>;
- CONTAINS <AST=org.apache.jdo.impl.jdoql.tree.ContainsCallExpr>;
- STARTS_WITH <AST=org.apache.jdo.impl.jdoql.tree.StartsWithCallExpr>;
- ENDS_WITH <AST=org.apache.jdo.impl.jdoql.tree.EndsWithCallExpr>;
- IS_EMPTY <AST=org.apache.jdo.impl.jdoql.tree.IsEmptyCallExpr>;
-
- // identifier types
- VARIABLE_ACCESS <AST=org.apache.jdo.impl.jdoql.tree.VariableAccessExpr>;
- PARAMETER_ACCESS <AST=org.apache.jdo.impl.jdoql.tree.ParameterAccessExpr>;
-
- // types
- TYPE <AST=org.apache.jdo.impl.jdoql.tree.TypeImpl>;
-
- // constant value
- CONSTANT <AST=org.apache.jdo.impl.jdoql.tree.ConstantExpr>;
-
- // Query Tree nodes
- BOOLEAN_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.BooleanLiteralExpr>;
- BYTE_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.ByteLiteralExpr>;
- SHORT_LITERAL <AST=org.apache.jdo.impl.jdoql.tree.ShortLiteralExpr>;
-
- // temporary node removed by Semantic
- ARG_LIST <AST=org.apache.jdo.impl.jdoql.tree.NodeImpl>;
-}
-
-{
- /** The error message support class. */
- protected ErrorMsg errorMsg;
-
- /** I18N support. */
- protected final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", JDOQLParser.class.getClassLoader()); //NOI18N
-
- /**
- *
- */
- public void init(ErrorMsg errorMsg)
- {
- this.errorMsg = errorMsg;
- }
-
- /**
- * ANTLR method called when an error was detected.
- */
- public void reportError(RecognitionException ex)
- {
- JDOQLLexer.handleANTLRException(ex, errorMsg);
- }
-
- /**
- * ANTLR method called when an error was detected.
- */
- public void reportError(String s)
- {
- errorMsg.error(0, 0, s);
- }
-
- /**
- *
- */
- public void reportError(int line, int column, String s)
- {
- errorMsg.error(line, column, s);
- }
-
- /**
- * ANTLR method called when a warning was detected.
- */
- public void reportWarning(String s)
- {
- throw new JDOQueryException(s);
- }
-
-}
-
-// ----------------------------------
-// rules: import declaration
-// ----------------------------------
-
-parseImports
-{
- errorMsg.setContext("declareImports"); //NOI18N
-}
- : ( declareImport ( SEMI! declareImport )* )? ( SEMI! )? EOF!
- ;
-
-declareImport
- : i:IMPORT^ q:qualifiedNameStar
- {
- if (#q.getType() == STAR) {
- #i.setType(IMPORT_ON_DEMAND);
- #i.setFirstChild(#q.getFirstChild());
- }
- }
- ;
-
-// ----------------------------------
-// rules: parameter declaration
-// ----------------------------------
-
-parseParameters
-{
- errorMsg.setContext("declareParameters"); //NOI18N
-}
- : ( declareParameter ( COMMA! declareParameter )* )? ( COMMA! )? EOF!
- ;
-
-declareParameter
- : type IDENT
- {
- ParameterDecl paramDecl =
- new ParameterDecl(new Token(PARAMETER_DECL,"parameterDecl")); //NOI18N
- paramDecl.setFirstChild(#declareParameter);
- #declareParameter = paramDecl;
- }
- ;
-
-// ----------------------------------
-// rules: variables declaration
-// ----------------------------------
-
-parseVariables
-{
- errorMsg.setContext("declareVariables"); //NOI18N
-}
- : ( declareVariable ( SEMI! declareVariable )* )? ( SEMI! )? EOF!
- ;
-
-declareVariable
- : type IDENT
- {
- VariableDecl variableDecl =
- new VariableDecl(new Token(VARIABLE_DECL,"variableDecl")); //NOI18N
- variableDecl.setFirstChild(#declareVariable);
- #declareVariable = variableDecl;
- }
- ;
-
-// ----------------------------------
-// rules ordering specification
-// ----------------------------------
-
-parseOrdering
-{
- errorMsg.setContext("setOrdering"); //NOI18N
-}
- : ( orderSpec ( COMMA! orderSpec )* )? ( COMMA! )? EOF!
- ;
-
-orderSpec
- : e:expression ( ASCENDING^ | DESCENDING^ )
- ;
-
-// ----------------------------------
-// rules filer expression
-// ----------------------------------
-
-parseFilter
-{
- errorMsg.setContext("setFilter"); //NOI18N
-}
- : e:expression EOF!
- ;
-
-// This is a list of expressions.
-expressionList
- : expression (COMMA! expression)*
- ;
-
-expression
- : invalidExpression
- ;
-
-// assignment expression: not supported => syntax error
-invalidExpression
- : conditionalOrExpression
- (
- op:invalidOperator
- {
- errorMsg.error(#op.getLine(), #op.getColumn(),
- msg.msg("EXC_UnexpectedToken", #op.getText())); //NOI18N
- }
- invalidExpression
- )?
- ;
-
-invalidOperator
- : ASSIGN | PLUS_ASSIGN | MINUS_ASSIGN | STAR_ASSIGN |
- DIV_ASSIGN | BAND_ASSIGN | BOR_ASSIGN | SR | SL
- ;
-
-// conditional or ||
-conditionalOrExpression
- : conditionalAndExpression (OR^ conditionalAndExpression)*
- ;
-
-// conditional and &&
-conditionalAndExpression
- : inclusiveOrExpression (AND^ inclusiveOrExpression)*
- ;
-
-// bitwise or logical or |
-inclusiveOrExpression
- : andExpression (BOR^ andExpression)*
- ;
-
-// bitwise or logical and &
-andExpression
- : equalityExpression (BAND^ equalityExpression)*
- ;
-
-// equality/inequality ==/!=
-equalityExpression
- : relationalExpression ((NOT_EQUAL^ | EQUAL^) relationalExpression)*
- ;
-// boolean relational expressions
-relationalExpression
- : additiveExpression
- ( ( LT^
- | GT^
- | LE^
- | GE^
- )
- additiveExpression
- )*
- ;
-
-// binary addition/subtraction
-additiveExpression
- : multiplicativeExpression ((PLUS^ | MINUS^) multiplicativeExpression)*
- ;
-// multiplication/division/modulo
-multiplicativeExpression
- : unaryExpression ((STAR^ | DIV^ ) unaryExpression)*
- ;
-
-unaryExpression
- : MINUS^ {#MINUS.setType(UNARY_MINUS);} unaryExpression
- | PLUS^ {#PLUS.setType(UNARY_PLUS);} unaryExpression
- | i:INC^ unaryExpression
- {
- errorMsg.error(#i.getLine(), #i.getColumn(),
- msg.msg("EXC_UnexpectedToken", #i.getText())); //NOI18N
- }
- | d:DEC^ unaryExpression
- {
- errorMsg.error(#d.getLine(), #d.getColumn(),
- msg.msg("EXC_UnexpectedToken", #d.getText())); //NOI18N
- }
- | unaryExpressionNotPlusMinus
- ;
-
-unaryExpressionNotPlusMinus
- : BNOT^ unaryExpression
- | LNOT^ unaryExpression
- | ( LPAREN type RPAREN unaryExpression )=>
- lp:LPAREN^ {#lp.setType(CAST);} type RPAREN! unaryExpression
- | postfixExpression
- ;
-
-// qualified names, field access, method invocation
-postfixExpression
- : primary
- ( DOT^ IDENT ( argList )? )*
- ;
-
-argList
- : LPAREN!
- ( expressionList
- {
- NodeImpl argListRoot = new NodeImpl(new Token(ARG_LIST,"argList")); //NOI18N
- argListRoot.setFirstChild(#argList);
- #argList = argListRoot;
- }
- | /* empty list */
- {
- NodeImpl argListRoot = new NodeImpl(new Token(ARG_LIST,"argList")); //NOI18N
- #argList = argListRoot;
- }
- )
- RPAREN!
- ;
-
-// the basic element of an expression
-primary
- : IDENT
- | literal
- | THIS
- | LPAREN! expression RPAREN!
- ;
-
-literal
- : TRUE
- | FALSE
- | INT_LITERAL
- | LONG_LITERAL
- | FLOAT_LITERAL
- | DOUBLE_LITERAL
- | c:CHAR_LITERAL
- {
- // strip quotes from the token text
- String text = #c.getText();
- #c.setText(text.substring(1,text.length()-1));
- }
- | s:STRING_LITERAL
- {
- // strip quotes from the token text
- String text = #s.getText();
- #s.setText(text.substring(1,text.length()-1));
- }
- | NULL
- ;
-
-qualifiedName
- : IDENT ( DOT^ IDENT )*
- ;
-
-qualifiedNameStar
- : IDENT ( DOT^ IDENT )* ( DOT! STAR^ )?
- ;
-
-type
- : qualifiedName
- | primitiveType
- ;
-
-// The primitive types.
-primitiveType
- : BOOLEAN
- | BYTE
- | CHAR
- | SHORT
- | INT
- | FLOAT
- | LONG
- | DOUBLE
- ;
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLAST.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLAST.java
deleted file mode 100644
index c3840fd..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLAST.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * JDOQLAST.java
- *
- * Created on August 28, 2001
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import org.apache.jdo.model.java.JavaType;
-
-import antlr.Token;
-import antlr.CommonAST;
-import antlr.collections.AST;
-
-
-/**
- * This class represents a node in the intermediate representation (AST)
- * used by the query compiler.
- * It provides
- * - line info
- * - column info
- * - type info (JavaType instance): the semantic analysis calculates
- * the type of an expression and adds this info to each node.
- * @author Michael Bouschen
- */
-public class JDOQLAST
- extends CommonAST
- implements Cloneable
-{
- /** The line info */
- protected int line = 0;
-
- /** The column info */
- protected int column = 0;
-
- /** The type info */
- protected transient JavaType typeInfo;
-
- /** */
- public JDOQLAST()
- {
- }
-
- /** */
- public JDOQLAST(int type, String text, JavaType typeInfo)
- {
- initialize(type, text, typeInfo);
- }
-
- /** */
- public JDOQLAST(JDOQLAST ast)
- {
- initialize(ast);
- }
-
- /** */
- public void initialize(Token t)
- {
- setType(t.getType());
- setText(t.getText());
- setLine(t.getLine());
- setColumn(t.getColumn());
- }
-
- /** */
- public void initialize(int type, String text, JavaType typeInfo)
- {
- setType(type);
- setText(text);
- setTypeInfo(typeInfo);
- }
-
- /** */
- public void initialize(AST _ast)
- {
- JDOQLAST ast = (JDOQLAST)_ast;
- setType(ast.getType());
- setText(ast.getText());
- setLine(ast.getLine());
- setColumn(ast.getColumn());
- setTypeInfo(ast.getTypeInfo());
- }
-
- /** */
- public void setLine(int line)
- {
- this.line = line;
- }
-
- /** */
- public int getLine()
- {
- return line;
- }
-
- /** */
- public void setColumn(int column)
- {
- this.column = column;
- }
-
- /** */
- public int getColumn()
- {
- return column;
- }
-
- /** */
- public void setTypeInfo(JavaType typeInfo)
- {
- this.typeInfo = typeInfo;
- }
-
- /** */
- public JavaType getTypeInfo()
- {
- return typeInfo;
- }
-
- /**
- * Returns a string representation of this JDOQLAST.
- * @return a string representation of the object.
- */
- public String toString()
- {
- JavaType typeInfo = getTypeInfo();
- StringBuffer repr = new StringBuffer();
- // token text
- repr.append((getText() == null ? "null" : getText())); //NOI18N
- repr.append(" ["); //NOI18N
- // token type
- repr.append(getType());
- // line/column info
- repr.append(", ("); //NOI18N
- repr.append(getLine() + "/" + getColumn()); //NOI18N
- repr.append("), "); //NOI18N
- // type info
- repr.append(typeInfo);
- repr.append(", "); //NOI18N
- // node class info
- String className = getClass().getName();
- int index = className.lastIndexOf('.');
- if (index > -1)
- className = className.substring(index+1);
- repr.append(className);
- repr.append("]"); //NOI18N
- return repr.toString();
- }
-
- /**
- * Returns a string representation of this JDOQLAST including
- * all child nodes.
- * @return a string representation of this JDOQLAST including all
- * child nodes.
- */
- public String treeToString()
- {
- StringBuffer repr = new StringBuffer();
- treeToString(0, repr);
- return repr.toString();
- }
-
- /**
- * Creates and returns a copy of this object.
- * The returned JDOQLAST shares the same state as this object, meaning
- * the fields type, text, line, column, and typeInfo have the same values.
- * But it is not bound to any tree structure, thus the child is null
- * and the sibling is null.
- * @return a clone of this instance.
- */
- protected Object clone()
- throws CloneNotSupportedException
- {
- JDOQLAST clone = (JDOQLAST)super.clone();
- clone.setFirstChild(null);
- clone.setNextSibling(null);
- return clone;
- }
-
- // Internal helper method
-
- /** */
- private void treeToString(int indent, StringBuffer repr)
- {
- // indent
- for (int i = 0; i < indent; i++) {
- repr.append(" "); //NOI18N
- }
-
- // append string representation of current node
- repr.append(toString());
-
- // child nodes in new line
- repr.append("\n");
-
- // append string representation(s) of child nodes
- for (JDOQLAST node = (JDOQLAST)this.getFirstChild();
- node != null;
- node = (JDOQLAST)node.getNextSibling()) {
- node.treeToString(indent+1, repr);
- }
- }
-}
-
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLASTFactory.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLASTFactory.java
deleted file mode 100644
index 28c2d9c..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLASTFactory.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * JDOQLASTFactory.java
- *
- * Created on September 3, 2001
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import antlr.collections.AST;
-import antlr.ASTFactory;
-
-import javax.jdo.JDOFatalInternalException;
-
-import org.apache.jdo.util.I18NHelper;
-
-/**
- * Factory to create and connect JDOQLAST nodes.
- *
- * @author Michael Bouschen
- */
-public class JDOQLASTFactory
- extends ASTFactory
-{
- /** The singleton JDOQLASTFactory instance. */
- private static JDOQLASTFactory factory = new JDOQLASTFactory();
-
- /** I18N support. */
- private final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", JDOQLASTFactory.class.getClassLoader()); //NOI18N
-
- /**
- * Get an instance of JDOQLASTFactory.
- * @return an instance of JDOQLASTFactory
- */
- public static JDOQLASTFactory getInstance()
- {
- return factory;
- }
-
- /**
- *
- */
- protected JDOQLASTFactory()
- {
- this.theASTNodeTypeClass = JDOQLAST.class;
- this.theASTNodeType = this.theASTNodeTypeClass.getName();
- }
-
- /**
- *
- */
- public AST create()
- {
- return new JDOQLAST();
- }
-
- /**
- *
- */
- public AST create(AST tr)
- {
- return create((JDOQLAST)tr);
- }
-
- /**
- *
- */
- public JDOQLAST create(JDOQLAST tr)
- {
- try {
- return (tr==null) ? null : (JDOQLAST)tr.clone();
- }
- catch(CloneNotSupportedException ex) {
- throw new JDOFatalInternalException(
- msg.msg("ERR_UnexpectedExceptionClone"), ex); //NOI18N
- }
- }
-}
-
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLC.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLC.java
deleted file mode 100644
index 465753c..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/JDOQLC.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * JDOQLC.java
- *
- * Created on August 28, 2001
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Collection;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.jdo.impl.jdoql.scope.ParameterTable;
-import org.apache.jdo.impl.jdoql.scope.VariableTable;
-import org.apache.jdo.impl.jdoql.tree.Tree;
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-import org.apache.jdo.util.I18NHelper;
-
-import antlr.TokenBuffer;
-import antlr.ANTLRException;
-
-/**
- * This class controls the JDOQL compiler passes.
- *
- * @author Michael Bouschen
- */
-public class JDOQLC
-{
- /** The persistence manager of the query instance. */
- protected PersistenceManagerInternal pm;
-
- /** Type support. */
- protected TypeSupport typeSupport;
-
- /** Error message helper. */
- protected ErrorMsg errorMsg;
-
- /** The candidate class. */
- protected Class candidateClass;
-
- /** The AST representing the filter expression. */
- protected JDOQLAST filterAST = null;
-
- /** The AST representing the import declarations. */
- protected JDOQLAST importsAST = null;
-
- /** The AST representing the parameter declarations. */
- protected JDOQLAST paramsAST = null;
-
- /** The AST representing the variable declarations. */
- protected JDOQLAST varsAST = null;
-
- /** The AST representing the ordering specification. */
- protected JDOQLAST orderingAST = null;
-
- /** The complete query tree. */
- protected JDOQLAST queryTree = null;
-
- /** I18N support */
- private final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", //NOI18N
- JDOQLC.class.getClassLoader());
-
- /** Logger */
- private static Log logger = LogFactory.getFactory().getInstance(
- "org.apache.jdo.impl.jdoql.jdoqlc"); //NOI18N
-
- /**
- *
- */
- public JDOQLC(PersistenceManagerInternal pm)
- {
- this.pm = pm;
- this.typeSupport = new TypeSupport();
- this.errorMsg = new ErrorMsg();
- }
-
- /**
- *
- */
- public void setClass(Class candidateClass)
- {
- // Method semanticCheck checks for valid candidateClass
- this.candidateClass = candidateClass;
- }
-
- /**
- *
- */
- public void declareImports(String imports)
- {
- if (imports == null) {
- importsAST = null;
- return;
- }
-
- try {
- JDOQLParser parser = createStringParser(imports);
- parser.parseImports();
- importsAST = (JDOQLAST)parser.getAST();
- }
- catch (ANTLRException ex) {
- JDOQLLexer.handleANTLRException(ex, errorMsg);
- }
- }
-
- /**
- *
- */
- public void declareParameters(String parameters)
- {
- if (parameters == null) {
- paramsAST = null;
- return;
- }
-
- try {
- JDOQLParser parser = createStringParser(parameters);
- parser.parseParameters();
- paramsAST = (JDOQLAST)parser.getAST();
- }
- catch (ANTLRException ex) {
- JDOQLLexer.handleANTLRException(ex, errorMsg);
- }
- }
-
- /**
- *
- */
- public void declareVariables(String variables)
- {
- if (variables == null) {
- varsAST = null;
- return;
- }
-
- try {
- JDOQLParser parser = createStringParser(variables);
- parser.parseVariables();
- varsAST = (JDOQLAST)parser.getAST();
- }
- catch (ANTLRException ex) {
- JDOQLLexer.handleANTLRException(ex, errorMsg);
- }
- }
-
- /**
- *
- */
- public void setOrdering(String ordering)
- {
- if (ordering == null) {
- orderingAST = null;
- return;
- }
-
- try {
- JDOQLParser parser = createStringParser(ordering);
- parser.parseOrdering();
- orderingAST = (JDOQLAST)parser.getAST();
- }
- catch (ANTLRException ex) {
- JDOQLLexer.handleANTLRException(ex, errorMsg);
- }
- }
-
- /**
- *
- */
- public void setFilter(String filter)
- {
- if ((filter == null) || (filter.trim().length() == 0)) {
- // If there is no filter specified use "true" as filter.
- // This is the case if
- // - setFilter is not called at all (filter == null)
- // - the filter is empty or contians whitespecace only.
- // Internally the filter has to be specified,
- // otherwise semantic analysis has problems with empty AST.
- filter = "true"; //NOI18N
- }
-
- try {
- JDOQLParser parser = createStringParser(filter);
- parser.parseFilter();
- filterAST = (JDOQLAST)parser.getAST();
- }
- catch (ANTLRException ex) {
- JDOQLLexer.handleANTLRException(ex, errorMsg);
- }
- }
-
- /**
- *
- */
- public void setQueryTree(JDOQLAST queryTree)
- {
- this.queryTree = queryTree;
- }
-
- /**
- *
- */
- public JDOQLAST semanticCheck(ParameterTable paramtab, VariableTable vartab)
- {
- boolean trace = logger.isTraceEnabled();
- ClassLoader applClassLoader = null;
-
- Semantic semantic = new Semantic();
- semantic.init(typeSupport, paramtab, vartab, errorMsg);
- semantic.setASTFactory(JDOQLASTFactory.getInstance());
-
- if (queryTree == null) {
- // check candidate class
- if (candidateClass == null) {
- throw new JDOQueryException(
- msg.msg("EXC_MissingCandidateClass")); //NOI18N
- }
- applClassLoader = candidateClass.getClassLoader();
- // create complete tree representation
- queryTree = semantic.createQueryTree(
- candidateClass, importsAST, paramsAST,
- varsAST, orderingAST, filterAST);
- }
- else {
- Tree tree = (Tree)queryTree;
- Class clazz = tree.getCandidateClass();
- if (clazz != null)
- applClassLoader = clazz.getClassLoader();
- tree.initANTLRAST();
- }
-
- // set the candidateClass class loader
- typeSupport.initApplicationJavaModel(applClassLoader);
-
- if (trace)
- logger.trace("AST\n" + queryTree.treeToString()); //NOI18N
-
- try {
- if (logger.isDebugEnabled())
- logger.debug("Start semantic analysis"); //NOI18N
- semantic.query(queryTree);
- queryTree = (JDOQLAST)semantic.getAST();
- if (trace)
- logger.trace("Typed AST\n" + queryTree.treeToString()); //NOI18N
- }
- catch (ANTLRException ex) {
- ex.printStackTrace();
- errorMsg.fatal(
- msg.msg("ERR_UnexpectedExceptionSemantic"), ex); //NOI18N
- }
- return queryTree;
- }
-
- /**
- *
- */
- public JDOQLAST optimize(JDOQLAST tree)
- {
- // Do not include parameters into optimization => paramtab == null
- return optimize(tree, null);
- }
-
- /**
- *
- */
- public JDOQLAST optimize(JDOQLAST tree, ParameterTable paramtab)
- {
- Tree ast = null;
- Optimizer optimizer= new Optimizer();
- optimizer.init(pm, paramtab, errorMsg);
- optimizer.setASTFactory(JDOQLASTFactory.getInstance());
-
- try {
- if (logger.isDebugEnabled())
- logger.debug("START optimizer"); //NOI18N
- optimizer.query(tree);
- ast = (Tree)optimizer.getAST();
- if (logger.isTraceEnabled())
- logger.trace("Optimized AST\n" + queryTree.treeToString()); //NOI18N
- }
- catch (ANTLRException ex) {
- ex.printStackTrace();
- errorMsg.fatal(
- msg.msg("ERR_UnexpectedExceptionOptimizer"), ex); //NOI18N
- }
- return ast;
- }
-
- //========= Internal helper methods ==========
-
- /**
- *
- */
- private JDOQLParser createStringParser(String text)
- {
- Reader in = new StringReader(text);
- JDOQLLexer lexer = new JDOQLLexer(in);
- lexer.init(errorMsg);
- TokenBuffer buffer = new TokenBuffer(lexer);
- JDOQLParser parser = new JDOQLParser(buffer);
- parser.init(errorMsg);
- parser.setASTFactory(JDOQLASTFactory.getInstance());
- return parser;
- }
-
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Optimizer.g b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Optimizer.g
deleted file mode 100644
index 13f7546..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Optimizer.g
+++ /dev/null
@@ -1,1313 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Optimizer.g
- *
- * Created on August 28, 2001
- */
-
-header
-{
- package org.apache.jdo.impl.jdoql.jdoqlc;
-
- import java.util.Collection;
-
- import java.math.BigDecimal;
- import java.math.BigInteger;
-
- import java.lang.reflect.Field;
- import java.security.AccessController;
- import java.security.PrivilegedAction;
-
- import org.apache.jdo.model.java.JavaField;
- import org.apache.jdo.model.java.JavaType;
- import org.apache.jdo.impl.model.java.PredefinedType;
- import org.apache.jdo.impl.model.java.WrapperClassType;
-
- import org.apache.jdo.pm.PersistenceManagerInternal;
- import org.apache.jdo.util.I18NHelper;
- import org.apache.jdo.impl.jdoql.tree.*;
- import org.apache.jdo.impl.jdoql.scope.ParameterTable;
-}
-
-/**
- * This class defines the optimizer pass of the JDOQL compiler.
- * It takes the typed AST as produced by the smenatic analysis and
- * converts it into a simpler but equivalent typed AST.
- *
- * @author Michael Bouschen
- */
-class Optimizer extends TreeParser;
-
-options
-{
- importVocab = JDOQL;
- buildAST = true;
- defaultErrorHandler = false;
- ASTLabelType = "JDOQLAST"; //NOI18N
-}
-
-{
- /** The persistence manager of the query instance. */
- protected PersistenceManagerInternal pm;
-
- /** The error message support class. */
- protected ErrorMsg errorMsg;
-
- /** The query parameter table */
- protected ParameterTable paramtab;
-
- /** Flag indicating whether query parameers should be included. */
- protected boolean optimizeParameters;
-
- /** I18N support */
- protected final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", Optimizer.class.getClassLoader()); //NOI18N
-
- /**
- *
- */
- public void init(PersistenceManagerInternal pm,
- ParameterTable paramtab, ErrorMsg errorMsg)
- {
- this.pm = pm;
- this.errorMsg = errorMsg;
- this.paramtab = paramtab;
- this.optimizeParameters = (paramtab != null);
- }
-
- /**
- *
- */
- public void reportError(RecognitionException ex) {
- errorMsg.fatal(msg.msg("ERR_OptimizerError", ex)); //NOI18N
- }
-
- /**
- *
- */
- public void reportError(String s) {
- errorMsg.fatal(msg.msg("ERR_OptimizerError") + s); //NOI18N
- }
-
- /**
- * Converts the string argument into a single char.
- */
- protected static char parseChar(String text)
- {
- char first = text.charAt(0);
- if (first == '\\') {
- //found escape => check the next char
- char second = text.charAt(1);
- switch (second)
- {
- case 'n': return '\n';
- case 'r': return '\r';
- case 't': return '\t';
- case 'b': return '\b';
- case 'f': return '\f';
- case 'u':
- // unicode spec
- return (char)Integer.parseInt(text.substring(2, text.length()), 16);
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- // octal spec
- return (char)Integer.parseInt(text.substring(1, text.length()), 8);
- default : return second;
- }
- }
- return first;
- }
-
- /**
- * Check an AND operation (BAND, AND) for constant operands
- * that could be optimized.
- * @param op the AND operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkAnd(JDOQLAST op, JDOQLAST left, JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if (isBooleanValueAST(left)) {
- ast = handleValueAndExpr(op, ((ConstantExpr)left).getValue(), right);
- }
- else if (isBooleanValueAST(right)) {
- ast = handleValueAndExpr(op, ((ConstantExpr)right).getValue(), left);
- }
- return ast;
- }
-
- /**
- * Check an OR operation (BOR, OR) for constant operands
- * that could be optimized.
- * @param op the OR operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkOr(JDOQLAST op, JDOQLAST left, JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if (isBooleanValueAST(left)) {
- ast = handleValueOrExpr(op, ((ConstantExpr)left).getValue(), right);
- }
- else if (isBooleanValueAST(right)) {
- ast = handleValueOrExpr(op, ((ConstantExpr)right).getValue(), left);
- }
- return ast;
- }
-
- /**
- * Check a equality operation (EQUAL, NOT_EQUAL) for constant operands
- * that could be optimized.
- * @param op the equality operator
- * @param left the left operand
- * @param right the right operand
- * @param negate true for not equal operation, false otherwise
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkEqualityOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right, boolean negate)
- {
- JDOQLAST ast = op;
-
- // case <CONSTANT> <op> <CONSTANT>
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- ast = handleValueEqValue(op, left, right, negate);
- }
- // case <boolean CONSTANT> <op> <expr>
- else if (isBooleanValueAST(left)) {
- ast = handleBooleanValueEqExpr(op, ((ConstantExpr)left).getValue(),
- right, negate);
- }
- // case <expr> <op> <boolean CONSTANT>
- else if (isBooleanValueAST(right)) {
- ast = handleBooleanValueEqExpr(op, ((ConstantExpr)right).getValue(),
- left, negate);
- }
- return ast;
- }
-
- /**
- * Check a object equality operation (OBJECT_EQUAL, OBJECT_NOT_EQUAL)
- * for constant operands that could be optimized.
- * @param op the object equality operator
- * @param left the left operand
- * @param right the right operand
- * @param negate true for not equal operation, false otherwise
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkObjectEqualityOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right, boolean negate)
- {
- JDOQLAST ast = op;
-
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- ast = handleValueEqValue(op, left, right, negate);
- }
- return ast;
- }
-
- /**
- * Check a collection equality operation (COLLECTION_EQUAL,
- * COLLECTION_NOT_EQUAL) for constant operands that could be optimized.
- * @param op the collection equality operator
- * @param left the left operand
- * @param right the right operand
- * @param negate true for not equal operation, false otherwise
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkCollectionEqualityOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right, boolean negate)
- {
- JDOQLAST ast = op;
- boolean isLeftConstant = (left.getType() == CONSTANT);
- boolean isRightConstant = (right.getType() == CONSTANT);
-
- if (isLeftConstant && isRightConstant) {
- ast = handleValueEqValue(op, left, right, negate);
- }
- return ast;
- }
-
- /**
- * Check a logical not operation (LNOT) for a constant operand
- * that could be optimized.
- * @param op the logical not operator
- * @param arg the operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkLogicalNotOp(JDOQLAST op, JDOQLAST arg)
- {
- JDOQLAST ast = op;
-
- if (arg.getType() == CONSTANT) {
- // !value may be calculated at compile time.
- Object valueObj = ((ConstantExpr)arg).getValue();
- Boolean value = (valueObj instanceof Boolean) ?
- new Boolean(!((Boolean)valueObj).booleanValue()) :
- Boolean.TRUE;
- ast = ConstantExpr.newConstant(value);
- ast.setType(CONSTANT);
- ast.setText(value.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Check a binary plus operation (PLUS) for constant operands
- * that could be optimized.
- * @param op the plus operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkBinaryPlusOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- Object leftValue = ((ConstantExpr)left).getValue();
- Object rightValue = ((ConstantExpr)right).getValue();
- Object value = null;
- if (leftValue == null)
- value = rightValue;
- else if (rightValue == null)
- value = leftValue;
- else {
- JavaType type = op.getTypeInfo();
-
- if (type.isWrapperClass())
- type = ((WrapperClassType)type).getWrappedPrimitiveType();
-
- if (type.equals(PredefinedType.intType))
- value = new Integer(((Number)leftValue).intValue() +
- ((Number)rightValue).intValue());
- else if (type.equals(PredefinedType.longType))
- value = new Long(((Number)leftValue).longValue() +
- ((Number)rightValue).longValue());
- else if (type.equals(PredefinedType.floatType))
- value = new Float(((Number)leftValue).floatValue() +
- ((Number)rightValue).floatValue());
- else if (type.equals(PredefinedType.doubleType))
- value = new Double(((Number)leftValue).doubleValue() +
- ((Number)rightValue).doubleValue());
- else if (type.equals(PredefinedType.bigDecimalType))
- value = getBigDecimalValue(leftValue).add(
- getBigDecimalValue(rightValue));
- else if (type.equals(PredefinedType.bigIntegerType))
- value = getBigIntegerValue(leftValue).add(
- getBigIntegerValue(rightValue));
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerInvalidType", //NOI18N
- "checkBinaryPlusOp", type)); //NOI18N
- }
- ast = ConstantExpr.newConstant(value);
- ast.setType(CONSTANT);
- ast.setText(value.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Check a string concatenation operation (CONCAT) for constant operands
- * that could be optimized.
- * @param op the concat operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkConcatOp(JDOQLAST op, JDOQLAST left, JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- Object leftValue = ((ConstantExpr)left).getValue();
- Object rightValue = ((ConstantExpr)right).getValue();
- Object value = null;
- if (leftValue == null)
- value = rightValue;
- else if (rightValue == null)
- value = leftValue;
- else
- value = leftValue.toString() + rightValue.toString();
- ast = ConstantExpr.newConstant(value);
- ast.setType(CONSTANT);
- ast.setText(value.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Check a binary minus operation (MINUS) for constant operands
- * that could be optimized.
- * @param op the minus operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkBinaryMinusOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- Object leftValue = ((ConstantExpr)left).getValue();
- Object rightValue = ((ConstantExpr)right).getValue();
- Object value = null;
- if (rightValue == null)
- value = leftValue;
- else {
- if (leftValue == null)
- leftValue = new Integer(0);
-
- JavaType type = op.getTypeInfo();
-
- if (type.isWrapperClass())
- type = ((WrapperClassType)type).getWrappedPrimitiveType();
-
- if (type.equals(PredefinedType.intType))
- value = new Integer(((Number)leftValue).intValue() -
- ((Number)rightValue).intValue());
- else if (type.equals(PredefinedType.longType))
- value = new Long(((Number)leftValue).longValue() -
- ((Number)rightValue).longValue());
- else if (type.equals(PredefinedType.floatType))
- value = new Float(((Number)leftValue).floatValue() -
- ((Number)rightValue).floatValue());
- else if (type.equals(PredefinedType.doubleType))
- value = new Double(((Number)leftValue).doubleValue() -
- ((Number)rightValue).doubleValue());
- else if (type.equals(PredefinedType.bigDecimalType))
- value = getBigDecimalValue(leftValue).subtract(
- getBigDecimalValue(rightValue));
- else if (type.equals(PredefinedType.bigIntegerType))
- value = getBigIntegerValue(leftValue).subtract(
- getBigIntegerValue(rightValue));
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerInvalidType", //NOI18N
- "checkBinaryMinusOp", type)); //NOI18N
- }
- ast = ConstantExpr.newConstant(value);
- ast.setType(CONSTANT);
- ast.setText(value.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Check a binary multiplication operation (STAR) for constant operands
- * that could be optimized.
- * @param op the multiplication operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkMultiplicationOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- Object leftValue = ((ConstantExpr)left).getValue();
- Object rightValue = ((ConstantExpr)right).getValue();
- Object value = null;
- if (leftValue == null)
- leftValue = new Integer(0);
- if (rightValue == null)
- rightValue = new Integer(0);
- JavaType type = op.getTypeInfo();
-
- if (type.isWrapperClass())
- type = ((WrapperClassType)type).getWrappedPrimitiveType();
-
- if (type.equals(PredefinedType.intType))
- value = new Integer(((Number)leftValue).intValue() *
- ((Number)rightValue).intValue());
- else if (type.equals(PredefinedType.longType))
- value = new Long(((Number)leftValue).longValue() *
- ((Number)rightValue).longValue());
- else if (type.equals(PredefinedType.floatType))
- value = new Float(((Number)leftValue).floatValue() *
- ((Number)rightValue).floatValue());
- else if (type.equals(PredefinedType.doubleType))
- value = new Double(((Number)leftValue).doubleValue() *
- ((Number)rightValue).doubleValue());
- else if (type.equals(PredefinedType.bigDecimalType))
- value = getBigDecimalValue(leftValue).multiply(
- getBigDecimalValue(rightValue));
- else if (type.equals(PredefinedType.bigIntegerType))
- value = getBigIntegerValue(leftValue).multiply(
- getBigIntegerValue(rightValue));
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerInvalidType", //NOI18N
- "checkMultiplicationOp", type)); //NOI18N
-
- ast = ConstantExpr.newConstant(value);
- ast.setType(CONSTANT);
- ast.setText(value.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Check a binary division operation (DIV) for constant operands
- * that could be optimized.
- * @param op the division operator
- * @param left the left operand
- * @param right the right operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkDivisionOp(JDOQLAST op, JDOQLAST left,
- JDOQLAST right)
- {
- JDOQLAST ast = op;
-
- if ((left.getType() == CONSTANT) && (right.getType() == CONSTANT)) {
- Object leftValue = ((ConstantExpr)left).getValue();
- Object rightValue = ((ConstantExpr)right).getValue();
- Object value = null;
- if (leftValue == null)
- leftValue = new Integer(0);
- if (rightValue == null)
- // division by zero!
- rightValue = new Integer(0);
-
- JavaType type = op.getTypeInfo();
-
- if (type.isWrapperClass())
- type = ((WrapperClassType)type).getWrappedPrimitiveType();
-
- if (type.equals(PredefinedType.intType))
- value = new Integer(((Number)leftValue).intValue() /
- ((Number)rightValue).intValue());
- else if (type.equals(PredefinedType.longType))
- value = new Long(((Number)leftValue).longValue() /
- ((Number)rightValue).longValue());
- else if (type.equals(PredefinedType.floatType))
- value = new Float(((Number)leftValue).floatValue() /
- ((Number)rightValue).floatValue());
- else if (type.equals(PredefinedType.doubleType))
- value = new Double(((Number)leftValue).doubleValue() /
- ((Number)rightValue).doubleValue());
- else if (type.equals(PredefinedType.bigDecimalType))
- value = getBigDecimalValue(leftValue).divide(
- getBigDecimalValue(rightValue), BigDecimal.ROUND_HALF_EVEN);
- else if (type.equals(PredefinedType.bigIntegerType))
- value = getBigIntegerValue(leftValue).divide(
- getBigIntegerValue(rightValue));
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerInvalidType", //NOI18N
- "checkDivisionOp", type)); //NOI18N
-
- ast = ConstantExpr.newConstant(value);
- ast.setType(CONSTANT);
- ast.setText(value.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Check a unary minus operation (UNARY_MINUS) for a constant operand
- * that could be optimized.
- * @param op the unary minus operator
- * @param arg the operand
- * @return optimized JDOQLAST
- */
- protected JDOQLAST checkUnaryMinusOp(JDOQLAST op, JDOQLAST arg)
- {
- JDOQLAST ast = op;
-
- if (arg.getType() == CONSTANT) {
- Object value = ((ConstantExpr)arg).getValue();
- JavaType type = op.getTypeInfo();
- Object negate = null;
-
- if (type.equals(PredefinedType.intType))
- negate = new Integer(-((Number)value).intValue());
- else if (type.equals(PredefinedType.longType))
- negate = new Long(-((Number)value).longValue());
- else if (type.equals(PredefinedType.floatType))
- negate = new Float(-((Number)value).floatValue());
- else if (type.equals(PredefinedType.doubleType))
- negate = new Double(-((Number)value).doubleValue());
- else if (type.equals(PredefinedType.bigDecimalType))
- negate = getBigDecimalValue(value).negate();
- else if (type.equals(PredefinedType.bigIntegerType))
- negate = getBigIntegerValue(value).negate();
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerInvalidType", //NOI18N
- "checkUnaryMinusOp", type)); //NOI18N
-
- ast = ConstantExpr.newConstant(negate);
- ast.setType(CONSTANT);
- ast.setText(negate.toString());
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * Converts the specified value into a BigDecimal value.
- * @param value value to be converted
- * @return BigDecimal representation
- */
- protected BigDecimal getBigDecimalValue(Object value)
- {
- BigDecimal ret = null;
- if (value instanceof BigDecimal)
- ret = (BigDecimal)value;
- else if (value instanceof BigInteger)
- ret = new BigDecimal((BigInteger)value);
- else if (value instanceof Double)
- ret = new BigDecimal(((Double)value).doubleValue());
- else if (value instanceof Float)
- ret = new BigDecimal(((Float)value).doubleValue());
- else if (value instanceof Number)
- ret = BigDecimal.valueOf(((Number)value).longValue());
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerNumberExpected", //NOI18N
- "getBigDecimalValue", value)); //NOI18N
- return ret;
- }
-
- /**
- * Converts the specified value into a BigInteger value.
- * @param value value to be converted
- * @return BigInteger representation
- */
- protected BigInteger getBigIntegerValue(Object value)
- {
- BigInteger ret = null;
-
- if (value instanceof BigInteger)
- ret = (BigInteger)value;
- else if (value instanceof Number)
- ret = BigInteger.valueOf(((Number)value).longValue());
- else
- errorMsg.fatal(msg.msg("ERR_OptmizerNumberExpected", //NOI18N
- "getBigIntegerValue", value)); //NOI18N
- return ret;
- }
-
- /**
- * This method is called in the case of an equality operation having two
- * constant operands. It calculates the result of this constant operation
- * and returns a JDOQLAST node representing a constant boolean value.
- * @param op the equality operator
- * @param left the left operand
- * @param right the right operand
- * @param negate true for not equal operation, false otherwise
- * @return optimized JDOQLAST
- */
- protected JDOQLAST handleValueEqValue(JDOQLAST op, JDOQLAST left,
- JDOQLAST right,
- boolean negate)
- {
- Object leftValue = ((ConstantExpr)left).getValue();
- Object rightValue = ((ConstantExpr)right).getValue();
- boolean booleanValue = false;
-
- if ((leftValue == null) && (rightValue == null)) {
- // both values are null -> true
- booleanValue = true;
- }
- else if ((leftValue != null) && (rightValue != null)) {
- // both values are not null -> use equals
- booleanValue = leftValue.equals(rightValue);
- }
- else
- {
- // one value is null, the other is not null -> false
- booleanValue = false;
- }
- if (negate) {
- booleanValue = !booleanValue;
- }
-
- Boolean value = booleanValue ? Boolean.TRUE : Boolean.FALSE;
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText(value.toString());
- constant.setTypeInfo(op.getTypeInfo());
- return op;
- }
-
- /**
- * This method is called in the case of an equality operation having
- * a boolean constant operand and a non constant operand.
- * It returns the non constant operand either as it is or inverted,
- * depending on the equality operation.
- * @param op the equality operator
- * @param value the contant boolean value
- * @param expr the non constant operand
- * @param negate true for not equal operation, false otherwise
- * @return optimized JDOQLAST
- */
- private JDOQLAST handleBooleanValueEqExpr(JDOQLAST op, Object value,
- JDOQLAST expr, boolean negate)
- {
- JDOQLAST ast;
- boolean skip = (value instanceof Boolean) ?
- ((Boolean)value).booleanValue() : false;
- if (negate) skip = !skip;
-
- if (skip) {
- // expr == true -> expr
- // expr != false -> expr
- ast = expr;
- }
- else {
- // if expr is a equality op or a not op the invert operation
- // may be "inlined":
- // (expr1 == expr2) != true -> expr1 != expr2
- // (expr1 != expr2) != true -> expr1 == expr2
- // !expr != true -> expr
- // !expr == false -> expr
- // Otherwise wrap the expr with a not op
- // expr != true -> !expr
- // expr == false -> !expr
- switch (expr.getType()) {
- case EQUAL:
- ast = new NotEqualsExpr();
- ast.initialize(NOT_EQUAL, "!=", PredefinedType.booleanType); //NOI18N
- ast.setFirstChild(expr.getFirstChild());
- ((BinaryExpr)ast).setCommonOperandType(
- ((BinaryExpr)expr).getCommonOperandType());
- break;
- case NOT_EQUAL:
- ast = new EqualsExpr();
- ast.initialize(EQUAL, "==", PredefinedType.booleanType); //NOI18N
- ast.setFirstChild(expr.getFirstChild());
- ((BinaryExpr)ast).setCommonOperandType(
- ((BinaryExpr)expr).getCommonOperandType());
- break;
- case LNOT:
- ast = (JDOQLAST)expr.getFirstChild();
- break;
- default:
- ast = new NotExpr();
- ast.initialize(LNOT, "!", PredefinedType.booleanType); //NOI18N
- ast.setFirstChild(expr);
- }
- expr.setNextSibling(null);
- }
- return ast;
- }
-
- /**
- * This method is called in the case of an AND operation having at least
- * one constant operand. If the constant operand evaluates to true it
- * returns the other operand. If it evaluates to false it returns an AST
- * representing the constant boolean value false.
- * @param op the AND operator
- * @param value the value of the contsnat operand
- * @param expr the other operand
- * @return optimized JDOQLAST
- */
- private JDOQLAST handleValueAndExpr(JDOQLAST op, Object value, JDOQLAST expr)
- {
- JDOQLAST ast;
-
- if ((value instanceof Boolean) && ((Boolean)value).booleanValue()) {
- // true AND expr -> expr
- // expr AND true -> expr
- expr.setNextSibling(null);
- ast = expr;
- }
- else
- {
- // false AND expr -> false
- // expr AND false -> false
- ast = ConstantExpr.newConstant(Boolean.FALSE);
- ast.setType(CONSTANT);
- ast.setText("false"); //NOI18N
- ast.setTypeInfo(op.getTypeInfo());
- }
- return ast;
- }
-
- /**
- * This method is called in the case of an OR operation having at least
- * one constant operand. If the constant operand evaluates to false it
- * returns the other operand. If it evaluates to true it returns an AST
- * representing the constant boolean value true.
- * @param op the AND operator
- * @param value the value of the constant operand
- * @param expr the other operand
- * @return optimized JDOQLAST
- */
- private JDOQLAST handleValueOrExpr(JDOQLAST op, Object value, JDOQLAST expr)
- {
- JDOQLAST ast;
-
- if ((value instanceof Boolean) && ((Boolean)value).booleanValue()) {
- // true OR expr -> true
- // expr OR true -> true
- ast = ConstantExpr.newConstant(Boolean.TRUE);
- ast.setType(CONSTANT);
- ast.setText("true"); //NOI18N
- ast.setTypeInfo(op.getTypeInfo());
- }
- else {
- // false OR expr -> expr
- // expr OR false -> expr
- expr.setNextSibling(null);
- ast = expr;
- }
- return ast;
- }
-
- /**
- * Returns true if the specified AST represents a constant boolean value.
- */
- protected boolean isBooleanValueAST(JDOQLAST ast)
- {
- return (ast.getType() == CONSTANT) &&
- (PredefinedType.booleanType.equals(ast.getTypeInfo()));
- }
-
- /**
- * Returns the specified string w/o a long type suffix 'l' or 'L' or
- * the specified string if there is no such suffix.
- */
- private String skipLongTypeSuffix(String txt)
- {
- int index = txt.length() - 1;
- char last = txt.charAt(index);
- return ((last == 'l') || (last == 'L')) ? txt.substring(0, index) : txt;
- }
-
- /**
- * Returns the value of the specified field of the specified object.
- * The method uses StateManager methods to access the field value,
- * if it is a managed field of a persistent instance.
- * Otherwise it uses reflection.
- * @param javaField the field representation
- * @param pm the pm used in case of a managed field of a persistent instance
- * @param object the instance
- * @return the field value
- */
- private Object getFieldValue(JavaField javaField,
- PersistenceManagerInternal pm,
- Object object)
- {
- int fieldNumber =
- TypeSupport.getFieldNumber(javaField, pm, object);
- if (fieldNumber == -1)
- return TypeSupport.getFieldValue(getAccessibleField(javaField),
- object);
- else
- return TypeSupport.getFieldValue(fieldNumber, pm, object);
- }
-
- /**
- * Returns the value of the specified static field.
- * @param javaField the field representation
- * @return the field value
- */
- private Object getStaticFieldValue(JavaField javaField)
- {
- return TypeSupport.getFieldValue(getAccessibleField(javaField), null);
- }
-
- /**
- * Method executing TypeSupport.getAccessibleField in a doPrivileged block.
- */
- private Field getAccessibleField(final JavaField javaField)
- {
- return (Field) AccessController.doPrivileged(
- new PrivilegedAction() {
- public Object run () {
- return TypeSupport.getAccessibleField(javaField);
- }});
- }
-
-}
-
-// rules
-
-query!
- : #( q:QUERY_TREE
- c:candidateClass
- p:parameters
- v:variables
- o:ordering
- f:filter
- )
- {
- Tree tree = new Tree((CandidateClassImpl)#c, (ParameterDecl)#p,
- (VariableDecl)#v, (OrderingExpr)#o, (Expr)#f);
- tree.setType(QUERY_TREE);
- tree.setText("QUERY_TREE"); //NOI18N
- #query = tree;
- }
- ;
-
-// ----------------------------------
-// rules: candidate class
-// ----------------------------------
-
-candidateClass
-{
- errorMsg.setContext("setCandidates"); //NOI18N
-}
- : #(CANDIDATE_CLASS TYPE)
- ;
-
-// ----------------------------------
-// rules: parameter declaration
-// ----------------------------------
-
-parameters
-{
- errorMsg.setContext("declareParameters"); //NOI18N
-}
- : ( declareParameter )*
- ;
-
-declareParameter
- : #( PARAMETER_DECL TYPE ( IDENT )? )
- ;
-
-// ----------------------------------
-// rules: variable declaration
-// ----------------------------------
-
-variables
-{
- errorMsg.setContext("declareVariables"); //NOI18N
-}
- : ( declareVariable )*
- ;
-
-declareVariable
- : #( VARIABLE_DECL TYPE ( IDENT )? )
- ;
-
-// ----------------------------------
-// rules: ordering specification
-// ----------------------------------
-
-ordering
-{
- errorMsg.setContext("setOrdering"); //NOI18N
-}
- : ( orderSpec )*
- ;
-
-orderSpec
- : #( ASCENDING expression )
- | #( DESCENDING expression )
- ;
-
-// ----------------------------------
-// rules: filer expression
-// ----------------------------------
-
-filter
-{
- errorMsg.setContext("setFilter"); //NOI18N
-}
- : expression
- ;
-
-expression
- : primary
- | bitwiseExpr
- | conditionalExpr
- | relationalExpr
- | binaryArithmeticExpr
- | unaryArithmeticExpr
- | complementExpr
- ;
-
-bitwiseExpr
- : #( op1:BAND left1:expression right1:expression )
- {
- #bitwiseExpr = checkAnd(#op1, #left1, #right1);
- }
- | #( op2:BOR left2:expression right2:expression )
- {
- #bitwiseExpr = checkOr(#op2, #left2, #right2);
- }
- ;
-
-conditionalExpr
- : #( op1:AND left1:expression right1:expression )
- {
- #conditionalExpr = checkAnd(#op1, #left1, #right1);
- }
- | #( op2:OR left2:expression right2:expression )
- {
- #conditionalExpr = checkOr(#op2, #left2, #right2);
- }
- ;
-
-relationalExpr
- : #( op1:EQUAL left1:expression right1:expression )
- {
- #relationalExpr = checkEqualityOp(#op1, #left1, #right1, false);
- }
- | #( op2:NOT_EQUAL left2:expression right2:expression )
- {
- #relationalExpr = checkEqualityOp(#op2, #left2, #right2, true);
- }
- | #( op3:OBJECT_EQUAL left3:expression right3:expression )
- {
- #relationalExpr = checkObjectEqualityOp(#op3, #left3, #right3, false);
- }
- | #( op4:OBJECT_NOT_EQUAL left4:expression right4:expression )
- {
- #relationalExpr = checkObjectEqualityOp(#op4, #left4, #right4, true);
- }
- | #( op5:COLLECTION_EQUAL left5:expression right5:expression )
- {
- #relationalExpr = checkCollectionEqualityOp(#op5, #left5, #right5, false);
- }
- | #( op6:COLLECTION_NOT_EQUAL left6:expression right6:expression )
- {
- #relationalExpr = checkCollectionEqualityOp(#op6, #left6, #right6, true);
- }
- | #( LT expression expression )
- | #( GT expression expression )
- | #( LE expression expression )
- | #( GE expression expression )
- ;
-
-binaryArithmeticExpr
- : #( op1:PLUS left1:expression right1:expression )
- {
- #binaryArithmeticExpr = checkBinaryPlusOp(#op1, #left1, #right1);
- }
- | #( op2:CONCAT left2:expression right2:expression )
- {
- #binaryArithmeticExpr = checkConcatOp(#op2, #left2, #right2);
- }
- | #( op3:MINUS left3:expression right3:expression )
- {
- #binaryArithmeticExpr = checkBinaryMinusOp(#op3, #left3, #right3);
- }
- | #( op4:STAR left4:expression right4:expression )
- {
- #binaryArithmeticExpr = checkMultiplicationOp(#op4, #left4, #right4);
- }
- | #( op5:DIV left5:expression right5:expression )
- {
- #binaryArithmeticExpr = checkDivisionOp(#op5, #left5, #right5);
- }
- ;
-
-unaryArithmeticExpr
- : #( UNARY_PLUS expression )
- | ( #( UNARY_MINUS ( INT_LITERAL | LONG_LITERAL ) ) )=>
- #( UNARY_MINUS l:integralLiteral[true] )
- {
- #unaryArithmeticExpr = #l;
- }
- | #( op2:UNARY_MINUS arg2:expression )
- {
- #unaryArithmeticExpr = checkUnaryMinusOp(#op2, #arg2);
- }
- ;
-
-complementExpr
- : #( op1:BNOT arg1:expression )
- | #( op2:LNOT arg2:expression )
- {
- #complementExpr = checkLogicalNotOp(#op2, #arg2);
- }
- ;
-
-primary
- : #( CAST TYPE expression )
- | literal
- | THIS
- | parameterAccess
- | variableAccess
- | staticFieldAccess
- | fieldAccess
- | navigation
- | contains
- | startsWith
- | endsWith
- | isEmpty
- ;
-
-literal
- : b1:TRUE
- {
- ConstantExpr constant = ConstantExpr.newConstant(Boolean.TRUE);
- constant.setType(CONSTANT);
- constant.setText("true"); //NOI18N
- constant.setTypeInfo(b1.getTypeInfo());
- #literal = constant;
- }
- | b2:FALSE
- {
- ConstantExpr constant = ConstantExpr.newConstant(Boolean.FALSE);
- constant.setType(CONSTANT);
- constant.setText("false"); //NOI18N
- constant.setTypeInfo(b2.getTypeInfo());
- #literal = constant;
- }
- | b3:BOOLEAN_LITERAL
- {
- b3.setType(CONSTANT);
- }
- | integralLiteral[false]
- | f:FLOAT_LITERAL
- {
- String txt = f.getText();
- Float value = null;
- try {
- value = new Float(txt);
- }
- catch (NumberFormatException ex) {
- errorMsg.error(f.getLine(), f.getColumn(),
- msg.msg("EXC_InvalidLiteral", "float", txt)); //NOI18N
- }
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText(f.getText());
- constant.setTypeInfo(f.getTypeInfo());
- #literal = constant;
- }
- | d:DOUBLE_LITERAL
- {
- String txt = d.getText();
- Double value = null;
- try {
- value = new Double(txt);
- }
- catch (NumberFormatException ex) {
- errorMsg.error(d.getLine(), d.getColumn(),
- msg.msg("EXC_InvalidLiteral", "double", txt)); //NOI18N
- }
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText(d.getText());
- constant.setTypeInfo(d.getTypeInfo());
- #literal = constant;
- }
- | c:CHAR_LITERAL
- {
- Character value = new Character(parseChar(c.getText()));
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText(c.getText());
- constant.setTypeInfo(c.getTypeInfo());
- #literal = constant;
- }
- | s:STRING_LITERAL
- {
- ConstantExpr constant = ConstantExpr.newConstant(s.getText());
- constant.setType(CONSTANT);
- constant.setText(s.getText());
- constant.setTypeInfo(s.getTypeInfo());
- #literal = constant;
- }
- | n:NULL
- {
- ConstantExpr constant = ConstantExpr.newConstant(null);
- constant.setType(CONSTANT);
- constant.setText("null"); //NOI18N
- constant.setTypeInfo(n.getTypeInfo());
- #literal = constant;
- }
- | by:BYTE_LITERAL
- {
- by.setType(CONSTANT);
- }
- | sh:SHORT_LITERAL
- {
- sh.setType(CONSTANT);
- }
- | con:CONSTANT
- ;
-
-integralLiteral! [boolean negate]
- : i:INT_LITERAL
- {
- String txt = negate ? "-" + i.getText() : i.getText();
- Integer value = null;
- try {
- value = Integer.decode(txt);
- }
- catch (NumberFormatException ex) {
- errorMsg.error(i.getLine(), i.getColumn(),
- msg.msg("EXC_InvalidLiteral", "int", txt)); //NOI18N
- }
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText(txt);
- constant.setTypeInfo(i.getTypeInfo());
- #integralLiteral = constant;
- }
- | l:LONG_LITERAL
- {
- String txt = negate ? "-" + l.getText() : l.getText();
- Long value = null;
- try {
- value = Long.decode(skipLongTypeSuffix(txt));
- }
- catch (NumberFormatException ex) {
- errorMsg.error(l.getLine(), l.getColumn(),
- msg.msg("EXC_InvalidLiteral", "long", txt)); //NOI18N
- }
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText(txt);
- constant.setTypeInfo(l.getTypeInfo());
- #integralLiteral = constant;
- }
- ;
-
-parameterAccess
- : p:PARAMETER_ACCESS
- {
- if (optimizeParameters) {
- Object value = paramtab.getValue(#p.getText());
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText((value==null) ? "null" : value.toString()); //NOI18N
- constant.setTypeInfo(#p.getTypeInfo());
- #parameterAccess = constant;
- }
- }
- ;
-
-variableAccess
- : #( VARIABLE_ACCESS ( expression )? )
- ;
-
-staticFieldAccess!
- : #( s:STATIC_FIELD_ACCESS t:TYPE (i:IDENT)? )
- {
- // Calculate the value of the static field at compile time
- // and treat it as constant value.
- StaticFieldAccessExpr fieldAccess = (StaticFieldAccessExpr)#s;
- String fieldName = fieldAccess.getName();
- JavaField javaField = #t.getTypeInfo().getJavaField(fieldName);
- Object value = getStaticFieldValue(javaField);
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText((value==null) ? "null" : value.toString()); //NOI18N
- constant.setTypeInfo(#s.getTypeInfo());
- #staticFieldAccess = constant;
- }
- ;
-
-fieldAccess
- : #( f:FIELD_ACCESS o:expression ( i:IDENT )? )
- {
- if (#o.getType() == CONSTANT) {
- // If the object of the field access is a constant value,
- // evaluate the field access at compile time and
- // treat the expression as constant value.
- FieldAccessExpr fieldAccess = (FieldAccessExpr)#f;
- String fieldName = fieldAccess.getName();
- JavaField javaField = #o.getTypeInfo().getJavaField(fieldName);
- Object value = getFieldValue(
- javaField, pm, ((ConstantExpr)#o).getValue());
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText((value==null) ? "null" : value.toString()); //NOI18N
- constant.setTypeInfo(#f.getTypeInfo());
- #fieldAccess = constant;
- }
- }
- ;
-
-navigation
- : #( n:NAVIGATION o:expression ( i:IDENT )? )
- {
- if (#o.getType() == CONSTANT) {
- // If the object of the navigation is a constant value,
- // evaluate the field access at compile time and
- // treat the expression as constant value.
- FieldAccessExpr fieldAccess = (FieldAccessExpr)#n;
- String fieldName = fieldAccess.getName();
- JavaField javaField = #o.getTypeInfo().getJavaField(fieldName);
- Object value = getFieldValue(
- javaField, pm, ((ConstantExpr)#o).getValue());
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText((value==null) ? "null" : value.toString()); //NOI18N
- constant.setTypeInfo(#n.getTypeInfo());
- #navigation = constant;
- }
- }
- ;
-
-contains
- : #( CONTAINS expression expression )
- ;
-
-startsWith
- : #( STARTS_WITH expression expression )
- ;
-
-endsWith
- : #( ENDS_WITH expression expression )
- ;
-
-isEmpty
- : #( op:IS_EMPTY e:expression)
- {
- if (#e.getType() == CONSTANT) {
- // If the expression that specifies the collection is a
- // constant value, evaluate the isEmpty call at compile time
- // and treat the expression as constant value.
- Object object = ((ConstantExpr)#e).getValue();
- Object value = null;
- if (object == null) {
- value = new Boolean(false);
- }
- else if (object instanceof Collection) {
- value = new Boolean(((Collection)object).isEmpty());
- }
- else {
- errorMsg.fatal(msg.msg("ERR_OptmizerCollectionExpected", //NOI18N
- "isEmpty", object)); //NOI18N
- }
- ConstantExpr constant = ConstantExpr.newConstant(value);
- constant.setType(CONSTANT);
- constant.setText((value==null) ? "null" : value.toString()); //NOI18N
- constant.setTypeInfo(#op.getTypeInfo());
- #isEmpty = constant;
- }
- }
- ;
-
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Semantic.g b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Semantic.g
deleted file mode 100644
index d81152c..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Semantic.g
+++ /dev/null
@@ -1,1727 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Semantic.g
- *
- * Created on August 28, 2001
- */
-
-header
-{
- package org.apache.jdo.impl.jdoql.jdoqlc;
-
- import java.util.Collection;
-
- import org.apache.jdo.model.java.JavaType;
- import org.apache.jdo.model.java.JavaField;
- import org.apache.jdo.impl.model.java.ErrorType;
- import org.apache.jdo.impl.model.java.NullType;
- import org.apache.jdo.impl.model.java.PrimitiveType;
- import org.apache.jdo.impl.model.java.WrapperClassType;
- import org.apache.jdo.impl.model.java.PredefinedType;
-
- import org.apache.jdo.impl.jdoql.tree.*;
- import org.apache.jdo.impl.jdoql.scope.ParameterTable;
- import org.apache.jdo.impl.jdoql.scope.SymbolTable;
- import org.apache.jdo.impl.jdoql.scope.TypeNames;
- import org.apache.jdo.impl.jdoql.scope.VariableTable;
-
- import org.apache.jdo.util.I18NHelper;
-}
-
-/**
- * This class defines the semantic analysis of the JDOQL compiler.
- * Input of this pass is the AST as produced by the parser,
- * that consists of JDOQLAST nodes.
- * The result is a typed JDOQLAST tree.
- * <p>
- * TBD:
- * <ul>
- * <li> Check for non portable contains queries
- * </ul>
- *
- * @author Michael Bouschen
- */
-class Semantic extends TreeParser;
-
-options
-{
- importVocab = JDOQL;
- buildAST = true;
- defaultErrorHandler = false;
- ASTLabelType = "JDOQLAST"; //NOI18N
-}
-
-{
- /** The error message support class. */
- protected ErrorMsg errorMsg;
-
- /** Symbol table handling names of variables and parameters. */
- protected SymbolTable symtab;
-
- /** Table of type names handling imports. */
- protected TypeNames typeNames;
-
- /** The type support. */
- protected TypeSupport typeSupport;
-
- /** The query parameter table */
- protected ParameterTable paramtab;
-
- /** The variable table. */
- protected VariableTable vartab;
-
- /** The variable checker. */
- protected VariableChecker varChecker;
-
- /** Candidate class. */
- protected JavaType candidateClass;
-
- /** I18N support */
- protected final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", Semantic.class.getClassLoader()); //NOI18N
-
- /**
- *
- */
- public void init(TypeSupport typeSupport, ParameterTable paramtab,
- VariableTable vartab, ErrorMsg errorMsg)
- {
- this.errorMsg = errorMsg;
- this.symtab = new SymbolTable();
- this.typeNames = new TypeNames(typeSupport);
- this.vartab = vartab;
- this.typeSupport = typeSupport;
- this.paramtab = paramtab;
- this.varChecker = new VariableChecker();
- }
-
- /**
- *
- */
- public void reportError(RecognitionException ex) {
- errorMsg.fatal(msg.msg("ERR_SemanticError"), ex); //NOI18N
- }
-
- /**
- *
- */
- public void reportError(String s) {
- errorMsg.fatal(msg.msg("ERR_SemanticError") + s); //NOI18N
- }
-
- /**
- * Combines partial ASTs into one query AST.
- */
- public JDOQLAST createQueryTree(Class candidateClass, JDOQLAST importsAST,
- JDOQLAST paramsAST, JDOQLAST varsAST,
- JDOQLAST orderingAST, JDOQLAST filterAST)
- {
- CandidateClassImpl candidateClassAST = new CandidateClassImpl();
- candidateClassAST.setType(CANDIDATE_CLASS);
- candidateClassAST.setText(candidateClass.getName());
- candidateClassAST.setCandidateClass(candidateClass);
- JDOQLAST query = new NodeImpl();
- query.setType(QUERY_TREE);
- query.setText("query"); //NOI18N
- query.addChild(candidateClassAST);
- if (importsAST != null)
- query.addChild(importsAST);
- if (paramsAST != null)
- query.addChild(paramsAST);
- if (varsAST != null)
- query.addChild(varsAST);
- if (orderingAST != null)
- query.addChild(orderingAST);
- if (filterAST != null)
- query.addChild(filterAST);
- return query;
- }
-
- /**
- * This method analyses the expression of a single ordering definition.
- * It checks whether the expression
- * - is of a orderable type
- * @param expr the expression of an ordering definition
- */
- protected void analyseOrderingExpression(JDOQLAST expr)
- {
- JavaType exprType = expr.getTypeInfo();
- if (!exprType.isOrderable())
- {
- errorMsg.error(expr.getLine(), expr.getColumn(),
- msg.msg("EXC_NotSortableInOrdering", //NOI18N
- exprType.getName()));
- expr.setTypeInfo(ErrorType.errorType);
- }
- }
-
- /**
- * This method analyses a dot expression of the form expr.ident or
- * expr.ident(params) where expr itself can again be a dot expression.
- * It checks whether the dot expression is
- * - part of a qualified class name specification
- * - field access,
- * - a method call
- * The method returns a temporary single AST node that is defined with a
- * specific token type (field access, method call, etc.). This node also
- * contains the type of the dot expression.
- * @param expr the left hand side of the dot expression
- * @param ident the right hand side of the dot expression
- * @param args arguments (in the case of a call)
- * @return AST node representing the specialized dot expr
- */
- protected JDOQLAST analyseDotExpr(JDOQLAST dot, JDOQLAST expr,
- JDOQLAST ident, JDOQLAST args)
- {
- JavaType exprType = expr.getTypeInfo();
- String name = ident.getText();
- dot.setText(expr.getText() + '.' + name);
- if (!exprType.isPrimitive()) {
- // left expression is of a class type
- if (args == null) {
- // no paranethesis specified => field access
- JavaField javaField = exprType.getJavaField(name);
- if (javaField == null) {
- errorMsg.error(ident.getLine(), ident.getColumn(),
- msg.msg("EXC_UnknownField", //NOI18N
- ident.getText(), exprType.getName()));
- dot.setTypeInfo(ErrorType.errorType);
- ident.setTypeInfo(ErrorType.errorType);
- return dot;
- }
- else if (expr.getType() == TYPE) {
- // access of the form: className.staticField
- JDOQLAST fieldAccess = analyseStaticFieldAccess(
- expr, ident, exprType, javaField);
- fieldAccess.setLine(#dot.getLine());
- fieldAccess.setColumn(#dot.getColumn());
- return fieldAccess;
- }
- else {
- // access of the form: object.field
- JDOQLAST fieldAccess =
- analyseFieldAccess(expr, ident, exprType, javaField);
- fieldAccess.setLine(#dot.getLine());
- fieldAccess.setColumn(#dot.getColumn());
- return fieldAccess;
- }
- }
- else {
- // parenthesis specified => method call
- if (exprType.isJDOSupportedCollection()) {
- JDOQLAST call =
- analyseCollectionCall(dot, expr, ident, args);
- call.setLine(#dot.getLine());
- call.setColumn(#dot.getColumn());
- return call;
- }
- else if (exprType.equals(PredefinedType.stringType)) {
- JDOQLAST call = analyseStringCall(dot, expr, ident, args);
- call.setLine(#dot.getLine());
- call.setColumn(#dot.getColumn());
- return call;
- }
- errorMsg.error(dot.getLine(), dot.getColumn(),
- msg.msg("EXC_InvalidMethodCall")); //NOI18N
- dot.setTypeInfo(ErrorType.errorType);
- return dot;
- }
- }
- else {
- errorMsg.error(expr.getLine(), expr.getColumn(),
- msg.msg("EXC_ClassTypeExpressionExpected", //NOI18N
- ident.getText(), exprType.getName()));
- dot.setTypeInfo(ErrorType.errorType);
- return dot;
- }
- }
-
- /**
- *
- */
- protected JDOQLAST analyseFieldAccess(
- JDOQLAST objectExpr, JDOQLAST ident, JavaType classType,
- JavaField javaField)
- {
- FieldAccessExpr fieldAccess = new FieldAccessExpr();
- String name = ident.getText();
- JavaType fieldType = javaField.getType();
- int tokenType = (classType.isPersistenceCapable() &&
- fieldType.isPersistenceCapable()) ?
- NAVIGATION : FIELD_ACCESS;
- fieldAccess.initialize(tokenType, objectExpr.getText() + '.' + name,
- fieldType);
- fieldAccess.setName(name);
- fieldAccess.setFirstChild(objectExpr);
- objectExpr.setNextSibling(null);
- return fieldAccess;
- }
-
- /**
- *
- */
- protected JDOQLAST analyseStaticFieldAccess(
- JDOQLAST typename, JDOQLAST ident, JavaType classType,
- JavaField javaField)
- {
- String name = ident.getText();
- if (!typeSupport.isStaticField(javaField)) {
- errorMsg.error(ident.getLine(), ident.getColumn(),
- msg.msg("EXC_InvalidStaticReference", //NOI18N
- name, classType.getName()));
- }
- StaticFieldAccessExpr fieldAccess = new StaticFieldAccessExpr();
- fieldAccess.initialize(STATIC_FIELD_ACCESS,
- typename.getText() + '.' + name,
- javaField.getType());
- fieldAccess.setName(name);
- fieldAccess.setFirstChild(typename);
- typename.setNextSibling(null);
- return fieldAccess;
- }
-
- /**
- * This method analyses an identifier defined in the current scope which
- * is a field, variable or parameter defined in the symbol table.
- * @param ident the identifier AST
- * @return AST node representing a defined identifier
- */
- protected JDOQLAST analyseDefinedIdentifier(JDOQLAST ident)
- {
- JDOQLAST ast = null;
- String name = ident.getText();
- Decl decl = (Decl)symtab.getDeclaration(name);
- if (decl != null) {
- if (decl instanceof VariableDecl) {
- ast = new VariableAccessExpr();
- ast.initialize(VARIABLE_ACCESS, name, decl.getTypeInfo());
- ast.setLine(ident.getLine());
- ast.setColumn(ident.getColumn());
- }
- else if (decl instanceof ParameterDecl) {
- ast = new ParameterAccessExpr();
- ast.initialize(PARAMETER_ACCESS, name, decl.getTypeInfo());
- ast.setLine(ident.getLine());
- ast.setColumn(ident.getColumn());
- }
- }
- else {
- JavaField javaField = candidateClass.getJavaField(name);
- if (javaField != null) {
- ThisExpr thisAST = new ThisExpr();
- thisAST.initialize(THIS, "this", candidateClass); //NOI18N
- ast = analyseFieldAccess(thisAST, ident, candidateClass,
- javaField);
- ast.setLine(ident.getLine());
- ast.setColumn(ident.getColumn());
- }
- }
- return ast;
- }
-
- /**
- * Analyses a call for an object that implements Collection.
- * Currently, only contains and isEmpty are supported.
- */
- protected JDOQLAST analyseCollectionCall(JDOQLAST dot, JDOQLAST collection,
- JDOQLAST method, JDOQLAST args)
- {
- String methodName = method.getText();
- JDOQLAST call = null;
- JDOQLAST firstArg = (JDOQLAST)args.getFirstChild();
- if (methodName.equals("contains")) { //NOI18N
- call = new ContainsCallExpr();
- call.initialize(CONTAINS, methodName, PredefinedType.booleanType);
- checkContainsArgs(collection, method, firstArg);
- call.setFirstChild(collection);
- collection.setNextSibling(firstArg);
- }
- else if (methodName.equals("isEmpty")) { //NOI18N
- call = new IsEmptyCallExpr();
- call.initialize(IS_EMPTY, methodName, PredefinedType.booleanType);
- checkIsEmptyArgs(firstArg);
- call.setFirstChild(collection);
- collection.setNextSibling(null);
- }
- else {
- errorMsg.error(dot.getLine(), dot.getColumn(),
- msg.msg("EXC_InvalidMethodCall")); //NOI18N
- call = new IsEmptyCallExpr();
- call.initialize(IS_EMPTY, methodName, ErrorType.errorType);
- }
- return call;
- }
-
- /**
- * Check the arguments of a contains call.
- */
- protected void checkContainsArgs(JDOQLAST collection, JDOQLAST method,
- JDOQLAST args)
- {
- JDOQLAST firstArg = args;
- if (firstArg == null) {
- errorMsg.error(method.getLine(), method.getColumn(),
- msg.msg("EXC_WrongNumberOfArgs")); //NOI18N
- }
- else if (firstArg.getNextSibling() != null) {
- JDOQLAST nextArg = (JDOQLAST)firstArg.getNextSibling();
- errorMsg.error(nextArg.getLine(), nextArg.getColumn(),
- msg.msg("EXC_WrongNumberOfArgs")); //NOI18N
- }
- else {
- JavaType elementType = PredefinedType.objectType;
- JavaField collectionJavaField = getCollectionField(collection);
- if (collectionJavaField != null) {
- elementType = TypeSupport.getElementType(collectionJavaField);
- }
- JavaType argumentType = firstArg.getTypeInfo();
- JavaType testElementType = elementType.isPrimitive() ?
- ((PrimitiveType)elementType).getWrapperClassType() : elementType;
- JavaType testArgumentType = argumentType.isPrimitive() ?
- ((PrimitiveType)argumentType).getWrapperClassType() : argumentType;
- // elementType compatible with argumentType => OK
- // argumentType compatible with elementType => OK
- // otherwise error
- if (!testElementType.isCompatibleWith(testArgumentType) &&
- !testArgumentType.isCompatibleWith(testElementType)) {
- errorMsg.error(collection.getLine(), collection.getColumn(),
- msg.msg("EXC_CollectionElementTypeMismatch", //NOI18N
- elementType.getName(), argumentType.getName()));
- }
- }
- }
-
- /**
- *
- */
- protected JavaField getCollectionField(JDOQLAST expr)
- {
- JDOQLAST child = (JDOQLAST)expr.getFirstChild();
- switch (expr.getType()) {
- case FIELD_ACCESS:
- case NAVIGATION:
- if (child != null) {
- JavaType classType = child.getTypeInfo();
- String fieldName = null;
- if (child.getNextSibling() != null) {
- fieldName = child.getNextSibling().getText();
- }
- else {
- fieldName = ((FieldAccessExpr)expr).getName();
- }
- return classType.getJavaField(fieldName);
- }
- errorMsg.fatal(msg.msg("ERR_MissingChildren", expr)); //NOI18N
- break;
- case CAST:
- if ((child != null) && (child.getNextSibling() != null)) {
- return getCollectionField((JDOQLAST)child.getNextSibling());
- }
- errorMsg.fatal(msg.msg("ERR_MissingChildren", expr)); //NOI18N
- break;
- }
- return null;
- }
-
- /**
- * Check the arguments of a isEmpty call.
- */
- protected void checkIsEmptyArgs(JDOQLAST args)
- {
- if (args != null) {
- // isEmpty does not take parameters
- errorMsg.error(args.getLine(), args.getColumn(),
- msg.msg("EXC_WrongNumberOfArgs")); //NOI18N
- }
- }
-
- /**
- * Analyses a call for an object of type String.
- * Currently startsWith and endsWith are the only valid String methods
- * in a query filter.
- */
- protected JDOQLAST analyseStringCall(JDOQLAST dot, JDOQLAST string,
- JDOQLAST method, JDOQLAST args)
- {
- String methodName = method.getText();
- JDOQLAST call = null;
- JDOQLAST firstArg = (JDOQLAST)args.getFirstChild();
- if (methodName.equals("startsWith")) { //NOI18N
- call = new StartsWithCallExpr();
- call.initialize(STARTS_WITH, methodName, PredefinedType.booleanType);
- checkStringCallArgs(method, firstArg);
- call.setFirstChild(string);
- string.setNextSibling(firstArg);
- }
- else if (methodName.equals("endsWith")) { //NOI18N
- call = new EndsWithCallExpr();
- call.initialize(ENDS_WITH, methodName, PredefinedType.booleanType);
- checkStringCallArgs(method, firstArg);
- call.setFirstChild(string);
- string.setNextSibling(firstArg);
- }
- else
- {
- errorMsg.error(dot.getLine(), dot.getColumn(),
- msg.msg("EXC_InvalidMethodCall")); //NOI18N
- call = new StartsWithCallExpr();
- call.initialize(STARTS_WITH, methodName, ErrorType.errorType);
- }
- return call;
- }
-
- /**
- * Check the arguments of a startWith or endWith call.
- */
- protected void checkStringCallArgs(JDOQLAST method, JDOQLAST args)
- {
- JDOQLAST firstArg = args;
- if (firstArg == null) {
- errorMsg.error(method.getLine(), method.getColumn(),
- msg.msg("EXC_WrongNumberOfArgs")); //NOI18N
- }
- else if (firstArg.getNextSibling() != null) {
- JDOQLAST nextArg = (JDOQLAST)firstArg.getNextSibling();
- errorMsg.error(nextArg.getLine(), nextArg.getColumn(),
- msg.msg("EXC_WrongNumberOfArgs")); //NOI18N
- }
- else {
- JavaType argType = firstArg.getTypeInfo();
- if (!argType.equals(PredefinedType.stringType)) {
- errorMsg.error(firstArg.getLine(), firstArg.getColumn(),
- msg.msg("EXC_ArgumentTypeMismatch", //NOI18N
- argType.getName(), PredefinedType.stringType.getName()));
- }
- }
- }
-
- /**
- * Analyses a bitwise/logical operation (&, |, ^)
- * @param op the bitwise/logical operator
- * @param leftAST left operand
- * @param rightAST right operand
- * @return the type info of the operator
- */
- protected JavaType analyseBitwiseExpr(JDOQLAST op, JDOQLAST leftAST,
- JDOQLAST rightAST)
- {
- JavaType left = leftAST.getTypeInfo();
- JavaType right = rightAST.getTypeInfo();
-
- // handle error type
- if (left.equals(ErrorType.errorType) ||
- right.equals(ErrorType.errorType))
- return ErrorType.errorType;
-
- switch(op.getType()) {
- case BAND:
- case BOR:
- if (TypeSupport.isBooleanType(left) &&
- TypeSupport.isBooleanType(right)) {
- JavaType common = PredefinedType.booleanType;
- ((BinaryExpr)op).setCommonOperandType(
- TypeSupport.getJavaClass(common));
- return common;
- }
- break;
- }
-
- // if this code is reached a bitwise operator was used with
- // invalid arguments
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_InvalidArguments", op.getText())); //NOI18N
- return ErrorType.errorType;
- }
-
- /**
- * Analyses a boolean conditional operation (&&, ||)
- * @param op the conditional operator
- * @param leftAST left operand
- * @param rightAST right operand
- * @return the type info of the operator
- */
- protected JavaType analyseConditionalExpr(JDOQLAST op, JDOQLAST leftAST,
- JDOQLAST rightAST)
- {
- JavaType left = leftAST.getTypeInfo();
- JavaType right = rightAST.getTypeInfo();
-
- // handle error type
- if (left.equals(ErrorType.errorType) ||
- right.equals(ErrorType.errorType))
- return ErrorType.errorType;
-
- switch(op.getType()) {
- case AND:
- case OR:
- if (TypeSupport.isBooleanType(left) &&
- TypeSupport.isBooleanType(right)) {
- JavaType common = PredefinedType.booleanType;
- ((BinaryExpr)op).setCommonOperandType(
- TypeSupport.getJavaClass(common));
- return common;
- }
- break;
- }
-
- // if this code is reached a conditional operator was used
- // with invalid arguments
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_InvalidArguments", op.getText())); //NOI18N
- return ErrorType.errorType;
- }
-
- /**
- * Analyses a relational operation.
- * A relational operation contains one of <, <=, >, >=, ==, or !=.
- * @param op the relational operator
- * @param leftAST left operand
- * @param rightAST right operand
- * @return the node representing the relational expr
- */
- protected JDOQLAST analyseRelationalExpr(JDOQLAST op, JDOQLAST leftAST,
- JDOQLAST rightAST)
- {
- JavaType left = leftAST.getTypeInfo();
- JavaType right = rightAST.getTypeInfo();
-
- // handle error type
- if (left.equals(ErrorType.errorType) ||
- right.equals(ErrorType.errorType)) {
- op.setTypeInfo(ErrorType.errorType);
- return op;
- }
-
- // special check for <, <=, >, >=
- // left and right hand types must be orderable
- switch(op.getType()) {
- case LT:
- case LE:
- case GT:
- case GE:
- if (!left.isOrderable()) {
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_NotSortableType", //NOI18N
- left.getName(), op.getText()));
- op.setTypeInfo(ErrorType.errorType);
- return op;
- }
- if (!right.isOrderable()) {
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_NotSortableType", //NOI18N
- right.getName(), op.getText()));
- op.setTypeInfo(ErrorType.errorType);
- return op;
- }
- break;
- case EQUAL:
- if (left.isPersistenceCapable() ||
- right.isPersistenceCapable()) {
- op.setType(OBJECT_EQUAL);
- }
- else if (left.isJDOSupportedCollection() ||
- right.isJDOSupportedCollection()) {
- op.setType(COLLECTION_EQUAL);
- }
- break;
- case NOT_EQUAL:
- if (left.isPersistenceCapable() ||
- right.isPersistenceCapable()) {
- op.setType(OBJECT_NOT_EQUAL);
- }
- else if (left.isJDOSupportedCollection() ||
- right.isJDOSupportedCollection()) {
- op.setType(COLLECTION_NOT_EQUAL);
- }
- break;
- }
-
- JavaType common = getCommonOperandType(left, right);
- if (common != ErrorType.errorType) {
- ((BinaryExpr)op).setCommonOperandType(
- TypeSupport.getJavaClass(common));
- op.setTypeInfo(PredefinedType.booleanType);
- // check for operands of type char or Character;
- // they need to be explictly cast to the common operand type.
- leftAST = addCharacterCast(leftAST, common);
- rightAST = addCharacterCast(rightAST, common);
- op.setFirstChild(leftAST);
- leftAST.setNextSibling(rightAST);
- return op;
- }
-
- // if this code is reached a conditional operator was used with
- // invalid arguments
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_InvalidArguments", op.getText())); //NOI18N
- op.setTypeInfo(ErrorType.errorType);
- return op;
- }
-
- /**
- * Analyses a binary arithmetic expression +, -, *, /.
- * @param op the operator
- * @param leftAST left operand
- * @param rightAST right operand
- * @return the node representing the binary arithmetic op
- */
- protected JDOQLAST analyseBinaryArithmeticExpr(JDOQLAST op, JDOQLAST leftAST,
- JDOQLAST rightAST)
- {
- JavaType left = leftAST.getTypeInfo();
- JavaType right = rightAST.getTypeInfo();
-
- // handle error type
- if (left.equals(ErrorType.errorType) ||
- right.equals(ErrorType.errorType)) {
- op.setTypeInfo(ErrorType.errorType);
- return op;
- }
-
- if (TypeSupport.isNumberType(left) && TypeSupport.isNumberType(right)) {
- JavaType common = getCommonOperandType(left, right);
- if (common != ErrorType.errorType) {
- ((BinaryExpr)op).setCommonOperandType(
- TypeSupport.getJavaClass(common));
- op.setTypeInfo(common);
- // Check for operands of type char or Character;
- // they need to be explictly cast to the common operand type.
- leftAST = addCharacterCast(leftAST, common);
- rightAST = addCharacterCast(rightAST, common);
- op.setFirstChild(leftAST);
- leftAST.setNextSibling(rightAST);
- return op;
- }
- }
- else if (op.getType() == PLUS) {
- // handle + for strings
- if (left.equals(PredefinedType.stringType) &&
- right.equals(PredefinedType.stringType)) {
- JavaType common = PredefinedType.stringType;
- ((BinaryExpr)op).setCommonOperandType(
- TypeSupport.getJavaClass(common));
- op.setTypeInfo(common);
- // change the token type to CONCAT
- op.setType(CONCAT);
- return op;
- }
- }
-
- // if this code is reached a conditional operator was used
- // with invalid arguments
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_InvalidArguments", op.getText())); //NOI18N
- op.setTypeInfo(ErrorType.errorType);
- return op;
- }
-
- /**
- * The query runtime has a problem with binary or relational expressions
- * having an operand of type char or Character. The query runtime treats the
- * value of the expression to be a value of the promoted type (see binary
- * numeric promotion). The value will be of type Character which is not
- * compatible to java.lang.Number.
- * In the current query runtime only the CastExpression includes the
- * conversion code from the Character to Number. This keeps the code for
- * binary and relational expressions free from any special treatement of
- * char or Character values.
- * As a consequence the semantic analsis needs to insert a cast node
- * whenever binary numeric promotion converts a char or Character into a
- * numeric or Number type.
- * Method addCharacterCast checks whether the specified ast is of type
- * char or Character. If so it wraps it into a cast expression ast using
- * the specified type. If not the ast is reured as it is.
- * @param ast the ast to be checked
- * @param common the type to be used inside the cast
- * @return a cast node that wraps the specified ast node, if the ast is
- * of type char or Character; the ast itself otherwise.
- */
- protected JDOQLAST addCharacterCast(JDOQLAST ast, JavaType common)
- {
- JDOQLAST node = ast;
- if (TypeSupport.isCharType(ast.getTypeInfo())) {
- CastExpr cast = new CastExpr();
- cast.initialize(CAST, "CAST", common); //NOI18N
- cast.setLine(ast.getLine());
- cast.setColumn(ast.getColumn());
- TypeImpl typeNode = new TypeImpl();
- typeNode.initialize(TYPE, common.getName(), common);
- cast.setFirstChild(typeNode);
- typeNode.setNextSibling(ast);
- node = cast;
- }
- return node;
- }
-
- /**
- * Returns the common type info for the specified operand types.
- * This includes binary numeric promotion as specified in Java.
- * @param left type info of left operand
- * @param right type info of right operand
- * @return the common type info
- */
- protected JavaType getCommonOperandType(JavaType left, JavaType right)
- {
- if (TypeSupport.isNumberType(left) && TypeSupport.isNumberType(right)) {
- // handle java.math.BigDecimal
- if (left.isCompatibleWith(PredefinedType.bigDecimalType))
- return left;
- if (right.isCompatibleWith(PredefinedType.bigDecimalType))
- return right;
-
- // handle java.math.BigInteger
- if (left.isCompatibleWith(PredefinedType.bigIntegerType)) {
- // if right is floating point return BigDecimal,
- // otherwise return BigInteger
- if (right.isWrapperClass())
- right = ((WrapperClassType)right).getWrappedPrimitiveType();
- return right.isFloatingPoint() ?
- PredefinedType.bigDecimalType : left;
- }
- if (right.isCompatibleWith(PredefinedType.bigIntegerType)) {
- // if left is floating point return BigDecimal,
- // otherwise return BigInteger
- if (left.isWrapperClass())
- left = ((WrapperClassType)left).getWrappedPrimitiveType();
- return left.isFloatingPoint() ?
- PredefinedType.bigDecimalType : right;
- }
-
- boolean wrapper = false;
- if (left.isWrapperClass()) {
- left = ((WrapperClassType)left).getWrappedPrimitiveType();
- wrapper = true;
- }
- if (right.isWrapperClass()) {
- right = ((WrapperClassType)right).getWrappedPrimitiveType();
- wrapper = true;
- }
-
- // handle numeric types with arbitrary arithmetic operator
- if (TypeSupport.isNumericType(left) &&
- TypeSupport.isNumericType(right)) {
- JavaType promotedType =
- TypeSupport.binaryNumericPromotion(left, right);
- if (wrapper && TypeSupport.isNumericType(promotedType)) {
- promotedType =
- ((PrimitiveType)promotedType).getWrapperClassType();
- }
- return promotedType;
- }
- }
- else if (TypeSupport.isBooleanType(left) &&
- TypeSupport.isBooleanType(right)) {
- // check for boolean wrapper class: if one of the operands has the
- // type Boolean return Boolean, otherwise return boolean.
- if (left instanceof WrapperClassType)
- return left;
- else if (right instanceof WrapperClassType)
- return right;
- else
- return PredefinedType.booleanType;
- }
- else if (left.isCompatibleWith(right)) {
- return right;
- }
- else if (right.isCompatibleWith(left)) {
- return left;
- }
-
- // not compatible types => return errorType
- return ErrorType.errorType;
- }
-
- /**
- * Analyses a unary expression + and -
- * @param op the operator
- * @param argAST the opreand
- * @return the node representing the unary expression
- */
- protected JDOQLAST analyseUnaryArithmeticExpr(JDOQLAST op, JDOQLAST argAST)
- {
- JDOQLAST expr = null;
- JavaType type = analyseUnaryArithmeticExprType(op, argAST);
-
- switch(op.getType()) {
- case UNARY_PLUS:
- // create the correct node type here,
- // the lexer create Binary plus
- expr = new UnaryPlusExpr();
- expr.initialize(UNARY_PLUS, "+", type); //NOI18N
- break;
- case UNARY_MINUS:
- // create the correct node type here,
- // the lexer create Binary plus
- expr = new UnaryMinusExpr();
- expr.initialize(UNARY_MINUS, "-", type); //NOI18N
- break;
- }
- expr.setFirstChild(addCharacterCast(argAST, type));
- expr.setLine(op.getLine());
- expr.setColumn(op.getColumn());
-
- return expr;
- }
-
- /**
- * Analyses a unary expression + and -
- * @param op the operator
- * @param argAST the operand
- * @return the type info of the operator
- */
- protected JavaType analyseUnaryArithmeticExprType(JDOQLAST op,
- JDOQLAST argAST)
- {
- JavaType arg = argAST.getTypeInfo();
-
- // handle error type
- if (arg.equals(ErrorType.errorType))
- return ErrorType.errorType;
-
- // handle java.math.BigDecimal and java.math.BigInteger
- if (arg.isCompatibleWith(PredefinedType.bigDecimalType))
- return arg;
-
- // handle java.math.BigInteger
- if (arg.isCompatibleWith(PredefinedType.bigIntegerType))
- return arg;
-
- boolean wrapper = false;
- if (arg.isWrapperClass()) {
- arg = ((WrapperClassType)arg).getWrappedPrimitiveType();
- wrapper = true;
- }
-
- if (TypeSupport.isNumericType(arg)) {
- JavaType promotedType = TypeSupport.unaryNumericPromotion(arg);
- if (wrapper && TypeSupport.isNumericType(promotedType)) {
- promotedType =
- ((PrimitiveType)promotedType).getWrapperClassType();
- }
- return promotedType;
- }
-
- // if this code is reached a conditional operator was used
- // with invalid arguments
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_InvalidArguments", op.getText())); //NOI18N
- return ErrorType.errorType;
- }
-
- /**
- * Analyses a complement expression.
- * A complement expression contains one of ! and ~
- * @param op the operator
- * @param argAST the operand
- * @return the node representing the complement expression
- */
- protected JDOQLAST analyseComplementExpr(JDOQLAST op, JDOQLAST argAST)
- {
- JDOQLAST expr = null;
- JavaType type = analyseComplementExprType(op, argAST);
-
- switch(op.getType()) {
- case BNOT:
- // create the correct node type here,
- // the lexer create Binary plus
- expr = new ComplementExpr();
- expr.initialize(BNOT, "~", type); //NOI18N
- break;
- case LNOT:
- // create the correct node type here,
- // the lexer create Binary plus
- expr = new NotExpr();
- expr.initialize(LNOT, "!", type); //NOI18N
- break;
- }
- expr.setFirstChild(addCharacterCast(argAST, type));
- expr.setLine(op.getLine());
- expr.setColumn(op.getColumn());
-
- return expr;
- }
-
- /**
- * Analyses a complement expression.
- * A complement expression contains one of ! and ~
- * @param op the operator
- * @param argAST the operand
- * @return the type info of the operator
- */
- protected JavaType analyseComplementExprType(JDOQLAST op, JDOQLAST argAST)
- {
- JavaType arg = argAST.getTypeInfo();
-
- // handle error type
- if (arg.equals(ErrorType.errorType))
- return ErrorType.errorType;
-
- switch(op.getType()) {
- case BNOT:
- if (TypeSupport.isIntegralType(arg)) {
- boolean wrapper = false;
- if (arg.isWrapperClass()) {
- arg = ((WrapperClassType)arg).getWrappedPrimitiveType();
- wrapper = true;
- }
-
- JavaType promotedType = TypeSupport.unaryNumericPromotion(arg);
- if (wrapper) {
- promotedType =
- ((PrimitiveType)promotedType).getWrapperClassType();
- }
- return promotedType;
- }
- break;
- case LNOT:
- if (TypeSupport.isBooleanType(arg)) {
- return arg;
- }
- break;
- }
-
- // if this code is reached a conditional operator was used with
- // invalid arguments
- errorMsg.error(op.getLine(), op.getColumn(),
- msg.msg("EXC_InvalidArguments", op.getText())); //NOI18N
- return ErrorType.errorType;
- }
-
- /**
- *
- */
- protected void checkConstraints(JDOQLAST ast, VariableChecker tab)
- {
- checkConstraints(ast, null, tab);
- }
-
- /**
- *
- */
- protected void checkConstraints(JDOQLAST ast, String dependentVariable,
- VariableChecker tab)
- {
- if (ast == null) return;
- switch (ast.getType()) {
- case VARIABLE_ACCESS:
- tab.markUsed(ast, dependentVariable);
- break;
- case CONTAINS:
- JDOQLAST expr = (JDOQLAST)ast.getFirstChild();
- JDOQLAST var = (JDOQLAST)expr.getNextSibling();
- if (var.getType() == VARIABLE_ACCESS) {
- checkConstraints(expr, var.getText(), tab);
- tab.markConstraint(var, expr);
- }
- else {
- checkConstraints(expr, dependentVariable, tab);
- }
- break;
- case BOR:
- case OR:
- JDOQLAST left = (JDOQLAST)ast.getFirstChild();
- JDOQLAST right = (JDOQLAST)left.getNextSibling();
- // prepare tab copy for right hand side and merge
- // the right hand side copy into vartab
- VariableChecker copy = new VariableChecker(tab);
- checkConstraints(left, dependentVariable, tab);
- checkConstraints(right, dependentVariable, copy);
- tab.merge(copy);
- break;
- default:
- for (JDOQLAST node = (JDOQLAST)ast.getFirstChild();
- node != null; node = (JDOQLAST)node.getNextSibling()) {
- checkConstraints(node, dependentVariable, tab);
- }
- break;
- }
- }
-
-}
-
-// rules
-
-query
- : #( QUERY_TREE
- candidateClass
- {
- typeNames.init(candidateClass.getName());
- }
- imports
- parameters
- variables
- ordering
- filter
- )
- ;
-
-// ----------------------------------
-// rules: candidate class
-// ----------------------------------
-
-candidateClass
-{
- errorMsg.setContext("setClass"); //NOI18N
-}
- : #( c:CANDIDATE_CLASS t:type )
- {
- candidateClass = #t.getTypeInfo();
- if (candidateClass == null) {
- errorMsg.fatal(msg.msg("EXC_UnknownCandidateClass", //NOI18N
- #t.getText()));
- }
- #c.setTypeInfo(candidateClass);
- }
- ;
-
-// ----------------------------------
-// rules: import declaration
-// ----------------------------------
-
-imports!
-{
- errorMsg.setContext("declareImports"); //NOI18N
-}
- : ( declareImport )*
- ;
-
-declareImport
- { String name = null; }
- : #( i1:IMPORT name = qualifiedName )
- {
- JavaType type = typeSupport.checkType(name);
- if (type == null) {
- errorMsg.error(#i1.getLine(), #i1.getColumn(),
- msg.msg("EXC_UnknownType", name)); //NOI18N
- }
-
- String old = typeNames.declareImport(name);
- if (old != null) {
- errorMsg.error(#i1.getLine(), #i1.getColumn(),
- msg.msg("EXC_MultipleImport", name)); //NOI18N
- }
- }
- | #( i2:IMPORT_ON_DEMAND name = qualifiedName )
- {
- typeNames.declareImportOnDemand(name);
- }
- ;
-
-// ----------------------------------
-// rules: parameter declaration
-// ----------------------------------
-
-parameters
-{
- errorMsg.setContext("declareParameters"); //NOI18N
-}
- : ( declareParameter )*
- ;
-
-declareParameter
- : #( p:PARAMETER_DECL t:type ( i:IDENT )? )
- {
- ParameterDecl paramDecl = (ParameterDecl)#p;
- String name = (#i != null) ? #i.getText() : paramDecl.getName();
- JavaType type = #t.getTypeInfo();
- if (symtab.declare(name, paramDecl) != null) {
- errorMsg.error(#i.getLine(), #i.getColumn(),
- msg.msg("EXC_MultipleDeclaration", name)); //NOI18N
- }
- paramDecl.setTypeInfo(type);
- paramDecl.setName(name);
- paramDecl.setFirstChild(#t);
- paramtab.declare(paramDecl);
- #t.setNextSibling(null);
- }
- ;
-
-// ----------------------------------
-// rules: variable declaration
-// ----------------------------------
-
-variables
-{
- errorMsg.setContext("declareVariables"); //NOI18N
-}
- : ( declareVariable )*
- ;
-
-declareVariable
- : #( v:VARIABLE_DECL t:type ( i:IDENT )? )
- {
- VariableDecl varDecl = (VariableDecl)#v;
- String name = (#i != null) ? #i.getText() : varDecl.getName();
- JavaType type = #t.getTypeInfo();
- if (symtab.declare(name, varDecl) != null) {
- errorMsg.error(#i.getLine(), #i.getColumn(),
- msg.msg("EXC_MultipleDeclaration", name)); //NOI18N
- }
- varDecl.setTypeInfo(type);
- varDecl.setName(name);
- varDecl.setFirstChild(#t);
- #t.setNextSibling(null);
- vartab.declare(varDecl);
- varChecker.add(name);
- }
- ;
-
-// ----------------------------------
-// rules: ordering specification
-// ----------------------------------
-
-ordering
-{
- errorMsg.setContext("setOrdering"); //NOI18N
-}
- : ( orderSpec )*
- ;
-
-orderSpec
- : #( ASCENDING e1:expression )
- { analyseOrderingExpression(#e1); }
- | #( DESCENDING e2:expression )
- { analyseOrderingExpression(#e2); }
- ;
-
-// ----------------------------------
-// rules: filer expression
-// ----------------------------------
-
-filter
-{
- errorMsg.setContext("setFilter"); //NOI18N
-}
- // There is always a filter defined and it is the last node of the query
- // tree. Otherwise all the remaining subtrees after the CANDIDATE_CLASS
- // subtree are empty which results in a ClassCastException
- // antlr.ASTNullType during analysis of the (non existsent) subtrees
- : e:expression
- {
- JavaType exprType = #e.getTypeInfo();
- if (!(TypeSupport.isBooleanType(exprType) ||
- exprType.equals(ErrorType.errorType))) {
- // filter expression must have the type boolean or Boolean
- errorMsg.error(#e.getLine(), #e.getColumn(),
- msg.msg("EXC_BooleanFilterExpected", exprType)); //NOI18N
- }
- checkConstraints(#e, varChecker);
- varChecker.checkConstraints();
- }
- ;
-
-expression
- { String repr; }
- : repr = e:exprNoCheck[false]
- {
- if (repr != null) {
- #e.setTypeInfo(ErrorType.errorType);
- errorMsg.error(#e.getLine(), #e.getColumn(),
- msg.msg("EXC_UndefinedExpression", repr)); //NOI18N
- }
- }
- ;
-
-exprNoCheck [boolean insideDotExpr] returns [String repr]
- { repr = null; } // repr is used to get the text of identifier
- // inside a dot expression
- : bitwiseExpr
- | conditionalExpr
- | relationalExpr
- | binaryArithmeticExpr
- | unaryArithmeticExpr
- | complementExpr
- | repr = primary[insideDotExpr]
- ;
-
-bitwiseExpr
- : #( op1:BAND left1:expression right1:expression )
- {
- #op1.setTypeInfo(analyseBitwiseExpr(#op1, #left1, #right1));
- }
- | #( op2:BOR left2:expression right2:expression )
- {
- #op2.setTypeInfo(analyseBitwiseExpr(#op2, #left2, #right2));
- }
- ;
-
-conditionalExpr
- : #( op1:AND left1:expression right1:expression )
- {
- #op1.setTypeInfo(analyseConditionalExpr(#op1, #left1, #right1));
- }
- | #( op2:OR left2:expression right2:expression )
- {
- #op2.setTypeInfo(analyseConditionalExpr(#op2, #left2, #right2));
- }
- ;
-
-relationalExpr
-{
- JavaType left = null;
- JavaType right = null;
-}
- : #( op1:EQUAL left1:expression right1:expression )
- {
- #relationalExpr = analyseRelationalExpr(#op1, #left1, #right1);
- }
- | #( op2:NOT_EQUAL left2:expression right2:expression )
- {
- #relationalExpr = analyseRelationalExpr(#op2, #left2, #right2);
- }
- | #( op3:LT left3:expression right3:expression )
- {
- #relationalExpr = analyseRelationalExpr(#op3, #left3, #right3);
- }
- | #( op4:GT left4:expression right4:expression )
- {
- #relationalExpr = analyseRelationalExpr(#op4, #left4, #right4);
- }
- | #( op5:LE left5:expression right5:expression )
- {
- #relationalExpr = analyseRelationalExpr(#op5, #left5, #right5);
- }
- | #( op6:GE left6:expression right6:expression )
- {
- #relationalExpr = analyseRelationalExpr(#op6, #left6, #right6);
- }
- ;
-
-binaryArithmeticExpr
- : #( op1:PLUS left1:expression right1:expression )
- {
- #binaryArithmeticExpr = analyseBinaryArithmeticExpr(#op1, #left1,
- #right1);
- }
- | #( op2:MINUS left2:expression right2:expression )
- {
- #binaryArithmeticExpr = analyseBinaryArithmeticExpr(#op2, #left2,
- #right2);
- }
- | #( op3:STAR left3:expression right3:expression )
- {
- #binaryArithmeticExpr = analyseBinaryArithmeticExpr(#op3, #left3,
- #right3);
- }
- | #( op4:DIV left4:expression right4:expression )
- {
- #binaryArithmeticExpr = analyseBinaryArithmeticExpr(#op4, #left4,
- #right4);
- }
- ;
-
-unaryArithmeticExpr
- : #( op1:UNARY_PLUS arg1:expression )
- {
- #unaryArithmeticExpr = analyseUnaryArithmeticExpr(#op1, #arg1);
- }
- | #( op2:UNARY_MINUS arg2:expression )
- {
- #unaryArithmeticExpr = analyseUnaryArithmeticExpr(#op2, #arg2);
- }
- ;
-
-complementExpr
- : #( op1:BNOT arg1:expression )
- {
- #complementExpr = analyseComplementExpr(#op1, #arg1);
- }
- | #( op2:LNOT arg2:expression )
- {
- #complementExpr = analyseComplementExpr(#op2, #arg2);
- }
- ;
-
-primary [boolean insideDotExpr] returns [String repr]
-{ repr = null; }
- : #( c:CAST t:type e:expression )
- {
- JavaType type = #t.getTypeInfo();
- JavaType exprType = #e.getTypeInfo();
- if (! ((TypeSupport.isNumberType(type) &&
- TypeSupport.isNumberType(exprType)) ||
- type.isCompatibleWith(exprType) ||
- exprType.isCompatibleWith(type))) {
- errorMsg.error(#c.getLine(), #c.getColumn(),
- msg.msg("EXC_InvalidCast", //NOI18N
- exprType.getName(), type.getName()));
- type = ErrorType.errorType;
- }
- CastExpr cast = new CastExpr();
- cast.initialize(#c.getType(), "CAST", type); //NOI18N
- cast.setLine(#c.getLine());
- cast.setColumn(#c.getColumn());
- cast.setFirstChild(#t);
- #t.setNextSibling(#e);
- #primary = cast;
- }
- | literal
- | i:THIS
- { #i.setTypeInfo(candidateClass); }
- | repr = dotExpr
- | repr = identifier [insideDotExpr]
- | parameterAccess
- | variableAccess
- | fieldAccess
- | navigation
- | contains
- | isEmpty
- | startsWith
- | endsWith
- ;
-
-literal
- : b1:TRUE { #b1.setTypeInfo(PredefinedType.booleanType); }
- | b2:FALSE { #b2.setTypeInfo(PredefinedType.booleanType); }
- | b3:BOOLEAN_LITERAL { #b3.setTypeInfo(PredefinedType.booleanType); }
- | i:INT_LITERAL { #i.setTypeInfo(PredefinedType.intType); }
- | l:LONG_LITERAL { #l.setTypeInfo(PredefinedType.longType); }
- | f:FLOAT_LITERAL { #f.setTypeInfo(PredefinedType.floatType); }
- | d:DOUBLE_LITERAL { #d.setTypeInfo(PredefinedType.doubleType); }
- | c:CHAR_LITERAL { #c.setTypeInfo(PredefinedType.charType); }
- | s:STRING_LITERAL { #s.setTypeInfo(PredefinedType.stringType); }
- | n:NULL { #n.setTypeInfo(NullType.nullType); }
- | by:BYTE_LITERAL { #by.setTypeInfo(PredefinedType.byteType); }
- | sh:SHORT_LITERAL { #sh.setTypeInfo(PredefinedType.shortType); }
- | con:CONSTANT
- {
- Object value = ((ConstantExpr)#con).getValue();
- #con.setTypeInfo((value == null) ? NullType.nullType :
- typeSupport.checkType(value.getClass()));
- }
- ;
-
-dotExpr returns [String repr]
- {
- repr = null;
- }
- : #( dot:DOT
- repr = expr:exprNoCheck[true] ident:IDENT ( args:argList )?
- )
- {
- JavaType type = null;
- if (repr != null) { // possible package name
- String qualifiedName = repr + '.' + #ident.getText();
- type = typeSupport.checkType(qualifiedName);
- if (type == null) {
- // name does not define a valid class => return qualifiedName
- repr = qualifiedName;
- }
- else if (#args == null) {
- // found valid class name and NO arguments specified
- // => use of the class name
- repr = null;
- TypeImpl typeNode = new TypeImpl();
- typeNode.initialize(TYPE, qualifiedName, type);
- #dotExpr = typeNode;
- }
- else {
- // found valid class name and arguments specified =>
- // looks like constructor call
- repr = null;
- errorMsg.error(dot.getLine(), dot.getColumn(),
- msg.msg("EXC_InvalidMethodCall")); //NOI18N
- }
- #dot.setTypeInfo(type);
- #dot.setText(#expr.getText() + '.' + #ident.getText());
- }
- else { // no string repr of left hand side => expression is defined
- #dotExpr = analyseDotExpr(#dot, #expr, #ident, #args);
- }
- }
- ;
-
-argList
- : #(ARG_LIST args)
- ;
-
-identifier [boolean insideDotExpr] returns [String repr]
- {
- repr = null; // repr is set when ident is part of a package name spec
- }
- : ident:IDENT ( args:argList )?
- {
- String name = #ident.getText();
-
- // check args, if defined => invalid method call
- if (#args != null) {
- #ident.setTypeInfo(ErrorType.errorType);
- errorMsg.error(#ident.getLine(), #ident.getColumn(),
- msg.msg("EXC_InvalidMethodCall")); //NOI18N
- }
- JDOQLAST ast = analyseDefinedIdentifier(#ident);
- if (ast != null) {
- #identifier = ast;
- }
- else if (insideDotExpr) {
- JavaType resolved = typeNames.resolve(name);
- if (resolved != null) {
- // type name
- TypeImpl typeNode = new TypeImpl();
- typeNode.initialize(TYPE, resolved.getName(), resolved);
- #identifier = typeNode;
- }
- else {
- repr = #ident.getText();
- }
- }
- else {
- #ident.setTypeInfo(ErrorType.errorType);
- errorMsg.error(ident.getLine(), ident.getColumn(),
- msg.msg("EXC_UndefinedIdentifier", //NOI18N
- ident.getText()));
- }
- }
- ;
-
-parameterAccess
- : p:PARAMETER_ACCESS
- {
- String name = #p.getText();
- Decl decl = (Decl)symtab.getDeclaration(name);
- if (decl instanceof ParameterDecl) {
- #p.setTypeInfo(decl.getTypeInfo());
- }
- else {
- errorMsg.error(#p.getLine(), #p.getColumn(),
- msg.msg("EXC_InvalidParameterAccess", name)); //NOI18N
- }
- }
- ;
-
-variableAccess
- : #( v:VARIABLE_ACCESS ( expression )? )
- {
- String name = #v.getText();
- Decl decl = (Decl)symtab.getDeclaration(name);
- if (decl instanceof VariableDecl) {
- #v.setTypeInfo(decl.getTypeInfo());
- }
- else {
- errorMsg.error(#v.getLine(), #v.getColumn(),
- msg.msg("EXC_InvalidVariableAccess", name)); //NOI18N
- }
- }
- ;
-
-staticFieldAccess
- : #( s:STATIC_FIELD_ACCESS t:type ( i:IDENT )? )
- {
- String fieldName = ((StaticFieldAccessExpr)#s).getName();
- JavaType type = #t.getTypeInfo();
- JavaType fieldType = ErrorType.errorType;
- if (!type.isPrimitive()) {
- // left expression is of a class type
- JavaField javaField = type.getJavaField(fieldName);
- if (javaField == null) {
- errorMsg.error(#s.getLine(), #s.getColumn(),
- msg.msg("EXC_UnknownField", //NOI18N
- fieldName, type.getName()));
- }
- else {
- if (typeSupport.isStaticField(javaField)) {
- errorMsg.error(#s.getLine(), #s.getColumn(),
- msg.msg("EXC_InvalidStaticReference", //NOI18N
- fieldName, type.getName()));
- }
- }
- fieldType = javaField.getType();
- }
- else {
- errorMsg.error(#s.getLine(), #s.getColumn(),
- msg.msg("EXC_ClassTypeExpressionExpected")); //NOI18N
- }
- #s.setTypeInfo(fieldType);
- }
- ;
-
-fieldAccess
- : #( f:FIELD_ACCESS o:expression ( i:IDENT )? )
- {
- String fieldName = ((FieldAccessExpr)#f).getName();
- JavaType exprType = #o.getTypeInfo();
- JavaType fieldType = ErrorType.errorType;
- if (!exprType.isPrimitive()) {
- // left expression is of a class type
- JavaField javaField = exprType.getJavaField(fieldName);
- if (javaField == null) {
- errorMsg.error(#f.getLine(), #f.getColumn(),
- msg.msg("EXC_UnknownField", //NOI18N
- fieldName, exprType.getName()));
- }
- fieldType = javaField.getType();
- }
- else {
- errorMsg.error(#o.getLine(), #o.getColumn(),
- msg.msg("EXC_ClassTypeExpressionExpected")); //NOI18N
- }
- #f.setTypeInfo(fieldType);
- if (fieldType.isPersistenceCapable()) {
- #f.setType(NAVIGATION);
- }
- }
- ;
-
-navigation
- : #( n:NAVIGATION o:expression ( i:IDENT )? )
- {
- String fieldName = ((FieldAccessExpr)#n).getName();
- JavaType exprType = #o.getTypeInfo();
- JavaType fieldType = ErrorType.errorType;
- if (!exprType.isPrimitive()) {
- // left expression is of a class type
- JavaField javaField = exprType.getJavaField(fieldName);
- if (javaField == null) {
- errorMsg.error(#n.getLine(), #n.getColumn(),
- msg.msg("EXC_UnknownField", //NOI18N
- fieldName, exprType.getName()));
- }
- fieldType = javaField.getType();
- }
- else {
- errorMsg.error(#o.getLine(), #o.getColumn(),
- msg.msg("EXC_ClassTypeExpressionExpected")); //NOI18N
- }
- #n.setTypeInfo(fieldType);
- }
- ;
-
-contains
- : #(c:CONTAINS collection:expression args:args )
- {
- // check type of collection expression
- JavaType type = #collection.getTypeInfo();
- if (!type.isJDOSupportedCollection()) {
- errorMsg.error(#collection.getLine(), #collection.getColumn(),
- msg.msg("EXC_CollectionTypeExpected", type.getName())); //NOI18N
- }
- checkContainsArgs(#collection, #c, #args);
- #c.setTypeInfo(PredefinedType.booleanType);
- }
- ;
-
-isEmpty
- : #(i:IS_EMPTY collection:expression args:args )
- {
- // check type of collection expression
- JavaType type = #collection.getTypeInfo();
- if (!type.isJDOSupportedCollection()) {
- errorMsg.error(#collection.getLine(), #collection.getColumn(),
- msg.msg("EXC_CollectionTypeExpected", type.getName())); //NOI18N
- }
- checkIsEmptyArgs(#args);
- #i.setTypeInfo(PredefinedType.booleanType);
- }
- ;
-
-startsWith
- : #(s:STARTS_WITH string:expression args:args )
- {
- // check type of string expression
- JavaType type = #string.getTypeInfo();
- if (!PredefinedType.stringType.equals(type)) {
- errorMsg.error(#string.getLine(), #string.getColumn(),
- msg.msg("EXC_StringTypeExpected", type.getName())); //NOI18N
- }
- checkStringCallArgs(#s, #args);
- #s.setTypeInfo(PredefinedType.booleanType);
- }
- ;
-
-endsWith
- : #(e:ENDS_WITH string:expression args:args )
- {
- // check type of string expression
- JavaType type = #string.getTypeInfo();
- if (!PredefinedType.stringType.equals(type)) {
- errorMsg.error(#string.getLine(), #string.getColumn(),
- msg.msg("EXC_StringTypeExpected", type.getName())); //NOI18N
- }
- checkStringCallArgs(#e, #args);
- #e.setTypeInfo(PredefinedType.booleanType);
- }
- ;
-
-args
- : (expression)*
- ;
-
-qualifiedName returns [String name]
- { name = null; }
- : id1:IDENT
- {
- name = #id1.getText();
- }
- | #( d:DOT
- name = qualifiedName
- id2:IDENT
- {
- name += (#d.getText() + #id2.getText());
- }
- )
- ;
-
-// ----------------------
-// types
-// ----------------------
-
-type
- { String name = null; }
- : name = qn:qualifiedName
- {
- // First check type name as it is
- JavaType type = typeSupport.checkType(name);
- if (type == null)
- // Check type imports
- type = typeNames.resolve(name);
- if (type == null) {
- // unknown type
- errorMsg.error(#qn.getLine(), #qn.getColumn(),
- msg.msg("EXC_UnknownType", name)); //NOI18N
- }
- TypeImpl typeNode = new TypeImpl();
- typeNode.initialize(TYPE, type.getName(), type);
- #type = typeNode;
- }
- | t:TYPE
- {
- Class clazz = ((NodeImpl)#t).getJavaClass();
- if (clazz != null)
- #t.setTypeInfo(typeSupport.checkType(clazz));
- else
- #t.setTypeInfo(typeSupport.checkType(#t.getText()));
- }
- | p:primitiveType
- {
- name = #p.getText();
- TypeImpl typeNode = new TypeImpl();
- typeNode.initialize(TYPE, name, typeSupport.checkType(name));
- #type = typeNode;
- }
- ;
-
-primitiveType
- : BOOLEAN
- | BYTE
- | CHAR
- | SHORT
- | INT
- | FLOAT
- | LONG
- | DOUBLE
- ;
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/SimpleFieldManager.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/SimpleFieldManager.java
deleted file mode 100644
index 3aeeec1..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/SimpleFieldManager.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import org.apache.jdo.state.FieldManager;
-
-/**
- * This is the means by which a StateManager implementation's setXXXField()
- * method (where XXX is e.g. Int) can give the value back to the object
- *
- * @author Michael Bouschen
- */
-public class SimpleFieldManager implements FieldManager {
-
- private Object value;
-
- /**
- * Provides the means by which the value of a boolean field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Boolean that is the value of a particular field.
- */
- public void storeBooleanField(int fieldNum, boolean value) {
- this.value = new Boolean(value);
- }
-
- public boolean fetchBooleanField(int fieldNum) {
- return ((Boolean)value).booleanValue();
- }
-
- /**
- * Provides the means by which the value of a char field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Char that is the value of a particular field.
- */
- public void storeCharField(int fieldNum, char value){
- this.value = new Character(value);
- }
-
- public char fetchCharField(int fieldNum) {
- return ((Character)value).charValue();
- }
-
- /**
- * Provides the means by which the value of a byte field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Byte that is the value of a particular field.
- */
- public void storeByteField(int fieldNum, byte value){
- this.value = new Byte(value);
- }
-
-
- public byte fetchByteField(int fieldNum) {
- return ((Byte)value).byteValue();
- }
-
- /**
- * Provides the means by which the value of a short field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Short that is the value of a particular field.
- */
- public void storeShortField(int fieldNum, short value){
- this.value = new Short(value);
- }
-
-
- public short fetchShortField(int fieldNum) {
- return ((Short)value).shortValue();
- }
-
- /**
- * Provides the means by which the value of a int field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Int that is the value of a particular field.
- */
- public void storeIntField(int fieldNum, int value){
- this.value = new Integer(value);
- }
-
-
- public int fetchIntField(int fieldNum) {
- return ((Integer)value).intValue();
- }
-
- /**
- * Provides the means by which the value of a long field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Long that is the value of a particular field.
- */
- public void storeLongField(int fieldNum, long value){
- this.value = new Long(value);
- }
-
-
- public long fetchLongField(int fieldNum) {
- return ((Long)value).longValue();
- }
-
- /**
- * Provides the means by which the value of a field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value that is the value of a particular field.
- */
- public void storeFloatField(int fieldNum, float value){
- this.value = new Float(value);
- }
-
-
- public float fetchFloatField(int fieldNum) {
- return ((Float)value).floatValue();
- }
-
- /**
- * Provides the means by which the value of a double field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Double that is the value of a particular field.
- */
- public void storeDoubleField(int fieldNum, double value){
- this.value = new Double(value);
- }
-
-
- public double fetchDoubleField(int fieldNum) {
- return ((Double)value).doubleValue();
- }
-
- /**
- * Provides the means by which the value of a String field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value String that is the value of a particular field.
- */
- public void storeStringField(int fieldNum, String value){
- this.value = value;
- }
-
-
- public String fetchStringField(int fieldNum) {
- return (String)value;
- }
-
- /**
- * Provides the means by which the value of an Object field can be given
- * by a StateManager to an object that needs the value.
- * @param fieldNum Field number of the field in the object whose value is
- * given.
- * @param value Object that is the value of a particular field.
- */
- public void storeObjectField(int fieldNum, Object value){
- this.value = value;
- }
-
-
- public Object fetchObjectField(int fieldNum) {
- return value;
- }
-
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java
deleted file mode 100644
index 948abe5..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/TypeSupport.java
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * TypeTable.java
- *
- * Created on August 28, 2001
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import java.util.*;
-import java.lang.Class;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Field;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import javax.jdo.JDOHelper;
-import javax.jdo.JDOException;
-import javax.jdo.JDOFatalInternalException;
-import javax.jdo.PersistenceManager;
-import javax.jdo.spi.PersistenceCapable;
-
-import org.apache.jdo.impl.model.java.ErrorType;
-import org.apache.jdo.impl.model.java.PredefinedType;
-import org.apache.jdo.impl.model.java.WrapperClassType;
-import org.apache.jdo.impl.model.java.reflection.ReflectionJavaField;
-import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory;
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.model.ModelFatalException;
-import org.apache.jdo.model.java.JavaField;
-import org.apache.jdo.model.java.JavaModel;
-import org.apache.jdo.model.java.JavaType;
-import org.apache.jdo.model.jdo.JDOClass;
-import org.apache.jdo.model.jdo.JDOCollection;
-import org.apache.jdo.model.jdo.JDOField;
-import org.apache.jdo.model.jdo.JDORelationship;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-import org.apache.jdo.state.FieldManager;
-import org.apache.jdo.state.StateManagerInternal;
-import org.apache.jdo.util.I18NHelper;
-
-
-/**
- * Provides query convenience methods to deal with Java/JDO metadata.
- *
- * @author Michael Bouschen
- * @since JDO 1.0.1
- */
-public class TypeSupport
-{
- /** The JavaModel for the class loader of the candidate class. */
- protected JavaModel applicationJavaModel;
-
- /** The runtime JavaModel factory. */
- private static final RuntimeJavaModelFactory javaModelFactory =
- (RuntimeJavaModelFactory) AccessController.doPrivileged(
- new PrivilegedAction () {
- public Object run () {
- return RuntimeJavaModelFactory.getInstance();
- }
- }
- );
-
- /** I18N support */
- private static final I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", TypeSupport.class.getClassLoader()); //NOI18N
-
- /**
- * This methods sets the application JavaModel to the JavaModel
- * instance for the specified ClassLoader.
- * @param classLoader the class loader of the candidate class.
- */
- public void initApplicationJavaModel(ClassLoader classLoader)
- {
- this.applicationJavaModel = javaModelFactory.getJavaModel(classLoader);
- }
-
- /**
- * Returns the JavaType representation for the type with the specified
- * name. This method uses the application JavaModel for the type
- * lookup. This means any type is checked in the context of the
- * JavaModel for the class loader of the candidate class.
- * @param name the name of the type to be checked.
- * @return the JavaType object representing the type with the
- * specified name or null when the type was not found.
- */
- public JavaType checkType(String name)
- {
- return applicationJavaModel.getJavaType(name);
- }
-
- /**
- * Checks for the Java Type with the specified class object.
- * @param clazz the clazz object of the type to be checked.
- * @return the TypeDescriptor object representing the type
- */
- public JavaType checkType(Class clazz)
- {
- if (clazz == null)
- return null;
- return javaModelFactory.getJavaType(clazz);
- }
-
- /**
- * Implements binary numeric promotion as defined in the
- * Java Language Specification section 5.6.2
- */
- public static JavaType binaryNumericPromotion(JavaType left, JavaType right)
- {
- if ((left == null) || (right == null))
- return ErrorType.errorType;
-
- if (isNumericType(left) && isNumericType(right)) {
- if (left.equals(PredefinedType.doubleType) ||
- right.equals(PredefinedType.doubleType)) {
- return PredefinedType.doubleType;
- }
- else if (left.equals(PredefinedType.floatType) ||
- right.equals(PredefinedType.floatType)) {
- return PredefinedType.floatType;
- }
- else if (left.equals(PredefinedType.longType) ||
- right.equals(PredefinedType.longType)) {
- return PredefinedType.longType;
- }
- else {
- return PredefinedType.intType;
- }
- }
-
- return ErrorType.errorType;
- }
-
- /**
- * Implements unray numeric promotion as defined in the
- * Java Language Specification section 5.6.1
- */
- public static JavaType unaryNumericPromotion(JavaType type)
- {
- if (type == null)
- return ErrorType.errorType;
-
- if (isNumericType(type)) {
- if (type.equals(PredefinedType.byteType) ||
- type.equals(PredefinedType.shortType) ||
- type.equals(PredefinedType.charType)) {
- return PredefinedType.intType;
- }
- else {
- return type;
- }
- }
-
- return ErrorType.errorType;
- }
-
- /**
- * Returns the java.lang.Class instance for the specified type.
- * @param type the type to be checked
- * @return the corresponding class instance.
- */
- public static Class getJavaClass(JavaType type)
- {
- return javaModelFactory.getJavaClass(type);
- }
-
- //========= Interrogative methods ==========
-
- /**
- * Returns <code>true</code> if the specified type is
- * boolean or java.lang.Boolean.
- * @param type the type to be checked
- * @return <code>true</code> if type is boolean or java.lang.Boolean;
- * <code>false</code> otherwise.
- */
- public static boolean isBooleanType(JavaType type)
- {
- return type.equals(PredefinedType.booleanType) ||
- type.equals(PredefinedType.booleanClassType);
- }
-
- /**
- * Returns <code>true</code> if the specified type is
- * char or java.lang.Character
- * @param type the type to be checked
- * @return <code>true</code> if type is char or java.lang.Character
- * <code>false</code> otherwise.
- */
- public static boolean isCharType(JavaType type)
- {
- return type.equals(PredefinedType.charType) ||
- type.equals(PredefinedType.characterClassType);
- }
-
- /**
- * Returns <code>true</code> if the specified type is an interal type
- * or a Java wrapper class for an interal type.
- * @param type the type to be checked
- * @return <code>true</code> if type is an integral type or a Java
- * wrapper for an integral type; <code>false</code> otherwise.
- */
- public static boolean isIntegralType(JavaType type)
- {
- return type.isIntegral() ||
- (type.isWrapperClass() &&
- ((WrapperClassType)type).getWrappedPrimitiveType().isIntegral());
- }
-
- /**
- * Returns <code>true</code> if specified type is a number type:
- * <br>
- * a numeric primitive
- * <br>
- * a numeric wrapper class
- * <br>
- * java.math.BigDecimal, java.math.BigInteger.
- * @param type the type to be checked
- * @return <code>true</code> if type is a number type;
- * <code>false</code> otherwise.
- */
- public static boolean isNumberType(JavaType type)
- {
- return isNumericType(type) ||
- isNumericWrapperClassType(type) ||
- isMathType(type);
- }
-
- /**
- * Returns <code>true</code> if the specified type is a Java wrapper
- * class type for a numeric primitive type.
- * @param type the type to be checked
- * @return <code>true</code> if type is a numeric wrapper class type;
- * <code>false</code> otherwise.
- */
- public static boolean isNumericWrapperClassType(JavaType type)
- {
- return type.isWrapperClass() &&
- isNumericType(((WrapperClassType)type).getWrappedPrimitiveType());
- }
-
- /**
- * Returns <code>true</code> if the specified type is a either a
- * integral or a floating point type.
- * @param type the type to be checked
- * @return <code>true</code> if type is a numeric type;
- * <code>false</code> otherwise.
- */
- public static boolean isNumericType(JavaType type)
- {
- return type.isIntegral() || type.isFloatingPoint();
- }
-
- /**
- * Returns <code>true</code> if the specified type is either
- * java.math.BigDecimal or java.math.BigInteger.
- * @param type the type to be checked
- * @return <code>true</code> if type is BigDecimal or BigInteger;
- * <code>false</code> otherwise.
- */
- public static boolean isMathType(JavaType type)
- {
- return PredefinedType.bigDecimalType.equals(type) ||
- PredefinedType.bigIntegerType.equals(type);
- }
-
- //========= Field access methods ==========
-
- /** */
- public static boolean isStaticField(JavaField field)
- {
- int modifiers = field.getModifiers();
- return Modifier.isStatic(modifiers);
- }
-
- /** */
- public static JDOField getJDOField(JavaField javaField)
- {
- JDOField jdoField = null;
- JDOClass jdoClass = javaField.getDeclaringClass().getJDOClass();
- if (jdoClass != null) {
- jdoField = jdoClass.getField(javaField.getName());
- }
- return jdoField;
- }
-
- /** */
- public static JavaType getElementType(JavaField field)
- {
- JDOField jdoField = getJDOField(field);
- if (jdoField != null) {
- // check relationship
- try {
- JDORelationship jdoRelationship = jdoField.getRelationship();
- if (jdoRelationship instanceof JDOCollection) {
- return ((JDOCollection)jdoRelationship).getElementType();
- }
- }
- catch (ModelFatalException ex) {
- throw new JDOQueryException(ex.getMessage());
- }
- }
- JavaType fieldType = field.getType();
- if (fieldType.isJDOSupportedCollection())
- return PredefinedType.objectType;
-
- // If this code is reached the field is not specified as collection
- // in the JDO metadata and does not have a JDO supported collection
- // type => internal error.
- String fieldName = field.getName();
- String className = field.getDeclaringClass().getName();
- throw new JDOFatalInternalException(
- msg.msg("ERR_CollectionFieldExpected", //NOI18N
- fieldName, className, fieldType.getName()));
- }
-
- /**
- * field value of a managed field. Not using reflection.
- */
- public static Object getFieldValue(int fieldNumber,
- PersistenceManagerInternal pm,
- Object object)
- {
- PersistenceCapable pc = (PersistenceCapable)object;
- StateManagerInternal sm = pm.findStateManager(pc);
- FieldManager fm = new SimpleFieldManager();
- // Call isLoaded to ensure the field with the specified
- // field number is loaded.
- // NOTE, this code is not StateManager implementation neutral,
- // because it relies on the fact that isLoaded actually loads
- // the field. A neutral implementation would check the returns
- // value of isLoaded and if it returns false it would call a
- // jdoGetXXX to load the field.
- sm.isLoaded(pc, fieldNumber);
- sm.provideField(fieldNumber, fm , false);
- // NOTE, this call assumes that fetchObjectField return the
- // field value regardless which type the field has. Only
- // SimpleFieldManager from common.query.util.types has this
- // behavior. This is a workaround and needs to be changed!
- return fm.fetchObjectField(fieldNumber);
- }
-
- /**
- * Get field value via reflection
- */
- public static Object getFieldValue(Field field, Object object)
- {
- try {
- return field.get(object);
- }
- catch (IllegalAccessException ex) {
- String fieldName = field.getName();
- String className = field.getDeclaringClass().getName();
- throw new JDOQueryException(
- msg.msg("EXC_CannotAccessField", //NOI18N
- fieldName, className, ex));
- }
- }
-
- /**
- * Returns the fieldNumber of the specified field.
- * @return field number
- */
- public static int getFieldNumber(JavaField javaField,
- PersistenceManager pm,
- Object object)
- {
- JDOField jdoField = getJDOField(javaField);
- if ((object == null) || // null object means static field access
- (jdoField == null) || // no jdo field info
- !jdoField.isManaged()) { // field is not managed
- return -1; // use reflection
- }
-
- PersistenceManager instancePM =
- JDOHelper.getPersistenceManager(object);
- if (instancePM == null) { // object is a transient instance
- return -1; // use reflection
- }
- else if (!instancePM.equals(pm)) {
- // instancePM is NOT the one from the query => exception
- throw new JDOException(
- msg.msg("EXC_InstanceBoundToDifferentPM", object)); //NOI18N
- }
-
- // return the field number from the JDOField
- return jdoField.getFieldNumber();
- }
-
- /**
- * Returns a accessible java.lang.reflect.Field instance for the
- * specified JavaField. Note, this method gets a new Field instance
- * from reflection and sets the accessibility. The method requires the
- * caller to have the permission ReflectPermission("suppressAccessChecks").
- * @param javaField the JavaField
- * @return accessible Field instance
- */
- public static Field getAccessibleField(JavaField javaField)
- {
- // Get a new java.lang.reflect.Field instance. The query runtime
- // needs an accessible Field instance.
- Class clazz = javaModelFactory.getJavaClass(javaField.getDeclaringClass());
- String fieldName = javaField.getName();
- final Field field =
- ReflectionJavaField.getDeclaredFieldPrivileged(clazz, fieldName);
- if (field == null) {
- throw new JDOQueryException(
- msg.msg("EXC_CannotFindField", //NOI18N
- fieldName, clazz.getName()));
- }
-
- // if the field is not accessible, try to set the accessible flag.
- if (!field.isAccessible()) {
- try {
- field.setAccessible(true);
- }
- catch (SecurityException ex) {
- throw new JDOQueryException(
- msg.msg("EXC_CannotChangeAccessibility", //NOI18N
- fieldName, clazz.getName()));
- }
- }
- return field;
- }
-
-}
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java b/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java
deleted file mode 100644
index b281d18..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/jdoqlc/VariableChecker.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * VariableChecker.java
- *
- * Created on September 12, 2001
- */
-
-package org.apache.jdo.impl.jdoql.jdoqlc;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.HashSet;
-
-import javax.jdo.JDOUnsupportedOptionException;
-import javax.jdo.JDOFatalInternalException;
-
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.util.I18NHelper;
-
-
-/**
- * Checks variable declarations/application.
- *
- * @author Michael Bouschen
- * @version 0.1
- */
-public class VariableChecker
-{
- /** I18N support */
- protected final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", VariableChecker.class.getClassLoader()); //NOI18N
-
- /**
- * A VarInfo consists of two info fields:
- * - constraint: the variable is constraint with the specified expr
- * - used: the variable is used
- */
- static class VarInfo
- {
- /**
- * The constraint expression.
- */
- JDOQLAST constraint;
-
- /**
- * Set of JDOQLAST nodes denoting an access of this variable.
- */
- Set used;
-
- /**
- * Dependency for this variable.
- * The constraint for this variable may use another variable.
- */
- String dependsOn;
-
- /**
- * Flag whether this varInfo is checked already (see checkConstraints)
- */
- int status;
-
- static final int UNCHECKED = 0;
- static final int IN_PROGRESS = 1;
- static final int CHECKED = 2;
-
- VarInfo()
- {
- this.constraint = null;
- this.used = new HashSet();
- this.dependsOn = null;
- this.status = UNCHECKED;
- }
-
- VarInfo(VarInfo other)
- {
- this.constraint = other.constraint;
- this.used = new HashSet(other.used);
- this.dependsOn = other.dependsOn;
- this.status = other.status;
- }
- }
-
- /**
- * Map of variable infos
- */
- protected Map varInfos;
-
- /**
- * Create an empty variable table
- */
- public VariableChecker()
- {
- varInfos = new HashMap();
- }
-
- /**
- * Create a variable table initialized with the entries of the other variable table.
- * The constructor creates copies of the values stored in the map (instances of class VarInfo).
- */
- public VariableChecker(VariableChecker other)
- {
- varInfos = new HashMap();
- for (Iterator i = other.varInfos.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry)i.next();
- varInfos.put(entry.getKey(), new VarInfo((VarInfo)entry.getValue()));
- }
- }
-
- /**
- * Creates a new entry in the variable table with the specified name as key and
- * an empty value.
- */
- public void add(String name)
- {
- // init var entry as not constraint and unused
- varInfos.put(name, new VarInfo());
- }
-
- /**
- * Mark the specified variable as used.
- * The method sets the info field of the VarInfo object to true.
- */
- public void markUsed(JDOQLAST variable, String dependendVar)
- {
- String name = variable.getText();
- VarInfo entry = (VarInfo)varInfos.get(name);
- if (entry == null) {
- throw new JDOFatalInternalException(
- msg.msg("ERR_VariableCheckerUndefinedVariable", //NOI18N
- "markUsed", name)); //NOI18N
- }
- entry.used.add(variable);
- if (dependendVar != null) {
- VarInfo dependendVarInfo = (VarInfo)varInfos.get(dependendVar);
- if (dependendVarInfo.dependsOn != null) {
- throw new JDOFatalInternalException(
- msg.msg("ERR_VariableCheckerMultipleDependencies", //NOI18N
- dependendVar, dependendVarInfo.dependsOn, name));
- }
- dependendVarInfo.dependsOn = name;
- }
- }
-
- /**
- * Mark the specified variable as constaint with the specified expr.
- * The method sets the constraint field of the VarInfo object to true.
- */
- public void markConstraint(JDOQLAST variable, JDOQLAST expr)
- {
- String name = variable.getText();
- VarInfo entry = (VarInfo)varInfos.get(name);
- if (entry == null) {
- throw new JDOFatalInternalException(
- msg.msg("ERR_VariableCheckerUndefinedVariable", //NOI18N
- "markConstraint", name)); //NOI18N
- }
- String old = (entry.constraint==null ? null : entry.constraint.getText());
- if ((old != null) && !old.equals(expr.getText())) {
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_UnsupportedMultipleConstraints", name)); //NOI18N
- }
- entry.constraint = expr;
- }
-
- /**
- * Merges the specified variable table (other) into this variable table.
- */
- public void merge(VariableChecker other)
- {
- for (Iterator i = varInfos.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry)i.next();
- String name = (String)entry.getKey();
- VarInfo info = (VarInfo)entry.getValue();
- VarInfo otherInfo = (VarInfo)other.varInfos.get(name);
-
- // copy other info if this info is empty
- if ((info.constraint == null) && (info.used.size() == 0)) {
- info.constraint = otherInfo.constraint;
- info.used = otherInfo.used;
- info.dependsOn = otherInfo.dependsOn;
- info.status = otherInfo.status;
- continue;
- }
-
- // do nothing if otherInfo is empty
- if ((otherInfo.constraint == null) && (otherInfo.used.size() == 0)) {
- continue;
- }
-
- // constraint check
- // If both variables tables include constraints they have to be the same
- if ((info.constraint != null) && (otherInfo.constraint != null)) {
- if (!otherInfo.constraint.getText().equals(info.constraint.getText())) {
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_DifferentConstraints", name)); //NOI18N
- }
- }
- // If at least one variable table does not define constraint,
- // nullify the constaint in this variable table
- else {
- info.constraint = null;
- info.dependsOn = null;
- info.status = VarInfo.UNCHECKED;
- }
-
- // copy otherInfo.used to this used list
- info.used.addAll(otherInfo.used);
- }
- }
-
- /**
- *
- */
- public void checkConstraints()
- {
- for (Iterator i = varInfos.entrySet().iterator(); i.hasNext();) {
- Map.Entry entry = (Map.Entry)i.next();
- VarInfo info = (VarInfo)entry.getValue();
- checkConstraint((String)entry.getKey(), (VarInfo)entry.getValue());
- }
- }
-
- protected void checkConstraint(String variable, VarInfo info)
- {
- switch (info.status) {
- case VarInfo.UNCHECKED:
- // if unchecked, start checking
- info.status = VarInfo.IN_PROGRESS;
- break;
- case VarInfo.IN_PROGRESS:
- // if this VarInfo is currently processed we have a cyclic dependency
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_UnsupportedCyclicConstaint", variable)); // NOI18N
- case VarInfo.CHECKED:
- // if alreday checked just return
- return;
- }
-
- if (info.dependsOn != null) {
- VarInfo dependendVarInfo = (VarInfo)varInfos.get(info.dependsOn);
- checkConstraint(info.dependsOn, dependendVarInfo);
- }
-
- if (info.constraint == null) {
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_UnconstraintVariable", variable)); //NOI18N
- }
-
- if (info.used.size() == 0) {
- throw new JDOUnsupportedOptionException(
- msg.msg("EXC_UnusedVariable", variable)); //NOI18N
- }
-
- // Next line in comment, because the node visitor for queries in memory
- // does not like VARIABLE_ACCESS child nodes.
- // This needs to be investigated for the SQL generation.
- //attachConstraintToUsedAST(info);
- info.status = VarInfo.CHECKED;
- }
-
- /**
- *
- */
- protected void attachConstraintToUsedAST(VarInfo info)
- {
- for (Iterator i = info.used.iterator(); i.hasNext();) {
- JDOQLAST varNode = (JDOQLAST)i.next();
- if (varNode.getFirstChild() == null)
- varNode.setFirstChild(JDOQLASTFactory.getInstance().dupTree(info.constraint));
- }
- }
-
-}
-
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java b/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java
deleted file mode 100644
index 14a789f..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/scope/AbstractValueTable.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * AbstractValueTable.java
- *
- * Created on September 11, 2001
- */
-
-package org.apache.jdo.impl.jdoql.scope;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.io.Serializable;
-
-import javax.jdo.JDOFatalInternalException;
-
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.jdoql.tree.Declaration;
-import org.apache.jdo.jdoql.tree.ValueTable;
-import org.apache.jdo.util.I18NHelper;
-
-
-/**
- * This method is the abstract super class for ParameterTable and VariableTable.
- * It provides common implementation for managing parameter and variable values.
- *
- * @author Michael Bouschen
- */
-abstract class AbstractValueTable
- implements ValueTable, Serializable, Cloneable
-{
- /**
- * Map of declarations. Key is the the name of the declared identifier,
- * value is the Declaration node.
- */
- Map declMap = new HashMap();
-
- /**
- * Map of values. This map includes a values entry for each declared
- * identifier. Default value is UNDEFINED.
- */
- transient Map valueMap;
-
- /** I18N support */
- protected final static I18NHelper msg = I18NHelper.getInstance(
- "org.apache.jdo.impl.jdoql.Bundle", //NOI18N
- AbstractValueTable.class.getClassLoader());
-
- /**
- * Adds a new declaration. The value is set to UNDEFINED.
- * @param decl the declaration node
- */
- public void declare(Declaration decl)
- {
- String name = decl.getName();
- declMap.put(name, decl);
- }
-
- /**
- * This method initializes the map of values for this ValueTable.
- * It needs to be called prior to any use of an AbstractValueTable
- * at query execution time.
- */
- public void initValueHandling()
- {
- valueMap = new HashMap();
- for (Iterator i = declMap.keySet().iterator(); i.hasNext();) {
- String name = (String)i.next();
- valueMap.put(name, UNDEFINED.getInstance());
- }
- }
-
- /**
- * Sets the value for the specified identifier.
- * @param name the name of the identifier
- * @param value the current value of the identifier
- */
- public void setValue(String name, Object value)
- {
- if (valueMap == null)
- throw new JDOFatalInternalException(
- msg.msg("ERR_InvalidTableForExecution", //NOI18N
- this.getClass().getName()));
- Declaration decl = (Declaration)declMap.get(name);
- checkDeclaredIdentifier(name, decl);
- valueMap.put(name, value);
- }
-
- /**
- * Returns the current value for the specified identifier.
- * @param name the name of the identifier
- * @return the current value of the identifier
- */
- public Object getValue(String name)
- {
- if (valueMap == null)
- throw new JDOFatalInternalException(
- msg.msg("ERR_InvalidTableForExecution", //NOI18N
- this.getClass().getName()));
- checkDeclaredIdentifier(name, (Declaration)declMap.get(name));
- return valueMap.get(name);
- }
-
- /**
- * Checks whether the type of the specified value is compatible of the type
- * of the identifier from its declaration.
- * @param name the name of the identifier
- * @param value the value to be checked
- * @return <code>true</code> if the type of the value is compatible with the
- * type of the identifier; <code>false</code> otherwise.
- */
- public boolean isCompatibleValue(String name, Object value)
- {
- Declaration decl = (Declaration)declMap.get(name);
- checkDeclaredIdentifier(name, decl);
-
- boolean isCompatible = true;
-
- // check type compatibility of actual and formal parameter
- Class formalType = decl.getJavaClass();
-
- // handle value == null
- if (value == null) {
- isCompatible = !formalType.isPrimitive();
- }
- else {
- Class actualType = value.getClass();
- Class type = formalType;
- if (formalType.isPrimitive()) {
- if (formalType == int.class)
- type = Integer.class;
- else if (formalType == long.class)
- type = Long.class;
- else if (formalType == short.class)
- type = Short.class;
- else if (formalType == byte.class)
- type = Byte.class;
- else if (formalType == double.class)
- type = Double.class;
- else if (formalType == float.class)
- type = Float.class;
- else if (formalType == boolean.class)
- type = Boolean.class;
- else if (formalType == char.class)
- type = Character.class;
- }
- isCompatible = type.isAssignableFrom(actualType);
- }
- return isCompatible;
- }
-
- /**
- * Internal method to check whether the specified identifier is declared.
- * Allows subclasses of AbstractValueTable to use specific error messages.
- */
- protected abstract void checkDeclaredIdentifier(String name,
- Declaration decl);
-
-}
-
diff --git a/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java b/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java
deleted file mode 100644
index 6b462bb..0000000
--- a/query20/src/java/org/apache/jdo/impl/jdoql/scope/ParameterTable.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright 2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * ParameterTable.java
- *
- * Created on August 28, 2001
- */
-
-package org.apache.jdo.impl.jdoql.scope;
-
-import java.util.*;
-
-import javax.jdo.JDOFatalInternalException;
-
-import org.apache.jdo.impl.jdoql.QueryResultHelperImpl;
-import org.apache.jdo.jdoql.JDOQueryException;
-import org.apache.jdo.jdoql.tree.Declaration;
-import org.apache.jdo.pm.PersistenceManagerInternal;
-
-
-/**
- * The query parameter table.
- *
- * @author Michael Bouschen
- */
-public class ParameterTable
- extends AbstractValueTable
-{
- /**
- * List of query parameter names. The query parameter tables stores the
- * query parameter names in an extra list to presever the order of
- * parameter declarations.
- */
- List names = new ArrayList();
-
- /**
- * Adds a new declaration. The value is initially set to UNDEFINED.
- * @param decl the declaration node
- */
- public void declare(Declaration decl)
- {
- super.declare(decl);
- names.add(decl.getName());
- }
-
- /**
- * Returns a copy of this ParameterTable.
- * @return a copy of this ParameterTable.
- */
- public ParameterTable getCopy()
- {
- try {
- return (ParameterTable)clone();
- }
- catch (CloneNotSupportedException ex) {
- throw new JDOFatalInternalException(
- msg.msg("ERR_UnexpectedCloneProblems", ex)); //NOI18N
- }
- }
-
- /**
- * Internal method to check whether the specified identifier is declared.
- */
- protected void checkDeclaredIdentifier(String name, Declaration decl)
- {
- if (decl == null)
- throw new JDOQueryException(
- msg.msg("EXC_UndefinedQueryParameter", name)); //NOI18N
- }
-
- //========= PatameterTable convenience methods ==========
-
- /**
- * Sets all query parameter values. The order of declarations in
- * declareParameters defines the order in the specified array of parameter
- * values. The method checks the type compatibility of the query parameter
- * values.
- * @param paramValues the parameter values
- */
- public void setValues(PersistenceManagerInternal queryPM, Object[] paramValues)
- {
... 39288 lines suppressed ...