001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.jdbc.kernel.exps;
020:
021: import java.sql.SQLException;
022:
023: import org.apache.openjpa.jdbc.sql.Result;
024: import org.apache.openjpa.jdbc.sql.SQLBuffer;
025: import org.apache.openjpa.jdbc.sql.Select;
026: import org.apache.openjpa.kernel.exps.ExpressionVisitor;
027: import org.apache.openjpa.meta.ClassMetaData;
028:
029: /**
030: * A variable in a filter. Typically, the {@link #initialize} and
031: * {@link #getJoins} methods of this value are not called. They are
032: * only called if the variable is bound but otherwise unused in the filter,
033: * in which case we must at least make the joins to the variable because the
034: * act of binding a variable should at least guarantee that an instance
035: * represting the variable could exist (i.e. the binding collection is not
036: * empty).
037: *
038: * @author Abe White
039: */
040: class Variable extends AbstractVal {
041:
042: private final String _name;
043: private final Class _type;
044: private ClassMetaData _meta;
045: private PCPath _path = null;
046: private Class _cast = null;
047:
048: /**
049: * Constructor. Supply variable name and type.
050: */
051: public Variable(String name, Class type) {
052: _name = name;
053: _type = type;
054: }
055:
056: /**
057: * Return the variable name.
058: */
059: public String getName() {
060: return _name;
061: }
062:
063: /**
064: * Return true if the variable is bound.
065: */
066: public boolean isBound() {
067: return _path != null;
068: }
069:
070: /**
071: * Return the path this variable is aliased to.
072: */
073: public PCPath getPCPath() {
074: return _path;
075: }
076:
077: /**
078: * Set the path this variable is aliased to.
079: */
080: public void setPCPath(PCPath path) {
081: _path = path;
082: }
083:
084: public ClassMetaData getMetaData() {
085: return _meta;
086: }
087:
088: public void setMetaData(ClassMetaData meta) {
089: _meta = meta;
090: }
091:
092: public boolean isVariable() {
093: return true;
094: }
095:
096: public Class getType() {
097: if (_cast != null)
098: return _cast;
099: return _type;
100: }
101:
102: public void setImplicitType(Class type) {
103: _cast = type;
104: if (_path != null)
105: _path.setImplicitType(type);
106: }
107:
108: public ExpState initialize(Select sel, ExpContext ctx, int flags) {
109: if (_path != null) {
110: _path.addVariableAction(this );
111: return _path.initialize(sel, ctx, flags | JOIN_REL);
112: }
113: return ExpState.NULL;
114: }
115:
116: public void select(Select sel, ExpContext ctx, ExpState state,
117: boolean pks) {
118: }
119:
120: public void selectColumns(Select sel, ExpContext ctx,
121: ExpState state, boolean pks) {
122: }
123:
124: public void groupBy(Select sel, ExpContext ctx, ExpState state) {
125: }
126:
127: public void orderBy(Select sel, ExpContext ctx, ExpState state,
128: boolean asc) {
129: }
130:
131: public Object load(ExpContext ctx, ExpState state, Result res)
132: throws SQLException {
133: return null;
134: }
135:
136: public void calculateValue(Select sel, ExpContext ctx,
137: ExpState state, Val other, ExpState otherState) {
138: if (_path != null)
139: _path.calculateValue(sel, ctx, state, other, otherState);
140: }
141:
142: public int length(Select sel, ExpContext ctx, ExpState state) {
143: return 0;
144: }
145:
146: public void appendTo(Select sel, ExpContext ctx, ExpState state,
147: SQLBuffer sql, int index) {
148: }
149:
150: public void appendIsEmpty(Select sel, ExpContext ctx,
151: ExpState state, SQLBuffer buf) {
152: }
153:
154: public void appendIsNotEmpty(Select sel, ExpContext ctx,
155: ExpState state, SQLBuffer buf) {
156: }
157:
158: public void appendSize(Select sel, ExpContext ctx, ExpState state,
159: SQLBuffer buf) {
160: }
161:
162: public void appendIsNull(Select sel, ExpContext ctx,
163: ExpState state, SQLBuffer buf) {
164: }
165:
166: public void appendIsNotNull(Select sel, ExpContext ctx,
167: ExpState state, SQLBuffer buf) {
168: }
169:
170: public void acceptVisit(ExpressionVisitor visitor) {
171: visitor.enter(this);
172: if (_path != null)
173: _path.acceptVisit(visitor);
174: visitor.exit(this);
175: }
176: }
|