From jdo-commits-return-174-apmail-db-jdo-commits-archive=www.apache.org@db.apache.org Sat Mar 19 05:00:34 2005 Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 82350 invoked from network); 19 Mar 2005 05:00:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Mar 2005 05:00:34 -0000 Received: (qmail 83332 invoked by uid 500); 19 Mar 2005 05:00:34 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Delivered-To: moderator for jdo-commits@db.apache.org Received: (qmail 82873 invoked by uid 99); 19 Mar 2005 01:06:11 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Message-ID: <20050319010605.28141.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sat, 19 Mar 2005 01:06:05 -0000 Subject: svn commit: r158176 [32/79] - in incubator/jdo/trunk/ri11: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/ejb/ src/java/org/apache/jdo/enhancer/ src/java/org/apache/jdo/impl/ src/java/org/apache/jdo/impl/enhancer/ src/java/org/apache/jdo/impl/enhancer/classfile/ src/java/org/apache/jdo/impl/enhancer/core/ src/java/org/apache/jdo/impl/enhancer/generator/ src/java/org/apache/jdo/impl/enhancer/meta/ src/java/org/apache/jdo/impl/enhancer/meta/model/ src/java/org/apache/jdo/impl/enhancer/meta/prop/ src/java/org/apache/jdo/impl/enhancer/meta/util/ src/java/org/apache/jdo/impl/enhancer/util/ src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/jdoql/jdoqlc/ src/java/org/apache/jdo/impl/jdoql/scope/ src/java/org/apache/jdo/impl/jdoql/tree/ src/java/org/apache/jdo/impl/model/ src/java/org/apache/jdo/impl/model/java/ src/java/org/apache/jdo/impl/model/java/runtime/ src/java/org/apache/jdo/impl/model/jdo/ src/java/org/apache/jdo/impl/model/jdo/caching/ src/java/org/apache/jdo/impl/model/jdo/util/ src/java/org/apache/jdo/impl/model/jdo/xml/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/impl/sco/ src/java/org/apache/jdo/impl/state/ src/java/org/apache/jdo/jdoql/ src/java/org/apache/jdo/jdoql/tree/ src/java/org/apache/jdo/model/ src/java/org/apache/jdo/model/java/ src/java/org/apache/jdo/model/jdo/ src/java/org/apache/jdo/pm/ src/java/org/apache/jdo/sco/ src/java/org/apache/jdo/state/ src/java/org/apache/jdo/store/ src/java/org/apache/jdo/util/ test/ test/conf/ test/enhancer/ test/enhancer/sempdept/ test/enhancer/sempdept/src/ test/enhancer/sempdept/src/empdept/ test/fsuid2/ test/fsuid2/org/ test/fsuid2/org/apache/ test/fsuid2/org/apache/jdo/ test/fsuid2/org/apache/jdo/pc/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/impl/ test/java/org/apache/jdo/impl/fostore/ test/java/org/apache/jdo/pc/ test/java/org/apache/jdo/pc/appid/ test/java/org/apache/jdo/pc/empdept/ test/java/org/apache/jdo/pc/serializable/ test/java/org/apache/jdo/pc/xempdept/ test/java/org/apache/jdo/test/ test/java/org/apache/jdo/test/query/ test/java/org/apache/jdo/test/util/ test/jdo/ test/jdo/org/ test/jdo/org/apache/ test/jdo/org/apache/jdo/ test/jdo/org/apache/jdo/pc/ test/jdo/org/apache/jdo/pc/appid/ test/jdo/org/apache/jdo/pc/empdept/ test/jdo/org/apache/jdo/pc/serializable/ test/jdo/org/apache/jdo/pc/xempdept/ xdocs/ To: jdo-commits@db.apache.org From: mbo@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/V= ariableChecker.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/jdoqlc/VariableChecker.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Vari= ableChecker.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/jdoqlc/Vari= ableChecker.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,290 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * VariableChecker.java + * + * Created on September 12, 2001 + */ + +package org.apache.jdo.impl.jdoql.jdoqlc; + +import java.util.Map; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; +import java.util.HashSet; + +import javax.jdo.JDOUnsupportedOptionException; +import javax.jdo.JDOFatalInternalException; + +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.util.I18NHelper; + + +/** + * Checks variable declarations/application. + * + * @author Michael Bouschen + * @version 0.1 + */ +public class VariableChecker +{ + /** I18N support */ + protected final static I18NHelper msg =3D I18NHelper.getInstance( + "org.apache.jdo.impl.jdoql.Bundle", VariableChecker.class.getClass= Loader()); //NOI18N + + /** + * A VarInfo consists of two info fields: + * - constraint: the variable is constraint with the specified expr + * - used: the variable is used + */ + static class VarInfo + { + /** + * The constraint expression. + */ + JDOQLAST constraint; + + /** + * Set of JDOQLAST nodes denoting an access of this variable. + */ + Set used; + + /** + * Dependency for this variable.=20 + * The constraint for this variable may use another variable.=20 + */ + String dependsOn; + + /** + * Flag whether this varInfo is checked already (see checkConstrai= nts) + */ + int status; + + static final int UNCHECKED =3D 0; + static final int IN_PROGRESS =3D 1; + static final int CHECKED =3D 2; + + VarInfo() + { + this.constraint =3D null; + this.used =3D new HashSet(); + this.dependsOn =3D null; + this.status =3D UNCHECKED; + } + + VarInfo(VarInfo other) + { + this.constraint =3D other.constraint; + this.used =3D new HashSet(other.used); + this.dependsOn =3D other.dependsOn; + this.status =3D other.status; + } + } + + /** + * Map of variable infos + */ + protected Map varInfos; + + /** + * Create an empty variable table + */ + public VariableChecker() + { + varInfos =3D new HashMap(); + } + + /** + * Create a variable table initialized with the entries of the other v= ariable table. + * The constructor creates copies of the values stored in the map (ins= tances of class VarInfo). + */ + public VariableChecker(VariableChecker other) + { + varInfos =3D new HashMap(); + for (Iterator i =3D other.varInfos.entrySet().iterator(); i.hasNex= t();) { + Map.Entry entry =3D (Map.Entry)i.next(); + varInfos.put(entry.getKey(), new VarInfo((VarInfo)entry.getVal= ue())); + } + } + + /** + * Creates a new entry in the variable table with the specified name a= s key and=20 + * an empty value. + */ + public void add(String name) + { + // init var entry as not constraint and unused + varInfos.put(name, new VarInfo()); + } + + /** + * Mark the specified variable as used.=20 + * The method sets the info field of the VarInfo object to true. + */ + public void markUsed(JDOQLAST variable, String dependendVar) + { + String name =3D variable.getText(); + VarInfo entry =3D (VarInfo)varInfos.get(name); + if (entry =3D=3D null) { + throw new JDOFatalInternalException( + msg.msg("ERR_VariableCheckerUndefinedVariable", //NOI18N + "markUsed", name)); //NOI18N + } + entry.used.add(variable); + if (dependendVar !=3D null) { + VarInfo dependendVarInfo =3D (VarInfo)varInfos.get(dependendVa= r); + if (dependendVarInfo.dependsOn !=3D null) { + throw new JDOFatalInternalException( + msg.msg("ERR_VariableCheckerMultipleDependencies", //N= OI18N =20 + dependendVar, dependendVarInfo.dependsOn, name= )); + } + dependendVarInfo.dependsOn =3D name; + } + } + + /** + * Mark the specified variable as constaint with the specified expr. + * The method sets the constraint field of the VarInfo object to true. + */ + public void markConstraint(JDOQLAST variable, JDOQLAST expr) + { + String name =3D variable.getText(); + VarInfo entry =3D (VarInfo)varInfos.get(name); + if (entry =3D=3D null) { + throw new JDOFatalInternalException( + msg.msg("ERR_VariableCheckerUndefinedVariable", //NOI18N + "markConstraint", name)); //NOI18N + } + String old =3D (entry.constraint=3D=3Dnull ? null : entry.constrai= nt.getText()); + if ((old !=3D null) && !old.equals(expr.getText())) { + throw new JDOUnsupportedOptionException( + msg.msg("EXC_UnsupportedMultipleConstraints", name)); //NO= I18N + } + entry.constraint =3D expr; + } + + /** + * Merges the specified variable table (other) into this variable tabl= e=2E + */ + public void merge(VariableChecker other) + { + for (Iterator i =3D varInfos.entrySet().iterator(); i.hasNext();) { + Map.Entry entry =3D (Map.Entry)i.next(); + String name =3D (String)entry.getKey(); + VarInfo info =3D (VarInfo)entry.getValue(); + VarInfo otherInfo =3D (VarInfo)other.varInfos.get(name); + =20 + // copy other info if this info is empty + if ((info.constraint =3D=3D null) && (info.used.size() =3D=3D = 0)) { + info.constraint =3D otherInfo.constraint; + info.used =3D otherInfo.used; + info.dependsOn =3D otherInfo.dependsOn; + info.status =3D otherInfo.status; + continue; + } + + // do nothing if otherInfo is empty + if ((otherInfo.constraint =3D=3D null) && (otherInfo.used.size= () =3D=3D 0)) { + continue; + } + =20 + // constraint check + // If both variables tables include constraints they have to b= e the same + if ((info.constraint !=3D null) && (otherInfo.constraint !=3D = null)) { + if (!otherInfo.constraint.getText().equals(info.constraint= .getText())) { + throw new JDOUnsupportedOptionException( + msg.msg("EXC_DifferentConstraints", name)); //NOI1= 8N + } + } + // If at least one variable table does not define constraint,=20 + // nullify the constaint in this variable table + else { + info.constraint =3D null; + info.dependsOn =3D null; + info.status =3D VarInfo.UNCHECKED; + } + =20 + // copy otherInfo.used to this used list + info.used.addAll(otherInfo.used); + } + } + + /** + * + */ + public void checkConstraints() + { + for (Iterator i =3D varInfos.entrySet().iterator(); i.hasNext();) { + Map.Entry entry =3D (Map.Entry)i.next(); + VarInfo info =3D (VarInfo)entry.getValue(); + checkConstraint((String)entry.getKey(), (VarInfo)entry.getValu= e()); + } + } + + protected void checkConstraint(String variable, VarInfo info) + { + switch (info.status) { + case VarInfo.UNCHECKED: + // if unchecked, start checking + info.status =3D VarInfo.IN_PROGRESS; + break; + case VarInfo.IN_PROGRESS: + // if this VarInfo is currently processed we have a cyclic dep= endency + throw new JDOUnsupportedOptionException( + msg.msg("EXC_UnsupportedCyclicConstaint", variable)); // N= OI18N + case VarInfo.CHECKED: + // if alreday checked just return + return; + } + =20 + if (info.dependsOn !=3D null) { + VarInfo dependendVarInfo =3D (VarInfo)varInfos.get(info.depend= sOn); + checkConstraint(info.dependsOn, dependendVarInfo); + } + =20 + if (info.constraint =3D=3D null) { + throw new JDOUnsupportedOptionException( + msg.msg("EXC_UnconstraintVariable", variable)); //NOI18N + } + =20 + if (info.used.size() =3D=3D 0) { + throw new JDOUnsupportedOptionException( + msg.msg("EXC_UnusedVariable", variable)); //NOI18N + } + =20 + // Next line in comment, because the node visitor for queries in m= emory + // does not like VARIABLE_ACCESS child nodes.=20 + // This needs to be investigated for the SQL generation. + //attachConstraintToUsedAST(info); + info.status =3D VarInfo.CHECKED; + } + =20 + /** + * + */ + protected void attachConstraintToUsedAST(VarInfo info) + { + for (Iterator i =3D info.used.iterator(); i.hasNext();) { + JDOQLAST varNode =3D (JDOQLAST)i.next(); + if (varNode.getFirstChild() =3D=3D null)=20 + varNode.setFirstChild(JDOQLASTFactory.getInstance().dupTre= e(info.constraint)); + } + } + +} + Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Ab= stractValueTable.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/scope/AbstractValueTable.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Abstr= actValueTable.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Abstr= actValueTable.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,175 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * AbstractValueTable.java + * + * Created on September 11, 2001 + */ + +package org.apache.jdo.impl.jdoql.scope; + +import java.util.Map; +import java.util.HashMap; +import java.util.Iterator; +import java.io.Serializable; + +import javax.jdo.JDOFatalInternalException; + +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.jdoql.tree.Declaration; +import org.apache.jdo.jdoql.tree.ValueTable; +import org.apache.jdo.util.I18NHelper; + + +/** + * This method is the abstract super class for ParameterTable and Variable= Table. + * It provides common implementation for managing parameter and variable v= alues. + * + * @author Michael Bouschen + */ +abstract class AbstractValueTable + implements ValueTable, Serializable, Cloneable +{ + /** + * Map of declarations. Key is the the name of the declared identifier= ,=20 + * value is the Declaration node. + */ + Map declMap =3D new HashMap(); + =20 + /** + * Map of values. This map includes a values entry for each declared=20 + * identifier. Default value is UNDEFINED. + */ + transient Map valueMap; + =20 + /** I18N support */ + protected final static I18NHelper msg =3D I18NHelper.getInstance( + "org.apache.jdo.impl.jdoql.Bundle", //NOI18N + AbstractValueTable.class.getClassLoader());=20 +=20 + /** + * Adds a new declaration. The value is set to UNDEFINED. + * @param decl the declaration node + */ + public void declare(Declaration decl) + { + String name =3D decl.getName(); + declMap.put(name, decl); + } + =20 + /** + * This method initializes the map of values for this ValueTable.=20 + * It needs to be called prior to any use of an AbstractValueTable + * at query execution time. + */ + public void initValueHandling() + { + valueMap =3D new HashMap(); + for (Iterator i =3D declMap.keySet().iterator(); i.hasNext();) { + String name =3D (String)i.next(); + valueMap.put(name, UNDEFINED.getInstance()); + } + } + + /** + * Sets the value for the specified identifier. + * @param name the name of the identifier + * @param value the current value of the identifier + */ + public void setValue(String name, Object value) + { + if (valueMap =3D=3D null) + throw new JDOFatalInternalException( + msg.msg("ERR_InvalidTableForExecution", //NOI18N + this.getClass().getName())); + Declaration decl =3D (Declaration)declMap.get(name); + checkDeclaredIdentifier(name, decl); + valueMap.put(name, value); + } + =20 + /** + * Returns the current value for the specified identifier. + * @param name the name of the identifier + * @return the current value of the identifier + */ + public Object getValue(String name) + { + if (valueMap =3D=3D null) + throw new JDOFatalInternalException( + msg.msg("ERR_InvalidTableForExecution", //NOI18N + this.getClass().getName())); + checkDeclaredIdentifier(name, (Declaration)declMap.get(name)); + return valueMap.get(name); + } + =20 + /** + * Checks whether the type of the specified value is compatible of the= type + * of the identifier from its declaration. + * @param name the name of the identifier + * @param value the value to be checked + * @return true if the type of the value is compatible wi= th the=20 + * type of the identifier; false otherwise. + */ + public boolean isCompatibleValue(String name, Object value) + { + Declaration decl =3D (Declaration)declMap.get(name); + checkDeclaredIdentifier(name, decl); + + boolean isCompatible =3D true; + + // check type compatibility of actual and formal parameter + Class formalType =3D decl.getJavaClass(); + + // handle value =3D=3D null + if (value =3D=3D null) { + isCompatible =3D !formalType.isPrimitive(); + } + else { + Class actualType =3D value.getClass(); + Class type =3D formalType; + if (formalType.isPrimitive()) { + if (formalType =3D=3D int.class) + type =3D Integer.class; + else if (formalType =3D=3D long.class) + type =3D Long.class; + else if (formalType =3D=3D short.class) + type =3D Short.class; + else if (formalType =3D=3D byte.class) + type =3D Byte.class; + else if (formalType =3D=3D double.class) + type =3D Double.class; + else if (formalType =3D=3D float.class) + type =3D Float.class; + else if (formalType =3D=3D boolean.class) + type =3D Boolean.class; + else if (formalType =3D=3D char.class) + type =3D Character.class; + } + isCompatible =3D type.isAssignableFrom(actualType); + } + return isCompatible; + } +=20 + /** + * Internal method to check whether the specified identifier is declar= ed.=20 + * Allows subclasses of AbstractValueTable to use specific error messa= ges. + */ + protected abstract void checkDeclaredIdentifier(String name,=20 + Declaration decl); + +} + Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Pa= rameterTable.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/scope/ParameterTable.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Param= eterTable.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Param= eterTable.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,173 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * ParameterTable.java + * + * Created on August 28, 2001 + */ + +package org.apache.jdo.impl.jdoql.scope; + +import java.util.*; + +import javax.jdo.JDOFatalInternalException; + +import org.apache.jdo.impl.jdoql.QueryResultHelperImpl; +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.jdoql.tree.Declaration; +import org.apache.jdo.pm.PersistenceManagerInternal; + + +/** + * The query parameter table. + * + * @author Michael Bouschen + */ +public class ParameterTable + extends AbstractValueTable +{ + /** + * List of query parameter names. The query parameter tables stores th= e=20 + * query parameter names in an extra list to presever the order of=20 + * parameter declarations. + */ + List names =3D new ArrayList(); + + /** + * Adds a new declaration. The value is initially set to UNDEFINED. + * @param decl the declaration node + */ + public void declare(Declaration decl) + { + super.declare(decl); + names.add(decl.getName()); + } + =20 + /** + * Returns a copy of this ParameterTable. + * @return a copy of this ParameterTable. + */ + public ParameterTable getCopy() + { + try { + return (ParameterTable)clone(); + } + catch (CloneNotSupportedException ex) { + throw new JDOFatalInternalException( + msg.msg("ERR_UnexpectedCloneProblems", ex)); //NOI18N + } + } + =20 + /** + * Internal method to check whether the specified identifier is declar= ed.=20 + */ + protected void checkDeclaredIdentifier(String name, Declaration decl) + { + if (decl =3D=3D null) + throw new JDOQueryException( + msg.msg("EXC_UndefinedQueryParameter", name)); //NOI18N + } + + //=3D=3D=3D=3D=3D=3D=3D=3D=3D PatameterTable convenience methods =3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D + + /** + * Sets all query parameter values. The order of declarations in=20 + * declareParameters defines the order in the specified array of param= eter=20 + * values. The method checks the type compatibility of the query param= eter=20 + * values. + * @param paramValues the parameter values + */ + public void setValues(PersistenceManagerInternal queryPM, Object[] par= amValues) + { + if (paramValues !=3D null) + { + Iterator i =3D names.iterator(); + for (int index =3D 0; index < paramValues.length; index++) { + Object value =3D paramValues[index]; + if (!i.hasNext()) { + throw new JDOQueryException( + msg.msg("EXC_WrongNumberOfQueryParameters")); //NO= I18N + } + String name =3D (String)i.next(); + QueryResultHelperImpl.checkPM(queryPM, value); + checkCompatibility(name, value); + setValue(name, value); + } + } + } + + /** + * Sets all query parameter values. The values are taken from the spec= ified=20 + * map. The method assumes the key in the map to be the parameter name= and=20 + * the value in the map to be the parameter value.=20 + * @param paramValues the parameter values + */ + public void setValues(PersistenceManagerInternal queryPM, Map paramVal= ues) + { + if (paramValues !=3D null) + { + for (Iterator i =3D paramValues.entrySet().iterator(); i.hasNe= xt();) + { + Map.Entry actualParam =3D (Map.Entry)i.next(); + String name =3D (String)actualParam.getKey(); + Object value =3D actualParam.getValue(); + QueryResultHelperImpl.checkPM(queryPM, value); + checkCompatibility(name, value); + setValue(name, value); + } + } + } + + /** + * Checks whether all query parameters are bound.=20 + * If not a JDOQueryException is thrown. + */ + public void checkUnboundParams() + { + if (valueMap =3D=3D null) + throw new JDOFatalInternalException( + msg.msg("ERR_InvalidTableForExecution", //NOI18N + this.getClass().getName())); + for (Iterator i =3D valueMap.entrySet().iterator(); i.hasNext();) + { + Map.Entry valueEntry =3D (Map.Entry)i.next(); + if (valueEntry.getValue() instanceof UNDEFINED) + { + throw new JDOQueryException( + msg.msg("EXC_UnboundQueryParameter", (String)valueEntr= y=2EgetKey())); //NOI18N + } + } + } + + //=3D=3D=3D=3D=3D=3D=3D=3D=3D Internal helper methods =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + =20 + /** + * Checks the type compatibility of the specified value and throws a + * JDOQueryException if the value has an incompatible type. + */ + private void checkCompatibility(String name, Object value) + { + if (!isCompatibleValue(name, value)) { + Declaration decl =3D (Declaration)declMap.get(name); + String formalType =3D decl.getJavaClass().getName(); + String actualType =3D (value =3D=3D null) ? "null" : value.get= Class().getName(); //NOI18N + throw new JDOQueryException( + msg.msg("EXC_IncompatibleTypeOfQueryParameter", actualType= , formalType)); //NOI18N + } + } +} + Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Sy= mbolTable.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/scope/SymbolTable.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Symbo= lTable.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Symbo= lTable.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,87 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * SymbolTable.java + * + * Created on August 28, 2001 + */ + +package org.apache.jdo.impl.jdoql.scope; + +import java.util.Map; +import java.util.HashMap; + +import org.apache.jdo.jdoql.tree.Declaration; + + +/** + * The symbol table handling declared identifies. + * + * @author Michael Bouschen + */ +public class SymbolTable +{ + /** + * The table of declared identifier (symbols). + */ + protected Map symbols =3D new HashMap(); + + /** + * This method adds the specified identifier to this SymbolTable.=20 + * The specified declaration node provides details anbout the declarat= ion.=20 + * If this SymbolTable already defines an identifier with the same nam= e,=20 + * the SymbolTable is not changed and the existing declaration is retu= rned.=20 + * Otherwise null is returned. + * @param ident identifier to be declared + * @param def new definition of identifier + * @return the old definition if the identifier was already declared;=20 + * null otherwise + */ + public Declaration declare(String ident, Declaration def) + { + Declaration old =3D (Declaration)symbols.get(ident); + if (old =3D=3D null) { + symbols.put(ident, def); + } + return old; + } + + /** + * Checks whether the specified identifier is declared. =20 + * @param ident the name of identifier to be tested + * @return true if the identifier is declared;=20 + * false otherwise. + */ + public boolean isDeclared(String ident) + { + return (getDeclaration(ident) !=3D null); + } + + /** + * Checks the symbol table for the actual declaration of the specified=20 + * identifier. The method returns the declaration node if available or + * null for an undeclared identifier.=20 + * @param ident the name of identifier + * @return the declaration node if ident is declared; + * null otherise. + */ + public Declaration getDeclaration(String ident) + { + return (Declaration)symbols.get(ident); + } +=09 +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Ty= peNames.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/scope/TypeNames.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/TypeN= ames.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/TypeN= ames.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,156 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * TypeNames.java + * + * Created on September 06, 2001 + */ + +package org.apache.jdo.impl.jdoql.scope; + +import java.util.Map; +import java.util.Set; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; + +import org.apache.jdo.impl.jdoql.jdoqlc.TypeSupport; +import org.apache.jdo.model.java.JavaType; + + +/** + * The table handling type names. + *

+ * TBD: + *

    + *
  • check single type-import-on-demand on access + *
=20 + * @author Michael Bouschen + */ +public class TypeNames +{ + /** + * The corresponding type table. + **/ + protected TypeSupport typeSupport; + + /** + * Map of single-type-imports.=20 + * Key is the imported class name, value is the fully qualified class = name. + */ + protected Map imports =3D new HashMap(); + + /** + * Collection of type-imports-on-demand.=20 + * The collection stores the imported package names. + */ + protected Set importOnDemands =3D new HashSet(); + + /** + * The package of the class of the current compilation unit. + */ + protected String currentPackage =3D null; + + /** + * Creates a new TypeNames instance. + */ + public TypeNames(TypeSupport typeSupport) + { + this.typeSupport =3D typeSupport; + } + + /** + * This method initializes the TypeNames table. It sets the currentPac= kage=20 + * as the package name of the specified compilation unit. It also adds= the=20 + * package java.lang to the type-imports-on-demand. + */ + public void init(String compilationUnit) + { + declareImport(compilationUnit); + declareImportOnDemand("java.lang"); //NOI18N + int index =3D compilationUnit.lastIndexOf('.'); + currentPackage =3D index > 0 ? compilationUnit.substring(0, index)= : ""; //NOI18N + } + + /** + * Defines a single-type-import. + * @param typeName the fully qualified name of the type to be imported. + */ + public String declareImport(String typeName) + { + int index =3D typeName.lastIndexOf('.'); + String shortName =3D index>0 ? typeName.substring(index+1) : typeN= ame; + String old =3D (String)imports.get(shortName); + if (old =3D=3D null) + imports.put(shortName, typeName); + else if (old.equals(typeName)) + // same import twice =3D> no problem + old =3D null; + return old; + } + + /** + * Defines a type-import-on-demand. + * @param packageName the package name to be imported. + */ + public void declareImportOnDemand(String packageName) + { + importOnDemands.add(packageName); + } + + /** + * Resolves a type name. If the specified type name is fully qualified=20 + * the method checks the type table for the type representation. If th= e=20 + * name is not fully qualified, the method first checks whether there = is=20 + * a single-type-import importing the specified name. If not it checks=20 + * whether the current package defines this type. If not the method ch= ecks=20 + * whether there is a single type-import-on-demand for the spceified n= ame.=20 + * @param name a type name + * @return the type representation for the type name. + */ + public JavaType resolve(String name) + { + // check fully qulified class name + int index =3D name.indexOf('.'); + if (index > -1) { + return typeSupport.checkType(name); + } + =20 + // check single-type-import + String singleTypeImort =3D (String)imports.get(name); + if (singleTypeImort !=3D null) + return typeSupport.checkType(singleTypeImort); + =20 + // check current package + JavaType type =3D typeSupport.checkType(currentPackage + '.' + nam= e); + if (type !=3D null) + return type; + + // check type-import-on-demand + // TBD: check single type-import-on-demand + for (Iterator i =3D importOnDemands.iterator(); i.hasNext();) { + String next =3D (String)i.next(); + type =3D typeSupport.checkType(next + '.' + name); + if (type !=3D null) + return type; + } + + // not found + return null; + } + +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/UN= DEFINED.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/scope/UNDEFINED.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/UNDEF= INED.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/UNDEF= INED.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,62 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * UNDEFINED.java + * + * Created on September 11, 2001 + */ + +package org.apache.jdo.impl.jdoql.scope; + +/** + * An instance of this class represents an undefined value in a ValueTable + * (ParameterTable or VariableTable). + * + * @author Michael Bouschen + */ +public class UNDEFINED +{ + /** The singleton UNDEFINED instance. */ =20 + private static UNDEFINED undefined =3D new UNDEFINED(); + =20 + /**=20 + * Get an instance of UNDEFINED + * @return an instance of UNDEFINED + */ =20 + public static UNDEFINED getInstance() + { + return undefined; + } + + /** + * Creates new UNDEFINED. This constructor should not be=20 + * called directly; instead, the singleton access method=20 + * {@link #getInstance} should be used. + */ + private UNDEFINED() {} + + /** + * Returns a string representation of an UNDEFINED instance. + */ + public String toString() + { + return "UNDEFINED"; //NOI18N + } + =20 + =20 +} + Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Va= riableTable.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/scope/VariableTable.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Varia= bleTable.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/scope/Varia= bleTable.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,66 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +/* + * VariableTable.java + * + * Created on September 11, 2001 + */ + +package org.apache.jdo.impl.jdoql.scope; + +import javax.jdo.JDOFatalInternalException; + +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.jdoql.tree.Declaration; + + + +/** + * The variable table. + * + * @author Michael Bouschen + * @version 0.1 + */ +public class VariableTable + extends AbstractValueTable +{ + /** + * Returns a copy of this VariableTable. + * @return a copy of this VariableTable. + */ + public VariableTable getCopy() + { + try { + return (VariableTable)clone(); + } + catch (CloneNotSupportedException ex) { + throw new JDOFatalInternalException( + msg.msg("ERR_UnexpectedCloneProblems", ex)); //NOI18N + } + } +=20 + /** + * Internal method to check whether the specified identifier is declar= ed.=20 + */ + protected void checkDeclaredIdentifier(String name, Declaration decl) + { + if (decl =3D=3D null) + throw new JDOQueryException( + msg.msg("EXC_UndefinedQueryVariable", name)); //NOI18N + } +} + Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/And= Expr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/AndExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/AndExp= r=2Ejava (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/AndExp= r=2Ejava Fri Mar 18 17:02:29 2005 @@ -0,0 +1,94 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.AndExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a logical and operator. + * A logical and operator is based on boolean types. + * The string representation of this operator is &. + * + * @author Michael Watzek + */ +public final class AndExpr extends BinaryExpr implements AndExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public AndExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public AndExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param left the first child + * @param right the second child + */ + AndExpr(Expression left, Expression right) + { super( JDOQLTokenTypes.BAND, "And", Boolean.class, left, right ); = //NOI18N + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param resultOfPreviousChild the result computed by leaving the + * previous child node + * @param indexOfNextChild the index in the children array of the + * next child to walk + * @return the boolean value returned by the visitor instance + */ + public boolean walkNextChild(NodeVisitor visitor, + Object resultOfPreviousChild, + int indexOfNextChild) + { return visitor.walkNextChild( this, resultOfPreviousChild,=20 + indexOfNextChild ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Asc= endingOrderingExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/AscendingOrderingExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Ascend= ingOrderingExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Ascend= ingOrderingExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,79 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.AscendingOrderingExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents an operator defining ascendent ordering of instanc= es + * returned by a query execution. The order is determined by an expression + * such as FieldAccessExpression. This expression is this nod= e's + * child. + * + * @author Michael Watzek + */ +public final class AscendingOrderingExpr=20 + extends OrderingExpr implements AscendingOrderingExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public AscendingOrderingExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public AscendingOrderingExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param expr the expression defining the order + */ + AscendingOrderingExpr(Expression expr) + { super( JDOQLTokenTypes.ASCENDING, "AscendingOrderingExpression", e= xpr ); //NOI18N + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Bin= aryExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/BinaryExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Binary= Expr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Binary= Expr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,166 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + + +import java.io.IOException; +import java.math.BigDecimal; +import java.math.BigInteger; + +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.jdoql.tree.BinaryExpression; +import org.apache.jdo.jdoql.tree.EqualsExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NotEqualsExpression; + +/** + * This node represents a binary operator. All binary operators have exact= ly + * two children. Examples of binary operators + * are AndExpression and EqualsExpression. + * + * @author Michael Watzek + */ +public abstract class BinaryExpr extends Expr implements BinaryExpression +{ + transient Class commonOperandType; + String commonOperandTypeName; // needed for serialization support only + + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public BinaryExpr() + {} + + /** + * This constructor is called by specialized nodes. + * It calls setChildren in order to initialize the node's + * children left and right. + * @param tokenType the token type + * @param tokenName the name of this node + * @param clazz the Java type of this node + * @param left the first child + * @param right the second child + */ + BinaryExpr(int tokenType, String tokenName, Class clazz, Expression le= ft, Expression right) + { super( tokenType, tokenName, clazz ); + this.commonOperandType =3D computeJavaClass( left.getJavaClass(), = right.getJavaClass() ); + setChildren( new org.apache.jdo.jdoql.tree.Node[] {left, right} ); + } + + /** + * Returns the first child of this node. + * @return the first child + */ + public Expression getLeftExpression() + { ASTToChildren(); + if( this.children=3D=3Dnull || + this.children.length<1 ) + return null; + return (Expression) this.children[0]; + } + + /** + * Returns the second child of this node. + * @return the second child + */ + public Expression getRightExpression() + { ASTToChildren(); + if( this.children=3D=3Dnull || + this.children.length<2 ) + return null; + return (Expression) this.children[1]; + } + + /** + * Returns the class instance suiteable for implementing the result + * of this expression. In case of integral binary expressions + * that class instance is also the result type of the operation retrie= ved + * by method getJavaClass. In case of relational binary + * expressions, that class instance differs from the type retrieved by + * getJavaClass, because relational binary expressions + * have a boolean result type which does not depend of the operand typ= es. + * @return the common operand type + */ + public Class getCommonOperandType() + { return this.commonOperandType; + } + + /** + * Sets the common operand type for this binary expression. + * @param clazz the common operand type + */ + public void setCommonOperandType(Class clazz) + { this.commonOperandType =3D clazz; + } + + Class computeJavaClass( Class left, Class right ) + { Class clazz =3D null; + if( left!=3Dnull && right!=3Dnull ) + { if( (BigDecimal.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (BigDecimal.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) || + (BigInteger.class.isAssignableFrom(left) && + (right=3D=3DFloat.class || right=3D=3DDouble.class)) || + (BigInteger.class.isAssignableFrom(right) && + (left=3D=3DFloat.class || left=3D=3DDouble.class)) ) + clazz =3D BigDecimal.class; + else if( (BigInteger.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (BigInteger.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) ) + clazz =3D BigInteger.class; + else if( (Double.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (Double.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) ) + clazz =3D Double.class; + else if( (Float.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (Float.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) ) + clazz =3D Float.class; + else if( (Long.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (Long.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) ) + clazz =3D Long.class; + else if( (Integer.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (Integer.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) || + (Short.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) || + (Short.class.isAssignableFrom(right) && + Number.class.isAssignableFrom(left)) || + (Byte.class.isAssignableFrom(left) && + Number.class.isAssignableFrom(right)) ) + clazz =3D Integer.class; + else if( Boolean.class.isAssignableFrom(left) && + Boolean.class.isAssignableFrom(right) ) + clazz =3D Boolean.class; + else if( this instanceof EqualsExpression || + this instanceof NotEqualsExpression ) + clazz =3D Object.class; + else + throw new JDOQueryException( msg.msg("EXC_IncompatibleType= s", left, right, this) ); //NOI18N + } + return clazz; + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Boo= leanLiteralExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/BooleanLiteralExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Boolea= nLiteralExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Boolea= nLiteralExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,93 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.BooleanLiteralExpression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a boolean literal such as true or + * false. It does not have any children. + * + * @author Michael Watzek + */ +public final class BooleanLiteralExpr=20 + extends ConstantExpr implements BooleanLiteralExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public BooleanLiteralExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public BooleanLiteralExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param b the boolean value + */ + BooleanLiteralExpr(Boolean b) + { super( JDOQLTokenTypes.BOOLEAN_LITERAL, b.toString(), b ); //NOI18N + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param b the boolean value + */ + BooleanLiteralExpr(boolean b) + { this( new Boolean(b) ); + } + + /** + * Returns the boolean value represented by this expression. + * @return the boolean value + */ + public boolean getBoolean() + { return ((Boolean)this.value).booleanValue(); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Byt= eLiteralExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/ByteLiteralExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/ByteLi= teralExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/ByteLi= teralExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,92 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.ByteLiteralExpression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a byte literal. It does not have any children. + * + * @author Michael Watzek + */ +public final class ByteLiteralExpr + extends ConstantExpr implements ByteLiteralExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ByteLiteralExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ByteLiteralExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param b the byte value + */ + ByteLiteralExpr(Byte b) + { super( JDOQLTokenTypes.BYTE_LITERAL, b.toString(), b ); //NOI18N + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param b the byte value + */ + ByteLiteralExpr(byte b) + { this( new Byte(b) ); + } + + /** + * Returns the byte value represented by this expression. + * @return the byte value + */ + public byte getByte() + { return ((Byte)this.value).byteValue(); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Can= didateClassImpl.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/CandidateClassImpl.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Candid= ateClassImpl.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Candid= ateClassImpl.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,94 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.CandidateClass; +import org.apache.jdo.jdoql.tree.Node; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents the candidate class of a query. + * The candidate class defines the type of instances in the + * candidate collection on which the filter expression is applied. + * + * @author Michael Watzek + */ +public final class CandidateClassImpl extends NodeImpl implements Candidat= eClass +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public CandidateClassImpl() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public CandidateClassImpl(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor and + * sets the specified candidate class. + * @param type the type instance wrapping the candidate class + */ + CandidateClassImpl(TypeImpl type) + { super( JDOQLTokenTypes.CANDIDATE_CLASS, "CandidateClass",=20 + type.getJavaClass() ); //NOI18N + setChildren( new Node[] {type} ); + } + + /** + * Sets the candidate class for this instance. + * This method is used by semantic analysis only. + * @param clazz the candidate clazz + */ + public void setCandidateClass(Class clazz) + { ASTToChildren(); + if( this.children=3D=3Dnull ) + setChildren( new Node[] {new TypeImpl(clazz)} ); + TypeImpl type =3D (TypeImpl) this.children[0]; + type.clazz =3D clazz; + this.clazz =3D clazz; + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Cas= tExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/CastExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/CastEx= pr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/CastEx= pr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,116 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.jdoql.tree.CastExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.Node; +import org.apache.jdo.jdoql.tree.NodeVisitor; +import org.apache.jdo.jdoql.tree.Type; + + + +/** + * This node represents a cast expression. It has a result type and a child + * which corresponds with the expression to cast. + * + * @author Michael Watzek + */ +public final class CastExpr extends Expr implements CastExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public CastExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public CastExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param type the type instance wrapping the Java class to which + * the argument expr is casted + * @param expr the expression to cast + * @exception JDOQueryException if the result type of expr cannot + * be casted to clazz + */ + CastExpr(Type type, Expression expr) + { super( JDOQLTokenTypes.CAST, "Cast", type.getJavaClass() ); //NOI1= 8N + setChildren( new Node[] {type, expr} ); + if( expr.getJavaClass()!=3Dnull && + !clazz.isAssignableFrom(expr.getJavaClass()) && + !expr.getJavaClass().isAssignableFrom(clazz) ) + throw new JDOQueryException(=20 + msg.msg("EXC_IllegalCast", expr.getJavaClass().getName(),=20 + clazz.getName(), this) ); //NOI18N + } + + /** + * Returns the string representation of the Java class, + * to which this node's expression is casted. + * @return the Java type name + */ + public String getTypeName() + { ASTToChildren(); + if( this.children=3D=3Dnull || + this.children.length<1 ) + return null; + return ((Type)this.children[0]).getTypeName(); + } + + /** + * Returns the node's cast expression. + * @return the node's cast expression + */ + public Expression getExpression() + { ASTToChildren(); + if( this.children=3D=3Dnull || + this.children.length<2 ) + return null; + return (Expression) this.children[1]; + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Cha= rLiteralExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/CharLiteralExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/CharLi= teralExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/CharLi= teralExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,92 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.CharLiteralExpression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a character literal. It does not have any children. + * + * @author Michael Watzek + */ +public final class CharLiteralExpr=20 + extends ConstantExpr implements CharLiteralExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public CharLiteralExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public CharLiteralExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param c the char value + */ + CharLiteralExpr(Character c) + { super( JDOQLTokenTypes.CHAR_LITERAL, c.toString(), c ); //NOI18N + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param c the char value + */ + CharLiteralExpr(char c) + { this( new Character(c) ); + } + + /** + * Returns the char value represented by this expression. + * @return the char value + */ + public char getChar() + { return ((Character)this.value).charValue(); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Com= plementExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/ComplementExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Comple= mentExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Comple= mentExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,78 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.ComplementExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a bitwise not operator. + * A bitwise not operator is a unary expression. + * The string representation of this operator is ~. + * + * @author Michael Watzek + */ +public final class ComplementExpr=20 + extends UnaryExpr implements ComplementExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ComplementExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ComplementExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param expr the expression to compute the complement for + */ + ComplementExpr(Expression expr) + { super( JDOQLTokenTypes.BNOT, "Complement", expr ); //NOI18N + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Con= ditionalAndExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/ConditionalAndExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Condit= ionalAndExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Condit= ionalAndExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,96 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.ConditionalAndExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a conditional and operator. + * A conditional and operator is a binary expression. + * The string representation of this operator is &&. + * + * @author Michael Watzek + */ +public final class ConditionalAndExpr=20 + extends BinaryExpr implements ConditionalAndExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ConditionalAndExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ConditionalAndExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param left the left operand + * @param right the right operand + */ + ConditionalAndExpr(Expression left, Expression right) + { super( JDOQLTokenTypes.AND, "ConditionalAnd", Boolean.class,=20 + left, right ); //NOI18N + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param resultOfPreviousChild the result computed by leaving the=20 + * previous child node + * @param indexOfNextChild the index in the children array of the=20 + * next child to walk=20 + * @return the boolean value returned by the visitor instance + */ + public boolean walkNextChild(NodeVisitor visitor,=20 + Object resultOfPreviousChild,=20 + int indexOfNextChild) + { return visitor.walkNextChild( this, resultOfPreviousChild,=20 + indexOfNextChild ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Con= ditionalOrExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/ConditionalOrExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Condit= ionalOrExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Condit= ionalOrExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,96 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.ConditionalOrExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a conditional or operator. + * A conditional or operator is a binary expression. + * The string representation of this operator is ||. + * + * @author Michael Watzek + */ +public final class ConditionalOrExpr + extends BinaryExpr implements ConditionalOrExpression +{ + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ConditionalOrExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ConditionalOrExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param left the first child + * @param right the second child + */ + ConditionalOrExpr(Expression left, Expression right) + { super( JDOQLTokenTypes.OR, "ConditionalOr", Boolean.class,=20 + left, right ); //NOI18N + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param resultOfPreviousChild the result computed by leaving the + * previous child node. + * @param indexOfNextChild the index in the children array of the + * next child to walk + * @return the boolean value returned by the visitor instance + */ + public boolean walkNextChild(NodeVisitor visitor, + Object resultOfPreviousChild, + int indexOfNextChild) + { return visitor.walkNextChild( this, resultOfPreviousChild, + indexOfNextChild ); + } +} Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Con= stantExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/ap= ache/jdo/impl/jdoql/tree/ConstantExpr.java?view=3Dauto&rev=3D158176 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Consta= ntExpr.java (added) +++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/tree/Consta= ntExpr.java Fri Mar 18 17:02:29 2005 @@ -0,0 +1,127 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.impl.jdoql.tree; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.tree.ConstantExpression; +import org.apache.jdo.jdoql.tree.NodeVisitor; + + +/** + * This node represents a constant expression. + * Examples of constant expressions are BooleanLiteralExpression or + * ByteLiteralExpression. It does not have any children. + * + * @author Michael Watzek + */ +public class ConstantExpr extends Expr implements ConstantExpression +{ + /** + * Returns an instance of ConstantExpression. + * This method handles null as a constant expression. + * @param value the object wrapped by the constant expression + * @return the constant expression + */ + public static ConstantExpr newConstant(Object value) + { ConstantExpr constant; + if( value instanceof Boolean ) + constant =3D new BooleanLiteralExpr( (Boolean)value ); + else if( value instanceof Byte ) + constant =3D new ByteLiteralExpr( (Byte)value ); + else if( value instanceof Character ) + constant =3D new CharLiteralExpr( (Character)value ); + else if( value instanceof Double ) + constant =3D new DoubleLiteralExpr( (Double)value ); + else if( value instanceof Float ) + constant =3D new FloatLiteralExpr( (Float)value ); + else if( value instanceof Integer ) + constant =3D new IntLiteralExpr( (Integer)value ); + else if( value instanceof Long ) + constant =3D new LongLiteralExpr( (Long)value ); + else if( value instanceof Short ) + constant =3D new ShortLiteralExpr( (Short)value ); + else + constant =3D new ConstantExpr( value ); + return constant; + } + + Object value =3D null; + + /** + * The noarg constructor is needed for ANTLR support and deserializati= on. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ConstantExpr() + {} + + /** + * The noarg constructor is needed for ANTLR support. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + */ + public ConstantExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by specialized nodes. + * The caller must make sure to set the ANTLR tree structure himself + * or, call setChildren optionally. + * @param tokenType the token tpye + * @param tokenName the name of this node + */ + ConstantExpr(int tokenType, String tokenName, Object value) + { super( tokenType, tokenName, value=3D=3Dnull?null:value.getClass()= ); + this.value =3D value; + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param value the value represented by this expression + */ + ConstantExpr(Object value) + { this( JDOQLTokenTypes.CONSTANT, "Constant", value ); // NOI18N + } + + /** + * Returns the value represented by this expression. + * @return the value + */ + public Object getValue() + { return this.value; + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + */ + public void arrive(NodeVisitor visitor) + { visitor.arrive( this ); + } + + /** + * Delegates to the argument visitor. + * @param visitor the node visitor + * @param results the result array + * @return the object returned by the visitor instance + */ + public Object leave(NodeVisitor visitor, Object[] results) + { return visitor.leave( this, results ); + } +}