From jdo-commits-return-523-apmail-db-jdo-commits-archive=www.apache.org@db.apache.org Sun May 22 18:16:09 2005 Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 49040 invoked from network); 22 May 2005 18:16:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 May 2005 18:16:09 -0000 Received: (qmail 34958 invoked by uid 500); 22 May 2005 18:16:08 -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 Received: (qmail 34911 invoked by uid 99); 22 May 2005 18:16:05 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 22 May 2005 11:16:02 -0700 Received: (qmail 46368 invoked by uid 65534); 22 May 2005 18:09:19 -0000 Message-ID: <20050522180919.46366.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r171353 [9/13] - in /incubator/jdo/trunk/query20: ./ src/ src/conf/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jdo/ src/java/org/apache/jdo/impl/ 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/jdoql/ src/java/org/apache/jdo/jdoql/tree/ Date: Sun, 22 May 2005 18:09:00 -0000 To: jdo-commits@db.apache.org From: mbo@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/= Tree.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/Tree.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Tre= e=2Ejava (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Tre= e=2Ejava Sun May 22 11:08:57 2005 @@ -0,0 +1,1021 @@ +/* + * 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 antlr.collections.AST; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.LinkedList; +import java.util.Map; + +import org.apache.jdo.impl.jdoql.jdoqlc.JDOQLTokenTypes; +import org.apache.jdo.jdoql.JDOQueryException; +import org.apache.jdo.jdoql.tree.AndExpression; +import org.apache.jdo.jdoql.tree.CandidateClass; +import org.apache.jdo.jdoql.tree.CastExpression; +import org.apache.jdo.jdoql.tree.ComplementExpression; +import org.apache.jdo.jdoql.tree.ConditionalAndExpression; +import org.apache.jdo.jdoql.tree.ConditionalOrExpression; +import org.apache.jdo.jdoql.tree.ConstantExpression; +import org.apache.jdo.jdoql.tree.Declaration; +import org.apache.jdo.jdoql.tree.DivideExpression; +import org.apache.jdo.jdoql.tree.EqualsExpression; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.ExpressionFactory; +import org.apache.jdo.jdoql.tree.FieldAccessExpression; +import org.apache.jdo.jdoql.tree.GreaterThanEqualsExpression; +import org.apache.jdo.jdoql.tree.GreaterThanExpression; +import org.apache.jdo.jdoql.tree.IdentifierExpression; +import org.apache.jdo.jdoql.tree.LessThanEqualsExpression; +import org.apache.jdo.jdoql.tree.LessThanExpression; +import org.apache.jdo.jdoql.tree.MethodCallExpression; +import org.apache.jdo.jdoql.tree.MinusExpression; +import org.apache.jdo.jdoql.tree.Node; +import org.apache.jdo.jdoql.tree.NodeVisitor; +import org.apache.jdo.jdoql.tree.NotEqualsExpression; +import org.apache.jdo.jdoql.tree.NotExpression; +import org.apache.jdo.jdoql.tree.OrExpression; +import org.apache.jdo.jdoql.tree.ParameterDeclaration; +import org.apache.jdo.jdoql.tree.PlusExpression; +import org.apache.jdo.jdoql.tree.QueryTree; +import org.apache.jdo.jdoql.tree.StaticFieldAccessExpression; +import org.apache.jdo.jdoql.tree.TimesExpression; +import org.apache.jdo.jdoql.tree.UnaryMinusExpression; +import org.apache.jdo.jdoql.tree.UnaryPlusExpression; +import org.apache.jdo.jdoql.tree.VariableDeclaration; + + +/** + * This node represents the root of a query tree. + * You can use it to factorize this node's children, as there are + * candidate class, declarations, filter expression and + * ordering expressions. + * + * @author Michael Watzek + */ +public final class Tree extends NodeImpl implements QueryTree, ExpressionF= actory +{ + static final JavaKeyWords javaKeyWords =3D new Java= KeyWords(); + + CandidateClass candidateClass; + Map parameterMap; + List parameterList; + Map variableMap; + List orderings; + Expression filter; + + String serializedCandidateClassName; // s= erialization support + + /** + * The noarg constructor is called by persistence manager internal. + */ + public Tree() + { super( JDOQLTokenTypes.QUERY_TREE, "QueryTree", null ); //NOI18N + init(); + } + + /** + * This constructor is called by semantic analysis only. + * @param candidateClass the candidate class + * @param parameterDeclarations the antlr node containing all + * parameter declaration nodes as siblings=20 + * @param variableDeclarations the antlr node containing all + * variable declaration nodes as siblings=20 + * @param orderingExpressions the antlr node containing all + * ordering nodes as siblings=20 + * @param filter the filter expression + */ + public Tree(CandidateClass candidateClass,=20 + ParameterDecl parameterDeclarations,=20 + VariableDecl variableDeclarations,=20 + OrderingExpr orderingExpressions,=20 + Expr filter) + { this(); + Class clazz =3D candidateClass.getJavaClass(); + this.clazz =3D clazz; + this.candidateClass =3D candidateClass; + for( ParameterDecl current=3DparameterDeclarations; current!=3Dnul= l; current =3D (ParameterDecl)current.getNextSibling() ) + { this.parameterMap.put( current.getName(), current ); + this.parameterList.add( current ); + } + for( VariableDecl current=3DvariableDeclarations; current!=3Dnull;= current =3D (VariableDecl)current.getNextSibling() ) + this.variableMap.put( current.getName(), current ); + for( OrderingExpr current=3DorderingExpressions; current!=3Dnull; = current =3D (OrderingExpr)current.getNextSibling() ) + this.orderings.add( current ); + this.filter =3D filter; + initANTLRAST(); + } + + /** + * Creates and returns a copy of this object. + * @return the copy + * @exception CloneNotSupportedException thrown by super.clone()= + */ + protected Object clone() throws CloneNotSupportedException + { Tree copy =3D (Tree) super.clone(); + init(); + return copy; + } + + /** + * Sets the candidate class for this query tree. + * This method throws NullPointerException if the argument + * clazz is null. + * Otherwise this method invalidates this tree: + * Parameters, variables, orderings and the filter are nullified. + * @param clazz the candidate class + * @exception NullPointerException if the argument = clazz is null + */ + public void setCandidateClass(Class clazz) + { if( clazz=3D=3Dnull ) + throw new NullPointerException(); + if( this.clazz!=3Dnull ) + reset(); + this.clazz =3D clazz; + this.candidateClass =3D new CandidateClassImpl( new TypeImpl(clazz= ) ); + } + + /** + * Declares a parameter for this query tree. + * This method throws NullPointerException if one of the = arguments + * type or parameter are null. + * If a parameter is already declared having the same name + * as the argument parameter, then that declaration is + * replaced by this declaration. + * Once you have declared a parameter, you can access it using method + * newIdentifier. + * Please note: You can not declare a parameter and a variable having = the same name. + * @param clazz the instance of a Java class which is the type of the = declared parameter + * @param parameter the name of the declared parameter + * @exception NullPointerException if type or parameter are null + * @exception JDOQueryException if a variable has been declared with t= he same name + */ + public void declareParameter(Class clazz, String parameter) + { if( clazz=3D=3Dnull || + parameter=3D=3Dnull ) + throw new NullPointerException(); + if( this.variableMap.get(parameter)!=3Dnull ) + throw new JDOQueryException( msg.msg("EXC_ParameterVariableCol= lision", parameter) ); //NOI18N + ParameterDeclaration decl =3D new ParameterDecl( new TypeImpl(claz= z), parameter ); + this.parameterMap.put( parameter, decl ); + this.parameterList.add( decl ); + } + + /** + * Declares a variable for this query tree. + * This method throws NullPointerException if one of the = arguments + * type or variable are null. + * If a variable is already declared having the same name + * as the argument variable, then that declaration is + * replaced by this declaration. + * Once you have declared a variable, you can access it using method + * newIdentifier. + * Please note: You can not declare a parameter and a variable having = the same name. + * @param clazz the instance of a Java class which is the type of the = declared variable + * @param variable the name of the declared variable + * @exception NullPointerException if type or variable are null + * @exception JDOQueryException if a parameter has been declared with = the same name + */ + public void declareVariable(Class clazz, String variable) + { if( clazz=3D=3Dnull || + variable=3D=3Dnull ) + throw new NullPointerException(); + if( this.parameterMap.get(variable)!=3Dnull ) + throw new JDOQueryException( msg.msg("EXC_VariableParameterCol= lision", variable) ); //NOI18N + VariableDeclaration decl =3D new VariableDecl( new TypeImpl(clazz)= , variable ); + this.variableMap.put( variable, decl ); + } + + /** + * Adds an ascending ordering expression to this query tree. + * This method throws NullPointerException if the argument + * expression is null. + * The order of adding ascending and descending ordering expressions d= efines + * the order of instances in the result collection of an executed query + * instance corresponding with this query tree. + * @param expression the order expression + * @exception NullPointerException if expression is null + */ + public void addAscendingOrdering(Expression expression) + { if( expression=3D=3Dnull ) + throw new NullPointerException(); + this.orderings.add( new AscendingOrderingExpr(expression) ); + } + + /** + * Adds an descending ordering expression to this query tree. + * This method throws NullPointerException if the argument + * expression is null. + * The order of adding ascending and descending ordering expressions d= efines + * the order of instances in the result collection of an executed query + * instance corresponding with this query tree. + * @param expression the order expression + * @exception NullPointerException if expression is null + */ + public void addDescendingOrdering(Expression expression) + { if( expression=3D=3Dnull ) + throw new NullPointerException(); + this.orderings.add( new DescendingOrderingExpr(expression) ); + } + + /** + * Sets the filter expression for this query tree. + * This method throws NullPointerException if the argument + * filter is null. + * @param filter the filter expression + * @exception NullPointerException if filter is null + * @exception JDOQueryException if the result type of filter is a non = boolean type + */ + public void setFilter(Expression filter) + { if( filter=3D=3Dnull ) + throw new NullPointerException(); + if( filter.getJavaClass()!=3DBoolean.class && + filter.getJavaClass()!=3Dboolean.class ) + throw new JDOQueryException( msg.msg("EXC_IllegalTypeForFilter= Expression", filter) ); //NOI18N + this.filter =3D filter; + } + + /** + * Returns the candidate class. + * @return the candidate class + */ + public Class getCandidateClass() + { if( this.candidateClass=3D=3Dnull ) + throw new JDOQueryException( msg.msg("EXC_MissingCandidateClas= s") ); //NOI18N + return this.candidateClass.getJavaClass(); + } + + /** + * Returns a map containing all declared variables. + * This map contains variable names as keys and instances of + * VariableDeclaration as values. + * @return the map of declared variables + */ + public Map getDeclaredVariables() + { return this.variableMap; + } + + /** + * Returns a map containing all declared parameters. + * This map contains parameter names as keys and instances of + * ParameterDeclaration as values. + * @return the map of declared parameters + */ + public Map getDeclaredParameters() + { return this.parameterMap; + } + + /** + * Returns a list of all declared parameters. The order of entries is + * defined by the order of calls declareParameter. + * This list contains instances of + * ParametersDeclaration as entries. + * @return the list of declared parameters + */ + public List getDeclaredParametersAsList() + { return this.parameterList; + } + + /** + * Returns the filter expression of this query tree. + * @return the filter or null. + */ + public Expression getFilter() + { return (Expression) this.filter; + } + + /** + * Returns a list of all added ordering expressions. + * The order of entries is defined by the order of calls + * addAscendingOrdering and addDescendingOrdering. + * This list contains instances of + * OrderingExpression as entries. + * @return the list of declared parameters + */ + public List getOrderingExpressions() + { return this.orderings; + } + + /** + * Returns an instance of either ThisExpression or + * VariableAccessExpression or + * ParameterAccessExpression or FieldAccessExpressi= on + * depending on the fact which of the classes the argument + * identifier maps to. + * This method throws NullPointerException if the argument + * identifier is null or the candidate class= is not set. + * Note: If you pass "this" as an identifier name, then + * an instance of ThisExpression is returned. If you pass= any + * other java key word as an identifier name, then an instance of + * JDOQueryException is thrown. + * @param identifier the name of the identifier access expression + * @return the specialized identifier access expression instance + * @exception NullPointerException if identifier is null + * @exception JDOQueryException if identifier is a java key word. + */ + public IdentifierExpression newIdentifier(String identifier) + { if( identifier=3D=3Dnull ) + throw new NullPointerException(); + IdentifierExpression identifierExpr; + if( identifier.equals("this") ) //NOI18N + identifierExpr =3D new ThisExpr( this.candidateClass=3D=3Dnull= ?null:this.candidateClass.getJavaClass() ); + else + { if( javaKeyWords.isJavaKeyWord(identifier) ) + throw new JDOQueryException( msg.msg("EXC_IllegalIdentifie= r", identifier) ); //NOI18N + Declaration decl =3D (Declaration) this.variableMap.get( ident= ifier ); + if( decl=3D=3Dnull ) + { decl =3D (Declaration) this.parameterMap.get( identifier ); + if( decl=3D=3Dnull ) + //identifierExpr =3D new FieldAccessExpr( new ThisExpr= (this.candidateClass.getJavaClass()), identifier ); + identifierExpr =3D new IdentifierExpr( JDOQLTokenTypes= .IDENT, identifier, null ); + else + identifierExpr =3D new ParameterAccessExpr( decl.getJa= vaClass(), identifier ); + } + else + identifierExpr =3D new VariableAccessExpr( decl.getJavaCla= ss(), identifier ); + } + return identifierExpr; + } + + /** + * Returns an instance of FieldAccessExpression. + * This method throws NullPointerException if one of the = arguments + * target or fieldName are null. + * @param target the target expression of the field access expression + * @param fieldName the name of the field to access + * @return the field access expression instance + * @exception NullPointerException if target or fieldName are null + */ + public FieldAccessExpression newFieldAccess(Expression target, String = fieldName) + { if( target=3D=3Dnull || + fieldName=3D=3Dnull ) + throw new NullPointerException(); + return new FieldAccessExpr( target, fieldName ); + } + + /** + * Returns an instance of StaticFieldAccessExpression. + * This method throws NullPointerException if one of the = arguments + * clazz or fieldName are null. + * @param clazz the class instance defining the field + * @param fieldName the name of the field to access + * @return the static field access expression instance + * @exception NullPointerException if clazz or fieldName are null + */ + public StaticFieldAccessExpression newFieldAccess(Class clazz, String = fieldName) + { if( clazz=3D=3Dnull || + fieldName=3D=3Dnull ) + throw new NullPointerException(); + return new StaticFieldAccessExpr( new TypeImpl(clazz), fieldName ); + } + + /** + * Returns an instance of MethodCallExpression. + * Note: If the method corresponding with methodName does not have any + * arguments, then the argument arguments is ignored. + * This method throws NullPointerException if one of the = arguments + * target or methodName + * are null. + * @param target the target expression of the method call expression + * @param methodName the name of the method + * @param arguments the array of arguments + * @return the specialized method call expression + * @exception NullPointerException if target or methodName are null + * @exception JDOQueryException if methodName is not one of + * "contains", "endsWith", "isEmpty" + * or "startsWith". + */ + public MethodCallExpression newMethodCall(Expression target, String me= thodName, Expression[] arguments) + { if( target=3D=3Dnull || + methodName=3D=3Dnull ) + throw new NullPointerException(); + MethodCallExpression methodCall; + if( methodName.equals("contains") ) //NOI18N + methodCall =3D new ContainsCallExpr( target, arguments ); + else if( methodName.equals("endsWith") ) //NOI18N + methodCall =3D new EndsWithCallExpr( target, arguments ); + else if( methodName.equals("isEmpty") ) //NOI18N + methodCall =3D new IsEmptyCallExpr( target ); + else if( methodName.equals("startsWith") ) //NOI18N + methodCall =3D new StartsWithCallExpr( target, arguments ); + else + throw new JDOQueryException( msg.msg("EXC_NonSupportedMethodCa= ll", methodName) ); //NOI18N + return methodCall; + } + + /** + * Returns an instance of CastExpression. + * This method throws NullPointerException if one of the = arguments + * clazz or expression + * are null. + * @param clazz the Java class to cast the argument expression to + * @param expression the expression to cast + * @return the cast expression instance + * @exception NullPointerException if expression is null + */ + public CastExpression newCast(Class clazz, Expression expression) + { if( clazz=3D=3Dnull || + expression=3D=3Dnull ) + throw new NullPointerException(); + return new CastExpr( new TypeImpl(clazz), expression ); + } + + /** + * 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 instance + */ + public ConstantExpression newConstant(Object value) + { return ConstantExpr.newConstant( value ); + } + + /** + * Returns an instance of BooleanLiteralExpression. + * @param b the value wrapped by the boolean expression + * @return the boolean expression instance + */ + public ConstantExpression newConstant(boolean b) + { return new BooleanLiteralExpr( b ); + } + + /** + * Returns an instance of ByteLiteralExpression. + * @param b the value wrapped by the byte expression + * @return the byte expression instance + */ + public ConstantExpression newConstant(byte b) + { return new ByteLiteralExpr( b ); + } + + /** + * Returns an instance of CharLiteralExpression. + * @param c the value wrapped by the char expression + * @return the char expression instance + */ + public ConstantExpression newConstant(char c) + { return new CharLiteralExpr( c ); + } + + /** + * Returns an instance of DoubleLiteralExpression. + * @param d the value wrapped by the double expression + * @return the double expression instance + */ + public ConstantExpression newConstant(double d) + { return new DoubleLiteralExpr( d ); + } + + /** + * Returns an instance of FloatLiteralExpression. + * @param f the value wrapped by the float expression + * @return the float expression instance + */ + public ConstantExpression newConstant(float f) + { return new FloatLiteralExpr( f ); + } + + /** + * Returns an instance of IntLiteralExpression. + * @param i the value wrapped by the int expression + * @return the int expression instance + */ + public ConstantExpression newConstant(int i) + { return new IntLiteralExpr( i ); + } + + /** + * Returns an instance of LongLiteralExpression. + * @param l the value wrapped by the long expression + * @return the long expression instance + */ + public ConstantExpression newConstant(long l) + { return new LongLiteralExpr( l ); + } + + /** + * Returns an instance of ShortLiteralExpression. + * @param s the value wrapped by the short expression + * @return the short expression instance + */ + public ConstantExpression newConstant(short s) + { return new ShortLiteralExpr( s ); + } + + /** + * Returns a complement expression for the argument + * expr. + * This method throws NullPointerException if the argument + * expr is null. + * @param expr the expression argument for the operation + * @return the complement expression instance + * @exception NullPointerException if expr is null + */ + public ComplementExpression newComplement(Expression expr) + { if( expr=3D=3Dnull ) + throw new NullPointerException(); + return new ComplementExpr( expr ); + } + + /** + * Returns a unary minus expression for the argument + * expr. + * This method throws NullPointerException if the argument + * expr is null. + * @param expr the expression argument for the operation + * @return the unary minus expression instance + * @exception NullPointerException if expr is null + */ + public UnaryMinusExpression newMinus(Expression expr) + { if( expr=3D=3Dnull ) + throw new NullPointerException(); + return new UnaryMinusExpr( expr ); + } + + /** + * Returns a not expression for the argument + * expr. + * This method throws NullPointerException if the argument + * expr is null. + * @param expr the expression argument for the operation + * @return the not expression instance + * @exception NullPointerException if expr is null + */ + public NotExpression newNot(Expression expr) + { if( expr=3D=3Dnull ) + throw new NullPointerException(); + return new NotExpr( expr ); + } + + /** + * Returns a plus expression for the argument + * expr. + * This method throws NullPointerException if the argument + * expr is null. + * @param expr the expression argument for the operation + * @return the plus expression instance + * @exception NullPointerException if expr is null + */ + public UnaryPlusExpression newPlus(Expression expr) + { if( expr=3D=3Dnull ) + throw new NullPointerException(); + return new UnaryPlusExpr( expr ); + } + + /** + * Returns an and expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the and expression instance + * @exception NullPointerException if left or right are null + */ + public AndExpression newAnd(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new AndExpr( left, right ); + } + + /** + * Returns a conditional and expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the conditional and expression instance + * @exception NullPointerException if left or right are null + */ + public ConditionalAndExpression newConditionalAnd(Expression left, Exp= ression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new ConditionalAndExpr( left, right ); + } + + /** + * Returns a conditional or expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the conditional or expression instance + * @exception NullPointerException if left or right are null + */ + public ConditionalOrExpression newConditionalOr(Expression left, Expre= ssion right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new ConditionalOrExpr( left, right ); + } + + /** + * Returns a divide expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the divide expression instance + * @exception NullPointerException if left or right are null + */ + public DivideExpression newDivide(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new DivideExpr( left, right ); + } + + /** + * Returns an equals expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the equals expression instance + * @exception NullPointerException if left or right are null + */ + public EqualsExpression newEquals(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new EqualsExpr( left, right ); + } + + /** + * Returns a greater than expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the greater than expression instance + * @exception NullPointerException if left or right are null + */ + public GreaterThanExpression newGreaterThan(Expression left, Expressio= n right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new GreaterThanExpr( left, right ); + } + + /** + * Returns a greater than equals expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the greater than equals expression instance + * @exception NullPointerException if left or right are null + */ + public GreaterThanEqualsExpression newGreaterThanEquals(Expression lef= t, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new GreaterThanEqualsExpr( left, right ); + } + + /** + * Returns a less than expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the less than expression instance + * @exception NullPointerException if left or right are null + */ + public LessThanExpression newLessThan(Expression left, Expression righ= t) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new LessThanExpr( left, right ); + } + + /** + * Returns a less than equals expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the less than equals expression instance + * @exception NullPointerException if left or right are null + */ + public LessThanEqualsExpression newLessThanEquals(Expression left, Exp= ression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new LessThanEqualsExpr( left, right ); + } + + /** + * Returns a minus expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the minus expression instance + * @exception NullPointerException if left or right are null + */ + public MinusExpression newMinus(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new MinusExpr( left, right ); + } + + /** + * Returns a not equals expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the not equals expression instance + * @exception NullPointerException if left or right are null + */ + public NotEqualsExpression newNotEquals(Expression left, Expression ri= ght) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new NotEqualsExpr( left, right ); + } + + /** + * Returns a plus expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the plus expression instance + * @exception NullPointerException if left or right are null + */ + public PlusExpression newPlus(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new PlusExpr( left, right ); + } + + /** + * Returns an or expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the or expression instance + * @exception NullPointerException if left or right are null + */ + public OrExpression newOr(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new OrExpr( left, right ); + } + + /** + * Returns a times expression for the arguments + * left and right. + * This method throws NullPointerException if one of the = arguments + * left or right are null. + * @param left the left expression argument for the operation + * @param right the right expression argument for the operation + * @return the times expression instance + * @exception NullPointerException if left or right are null + */ + public TimesExpression newTimes(Expression left, Expression right) + { if( left=3D=3Dnull || + right=3D=3Dnull ) + throw new NullPointerException(); + return new TimesExpr( left, right ); + } + + /** + * Returns the children of this node. + * This method ensures that the children array corresponds with + * the children nodes of the underlying ANTLR tree structure. + * @return the children + * @exception JDOQueryException if the candidate class is not set + */ + public Node[] getChildren() + { initANTLRAST(); + return super.getChildren(); + } + + /** + * 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 of the next child node + * @return the boolean value returned by the visitor instance + */ + public boolean walkNextChild(NodeVisitor visitor, Object resultOfPrevi= ousChild, int indexOfNextChild) + { return visitor.walkNextChild( this, resultOfPreviousChild, indexOf= NextChild ); + } + + /** + * Ensures that this node has a corresponding ANTLR tree structure. + * @exception JDOQueryException if the candidate class is not set + */ + public void initANTLRAST() + { if( getFirstChild()=3D=3Dnull ) + { if( this.candidateClass=3D=3Dnull ) + throw new JDOQueryException( msg.msg("EXC_MissingCandidate= Class") ); //NOI18N + + setFirstChild( (AST) this.candidateClass ); + AST current =3D (AST) candidateClass; + for( Iterator i=3Dthis.parameterList.iterator(); i.hasNext(); ) + { current.setNextSibling( (AST) i.next() ); + current =3D current.getNextSibling(); + } + for( Iterator i=3Dthis.variableMap.values().iterator(); i.hasN= ext(); ) + { current.setNextSibling( (AST) i.next() ); + current =3D current.getNextSibling(); + } + for( Iterator i=3Dthis.orderings.iterator(); i.hasNext(); ) + { current.setNextSibling( (AST) i.next() ); + current =3D current.getNextSibling(); + } + current.setNextSibling( (AST) this.filter ); + } + } + + /** + * Nullifies the declared fields in this node as well as the underlying + * ANTLR tree structure. + */ + private void reset() + { this.candidateClass =3D null; + this.parameterMap.clear(); + this.parameterList.clear(); + this.variableMap.clear(); + this.orderings.clear(); + this.filter =3D null; + this.children =3D null; + + this.parent =3D null; + setFirstChild( null ); + setChildren( null ); + } + + private void init() + { this.candidateClass =3D null; + this.parameterMap =3D new HashMap(); + this.parameterList =3D new LinkedList(); + this.variableMap =3D new HashMap(); + this.orderings =3D new LinkedList(); + this.filter =3D null; + } + + static Class toWrapperClass(Class clazz) + { if( clazz=3D=3Dboolean.class ) + clazz =3D Boolean.class; + if( clazz=3D=3Dbyte.class ) + clazz =3D Byte.class; + if( clazz=3D=3Dchar.class ) + clazz =3D Character.class; + if( clazz=3D=3Ddouble.class ) + clazz =3D Double.class; + if( clazz=3D=3Dfloat.class ) + clazz =3D Float.class; + if( clazz=3D=3Dint.class ) + clazz =3D Integer.class; + if( clazz=3D=3Dlong.class ) + clazz =3D Long.class; + if( clazz=3D=3Dshort.class ) + clazz =3D Short.class; + return clazz; + } + + static class JavaKeyWords + { Collection javaKeyWords =3D new HashSet(); + JavaKeyWords() + { javaKeyWords.add( "abstract" ); //NOI18N + javaKeyWords.add( "boolean" ); //NOI18N + javaKeyWords.add( "break" ); //NOI18N + javaKeyWords.add( "byte" ); //NOI18N + javaKeyWords.add( "case" ); //NOI18N + javaKeyWords.add( "catch" ); //NOI18N + javaKeyWords.add( "char" ); //NOI18N + javaKeyWords.add( "class" ); //NOI18N + javaKeyWords.add( "const" ); //NOI18N + javaKeyWords.add( "continue" ); //NOI18N + javaKeyWords.add( "default" ); //NOI18N + javaKeyWords.add( "do" ); //NOI18N + javaKeyWords.add( "double" ); //NOI18N + javaKeyWords.add( "else" ); //NOI18N + javaKeyWords.add( "extends" ); //NOI18N + javaKeyWords.add( "final" ); //NOI18N + javaKeyWords.add( "finally" ); //NOI18N + javaKeyWords.add( "float" ); //NOI18N + javaKeyWords.add( "for" ); //NOI18N + javaKeyWords.add( "goto" ); //NOI18N + javaKeyWords.add( "if" ); //NOI18N + javaKeyWords.add( "implements" ); //NOI18N + javaKeyWords.add( "import" ); //NOI18N + javaKeyWords.add( "instanceof" ); //NOI18N + javaKeyWords.add( "int" ); //NOI18N + javaKeyWords.add( "interface" ); //NOI18N + javaKeyWords.add( "long" ); //NOI18N + javaKeyWords.add( "native" ); //NOI18N + javaKeyWords.add( "new" ); //NOI18N + javaKeyWords.add( "package" ); //NOI18N + javaKeyWords.add( "private" ); //NOI18N + javaKeyWords.add( "protected" ); //NOI18N + javaKeyWords.add( "public" ); //NOI18N + javaKeyWords.add( "return" ); //NOI18N + javaKeyWords.add( "short" ); //NOI18N + javaKeyWords.add( "static" ); //NOI18N + javaKeyWords.add( "strictfp" ); //NOI18N + javaKeyWords.add( "super" ); //NOI18N + javaKeyWords.add( "switch" ); //NOI18N + javaKeyWords.add( "synchronized" ); //NOI18N + javaKeyWords.add( "this" ); //NOI18N + javaKeyWords.add( "throw" ); //NOI18N + javaKeyWords.add( "throws" ); //NOI18N + javaKeyWords.add( "transient" ); //NOI18N + javaKeyWords.add( "try" ); //NOI18N + javaKeyWords.add( "void" ); //NOI18N + javaKeyWords.add( "volatile" ); //NOI18N + javaKeyWords.add( "while" ); //NOI18N + } + /** + * Checks if the argument identifier equals a Java ke= y word. + * @param identifier the identifier to check + * @return true, if identifier is a Java= key word, + * else false + */ + private boolean isJavaKeyWord(String identifier) + { return javaKeyWords.contains(identifier); + } + } + + // Serialization support + + /**=20 + * Returns the candidate class name calculated during serialization of + * this query tree instance.=20 + * @return serialized candidate class name + */ + public String getSerializedCandidateClassName() + { =20 + return serializedCandidateClassName; + } + + /** Deserialization support. */ + private void writeObject(java.io.ObjectOutputStream out) + throws java.io.IOException + { + if ((candidateClass !=3D null) && (getCandidateClass() !=3D null)) + this.serializedCandidateClassName =3D getCandidateClass().getN= ame(); + out.defaultWriteObject(); + } +} + Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/= TypeImpl.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/TypeImpl.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Typ= eImpl.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Typ= eImpl.java Sun May 22 11:08:57 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.NodeVisitor; +import org.apache.jdo.jdoql.tree.Type; + + +/** + * This node represents a type instance. A type instance wraps a + * java.lang.Class instance which has been supplied by + * the application. The following nodes have type instances as children: + *
  • CandidateClass + *
  • CastExpr + *
  • Decl + *
  • StaticFieldAccessExpr + * The result type of a type instance is the wrapped java.lang.Class= + * instance. Type instances are not visible in query tree factory methods = and + * expression factory methods. They are internally created by in implement= ation + * and are walked by a node visitor. + * + * @author Michael Watzek + */ +public final class TypeImpl extends NodeImpl implements Type +{ + /** + * 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 TypeImpl() + {} + + /** + * 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 TypeImpl(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param clazz the Java class which is wrapped by this instance + */ + TypeImpl(Class clazz) + { super( JDOQLTokenTypes.TYPE, clazz.getName(), clazz ); + } + + /** + * Returns the string representation of the Java class, + * which is wrapped by this instance. + * @return the Java type name + */ + public String getTypeName() + { return getJavaClass().getName(); + } + + /** + * 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/query20/src/java/org/apache/jdo/impl/jdoql/tree/= UnaryExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/UnaryExpr.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Una= ryExpr.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Una= ryExpr.java Sun May 22 11:08:57 2005 @@ -0,0 +1,64 @@ +/* + * 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.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.Node; +import org.apache.jdo.jdoql.tree.UnaryExpression; + +/** + * This node represents a unary operator. All unary operators have exactly + * one children. Examples of binary operators + * are ComplementExpression and NotExpression. + * + * @author Michael Watzek + */ +public abstract class UnaryExpr extends Expr implements UnaryExpression +{ + /** + * 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 UnaryExpr() + {} + + /** + * This constructor is called by specialized nodes. + * It calls setChildren in order to initialize the node's + * child expr. + * @param tokenType the token tpye + * @param tokenName the name of this node + * @param expr the first child + */ + UnaryExpr(int tokenType, String tokenName, Expression expr) + { super( tokenType, tokenName, expr.getJavaClass() ); + setChildren( new Node[] {expr} ); + } + + /** + * Returns the node's expression. + * @return the node's expression + */ + public Expression getExpression() + { ASTToChildren(); + if( this.children=3D=3Dnull || + this.children.length<1 ) + return null; + return (Expression) this.children[0]; + } +} Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/= UnaryMinusExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/UnaryMinusExpr.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Una= ryMinusExpr.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Una= ryMinusExpr.java Sun May 22 11:08:57 2005 @@ -0,0 +1,77 @@ +/* + * 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.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; +import org.apache.jdo.jdoql.tree.UnaryMinusExpression; + + +/** + * This node represents a unary minus operator. + * The string representation of this operator is -. + * + * @author Michael Watzek + */ +public final class UnaryMinusExpr + extends UnaryExpr implements UnaryMinusExpression +{ + /** + * 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 UnaryMinusExpr() + {} + + /** + * 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 UnaryMinusExpr(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 + */ + UnaryMinusExpr(Expression expr) + { super( JDOQLTokenTypes.UNARY_MINUS, "UnaryMinus", 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/query20/src/java/org/apache/jdo/impl/jdoql/tree/= UnaryPlusExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/UnaryPlusExpr.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Una= ryPlusExpr.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Una= ryPlusExpr.java Sun May 22 11:08:57 2005 @@ -0,0 +1,76 @@ +/* + * 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.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; +import org.apache.jdo.jdoql.tree.UnaryPlusExpression; + + +/** + * This node represents a unary plus operator. + * The string representation of this operator is +. + * + * @author Michael Watzek + */ +public final class UnaryPlusExpr extends UnaryExpr implements UnaryPlusExp= ression +{ + /** + * 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 UnaryPlusExpr() + {} + + /** + * 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 UnaryPlusExpr(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 + */ + UnaryPlusExpr(Expression expr) + { super( JDOQLTokenTypes.UNARY_PLUS, "UnaryPlus", 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/query20/src/java/org/apache/jdo/impl/jdoql/tree/= VariableAccessExpr.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/VariableAccessExpr.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Var= iableAccessExpr.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Var= iableAccessExpr.java Sun May 22 11:08:57 2005 @@ -0,0 +1,81 @@ +/* + * 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.Declaration; +import org.apache.jdo.jdoql.tree.Expression; +import org.apache.jdo.jdoql.tree.NodeVisitor; +import org.apache.jdo.jdoql.tree.VariableAccessExpression; + + +/** + * This node represents a variable access expression. + * It does not have any children. + * + * @author Michael Watzek + */ +public final class VariableAccessExpr + extends IdentifierExpr implements VariableAccessExpression +{ + /** + * 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 VariableAccessExpr() + {} + + /** + * 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 VariableAccessExpr(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor is called by the query tree instance. + * It delegates to the super class constructor. + * @param clazz the Java type of this identifier + * @param name the name of this identifier + */ + VariableAccessExpr(Class clazz, String name) + { super( JDOQLTokenTypes.VARIABLE_ACCESS, name,=20 + Tree.toWrapperClass(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/query20/src/java/org/apache/jdo/impl/jdoql/tree/= VariableDecl.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/impl/jdoql/tree/VariableDecl.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/impl/jdoql/tree/Var= iableDecl.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/impl/jdoql/tree/Var= iableDecl.java Sun May 22 11:08:57 2005 @@ -0,0 +1,77 @@ +/* + * 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.NodeVisitor; +import org.apache.jdo.jdoql.tree.Type; +import org.apache.jdo.jdoql.tree.VariableDeclaration; + + +/** + * This node represents a variable declaration. + * It does not have any children. + * + * @author Michael Watzek + */ +public final class VariableDecl extends Decl implements VariableDeclaration +{ + /** + * 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 VariableDecl() + {} + + /** + * 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 VariableDecl(antlr.Token token) + { initialize( token ); + } + + /** + * This constructor delegates to the super class constructor. + * @param type the type instance wrapping the Java class + * @param name the name of the variable + */ + VariableDecl(Type type, String name) + { super( JDOQLTokenTypes.VARIABLE_DECL, "VariableDeclaration",=20 + type, name ); //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/query20/src/java/org/apache/jdo/jdoql/JDOQLQuery= Factory.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/jdoql/JDOQLQueryFactory.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/jdoql/JDOQLQueryFac= tory.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/jdoql/JDOQLQueryFac= tory.java Sun May 22 11:08:57 2005 @@ -0,0 +1,151 @@ +/* + * 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.jdoql; + +import java.util.Collection; + +import javax.jdo.Extent; +import javax.jdo.Query; + +import org.apache.jdo.pm.PersistenceManagerInternal; +import org.apache.jdo.jdoql.tree.QueryTree; + +/** + * This interface allows for choosing between different + * JDO query implementations.=20 + * Query implementations implementing this interface + * are capable to run together with other components. + * The interface declares methods creating JDO query instances + * and JDO query tree instances. + * All methods creating query instances take persistence manager + * instances as parameters. + *=20 + * @author Michael Watzek + */ +public interface JDOQLQueryFactory=20 +{ + /**=20 + * Returns a new QueryTree instance. This instance allows to specify a=20 + * query with an API (see {@link org.apache.jdo.jdoql.tree.QueryTree} = and=20 + * {@link org.apache.jdo.jdoql.tree.ExpressionFactory}) rather than as + * JDOQL strings. To run you create a query object from the QueryTree = (see=20 + * {@link javax.jdo.PersistenceManager#newQuery(Object compiled)})=20 + * and call the execute method on the Query object. + * @return new QueryTree instance. + */ + QueryTree newTree(); + =20 + /**=20 + * Creates a new Query with no elements. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm); + =20 + /**=20 + * Creates a new Query using elements from another=20 + * Query. The other Query must have been cre= ated + * by the same JDO implementation. It might be active in a different + * PersistenceManager or might have been serialized and + * restored.=20 + *

    All of the settings of the other Query are copied to + * this Query, except for the candidate + * Collection or Extent.=20 + * @return the new Query. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @param compiled another Query from the same JDO + * implementation.=20 + */ + Query newQuery(PersistenceManagerInternal pm, Object compiled); + =20 + /**=20 + * Creates a new Query specifying the Class = of + * the candidate instances.=20 + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @param cls the Class of the candidate instances. + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm, Class cls); + =20 + /**=20 + * Creates a new Query with the Class of the + * candidate instances and candidate Extent. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistenc= e=20 + * manager is valid. + * @param cln the Extent of candidate instances. + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm, Extent cln); + =20 + /**=20 + * Creates a new Query with the candidate Class=20 + * and Collection. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @param cls the Class of results. + * @param cln the Collection of candidate instances. + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cl= n); + =20 + /**=20 + * Creates a new Query with the Class of the + * candidate instances and filter. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @param cls the Class of results. + * @param filter the filter for candidate instances. + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm, Class cls, String filter= ); + =20 + /**=20 + * Creates a new Query with the Class of the + * candidate instances, candidate Collection, and filter. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @param cls the Class of candidate instances. + * @param cln the Collection of candidate instances. + * @param filter the filter for candidate instances. + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cl= n,=20 + String filter); + =20 + /**=20 + * Creates a new Query with the + * candidate Extent and filter; the class + * is taken from the Extent. + * @param pm the persistence manager for the new query.=20 + * It is the responsibility of the caller to check that the persistence + * manager is valid.=20 + * @param cln the Extent of candidate instances. + * @param filter the filter for candidate instances. + * @return the new Query. + */ + Query newQuery(PersistenceManagerInternal pm, Extent cln, String filte= r); +} Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/jdoql/JDOQueryEx= ception.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/jdoql/JDOQueryException.java?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/jdoql/JDOQueryExcep= tion.java (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/jdoql/JDOQueryExcep= tion.java Sun May 22 11:08:57 2005 @@ -0,0 +1,61 @@ +/* + * 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. + */ + +/* + * JDOQueryException.java + * + * Created on August 28, 2001 + */ + +package org.apache.jdo.jdoql; + +import javax.jdo.JDOUserException; + +/**=20 + * This class represents query user errors. + *=20 + * @author Michael Bouschen + */ +public class JDOQueryException=20 + extends JDOUserException +{ + /** + * Creates a new JDOQueryException without detail message. + */ + public JDOQueryException()=20 + { + } + + /** + * Constructs a new JDOQueryException with the specified = detail message. + * @param msg the detail message. + */ + public JDOQueryException(String msg)=20 + { + super(msg); + } + =20 + /** + * Constructs a new JDOQueryException with the specified= detail message + * and nested Exception. + * @param msg the detail message. + * @param nested the nested Exception. + */ + public JDOQueryException(String msg, Throwable nested)=20 + { + super(msg, nested); + } +} Added: incubator/jdo/trunk/query20/src/java/org/apache/jdo/jdoql/package.ht= ml URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/query20/src/java/org= /apache/jdo/jdoql/package.html?rev=3D171353&view=3Dauto =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=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/query20/src/java/org/apache/jdo/jdoql/package.html = (added) +++ incubator/jdo/trunk/query20/src/java/org/apache/jdo/jdoql/package.html = Sun May 22 11:08:57 2005 @@ -0,0 +1,27 @@ + + + + +Package org.apache.jdo.jdoql + + + + +

    This package contains interfaces defining the query result and a basic = implementation.=20 +Furthermore, it defines the the exception class JDOQueryException.

    + +