KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.versant.core.metadata.FieldMetaData;
16 import com.versant.core.common.Debug;
17 import com.versant.core.common.CmdBitSet;
18
19 /**
20  * A variable declaration.
21  */

22 public class VarNode extends LeafNode implements VarNodeIF {
23
24     private String JavaDoc type;
25     private String JavaDoc identifier;
26     private Class JavaDoc cls;
27     private ClassMetaData cmd;
28     private Object JavaDoc storeExtent;
29     private FieldMetaData fmd;
30     private Object JavaDoc fieldExtent;
31     public boolean bound;
32
33     /**
34      * If this variable is present in the result projection
35      */

36     private boolean usedInProjection;
37
38     public VarNode() {
39     }
40
41     public Object JavaDoc accept(NodeVisitor visitor, Object JavaDoc[] results) {
42       return visitor.visitVarNode(this, results);
43     }
44
45     public String JavaDoc toString() {
46         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
47         s.append(super.toString());
48         s.append(' ');
49         if (cls != null) s.append(cls);
50         else s.append(type);
51         s.append(' ');
52         s.append(identifier);
53         s.append(' ');
54         s.append(bound ? "bound" : "unbound");
55         return s.toString();
56     }
57
58     public Field visit(MemVisitor visitor, Object JavaDoc obj) {
59         return visitor.visitVarNode(this, obj);
60     }
61
62     public String JavaDoc getType() {
63         return type;
64     }
65
66     public void setType(String JavaDoc type) {
67         this.type = type;
68     }
69
70     public String JavaDoc getIdentifier() {
71         return identifier;
72     }
73
74     public void setIdentifier(String JavaDoc identifier) {
75         this.identifier = identifier;
76     }
77
78     public Class JavaDoc getCls() {
79         return cls;
80     }
81
82     public void setCls(Class JavaDoc cls) {
83         this.cls = cls;
84     }
85
86     public ClassMetaData getCmd() {
87         return cmd;
88     }
89
90     public void setCmd(ClassMetaData cmd) {
91         this.cmd = cmd;
92     }
93
94     public void resolve(QueryParser comp) {
95         cls = comp.resolveVarType(type);
96         cmd = comp.getCMD(cls);
97     }
98
99     public Object JavaDoc getStoreExtent() {
100         return storeExtent;
101     }
102
103     public void setStoreExtent(Object JavaDoc storeExtent) {
104         this.storeExtent = storeExtent;
105     }
106
107     public void setFieldExtent(Object JavaDoc fieldExtent) {
108         this.fieldExtent = fieldExtent;
109     }
110
111     public void setFmd(FieldMetaData fmd) {
112         this.fmd = fmd;
113     }
114
115     /**
116      * Insert a VarBindingNode for us into the tree before sibling (i.e.
117      * sibling.parent == varbindingnode.parent && varbindingnode.next = sibling).
118      * This is used to "bind" unbound variables to the extent of the variables
119      * class.
120      */

121     public void insertVarBindingNode(Node sibling) {
122         // 'and' our sibling with a VarBindingNode to bind us to the
123
// variables extent
124
if (sibling.parent.getClass() == AndNode.class) {
125             AndNode and = (AndNode)sibling.parent;
126             and.insertChildBefore(sibling, new VarBindingNode(this));
127         } else {
128             AndNode and = new AndNode();
129             sibling.parent.replaceChild(sibling, and);
130             and.childList = new VarBindingNode(this);
131             and.childList.parent = and;
132             and.childList.next = sibling;
133             sibling.parent = and;
134         }
135         bound = true;
136         if (Debug.DEBUG) {
137             System.out.println("### Added VarBindingNode for " + this);
138         }
139     }
140
141     /**
142      * Implement this in nodes to udpate the ClassMetaData depency of the graph.
143      * This is used for query eviction.
144      *
145      * @param bitSet
146      */

147     public void updateEvictionDependency(CmdBitSet bitSet) {
148         if (cmd == null) return;
149         bitSet.addPlus(cmd);
150     }
151
152     public void setUsedInProjection(boolean usedInProjection) {
153         this.usedInProjection = usedInProjection;
154     }
155
156     public boolean isUsedInProjection() {
157         return usedInProjection;
158     }
159
160     public VarNode getVarNode() {
161         return this;
162     }
163
164     public Object JavaDoc getFieldExtent() {
165         return fieldExtent;
166     }
167
168     public FieldMetaData getFmd() {
169         return fmd;
170     }
171
172     public Object JavaDoc arrive(NodeVisitor v, Object JavaDoc msg) {
173         return v.arriveVarNode(this, msg);
174     }
175 }
176
Popular Tags