001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo.query;
012:
013: import com.versant.core.metadata.ClassMetaData;
014: import com.versant.core.metadata.FieldMetaData;
015: import com.versant.core.common.Debug;
016: import com.versant.core.common.CmdBitSet;
017:
018: /**
019: * A variable declaration.
020: */
021: public class VarNode extends LeafNode implements VarNodeIF {
022:
023: private String type;
024: private String identifier;
025: private Class cls;
026: private ClassMetaData cmd;
027: private Object storeExtent;
028: private FieldMetaData fmd;
029: private Object fieldExtent;
030: public boolean bound;
031:
032: /**
033: * If this variable is present in the result projection
034: */
035: private boolean usedInProjection;
036:
037: public VarNode() {
038: }
039:
040: public Object accept(NodeVisitor visitor, Object[] results) {
041: return visitor.visitVarNode(this , results);
042: }
043:
044: public String toString() {
045: StringBuffer s = new StringBuffer();
046: s.append(super .toString());
047: s.append(' ');
048: if (cls != null)
049: s.append(cls);
050: else
051: s.append(type);
052: s.append(' ');
053: s.append(identifier);
054: s.append(' ');
055: s.append(bound ? "bound" : "unbound");
056: return s.toString();
057: }
058:
059: public Field visit(MemVisitor visitor, Object obj) {
060: return visitor.visitVarNode(this , obj);
061: }
062:
063: public String getType() {
064: return type;
065: }
066:
067: public void setType(String type) {
068: this .type = type;
069: }
070:
071: public String getIdentifier() {
072: return identifier;
073: }
074:
075: public void setIdentifier(String identifier) {
076: this .identifier = identifier;
077: }
078:
079: public Class getCls() {
080: return cls;
081: }
082:
083: public void setCls(Class cls) {
084: this .cls = cls;
085: }
086:
087: public ClassMetaData getCmd() {
088: return cmd;
089: }
090:
091: public void setCmd(ClassMetaData cmd) {
092: this .cmd = cmd;
093: }
094:
095: public void resolve(QueryParser comp) {
096: cls = comp.resolveVarType(type);
097: cmd = comp.getCMD(cls);
098: }
099:
100: public Object getStoreExtent() {
101: return storeExtent;
102: }
103:
104: public void setStoreExtent(Object storeExtent) {
105: this .storeExtent = storeExtent;
106: }
107:
108: public void setFieldExtent(Object fieldExtent) {
109: this .fieldExtent = fieldExtent;
110: }
111:
112: public void setFmd(FieldMetaData fmd) {
113: this .fmd = fmd;
114: }
115:
116: /**
117: * Insert a VarBindingNode for us into the tree before sibling (i.e.
118: * sibling.parent == varbindingnode.parent && varbindingnode.next = sibling).
119: * This is used to "bind" unbound variables to the extent of the variables
120: * class.
121: */
122: public void insertVarBindingNode(Node sibling) {
123: // 'and' our sibling with a VarBindingNode to bind us to the
124: // variables extent
125: if (sibling.parent.getClass() == AndNode.class) {
126: AndNode and = (AndNode) sibling.parent;
127: and.insertChildBefore(sibling, new VarBindingNode(this ));
128: } else {
129: AndNode and = new AndNode();
130: sibling.parent.replaceChild(sibling, and);
131: and.childList = new VarBindingNode(this );
132: and.childList.parent = and;
133: and.childList.next = sibling;
134: sibling.parent = and;
135: }
136: bound = true;
137: if (Debug.DEBUG) {
138: System.out.println("### Added VarBindingNode for " + this );
139: }
140: }
141:
142: /**
143: * Implement this in nodes to udpate the ClassMetaData depency of the graph.
144: * This is used for query eviction.
145: *
146: * @param bitSet
147: */
148: public void updateEvictionDependency(CmdBitSet bitSet) {
149: if (cmd == null)
150: return;
151: bitSet.addPlus(cmd);
152: }
153:
154: public void setUsedInProjection(boolean usedInProjection) {
155: this .usedInProjection = usedInProjection;
156: }
157:
158: public boolean isUsedInProjection() {
159: return usedInProjection;
160: }
161:
162: public VarNode getVarNode() {
163: return this ;
164: }
165:
166: public Object getFieldExtent() {
167: return fieldExtent;
168: }
169:
170: public FieldMetaData getFmd() {
171: return fmd;
172: }
173:
174: public Object arrive(NodeVisitor v, Object msg) {
175: return v.arriveVarNode(this, msg);
176: }
177: }
|