KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > odmg > oql > OQLParser


1 // $ANTLR 2.7.5 (20050128): "oql-ojb.g" -> "OQLParser.java"$
2

3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.ojb.odmg.oql;
19
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Vector JavaDoc;
24
25 import org.apache.ojb.broker.metadata.ClassDescriptor;
26 import org.apache.ojb.broker.metadata.MetadataManager;
27 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
28 import org.apache.ojb.broker.query.Criteria;
29 import org.apache.ojb.broker.query.Query;
30 import org.apache.ojb.broker.query.QueryByCriteria;
31 import org.apache.ojb.broker.query.QueryFactory;
32 import org.apache.ojb.broker.util.ClassHelper;
33
34 import antlr.NoViableAltException;
35 import antlr.ParserSharedInputState;
36 import antlr.RecognitionException;
37 import antlr.Token;
38 import antlr.TokenBuffer;
39 import antlr.TokenStream;
40 import antlr.TokenStreamException;
41 import antlr.collections.impl.BitSet;
42
43 public class OQLParser extends antlr.LLkParser implements OQLLexerTokenTypes
44  {
45
46 protected OQLParser(TokenBuffer tokenBuf, int k) {
47   super(tokenBuf,k);
48   tokenNames = _tokenNames;
49 }
50
51 public OQLParser(TokenBuffer tokenBuf) {
52   this(tokenBuf,3);
53 }
54
55 protected OQLParser(TokenStream lexer, int k) {
56   super(lexer,k);
57   tokenNames = _tokenNames;
58 }
59
60 public OQLParser(TokenStream lexer) {
61   this(lexer,3);
62 }
63
64 public OQLParser(ParserSharedInputState state) {
65   super(state,3);
66   tokenNames = _tokenNames;
67 }
68
69     public final Query buildQuery() throws RecognitionException, TokenStreamException {
70         Query query = null;
71         
72         
73         try { // for error handling
74
query=selectQuery();
75             {
76             if ((LA(1)==TOK_SEMIC)) {
77                 match(TOK_SEMIC);
78             }
79             else if ((LA(1)==EOF)) {
80             }
81             else {
82                 throw new NoViableAltException(LT(1), getFilename());
83             }
84             
85             }
86         }
87         catch (RecognitionException ex) {
88             reportError(ex);
89             recover(ex,_tokenSet_0);
90         }
91         return query;
92     }
93     
94     public final QueryByCriteria selectQuery() throws RecognitionException, TokenStreamException {
95         QueryByCriteria query = null;
96         
97         
98         try { // for error handling
99

100             Class JavaDoc clazz = null;
101             Criteria criteria = new Criteria();
102             String JavaDoc[] projectionAttrs;
103             boolean distinct = false;
104             
105             match(LITERAL_select);
106             {
107             if ((LA(1)==LITERAL_distinct)) {
108                 match(LITERAL_distinct);
109                 
110                 distinct = true;
111                 
112             }
113             else if ((LA(1)==TOK_STAR||LA(1)==Identifier)) {
114             }
115             else {
116                 throw new NoViableAltException(LT(1), getFilename());
117             }
118             
119             }
120             projectionAttrs=projectionAttributes();
121             match(LITERAL_from);
122             clazz=fromClause();
123             {
124             if ((LA(1)==LITERAL_where)) {
125                 match(LITERAL_where);
126                 whereClause(criteria);
127             }
128             else if ((_tokenSet_1.member(LA(1)))) {
129             }
130             else {
131                 throw new NoViableAltException(LT(1), getFilename());
132             }
133             
134             }
135             
136             if (clazz != null)
137             {
138             if (projectionAttrs[0].indexOf('.') < 0)
139             {
140             query = QueryFactory.newQuery(clazz, criteria, distinct);
141             }
142             else
143             {
144             ClassDescriptor cld = MetadataManager.getInstance().getRepository().getDescriptorFor(clazz);
145             for (int i = 0; i < projectionAttrs.length; i++)
146             {
147             projectionAttrs[i] = projectionAttrs[i].substring(projectionAttrs[i].indexOf('.') + 1);
148             }
149             
150             ArrayList JavaDoc descs = cld.getAttributeDescriptorsForPath(projectionAttrs[0]);
151             int pathLen = descs.size();
152             
153             if ((pathLen > 0) && (descs.get(pathLen - 1) instanceof ObjectReferenceDescriptor))
154             {
155             ObjectReferenceDescriptor ord =
156             ((ObjectReferenceDescriptor) descs.get(pathLen - 1));
157             query = QueryFactory.newQuery(clazz, criteria, distinct);
158             query.setObjectProjectionAttribute(projectionAttrs[0],
159             ord.getItemClass());
160             }
161             else
162             {
163             query = QueryFactory.newReportQuery(clazz, projectionAttrs, criteria, distinct);
164             }
165             }
166             }
167             
168             {
169             if ((LA(1)==LITERAL_order)) {
170                 match(LITERAL_order);
171                 match(LITERAL_by);
172                 orderClause(query);
173             }
174             else if ((_tokenSet_2.member(LA(1)))) {
175             }
176             else {
177                 throw new NoViableAltException(LT(1), getFilename());
178             }
179             
180             }
181             {
182             if ((LA(1)==LITERAL_group)) {
183                 match(LITERAL_group);
184                 match(LITERAL_by);
185                 groupClause(query);
186             }
187             else if ((_tokenSet_3.member(LA(1)))) {
188             }
189             else {
190                 throw new NoViableAltException(LT(1), getFilename());
191             }
192             
193             }
194             {
195             if ((LA(1)==LITERAL_prefetch)) {
196                 match(LITERAL_prefetch);
197                 prefetchClause(query);
198             }
199             else if ((LA(1)==EOF||LA(1)==TOK_RPAREN||LA(1)==TOK_SEMIC)) {
200             }
201             else {
202                 throw new NoViableAltException(LT(1), getFilename());
203             }
204             
205             }
206         }
207         catch (RecognitionException ex) {
208             reportError(ex);
209             recover(ex,_tokenSet_4);
210         }
211         return query;
212     }
213     
214     public final String JavaDoc[] projectionAttributes() throws RecognitionException, TokenStreamException {
215         String JavaDoc[] projectionAttrs = null;
216         
217         Token id = null;
218         Token id1 = null;
219         
220         try { // for error handling
221

222             String JavaDoc first = null;
223             ArrayList JavaDoc list = null;
224             
225             {
226             if ((LA(1)==Identifier)) {
227                 id = LT(1);
228                 match(Identifier);
229                 {
230                 
231                 first = id.getText();
232                 
233                 }
234                 {
235                 _loop80:
236                 do {
237                     if ((LA(1)==TOK_COMMA)) {
238                         match(TOK_COMMA);
239                         id1 = LT(1);
240                         match(Identifier);
241                         {
242                         
243                         if (list == null)
244                         {
245                         list = new ArrayList JavaDoc();
246                         list.add(first);
247                         }
248                         list.add(id1.getText());
249                         
250                         }
251                     }
252                     else {
253                         break _loop80;
254                     }
255                     
256                 } while (true);
257                 }
258             }
259             else if ((LA(1)==TOK_STAR)) {
260                 match(TOK_STAR);
261             }
262             else {
263                 throw new NoViableAltException(LT(1), getFilename());
264             }
265             
266             }
267             
268             if (list == null)
269             {
270             projectionAttrs = new String JavaDoc[] {first};
271             }
272             else
273             {
274             projectionAttrs = (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
275             }
276             
277             
278         }
279         catch (RecognitionException ex) {
280             reportError(ex);
281             recover(ex,_tokenSet_5);
282         }
283         return projectionAttrs;
284     }
285     
286     public final Class JavaDoc fromClause() throws RecognitionException, TokenStreamException {
287         Class JavaDoc clazz = null;
288         
289         Token id = null;
290         
291         try { // for error handling
292
id = LT(1);
293             match(Identifier);
294             
295             try {
296             clazz = ClassHelper.getClass(id.getText());
297             } catch (Exception JavaDoc e) {
298             }
299             
300         }
301         catch (RecognitionException ex) {
302             reportError(ex);
303             recover(ex,_tokenSet_6);
304         }
305         return clazz;
306     }
307     
308     public final void whereClause(
309         Criteria criteria
310     ) throws RecognitionException, TokenStreamException {
311         
312         
313         try { // for error handling
314
orExpr(criteria);
315         }
316         catch (RecognitionException ex) {
317             reportError(ex);
318             recover(ex,_tokenSet_7);
319         }
320     }
321     
322     public final void orderClause(
323         QueryByCriteria query
324     ) throws RecognitionException, TokenStreamException {
325         
326         
327         try { // for error handling
328
sortCriterion(query);
329             {
330             _loop83:
331             do {
332                 if ((LA(1)==TOK_COMMA)) {
333                     match(TOK_COMMA);
334                     sortCriterion(query);
335                 }
336                 else {
337                     break _loop83;
338                 }
339                 
340             } while (true);
341             }
342         }
343         catch (RecognitionException ex) {
344             reportError(ex);
345             recover(ex,_tokenSet_2);
346         }
347     }
348     
349     public final void groupClause(
350         QueryByCriteria query
351     ) throws RecognitionException, TokenStreamException {
352         
353         
354         try { // for error handling
355
groupCriterion(query);
356             {
357             _loop89:
358             do {
359                 if ((LA(1)==TOK_COMMA)) {
360                     match(TOK_COMMA);
361                     groupCriterion(query);
362                 }
363                 else {
364                     break _loop89;
365                 }
366                 
367             } while (true);
368             }
369         }
370         catch (RecognitionException ex) {
371             reportError(ex);
372             recover(ex,_tokenSet_3);
373         }
374     }
375     
376     public final void prefetchClause(
377         QueryByCriteria query
378     ) throws RecognitionException, TokenStreamException {
379         
380         
381         try { // for error handling
382
prefetchCriterion(query);
383             {
384             _loop93:
385             do {
386                 if ((LA(1)==TOK_COMMA)) {
387                     match(TOK_COMMA);
388                     prefetchCriterion(query);
389                 }
390                 else {
391                     break _loop93;
392                 }
393                 
394             } while (true);
395             }
396         }
397         catch (RecognitionException ex) {
398             reportError(ex);
399             recover(ex,_tokenSet_4);
400         }
401     }
402     
403     public final Query existsQuery() throws RecognitionException, TokenStreamException {
404         Query query = null;
405         
406         
407         try { // for error handling
408

409             Class JavaDoc clazz = null;
410             Criteria criteria = new Criteria();
411             
412             match(LITERAL_exists);
413             projectionAttributes();
414             match(LITERAL_in);
415             clazz=fromClause();
416             {
417             if ((LA(1)==TOK_COLON)) {
418                 match(TOK_COLON);
419                 whereClause(criteria);
420             }
421             else if ((_tokenSet_7.member(LA(1)))) {
422             }
423             else {
424                 throw new NoViableAltException(LT(1), getFilename());
425             }
426             
427             }
428             
429             if (clazz != null) {
430             query = QueryFactory.newQuery(clazz, criteria);
431             }
432                     
433         }
434         catch (RecognitionException ex) {
435             reportError(ex);
436             recover(ex,_tokenSet_7);
437         }
438         return query;
439     }
440     
441     public final void orExpr(
442         Criteria criteria
443     ) throws RecognitionException, TokenStreamException {
444         
445         
446         try { // for error handling
447
andExpr(criteria);
448             {
449             _loop97:
450             do {
451                 if ((LA(1)==LITERAL_or) && (_tokenSet_8.member(LA(2))) && (_tokenSet_9.member(LA(3)))) {
452                     match(LITERAL_or);
453                     Criteria orCriteria = new Criteria();
454                     andExpr(orCriteria);
455                     criteria.addOrCriteria(orCriteria);
456                 }
457                 else {
458                     break _loop97;
459                 }
460                 
461             } while (true);
462             }
463         }
464         catch (RecognitionException ex) {
465             reportError(ex);
466             recover(ex,_tokenSet_7);
467         }
468     }
469     
470     public final void sortCriterion(
471         QueryByCriteria query
472     ) throws RecognitionException, TokenStreamException {
473         
474         Token id = null;
475         
476         try { // for error handling
477
boolean descending = false;
478             id = LT(1);
479             match(Identifier);
480             {
481             if ((LA(1)==LITERAL_asc||LA(1)==LITERAL_desc)) {
482                 {
483                 if ((LA(1)==LITERAL_asc)) {
484                     match(LITERAL_asc);
485                     descending = false;
486                 }
487                 else if ((LA(1)==LITERAL_desc)) {
488                     match(LITERAL_desc);
489                     descending = true;
490                 }
491                 else {
492                     throw new NoViableAltException(LT(1), getFilename());
493                 }
494                 
495                 }
496             }
497             else if ((_tokenSet_10.member(LA(1)))) {
498             }
499             else {
500                 throw new NoViableAltException(LT(1), getFilename());
501             }
502             
503             }
504             
505             if (descending) {
506             query.addOrderByDescending(id.getText());
507             } else {
508             query.addOrderByAscending(id.getText());
509             }
510             
511         }
512         catch (RecognitionException ex) {
513             reportError(ex);
514             recover(ex,_tokenSet_10);
515         }
516     }
517     
518     public final void groupCriterion(
519         QueryByCriteria query
520     ) throws RecognitionException, TokenStreamException {
521         
522         Token id = null;
523         
524         try { // for error handling
525
id = LT(1);
526             match(Identifier);
527             
528             query.addGroupBy(id.getText());
529             
530         }
531         catch (RecognitionException ex) {
532             reportError(ex);
533             recover(ex,_tokenSet_11);
534         }
535     }
536     
537     public final void prefetchCriterion(
538         QueryByCriteria query
539     ) throws RecognitionException, TokenStreamException {
540         
541         Token id = null;
542         
543         try { // for error handling
544
id = LT(1);
545             match(Identifier);
546             
547             query.addPrefetchedRelationship(id.getText());
548             
549         }
550         catch (RecognitionException ex) {
551             reportError(ex);
552             recover(ex,_tokenSet_12);
553         }
554     }
555     
556     public final void andExpr(
557         Criteria criteria
558     ) throws RecognitionException, TokenStreamException {
559         
560         
561         try { // for error handling
562
quantifierExpr(criteria);
563             {
564             _loop100:
565             do {
566                 if ((LA(1)==LITERAL_and) && (_tokenSet_8.member(LA(2))) && (_tokenSet_9.member(LA(3)))) {
567                     match(LITERAL_and);
568                     Criteria andCriteria = new Criteria();
569                     quantifierExpr(andCriteria);
570                     criteria.addAndCriteria(andCriteria);
571                 }
572                 else {
573                     break _loop100;
574                 }
575                 
576             } while (true);
577             }
578         }
579         catch (RecognitionException ex) {
580             reportError(ex);
581             recover(ex,_tokenSet_7);
582         }
583     }
584     
585     public final void quantifierExpr(
586         Criteria criteria
587     ) throws RecognitionException, TokenStreamException {
588         
589         
590         try { // for error handling
591
switch ( LA(1)) {
592             case TOK_LPAREN:
593             {
594                 match(TOK_LPAREN);
595                 orExpr(criteria);
596                 match(TOK_RPAREN);
597                 break;
598             }
599             case LITERAL_is_undefined:
600             case LITERAL_is_defined:
601             {
602                 undefinedExpr(criteria);
603                 break;
604             }
605             case LITERAL_exists:
606             case LITERAL_not:
607             {
608                 existsExpr(criteria);
609                 break;
610             }
611             default:
612                 if ((LA(1)==Identifier) && (_tokenSet_13.member(LA(2)))) {
613                     equalityExpr(criteria);
614                 }
615                 else if ((LA(1)==Identifier) && (LA(2)==LITERAL_not||LA(2)==LITERAL_like) && (_tokenSet_14.member(LA(3)))) {
616                     likeExpr(criteria);
617                 }
618                 else if ((LA(1)==Identifier) && (LA(2)==LITERAL_not||LA(2)==LITERAL_between) && (_tokenSet_15.member(LA(3)))) {
619                     betweenExpr(criteria);
620                 }
621                 else if ((LA(1)==Identifier) && (LA(2)==LITERAL_in||LA(2)==LITERAL_not) && (LA(3)==TOK_LPAREN||LA(3)==LITERAL_in||LA(3)==LITERAL_list)) {
622                     inExpr(criteria);
623                 }
624             else {
625                 throw new NoViableAltException(LT(1), getFilename());
626             }
627             }
628         }
629         catch (RecognitionException ex) {
630             reportError(ex);
631             recover(ex,_tokenSet_7);
632         }
633     }
634     
635     public final void equalityExpr(
636         Criteria criteria
637     ) throws RecognitionException, TokenStreamException {
638         
639         Token id = null;
640         
641         try { // for error handling
642

643                 Object JavaDoc value = null;
644             
645             id = LT(1);
646             match(Identifier);
647             {
648             {
649             switch ( LA(1)) {
650             case TOK_EQ:
651             {
652                 match(TOK_EQ);
653                 {
654                 if ((LA(1)==LITERAL_nil)) {
655                     match(LITERAL_nil);
656                     criteria.addIsNull(id.getText());
657                 }
658                 else if ((_tokenSet_16.member(LA(1)))) {
659                     value=literal();
660                     criteria.addEqualTo(id.getText(), value);
661                 }
662                 else {
663                     throw new NoViableAltException(LT(1), getFilename());
664                 }
665                 
666                 }
667                 break;
668             }
669             case TOK_NE:
670             {
671                 match(TOK_NE);
672                 {
673                 if ((LA(1)==LITERAL_nil)) {
674                     match(LITERAL_nil);
675                     criteria.addNotNull(id.getText());
676                 }
677                 else if ((_tokenSet_16.member(LA(1)))) {
678                     value=literal();
679                     criteria.addNotEqualTo(id.getText(), value);
680                 }
681                 else {
682                     throw new NoViableAltException(LT(1), getFilename());
683                 }
684                 
685                 }
686                 break;
687             }
688             case TOK_NE2:
689             {
690                 match(TOK_NE2);
691                 {
692                 if ((LA(1)==LITERAL_nil)) {
693                     match(LITERAL_nil);
694                     criteria.addNotNull(id.getText());
695                 }
696                 else if ((_tokenSet_16.member(LA(1)))) {
697                     value=literal();
698                     criteria.addNotEqualTo(id.getText(), value);
699                 }
700                 else {
701                     throw new NoViableAltException(LT(1), getFilename());
702                 }
703                 
704                 }
705                 break;
706             }
707             case TOK_LT:
708             {
709                 match(TOK_LT);
710                 value=literal();
711                 criteria.addLessThan(id.getText(), value);
712                 break;
713             }
714             case TOK_GT:
715             {
716                 match(TOK_GT);
717                 value=literal();
718                 criteria.addGreaterThan(id.getText(), value);
719                 break;
720             }
721             case TOK_LE:
722             {
723                 match(TOK_LE);
724                 value=literal();
725                 criteria.addLessOrEqualThan(id.getText(), value);
726                 break;
727             }
728             case TOK_GE:
729             {
730                 match(TOK_GE);
731                 value=literal();
732                 criteria.addGreaterOrEqualThan(id.getText(), value);
733                 break;
734             }
735             default:
736             {
737                 throw new NoViableAltException(LT(1), getFilename());
738             }
739             }
740             }
741             }
742         }
743         catch (RecognitionException ex) {
744             reportError(ex);
745             recover(ex,_tokenSet_7);
746         }
747     }
748     
749     public final void likeExpr(
750         Criteria criteria
751     ) throws RecognitionException, TokenStreamException {
752         
753         Token id = null;
754         
755         try { // for error handling
756

757             boolean negative = false;
758             Object JavaDoc value = null;
759             
760             id = LT(1);
761             match(Identifier);
762             {
763             if ((LA(1)==LITERAL_not)) {
764                 match(LITERAL_not);
765                 negative = true;
766             }
767             else if ((LA(1)==LITERAL_like)) {
768             }
769             else {
770                 throw new NoViableAltException(LT(1), getFilename());
771             }
772             
773             }
774             match(LITERAL_like);
775             value=literal();
776             
777             if (negative) {
778             criteria.addNotLike(id.getText(), value);
779             } else {
780             criteria.addLike(id.getText(), value);
781             }
782             
783         }
784         catch (RecognitionException ex) {
785             reportError(ex);
786             recover(ex,_tokenSet_7);
787         }
788     }
789     
790     public final void undefinedExpr(
791         Criteria criteria
792     ) throws RecognitionException, TokenStreamException {
793         
794         Token id = null;
795         
796         try { // for error handling
797
boolean negative = false;
798             {
799             if ((LA(1)==LITERAL_is_undefined)) {
800                 match(LITERAL_is_undefined);
801                 negative = false;
802             }
803             else if ((LA(1)==LITERAL_is_defined)) {
804                 match(LITERAL_is_defined);
805                 negative = true;
806             }
807             else {
808                 throw new NoViableAltException(LT(1), getFilename());
809             }
810             
811             }
812             match(TOK_LPAREN);
813             id = LT(1);
814             match(Identifier);
815             match(TOK_RPAREN);
816             
817             if (negative) {
818             criteria.addNotNull(id.getText());
819             } else {
820             criteria.addIsNull(id.getText());
821             }
822             
823         }
824         catch (RecognitionException ex) {
825             reportError(ex);
826             recover(ex,_tokenSet_7);
827         }
828     }
829     
830     public final void betweenExpr(
831         Criteria criteria
832     ) throws RecognitionException, TokenStreamException {
833         
834         Token id = null;
835         
836         try { // for error handling
837

838             boolean negative = false;
839             Object JavaDoc lower = null;
840             Object JavaDoc upper = null;
841             
842             id = LT(1);
843             match(Identifier);
844             {
845             if ((LA(1)==LITERAL_not)) {
846                 match(LITERAL_not);
847                 negative = true;
848             }
849             else if ((LA(1)==LITERAL_between)) {
850             }
851             else {
852                 throw new NoViableAltException(LT(1), getFilename());
853             }
854             
855             }
856             match(LITERAL_between);
857             lower=literal();
858             match(LITERAL_and);
859             upper=literal();
860             
861             if (negative) {
862             criteria.addNotBetween(id.getText(), lower, upper);
863             } else {
864             criteria.addBetween(id.getText(), lower, upper);
865             }
866             
867         }
868         catch (RecognitionException ex) {
869             reportError(ex);
870             recover(ex,_tokenSet_7);
871         }
872     }
873     
874     public final void inExpr(
875         Criteria criteria
876     ) throws RecognitionException, TokenStreamException {
877         
878         Token id = null;
879         
880         try { // for error handling
881

882                  boolean negative = false;
883                  Collection JavaDoc coll;
884             
885             id = LT(1);
886             match(Identifier);
887             {
888             if ((LA(1)==LITERAL_not)) {
889                 match(LITERAL_not);
890                 negative = true;
891             }
892             else if ((LA(1)==LITERAL_in)) {
893             }
894             else {
895                 throw new NoViableAltException(LT(1), getFilename());
896             }
897             
898             }
899             match(LITERAL_in);
900             {
901             if ((LA(1)==LITERAL_list)) {
902                 match(LITERAL_list);
903             }
904             else if ((LA(1)==TOK_LPAREN)) {
905             }
906             else {
907                 throw new NoViableAltException(LT(1), getFilename());
908             }
909             
910             }
911             coll=argList();
912             
913             if (negative) {
914             criteria.addNotIn(id.getText(), coll);
915             } else {
916             criteria.addIn(id.getText(), coll);
917             }
918             
919         }
920         catch (RecognitionException ex) {
921             reportError(ex);
922             recover(ex,_tokenSet_7);
923         }
924     }
925     
926     public final void existsExpr(
927         Criteria criteria
928     ) throws RecognitionException, TokenStreamException {
929         
930         
931         try { // for error handling
932

933             Query subQuery = null;
934             boolean negative = false;
935             
936             {
937             if ((LA(1)==LITERAL_not)) {
938                 match(LITERAL_not);
939                 negative = true;
940             }
941             else if ((LA(1)==LITERAL_exists)) {
942             }
943             else {
944                 throw new NoViableAltException(LT(1), getFilename());
945             }
946             
947             }
948             {
949             if ((LA(1)==LITERAL_exists) && (LA(2)==TOK_LPAREN)) {
950                 match(LITERAL_exists);
951                 match(TOK_LPAREN);
952                 subQuery=selectQuery();
953                 match(TOK_RPAREN);
954             }
955             else if ((LA(1)==LITERAL_exists) && (LA(2)==TOK_STAR||LA(2)==Identifier)) {
956                 subQuery=existsQuery();
957             }
958             else {
959                 throw new NoViableAltException(LT(1), getFilename());
960             }
961             
962             }
963             
964             if (negative) {
965             criteria.addNotExists(subQuery);
966             } else {
967             criteria.addExists(subQuery);
968             }
969             
970         }
971         catch (RecognitionException ex) {
972             reportError(ex);
973             recover(ex,_tokenSet_7);
974         }
975     }
976     
977     public final Object JavaDoc literal() throws RecognitionException, TokenStreamException {
978         Object JavaDoc value = null;
979         
980         Token tokInt = null;
981         Token tokADbl = null;
982         Token tokEDbl = null;
983         Token tokChar = null;
984         Token tokStr = null;
985         Token tokDate = null;
986         Token tokTime = null;
987         Token tokTs = null;
988         
989         try { // for error handling
990
switch ( LA(1)) {
991             case TOK_DOLLAR:
992             {
993                 match(TOK_DOLLAR);
994                 match(TOK_UNSIGNED_INTEGER);
995                 value = null;
996                 break;
997             }
998             case LITERAL_true:
999             {
1000                match(LITERAL_true);
1001                value = Boolean.TRUE;
1002                break;
1003            }
1004            case LITERAL_false:
1005            {
1006                match(LITERAL_false);
1007                value = Boolean.FALSE;
1008                break;
1009            }
1010            case TOK_UNSIGNED_INTEGER:
1011            {
1012                tokInt = LT(1);
1013                match(TOK_UNSIGNED_INTEGER);
1014                
1015                    try
1016                    {
1017                        value = Integer.valueOf(tokInt.getText());
1018                    }
1019                    catch (NumberFormatException JavaDoc ignored)
1020                    {
1021                        value = Long.valueOf(tokInt.getText());
1022                    }
1023                
1024                break;
1025            }
1026            case TOK_APPROXIMATE_NUMERIC_LITERAL:
1027            {
1028                tokADbl = LT(1);
1029                match(TOK_APPROXIMATE_NUMERIC_LITERAL);
1030                value = Double.valueOf(tokADbl.getText());
1031                break;
1032            }
1033            case TOK_EXACT_NUMERIC_LITERAL:
1034            {
1035                tokEDbl = LT(1);
1036                match(TOK_EXACT_NUMERIC_LITERAL);
1037                value = Double.valueOf(tokEDbl.getText());
1038                break;
1039            }
1040            case CharLiteral:
1041            {
1042                tokChar = LT(1);
1043                match(CharLiteral);
1044                value = new Character JavaDoc(tokChar.getText().charAt(0));
1045                break;
1046            }
1047            case StringLiteral:
1048            {
1049                tokStr = LT(1);
1050                match(StringLiteral);
1051                value = tokStr.getText();
1052                break;
1053            }
1054            case LITERAL_date:
1055            {
1056                match(LITERAL_date);
1057                tokDate = LT(1);
1058                match(StringLiteral);
1059                value = java.sql.Date.valueOf(tokDate.getText());
1060                break;
1061            }
1062            case LITERAL_time:
1063            {
1064                match(LITERAL_time);
1065                tokTime = LT(1);
1066                match(StringLiteral);
1067                value = java.sql.Time.valueOf(tokTime.getText());
1068                break;
1069            }
1070            case LITERAL_timestamp:
1071            {
1072                match(LITERAL_timestamp);
1073                tokTs = LT(1);
1074                match(StringLiteral);
1075                value = java.sql.Timestamp.valueOf(tokTs.getText());
1076                break;
1077            }
1078            default:
1079            {
1080                throw new NoViableAltException(LT(1), getFilename());
1081            }
1082            }
1083        }
1084        catch (RecognitionException ex) {
1085            reportError(ex);
1086            recover(ex,_tokenSet_17);
1087        }
1088        return value;
1089    }
1090    
1091    public final Collection JavaDoc argList() throws RecognitionException, TokenStreamException {
1092        Collection JavaDoc coll = null;
1093        
1094        
1095        try { // for error handling
1096

1097                    Collection JavaDoc temp = new Vector JavaDoc();
1098                    Object JavaDoc val;
1099                
1100            match(TOK_LPAREN);
1101            {
1102            if ((_tokenSet_16.member(LA(1)))) {
1103                val=literal();
1104                if (val != null) {temp.add(val);}
1105                {
1106                _loop124:
1107                do {
1108                    if ((LA(1)==TOK_COMMA)) {
1109                        match(TOK_COMMA);
1110                        val=literal();
1111                        if (val != null) {temp.add(val);}
1112                    }
1113                    else {
1114                        break _loop124;
1115                    }
1116                    
1117                } while (true);
1118                }
1119            }
1120            else if ((LA(1)==TOK_RPAREN)) {
1121            }
1122            else {
1123                throw new NoViableAltException(LT(1), getFilename());
1124            }
1125            
1126            }
1127            match(TOK_RPAREN);
1128            
1129                    if (!temp.isEmpty()) {coll = temp;}
1130                    
1131        }
1132        catch (RecognitionException ex) {
1133            reportError(ex);
1134            recover(ex,_tokenSet_7);
1135        }
1136        return coll;
1137    }
1138    
1139    
1140    public static final String JavaDoc[] _tokenNames = {
1141        "<0>",
1142        "EOF",
1143        "<2>",
1144        "NULL_TREE_LOOKAHEAD",
1145        "right parenthesis",
1146        "left parenthesis",
1147        "comma",
1148        "semicolon",
1149        "TOK_COLON",
1150        "dot",
1151        "dot",
1152        "operator",
1153        "comparison operator",
1154        "operator",
1155        "operator",
1156        "operator",
1157        "operator",
1158        "comparison operator",
1159        "comparison operator",
1160        "comparison operator",
1161        "comparison operator",
1162        "comparison operator",
1163        "comparison operator",
1164        "left bracket",
1165        "right bracket",
1166        "TOK_DOLLAR",
1167        "NameFirstCharacter",
1168        "NameCharacter",
1169        "Identifier",
1170        "TOK_UNSIGNED_INTEGER",
1171        "TOK_APPROXIMATE_NUMERIC_LITERAL",
1172        "numeric value",
1173        "character string",
1174        "character string",
1175        "WhiteSpace",
1176        "NewLine",
1177        "CommentLine",
1178        "MultiLineComment",
1179        "\"select\"",
1180        "\"distinct\"",
1181        "\"from\"",
1182        "\"where\"",
1183        "\"order\"",
1184        "\"by\"",
1185        "\"group\"",
1186        "\"prefetch\"",
1187        "\"exists\"",
1188        "\"in\"",
1189        "\"asc\"",
1190        "\"desc\"",
1191        "\"or\"",
1192        "\"and\"",
1193        "\"nil\"",
1194        "\"not\"",
1195        "\"list\"",
1196        "\"between\"",
1197        "\"is_undefined\"",
1198        "\"is_defined\"",
1199        "\"like\"",
1200        "\"true\"",
1201        "\"false\"",
1202        "\"date\"",
1203        "\"time\"",
1204        "\"timestamp\""
1205    };
1206    
1207    private static final long[] mk_tokenSet_0() {
1208        long[] data = { 2L, 0L};
1209        return data;
1210    }
1211    public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
1212    private static final long[] mk_tokenSet_1() {
1213        long[] data = { 57174604644498L, 0L};
1214        return data;
1215    }
1216    public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
1217    private static final long[] mk_tokenSet_2() {
1218        long[] data = { 52776558133394L, 0L};
1219        return data;
1220    }
1221    public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
1222    private static final long[] mk_tokenSet_3() {
1223        long[] data = { 35184372088978L, 0L};
1224        return data;
1225    }
1226    public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
1227    private static final long[] mk_tokenSet_4() {
1228        long[] data = { 146L, 0L};
1229        return data;
1230    }
1231    public static final BitSet _tokenSet_4 = new BitSet(mk_tokenSet_4());
1232    private static final long[] mk_tokenSet_5() {
1233        long[] data = { 141836999983104L, 0L};
1234        return data;
1235    }
1236    public static final BitSet _tokenSet_5 = new BitSet(mk_tokenSet_5());
1237    private static final long[] mk_tokenSet_6() {
1238        long[] data = { 3437073348428178L, 0L};
1239        return data;
1240    }
1241    public static final BitSet _tokenSet_6 = new BitSet(mk_tokenSet_6());
1242    private static final long[] mk_tokenSet_7() {
1243        long[] data = { 3434874325172370L, 0L};
1244        return data;
1245    }
1246    public static final BitSet _tokenSet_7 = new BitSet(mk_tokenSet_7());
1247    private static final long[] mk_tokenSet_8() {
1248        long[] data = { 225250350381137952L, 0L};
1249        return data;
1250    }
1251    public static final BitSet _tokenSet_8 = new BitSet(mk_tokenSet_8());
1252    private static final long[] mk_tokenSet_9() {
1253        long[] data = { 549650261048496160L, 0L};
1254        return data;
1255    }
1256    public static final BitSet _tokenSet_9 = new BitSet(mk_tokenSet_9());
1257    private static final long[] mk_tokenSet_10() {
1258        long[] data = { 52776558133458L, 0L};
1259        return data;
1260    }
1261    public static final BitSet _tokenSet_10 = new BitSet(mk_tokenSet_10());
1262    private static final long[] mk_tokenSet_11() {
1263        long[] data = { 35184372089042L, 0L};
1264        return data;
1265    }
1266    public static final BitSet _tokenSet_11 = new BitSet(mk_tokenSet_11());
1267    private static final long[] mk_tokenSet_12() {
1268        long[] data = { 210L, 0L};
1269        return data;
1270    }
1271    public static final BitSet _tokenSet_12 = new BitSet(mk_tokenSet_12());
1272    private static final long[] mk_tokenSet_13() {
1273        long[] data = { 8261632L, 0L};
1274        return data;
1275    }
1276    public static final BitSet _tokenSet_13 = new BitSet(mk_tokenSet_13());
1277    private static final long[] mk_tokenSet_14() {
1278        long[] data = { -288230359475159040L, 0L};
1279        return data;
1280    }
1281    public static final BitSet _tokenSet_14 = new BitSet(mk_tokenSet_14());
1282    private static final long[] mk_tokenSet_15() {
1283        long[] data = { -540431938607906816L, 0L};
1284        return data;
1285    }
1286    public static final BitSet _tokenSet_15 = new BitSet(mk_tokenSet_15());
1287    private static final long[] mk_tokenSet_16() {
1288        long[] data = { -576460735626870784L, 0L};
1289        return data;
1290    }
1291    public static final BitSet _tokenSet_16 = new BitSet(mk_tokenSet_16());
1292    private static final long[] mk_tokenSet_17() {
1293        long[] data = { 3434874325172434L, 0L};
1294        return data;
1295    }
1296    public static final BitSet _tokenSet_17 = new BitSet(mk_tokenSet_17());
1297    
1298    }
1299
Popular Tags