Index: api/src/main/java/javax/jdo/JDOQLTypedQuery.java =================================================================== --- api/src/main/java/javax/jdo/JDOQLTypedQuery.java (revision 1842755) +++ api/src/main/java/javax/jdo/JDOQLTypedQuery.java (working copy) @@ -22,8 +22,6 @@ import java.util.List; import java.util.Map; -import javax.jdo.FetchPlan; -import javax.jdo.PersistenceManager; import javax.jdo.query.BooleanExpression; import javax.jdo.query.CharacterExpression; import javax.jdo.query.CollectionExpression; @@ -30,6 +28,7 @@ import javax.jdo.query.DateExpression; import javax.jdo.query.DateTimeExpression; import javax.jdo.query.Expression; +import javax.jdo.query.IfThenElseExpression; import javax.jdo.query.ListExpression; import javax.jdo.query.MapExpression; import javax.jdo.query.NumericExpression; @@ -170,6 +169,63 @@ JDOQLTypedQuery filter(BooleanExpression expr); /** + * Method to return an "IF (...) ... ELSE ..." expression for use in this query. + * @param type The type returned by the IfElse. + * @param cond The if condition + * @param thenValueExpr Expression for value to return when the if expression is met + * @param elseValueExpr Expression for value to return when the if expression is not met + * @return The IfThenElse expression + */ + IfThenElseExpression ifThenElse(Class type, BooleanExpression cond, + Expression thenValueExpr, Expression elseValueExpr); + + /** + * Method to return an "IF (...) ... ELSE ..." expression for use in this query. + * @param cond The if condition + * @param thenValue Value to return when the if expression is met + * @param elseValueExpr Expression to return when the if expression is not met + * @return The IfThenElse expression + */ + IfThenElseExpression ifThenElse(BooleanExpression cond, V thenValue, Expression elseValueExpr); + + /** + * Method to return an "IF (...) ... ELSE ..." expression for use in this query. + * @param cond The if condition + * @param thenValueExpr Expression to return when the if expression is met + * @param elseValue Value to return when the if expression is not met + * @return The IfThenElse expression + */ + IfThenElseExpression ifThenElse(BooleanExpression cond, Expression thenValueExpr, V elseValue); + + /** + * Method to return an "IF (...) ... ELSE ..." expression for use in this query. + * @param cond The if condition + * @param thenValue Value to return when the if expression is met + * @param elseValue Value to return when the if expression is not met + * @return The IfThenElse expression + */ + IfThenElseExpression ifThenElse(BooleanExpression cond, V thenValue, V elseValue); + + /** + * Method to return an "IF (...) ... ELSE ..." expression for use in this query. + * @param type The type returned by the IfElse. + * @param cond The if condition + * @param thenValueExpr Expression for value to return when the if expression is met + * @param + * @return + */ + IfThenElseExpression ifThen(Class type, BooleanExpression cond, Expression thenValueExpr); + + /** + * Method to return an "IF (...) ... ELSE ..." expression for use in this query. + * @param cond The if condition + * @param thenValue Value to return when the if expression is met + * @param + * @return + */ + IfThenElseExpression ifThen(BooleanExpression cond, V thenValue); + + /** * Method to set the grouping(s) for the query. * @param exprs Grouping expression(s) * @return The query Index: api/src/main/java/javax/jdo/query/ComparableExpression.java =================================================================== --- api/src/main/java/javax/jdo/query/ComparableExpression.java (revision 1842755) +++ api/src/main/java/javax/jdo/query/ComparableExpression.java (working copy) @@ -81,15 +81,15 @@ /** * Method to return a numeric expression representing the aggregated minimum of this expression. - * @return Numeric expression for the minimum + * @return expression for the minimum */ - NumericExpression min(); + ComparableExpression min(); /** * Method to return a numeric expression representing the aggregated maximum of this expression. - * @return Numeric expression for the maximum + * @return expression for the maximum */ - NumericExpression max(); + ComparableExpression max(); /** * Method to return an order expression for this expression in ascending order. Index: api/src/main/java/javax/jdo/query/IfThenElseExpression.java =================================================================== --- api/src/main/java/javax/jdo/query/IfThenElseExpression.java (nonexistent) +++ api/src/main/java/javax/jdo/query/IfThenElseExpression.java (working copy) @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javax.jdo.query; + +/** + * Representation of an IF-THEN-ELSE expression. + * + * @param Java type + */ +public interface IfThenElseExpression extends ComparableExpression { + + /** + * Method to add an "IF (...) ..." clause. + * If called multiple times, will add extra "IF (...) ..." or "ELSE IF (...) ..." + * @param cond The if expression + * @param thenValueExpr Expression to return when the if expression is met + * @return This expression + */ + IfThenElseExpression ifThen(BooleanExpression cond, Expression thenValueExpr); + + /** + * Method to add an "IF (...) ..." clause. + * If called multiple times, will add extra "IF (...) ..." or "ELSE IF (...) ..." + * @param cond The if condition + * @param thenValue Value to return when the if expression is met + * @return This expression + */ + IfThenElseExpression ifThen(BooleanExpression cond, T thenValue); + + /** + * Method to add the "ELSE ..." clause. + * If called multiple times will replace the previous else clause + * @param elseValueExpr Expression for value to return when the if expression is not met + * @return This expression + */ + IfThenElseExpression elseEnd(Expression elseValueExpr); + + /** + * Method to add the "ELSE ..." clause. + * If called multiple times will replace the previous else clause + * @param elseValue Value to return when the if expression is not met + * @return This expression + */ + IfThenElseExpression elseEnd(T elseValue); + +} Index: api/src/main/java/javax/jdo/query/NumericExpression.java =================================================================== --- api/src/main/java/javax/jdo/query/NumericExpression.java (revision 1842755) +++ api/src/main/java/javax/jdo/query/NumericExpression.java (working copy) @@ -21,7 +21,7 @@ * * @param Number type */ -public interface NumericExpression extends ComparableExpression +public interface NumericExpression extends ComparableExpression { /** * Method to return an expression for this expression added to the passed expression. @@ -28,7 +28,7 @@ * @param expr The other expression * @return The summation */ - NumericExpression add(Expression expr); + NumericExpression add(Expression expr); /** * Method to return an expression for this expression added to the passed number. @@ -35,7 +35,7 @@ * @param num Number to add * @return The summation */ - NumericExpression add(Number num); + NumericExpression add(Number num); /** * Method to return an expression for this expression subtracting the passed expression. @@ -42,7 +42,7 @@ * @param expr The other expression * @return The difference */ - NumericExpression sub(Expression expr); + NumericExpression sub(Expression expr); /** * Method to return an expression for this expression subtracting the passed number. @@ -49,7 +49,7 @@ * @param num Number to subtract * @return The difference */ - NumericExpression sub(Number num); + NumericExpression sub(Number num); /** * Method to return an expression for this expression multiplied by the passed expression. @@ -56,7 +56,7 @@ * @param expr The other expression * @return The multiplication */ - NumericExpression mul(Expression expr); + NumericExpression mul(Expression expr); /** * Method to return an expression for this expression multiplied by the passed number. @@ -63,7 +63,7 @@ * @param num Number * @return The multiplication */ - NumericExpression mul(Number num); + NumericExpression mul(Number num); /** * Method to return an expression for this expression divided by the passed expression. @@ -70,7 +70,7 @@ * @param expr The other expression * @return The division */ - NumericExpression div(Expression expr); + NumericExpression div(Expression expr); /** * Method to return an expression for this expression divided by the passed number. @@ -77,7 +77,7 @@ * @param num Number to divide by * @return The division */ - NumericExpression div(Number num); + NumericExpression div(Number num); /** * Method to return an expression for this expression modulus the passed expression (
a % b
). @@ -84,7 +84,7 @@ * @param expr The other expression * @return The modulus */ - NumericExpression mod(Expression expr); + NumericExpression mod(Expression expr); /** * Method to return an expression for this expression modulus the passed number. @@ -91,19 +91,19 @@ * @param num Number * @return The modulus */ - NumericExpression mod(Number num); + NumericExpression mod(Number num); /** * Method to return an expression that is the current expression negated. * @return The negated expression */ - NumericExpression neg(); + NumericExpression neg(); /** * Method to return an expression that is the complement of the current expression. * @return The complement expression */ - NumericExpression com(); + NumericExpression com(); /** * Method to return a numeric expression representing the aggregated average of this expression. @@ -112,82 +112,94 @@ NumericExpression avg(); /** + * Method to return a numeric expression representing the aggregated (distinct) average of this expression. + * @return Numeric expression for the average + */ + NumericExpression avgDistinct(); + + /** * Method to return a numeric expression representing the aggregated sum of this expression. * @return Numeric expression for the sum */ - NumericExpression sum(); + NumericExpression sum(); /** + * Method to return a numeric expression representing the aggregated (distinct) sum of this expression. + * @return Numeric expression for the sum + */ + NumericExpression sumDistinct(); + + /** * Method to return the absolute value expression of this expression. * @return The absolute value expression */ - NumericExpression abs(); + NumericExpression abs(); /** * Method to return the square-root value expression of this expression. * @return The square-root value expression */ - NumericExpression sqrt(); + NumericExpression sqrt(); /** * Method to return the arc cosine value expression of this expression. * @return The arc cosine value expression */ - NumericExpression acos(); + NumericExpression acos(); /** * Method to return the arc sine value expression of this expression. * @return The arc sine value expression */ - NumericExpression asin(); + NumericExpression asin(); /** * Method to return the arc tangent value expression of this expression. * @return The arc tangent value expression */ - NumericExpression atan(); + NumericExpression atan(); /** * Method to return the sine value expression of this expression. * @return The sine value expression */ - NumericExpression sin(); + NumericExpression sin(); /** * Method to return the cosine value expression of this expression. * @return The cosine value expression */ - NumericExpression cos(); + NumericExpression cos(); /** * Method to return the tangent value expression of this expression. * @return The tangent value expression */ - NumericExpression tan(); + NumericExpression tan(); /** * Method to return the exponential value expression of this expression. * @return The exponential value expression */ - NumericExpression exp(); + NumericExpression exp(); /** * Method to return the logarithm value expression of this expression. * @return The logarithm value expression */ - NumericExpression log(); + NumericExpression log(); /** * Method to return the ceiling value expression of this expression. * @return The ceiling value expression */ - NumericExpression ceil(); + NumericExpression ceil(); /** * Method to return the floor value expression of this expression. * @return The floor value expression */ - NumericExpression floor(); + NumericExpression floor(); /** * Method to return a bitwise AND expression for this expression with the supplied bit path. @@ -194,7 +206,7 @@ * @param bitExpr Bit expression * @return Bitwise AND expression */ - NumericExpression bAnd(NumericExpression bitExpr); + NumericExpression bAnd(NumericExpression bitExpr); /** * Method to return a bitwise OR expression for this expression with the supplied bit path. @@ -201,7 +213,7 @@ * @param bitExpr Bit expression * @return Bitwise OR expression */ - NumericExpression bOr(NumericExpression bitExpr); + NumericExpression bOr(NumericExpression bitExpr); /** * Method to return a bitwise XOR expression for this expression with the supplied bit path. @@ -208,5 +220,5 @@ * @param bitExpr Bit expression * @return Bitwise XOR expression */ - NumericExpression bXor(NumericExpression bitExpr); + NumericExpression bXor(NumericExpression bitExpr); } Index: copyjdorijars/pom.xml =================================================================== --- copyjdorijars/pom.xml (revision 1842755) +++ copyjdorijars/pom.xml (working copy) @@ -93,22 +93,27 @@ org.datanucleus datanucleus-core - 5.1.9 + 5.1.12-SNAPSHOT org.datanucleus datanucleus-rdbms - 5.1.9 + 5.1.12-SNAPSHOT org.datanucleus datanucleus-api-jdo - 5.1.6 + 5.1.10-SNAPSHOT org.datanucleus + datanucleus-jdo-query + 5.0.8-SNAPSHOT + + + org.datanucleus datanucleus-api-jpa - 5.1.6 + 5.1.9-SNAPSHOT log4j Index: tck/pom.xml =================================================================== --- tck/pom.xml (revision 1842755) +++ tck/pom.xml (working copy) @@ -123,11 +123,17 @@ junit junit - + org.datanucleus + datanucleus-api-jdo + 5.1.10-SNAPSHOT + + + org.datanucleus + datanucleus-jdo-query + 5.0.8-SNAPSHOT + + commons-logging commons-logging Index: tck/src/main/java/org/apache/jdo/tck/pc/company/Company.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/Company.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/Company.java (working copy) @@ -32,10 +32,13 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents information about a company. */ -public class Company +@PersistenceCapable +public class Company implements ICompany, Serializable, Comparable, Comparator, DeepEquality { private long companyid; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/DentalInsurance.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/DentalInsurance.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/DentalInsurance.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a dental insurance carrier selection for a * particular Employee. */ +@PersistenceCapable public class DentalInsurance extends Insurance implements IDentalInsurance { private BigDecimal lifetimeOrthoBenefit; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/Department.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/Department.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/Department.java (working copy) @@ -31,9 +31,12 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a department within a company. */ +@PersistenceCapable public class Department implements IDepartment, Serializable, Comparable, Comparator, DeepEquality { Index: tck/src/main/java/org/apache/jdo/tck/pc/company/Employee.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/Employee.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/Employee.java (working copy) @@ -25,12 +25,14 @@ import java.util.HashSet; import java.util.Set; -import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents an employee. */ +@PersistenceCapable public abstract class Employee extends Person implements IEmployee { private Date hiredate; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/FullTimeEmployee.java (working copy) @@ -19,12 +19,14 @@ import java.util.Date; -import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a full-time employee. */ +@PersistenceCapable public class FullTimeEmployee extends Employee implements IFullTimeEmployee { private double salary; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/Insurance.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/Insurance.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/Insurance.java (working copy) @@ -24,11 +24,14 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents an insurance carrier selection for a particular * Employee. */ -public abstract class Insurance +@PersistenceCapable +public abstract class Insurance implements IInsurance, Serializable, Comparable, Comparator, DeepEquality { private long insid; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/MedicalInsurance.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a dental insurance carrier selection for a * particular Employee. */ +@PersistenceCapable public class MedicalInsurance extends Insurance implements IMedicalInsurance { private String planType; // possible values: "PPO", "EPO", "NPO" Index: tck/src/main/java/org/apache/jdo/tck/pc/company/MeetingRoom.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/MeetingRoom.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/MeetingRoom.java (working copy) @@ -23,10 +23,13 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a meeting room. */ -public class MeetingRoom +@PersistenceCapable +public class MeetingRoom implements IMeetingRoom, Serializable, Comparable, Comparator, DeepEquality { private long roomid; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/Person.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/Person.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/Person.java (working copy) @@ -31,10 +31,13 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a person. */ -public class Person +@PersistenceCapable +public class Person implements IPerson, Serializable, Comparable, Comparator, DeepEquality { private long personid; Index: tck/src/main/java/org/apache/jdo/tck/pc/company/Project.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/company/Project.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/company/Project.java (working copy) @@ -30,11 +30,14 @@ import org.apache.jdo.tck.util.DeepEquality; import org.apache.jdo.tck.util.EqualityHelper; +import javax.jdo.annotations.PersistenceCapable; + /** * This class represents a project, a budgeted task with one or more * employees working on it. */ -public class Project +@PersistenceCapable +public class Project implements IProject, Serializable, Comparable, Comparator, DeepEquality { private long projid; Index: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/mylib/PrimitiveTypes.java (working copy) @@ -17,11 +17,13 @@ package org.apache.jdo.tck.pc.mylib; +import javax.jdo.annotations.PersistenceCapable; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Date; +@PersistenceCapable public class PrimitiveTypes implements Serializable { private static long counter = new Date().getTime(); Index: tck/src/main/java/org/apache/jdo/tck/pc/mylib/VersionedPCPoint.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/mylib/VersionedPCPoint.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/mylib/VersionedPCPoint.java (working copy) @@ -17,6 +17,7 @@ package org.apache.jdo.tck.pc.mylib; +import javax.jdo.annotations.PersistenceCapable; import java.io.Serializable; import java.util.Date; @@ -25,6 +26,7 @@ * * @author Marina Vatkina */ +@PersistenceCapable public class VersionedPCPoint implements Serializable { Index: tck/src/main/java/org/apache/jdo/tck/pc/query/NoExtent.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/pc/query/NoExtent.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/pc/query/NoExtent.java (working copy) @@ -17,9 +17,12 @@ package org.apache.jdo.tck.pc.query; +import javax.jdo.annotations.PersistenceCapable; + /** * The PC class for testing JDOQL queries. */ +@PersistenceCapable public class NoExtent { /** Index: tck/src/main/java/org/apache/jdo/tck/query/QueryElementHolder.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/QueryElementHolder.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/QueryElementHolder.java (working copy) @@ -18,8 +18,10 @@ package org.apache.jdo.tck.query; import javax.jdo.Extent; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Query; +import java.util.Map; /** * This class is an abstraction of a JDOQL query, @@ -56,6 +58,8 @@ private String toString; private Long fromLong; private Long toLong; + private JDOQLTypedQuery jdoqlTypedQuery; + private Map paramValues; /** * Returns an instance of this class holding the given arguments @@ -103,9 +107,60 @@ this.fromString = from; this.toString = to; } - + /** * Returns an instance of this class holding the given arguments + * such as the candidate class, the filter, etc. + * The given arguments represent JDOQL query elements. + * It is valid to pass null as a value + * for JDOQL querys elements. Such elements are not transfered into a + * JDO {@link javax.jdo.Query} instance. + * Instead, the default of JDO {@link javax.jdo.Query} instance is taken. + * @param unique the JDOQL unique query element + * @param result the JDOQL result query element + * @param resultClass the JDOQL result class query element + * @param candidateClass the JDOQL candidate class query element + * @param excludeSubClasses the JDOQL exclude subclasses query element + * @param filter the JDOQL filter query element + * @param variables the JDOQL variables query element + * @param parameters the JDOQL parameters query element + * @param imports the JDOQL imports query element + * @param grouping the JDOQL grouping query element + * @param ordering the JDOQL ordering query element + * @param from the JDOQL range from query element + * @param to the JDOQL range to query element + */ + public QueryElementHolder(Boolean unique, String result, + Class resultClass, Class candidateClass, + Boolean excludeSubClasses, String filter, + String variables, String parameters, String imports, + String grouping, String ordering, String from, String to, + JDOQLTypedQuery jdoqlTypedQuery, + Map paramValues) { + if (from == null ^ to == null) { + throw new IllegalArgumentException( + "Arguments from and to must both be null, " + + "or must not be null both."); + } + this.unique = unique; + this.result = result; + this.resultClass = resultClass; + this.candidateClass = candidateClass; + this.excludeSubClasses = excludeSubClasses; + this.filter = filter; + this.variables = variables; + this.parameters = parameters; + this.imports = imports; + this.grouping = grouping; + this.ordering = ordering; + this.fromString = from; + this.toString = to; + this.jdoqlTypedQuery = jdoqlTypedQuery; + this.paramValues = paramValues; + } + + /** + * Returns an instance of this class holding the given arguments * such as the candidate class, the filter, etc. * The given arguments represent JDOQL query elements. * It is valid to pass null as a value @@ -145,6 +200,52 @@ this.fromLong = new Long(from); this.toLong = new Long(to); } + + /** + * Returns an instance of this class holding the given arguments + * such as the candidate class, the filter, etc. + * The given arguments represent JDOQL query elements. + * It is valid to pass null as a value + * for JDOQL querys elements. Such elements are not transfered into a + * JDO {@link javax.jdo.Query} instance. + * Instead, the default of JDO {@link javax.jdo.Query} instance is taken. + * @param unique the JDOQL unique query element + * @param result the JDOQL result query element + * @param resultClass the JDOQL result class query element + * @param candidateClass the JDOQL candidate class query element + * @param excludeSubClasses the JDOQL exclude subclasses query element + * @param filter the JDOQL filter query element + * @param variables the JDOQL variables query element + * @param parameters the JDOQL parameters query element + * @param imports the JDOQL imports query element + * @param grouping the JDOQL grouping query element + * @param ordering the JDOQL ordering query element + * @param from the JDOQL from query element + * @param to the JDOQL to query element + */ + public QueryElementHolder(Boolean unique, String result, + Class resultClass, Class candidateClass, + Boolean excludeSubClasses, String filter, + String variables, String parameters, String imports, + String grouping, String ordering, long from, long to, + JDOQLTypedQuery jdoqlTypedQuery, + Map paramValues) { + this.unique = unique; + this.result = result; + this.resultClass = resultClass; + this.candidateClass = candidateClass; + this.excludeSubClasses = excludeSubClasses; + this.filter = filter; + this.variables = variables; + this.parameters = parameters; + this.imports = imports; + this.grouping = grouping; + this.ordering = ordering; + this.fromLong = new Long(from); + this.toLong = new Long(to); + this.jdoqlTypedQuery = jdoqlTypedQuery; + this.paramValues = paramValues; + } /** * Returns the single string JDOQL representation. @@ -226,8 +327,19 @@ rangeToAPI(query); return query; } - + /** + * Returns the JDOQLTypedQuery instance. + * @return the JDOQLTypedQuery instance + */ + public JDOQLTypedQuery getJDOQLTypedQuery() { + if (this.jdoqlTypedQuery != null) { + this.rangeToJDOQLTypedQuery(this.jdoqlTypedQuery); + } + return this.jdoqlTypedQuery; + } + + /** * Returns the unique JDOQL query element. * @return the unique JDOQL query element. */ @@ -252,6 +364,14 @@ } /** + * Returns the map of parameter values. + * @return the map of parameter values + */ + public Map getParamValues() { + return this.paramValues; + } + + /** * Delegates to {@link QueryElementHolder#toString(String, String) * if argument clazz does not equal null, * otherwise returns an empty string. @@ -334,4 +454,17 @@ query.setRange(this.fromLong.longValue(), this.toLong.longValue()); } } + + /** + * Call JDOQLTypedQuery API method {@link javax.jdo.JDOQLTypedQuery#range(long, long)}. + * @param query the JDOQLTypedQuery instance + */ + private void rangeToJDOQLTypedQuery(JDOQLTypedQuery query) { + if (this.fromString != null && this.toString != null) { + query.range(Long.parseLong(this.fromString), Long.parseLong(this.toString)); + } + else if (this.fromLong != null && this.toLong != null) { + query.range(this.fromLong.longValue(), this.toLong.longValue()); + } + } } Index: tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/QueryTest.java (working copy) @@ -29,6 +29,8 @@ import java.util.Map; import javax.jdo.JDOException; +import javax.jdo.JDOFatalInternalException; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.JDOUserException; import javax.jdo.PersistenceManager; import javax.jdo.Query; @@ -1046,28 +1048,10 @@ */ protected void executeAPIQuery(String assertion, QueryElementHolder queryElementHolder, Object expectedResult) { - executeAPIQuery(assertion, queryElementHolder, null, expectedResult); - } - - /** - * Executes the given query element holder instance as a JDO API query. - * The result of that query is compared against the given argument - * expectedResult. - * If the expected result does not match the returned query result, - * then the test case fails prompting argument assertion. - * @param assertion the assertion to prompt if the test case fails. - * @param queryElementHolder the query to execute. - * @param parameters the parmaters of the query. - * @param expectedResult the expected query result. - */ - protected void executeAPIQuery(String assertion, - QueryElementHolder queryElementHolder, - Object[] parameters, Object expectedResult) { if (logger.isDebugEnabled()) { logger.debug("Executing API query: " + queryElementHolder); } - execute(assertion, queryElementHolder, false, - parameters, expectedResult); + execute(assertion, queryElementHolder, false, expectedResult); } /** @@ -1083,33 +1067,90 @@ */ protected void executeSingleStringQuery(String assertion, QueryElementHolder queryElementHolder, Object expectedResult) { - executeSingleStringQuery(assertion, queryElementHolder, - null, expectedResult); + if (logger.isDebugEnabled()) + logger.debug("Executing single string query: " + + queryElementHolder); + execute(assertion, queryElementHolder, true, expectedResult); } - + /** - * Executes the given query element holder instance - * as a JDO single string query. - * The result of that query is compared against the given argument - * expectedResult. - * If the expected result does not match the returned query result, - * then the test case fails prompting argument assertion. - * @param assertion the assertion to prompt if the test case fails. - * @param queryElementHolder the query to execute. - * @param parameters the parmaters of the query. - * @param expectedResult the expected query result. + * + * @param assertion + * @param queryElementHolder + * @param expectedResult */ - protected void executeSingleStringQuery(String assertion, - QueryElementHolder queryElementHolder, - Object[] parameters, Object expectedResult) { - if (logger.isDebugEnabled()) - logger.debug("Executing single string query: " + - queryElementHolder); - execute(assertion, queryElementHolder, true, - parameters, expectedResult); + protected void executeJDOQLTypedQuery(String assertion, QueryElementHolder queryElementHolder, + Object expectedResult) { + executeJDOQLTypedQuery(assertion, queryElementHolder, null, expectedResult); } /** + * + * @param assertion + * @param queryElementHolder + * @param resultClass + * @param expectedResult + */ + protected void executeJDOQLTypedQuery(String assertion, QueryElementHolder queryElementHolder, + Class resultClass, Object expectedResult) { + String singleStringQuery = queryElementHolder.toString(); + getPM(); + Transaction tx = pm.currentTransaction(); + tx.begin(); + try { + JDOQLTypedQuery query = queryElementHolder.getJDOQLTypedQuery(); + if (query == null) { + throw new JDOFatalInternalException("Missing JDOQLTyped instance"); + } + Object result = null; + try { + Map paramValues = queryElementHolder.getParamValues(); + if (paramValues != null) { + query.setParameters(paramValues); + } + + if (resultClass != null) { + if (queryElementHolder.isUnique()) { + // result class specified and unique result + result = query.executeResultUnique(resultClass); + } else { + // result class specified and list result + result = query.executeResultList(resultClass); + } + } else { + if (queryElementHolder.isUnique()) { + // no result class and unique result + result = query.executeUnique(); + } else { + // no result class and list result + result = query.executeList(); + } + } + + if (logger.isDebugEnabled()) { + logger.debug("Query result: " + ConversionHelper. + convertObjectArrayElements(result)); + } + + checkResult(assertion, singleStringQuery, queryElementHolder.hasOrdering(), + result, expectedResult, true); + } finally { + query.close(result); + } + } catch (JDOUserException e) { + String msg = "JDOUserException thrown while executing query:\n" + singleStringQuery; + throw new JDOException(msg, e); + } catch (JDOException e) { + String msg = "JDOException thrown while executing query:\n" + singleStringQuery; + throw new JDOException(msg, e); + } finally { + if (tx.isActive()) { + tx.rollback(); + } + } + } + + /** * Converts the given query element holder instance * to a JDO query instance, * based on argument asSingleString. @@ -1119,13 +1160,11 @@ * @param queryElementHolder the query to execute. * @param asSingleString determines if the query is executed as * single string query or as API query. - * @param parameters the parmaters of the query. * @param expectedResult the expected query result. * @return the query result */ - private Object execute(String assertion, - QueryElementHolder queryElementHolder, boolean asSingleString, - Object parameters, Object expectedResult) { + private Object execute(String assertion, QueryElementHolder queryElementHolder, + boolean asSingleString, Object expectedResult) { getPM(); Query query = asSingleString ? queryElementHolder.getSingleStringQuery(pm) : @@ -1132,7 +1171,7 @@ queryElementHolder.getAPIQuery(pm); Object result = execute(assertion, query, queryElementHolder.toString(), - queryElementHolder.hasOrdering(), parameters, + queryElementHolder.hasOrdering(), queryElementHolder.getParamValues(), expectedResult, true); return result; } @@ -1285,18 +1324,8 @@ convertObjectArrayElements(result)); } - if (positive) { - if (hasOrdering) { - checkQueryResultWithOrder(assertion, singleStringQuery, result, - expectedResult); - } else { - checkQueryResultWithoutOrder(assertion, singleStringQuery, result, - expectedResult); - } - } else { - fail(assertion, "Query must throw JDOUserException: " + - singleStringQuery); - } + checkResult(assertion, singleStringQuery, hasOrdering, result, expectedResult, positive); + } finally { query.close(result); } @@ -1319,6 +1348,31 @@ } /** + * @param assertion the assertion to prompt if the test case fails. + * @param singleStringQuery the single string representation of the query. + * This parameter is only used as part of the falure message. + * @param hasOrdering indicates if the query has an ordering clause. + * @param positive indicates if query execution is supposed to fail + * @param result the query result. + * @param expectedResult the expected query result. + */ + private void checkResult(String assertion, String singleStringQuery, boolean hasOrdering, + Object result, Object expectedResult, boolean positive) { + if (positive) { + if (hasOrdering) { + checkQueryResultWithOrder(assertion, singleStringQuery, result, + expectedResult); + } else { + checkQueryResultWithoutOrder(assertion, singleStringQuery, result, + expectedResult); + } + } else { + fail(assertion, "Query must throw JDOUserException: " + + singleStringQuery); + } + } + + /** * Converts the given query element holder instance to a * JDO query instance. * Calls {@link Query#deletePersistentAll()}, or @@ -1330,18 +1384,16 @@ * then the test case fails prompting argument assertion. * @param assertion the assertion to prompt if the test case fails. * @param queryElementHolder the query to execute. - * @param parameters the parmaters of the query. * @param expectedNrOfDeletedObjects the expected number of deleted objects. */ protected void deletePersistentAllByAPIQuery(String assertion, QueryElementHolder queryElementHolder, - Object parameters, long expectedNrOfDeletedObjects) { + long expectedNrOfDeletedObjects) { if (logger.isDebugEnabled()) { logger.debug("Deleting persistent by API query: " + queryElementHolder); } - delete(assertion, queryElementHolder, false, - parameters, expectedNrOfDeletedObjects); + delete(assertion, queryElementHolder, false, expectedNrOfDeletedObjects); } /** @@ -1356,18 +1408,15 @@ * then the test case fails prompting argument assertion. * @param assertion the assertion to prompt if the test case fails. * @param queryElementHolder the query to execute. - * @param parameters the parmaters of the query. * @param expectedNrOfDeletedObjects the expected number of deleted objects. */ protected void deletePersistentAllBySingleStringQuery(String assertion, - QueryElementHolder queryElementHolder, - Object parameters, long expectedNrOfDeletedObjects) { + QueryElementHolder queryElementHolder, long expectedNrOfDeletedObjects) { if (logger.isDebugEnabled()) { logger.debug("Deleting persistent by single string query: " + queryElementHolder); } - delete(assertion, queryElementHolder, true, - parameters, expectedNrOfDeletedObjects); + delete(assertion, queryElementHolder, true, expectedNrOfDeletedObjects); } /** @@ -1388,17 +1437,16 @@ * @param expectedNrOfDeletedObjects the expected number of deleted objects. */ private void delete(String assertion, - QueryElementHolder queryElementHolder, boolean asSingleString, - Object parameters, long expectedNrOfDeletedObjects) { + QueryElementHolder queryElementHolder, boolean asSingleString, long expectedNrOfDeletedObjects) { getPM(); Query query = asSingleString ? queryElementHolder.getSingleStringQuery(pm) : queryElementHolder.getAPIQuery(pm); delete(assertion, query, queryElementHolder.toString(), - parameters, expectedNrOfDeletedObjects); + queryElementHolder.getParamValues(), expectedNrOfDeletedObjects); boolean positive = expectedNrOfDeletedObjects >= 0; if (positive) { - execute(assertion, queryElementHolder, asSingleString, parameters, + execute(assertion, queryElementHolder, asSingleString, queryElementHolder.isUnique() ? null : new ArrayList()); } } Index: tck/src/main/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/delete/DeletePersistentAll.java (working copy) @@ -23,10 +23,12 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Insurance; -import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.Query; +import javax.jdo.Transaction; + /** *Title: Delete Persistent All. *
@@ -50,41 +52,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.8-1 (DeletePersistentAll) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Insurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Insurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "carrier == param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "String param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -93,47 +60,179 @@ public static void main(String[] args) { BatchTestRunner.run(DeletePersistentAll.class); } - + /** */ public void testNoParametersAPI() { - deletePersistentAllByAPIQuery(ASSERTION_FAILED, - VALID_QUERIES[0], null, 11); + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = "SELECT FROM org.apache.jdo.tck.pc.company.Insurance"; + query = pm.newQuery(Insurance.class); + long expectedNrOfDeletedObjects = 11; + long nr = query.deletePersistentAll(); + if (nr != expectedNrOfDeletedObjects) { + fail(ASSERTION_FAILED, "deletePersistentAll returned " + nr + + ", expected is " + expectedNrOfDeletedObjects + + ". Query: " + singleStringQuery); + } + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } } /** */ public void testNoParametersSingleString() { - deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, - VALID_QUERIES[0], null, 11); + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = "SELECT FROM org.apache.jdo.tck.pc.company.Insurance"; + query = pm.newQuery(singleStringQuery); + long expectedNrOfDeletedObjects = 11; + long nr = query.deletePersistentAll(); + if (nr != expectedNrOfDeletedObjects) { + fail(ASSERTION_FAILED, "deletePersistentAll returned " + nr + + ", expected is " + expectedNrOfDeletedObjects + + ". Query: " + singleStringQuery); + } + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } } /** */ public void testObjectArrayParametersAPI() { - Object[] parameters = new Object[] {"Carrier1"}; - deletePersistentAllByAPIQuery(ASSERTION_FAILED, - VALID_QUERIES[1], parameters, 2); + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = "SELECT FROM org.apache.jdo.tck.pc.company.Insurance " + + "WHERE carrier == param PARAMETERS String param"; + query = pm.newQuery(Insurance.class, "carrier == param"); + query.declareParameters("String param"); + Object[] parameters = new Object[] {"Carrier1"}; + long expectedNrOfDeletedObjects = 2; + long nr = query.deletePersistentAll(parameters); + if (nr != expectedNrOfDeletedObjects) { + fail(ASSERTION_FAILED, "deletePersistentAll returned " + nr + + ", expected is " + expectedNrOfDeletedObjects + + ". Query: " + singleStringQuery); + } + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } } /** */ public void testObjectArrayParametersSingleString() { - Object[] parameters = new Object[] {"Carrier1"}; - deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, - VALID_QUERIES[1], parameters, 2); + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = "SELECT FROM org.apache.jdo.tck.pc.company.Insurance " + + "WHERE carrier == param PARAMETERS String param"; + query = pm.newQuery(singleStringQuery); + Object[] parameters = new Object[] {"Carrier1"}; + long expectedNrOfDeletedObjects = 2; + long nr = query.deletePersistentAll(parameters); + if (nr != expectedNrOfDeletedObjects) { + fail(ASSERTION_FAILED, "deletePersistentAll returned " + nr + + ", expected is " + expectedNrOfDeletedObjects + + ". Query: " + singleStringQuery); + } + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } } /** */ public void testMapParametersAPI() { - Map parameters = new HashMap(); - parameters.put("param", "Carrier1"); - deletePersistentAllByAPIQuery(ASSERTION_FAILED, - VALID_QUERIES[1], parameters, 2); + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = "SELECT FROM org.apache.jdo.tck.pc.company.Insurance " + + "WHERE carrier == param PARAMETERS String param"; + query = pm.newQuery(Insurance.class, "carrier == param"); + query.declareParameters("String param"); + Map parameters = new HashMap(); + parameters.put("param", "Carrier1"); + long expectedNrOfDeletedObjects = 2; + long nr = query.deletePersistentAll(parameters); + if (nr != expectedNrOfDeletedObjects) { + fail(ASSERTION_FAILED, "deletePersistentAll returned " + nr + + ", expected is " + expectedNrOfDeletedObjects + + ". Query: " + singleStringQuery); + } + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } } /** */ public void testMapParametersSingleString() { - Map parameters = new HashMap(); - parameters.put("param", "Carrier1"); - deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, - VALID_QUERIES[1], parameters, 2); + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = "SELECT FROM org.apache.jdo.tck.pc.company.Insurance " + + "WHERE carrier == param PARAMETERS String param"; + query = pm.newQuery(singleStringQuery); + Map parameters = new HashMap(); + parameters.put("param", "Carrier1"); + long expectedNrOfDeletedObjects = 2; + long nr = query.deletePersistentAll(parameters); + if (nr != expectedNrOfDeletedObjects) { + fail(ASSERTION_FAILED, "deletePersistentAll returned " + nr + + ", expected is " + expectedNrOfDeletedObjects + + ". Query: " + singleStringQuery); + } + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } } /** Index: tck/src/main/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/delete/DeleteQueryElements.java (working copy) @@ -18,15 +18,15 @@ package org.apache.jdo.tck.query.delete; import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.DentalInsurance; -import org.apache.jdo.tck.pc.company.FullTimeEmployee; import org.apache.jdo.tck.pc.company.Insurance; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; -import org.apache.jdo.tck.query.result.classes.FullName; import org.apache.jdo.tck.util.BatchTestRunner; /** @@ -51,29 +51,6 @@ "Assertion A14.8-1 (DeleteQueryElements) failed: "; /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ DentalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "((FullTimeEmployee)employee).salary > 10000 & " + - "employee.projects.contains(p) & p.budget > limit", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ "BigDecimal limit", - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Project; " + - "import java.math.BigDecimal;", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The array of invalid queries which may be executed as * single string queries and as API queries. */ @@ -220,25 +197,63 @@ /** */ public void testAPI() { - int index = 0; - deletePersistentAllByAPIQuery(ASSERTION_FAILED, - VALID_QUERIES[index], parameters[index], 1); + Map paramValues = new HashMap<>(); + paramValues.put("limit", new BigDecimal("2500000")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "((FullTimeEmployee)employee).salary > 10000 & " + + "employee.projects.contains(p) & p.budget > limit", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ "BigDecimal limit", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Project; " + + "import java.math.BigDecimal;", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + deletePersistentAllByAPIQuery(ASSERTION_FAILED, holder, 1); } /** */ public void testSingleString() { - int index = 0; - deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, - VALID_QUERIES[index], parameters[index], 1); + Map paramValues = new HashMap<>(); + paramValues.put("limit", new BigDecimal("2500000")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "((FullTimeEmployee)employee).salary > 10000 & " + + "employee.projects.contains(p) & p.budget > limit", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ "BigDecimal limit", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Project; " + + "import java.math.BigDecimal;", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, holder,1); } /** */ public void testNegative() { for (int i = 0; i < INVALID_QUERIES.length; i++) { - deletePersistentAllByAPIQuery(ASSERTION_FAILED, - INVALID_QUERIES[i], null, -1); - deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, - INVALID_QUERIES[i], null, -1); + deletePersistentAllByAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], -1); + deletePersistentAllBySingleStringQuery(ASSERTION_FAILED, INVALID_QUERIES[i], -1); } } Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/Cast.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/Cast.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/Cast.java (working copy) @@ -21,10 +21,17 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.FullTimeEmployee; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QFullTimeEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; + /** *Title: Cast Query Operator *
@@ -43,49 +50,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.2-38 (Cast) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "((FullTimeEmployee)this).salary > 15000.0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.FullTimeEmployee", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e) && ((FullTimeEmployee)e).salary > 15000.0", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.FullTimeEmployee", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{"dept1", "dept2"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -96,14 +60,71 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.cast(FullTimeEmployee.class); + query.filter(cast.salary.gt(15000.0)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "((FullTimeEmployee)this).salary > 15000.0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.FullTimeEmployee", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: cast not yet supported + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + /** */ + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1", "dept2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.cast(FullTimeEmployee.class); + query.filter(cand.employees.contains(e).and(cast.salary.gt(15000.0))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && ((FullTimeEmployee)e).salary > 15000.0", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.FullTimeEmployee", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: cast not yet supported + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/CharacterAndStringLiterals.java (working copy) @@ -20,10 +20,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.mylib.MylibReader; import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.pc.mylib.QPrimitiveTypes; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Character and String Literals. *
@@ -80,49 +83,6 @@ /*TO*/ null) }; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ PrimitiveTypes.class, - /*EXCLUDE*/ null, - /*WHERE*/ "stringNull.startsWith('Even') || charNotNull == 'O'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ PrimitiveTypes.class, - /*EXCLUDE*/ null, - /*WHERE*/ "stringNull.startsWith(\"Even\") || charNotNull == \"O\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesCharacterStringLiterals"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -131,19 +91,73 @@ public static void main(String[] args) { BatchTestRunner.run(CharacterAndStringLiterals.class); } - - /** */ - public void testPositive() { - if (isUnconstrainedVariablesSupported()) { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } - } + + /** + * + */ + public void testPositive1() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesCharacterStringLiterals"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.stringNull.startsWith("Even").or(cand.charNotNull.eq('0'))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ PrimitiveTypes.class, + /*EXCLUDE*/ null, + /*WHERE*/ "stringNull.startsWith('Even') || charNotNull == 'O'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + /** + * + */ + public void testPositive2() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesCharacterStringLiterals"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.stringNull.startsWith("Even").or(cand.charNotNull.eq('0'))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ PrimitiveTypes.class, + /*EXCLUDE*/ null, + /*WHERE*/ "stringNull.startsWith(\"Even\") || charNotNull == \"O\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** */ public void testNegative() { for (int i = 0; i < INVALID_QUERIES.length; i++) { Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingCollectionFieldToNull.java (working copy) @@ -20,10 +20,15 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import java.util.ArrayList; +import java.util.List; + /** *Title: Comparing a Collection Field to Null *
@@ -46,30 +51,9 @@ "Assertion A14.6.2-36 (ComparingCollectionFieldToNull) failed: "; /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1 && projects == null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The expected results of valid queries. */ - private Object[] expectedResult; + private List expectedResult; /** * The main is called when the class @@ -82,12 +66,30 @@ /** */ public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.personid.eq(1L).and(cand.projects.eq(null))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1 && projects == null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); } /** @@ -97,13 +99,12 @@ addTearDownClass(CompanyModelReader.getTearDownClasses()); loadAndPersistCompanyModel(getPM()); Employee employee = (Employee) getPersistentCompanyModelInstance("emp1"); - expectedResult = new Object[] { + expectedResult = // emp1 should be in the query result set, // if the JDO Implentation supports null values for Collections getTransientCompanyModelInstancesAsList( isNullCollectionSupported() ? - new String[]{"emp1"} : new String[]{}) - }; + new String[]{"emp1"} : new String[]{}); if (isNullCollectionSupported()) { getPM().currentTransaction().begin(); employee.setProjects(null); Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/ComparingPersistentAndNonPersistentInstance.java (working copy) @@ -20,10 +20,16 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; +import java.util.HashMap; +import java.util.Map; + /** *Title: Comparing persistent and non-persistent instance *
@@ -42,55 +48,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-44 (ComparingPersistentAndNonPersistentInstance) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this == param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Employee param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.personid == param.personid", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Employee param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; - - /** Parameters of valid queries. */ - private Object[][] parameters = { - {getTransientCompanyModelInstance("emp1")}, - {getTransientCompanyModelInstance("emp1")} - }; /** * The main is called when the class @@ -100,16 +57,75 @@ public static void main(String[] args) { BatchTestRunner.run(ComparingPersistentAndNonPersistentInstance.class); } - + /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("param", Employee.class); + query.filter(cand.eq(empParam)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", getTransientCompanyModelInstance("emp1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this == param", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Employee param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + /** */ + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParamExpression = query.parameter("param", Employee.class); + QEmployee empParam = QEmployee.parameter("param"); + query.filter(cand.personid.eq(empParam.personid)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", getTransientCompanyModelInstance("emp1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.personid == param.personid", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Employee param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/DenoteUniquenessInFilter.java (working copy) @@ -20,10 +20,14 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Element Returned in Query Result *
@@ -49,109 +53,130 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-2 (DenoteUniquenessInFilter) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. */ - private static final QueryElementHolder[] VALID_QUERIES = { + public static void main(String[] args) { + BatchTestRunner.run(DenoteUniquenessInFilter.class); + } + + /** */ + public void testPositive0() { // Uniqueness not specified. // emp1 qualifies for both contains clause => result is dept1 - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e1) && (e1.personid == 1 && " + - "(employees.contains(e2) && (e2.weeklyhours == 40)))", - /*VARIABLES*/ "Employee e1; Employee e2", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e1 = QEmployee.variable("e1"); + QEmployee e2 = QEmployee.variable("e2"); + query.filter(cand.employees.contains(e1).and(e1.personid.eq(1l).and( + cand.employees.contains(e2).and(e2.weeklyhours.eq(40d))))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e1) && (e1.personid == 1 && " + + "(employees.contains(e2) && (e2.weeklyhours == 40)))", + /*VARIABLES*/ "Employee e1; Employee e2", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive1() { // Uniqueness specified. // Only emp3 qualifies for both contains clause. // Condition e1 != e2 violated => result is empty - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e1) && (e1.personid == 3 && " + - "(employees.contains(e2) && (e2.weeklyhours == 19 && " + - "e1 != e2)))", - /*VARIABLES*/ "Employee e1; Employee e2", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), + Object expected = getTransientCompanyModelInstancesAsList(new String[]{}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e1 = QEmployee.variable("e1"); + QEmployee e2 = QEmployee.variable("e2"); + query.filter(cand.employees.contains(e1).and(e1.personid.eq(3l).and( + cand.employees.contains(e2).and(e2.weeklyhours.eq(19d).and(e1.ne(e2)))))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e1) && (e1.personid == 3 && " + + "(employees.contains(e2) && (e2.weeklyhours == 19 && " + + "e1 != e2)))", + /*VARIABLES*/ "Employee e1; Employee e2", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive2() { // Uniqueness specified. // Only emp1 matches the first contains clause. // emp1 and emp2 match the second contains clause. // Thus, there are two different values for e1 and e2 // satifying the entire filter => result is dept1 - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e1) && (e1.personid == 1 && " + - "(employees.contains(e2) && (e2.weeklyhours == 40 && " + - "e1 != e2)))", - /*VARIABLES*/ "Employee e1; Employee e2", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // Uniqueness not specified. - // emp1 qualifies for both contains clause => result is dept1 - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - // Uniqueness specified. - // Only emp3 qualifies for both contains clause. - // Condition e1 != e2 violated => result is empty - getTransientCompanyModelInstancesAsList(new String[]{}), - // Uniqueness specified. - // Only emp1 matches the first contains clause. - // emp1 and emp2 match the second contains clause. - // Thus, there are two different values for e1 and e2 - // satifying the entire filter => result is dept1 - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(DenoteUniquenessInFilter.class); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e1 = QEmployee.variable("e1"); + QEmployee e2 = QEmployee.variable("e2"); + query.filter(cand.employees.contains(e1).and(e1.personid.eq(1l).and( + cand.employees.contains(e2).and(e2.weeklyhours.eq(40d).and(e1.ne(e2)))))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e1) && (e1.personid == 1 && " + + "(employees.contains(e2) && (e2.weeklyhours == 40 && " + + "e1 != e2)))", + /*VARIABLES*/ "Employee e1; Employee e2", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/Having.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/Having.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/Having.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Having. *
@@ -42,44 +45,8 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.10-2 (Having) failed: "; - + /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department, AVG(weeklyhours)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ "department HAVING COUNT(department) > 0", - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // HAVING clause uses field that isn't contained in the SELECT clause. - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department, AVG(weeklyhours)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ "department HAVING COUNT(personid) > 1", - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The array of invalid queries which may be executed as * single string queries and as API queries. */ @@ -115,26 +82,6 @@ /*FROM*/ null, /*TO*/ null) }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - Arrays.asList(new Object[] { - new Object[] { - getTransientCompanyModelInstance("dept1"), - new Double(33.0)}, - new Object[] { - getTransientCompanyModelInstance("dept2"), - new Double(0.0)}}), - Arrays.asList(new Object[] { - new Object[] { - getTransientCompanyModelInstance("dept1"), - new Double(33.0)}, - new Object[] { - getTransientCompanyModelInstance("dept2"), - new Double(0.0)}}) - }; /** * The main is called when the class @@ -144,18 +91,83 @@ public static void main(String[] args) { BatchTestRunner.run(Having.class); } - + /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = Arrays.asList(new Object[] { + new Object[] { + getTransientCompanyModelInstance("dept1"), + new Double(33.0)}, + new Object[] { + getTransientCompanyModelInstance("dept2"), + new Double(0.0)}}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.groupBy(cand.department).having(cand.department.count().gt(0L)); + query.result(false, cand.department, cand.weeklyhours.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department, AVG(weeklyhours)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ "department HAVING COUNT(department) > 0", + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ + public void testPositive1() { + // HAVING clause uses field that isn't contained in the SELECT clause. + Object expected = Arrays.asList(new Object[] { + new Object[] { + getTransientCompanyModelInstance("dept1"), + new Double(33.0)}, + new Object[] { + getTransientCompanyModelInstance("dept2"), + new Double(0.0)}}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.groupBy(cand.department).having(cand.personid.count().gt(1L)); + query.result(false, cand.department, cand.weeklyhours.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department, AVG(weeklyhours)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ "department HAVING COUNT(personid) > 1", + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null , + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); + } + + /** */ public void testNegative() { for (int i = 0; i < INVALID_QUERIES.length; i++) { compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false); Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/IdentifiersEqualFieldNames.java (working copy) @@ -25,6 +25,11 @@ import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QPerson; + +import javax.jdo.JDOQLTypedQuery; + /** *Title: Identifiers Equal Field Names. *
@@ -42,95 +47,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-43 (IdentifiersEqualFieldNames) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.firstname == 'emp1First'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.personid < Byte.MAX_VALUE", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.size() > org.apache.jdo.tck.pc.company.Department.RECOMMENDED_NO_OF_EMPS", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.size() > Department.RECOMMENDED_NO_OF_EMPS", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.size() > RECOMMENDED_NO_OF_EMPS", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) - }; /** * The main is called when the class @@ -142,18 +58,160 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.eq("emp1First")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.firstname == 'emp1First'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + /** */ + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.lt((long)Byte.MAX_VALUE)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.personid < Byte.MAX_VALUE", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive2() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.employees.size().gt(org.apache.jdo.tck.pc.company.Department.RECOMMENDED_NO_OF_EMPS)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.size() > org.apache.jdo.tck.pc.company.Department.RECOMMENDED_NO_OF_EMPS", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive3() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.employees.size().gt(Department.RECOMMENDED_NO_OF_EMPS)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.size() > Department.RECOMMENDED_NO_OF_EMPS", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive4() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) ; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.employees.size().gt(Department.RECOMMENDED_NO_OF_EMPS)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.size() > RECOMMENDED_NO_OF_EMPS", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** * @see JDO_Test#localSetUp() */ + @Override protected void localSetUp() { addTearDownClass(CompanyModelReader.getTearDownClasses()); loadAndPersistCompanyModel(getPM()); Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/IfElseInFilter.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/IfElseInFilter.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/IfElseInFilter.java (working copy) @@ -22,10 +22,17 @@ import org.apache.jdo.tck.pc.company.DentalInsurance; import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.FullTimeEmployee; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QFullTimeEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.BooleanExpression; +import javax.jdo.query.IfThenElseExpression; +import javax.jdo.query.NumericExpression; + /** *Title: Use of If Else expression in filter *
@@ -41,73 +48,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.x (IfElseInFilter) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // simple If/Else using literals - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.salary > (IF (this.department.name == 'Development') 15000 ELSE 25000)", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.personid", - /*FROM*/ null, - /*TO*/ null), - // simple If/Else using relationships - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "(IF (this.manager == null) this.mentor.department.deptid ELSE this.manager.department.deptid) == this.department.deptid", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.personid", - /*FROM*/ null, - /*TO*/ null), - // multiple If/Else with distinct conditions - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "(IF (0.0 <= this.salary && this.salary < 10000.1) 1 ELSE IF (10000.1 <= this.salary && this.salary < 20000.1) 2 ELSE IF (20000.1 <= this.salary && this.salary < 30000.1) 3 ELSE 4) == 2", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.personid", - /*FROM*/ null, - /*TO*/ null), - // multiple If/Else with overlapping conditions - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "(IF (this.salary < 10000.1) 1 ELSE IF (this.salary < 20000.1) 2 ELSE IF (this.salary < 30000.1) 3 ELSE 4) == 2", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.personid", - /*FROM*/ null, - /*TO*/ null) - }; /** * The array of invalid queries which may be executed as @@ -160,16 +100,6 @@ /*FROM*/ null, /*TO*/ null) }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; /** * The main is called when the class @@ -179,18 +109,146 @@ public static void main(String[] args) { BatchTestRunner.run(IfElseInFilter.class); } - + /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + // simple If/Else using literals + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + IfThenElseExpression ifExpr = + query.ifThenElse(cand.department.name.eq("Development"), 15000.0,25000.0); + query.filter(cand.salary.gt(ifExpr)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.salary > (IF (this.department.name == 'Development') 15000 ELSE 25000)", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.personid", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + /** */ + public void testPositive1() { + // simple If/Else using relationships + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + IfThenElseExpression ifExpr = query.ifThenElse(Long.class, + cand.manager.eq((Employee)null), cand.mentor.department.deptid, cand.manager.department.deptid); + query.filter(ifExpr.eq(cand.department.deptid)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "(IF (this.manager == null) this.mentor.department.deptid ELSE this.manager.department.deptid) == this.department.deptid", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.personid", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** */ + public void testPositive2() { + // multiple If/Else with distinct conditions + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + BooleanExpression cond1 = cand.salary.gt(0.0).and(cand.salary.lt(10000.1)); + BooleanExpression cond2 = cand.salary.gt(10000.1).and(cand.salary.lt(20000.1)); + BooleanExpression cond3 = cand.salary.gt(20000.1).and(cand.salary.lt(30000.1)); + IfThenElseExpression ifExpr = + query.ifThen(cond1, 1).ifThen(cond2, 2).ifThen(cond3, 3).elseEnd(4); + query.filter(ifExpr.eq(2)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "(IF (0.0 <= this.salary && this.salary < 10000.1) 1 ELSE " + + "IF (10000.1 <= this.salary && this.salary < 20000.1) 2 ELSE " + + "IF (20000.1 <= this.salary && this.salary < 30000.1) 3 ELSE 4) == 2", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.personid", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** */ + public void testPositive3() { + // multiple If/Else with overlapping conditions + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + BooleanExpression cond1 = cand.salary.lt(10000.1); + BooleanExpression cond2 = cand.salary.lt(20000.1); + BooleanExpression cond3 = cand.salary.lt(30000.1); + IfThenElseExpression ifExpr = + query.ifThen(cond1, 1).ifThen(cond2, 2).ifThen(cond3, 3).elseEnd(4); + query.filter(ifExpr.eq(2)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "(IF (this.salary < 10000.1) 1 ELSE " + + "IF (this.salary < 20000.1) 2 ELSE IF (this.salary < 30000.1) 3 ELSE 4) == 2", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.personid", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ public void testNegative() { for (int i = 0; i < INVALID_QUERIES.length; i++) { compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false); Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/MultipleIdenticalImports.java (working copy) @@ -17,17 +17,17 @@ package org.apache.jdo.tck.query.jdoql; -import java.util.Collection; -import java.util.HashSet; +import java.util.HashMap; +import java.util.Map; -import javax.jdo.PersistenceManager; -import javax.jdo.Query; -import javax.jdo.Transaction; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; @@ -58,138 +58,120 @@ BatchTestRunner.run(MultipleIdenticalImports.class); } - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. + /** + * */ - private static final QueryElementHolder[] VALID_QUERIES = { + public void testImportDepartmentTwice() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("d", Department.class); + query.filter(cand.department.eq(empParam)); + + Map paramValues = new HashMap<>(); + paramValues.put("d", getPersistentCompanyModelInstance("dept1")); + // Import Department twice - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "department == d", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Department d", - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Department; " + - "import org.apache.jdo.tck.pc.company.Department;", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // Import Department explictly and per type-import-on-demand - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "department == d", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Department d", - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Department; " + - "import org.apache.jdo.tck.pc.company.*", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // type-import-on-demand twice - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "department == d", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Department d", - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.*; " + - "import org.apache.jdo.tck.pc.company.*", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "department == d", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Department d", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Department; " + + "import org.apache.jdo.tck.pc.company.Department;", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** + * */ - private Object[] expectedResult = { - // Import Department twice - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}), - // Import Department explictly and per type-import-on-demand - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}), - // type-import-on-demand twice - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}) - }; - - /** Parameters of valid queries. */ - private Object[][] parameters = { - // Import Department twice - {getPersistentCompanyModelInstance("dept1")}, - // Import Department explictly and per type-import-on-demand - {getPersistentCompanyModelInstance("dept1")}, - // type-import-on-demand twice - {getPersistentCompanyModelInstance("dept1")} - }; - - /** */ - void runTest(PersistenceManager pm, CompanyModelReader reader) { - Query query; - Collection expected; - Object result; - - Transaction tx = pm.currentTransaction(); - tx.begin(); - Department dept1 = (Department)reader.getDepartment("dept1"); - expected = new HashSet(); - expected.add(reader.getFullTimeEmployee("emp1")); - expected.add(reader.getFullTimeEmployee("emp2")); - expected.add(reader.getPartTimeEmployee("emp3")); - - // Import Department twice - query = pm.newQuery(Employee.class); - query.declareImports("import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Department;"); - query.declareParameters("Department d"); - query.setFilter("department == d"); - result = query.execute(dept1); - checkQueryResultWithoutOrder(ASSERTION_FAILED, "department == d", - result, expected); + public void testImportDepartmentExplicitlyAndPerTypeImportOnDemand() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("d", Department.class); + query.filter(cand.department.eq(empParam)); + + Map paramValues = new HashMap<>(); + paramValues.put("d", getPersistentCompanyModelInstance("dept1")); + // Import Department explictly and per type-import-on-demand - query = pm.newQuery(Employee.class); - query.declareImports("import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.*"); - query.declareParameters("Department d"); - query.setFilter("department == d"); - result = query.execute(dept1); - checkQueryResultWithoutOrder(ASSERTION_FAILED, "department == d", - result, expected); + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "department == d", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Department d", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Department; " + + "import org.apache.jdo.tck.pc.company.*", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** + * + */ + public void testTypeImportOnDemandTwice() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("d", Department.class); + query.filter(cand.department.eq(empParam)); + + Map paramValues = new HashMap<>(); + paramValues.put("d", getPersistentCompanyModelInstance("dept1")); + // type-import-on-demand twice - query = pm.newQuery(Employee.class); - query.declareImports("import org.apache.jdo.tck.pc.company.*; import org.apache.jdo.tck.pc.company.*"); - query.declareParameters("Department d"); - query.setFilter("department == d"); - result = query.execute(dept1); - checkQueryResultWithoutOrder(ASSERTION_FAILED, "department == d", - result, expected); + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "department == d", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Department d", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.*; " + + "import org.apache.jdo.tck.pc.company.*", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); - tx.commit(); - tx = null; + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationComparisonWithNull.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationComparisonWithNull.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationComparisonWithNull.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.FullTimeEmployee; import org.apache.jdo.tck.pc.company.MedicalInsurance; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QMedicalInsurance; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Transaction; import java.util.Calendar; @@ -64,188 +67,6 @@ return NAVIGATION_TEST_COMPANY_TESTDATA; } - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // 0: simple manager check being nill - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager == null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 1: simple manager check being not null - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager != null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 2: simple manager check being not null using not operator - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "!(this.manager == null)", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 3: manager's manager check - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager.manager == null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 4: manager's manager check with extra check on first level manager - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager != null && this.manager.manager == null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 5 : manager's manager check not being null - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager.manager != null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 6 : manager's manager check not being null using not operator - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "!(this.manager.manager == null)", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 7 : multiple relationships - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.employee.manager.manager == null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 8 : multiple relationships - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.employee != null && this.employee.manager != null && this.employee.manager.manager == null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 9 : multiple relationships - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.employee.manager.manager != null", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // 10 : multiple relationships - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "!(this.employee.manager.manager == null)", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - /** * Manager relationship: * emp0 @@ -261,47 +82,6 @@ * emp9 */ - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // 0 : this.manager == null - getTransientCompanyModelInstancesAsList(new String[]{ - "emp0", "emp4", "emp7"}), - // 1 : this.manager != null - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp5", "emp6", "emp8", "emp9", "emp10"}), - // 2 : !(this.manager == null) - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp5", "emp6", "emp8", "emp9", "emp10"}), - - // 3 : this.manager.manager == null - getTransientCompanyModelInstancesAsList(new String[]{ - "emp0", "emp1", "emp4", "emp5", "emp6", "emp7", "emp8", "emp9"}), - // 4: this.manager != null && this.manager.manager == null - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp5", "emp6", "emp8", "emp9"}), - // 5 : this.manager.manager != null - getTransientCompanyModelInstancesAsList(new String[]{ - "emp2", "emp3", "emp10"}), - // 6 : !(this.manager.manager == null) - getTransientCompanyModelInstancesAsList(new String[]{ - "emp2", "emp3", "emp10"}), - - // 7 : this.employee.manager.manager == null - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns1", "medicalIns4", "medicalIns5", "medicalIns98"}), - // 8 : this.employee != null && this.employee.manager != null && this.employee.manager.manager == null - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns1", "medicalIns5"}), - // 9 : this.employee.manager.manager != null - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns2", "medicalIns3"}), - // 10 : !(this.employee.manager.manager == null) - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns2", "medicalIns3"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -315,10 +95,33 @@ * this.manager == null */ public void testPositive0() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[0], - expectedResult[0]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[0], - expectedResult[0]); + // 0: simple manager check being null + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp0", "emp4", "emp7"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.eq((Employee)null)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager == null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -325,10 +128,33 @@ * this.manager != null */ public void testPositive1() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[1], - expectedResult[1]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[1], - expectedResult[1]); + // 1: simple manager check being not null + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp1", "emp2", "emp3", "emp5", "emp6", "emp8", "emp9", "emp10"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.ne((Employee)null)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager != null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -335,10 +161,34 @@ * !(this.manager == null) */ public void testPositive2() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[2], - expectedResult[2]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[2], - expectedResult[2]); + // 2: simple manager check being not null using not operator + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp1", "emp2", "emp3", "emp5", "emp6", "emp8", "emp9", "emp10"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.eq((Employee)null).not()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "!(this.manager == null)", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: Dont currently support operator NOT in JDOQL conversion + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -346,10 +196,34 @@ * Disabled, because it currently fails on the RI. */ public void testPositive3() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[3], - expectedResult[3]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[3], - expectedResult[3]); + // 3: manager's manager check + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp0", "emp1", "emp4", "emp5", "emp6", "emp7", "emp8", "emp9"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.manager.eq((Employee)null)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager.manager == null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -356,10 +230,34 @@ * this.manager != null && this.manager.manager == null */ public void testPositive4() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[4], - expectedResult[4]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[4], - expectedResult[4]); + // 4: manager's manager check with extra check on first level manager + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp1", "emp5", "emp6", "emp8", "emp9"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.ne((Employee)null).and(cand.manager.manager.eq((Employee)null))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager != null && this.manager.manager == null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -366,10 +264,34 @@ * this.manager.manager != null */ public void testPositive5() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[5], - expectedResult[5]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[5], - expectedResult[5]); + // 5 : manager's manager check not being null + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp2", "emp3", "emp10"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.manager.ne((Employee)null)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager.manager != null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -376,10 +298,36 @@ * !(this.manager.manager == null) */ public void testPositive6() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[6], - expectedResult[6]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[6], - expectedResult[6]); + // 6 : manager's manager check not being null using not operator + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"emp2", "emp3", "emp10"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.manager.manager.eq((Employee)null).not()); + + QueryElementHolder holder =new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "!(this.manager.manager == null)", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: Dont currently support operator NOT in JDOQL conversion + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -387,10 +335,33 @@ * Disabled, because it currently fails on the RI. */ public void testPositive7() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[7], - expectedResult[7]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[7], - expectedResult[7]); + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"medicalIns1", "medicalIns4", "medicalIns5", "medicalIns98"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.manager.manager.eq((Employee)null)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.employee.manager.manager == null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -397,10 +368,36 @@ * this.employee != null && this.employee.manager != null && this.employee.manager.manager == null */ public void testPositive8() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[8], - expectedResult[8]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[8], - expectedResult[8]); + // 8 : multiple relationships + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"medicalIns1", "medicalIns5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.ne((Employee)null).and(cand.employee.manager.ne((Employee)null)) + .and(cand.employee.manager.manager.eq((Employee)null))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.employee != null && this.employee.manager != null && " + + "this.employee.manager.manager == null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -407,10 +404,34 @@ * this.employee.manager.manager != null */ public void testPositive9() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[9], - expectedResult[9]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[9], - expectedResult[9]); + // 9 : multiple relationships + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"medicalIns2", "medicalIns3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.manager.manager.ne((Employee)null)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.employee.manager.manager != null", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -417,10 +438,34 @@ * !(this.employee.manager.manager == null) */ public void testPositive10() { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[10], - expectedResult[10]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[10], - expectedResult[10]); + Object expected = getTransientCompanyModelInstancesAsList( + new String[]{"medicalIns2", "medicalIns3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.manager.manager.eq((Employee)null).not()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "!(this.employee.manager.manager == null)", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: Dont currently support operator NOT in JDOQL conversion + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughACollectionField.java (working copy) @@ -20,10 +20,14 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Navigation Through a Collection Field *
@@ -54,34 +58,6 @@ protected String getCompanyTestDataResource() { return NAVIGATION_TEST_COMPANY_TESTDATA; } - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e) && e.firstname == \"emp1First\"", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) - }; /** * The main is called when the class @@ -94,12 +70,33 @@ /** */ public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.employees.contains(e).and(e.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && e.firstname == \"emp1First\"", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughANullValuedField.java (working copy) @@ -21,10 +21,14 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Navigation Through a Null-Valued Field *
@@ -57,122 +61,143 @@ protected String getCompanyTestDataResource() { return NAVIGATION_TEST_COMPANY_TESTDATA; } - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. */ - private static final QueryElementHolder[] VALID_QUERIES = { + public static void main(String[] args) { + BatchTestRunner.run(NavigationThroughANullValuedField.class); + } + + public void testPositive1() { // navigation through reference relationship field // the relationship medicalInsurance is not set for emp2 and emp3 => // they should not be part of the result - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.medicalInsurance.carrier == \"Carrier1\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.medicalInsurance.carrier.eq("Carrier1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.medicalInsurance.carrier == \"Carrier1\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + + } + public void testPositive2() { // navigation through reference relationship field // emp5 and emp6 have have emp4 as manager - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager.lastname == \"emp4Last\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp5", "emp6"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.lastname.eq("emp4Last")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager.lastname == \"emp4Last\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + public void testPositive3() { // multiple navigation through reference relationship field - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.manager.manager.lastname == \"emp0Last\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3", "emp10"}); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.manager.manager.lastname.eq("emp0Last")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.manager.manager.lastname == \"emp0Last\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + public void testPositive4() { // navigation through collection relationship field // employees emp2 and emp3 do not have a medicalInsurance, but emp1 - // matches the filter such that dept1 qualifies for inclusion in the + // matches the filter such that dept1 qualifies for inclusion in the // result set. - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e) && e.medicalInsurance.carrier == \"Carrier1\"", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // navigation through reference relationship field - // the relationship medicalInsurance is not set for emp2 and emp3 => - // they should not be part of the result - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // navigation through reference relationship field - // emp5 and emp6 have have emp4 as manager - getTransientCompanyModelInstancesAsList(new String[]{"emp5", "emp6"}), - // multiple navigation through reference relationship field - getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3", "emp10"}), - // navigation through collection relationship field - // employees emp2 and emp3 do not have a medicalInsurance, but emp1 - // matches the filter such that dept1 qualifies for inclusion in the - // result set. - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(NavigationThroughANullValuedField.class); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.employees.contains(e).and(e.medicalInsurance.carrier.eq("Carrier1"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && e.medicalInsurance.carrier == \"Carrier1\"", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: NucleusUserException: Variable 'medicalInsurance' is unbound and cannot be determined + // (is it a misspelled field name? or is not intended to be a variable?) + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/NavigationThroughReferencesUsesDotOperator.java (working copy) @@ -21,10 +21,14 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.MedicalInsurance; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QMedicalInsurance; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Navigation Through a References uses Dot Operator *
@@ -54,89 +58,7 @@ protected String getCompanyTestDataResource() { return NAVIGATION_TEST_COMPANY_TESTDATA; } - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // navigation through one relationship - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "medicalInsurance.carrier == \"Carrier1\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // navigation through multiple relationships - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.employee.department.name == \"Development\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // navigation through a self referencing relationship - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.employee.manager.firstname == \"emp1First\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // navigation through a self referencing relationship multiple times - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ MedicalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.employee.manager.manager.firstname == \"emp0First\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // navigation through one relationship - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // navigation through multiple relationships - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns1", "medicalIns2", "medicalIns3", "medicalIns4", "medicalIns5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns2", "medicalIns3"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "medicalIns2", "medicalIns3"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -145,17 +67,130 @@ public static void main(String[] args) { BatchTestRunner.run(NavigationThroughReferencesUsesDotOperator.class); } - - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + + public void testPositive0() { + // navigation through one relationship + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.medicalInsurance.carrier.eq("Carrier1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "medicalInsurance.carrier == \"Carrier1\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + public void testPositive1() { + // navigation through multiple relationships + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "medicalIns1", "medicalIns2", "medicalIns3", "medicalIns4", "medicalIns5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.department.name.eq("Development")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.employee.department.name == \"Development\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + public void testPositive2() { + // navigation through a self referencing relationship + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "medicalIns2", "medicalIns3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.manager.firstname.eq("emp1First")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.employee.manager.firstname == \"emp1First\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + public void testPositive3() { + // navigation through a self referencing relationship multiple times + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "medicalIns2", "medicalIns3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(MedicalInsurance.class); + QMedicalInsurance cand = QMedicalInsurance.candidate(); + query.filter(cand.employee.manager.manager.firstname.eq("emp0First")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ MedicalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.employee.manager.manager.firstname == \"emp0First\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndContainsMethod.java (working copy) @@ -21,10 +21,16 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Project; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; +import java.util.HashMap; +import java.util.Map; + /** *Title: Null Collections and Contains Method *
@@ -43,62 +49,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-35 (NullCollectionsAndContainsMethod) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // contains - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1 && projects.contains(p)", - /*VARIABLES*/ null, - /*PARAMETERS*/ "org.apache.jdo.tck.pc.company.Project p", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // contains - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "!team.contains(null)", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // contains - getTransientCompanyModelInstancesAsList(new String[]{}), - // contains - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}) - }; - - /** Parameters of valid queries. */ - private Object[][] parameters = { - // contains - {new Project(999l, "TestProject", null)}, - // contains - null - }; /** * The main is called when the class @@ -108,16 +58,80 @@ public static void main(String[] args) { BatchTestRunner.run(NullCollectionsAndContainsMethod.class); } - - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + + /** + * + */ + public void testContains1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("p", Project.class); + query.filter(cand.personid.eq(1L).and(cand.projects.contains(empParam))); + + Map paramValues = new HashMap<>(); + paramValues.put("p", getPersistentCompanyModelInstance("proj1")); + + // contains + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1 && projects.contains(p)", + /*VARIABLES*/ null, + /*PARAMETERS*/ "org.apache.jdo.tck.pc.company.Project p", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + /** + * + */ + public void testContains2() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("p", Project.class); + query.filter(cand.projects.contains(empParam)); + + Map paramValues = new HashMap<>(); + paramValues.put("p", getPersistentCompanyModelInstance("proj1")); + + // contains + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projects.contains(p)", + /*VARIABLES*/ null, + /*PARAMETERS*/ "org.apache.jdo.tck.pc.company.Project p", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/NullCollectionsAndIsEmpty.java (working copy) @@ -20,10 +20,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Handling of Null Collections and isEmpty in Queries *
@@ -42,36 +45,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.2-34 (NullCollectionsAndIsEmpty) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // isEmpty - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1 && projects.isEmpty()", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // isEmpty - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -83,12 +56,33 @@ /** */ public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + // isEmpty + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.personid.eq(1L).and(cand.projects.isEmpty())); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1 && projects.isEmpty()", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/OrderingSpecification.java (working copy) @@ -22,6 +22,7 @@ import java.util.List; import java.util.ListIterator; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Query; import javax.jdo.Transaction; @@ -29,6 +30,7 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.DentalInsurance; +import org.apache.jdo.tck.pc.company.QDentalInsurance; import org.apache.jdo.tck.pc.fieldtypes.AllTypes; import org.apache.jdo.tck.pc.mylib.PCPoint; import org.apache.jdo.tck.query.QueryElementHolder; @@ -60,55 +62,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.6-1 (OrderingSpecification) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // nulls first - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ DentalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.lifetimeOrthoBenefit ascending nulls first", - /*FROM*/ null, - /*TO*/ null), - // nulls last - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ DentalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.lifetimeOrthoBenefit ascending nulls last", - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // nulls first - getTransientCompanyModelInstancesAsList(new String[]{ - "dentalIns99", "dentalIns1", "dentalIns2", "dentalIns3", "dentalIns4", "dentalIns5"}), - // nulls last - getTransientCompanyModelInstancesAsList(new String[]{ - "dentalIns1", "dentalIns2", "dentalIns3", "dentalIns4", "dentalIns5", "dentalIns99"}) - }; /** * The main is called when the class @@ -120,14 +73,70 @@ } /** */ - public void testPositiveCompanyQueries() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], expectedResult[i]); - } + public void testPositiveCompanyQueries0() { + // nulls first + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "dentalIns99", "dentalIns1", "dentalIns2", "dentalIns3", "dentalIns4", "dentalIns5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(DentalInsurance.class); + QDentalInsurance cand = QDentalInsurance.candidate(); + query.orderBy(cand.lifetimeOrthoBenefit.asc().nullsFirst()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.lifetimeOrthoBenefit ascending nulls first", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ + public void testPositiveCompanyQueries1() { + // nulls last + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "dentalIns1", "dentalIns2", "dentalIns3", "dentalIns4", "dentalIns5", "dentalIns99"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(DentalInsurance.class); + QDentalInsurance cand = QDentalInsurance.candidate(); + query.orderBy(cand.lifetimeOrthoBenefit.asc().nullsLast()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.lifetimeOrthoBenefit ascending nulls last", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ public void testPositive() { PersistenceManager pm = getPM(); Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/RangeAsString.java (working copy) @@ -20,10 +20,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Range as String. *
@@ -39,83 +42,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.8-3 (RangeAsString) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "personid ASCENDING", - /*FROM*/ "0", - /*TO*/ "5"), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "personid ASCENDING", - /*FROM*/ "0", - /*TO*/ "4"), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "personid ASCENDING", - /*FROM*/ "1", - /*TO*/ "5"), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "personid ASCENDING", - /*FROM*/ "1", - /*TO*/ "4") - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp2", "emp3", "emp4"}) - }; /** * The main is called when the class @@ -125,15 +51,126 @@ public static void main(String[] args) { BatchTestRunner.run(RangeAsString.class); } - + /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.orderBy(cand.personid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "personid ASCENDING", + /*FROM*/ "0", + /*TO*/ "5", + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + + } /** */ + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.orderBy(cand.personid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "personid ASCENDING", + /*FROM*/ "0", + /*TO*/ "4", + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + + } /** */ + public void testPositive2() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.orderBy(cand.personid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "personid ASCENDING", + /*FROM*/ "1", + /*TO*/ "5", + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + + } /** */ + public void testPositive3() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp2", "emp3", "emp4"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.orderBy(cand.personid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "personid ASCENDING", + /*FROM*/ "1", + /*TO*/ "4", + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/SeparateNamespaceForTypeNames.java (working copy) @@ -21,10 +21,19 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; +import java.util.HashMap; +import java.util.Map; + /** *Title: Namespace of Type Names Separate From Fields, Variables, Parameters *
@@ -44,61 +53,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.4-1 (SeparateNamespaceForTypeNames) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // query having a parameter with the same name as a type - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "department == Department", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Department Department", - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Department", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // query having a parameter with the same name as a type - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(Employee) && Employee.firstname == \"emp1First\"", - /*VARIABLES*/ "Employee Employee", - /*PARAMETERS*/ null, - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Employee", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // query having a parameter with the same name as a type - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}), - // query having a parameter with the same name as a type - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) - }; - - /** Parameters of valid queries. */ - private Object[][] parameters = { - // query having a parameter with the same name as a type - {getPersistentCompanyModelInstance("dept1")}, - // query having a parameter with the same name as a type - null - }; - /** * The main is called when the class * is directly executed from the command line. @@ -108,15 +62,74 @@ BatchTestRunner.run(SeparateNamespaceForTypeNames.class); } - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + /** + * + */ + public void testParameterName() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + Expression empParam = query.parameter("Department", Department.class); + query.filter(cand.department.eq(empParam)); + + Map paramValues = new HashMap<>(); + paramValues.put("Department", getPersistentCompanyModelInstance("dept1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "department == Department", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Department Department", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Department", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + /** + * + */ + public void testVaiableName() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee variable = QEmployee.variable("Employee"); + query.filter(cand.employees.contains(variable).and(variable.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(Employee) && Employee.firstname == \"emp1First\"", + /*VARIABLES*/ "Employee Employee", + /*PARAMETERS*/ null, + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Employee", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/keywords/SingleString.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/keywords/SingleString.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/keywords/SingleString.java (working copy) @@ -19,6 +19,8 @@ import java.math.BigDecimal; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; @@ -44,45 +46,7 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.13-1 (SingleString) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ Boolean.FALSE, - /*RESULT*/ "firstname AS firstName, lastname AS lastName", - /*INTO*/ FullName.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ Boolean.TRUE, - /*WHERE*/ "salary > 1000 & projects.contains(p) & " + - "p.budget > limit", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ "BigDecimal limit", - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Project; " + - "import java.math.BigDecimal", - /*GROUP BY*/ "firstname, lastname HAVING lastname.startsWith('emp')", - /*ORDER BY*/ "lastname ASCENDING", - /*FROM*/ 0, - /*TO*/ 3) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - Arrays.asList(new Object[]{ - new FullName("emp1First", "emp1Last"), - new FullName("emp2First", "emp2Last"), - new FullName("emp5First", "emp5Last")}) - }; - /** Parameters of valid queries. */ - private Object[][] parameters = { - {new BigDecimal("2000")} - }; - /** * The main is called when the class * is directly executed from the command line. @@ -94,12 +58,33 @@ /** */ public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + Object expected = Arrays.asList(new FullName("emp1First", "emp1Last"), + new FullName("emp2First", "emp2Last"), + new FullName("emp5First", "emp5Last")); + + Map paramValues = new HashMap<>(); + paramValues.put("limit", new BigDecimal("2000")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.FALSE, + /*RESULT*/ "firstname AS firstName, lastname AS lastName", + /*INTO*/ FullName.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ Boolean.TRUE, + /*WHERE*/ "salary > 1000 & projects.contains(p) & p.budget > limit", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ "BigDecimal limit", + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.Project; " + + "import java.math.BigDecimal", + /*GROUP BY*/ "firstname, lastname HAVING lastname.startsWith('emp')", + /*ORDER BY*/ "lastname ASCENDING", + /*FROM*/ 0, + /*TO*/ 3, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/StartsWithAndEndsWith.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/StartsWithAndEndsWith.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/StartsWithAndEndsWith.java (working copy) @@ -20,10 +20,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: StartsWith and EndsWith Query Operators *
@@ -45,53 +48,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.2-33 (StartsWithAndEndsWith) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // startsWith - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname.startsWith(\"emp1\")", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // endsWith - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname.endsWith(\"1First\")", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // startsWith - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // endsWith - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -102,14 +58,66 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + // startsWith + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.firstname.startsWith("emp1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname.startsWith(\"emp1\")", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + /** */ + public void testPositive1() { + // endsWith + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.firstname.endsWith("1First")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname.endsWith(\"1First\")", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedCollectionMethods.java (working copy) @@ -17,18 +17,21 @@ package org.apache.jdo.tck.query.jdoql.methods; -import javax.jdo.PersistenceManager; -import javax.jdo.Query; -import javax.jdo.Transaction; - import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; +import java.util.HashMap; +import java.util.Map; + /** *Title:Supported collection methods *
@@ -50,17 +53,30 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-45 (SupportedCollectionMethods) failed: "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SupportedCollectionMethods.class); + } - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { + /** */ + public void testContains() { // contains(VARIABLE) - new QueryElementHolder( + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee eVariable = QEmployee.variable("e"); + query.filter(cand.employees.contains(eVariable).and(eVariable.personid.eq(1L))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Department.class, /*EXCLUDE*/ null, /*WHERE*/ "employees.contains(e) && e.personid == 1", @@ -70,12 +86,32 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); + // contains(PARAMETER) - new QueryElementHolder( + + expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + getPM().currentTransaction().begin(); + Map paramValues = new HashMap<>(); + paramValues.put("e", getPersistentCompanyModelInstance("emp1")); + getPM().currentTransaction().commit(); + + query = getPM().newJDOQLTypedQuery(Department.class); + cand = QDepartment.candidate(); + Expression paramExpression = query.parameter("e", Employee.class); + query.filter(cand.employees.contains(paramExpression)); + + holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Department.class, /*EXCLUDE*/ null, /*WHERE*/ "employees.contains(e)", @@ -85,12 +121,29 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); + } + + /** */ + public void testIsEmpty() { + // !isEmpty - new QueryElementHolder( + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"dept1", "dept2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.employees.isEmpty().not()); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Department.class, /*EXCLUDE*/ null, /*WHERE*/ "!employees.isEmpty()", @@ -100,12 +153,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + // DataNucleus: exception UnsupportedOperationException: Dont currently support operator NOT in JDOQL conversion + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); + // isEmpty - new QueryElementHolder( + expectedResult = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query2 = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee empCand = QEmployee.candidate(); + query2.filter(empCand.team.isEmpty()); + + holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Employee.class, /*EXCLUDE*/ null, /*WHERE*/ "team.isEmpty()", @@ -115,12 +183,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), + /*TO*/ null, + /*JDOQLTyped*/ query2, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); + } + + /** */ + public void testSize() { // size - new QueryElementHolder( + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.employees.size().eq(3)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Department.class, /*EXCLUDE*/ null, /*WHERE*/ "employees.size() == 3", @@ -130,72 +214,15 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null) - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // contains(VARIABLE) - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - // contains(PARAMETER) - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - // !isEmpty - getTransientCompanyModelInstancesAsList(new String[]{"dept1", "dept2"}), - // isEmpty - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp3", "emp4", "emp5"}), - // size - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedCollectionMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); } - - /** */ - public void testContains() { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - - index++; - getPM().currentTransaction().begin(); - Object[] parameters = new Object[]{getPersistentCompanyModelInstance("emp1")}; - getPM().currentTransaction().commit(); - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - } - /** */ - public void testIsEmpty() { - for (int index = 2; index < 4; index++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - } - - /** */ - public void testSize() { - int index = 4; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedDateMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedDateMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedDateMethods.java (working copy) @@ -20,10 +20,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Supported Date methods. *
@@ -44,16 +47,28 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-60 (SupportedDateMethods) failed: "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SupportedDateMethods.class); + } - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( + /** */ + public void testGetDate() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.birthdate.getDay().eq(10)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "birthdate.getDate() == 10", @@ -63,11 +78,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testGetMonth() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.birthdate.getMonth().eq(5)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "birthdate.getMonth() == 5", @@ -77,11 +108,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testGetYear() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.birthdate.getYear().eq(1970)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "birthdate.getYear() == 1970", @@ -91,45 +138,15 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedDateMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - - /** */ - public void testGetDate() { - int index = 0; - executeQuery(index); - } - - /** */ - public void testGetMonth() { - int index = 1; - executeQuery(index); - } - /** */ - public void testGetYear() { - int index = 2; - executeQuery(index); - } - /** * @see JDO_Test#localSetUp() */ @@ -138,11 +155,4 @@ loadAndPersistCompanyModel(getPM()); } - /** */ - private void executeQuery(int index) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } } Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedJDOHelperMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedJDOHelperMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedJDOHelperMethods.java (working copy) @@ -18,18 +18,25 @@ package org.apache.jdo.tck.query.jdoql.methods; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.jdo.JDOHelper; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Query; import javax.jdo.Transaction; +import javax.jdo.query.Expression; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; +import org.apache.jdo.tck.pc.mylib.QVersionedPCPoint; import org.apache.jdo.tck.pc.mylib.VersionedPCPoint; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; @@ -54,16 +61,29 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-49 (SupportedJDOHelperMethods) failed: "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SupportedJDOHelperMethods.class); + } - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( + /** */ + public void testGetObjectById1() { + Class oidClass = getPM().getObjectIdClass(Person.class); + List expectedResult = getExpectedResult(true, Person.class); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.result(false, cand.jdoObjectId()); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ "JDOHelper.getObjectId(this)", - /*INTO*/ null, + /*RESULT*/ "JDOHelper.getObjectId(this)", + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ null, @@ -73,11 +93,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, oidClass, expectedResult); + } + + /** */ + public void testGetObjectById2() { + List expectedResult = getExpectedResult(false, Person.class, "personid == 1"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + Expression oid = query.parameter("oid", Object.class); + query.filter(cand.jdoObjectId().eq(oid)); + + // The query above returns a collection of size 1. The collection element is a + // pc instance whose oid is the parameter of the query below. + Map paramValues = new HashMap<>(); + paramValues.put("oid", JDOHelper.getObjectId(expectedResult.get(0))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "JDOHelper.getObjectId(this) == oid", @@ -87,70 +129,15 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "JDOHelper.getVersion(this)", - /*INTO*/ null, - /*FROM*/ VersionedPCPoint.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ VersionedPCPoint.class, - /*EXCLUDE*/ null, - /*WHERE*/ "JDOHelper.getVersion(this) == ver", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Long ver", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedJDOHelperMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); } - - /** */ - public void testGetObjectById() { - // query 1 - int index = 0; - List expectedResult = getExpectedResult(true, Person.class); - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult); - // query 2 - index = 1; - expectedResult = getExpectedResult(false, Person.class, "personid == 1"); - // The query above returns a collection of size 1. - // The collection element is a pc instances - // whose oid is the parameter of the query below. - Object[] parameters = new Object[]{ - JDOHelper.getObjectId(expectedResult.get(0))}; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult); - } - /** Test for JDOHelper.getVersion() in queries. */ public void testGetVersion() { // create some sample data @@ -160,32 +147,72 @@ pm.currentTransaction().commit(); Object id = pm.getObjectId(pt1); - try - { - // query 1 - int index = 2; - List expectedResult = new ArrayList(); - expectedResult.add((long) 1); - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult); + try { + // query 1 + List expectedResult = Arrays.asList(Long.valueOf(1)); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(VersionedPCPoint.class); + QVersionedPCPoint cand = QVersionedPCPoint.candidate(); + query.result(false, cand.jdoVersion()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "JDOHelper.getVersion(this)", + /*INTO*/ null, + /*FROM*/ VersionedPCPoint.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + //executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); + // query 2 - index = 3; expectedResult = getExpectedResult(false, VersionedPCPoint.class, "x == 1"); - Object[] parameters = new Object[]{new Long(1)}; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult); + + query = getPM().newJDOQLTypedQuery(VersionedPCPoint.class); + cand = QVersionedPCPoint.candidate(); + Expression ver = query.parameter("ver", Object.class); + query.filter(cand.jdoVersion().eq(ver)); + + Map paramValues = new HashMap<>(); + paramValues.put("ver", Long.valueOf(1)); + + holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ VersionedPCPoint.class, + /*EXCLUDE*/ null, + /*WHERE*/ "JDOHelper.getVersion(this) == ver", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Long ver", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expectedResult); + + } finally { + pm.currentTransaction().begin(); + pm.deletePersistent(pm.getObjectById(id)); + pm.currentTransaction().commit(); } - finally - { - pm.currentTransaction().begin(); - pm.deletePersistent(pm.getObjectById(id)); - pm.currentTransaction().commit(); - } } /** Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedListMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedListMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedListMethods.java (working copy) @@ -17,18 +17,22 @@ package org.apache.jdo.tck.query.jdoql.methods; -import javax.jdo.PersistenceManager; -import javax.jdo.Query; -import javax.jdo.Transaction; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; +import javax.jdo.query.NumericExpression; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.MeetingRoom; +import org.apache.jdo.tck.pc.company.QDepartment; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import java.util.HashMap; +import java.util.Map; + /** *Title:Supported list methods *
@@ -48,14 +52,34 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-58 (SupportedListMethods) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. */ - private static final QueryElementHolder[] VALID_QUERIES = { + public static void main(String[] args) { + BatchTestRunner.run(SupportedListMethods.class); + } + + /** */ + public void testGetInFilter() { // get(PARAMETER) in filter - new QueryElementHolder( + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + Expression roomParam = query.parameter("room1", MeetingRoom.class); + NumericExpression posParam = query.numericParameter("pos"); + query.filter(cand.meetingRooms.get(posParam).eq(roomParam)); + + getPM().currentTransaction().begin(); + Map paramValues = new HashMap<>(); + paramValues.put("pos", Integer.valueOf(1)); + paramValues.put("room1", getPersistentCompanyModelInstance("room2")); + getPM().currentTransaction().commit(); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ null, /*INTO*/ null, @@ -68,9 +92,26 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testGetInResult() { // get(LITERAL) in result - new QueryElementHolder( + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"room2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.result(false, cand.meetingRooms.get(1)); + query.filter(cand.deptid.eq(1L)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ "meetingRooms.get(1)", /*INTO*/ null, @@ -83,49 +124,15 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null) - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // get(PARAMETER) in filter - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - // get(LITERAL) in result - getTransientCompanyModelInstancesAsList(new String[]{"room2"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedListMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, MeetingRoom.class, expected); } - /** */ - public void testGetInFilter() { - int index = 0; - getPM().currentTransaction().begin(); - Object[] parameters = new Object[]{1, getPersistentCompanyModelInstance("room2")}; - getPM().currentTransaction().commit(); - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - } - - /** */ - public void testGetInResult() { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMapMethods.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Supported Map methods. *
@@ -48,17 +51,28 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-46 (SupportedMapMethods) failed: "; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SupportedMapMethods.class); + } - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // get - new QueryElementHolder( + /** */ + public void testGet() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.phoneNumbers.get("home").eq("1111")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "phoneNumbers.get('home') == '1111'", @@ -68,12 +82,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - // containsKey - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testContainsKey() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.phoneNumbers.containsKey("home")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "phoneNumbers.containsKey('home')", @@ -83,12 +113,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - // containsValue - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testContainsValue() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.phoneNumbers.containsValue("1111")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "phoneNumbers.containsValue('1111')", @@ -98,12 +143,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - // isEmpty - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testIsEmpty() { + Object expected = new ArrayList(); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.phoneNumbers.isEmpty()); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "phoneNumbers.isEmpty()", @@ -113,12 +173,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - // size - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSize() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.phoneNumbers.size().eq(2)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "phoneNumbers.size() == 2", @@ -128,81 +204,15 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null) - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // get - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // containsKey - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - // containsValue - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // isEmpty - new ArrayList(), - // size - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedMapMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - - /** */ - public void testGet() { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - - /** */ - public void testContainsKey() { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - /** */ - public void testContainsValue() { - int index = 2; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - - /** */ - public void testIsEmpty() { - int index = 3; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - - /** */ - public void testSize() { - int index = 4; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMathMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMathMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedMathMethods.java (working copy) @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Query; import javax.jdo.Transaction; @@ -28,6 +29,7 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.mylib.MylibReader; import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.pc.mylib.QPrimitiveTypes; import org.apache.jdo.tck.pc.query.MathSample; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; @@ -58,17 +60,38 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-48 (SupportedMathMethods) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - * These queries are used to test Math.abs. + + /** */ + private Object oidOfMath1; + + /** */ + private Object oidOfMath2; + + /** */ + private Object oidOfMath3; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. */ - private static final QueryElementHolder[] VALID_QUERIES_ABS = { - new QueryElementHolder( + public static void main(String[] args) { + BatchTestRunner.run(SupportedMathMethods.class); + } + + /** */ + public void testAbs0() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.intNotNull.abs().eq(4)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(intNotNull) == 4", @@ -78,11 +101,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs1() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.intNull.abs().eq(4)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(intNull) == 4", @@ -92,11 +132,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs2() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.longNotNull.abs().eq(4L)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(longNotNull) == 4", @@ -106,11 +163,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs3() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.longNull.abs().eq(4L)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(longNull) == 4", @@ -120,15 +194,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs4() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.floatNotNull.abs().lt(4.1f). + and(cand.floatNotNull.abs().gt(3.9f))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(floatNotNull) < 4.1 &&" + - "Math.abs(floatNotNull) > 3.9", + "Math.abs(floatNotNull) > 3.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -135,15 +227,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs5() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.floatNull.abs().lt(4.1f). + and(cand.floatNull.abs().gt(3.9f))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(floatNull) < 4.1 &&" + - "Math.abs(floatNull) > 3.9", + "Math.abs(floatNull) > 3.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -150,15 +260,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs6() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.doubleNotNull.abs().lt(4.1). + and(cand.doubleNotNull.abs().gt(3.9))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(doubleNotNull) < 4.1 &&" + - "Math.abs(doubleNotNull) > 3.9", + "Math.abs(doubleNotNull) > 3.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -165,15 +293,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testAbs7() { + Object expected = getTransientMylibInstancesAsList(new String[]{ + "primitiveTypesPositive", "primitiveTypesNegative"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.doubleNull.abs().lt(4.1). + and(cand.doubleNull.abs().gt(3.9))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "Math.abs(doubleNull) < 4.1 &&" + - "Math.abs(doubleNull) > 3.9", + "Math.abs(doubleNull) > 3.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -180,24 +326,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null) - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - * These queries are used to test Math.sqrt. - */ - private static final QueryElementHolder[] VALID_QUERIES_SQRT = { - new QueryElementHolder( + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSqrt0() { + Object expected = getTransientMylibInstancesAsList(new String[]{"primitiveTypesPositive"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.doubleNotNull.gt(0d).and(cand.doubleNotNull.sqrt().lt(2.1). + and(cand.doubleNotNull.sqrt().gt(1.9)))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "doubleNotNull > 0 && " + - "Math.sqrt(doubleNotNull) < 2.1 && " + - "Math.sqrt(doubleNotNull) > 1.9", + "Math.sqrt(doubleNotNull) < 2.1 && " + + "Math.sqrt(doubleNotNull) > 1.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -204,16 +359,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSqrt1() { + Object expected = getTransientMylibInstancesAsList(new String[]{"primitiveTypesPositive"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.doubleNull.gt(0d).and(cand.doubleNull.sqrt().lt(2.1). + and(cand.doubleNull.sqrt().gt(1.9)))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "doubleNull > 0 && " + - "Math.sqrt(doubleNull) < 2.1 && " + - "Math.sqrt(doubleNull) > 1.9", + "Math.sqrt(doubleNull) < 2.1 && " + + "Math.sqrt(doubleNull) > 1.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -220,16 +392,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSqrt2() { + Object expected = getTransientMylibInstancesAsList(new String[]{"primitiveTypesPositive"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.intNotNull.gt(0).and(cand.intNotNull.sqrt().lt(2.1). + and(cand.intNotNull.sqrt().gt(1.9)))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "intNotNull > 0 && " + - "Math.sqrt(intNotNull) < 2.1 && " + - "Math.sqrt(intNotNull) > 1.9", + "Math.sqrt(intNotNull) < 2.1 && " + + "Math.sqrt(intNotNull) > 1.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -236,16 +425,33 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSqrt3() { + Object expected = getTransientMylibInstancesAsList(new String[]{"primitiveTypesPositive"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(PrimitiveTypes.class); + QPrimitiveTypes cand = QPrimitiveTypes.candidate(); + query.filter(cand.intNull.gt(0).and(cand.intNull.sqrt().lt(2.1). + and(cand.intNull.sqrt().gt(1.9)))); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ PrimitiveTypes.class, /*EXCLUDE*/ null, /*WHERE*/ "intNull > 0 && " + - "Math.sqrt(intNull) < 2.1 && " + - "Math.sqrt(intNull) > 1.9", + "Math.sqrt(intNull) < 2.1 && " + + "Math.sqrt(intNull) > 1.9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -252,89 +458,15 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** */ - private Object oidOfMath1; - - /** */ - private Object oidOfMath2; - - /** */ - private Object oidOfMath3; - - /** - * The expected results of valid queries testing Math.abs. - */ - private Object[] expectedResultABS = { - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive", "primitiveTypesNegative"}) - }; - - /** The expected results of valid queries testing Math.sqrt. */ - private Object[] expectedResultSQRT = { - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}), - getTransientMylibInstancesAsList(new String[]{ - "primitiveTypesPositive"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedMathMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - /** */ - public void testAbs() { - for (int i = 0; i < VALID_QUERIES_ABS.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES_ABS[i], - expectedResultABS[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES_ABS[i], - expectedResultABS[i]); - } - } - - /** */ - public void testSqrt() { - for (int i = 0; i < VALID_QUERIES_SQRT.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES_SQRT[i], - expectedResultSQRT[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES_SQRT[i], - expectedResultSQRT[i]); - } - } - /** * Tests for Math.sin() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedOptionalMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedOptionalMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedOptionalMethods.java (working copy) @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import javax.jdo.PersistenceManager; @@ -156,7 +158,9 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null); + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ null); ArrayList expectedResults = new ArrayList<>(); Transaction tx = pm.currentTransaction(); @@ -181,18 +185,23 @@ public void testParameterOptional() { OptionalSample osReferencedPC1 = getOptionalSampleById(oidReferencedPC1); String paramDecl = "java.util.Optional op"; + Map paramValues = new HashMap<>(); + + paramValues.put("op", Optional.of(osReferencedPC1)); checkQuery("this.optionalPC == op", paramDecl, - new Object[]{Optional.of(osReferencedPC1)}, - new Object[]{oidPC}); - checkQuery("this.optionalDate == op", paramDecl, - new Object[]{Optional.of(DATE)}, - new Object[]{oidPC}); - checkQuery("this.optionalInteger == op", paramDecl, - new Object[]{Optional.of(INTEGER)}, - new Object[]{oidPC}); - checkQuery("this.optionalString == op", paramDecl, - new Object[]{Optional.of(STRING)}, - new Object[]{oidPC}); + paramValues, new Object[]{oidPC}); + + paramValues.put("op", Optional.of(DATE)); + checkQuery("this.optionalDate == op", paramDecl, + paramValues, new Object[]{oidPC}); + + paramValues.put("op", Optional.of(INTEGER)); + checkQuery("this.optionalInteger == op", paramDecl, + paramValues, new Object[]{oidPC}); + + paramValues.put("op", Optional.of(STRING)); + checkQuery("this.optionalString == op", paramDecl, + paramValues, new Object[]{oidPC}); } /** @@ -201,18 +210,27 @@ */ public void testParameterOptionalAutoDeref() { OptionalSample osReferencedPC1 = getOptionalSampleById(oidReferencedPC1); - checkQuery("this.optionalPC == op", + Map paramValues = new HashMap<>(); + + paramValues.put("op", osReferencedPC1); + checkQuery("this.optionalPC == op", OptionalSample.class.getName() + " op", - new Object[]{osReferencedPC1}, new Object[]{oidPC}); - checkQuery("this.optionalDate == op", + paramValues, new Object[]{oidPC}); + + paramValues.put("op", DATE); + checkQuery("this.optionalDate == op", "java.util.Date op", - new Object[]{DATE}, new Object[]{oidPC}); - checkQuery("this.optionalInteger == op", - "Integer op", - new Object[]{INTEGER}, new Object[]{oidPC}); - checkQuery("this.optionalString == op", + paramValues, new Object[]{oidPC}); + + paramValues.put("op", INTEGER); + checkQuery("this.optionalInteger == op", + "Integer op", + paramValues, new Object[]{oidPC}); + + paramValues.put("op", STRING); + checkQuery("this.optionalString == op", "String op", - new Object[]{STRING}, new Object[]{oidPC}); + paramValues, new Object[]{oidPC}); } private OptionalSample getOptionalSampleById(Object id) { @@ -233,14 +251,15 @@ */ public void testParameterOptionalWithEmptyFields() { String paramDecl = "java.util.Optional op"; - Object[] params = new Object[]{Optional.empty()}; - checkQuery("this.optionalPC == op", paramDecl, params, + Map paramValues = new HashMap<>(); + paramValues.put("op", Optional.empty()); + checkQuery("this.optionalPC == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC2}); - checkQuery("this.optionalDate == op", paramDecl, params, + checkQuery("this.optionalDate == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); - checkQuery("this.optionalInteger == op", paramDecl, params, + checkQuery("this.optionalInteger == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); - checkQuery("this.optionalString == op", paramDecl, params, + checkQuery("this.optionalString == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); } @@ -250,14 +269,15 @@ */ public void testParameterOptionalWithNull() { String paramDecl = "java.util.Optional op"; - Object[] params = new Object[]{null}; - checkQuery("this.optionalPC == op", paramDecl, params, + Map paramValues = new HashMap<>(); + paramValues.put("op", null); + checkQuery("this.optionalPC == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC2}); - checkQuery("this.optionalDate == op", paramDecl, params, + checkQuery("this.optionalDate == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); - checkQuery("this.optionalInteger == op", paramDecl, params, + checkQuery("this.optionalInteger == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); - checkQuery("this.optionalString == op", paramDecl, params, + checkQuery("this.optionalString == op", paramDecl, paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); } @@ -266,14 +286,15 @@ * (Object)null. */ public void testParameterOptionalNull() { - Object[] params = new Object[]{null}; - checkQuery("this.optionalPC == op", OptionalSample.class.getName() + " op", params, + Map paramValues = new HashMap<>(); + paramValues.put("op", null); + checkQuery("this.optionalPC == op", OptionalSample.class.getName() + " op", paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC2}); - checkQuery("this.optionalDate == op", "java.util.Date op", params, + checkQuery("this.optionalDate == op", "java.util.Date op", paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); - checkQuery("this.optionalInteger == op", "java.lang.Integer op", params, + checkQuery("this.optionalInteger == op", "java.lang.Integer op", paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); - checkQuery("this.optionalString == op", "java.lang.String op", params, + checkQuery("this.optionalString == op", "java.lang.String op", paramValues, new Object[]{oidEmpty, oidNull, oidReferencedPC1, oidReferencedPC2}); } @@ -352,7 +373,7 @@ false, null, expectedResults, true); } - private void checkQuery(String filter, String paramDecl, Object[] params, Object[] result) { + private void checkQuery(String filter, String paramDecl, Map paramValues, Object[] result) { QueryElementHolder qeh = new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ null, @@ -366,7 +387,9 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null); + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); ArrayList expectedResults = new ArrayList<>(); PersistenceManager pm = getPM(); @@ -387,8 +410,8 @@ } } - executeAPIQuery(ASSERTION_FAILED, qeh, params, expectedResults); - executeSingleStringQuery(ASSERTION_FAILED, qeh, params, expectedResults); + executeAPIQuery(ASSERTION_FAILED, qeh, expectedResults); + executeSingleStringQuery(ASSERTION_FAILED, qeh, expectedResults); } Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedStringMethods.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedStringMethods.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/methods/SupportedStringMethods.java (working copy) @@ -21,10 +21,14 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Supported String methods. *
@@ -56,15 +60,27 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.2-47 (SupportedStringMethods) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( + public static void main(String[] args) { + BatchTestRunner.run(SupportedStringMethods.class); + } + + /** */ + public void testToLowerCase() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.toLowerCase().eq("emp1first")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.toLowerCase() == 'emp1first'", @@ -74,11 +90,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testToUpperCase() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.toUpperCase().eq("EMP1FIRST")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.toUpperCase() == 'EMP1FIRST'", @@ -88,11 +120,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testIndexOfString() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.name.indexOf("e").eq(1)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Department.class, /*EXCLUDE*/ null, /*WHERE*/ "name.indexOf('e') == 1", @@ -102,11 +150,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testIndexOfStringInt() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"dept1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.filter(cand.name.indexOf("e", 2).eq(3)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Department.class, /*EXCLUDE*/ null, /*WHERE*/ "name.indexOf('e', 2) == 3", @@ -116,11 +180,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testMatches1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.matches(".*First")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.matches('.*First')", @@ -130,11 +211,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testMatches2() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.matches("emp.First")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.matches('emp.First')", @@ -144,11 +242,26 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** */ + public void testMatches3() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.matches("(?i)EMP1FIRST")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.matches('(?i)EMP1FIRST')", @@ -158,11 +271,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSubstringInt() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.substring(4).eq("First")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.substring(4) == 'First'", @@ -172,11 +302,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testSubstringIntInt() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.substring(4,9).eq("First")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.substring(4,9) == 'First'", @@ -186,11 +333,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testStartsWith() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.startsWith("emp")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.startsWith('emp')", @@ -200,11 +364,28 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testEndsWith() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.endsWith("First")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.endsWith('First')", @@ -214,14 +395,31 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testStartsWithIndexed() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.startsWith("mp", 1)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, - /*WHERE*/ "firstname.charAt(3) == '1'", + /*WHERE*/ "firstname.startsWith('mp', 1)", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -228,14 +426,31 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testLength() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.length().eq(9)); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, - /*WHERE*/ "firstname.startsWith('mp', 1)", + /*WHERE*/ "firstname.length() == 9", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -242,14 +457,30 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testCharAt() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.charAt(3).eq('1')); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, - /*WHERE*/ "firstname.length() == 9", + /*WHERE*/ "firstname.charAt(3) == '1'", /*VARIABLES*/ null, /*PARAMETERS*/ null, /*IMPORTS*/ null, @@ -256,11 +487,27 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testTrim() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.trim().eq("emp1First")); + + QueryElementHolder holder = new QueryElementHolder( /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, + /*RESULT*/ null, + /*INTO*/ null, /*FROM*/ Person.class, /*EXCLUDE*/ null, /*WHERE*/ "firstname.trim() == 'emp1First'", @@ -270,129 +517,16 @@ /*GROUP BY*/ null, /*ORDER BY*/ null, /*FROM*/ null, - /*TO*/ null) - }; + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - getTransientCompanyModelInstancesAsList(new String[]{"dept1"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1"}) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(SupportedStringMethods.class); + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: NullPointerException at org.datanucleus.store.rdbms.sql.method.StringTrim2Method.getExpression(StringTrim2Method.java:48) + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } - - /** */ - public void testToLowerCase() { - int index = 0; - executeQuery(index); - } - - /** */ - public void testToUpperCase() { - int index = 1; - executeQuery(index); - } - /** */ - public void testIndexOfString() { - int index = 2; - executeQuery(index); - } - - /** */ - public void testIndexOfStringInt() { - int index = 3; - executeQuery(index); - } - - /** */ - public void testMatches() { - int index = 4; - executeQuery(index); - executeQuery(++index); - executeQuery(++index); - } - - /** */ - public void testSubstringInt() { - int index = 7; - executeQuery(index); - } - - /** */ - public void testSubstringIntInt() { - int index = 8; - executeQuery(index); - } - - /** */ - public void testStartsWith() { - int index = 9; - executeQuery(index); - } - - /** */ - public void testEndsWith() { - int index = 10; - executeQuery(index); - } - - /** */ - public void testStartsWithIndexed() { - int index = 11; - executeQuery(index); - } - - /** */ - public void testLength() { - int index = 12; - executeQuery(index); - } - - /** */ - public void testCharAt() { - int index = 13; - executeQuery(index); - } - - /** */ - public void testTrim() { - int index = 14; - executeQuery(index); - } - /** * @see JDO_Test#localSetUp() */ @@ -400,12 +534,4 @@ addTearDownClass(CompanyModelReader.getTearDownClasses()); loadAndPersistCompanyModel(getPM()); } - - /** */ - private void executeQuery(int index) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } } Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/EqualityAndComparisonsBetweenDateFieldsAndParameters.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/EqualityAndComparisonsBetweenDateFieldsAndParameters.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/EqualityAndComparisonsBetweenDateFieldsAndParameters.java (working copy) @@ -20,15 +20,20 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; -import java.util.TimeZone; +import java.util.HashMap; +import java.util.Map; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.DateTimeExpression; + /** *Title: Equality and Comparisons Between Date Fields and Parameters *
@@ -47,72 +52,7 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-4 (EqualityAndComparisonsBetweenDateFieldsAndParameters) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // date field == date parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "hiredate == param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "java.util.Date param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // date field >= date parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "hiredate >= param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "java.util.Date param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // date field >= date parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "param < birthdate", - /*VARIABLES*/ null, - /*PARAMETERS*/ "java.util.Date param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - }; - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // date field == date parameter - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // date field >= date parameter - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4"}), - // date field >= date parameter - getTransientCompanyModelInstancesAsList(new String[]{}) - }; - /** */ private static final Date FIRST_OF_JAN_1999; static { @@ -141,16 +81,119 @@ public static void main(String[] args) { BatchTestRunner.run(EqualityAndComparisonsBetweenDateFieldsAndParameters.class); } - - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + + /** + * + */ + public void testFieldEqualsParameter() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + DateTimeExpression param = query.datetimeParameter("param"); + query.filter(cand.hiredate.eq(param)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", FIRST_OF_JAN_1999); + + // date field == date parameter + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "hiredate == param", + /*VARIABLES*/ null, + /*PARAMETERS*/ "java.util.Date param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + /** + * + */ + public void testFieldGEParameter() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + DateTimeExpression param = query.datetimeParameter("param"); + query.filter(cand.hiredate.gteq(param)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", FIRST_OF_JAN_1999); + + // date field >= date parameter + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "hiredate >= param", + /*VARIABLES*/ null, + /*PARAMETERS*/ "java.util.Date param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** + * + */ + public void testParameterLTField() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + DateTimeExpression param = query.datetimeParameter("param"); + query.filter(param.lt(cand.birthdate)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", FIRST_OF_JAN_1999); + + // Import Department twice + QueryElementHolder holder = // date parameter < date field + new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "param < birthdate", + /*VARIABLES*/ null, + /*PARAMETERS*/ "java.util.Date param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/EqualityAndComparisonsBetweenStringFieldsAndParameters.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/EqualityAndComparisonsBetweenStringFieldsAndParameters.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/EqualityAndComparisonsBetweenStringFieldsAndParameters.java (working copy) @@ -20,10 +20,16 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.StringExpression; +import java.util.HashMap; +import java.util.Map; + /** *Title: Equality and Comparisons Between String Fields and Parameters *
@@ -43,83 +49,7 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-5 (EqualityAndComparisonsBetweenStringFieldsAndParameters) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // string field == string parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname == param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "java.lang.String param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // string field >= string parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname >= param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "java.lang.String param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // string parameter < string field - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "param < firstname", - /*VARIABLES*/ null, - /*PARAMETERS*/ "java.lang.String param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // string field == string parameter - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // string field >= string parameter - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - // string parameter < string field - getTransientCompanyModelInstancesAsList(new String[]{ - "emp3", "emp4", "emp5"}), - }; - - /** Parameters of valid queries. */ - private Object[][] parameters = { - // string field == string parameter - {"emp1First"}, - // string field >= string parameter - {"emp1First"}, - // string parameter < string field - {"emp2First"} - }; - + /** * The main is called when the class * is directly executed from the command line. @@ -129,15 +59,106 @@ BatchTestRunner.run(EqualityAndComparisonsBetweenStringFieldsAndParameters.class); } - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + public void testStringFieldEqualsStringParameter() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + StringExpression paramVariable = query.stringParameter("param"); + query.filter(cand.firstname.eq(paramVariable)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", "emp1First"); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname == param", + /*VARIABLES*/ null, + /*PARAMETERS*/ "java.lang.String param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + public void testStringFieldGEStringParameter() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + StringExpression paramVariable = query.stringParameter("param"); + query.filter(cand.firstname.gteq(paramVariable)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", "emp1First"); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname >= param", + /*VARIABLES*/ null, + /*PARAMETERS*/ "java.lang.String param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + public void testStringParameterLTStringField() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + StringExpression paramVariable = query.stringParameter("param"); + query.filter(paramVariable.lt(cand.firstname)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", "emp2First"); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "param < firstname", + /*VARIABLES*/ null, + /*PARAMETERS*/ "java.lang.String param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/Instanceof.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/Instanceof.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/Instanceof.java (working copy) @@ -20,10 +20,14 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.PartTimeEmployee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Instanceof operator. *
@@ -39,50 +43,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-41 (Instanceof) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "mentor instanceof " + - "org.apache.jdo.tck.pc.company.PartTimeEmployee", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "mentor instanceof PartTimeEmployee", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.PartTimeEmployee", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3"}) - }; /** * The main is called when the class @@ -92,17 +52,70 @@ public static void main(String[] args) { BatchTestRunner.run(Instanceof.class); } - - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: instanceOf not yet supported + query.filter(cand.mentor.instanceOf(PartTimeEmployee.class)); + + // Import Department twice + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "mentor instanceof org.apache.jdo.tck.pc.company.PartTimeEmployee", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: instanceOf not yet supported + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + public void testPositive2() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: instanceOf not yet supported + query.filter(cand.mentor.instanceOf(PartTimeEmployee.class)); + + // Import Department twice + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "mentor instanceof PartTimeEmployee", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ "import org.apache.jdo.tck.pc.company.PartTimeEmployee", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: instanceOf not yet supported + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/Modulo.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/Modulo.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/Modulo.java (working copy) @@ -19,6 +19,7 @@ import java.util.Collection; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Transaction; @@ -25,6 +26,7 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; @@ -45,34 +47,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.2-40 (Modulo) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid % 2 == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp4"}) - }; /** * The main is called when the class @@ -82,21 +56,40 @@ public static void main(String[] args) { BatchTestRunner.run(Modulo.class); } - - /** */ + public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } - - runTestUsingPrimitiveTypes(); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp4"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.mod(2).eq(0L)); + + // Import Department twice + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid % 2 == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + // DataNucleus: UnsupportedOperationException: Dont currently support operator % in JDOQL conversion + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ - private void runTestUsingPrimitiveTypes() { + public void testPostiveUsingPrimitiveTypes() { PersistenceManager pm = getPM(); Transaction tx = pm.currentTransaction(); tx.begin(); Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/StringConcatenation.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/StringConcatenation.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/operators/StringConcatenation.java (working copy) @@ -20,10 +20,16 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.StringExpression; +import java.util.HashMap; +import java.util.Map; + /** *Title: String Concatenation Query Operator *
@@ -43,61 +49,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.2-27 (StringConcatenation) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // string literal + string literal - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname == \"emp1\" + \"First\"", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // string field + string literal - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname + \"Ext\" == param", - /*VARIABLES*/ null, - /*PARAMETERS*/ "String param", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // string literal + string literal - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - // string field + string literal - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; - - /** Parameters of valid queries. */ - private Object[][] parameters = { - // string literal + string literal - null, - // string field + string literal - {"emp1FirstExt"} - }; - /** * The main is called when the class * is directly executed from the command line. @@ -106,16 +57,72 @@ public static void main(String[] args) { BatchTestRunner.run(StringConcatenation.class); } - - /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + + /** + * + */ + public void testStringLiteralPlusStringLiteral() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.firstname.eq("emp1" + "First")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname == \"emp1\" + \"First\"", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + + public void testStringFieldPlusStringLiteral() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + StringExpression paramExpr = query.stringParameter("param"); + query.filter(cand.firstname.add("Ext").eq(paramExpr)); + + Map paramValues = new HashMap<>(); + paramValues.put("param", "emp1FirstExt"); + + // Import Department twice + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname + \"Ext\" == param", + /*VARIABLES*/ null, + /*PARAMETERS*/ "String param", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/parameters/ImplicitParameters.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/parameters/ImplicitParameters.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/parameters/ImplicitParameters.java (working copy) @@ -18,7 +18,9 @@ package org.apache.jdo.tck.query.jdoql.parameters; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; @@ -37,8 +39,8 @@ *
*Assertion Description: * Parameters implicitly declared (in the result, filter, grouping, ordering, - * or range) are identified by prepending a ":" to the parameter - * everywhere it appears. All parameter types can be determined + * or range) are identified by prepending a ":" to the parameter + * everywhere it appears. All parameter types can be determined * by one of the following techniques: */ public class ImplicitParameters extends QueryTest { @@ -47,84 +49,7 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.3-3 (ImplicitParameters) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this, :param", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname == :param", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department.name", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ "department.name HAVING COUNT(this) >= :minValue", - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ ":zero", - /*TO*/ ":five") - }; - - private static String parameter = "parameterInResult"; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getExpectedResultOfFirstQuery( - getTransientCompanyModelInstancesAsList(new String[] { - "emp1", "emp2", "emp3", "emp4", "emp5"})), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - /* Note: "Development" is not a bean name! */ - Arrays.asList(new Object[]{"Development"}), - getTransientCompanyModelInstancesAsList(new String[] { - "emp1", "emp2", "emp3", "emp4", "emp5"}) - }; + private static final String PARAMETER = "parameterInResult"; /** * The main is called when the class @@ -137,27 +62,124 @@ /** */ public void testResult() { - int index = 0; - executeQuery(index, new Object[] {parameter}); + Object expected = getExpectedResultOfFirstQuery( + getTransientCompanyModelInstancesAsList(new String[] {"emp1", "emp2", "emp3", "emp4", "emp5"})); + + Map paramValues = new HashMap<>(); + paramValues.put("param", PARAMETER); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this, :param", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + //TBD executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ public void testFilter() { - int index = 1; - executeQuery(index, new Object[] {"emp1First"}); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + Map paramValues = new HashMap<>(); + paramValues.put("param", "emp1First"); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname == :param", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + //TBD executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ public void testGrouping() { - int index = 2; - executeQuery(index, new Object[] {new Long(3)}); + Object expected = /* Note: "Development" is not a bean name! */ + Arrays.asList("Development"); + + Map paramValues = new HashMap<>(); + paramValues.put("minValue", Long.valueOf(3)); + + // Import Department twice + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department.name", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ "department.name HAVING COUNT(this) >= :minValue", + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + //TBD executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ public void testRange() { - int index = 3; - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - new Object[] {new Long(0), new Long(5)}, expectedResult[index]); + Object expected = getTransientCompanyModelInstancesAsList(new String[] { + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + Map paramValues = new HashMap<>(); + paramValues.put("zero", Long.valueOf(0)); + paramValues.put("five", Long.valueOf(5)); + + // Import Department twice + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ ":zero", + /*TO*/ ":five", + /*JDOQLTyped*/ null, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + //TBD executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** @@ -167,19 +189,11 @@ addTearDownClass(CompanyModelReader.getTearDownClasses()); loadAndPersistCompanyModel(getPM()); } - - /** */ - private void executeQuery(int index, Object[] parameters) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - } private List getExpectedResultOfFirstQuery(List instances) { Object[] expectedResult = new Object[instances.size()]; for (int i = 0; i < expectedResult.length; i++) { - expectedResult[i] = new Object[] {instances.get(i), parameter}; + expectedResult[i] = new Object[] {instances.get(i), PARAMETER}; } return Arrays.asList(expectedResult); } Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/parameters/OrderOfParameters.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/parameters/OrderOfParameters.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/parameters/OrderOfParameters.java (working copy) @@ -24,6 +24,10 @@ import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.Query; +import javax.jdo.Transaction; +import java.util.List; + /** *Title: Order of Parameters. *
@@ -40,40 +44,7 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.13-3 (OrderOfParameters) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname == :param1 & lastname == :param2", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; - /** Parameters of valid queries. */ - private Object[][] parameters = { - {"emp1First", "emp1Last"} - }; - /** * The main is called when the class * is directly executed from the command line. @@ -84,14 +55,54 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); + public void testAPIQuery() { + // Do not use QueryElementHolder, because QueryElementHolder always uses a Map for parameter values + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = + "select from org.apache.jdo.tck.pc.company.Person where firstname == :param1 & lastname == :param2"; + query = pm.newQuery(Person.class, "firstname == :param1 & lastname == :param2"); + result = query.execute("emp1First", "emp1Last"); + List expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + checkQueryResultWithoutOrder(ASSERTION_FAILED, singleStringQuery, result, expected); + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } } } + + /** */ + public void testSingleStringAPIQuery() { + // Do not use QueryElementHolder, because QueryElementHolder always uses a Map for parameter values + Transaction tx = pm.currentTransaction(); + Query query = null; + Object result = null; + try { + tx.begin(); + String singleStringQuery = + "select from org.apache.jdo.tck.pc.company.Person where firstname == :param1 & lastname == :param2"; + query = pm.newQuery(singleStringQuery); + result = query.execute("emp1First", "emp1Last"); + List expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + checkQueryResultWithoutOrder(ASSERTION_FAILED, singleStringQuery, result, expected); + tx.commit(); + } finally { + if (query != null) { + query.close(result); + } + if (tx.isActive()) { + tx.rollback(); + } + } + } /** * @see JDO_Test#localSetUp() Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/UnconstrainedVariable.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/UnconstrainedVariable.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/UnconstrainedVariable.java (working copy) @@ -20,10 +20,16 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.NumericExpression; +import java.util.HashMap; +import java.util.Map; + /** *Title: Unconstrained Variables. *
@@ -41,41 +47,7 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.5-1 (UnconstrainedVariable) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.hireDate > e.hireDate & e.personid = id", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ "int id", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{ - "emp2", "emp3", "emp4"}) - }; - /** Parameters of valid queries. */ - private Object[][] parameters = { - {new Integer(1)}, - }; - /** * The main is called when the class * is directly executed from the command line. @@ -88,12 +60,37 @@ /** */ public void testPositive() { if (isUnconstrainedVariablesSupported()) { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - parameters[i], expectedResult[i]); - } + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", "emp3", "emp4"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee e = QEmployee.variable("e"); + NumericExpression param = query.numericParameter("id"); + query.filter(cand.hiredate.gt(e.hiredate).and(e.hiredate.eq(param))); + + Map paramValues = new HashMap<>(); + paramValues.put("id", Integer.valueOf(1)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.hiredate > e.hiredate & e.personid = id", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ "int id", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } } Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesAndFields.java (working copy) @@ -23,10 +23,14 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Variables and Fields. *
@@ -51,116 +55,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.5-4 (VariablesAndFields) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "team.contains(e) & " + - "e.firstname == 'emp1First'", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "team.contains(e) & " + - "e.firstname == 'emp1First'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "firstname == 'emp1First'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "team.contains(manager) & " + - "manager.firstname == 'emp1First'", - /*VARIABLES*/ "Employee manager", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "team.contains(manager) & " + - "manager.firstname == 'emp1First'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /* Note: the variable name is the same as the class - * name except for capitalization. This is legal. */ - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "team.contains(employee) & " + - "employee.firstname == 'emp1First'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp2"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp2"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp2"}), - new LinkedList(), - getTransientCompanyModelInstancesAsList(new String[]{"emp2"}) - }; /** * The main is called when the class @@ -170,17 +64,192 @@ public static void main(String[] args) { BatchTestRunner.run(VariablesAndFields.class); } - + /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.team.contains(e).and(e.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.contains(e) & e.firstname == 'emp1First'", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + /** */ + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.team.contains(e).and(e.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.contains(e) & e.firstname == 'emp1First'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive2() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.firstname.eq("emp1First")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "firstname == 'emp1First'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive3() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee manager = QEmployee.variable("manager"); + query.filter(cand.team.contains(manager).and(manager.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.contains(manager) & manager.firstname == 'emp1First'", + /*VARIABLES*/ "Employee manager", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** */ + public void testPositive4() { + Object expected = new LinkedList(); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee manager = QEmployee.variable("manager"); + query.filter(cand.team.contains(manager).and(manager.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.contains(manager) & manager.firstname == 'emp1First'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** */ + public void testPositive5() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee employee = QEmployee.variable("employee"); + query.filter(cand.team.contains(employee).and(employee.firstname.eq("emp1First"))); + + QueryElementHolder holder = new QueryElementHolder( + /* Note: the variable name is the same as the class + * name except for capitalization. This is legal. */ + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.contains(employee) & employee.firstname == 'emp1First'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/jdoql/variables/VariablesWithoutExtent.java (working copy) @@ -19,6 +19,7 @@ import java.util.LinkedList; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.PersistenceManager; import javax.jdo.Transaction; @@ -25,7 +26,9 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.pc.query.NoExtent; +import org.apache.jdo.tck.pc.query.QNoExtent; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; @@ -47,34 +50,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.5-2 (VariablesWithoutExtent) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "this.personid = noExtent.id", - /*VARIABLES*/ "NoExtent noExtent", - /*PARAMETERS*/ null, - /*IMPORTS*/ "import org.apache.jdo.tck.pc.query.NoExtent;", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - new LinkedList() - }; - /** * The main is called when the class * is directly executed from the command line. @@ -83,16 +58,38 @@ public static void main(String[] args) { BatchTestRunner.run(VariablesWithoutExtent.class); } - + /** */ public void testPositive() { if (isUnconstrainedVariablesSupported()) { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + + Object expected = new LinkedList(); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + QNoExtent noExtent = QNoExtent.variable("noExtent"); + query.filter(cand.personid.eq(noExtent.id)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "this.personid = noExtent.id", + /*VARIABLES*/ "NoExtent noExtent", + /*PARAMETERS*/ null, + /*IMPORTS*/ "import org.apache.jdo.tck.pc.query.NoExtent;", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } } Index: tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/AggregateResult.java (working copy) @@ -25,10 +25,16 @@ import org.apache.jdo.tck.pc.company.FullTimeEmployee; import org.apache.jdo.tck.pc.company.Person; import org.apache.jdo.tck.pc.company.Project; +import org.apache.jdo.tck.pc.company.QDentalInsurance; +import org.apache.jdo.tck.pc.company.QFullTimeEmployee; +import org.apache.jdo.tck.pc.company.QPerson; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Aggregate Result. *
@@ -50,445 +56,6 @@ "Assertion A14.6.9-6 (AggregateResult) failed: "; /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // COUNT(this) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(this)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // COUNT(this) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(this)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // COUNT(manager) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(manager)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // COUNT(manager.personid) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(manager.personid)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // COUNT(DISTINCT manager) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(DISTINCT manager)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM(long) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(personid)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM(double) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM(BigDecimal) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(budget)", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM(budget) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(budget)", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projid == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM(((FullTimeEmployee)manager).salary) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(((FullTimeEmployee)manager).salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM(DISTINCT ((FullTimeEmployee)manager).salary) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(DISTINCT ((FullTimeEmployee)manager).salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MIN(long) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MIN(personid)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MIN(double) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MIN(salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MIN(BigDecimal) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MIN(budget)", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MIN(budget) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MIN(budget)", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projid == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MIN(((FullTimeEmployee)manager).salary) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MIN(((FullTimeEmployee)manager).salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MAX(long) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(personid)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MAX(double) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MAX(BigDecimal) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(budget)", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MAX(budget) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(budget)", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projid == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MAX(((FullTimeEmployee)manager).salary) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(((FullTimeEmployee)manager).salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG(long) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(personid)", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG(double) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG(BigDecimal) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(lifetimeOrthoBenefit)", - /*INTO*/ null, - /*FROM*/ DentalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG(lifetimeOrthoBenefit) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(lifetimeOrthoBenefit)", - /*INTO*/ null, - /*FROM*/ DentalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ "insid == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG(((FullTimeEmployee)manager).salary) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(((FullTimeEmployee)manager).salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG(DISTINCT ((FullTimeEmployee)manager).salary) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(DISTINCT ((FullTimeEmployee)manager).salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - - }; - - /** * The array of invalid queries which may be executed as * single string queries and as API queries. */ @@ -509,110 +76,868 @@ /*FROM*/ null, /*TO*/ null) }; - - /** - * The expected results of valid queries. + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. */ - private Object[] expectedResult = { + public static void main(String[] args) { + BatchTestRunner.run(AggregateResult.class); + } + + /** */ + public void testCount0() { // COUNT(this) - new Long(3), + Object expected = new Long(3); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.count()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(this)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testCount1() { // COUNT(this) - new Long(0), + Object expected = new Long(0); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.count()); + query.filter(cand.personid.eq(0L)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(this)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testCount2() { // COUNT(manager) - new Long(2), + Object expected = new Long(2); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.manager.count()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(manager)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testCount3() { // COUNT(manager.personid) - new Long(2), + Object expected = new Long(2); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.manager.personid.count()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(manager.personid)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testCount4() { // COUNT(DISTINCT manager) - new Long(1), + Object expected = new Long(1); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.manager.countDistinct()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(DISTINCT manager)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testSum0() { // SUM(long) - new Long(1+2+5), + Object expected = new Long(1+2+5); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.personid.sum()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(personid)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testSum1() { // SUM(double) - new Double(20000.0+10000.0+45000.0), + Object expected = new Double(20000.0+10000.0+45000.0); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.salary.sum()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + + /** */ + public void testSum2() { // SUM(BigDecimal) - new BigDecimal("2500000.99").add - (new BigDecimal("50000.00")).add(new BigDecimal("2000.99")), + Object expected = new BigDecimal("2500000.99").add + (new BigDecimal("50000.00")).add(new BigDecimal("2000.99")); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget.sum()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(budget)", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testSum3() { // SUM(budget) - null, + Object expected = null; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget.sum()); + query.filter(cand.projid.eq(0L)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(budget)", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projid == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testSum4() { // SUM(((FullTimeEmployee)manager).salary) - new Double(20000), + Object expected = new Double(20000); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class); + query.result(false, cast.salary.sum()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(((FullTimeEmployee)manager).salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + + /** */ + public void testSum5() { // SUM(DISTINCT ((FullTimeEmployee)manager).salary) - new Double(10000), + Object expected = new Double(10000); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + query.result(false, + ((QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class)).salary.sumDistinct()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(DISTINCT ((FullTimeEmployee)manager).salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + + /** */ + public void testMin0() { // MIN(long) - new Long(1), + Object expected = new Long(1); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.personid.min()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MIN(personid)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testMin1() { // MIN(double) - new Double(10000.0), + Object expected = new Double(10000.0); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.salary.min()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MIN(salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + + /** */ + public void testMin2() { // MIN(BigDecimal) - new BigDecimal("2000.99"), + Object expected = new BigDecimal("2000.99"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget.min()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MIN(budget)", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testMin3() { // MIN(budget) - null, + Object expected = null; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget.min()); + query.filter(cand.projid.eq(0L)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MIN(budget)", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projid == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testMin4() { // MIN(((FullTimeEmployee)manager).salary) - new Double(10000), + Object expected = new Double(10000); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class); + query.result(false, cast.salary.min()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MIN(((FullTimeEmployee)manager).salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + /** */ + public void testMax0() { // MAX(long) - new Long(5), + Object expected = new Long(5); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.personid.max()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(personid)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); + } + + /** */ + public void testMax1() { // MAX(double) - new Double(45000.0), + Object expected = new Double(45000.0); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.salary.max()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + + /** */ + public void testMax2() { // MAX(BigDecimal) - new BigDecimal("2500000.99"), + Object expected = new BigDecimal("2500000.99"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget.max()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(budget)", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testMax3() { // MAX(budget) - null, + Object expected = null; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget.max()); + query.filter(cand.projid.eq(0L)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(budget)", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projid == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testMAX4() { // MAX(((FullTimeEmployee)manager).salary) - new Double(10000), + Object expected = new Double(10000); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class); + query.result(false, cast.salary.max()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(((FullTimeEmployee)manager).salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); + } + + /** */ + public void testAVG0() { // AVG(long) - new Double(3), - // AVG(double) - new Double(25000.0), - // AVG(BigDecimal) - new Double("99.997"), - // AVG(lifetimeOrthoBenefit) - null, - // AVG(((FullTimeEmployee)manager).salary) - new Double(10000), - // AVG(DISTINCT ((FullTimeEmployee)manager).salary) - new Double(10000) - }; - - /** - * The main is called when the class - * is directly executed from the command line. - * @param args The arguments passed to the program. - */ - public static void main(String[] args) { - BatchTestRunner.run(AggregateResult.class); + Object expected = new Double(3); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.result(false, cand.personid.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(personid)", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } - + /** */ - public void testCount() { - for(int i = 0; i < 5; i++) { - executeQuery(i); - } + public void testAVG1() { + // AVG(double) + Object expected = new Double(25000.0); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.salary.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } /** */ - public void testSUM() { - for(int i = 5; i < 11; i++) { - executeQuery(i); - } + public void testAVG2() { + // AVG(BigDecimal) + Object expected = new Double("99.997"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(DentalInsurance.class); + QDentalInsurance cand = QDentalInsurance.candidate(); + query.result(false, cand.lifetimeOrthoBenefit.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(lifetimeOrthoBenefit)", + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } /** */ - public void testMIN() { - for(int i = 11; i < 16; i++) { - executeQuery(i); - } + public void testAVG3() { + // AVG(lifetimeOrthoBenefit) + Object expected = null; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(DentalInsurance.class); + QDentalInsurance cand = QDentalInsurance.candidate(); + query.result(false, cand.lifetimeOrthoBenefit.avg()); + query.filter(cand.insid.eq(0L)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(lifetimeOrthoBenefit)", + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ "insid == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } /** */ - public void testMAX() { - for(int i = 16; i < 21; i++) { - executeQuery(i); - } + public void testAVG4() { + // AVG(((FullTimeEmployee)manager).salary) + Object expected = new Double(10000); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class); + query.result(false, cast.salary.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(((FullTimeEmployee)manager).salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } /** */ - public void testAVG() { - for(int i = 21; i < 27; i++) { - executeQuery(i); - } + public void testAVG5() { + // AVG(DISTINCT ((FullTimeEmployee)manager).salary) + Object expected = new Double(10000); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + QFullTimeEmployee cast = (QFullTimeEmployee)cand.manager.cast(FullTimeEmployee.class); + query.result(false, cast.salary.avgDistinct()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(DISTINCT ((FullTimeEmployee)manager).salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } public void testNegative() { @@ -622,15 +947,7 @@ false); } } - - /** */ - private void executeQuery(int index) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - + /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/DefaultResult.java (working copy) @@ -20,10 +20,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Default Result. *
@@ -39,35 +42,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.9-8 (DefaultResult) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}) - }; /** * The main is called when the class @@ -80,12 +54,31 @@ /** */ public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/DistinctCandidateInstances.java (working copy) @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.List; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.Query; import javax.jdo.Transaction; @@ -27,6 +28,7 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; @@ -51,49 +53,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.9-2 (DistintCandidateInstances) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "DISTINCT", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp1"}), - getTransientCompanyModelInstancesAsList(new String[]{"emp1"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -104,16 +63,68 @@ } /** */ - public void testExtentQueries() { + public void testExtentQueries0() { if (isUnconstrainedVariablesSupported()) { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + query.variable("p", Person.class); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } } + + /** */ + public void testExtentQueries1() { + if (isUnconstrainedVariablesSupported()) { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(true, cand); + query.variable("p", Person.class); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "DISTINCT", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + } /** */ public void testCollectionQueries() { @@ -128,11 +139,13 @@ query.setCandidates(candidates); query.setResult("this"); executeJDOQuery(ASSERTION_FAILED, query, singleStringQuery, - false, null, expectedResult[0], true); + false, null, + getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp1"}), true); query.setResult("DISTINCT this"); executeJDOQuery(ASSERTION_FAILED, query, singleStringDistinctQuery, - false, null, expectedResult[1], true); + false, null, + getTransientCompanyModelInstancesAsList(new String[]{"emp1"}), true); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/DistinctQuery.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/DistinctQuery.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/DistinctQuery.java (working copy) @@ -21,11 +21,15 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Disctinct Query. *
@@ -44,88 +48,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.9-1 (DistinctQuery) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "DISTINCT department", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department.deptid, department.name", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "DISTINCT department.deptid, department.name", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList(new String[]{ - "dept1", "dept1", "dept1", "dept2", "dept2"}), - getTransientCompanyModelInstancesAsList(new String[]{ - "dept1", "dept2"}), - Arrays.asList(new Object[] { - new Object[]{new Long(1),"Development"}, - new Object[]{new Long(1),"Development"}, - new Object[]{new Long(1),"Development"}, - new Object[]{new Long(2),"Human Resources"}, - new Object[]{new Long(2),"Human Resources"}}), - Arrays.asList(new Object[] { - new Object[]{new Long(1),"Development"}, - new Object[]{new Long(2),"Human Resources"}}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -136,15 +58,133 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "dept1", "dept1", "dept1", "dept2", "dept2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.department); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Department.class, expected); } + /** */ + public void testPositive1() { + Object expected = getTransientCompanyModelInstancesAsList(new String[]{ + "dept1", "dept2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(true, cand.department); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "DISTINCT department", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Department.class, expected); + } + + /** */ + public void testPositive2() { + Object expected = Arrays.asList(new Object[] { + new Object[]{new Long(1),"Development"}, + new Object[]{new Long(1),"Development"}, + new Object[]{new Long(1),"Development"}, + new Object[]{new Long(2),"Human Resources"}, + new Object[]{new Long(2),"Human Resources"}}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.department.deptid, cand.department.name); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department.deptid, department.name", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); + } + + /** */ + public void testPositive3() { + Object expected = Arrays.asList(new Object[] { + new Object[]{new Long(1),"Development"}, + new Object[]{new Long(2),"Human Resources"}}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(true, cand.department.deptid, cand.department.name); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "DISTINCT department.deptid, department.name", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); + } /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/result/Grouping.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/Grouping.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/Grouping.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.FullTimeEmployee; +import org.apache.jdo.tck.pc.company.QFullTimeEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Grouping. *
@@ -46,37 +49,16 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.10-1 (Grouping) failed: "; - - /** - * The array of valid queries which may be executed as + + /** + * The array of invalid queries which may be executed as * single string queries and as API queries. */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department, SUM(salary)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ "department", - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The array of invalid queries which may be executed as - * single string queries and as API queries. - */ private static final QueryElementHolder[] INVALID_QUERIES = { new QueryElementHolder( /*UNIQUE*/ null, /*RESULT*/ "department, salary", - /*INTO*/ null, + /*INTO*/ null, /*FROM*/ FullTimeEmployee.class, /*EXCLUDE*/ null, /*WHERE*/ null, @@ -88,15 +70,6 @@ /*FROM*/ null, /*TO*/ null) }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - Arrays.asList(new Object[] { - new Object[] {getTransientCompanyModelInstance("dept1"), new Double(30000.0)}, - new Object[] {getTransientCompanyModelInstance("dept2"), new Double(45000.0)}}) - }; /** * The main is called when the class @@ -109,12 +82,35 @@ /** */ public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + Object expected = Arrays.asList(new Object[] { + new Object[] {getTransientCompanyModelInstance("dept1"), new Double(30000.0)}, + new Object[] {getTransientCompanyModelInstance("dept2"), new Double(45000.0)}}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.department, cand.salary.sum()); + query.groupBy(cand.department); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department, SUM(salary)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ "department", + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ Index: tck/src/main/java/org/apache/jdo/tck/query/result/IfElseResult.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/IfElseResult.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/IfElseResult.java (working copy) @@ -25,10 +25,15 @@ import org.apache.jdo.tck.pc.company.DentalInsurance; import org.apache.jdo.tck.pc.company.Employee; import org.apache.jdo.tck.pc.company.Project; +import org.apache.jdo.tck.pc.company.QDentalInsurance; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.IfThenElseExpression; + /** *Title: IfElseResult. *
@@ -43,55 +48,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion (IfElseResult) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "IF (this.employee == null) 'No employee' ELSE this.employee.lastname", - /*INTO*/ null, - /*FROM*/ DentalInsurance.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.insid ascending", - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "IF (this.members.size() > 2) this.budget * 1.2 ELSE this.budget * 1.1", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.projid ascending", - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "IF (this.reviewers.isEmpty()) 'No reviewer' ELSE IF (this.reviewers.size() == 1) 'Single reviewer' ELSE 'Reviewer team'", - /*INTO*/ null, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.projid ascending", - /*FROM*/ null, - /*TO*/ null) - }; /** * The array of invalid queries which may be executed as @@ -145,15 +101,6 @@ /*TO*/ null) }; - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - Arrays.asList(new Object[] { "emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last", "No employee" }), - Arrays.asList(new Object[] { new BigDecimal("3000001.188"), new BigDecimal("55000"), new BigDecimal("2201.089") }), - Arrays.asList(new Object[] { "No reviewer", "Reviewer team", "Single reviewer" }) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -164,16 +111,106 @@ } /** */ - public void testPositive() { - for (int index = 0; index < VALID_QUERIES.length; index++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } + public void testPositive0() { + Object expected = Arrays.asList("emp1Last", "emp2Last", "emp3Last", "emp4Last", "emp5Last", "No employee"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(DentalInsurance.class); + QDentalInsurance cand = QDentalInsurance.candidate(); + query.result(false, + query.ifThenElse(cand.employee.eq((Employee)null), "No employee", cand.employee.lastname)); + query.orderBy(cand.insid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "IF (this.employee == null) 'No employee' ELSE this.employee.lastname", + /*INTO*/ null, + /*FROM*/ DentalInsurance.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.insid ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); } /** */ + public void testPositive1() { + Object expected = Arrays.asList( + new BigDecimal("3000001.188"), new BigDecimal("55000"), new BigDecimal("2201.089")); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, + query.ifThenElse(BigDecimal.class, cand.members.size().gt(2), + cand.budget.mul(new BigDecimal(1.2)), cand.budget.mul(new BigDecimal(1.1)))); + query.orderBy(cand.projid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "IF (this.members.size() > 2) this.budget * 1.2 ELSE this.budget * 1.1", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.projid ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); + } + + /** */ + public void testPositive2() { + Object expected = Arrays.asList("No reviewer", "Reviewer team", "Single reviewer"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + IfThenElseExpression ifThenElse = query.ifThen(cand.reviewers.isEmpty(), "No Reviewer"). + ifThen(cand.reviewers.size().eq(1), "Single reviewer").elseEnd("Reviewer team"); + query.result(false, ifThenElse); + query.orderBy(cand.projid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "IF (this.reviewers.isEmpty()) 'No reviewer' " + + "ELSE IF (this.reviewers.size() == 1) 'Single reviewer' ELSE 'Reviewer team'", + /*INTO*/ null, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.projid ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); + } + + /** */ public void testNegative() { for (int i = 0; i < INVALID_QUERIES.length; i++) { compileAPIQuery(ASSERTION_FAILED, INVALID_QUERIES[i], false); Index: tck/src/main/java/org/apache/jdo/tck/query/result/MethodsInResult.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/MethodsInResult.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/MethodsInResult.java (working copy) @@ -17,15 +17,16 @@ package org.apache.jdo.tck.query.result; -import java.math.BigInteger; import java.util.Arrays; -import javax.jdo.PersistenceManager; -import javax.jdo.Query; +import javax.jdo.JDOQLTypedQuery; +import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; @@ -48,127 +49,6 @@ private static final String ASSERTION_FAILED = "Assertion A14.6.9-5 (MethodsInResult) failed: "; - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // collection.size() - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this.employees.size()", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.name ascending", - /*FROM*/ null, - /*TO*/ null), - - // map.size() - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this.phoneNumbers.size()", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", - /*FROM*/ null, - /*TO*/ null), - - // MAX(collection.size()) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(this.employees.size())", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // map.get() - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this.phoneNumbers.get('home')", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", - /*FROM*/ null, - /*TO*/ null), - - // String.substring() - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this.firstname.substring(1,4)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", - /*FROM*/ null, - /*TO*/ null), - - // String.indexOf() - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this.firstname.indexOf('First')", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // collection.size() - Arrays.asList(new Object[] { new Integer(3), new Integer(2) }), - // map.size() - Arrays.asList(new Object[] { new Integer(2), new Integer(2), new Integer(2), new Integer(2), new Integer(2) }), - // MAX(collection.size()) - new Integer(3), - // map.get() - Arrays.asList(new Object[] { "1111", "2222", "3333", "3343", "3363" }), - // String.substring() - Arrays.asList(new Object[] { "mp1", "mp2", "mp3", "mp4", "mp5" }), - // String.indexOf() - //Arrays.asList(new Object[] { new BigInteger("4"), new BigInteger("4"), new BigInteger("4"), new BigInteger("4"), new BigInteger("4") }), - Arrays.asList(new Object[] { new Integer(4), new Integer(4), new Integer(4), new Integer(4), new Integer(4) }), - }; - /** * The main is called when the class * is directly executed from the command line. @@ -178,52 +58,191 @@ BatchTestRunner.run(MethodsInResult.class); } - public void testCollectionSizeInResult() throws Exception { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + public void testCollectionSizeInResult() { + // collection.size() + Object expected = Arrays.asList(new Integer(3), new Integer(2)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.result(false, cand.employees.size()); + query.orderBy(cand.name.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this.employees.size()", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.name ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Integer.class, expected); } - public void testMapSizeInResult() throws Exception { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + public void testMapSizeInResult() { + // map.size() + Object expected = Arrays.asList( + new Integer(2), new Integer(2), new Integer(2), new Integer(2), new Integer(2)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.phoneNumbers.size()); + query.orderBy(cand.lastname.asc(), cand.firstname.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this.phoneNumbers.size()", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Integer.class, expected); } - public void testMaxAndSizeInResult() throws Exception { - int index = 2; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + public void testMaxAndSizeInResult() { + // MAX(collection.size()) + Object expected = new Integer(3); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + query.result(false, cand.employees.size().max()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(this.employees.size())", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Integer.class, expected); } - public void testMapGetInResult() throws Exception { - int index = 3; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + public void testMapGetInResult() { + // map.get() + Object expected = Arrays.asList("1111", "2222", "3333", "3343", "3363"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.phoneNumbers.get("home")); + query.orderBy(cand.lastname.asc(), cand.firstname.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this.phoneNumbers.get('home')", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); } - public void testSubstringInResult() throws Exception { - int index = 4; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + public void testSubstringInResult() { + // String.substring() + Object expected = Arrays.asList("mp1", "mp2", "mp3", "mp4", "mp5"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.firstname.substring(1, 4)); + query.orderBy(cand.lastname.asc(), cand.firstname.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this.firstname.substring(1,4)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); } - public void testIndexOfInResult() throws Exception { - int index = 5; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + public void testIndexOfInResult() { + // String.indexOf() + Object expected = + Arrays.asList(new Integer(4), new Integer(4), new Integer(4), new Integer(4), new Integer(4)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.firstname.indexOf("First")); + query.orderBy(cand.lastname.asc(), cand.firstname.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this.firstname.indexOf('First')", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "this.lastname ascending, this.firstname ascending", + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Integer.class, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/NPEInResultExpr.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/NPEInResultExpr.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/NPEInResultExpr.java (working copy) @@ -23,10 +23,14 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: NullPointerException in Result Expression. *
@@ -45,52 +49,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.9-4 (NPEInResultExpr) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "manager.lastname", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e.manager.lastname", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e)", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - //Note: None of the entries below are bean names! - Arrays.asList(new Object[]{ - "emp2Last", null, "emp2Last", "emp2Last", "emp2Last"}), - Arrays.asList(new Object[]{ - "emp2Last", null, "emp2Last", "emp2Last", "emp2Last"}) - }; /** * The main is called when the class @@ -102,15 +60,67 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = Arrays.asList("emp2Last", null, "emp2Last", "emp2Last", "emp2Last"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.manager.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "manager.lastname", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); } + /** */ + public void testPositive1() { + Object expected = Arrays.asList("emp2Last", null, "emp2Last", "emp2Last", "emp2Last"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.employees.contains(e)); + query.result(false, e.manager.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e.manager.lastname", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e)", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); + } + /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/result/NullResults.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/NullResults.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/NullResults.java (working copy) @@ -22,10 +22,13 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QEmployee; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Null Results. *
@@ -42,64 +45,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.9-7 (NullResults) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ "manager", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "lastname == 'emp2Last'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "manager", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "lastname == 'emp2Last'", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "DISTINCT manager", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - null, - Arrays.asList(new Object[]{null}), - getTransientCompanyModelInstancesAsList(new String[]{"emp2", null}) - }; /** * The main is called when the class @@ -112,29 +57,94 @@ /** */ public void testUnique() { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = null; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.lastname.eq("emp2Last")); + query.result(false, cand.manager); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "manager", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "lastname == 'emp2Last'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Employee.class, expected); } /** */ public void testNavigation() { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList(new Object[]{null}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.filter(cand.lastname.eq("emp2Last")); + query.result(false, cand.manager); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "manager", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "lastname == 'emp2Last'", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Employee.class, expected); } /** */ public void testDistinctNavigation() { - int index = 2; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp2", null}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(true, cand.manager); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "DISTINCT manager", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/ResultClassRequirements.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/ResultClassRequirements.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/ResultClassRequirements.java (working copy) @@ -25,6 +25,8 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.FullTimeEmployee; import org.apache.jdo.tck.pc.company.Project; +import org.apache.jdo.tck.pc.company.QFullTimeEmployee; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.query.result.classes.LongString; @@ -35,6 +37,8 @@ import org.apache.jdo.tck.util.BatchTestRunner; import org.apache.jdo.tck.util.ConversionHelper; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Result Class Requirements. *
@@ -52,172 +56,6 @@ "Assertion A14.6.12-1 (ResultClassRequirements) failed: "; /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // Long - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid", - /*INTO*/ Long.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // Double - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "salary", - /*INTO*/ Double.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // BigDecimal - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "budget", - /*INTO*/ BigDecimal.class, - /*FROM*/ Project.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // java.util.Date - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "hiredate", - /*INTO*/ java.util.Date.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // Map - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid AS id, lastname AS name", - /*INTO*/ Map.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // user defined result class - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid AS l, lastname AS s", - /*INTO*/ LongString.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // constructor - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "new LongString(personid, lastname)", - /*INTO*/ null, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ "import org.apache.jdo.tck.query.result.classes.LongString;", - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // constructor without constructor call - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid, lastname", - /*INTO*/ LongString.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // public fields - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid AS l", - /*INTO*/ PublicLongField.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // public put method - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid, lastname", - /*INTO*/ PublicPutMethod.class, - /*FROM*/ FullTimeEmployee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The array of invalid queries which may be executed as * single string queries and as API queries. */ @@ -337,55 +175,6 @@ private static Object[][] publicPutMethod5 = {{"personid", new Long(5)}, {"lastname", "emp5Last"}}; - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // Long - Arrays.asList(new Object[]{new Long(1), new Long(2), new Long(5)}), - // Double - Arrays.asList(new Object[]{ - new Double(20000.0), new Double(10000.0), new Double(45000.0)}), - // BigDecimal - Arrays.asList(new Object[]{new BigDecimal("2500000.99"), - new BigDecimal("50000.00"), new BigDecimal("2000.99")}), - // java.util.Date - Arrays.asList(new Object[]{ - CompanyModelReader.stringToUtilDate("1/Jan/1999"), - CompanyModelReader.stringToUtilDate("1/Jul/2003"), - CompanyModelReader.stringToUtilDate("15/Aug/1998")}), - // Map - Arrays.asList(new Object[]{ - ConversionHelper.arrayToMap(emp1Map), - ConversionHelper.arrayToMap(emp2Map), - ConversionHelper.arrayToMap(emp5Map)}), - // user defined result class - Arrays.asList(new Object[]{ - new LongString(1, "emp1Last"), - new LongString(2, "emp2Last"), - new LongString(5, "emp5Last")}), - // constructor - Arrays.asList(new Object[]{ - new LongString(1, "emp1Last"), - new LongString(2, "emp2Last"), - new LongString(5, "emp5Last")}), - // constructor without constructor call - Arrays.asList(new Object[]{ - new LongString(1, "emp1Last"), - new LongString(2, "emp2Last"), - new LongString(5, "emp5Last")}), - // public fields - Arrays.asList(new Object[]{ - new PublicLongField(1), - new PublicLongField(2), - new PublicLongField(5)}), - // public put method - Arrays.asList(new Object[]{ - new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod1)), - new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod2)), - new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod5))}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -397,58 +186,330 @@ /** */ public void testLong() { - int index = 0; - executeQuery(index); + Object expected = Arrays.asList(new Long(1), new Long(2), new Long(5)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.personid); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid", + /*INTO*/ Long.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expected); } /** */ public void testDouble() { - int index = 1; - executeQuery(index); + Object expected = Arrays.asList(new Double(20000.0), new Double(10000.0), new Double(45000.0)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.salary); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "salary", + /*INTO*/ Double.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expected); } /** */ public void testBigDecimal() { - int index = 2; - executeQuery(index); + Object expected = Arrays.asList( + new BigDecimal("2500000.99"), new BigDecimal("50000.00"), new BigDecimal("2000.99")); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Project.class); + QProject cand = QProject.candidate(); + query.result(false, cand.budget); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "budget", + /*INTO*/ BigDecimal.class, + /*FROM*/ Project.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, BigDecimal.class, expected); } /** */ public void testDate() { - int index = 3; - executeQuery(index); + Object expected = Arrays.asList( + CompanyModelReader.stringToUtilDate("1/Jan/1999"), + CompanyModelReader.stringToUtilDate("1/Jul/2003"), + CompanyModelReader.stringToUtilDate("15/Aug/1998")); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + query.result(false, cand.hiredate); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "hiredate", + /*INTO*/ java.util.Date.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, java.util.Date.class, expected); } /** */ public void testMap() { - int index = 4; - executeQuery(index); + Object expected = Arrays.asList( + ConversionHelper.arrayToMap(emp1Map), + ConversionHelper.arrayToMap(emp2Map), + ConversionHelper.arrayToMap(emp5Map)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // JDOQLTypedQuery API: Map Result + query.result(false, cand.personid, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid AS id, lastname AS name", + /*INTO*/ Map.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Map.class, expected); } /** */ public void testUserDefinedResultClass() { - int index = 5; - executeQuery(index); + Object expected = Arrays.asList( + new LongString(1, "emp1Last"), + new LongString(2, "emp2Last"), + new LongString(5, "emp5Last")); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // JDOQLTypedQuery API: user defined class + query.result(false, cand.personid, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid AS l, lastname AS s", + /*INTO*/ LongString.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, LongString.class, expected); } /** */ public void testConstructor() { - int index = 6; - executeQuery(index); - index++; - executeQuery(index); + Object expected = Arrays.asList(new Object[]{ + new LongString(1, "emp1Last"), + new LongString(2, "emp2Last"), + new LongString(5, "emp5Last")}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // JDOQLTypedQuery API: constructor + query.result(false, cand.personid, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "new LongString(personid, lastname)", + /*INTO*/ null, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ "import org.apache.jdo.tck.query.result.classes.LongString;", + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, LongString.class, expected); } /** */ + public void testConstructorWithoutConstructorCall() { + Object expected = Arrays.asList(new Object[]{ + new LongString(1, "emp1Last"), + new LongString(2, "emp2Last"), + new LongString(5, "emp5Last")}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // JDOQLTypedQuery API: constructor + query.result(false, cand.personid, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid, lastname", + /*INTO*/ LongString.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, LongString.class, expected); + } + + /** */ public void testFields() { - int index = 8; - executeQuery(index); + Object expected = Arrays.asList(new Object[]{ + new PublicLongField(1), + new PublicLongField(2), + new PublicLongField(5)}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // JDOQLTypedQuery API: + query.result(false, cand.personid); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid AS l", + /*INTO*/ PublicLongField.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, PublicLongField.class, expected); } /** */ public void testPut() { - int index = 9; - executeQuery(index); + Object expected = Arrays.asList(new Object[]{ + new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod1)), + new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod2)), + new PublicPutMethod(ConversionHelper.arrayToMap(publicPutMethod5))}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(FullTimeEmployee.class); + QFullTimeEmployee cand = QFullTimeEmployee.candidate(); + // JDOQLTypedQuery API: constructor + query.result(false, cand.personid, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid, lastname", + /*INTO*/ PublicPutMethod.class, + /*FROM*/ FullTimeEmployee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, PublicPutMethod.class, expected); } /** */ @@ -460,14 +521,6 @@ } } - /** */ - private void executeQuery(int index) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/result/ResultExpressions.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/ResultExpressions.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/ResultExpressions.java (working copy) @@ -18,16 +18,26 @@ package org.apache.jdo.tck.query.result; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.FullTimeEmployee; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.Project; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QPerson; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; +import javax.jdo.query.Expression; + /** *Title: Result Expressions. *
@@ -46,284 +56,6 @@ "Assertion A14.6.9-5 (ResultExpressions) failed: "; /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // this - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // field - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // variable.field - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "p.projid", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projects.contains(p) && personid == 1", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // variable - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "p", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projects.contains(p) && personid == 1", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // COUNT(this) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(this)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // COUNT(variable) - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "COUNT(p)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projects.contains(p) && personid == 1", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // SUM - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "SUM(personid)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MIN - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MIN(personid)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // MAX - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "MAX(personid)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // AVG - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "AVG(personid)", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // field expression - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "personid + 1", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // navigational expression this - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this.personid", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // navigational expression variable - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "p.projid", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projects.contains(p) && personid == 1", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // navigational expression parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "p.projid", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Project p", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // navigational expression field - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "department.deptid", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // parameter - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "p", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ "Project p", - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // cast - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "(FullTimeEmployee)manager", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The array of invalid queries which may be executed as * single string queries and as API queries. */ @@ -390,49 +122,7 @@ /*TO*/ null) }; - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // this - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - // field - Arrays.asList(new Object[]{new Long(1), new Long(2), - new Long(3), new Long(4), new Long(5)}), - // variable.field - Arrays.asList(new Object[]{new Long(1)}), - // variable - getTransientCompanyModelInstancesAsList(new String[]{"proj1"}), - // COUNT(this) - new Long(5), - // COUNT(variable) - new Long(1), - // SUM - new Long(1+2+3+4+5), - // MIN - new Long(1), - // MAX - new Long(5), - // AVG - new Double(3), - // field expression - Arrays.asList(new Object[]{new Long(2), new Long(3), - new Long(4), new Long(5), new Long(6)}), - // navigational expression this - Arrays.asList(new Object[]{new Long(1), new Long(2), - new Long(3), new Long(4), new Long(5)}), - // navigational expression variable - Arrays.asList(new Object[]{new Long(1)}), - // navigational expression parameter - Arrays.asList(new Object[]{new Long(1)}), - // navigational expression field - Arrays.asList(new Object[]{new Long(1)}), - // parameter - getTransientCompanyModelInstancesAsList(new String[]{"proj1"}), - // cast - getTransientCompanyModelInstancesAsList(new String[]{"emp2"}) - }; + /** * The main is called when the class @@ -445,106 +135,559 @@ /** */ public void testThis() { - int index = 0; - executeQuery(index, null); + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{ + "emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + // DataNucleus: org.datanucleus.exceptions.NucleusUserException: Query needs to return objects of type + // "org.apache.jdo.tck.pc.company.Employee" but it was impossible to create a new instance of this type. + // The result class needs a no-args constructor. + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Employee.class, expectedResult); } /** */ public void testField() { - int index = 1; - executeQuery(index, null); + Object expectedResult = Arrays.asList( + Long.valueOf(1), Long.valueOf(2), Long.valueOf(3), Long.valueOf(4), Long.valueOf(5)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.personid); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testVariableField() { - int index = 2; - executeQuery(index, null); + Object expectedResult = Arrays.asList(new Object[]{new Long(1)}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject p = QProject.variable("p"); + query.result(false, p.projid); + query.filter(cand.projects.contains(p).and(cand.personid.eq(1l))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "p.projid", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projects.contains(p) && personid == 1", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testVariable() { - int index = 3; - executeQuery(index, null); + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"proj1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject variable = QProject.variable("p"); + query.result(false, variable); + query.filter(cand.projects.contains(variable).and(cand.personid.eq(1l))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "p", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projects.contains(p) && personid == 1", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Project.class, expectedResult); } /** */ public void testCountThis() { - int index = 4; - executeQuery(index, null); + // COUNT(this) + Object expectedResult = Long.valueOf(5); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.count()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(this)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testCountVariable() { - int index = 5; - executeQuery(index, null); + // COUNT(variable) + Object expectedResult = Long.valueOf(1); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject p = QProject.variable("p"); + query.result(false, p.count()); + query.filter(cand.projects.contains(p).and(cand.personid.eq(1l))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "COUNT(p)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projects.contains(p) && personid == 1", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testSum() { - int index = 6; - executeQuery(index, null); + // SUM + Object expectedResult = new Long(1+2+3+4+5); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.personid.sum()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "SUM(personid)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testMin() { - int index = 7; - executeQuery(index, null); + // MIN + Object expectedResult = Long.valueOf(1); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.personid.min()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MIN(personid)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testMax() { - int index = 8; - executeQuery(index, null); + // MAX + Object expectedResult = Long.valueOf(5); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.personid.max()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "MAX(personid)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testAvg() { - int index = 9; - executeQuery(index, null); + // AVG + Object expectedResult = new Double(3); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.personid.avg()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "AVG(personid)", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Double.class, expectedResult); } /** */ public void testFieldExpression() { - int index = 10; - executeQuery(index, null); + // field expression + Object expectedResult = Arrays.asList( + Long.valueOf(2), Long.valueOf(3), Long.valueOf(4), Long.valueOf(5), Long.valueOf(6)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.result(false, cand.personid.add(1)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "personid + 1", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testNavigationalExpressionThis() { - int index = 11; - executeQuery(index, null); + // navigational expression this + Object expectedResult = Arrays.asList( + Long.valueOf(1), Long.valueOf(2),Long.valueOf(3), Long.valueOf(4), Long.valueOf(5)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.personid); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this.personid", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testNavigationalExpressionVariable() { - int index = 12; - executeQuery(index, null); + // navigational expression variable + Object expectedResult = + Arrays.asList(new Object[]{"Development", "Human Resources"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QEmployee e = QEmployee.variable("e"); + Expression eExpr = query.variable("e", Employee.class); + query.result(true, e.department.name); + query.filter(cand.team.contains(eExpr).and(cand.personid.eq(2l))); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "distinct e.department.name", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "team.contains(e) && personid == 2", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + // DataNucleus: wrong result: [Development, Development, Development, Development] + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expectedResult); } /** */ public void testNavigationalExpressionParameter() { - int index = 13; - Object[] parameters = getPersistentCompanyModelInstances(new String[]{"proj1"}); - executeQuery(index, parameters); + // navigational expression parameter + Object expectedResult = Arrays.asList(Long.valueOf(1)); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject p = QProject.parameter("p"); + query.parameter("p", Project.class); + query.result(false, p.projid); + query.filter(cand.personid.eq(1l).and(p.projid.eq(cand.personid))); + + Map paramValues = new HashMap<>(); + paramValues.put("p", getPersistentCompanyModelInstance("proj1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "p.projid", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1 && p.projid == this.personid", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Project p", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testNavigationalExpressionField() { - int index = 14; - executeQuery(index, null); + // navigational expression field + Object expectedResult = Arrays.asList(new Object[]{new Long(1)}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + query.result(false, cand.department.deptid); + query.filter(cand.personid.eq(1l)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "department.deptid", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Long.class, expectedResult); } /** */ public void testParameter() { - int index = 15; - Object[] parameters = getPersistentCompanyModelInstances(new String[]{"proj1"}); - executeQuery(index, parameters); + // parameter + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"proj1"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject p = QProject.parameter("p"); + query.parameter("p", Project.class); + query.result(false, p); + query.filter(cand.personid.eq(1l).and(cand.personid.eq(p.projid))); + + Map paramValues = new HashMap<>(); + paramValues.put("p", getPersistentCompanyModelInstance("proj1")); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "p", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1 && personid == p.projid", + /*VARIABLES*/ null, + /*PARAMETERS*/ "Project p", + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ paramValues); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Project.class, expectedResult); } /** */ public void testCast() { - int index = 16; - executeQuery(index, null); + // cast + Object expectedResult = getTransientCompanyModelInstancesAsList(new String[]{"emp2"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + // DataNucleus: UnsupportedOperationException: cast not yet supported + query.result(false, cand.manager.cast(FullTimeEmployee.class)); + query.filter(cand.personid.eq(1l)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "(FullTimeEmployee)manager", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expectedResult); + executeSingleStringQuery(ASSERTION_FAILED, holder, expectedResult); + // DataNucleus: UnsupportedOperationException: cast not yet supported + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, FullTimeEmployee.class, expectedResult); } /** */ @@ -556,14 +699,6 @@ } } - /** */ - private void executeQuery(int index, Object[] parameters) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - parameters, expectedResult[index]); - } - /** * @see JDO_Test#localSetUp() */ Index: tck/src/main/java/org/apache/jdo/tck/query/result/ShapeOfResult.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/ShapeOfResult.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/ShapeOfResult.java (working copy) @@ -22,11 +22,14 @@ import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.query.result.classes.FullName; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Shape of Result. *
@@ -42,212 +45,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.12-2 (ShapeOfResult) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - // result: null - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: this AS C - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this AS Person", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: null, unique: true - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: this AS C, unique: true - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ "this AS Person", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: expression of type T - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "firstname", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: expression of type T, unique: true - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ "firstname", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: multiple expressions of type T - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "firstname, lastname", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: multiple expressions of type T, unique: true - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ "firstname, lastname", - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: multiple expressions of type T, result class - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "firstname, lastname", - /*INTO*/ FullName.class, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - // result: multiple expressions of type T, result class, unique: true - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ "firstname, lastname", - /*INTO*/ FullName.class, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - // result: null - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - // result: this AS C - getTransientCompanyModelInstancesAsList(new String[]{ - "emp1", "emp2", "emp3", "emp4", "emp5"}), - // result: null, unique: true - getTransientCompanyModelInstance("emp1"), - // result: this AS C, unique: true - getTransientCompanyModelInstance("emp1"), - // result: expression of type T - Arrays.asList(new Object[]{"emp1First", "emp2First", - "emp3First", "emp4First", "emp5First"}), - // result: expression of type T, unique: true - "emp1First", - // result: multiple expressions of type T - Arrays.asList(new Object[]{ - new Object[]{"emp1First", "emp1Last"}, - new Object[]{"emp2First", "emp2Last"}, - new Object[]{"emp3First", "emp3Last"}, - new Object[]{"emp4First", "emp4Last"}, - new Object[]{"emp5First", "emp5Last"}}), - // result: multiple expressions of type T, unique: true - new Object[]{"emp1First", "emp1Last"}, - // result: multiple expressions of type T, result class - Arrays.asList(new Object[]{ - new FullName("emp1First", "emp1Last"), - new FullName("emp2First", "emp2Last"), - new FullName("emp3First", "emp3Last"), - new FullName("emp4First", "emp4Last"), - new FullName("emp5First", "emp5Last")}), - // result: multiple expressions of type T, result class, unique: true - new FullName("emp1First", "emp1Last") - }; /** * The main is called when the class @@ -260,69 +57,326 @@ /** */ public void testNoResult() { - int index = 0; - execute(index, expectedResult[index]); + // result: null + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ public void testThisAsC() { - int index = 1; - execute(index, expectedResult[index]); + // result: this AS C + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1", "emp2", "emp3", "emp4", "emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.result(false, cand); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this AS Person", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Person.class, expected); } /** */ public void testNoResultUnique() { - int index = 2; - execute(index, expectedResult[index]); + // result: null, unique: true + Object expected = getTransientCompanyModelInstance("emp1"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(1l)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } /** */ public void testThisAsCUnique() { - int index = 3; - execute(index, expectedResult[index]); + // result: this AS C, unique: true + Object expected = getTransientCompanyModelInstance("emp1"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(1l)); + query.result(false, cand); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "this AS Person", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Person.class, expected); } /** */ public void testSingleExpression() { - int index = 4; - execute(index, expectedResult[index]); + // result: expression of type T + Object expected = Arrays.asList("emp1First", "emp2First", "emp3First", "emp4First", "emp5First"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.result(false, cand.firstname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "firstname", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); } /** */ public void testSingleExpressionUnique() { - int index = 5; - execute(index, expectedResult[index]); + // result: expression of type T, unique: true + Object expected = "emp1First"; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(1l)); + query.result(false, cand.firstname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "firstname", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, String.class, expected); } /** */ public void testMultipleExpressions() { - int index = 6; - execute(index, expectedResult[index]); + // result: multiple expressions of type T + Object expected = Arrays.asList( + new Object[]{"emp1First", "emp1Last"}, + new Object[]{"emp2First", "emp2Last"}, + new Object[]{"emp3First", "emp3Last"}, + new Object[]{"emp4First", "emp4Last"}, + new Object[]{"emp5First", "emp5Last"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.result(false, cand.firstname, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "firstname, lastname", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testMultipleExpressionsUnique() { - int index = 7; - execute(index, expectedResult[index]); + // result: multiple expressions of type T, unique: true + Object expected = new Object[]{"emp1First", "emp1Last"}; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(1l)); + query.result(false, cand.firstname, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "firstname, lastname", + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testMultipleExpressionsResultClass() { - int index = 8; - execute(index, expectedResult[index]); + // result: multiple expressions of type T, result class + Object expected = Arrays.asList( + new FullName("emp1First", "emp1Last"), + new FullName("emp2First", "emp2Last"), + new FullName("emp3First", "emp3Last"), + new FullName("emp4First", "emp4Last"), + new FullName("emp5First", "emp5Last")); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + // JDOQLTypedQuery API + query.result(false, cand.firstname, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "firstname, lastname", + /*INTO*/ FullName.class, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, FullName.class, expected); } /** */ public void testMultipleExpressionResultClassUnique() { - int index = 9; - execute(index, expectedResult[index]); - } + // result: multiple expressions of type T, result class, unique: true + Object expected = new FullName("emp1First", "emp1Last"); - /** */ - private void execute(int index, Object expected) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], expected); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expected); + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(1l)); + // JDOQLTypedQuery API + query.result(false, cand.firstname, cand.lastname); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ "firstname, lastname", + /*INTO*/ FullName.class, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, FullName.class, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/Unique.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/Unique.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/Unique.java (working copy) @@ -17,11 +17,13 @@ package org.apache.jdo.tck.query.result; +import javax.jdo.JDOQLTypedQuery; import javax.jdo.Query; import org.apache.jdo.tck.JDO_Test; import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Person; +import org.apache.jdo.tck.pc.company.QPerson; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; @@ -47,64 +49,6 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.11-1 (Unique) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 1", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ "personid == 0", - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ Boolean.TRUE, - /*RESULT*/ null, - /*INTO*/ null, - /*FROM*/ Person.class, - /*EXCLUDE*/ null, - /*WHERE*/ null, - /*VARIABLES*/ null, - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ "personid ASCENDING", - /*FROM*/ "0", - /*TO*/ "1"), - }; - - /** - * The expected results of valid queries. - */ - private Object[] expectedResult = { - getTransientCompanyModelInstance("emp1"), - null, - getTransientCompanyModelInstance("emp1") - }; /** * The main is called when the class @@ -116,15 +60,95 @@ } /** */ - public void testPositive() { - for (int i = 0; i < VALID_QUERIES.length; i++) { - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[i], - expectedResult[i]); - } + public void testPositive0() { + Object expected = getTransientCompanyModelInstance("emp1"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(1l)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 1", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); } + /** */ + public void testPositive1() { + Object expected = null; + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.filter(cand.personid.eq(0l)); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ "personid == 0", + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + + /** */ + public void testPositive2() { + Object expected = getTransientCompanyModelInstance("emp1"); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Person.class); + QPerson cand = QPerson.candidate(); + query.orderBy(cand.personid.asc()); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ Boolean.TRUE, + /*RESULT*/ null, + /*INTO*/ null, + /*FROM*/ Person.class, + /*EXCLUDE*/ null, + /*WHERE*/ null, + /*VARIABLES*/ null, + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ "personid ASCENDING", + /*FROM*/ "0", + /*TO*/ "1", + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, expected); + } + public void testNegative() { String singleString = "SELECT UNIQUE FROM " + Person.class.getName(); Index: tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResult.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResult.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResult.java (working copy) @@ -23,10 +23,15 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Department; import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Variable in Result. *
@@ -54,113 +59,7 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.9-3 (VariableInResult) failed: "; - - /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "distinct e", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e)", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "distinct p.projid, p.name", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projects.contains(p) & p.name == 'orange'", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "p.projid, p.name", - /*INTO*/ null, - /*FROM*/ Employee.class, - /*EXCLUDE*/ null, - /*WHERE*/ "projects.contains(p) & p.name == 'orange'", - /*VARIABLES*/ "Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e)", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - // SELECT e FROM Department WHERE deptid==2 & employees.contains(e) VARIABLES Employee e - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "deptid == 2 & employees.contains(e)", - /*VARIABLES*/ "Employee e", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** - * The expected results of valid queries. - */ - private Object emp1 = getTransientCompanyModelInstance("emp1"); - private Object emp2 = getTransientCompanyModelInstance("emp2"); - private Object emp3 = getTransientCompanyModelInstance("emp3"); - private Object emp4 = getTransientCompanyModelInstance("emp4"); - private Object emp5 = getTransientCompanyModelInstance("emp5"); - private Object proj1 = getTransientCompanyModelInstance("proj1"); - private Object proj2 = getTransientCompanyModelInstance("proj2"); - private Object proj3 = getTransientCompanyModelInstance("proj3"); - private Object[] expectedResult = { - getTransientCompanyModelInstancesAsList( - new String[]{"emp1","emp2","emp3","emp4","emp5"}), - // Note: "orange" is not a bean name! - Arrays.asList(new Object[]{ - new Object[]{new Long(1), "orange"}}), - Arrays.asList(new Object[]{ - new Object[]{new Long(1), "orange"}, - new Object[]{new Long(1), "orange"}, - new Object[]{new Long(1), "orange"}}), - getTransientCompanyModelInstancesAsList( - new String[]{"emp1","emp2","emp3","emp4","emp5"}), - getTransientCompanyModelInstancesAsList( - new String[]{"emp4","emp5"}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -172,47 +71,166 @@ /** */ public void testDistinctNoNavigation() { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1","emp2","emp3","emp4","emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.employees.contains(e)); + query.result(true, e); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "distinct e", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e)", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Employee.class, expected); } /** */ public void testDistinctNavigation() { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList(new Object[]{new Long(1), "orange"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject p = QProject.variable("p"); + query.filter(cand.projects.contains(p).and(p.name.eq("orange"))); + query.result(true, p.projid, p.name); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "distinct p.projid, p.name", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projects.contains(p) & p.name == 'orange'", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigation() { - int index = 2; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[]{new Long(1), "orange"}, + new Object[]{new Long(1), "orange"}, + new Object[]{new Long(1), "orange"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Employee.class); + QEmployee cand = QEmployee.candidate(); + QProject p = QProject.variable("p"); + query.filter(cand.projects.contains(p).and(p.name.eq("orange"))); + query.result(false, p.projid, p.name); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "p.projid, p.name", + /*INTO*/ null, + /*FROM*/ Employee.class, + /*EXCLUDE*/ null, + /*WHERE*/ "projects.contains(p) & p.name == 'orange'", + /*VARIABLES*/ "Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNoNavigation() { - int index = 3; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp1","emp2","emp3","emp4","emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.employees.contains(e)); + query.result(false, e); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e)", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Employee.class, expected); } /** */ public void testMultipleProjectionWithConstraints() { - int index = 4; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = getTransientCompanyModelInstancesAsList(new String[]{"emp4","emp5"}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + query.filter(cand.deptid.eq(2l).and(cand.employees.contains(e))); + query.result(false, e); + + // SELECT e FROM Department WHERE deptid==2 & employees.contains(e) VARIABLES Employee e + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "deptid == 2 & employees.contains(e)", + /*VARIABLES*/ "Employee e", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Employee.class, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResultMultipleNavigation.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResultMultipleNavigation.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResultMultipleNavigation.java (working copy) @@ -22,10 +22,16 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Company; import org.apache.jdo.tck.pc.company.Department; +import org.apache.jdo.tck.pc.company.QCompany; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Variable in Result. *
@@ -58,57 +64,8 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.9-3 (VariableInResult) failed: "; - + /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this, d, e, p", - /*INTO*/ null, - /*FROM*/ Company.class, - /*EXCLUDE*/ null, - /*WHERE*/ "name == \"Sun Microsystems, Inc.\" && departments.contains(d) && d.employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Department d; Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this, e, p", - /*INTO*/ null, - /*FROM*/ Company.class, - /*EXCLUDE*/ null, - /*WHERE*/ "name == \"Sun Microsystems, Inc.\" && departments.contains(d) && d.employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Department d; Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "d, e, p", - /*INTO*/ null, - /*FROM*/ Company.class, - /*EXCLUDE*/ null, - /*WHERE*/ "name == \"Sun Microsystems, Inc.\" && departments.contains(d) && d.employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Department d; Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The expected results of valid queries. */ private Object company1 = getTransientCompanyModelInstance("company1"); @@ -123,33 +80,6 @@ private Object dept1 = getTransientCompanyModelInstance("dept1"); private Object dept2 = getTransientCompanyModelInstance("dept2"); - private Object[] expectedResult = { - Arrays.asList(new Object[] { - new Object[] {company1, dept1, emp1, proj1}, - new Object[] {company1, dept1, emp2, proj1}, - new Object[] {company1, dept1, emp3, proj1}, - new Object[] {company1, dept1, emp2, proj2}, - new Object[] {company1, dept1, emp3, proj2}, - new Object[] {company1, dept2, emp4, proj3}, - new Object[] {company1, dept2, emp5, proj3}}), - Arrays.asList(new Object[] { - new Object[] {company1, emp1, proj1}, - new Object[] {company1, emp2, proj1}, - new Object[] {company1, emp3, proj1}, - new Object[] {company1, emp2, proj2}, - new Object[] {company1, emp3, proj2}, - new Object[] {company1, emp4, proj3}, - new Object[] {company1, emp5, proj3}}), - Arrays.asList(new Object[] { - new Object[] {dept1, emp1, proj1}, - new Object[] {dept1, emp2, proj1}, - new Object[] {dept1, emp3, proj1}, - new Object[] {dept1, emp2, proj2}, - new Object[] {dept1, emp3, proj2}, - new Object[] {dept2, emp4, proj3}, - new Object[] {dept2, emp5, proj3}}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -161,29 +91,131 @@ /** */ public void testNavigationWithCompanyAndDepartmentAndEmployeeAndProject() { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {company1, dept1, emp1, proj1}, + new Object[] {company1, dept1, emp2, proj1}, + new Object[] {company1, dept1, emp3, proj1}, + new Object[] {company1, dept1, emp2, proj2}, + new Object[] {company1, dept1, emp3, proj2}, + new Object[] {company1, dept2, emp4, proj3}, + new Object[] {company1, dept2, emp5, proj3}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Company.class); + QCompany cand = QCompany.candidate(); + QDepartment d = QDepartment.variable("d"); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.name.eq("Sun Microsystems, Inc.").and(e.projects.contains(p)). + and(cand.departments.contains(d)).and(e.projects.contains(p))); + query.result(false, cand, d, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this, d, e, p", + /*INTO*/ null, + /*FROM*/ Company.class, + /*EXCLUDE*/ null, + /*WHERE*/ "name == \"Sun Microsystems, Inc.\" && " + + "departments.contains(d) && d.employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Department d; Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigationWithCompanyAndEmployeeAndProject() { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {company1, emp1, proj1}, + new Object[] {company1, emp2, proj1}, + new Object[] {company1, emp3, proj1}, + new Object[] {company1, emp2, proj2}, + new Object[] {company1, emp3, proj2}, + new Object[] {company1, emp4, proj3}, + new Object[] {company1, emp5, proj3}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Company.class); + QCompany cand = QCompany.candidate(); + QDepartment d = QDepartment.variable("d"); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.name.eq("Sun Microsystems, Inc.").and(e.projects.contains(p)). + and(cand.departments.contains(d)).and(e.projects.contains(p))); + query.result(false, cand, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this, e, p", + /*INTO*/ null, + /*FROM*/ Company.class, + /*EXCLUDE*/ null, + /*WHERE*/ "name == \"Sun Microsystems, Inc.\" && " + + "departments.contains(d) && d.employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Department d; Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigationWithDepartmentAndEmployeeAndProject() { - int index = 2; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {dept1, emp1, proj1}, + new Object[] {dept1, emp2, proj1}, + new Object[] {dept1, emp3, proj1}, + new Object[] {dept1, emp2, proj2}, + new Object[] {dept1, emp3, proj2}, + new Object[] {dept2, emp4, proj3}, + new Object[] {dept2, emp5, proj3}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Company.class); + QCompany cand = QCompany.candidate(); + QDepartment d = QDepartment.variable("d"); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.name.eq("Sun Microsystems, Inc.").and(e.projects.contains(p)). + and(cand.departments.contains(d)).and(e.projects.contains(p))); + query.result(false, d, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "d, e, p", + /*INTO*/ null, + /*FROM*/ Company.class, + /*EXCLUDE*/ null, + /*WHERE*/ "name == \"Sun Microsystems, Inc.\" && " + + "departments.contains(d) && d.employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Department d; Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** Index: tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResultNavigation.java =================================================================== --- tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResultNavigation.java (revision 1842755) +++ tck/src/main/java/org/apache/jdo/tck/query/result/VariableInResultNavigation.java (working copy) @@ -22,10 +22,15 @@ import org.apache.jdo.tck.pc.company.CompanyModelReader; import org.apache.jdo.tck.pc.company.Company; import org.apache.jdo.tck.pc.company.Department; +import org.apache.jdo.tck.pc.company.QDepartment; +import org.apache.jdo.tck.pc.company.QEmployee; +import org.apache.jdo.tck.pc.company.QProject; import org.apache.jdo.tck.query.QueryElementHolder; import org.apache.jdo.tck.query.QueryTest; import org.apache.jdo.tck.util.BatchTestRunner; +import javax.jdo.JDOQLTypedQuery; + /** *Title: Variable in Result. *
@@ -58,85 +63,8 @@ /** */ private static final String ASSERTION_FAILED = "Assertion A14.6.9-3 (VariableInResult) failed: "; - + /** - * The array of valid queries which may be executed as - * single string queries and as API queries. - */ - private static final QueryElementHolder[] VALID_QUERIES = { - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e, p", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e) && e.projects.contains(p) && p.name == 'orange'", - /*VARIABLES*/ "Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e, p", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "this, e, p", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e, p", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "deptid == 1 && employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null), - new QueryElementHolder( - /*UNIQUE*/ null, - /*RESULT*/ "e, p", - /*INTO*/ null, - /*FROM*/ Department.class, - /*EXCLUDE*/ null, - /*WHERE*/ "company.name == \"Sun Microsystems, Inc.\" && employees.contains(e) && e.projects.contains(p)", - /*VARIABLES*/ "Employee e; Project p", - /*PARAMETERS*/ null, - /*IMPORTS*/ null, - /*GROUP BY*/ null, - /*ORDER BY*/ null, - /*FROM*/ null, - /*TO*/ null) - }; - - /** * The expected results of valid queries. */ private Object emp1 = getTransientCompanyModelInstance("emp1"); @@ -150,43 +78,6 @@ private Object dept1 = getTransientCompanyModelInstance("dept1"); private Object dept2 = getTransientCompanyModelInstance("dept2"); - private Object[] expectedResult = { - Arrays.asList(new Object[] { - new Object[] {emp1, proj1}, - new Object[] {emp2, proj1}, - new Object[] {emp3, proj1}}), - Arrays.asList(new Object[] { - new Object[] {emp1, proj1}, - new Object[] {emp2, proj1}, - new Object[] {emp3, proj1}, - new Object[] {emp2, proj2}, - new Object[] {emp3, proj2}, - new Object[] {emp4, proj3}, - new Object[] {emp5, proj3}}), - Arrays.asList(new Object[] { - new Object[] {dept1, emp1, proj1}, - new Object[] {dept1, emp2, proj1}, - new Object[] {dept1, emp3, proj1}, - new Object[] {dept1, emp2, proj2}, - new Object[] {dept1, emp3, proj2}, - new Object[] {dept2, emp4, proj3}, - new Object[] {dept2, emp5, proj3}}), - Arrays.asList(new Object[] { - new Object[] {emp1, proj1}, - new Object[] {emp2, proj1}, - new Object[] {emp3, proj1}, - new Object[] {emp2, proj2}, - new Object[] {emp3, proj2}}), - Arrays.asList(new Object[] { - new Object[] {emp1, proj1}, - new Object[] {emp2, proj1}, - new Object[] {emp3, proj1}, - new Object[] {emp2, proj2}, - new Object[] {emp3, proj2}, - new Object[] {emp4, proj3}, - new Object[] {emp5, proj3}}) - }; - /** * The main is called when the class * is directly executed from the command line. @@ -198,47 +89,196 @@ /** */ public void testNavigationWithConstraint() { - int index = 0; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {emp1, proj1}, + new Object[] {emp2, proj1}, + new Object[] {emp3, proj1}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.employees.contains(e).and(e.projects.contains(p)).and(p.name.eq("orange"))); + query.result(false, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e, p", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && e.projects.contains(p) && p.name == 'orange'", + /*VARIABLES*/ "Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigationWithoutConstraint() { - int index = 1; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {emp1, proj1}, + new Object[] {emp2, proj1}, + new Object[] {emp3, proj1}, + new Object[] {emp2, proj2}, + new Object[] {emp3, proj2}, + new Object[] {emp4, proj3}, + new Object[] {emp5, proj3}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.employees.contains(e).and(e.projects.contains(p))); + query.result(false, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e, p", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigationWithThis() { - int index = 2; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {dept1, emp1, proj1}, + new Object[] {dept1, emp2, proj1}, + new Object[] {dept1, emp3, proj1}, + new Object[] {dept1, emp2, proj2}, + new Object[] {dept1, emp3, proj2}, + new Object[] {dept2, emp4, proj3}, + new Object[] {dept2, emp5, proj3}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.employees.contains(e).and(e.projects.contains(p))); + query.result(false, cand, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "this, e, p", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigationWithThisConstraint() { - int index = 3; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {emp1, proj1}, + new Object[] {emp2, proj1}, + new Object[] {emp3, proj1}, + new Object[] {emp2, proj2}, + new Object[] {emp3, proj2}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.deptid.eq(1l).and(cand.employees.contains(e)).and(e.projects.contains(p))); + query.result(false, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e, p", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "deptid == 1 && employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** */ public void testNavigationWithCompanyConstraint() { - int index = 4; - executeAPIQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); - executeSingleStringQuery(ASSERTION_FAILED, VALID_QUERIES[index], - expectedResult[index]); + Object expected = Arrays.asList( + new Object[] {emp1, proj1}, + new Object[] {emp2, proj1}, + new Object[] {emp3, proj1}, + new Object[] {emp2, proj2}, + new Object[] {emp3, proj2}, + new Object[] {emp4, proj3}, + new Object[] {emp5, proj3}); + + JDOQLTypedQuery query = getPM().newJDOQLTypedQuery(Department.class); + QDepartment cand = QDepartment.candidate(); + QEmployee e = QEmployee.variable("e"); + QProject p = QProject.variable("p"); + query.filter(cand.company.name.eq("Sun Microsystems, Inc.").and(cand.employees.contains(e)).and(e.projects.contains(p))); + query.result(false, e, p); + + QueryElementHolder holder = new QueryElementHolder( + /*UNIQUE*/ null, + /*RESULT*/ "e, p", + /*INTO*/ null, + /*FROM*/ Department.class, + /*EXCLUDE*/ null, + /*WHERE*/ "company.name == \"Sun Microsystems, Inc.\" && employees.contains(e) && e.projects.contains(p)", + /*VARIABLES*/ "Employee e; Project p", + /*PARAMETERS*/ null, + /*IMPORTS*/ null, + /*GROUP BY*/ null, + /*ORDER BY*/ null, + /*FROM*/ null, + /*TO*/ null, + /*JDOQLTyped*/ query, + /*paramValues*/ null); + + executeAPIQuery(ASSERTION_FAILED, holder, expected); + executeSingleStringQuery(ASSERTION_FAILED, holder, expected); + executeJDOQLTypedQuery(ASSERTION_FAILED, holder, Object[].class, expected); } /** * @see QueryTest#localSetUp()