KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > query > ResultNode


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.query;
13
14 import com.versant.core.metadata.ClassMetaData;
15
16 /**
17  * A node that is created for queries with a non-null result spefied.
18  * This creates necc. metadata from the parsed structure to be used by the application.
19  */

20 public class ResultNode extends Node {
21     public static final int[] EMPTY_INT_ARRAY = new int[0];
22
23     private boolean distinct;
24     private int containsVarNodes = 0;
25     private int size;
26
27
28     public ResultNode(Node child) {
29         childList = child;
30     }
31
32     public boolean isDistinct() {
33         return distinct;
34     }
35
36     public void setDistinct(boolean distinct) {
37         this.distinct = distinct;
38     }
39
40     public String JavaDoc toString() {
41         return super.toString() + " distinct = " + distinct;
42     }
43
44     /**
45      * Resolve field refs and so on relative to the compiler. This must
46      * recursively resolve any child nodes.
47      */

48     public void resolve(QueryParser comp, ClassMetaData cmd, boolean ordering) {
49         for (Node n = childList; n != null; n = n.next) {
50             n.resolve(comp, cmd, ordering);
51             size++;
52         }
53     }
54
55     public int getResultSize() {
56         return size;
57     }
58
59     /**
60      * Abstract method to force all nodes to implement visitor pattern
61      */

62     public Field visit(MemVisitor visitor, Object JavaDoc obj) {
63         return null; //To change body of implemented methods use File | Settings | File Templates.
64
}
65
66     public boolean processForVarNodes() {
67         if (containsVarNodes == 0) {
68             if (containsVarNodeImp(this)) {
69                 containsVarNodes = 1;
70             } else {
71                 containsVarNodes = -1;
72             }
73         }
74         return (containsVarNodes == 1);
75     }
76
77     private boolean containsVarNodeImp(Node n) {
78         if (n == null) return false;
79         if (n instanceof VarNodeIF) {
80             ((VarNodeIF)n).setUsedInProjection(true);
81             return true;
82         }
83         if (n instanceof FieldNavNode) {
84             if (((FieldNavNode)n).var != null) {
85                 ((FieldNavNode)n).var.setUsedInProjection(true);
86                 return true;
87             }
88         }
89
90         if (n.childList != null) {
91             if (containsVarNodeImp(n.childList)) {
92                 return true;
93             }
94         }
95         for (Node nn = n.next; nn != null; nn = nn.next) {
96             if (containsVarNodeImp(nn)) return true;
97         }
98         return false;
99     }
100
101     public Object JavaDoc accept(NodeVisitor visitor, Object JavaDoc[] results) {
102         return visitor.visitResultNode(this, results);
103     }
104
105     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
106         return v.arriveResultNode(this, msg);
107     }
108 }
109
Popular Tags