Index: src/java/javax/jdo/query/BooleanExpression.java
===================================================================
--- src/java/javax/jdo/query/BooleanExpression.java	(revision 0)
+++ src/java/javax/jdo/query/BooleanExpression.java	(revision 0)
@@ -0,0 +1,43 @@
+/*
+ * 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 a boolean expression.
+ */
+public interface BooleanExpression extends ComparableExpression<Boolean>
+{
+    /**
+     * Method to return the AND of this expression and the other expression.
+     * @param expr The other expression
+     * @return The resultant (boolean) expression
+     */
+    BooleanExpression and(BooleanExpression expr);
+
+    /**
+     * Method to return the OR of this expression and the other expression.
+     * @param expr The other expression
+     * @return The resultant (boolean) expression
+     */
+    BooleanExpression or(BooleanExpression expr);
+
+    /**
+     * Method to negate this expression.
+     * @return The negated expression
+     */
+    BooleanExpression not();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/ByteExpression.java
===================================================================
--- src/java/javax/jdo/query/ByteExpression.java	(revision 0)
+++ src/java/javax/jdo/query/ByteExpression.java	(revision 0)
@@ -0,0 +1,24 @@
+/*
+ * 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 a byte expression.
+ */
+public interface ByteExpression extends ComparableExpression<Byte>
+{
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/CharacterExpression.java
===================================================================
--- src/java/javax/jdo/query/CharacterExpression.java	(revision 0)
+++ src/java/javax/jdo/query/CharacterExpression.java	(revision 0)
@@ -0,0 +1,24 @@
+/*
+ * 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 a character expression.
+ */
+public interface CharacterExpression extends ComparableExpression<Character>
+{
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/CollectionExpression.java
===================================================================
--- src/java/javax/jdo/query/CollectionExpression.java	(revision 0)
+++ src/java/javax/jdo/query/CollectionExpression.java	(revision 0)
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+/**
+ * Representation of a collection in a query.
+ * 
+ * @param <T> Java type being represented here
+ * @param <E> Element type of the collection being represented here
+ */
+public interface CollectionExpression<T extends Collection<E>, E> extends Expression<T>
+{
+    /**
+     * Method returning whether the specified elementexpression is contained in this collection.
+     * @param expr The element expression
+     * @return Whether it is contained here
+     */
+    BooleanExpression contains(Expression expr);
+
+    /**
+     * Method returning whether the specified element is contained in this collection.
+     * @param elem The element
+     * @return Whether it is contained here
+     */
+    BooleanExpression contains(E elem);
+
+    /**
+     * Method returning whether the collection is empty.
+     * @return Whether it is empty
+     */
+    BooleanExpression isEmpty();
+
+    /**
+     * Method returning an expression for the size of the collection
+     * @return The size
+     */
+    NumericExpression<Integer> size();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/ComparableExpression.java
===================================================================
--- src/java/javax/jdo/query/ComparableExpression.java	(revision 0)
+++ src/java/javax/jdo/query/ComparableExpression.java	(revision 0)
@@ -0,0 +1,112 @@
+/*
+ * 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 expression for a Java type that implements java.lang.Comparable.
+ * Nore that the methods taking Expression as an argument could have been defined to take
+ * ComparableExpression but that would then have prevented code like
+ * <pre>
+ * NumericExpression param = (NumericExpression)tq.parameter("criticalValue", Double.class);
+ * tq.filter(cand.value.lt(param));
+ * </pre>
+ * and we would have had to cast the parameter to NumericExpression
+ *
+ * @param <T> Java type being represented here
+ */
+public interface ComparableExpression<T> extends Expression<T>
+{
+    /**
+     * Method returning whether this expression is less than the other expression.
+     * @param expr Other expression
+     * @return Whether this is less than the other
+     */
+    BooleanExpression lt(ComparableExpression expr);
+
+    /**
+     * Method returning whether this expression is less than the literal.
+     * @param t literal
+     * @return Whether this is less than the other
+     */
+    BooleanExpression lt(T t);
+
+    /**
+     * Method returning whether this expression is less than or equal the other expression.
+     * @param expr Other expression
+     * @return Whether this is less than or equal the other
+     */
+    BooleanExpression lteq(ComparableExpression expr);
+
+    /**
+     * Method returning whether this expression is less than or equal the literal.
+     * @param t literal
+     * @return Whether this is less than or equal the other
+     */
+    BooleanExpression lteq(T t);
+
+    /**
+     * Method returning whether this expression is greater than the other expression.
+     * @param expr Other expression
+     * @return Whether this is greater than the other
+     */
+    BooleanExpression gt(ComparableExpression expr);
+
+    /**
+     * Method returning whether this expression is greater than the literal.
+     * @param t literal
+     * @return Whether this is greater than the other
+     */
+    BooleanExpression gt(T t);
+
+    /**
+     * Method returning whether this expression is greater than or equal the other expression.
+     * @param expr Other expression
+     * @return Whether this is greater than or equal to the other
+     */
+    BooleanExpression gteq(ComparableExpression expr);
+
+    /**
+     * Method returning whether this expression is greater than or equal the literal.
+     * @param t literal
+     * @return Whether this is greater than or equal to the other
+     */
+    BooleanExpression gteq(T t);
+
+    /**
+     * Method to return a numeric expression representing the aggregated minimum of this expression.
+     * @return Numeric expression for the minimum
+     */
+    NumericExpression min();
+
+    /**
+     * Method to return a numeric expression representing the aggregated maximum of this expression.
+     * @return Numeric expression for the maximum
+     */
+    NumericExpression max();
+
+    /**
+     * Method to return an order expression for this expression in ascending order.
+     * @return The order expression
+     */
+    OrderExpression asc();
+
+    /**
+     * Method to return an order expression for this expression in descending order.
+     * @return The order expression
+     */
+    OrderExpression desc();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/DateExpression.java
===================================================================
--- src/java/javax/jdo/query/DateExpression.java	(revision 0)
+++ src/java/javax/jdo/query/DateExpression.java	(revision 0)
@@ -0,0 +1,43 @@
+/*
+ * 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 a date in a query.
+ * 
+ * @param <T> Date type
+ */
+public interface DateExpression<T> extends TemporalExpression<T>
+{
+    /**
+     * Accessor for the year of this date.
+     * @return Expression for the year
+     */
+    NumericExpression<Integer> getYear();
+
+    /**
+     * Accessor for the month of this date.
+     * @return Expression for the month
+     */
+    NumericExpression<Integer> getMonth();
+
+    /**
+     * Accessor for the day (of the month) of this date.
+     * @return Expression for the day of the month
+     */
+    NumericExpression<Integer> getDay();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/DateTimeExpression.java
===================================================================
--- src/java/javax/jdo/query/DateTimeExpression.java	(revision 0)
+++ src/java/javax/jdo/query/DateTimeExpression.java	(revision 0)
@@ -0,0 +1,61 @@
+/*
+ * 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 a date-time type in a query.
+ * 
+ * @param <T> Date-time type
+ */
+public interface DateTimeExpression<T> extends TemporalExpression<T>
+{
+    /**
+     * Accessor for the year of this date-time.
+     * @return Expression for the year
+     */
+    NumericExpression<Integer> getYear();
+
+    /**
+     * Accessor for the month of this date-time.
+     * @return Expression for the month
+     */
+    NumericExpression<Integer> getMonth();
+
+    /**
+     * Accessor for the day (of the month) of this date-time.
+     * @return Expression for the day of the month
+     */
+    NumericExpression<Integer> getDay();
+
+    /**
+     * Accessor for the hour of this date-time.
+     * @return Expression for the hour
+     */
+    NumericExpression<Integer> getHour();
+
+    /**
+     * Accessor for the minute of this date-time.
+     * @return Expression for the minute
+     */
+    NumericExpression<Integer> getMinute();
+
+    /**
+     * Accessor for the second of this date-time.
+     * @return Expression for the second
+     */
+    NumericExpression<Integer> getSecond();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/EnumExpression.java
===================================================================
--- src/java/javax/jdo/query/EnumExpression.java	(revision 0)
+++ src/java/javax/jdo/query/EnumExpression.java	(revision 0)
@@ -0,0 +1,31 @@
+/*
+ * 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 Enum in a query.
+ * 
+ * @param <T> Enum type
+ */
+public interface EnumExpression<T> extends ComparableExpression<Enum>
+{
+    /**
+     * Method to return an expression for the ordinal of this enum.
+     * @return Expression for the ordinal of the passed enum
+     */
+    NumericExpression ordinal();
+}
Index: src/java/javax/jdo/query/Expression.java
===================================================================
--- src/java/javax/jdo/query/Expression.java	(revision 0)
+++ src/java/javax/jdo/query/Expression.java	(revision 0)
@@ -0,0 +1,79 @@
+/*
+ * 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 expression in a query.
+ * 
+ * @param <T> Java type being represented here
+ */
+public interface Expression<T>
+{
+    /**
+     * Method returning whether this expression equals the other expression.
+     * @param expr Other expression
+     * @return Whether they are equal
+     */
+    BooleanExpression eq(Expression expr);
+
+    /**
+     * Method returning whether this expression equals the literal.
+     * @param t Literal
+     * @return Whether they are equal
+     */
+    BooleanExpression eq(T t);
+
+    /**
+     * Method returning whether this expression doesn't equal the other expression.
+     * @param expr Other expression
+     * @return Whether they are not equal
+     */
+    BooleanExpression ne(Expression expr);
+
+    /**
+     * Method returning whether this expression doesn't equal the literal.
+     * @param t literal
+     * @return Whether they are not equal
+     */
+    BooleanExpression ne(T t);
+
+    /**
+     * Method to return a numeric expression representing the aggregated count of this expression.
+     * @return Numeric expression for the count
+     */
+    NumericExpression<Long> count();
+
+    /**
+     * Method to return a numeric expression representing the aggregated (distinct) count of this expression.
+     * @return Numeric expression for the distinct count
+     */
+    NumericExpression<Long> countDistinct();
+
+    /**
+     * Return an expression for whether this expression is an instanceof the supplied class.
+     * @param cls Class to check against
+     * @return Whether it is an instanceof
+     */
+    BooleanExpression instanceOf(Class cls);
+
+    /**
+     * Return an expression where this expression is cast to the specified type.
+     * @param cls Class to cast to
+     * @return The cast expression
+     */
+    Expression cast(Class cls);
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/ListExpression.java
===================================================================
--- src/java/javax/jdo/query/ListExpression.java	(revision 0)
+++ src/java/javax/jdo/query/ListExpression.java	(revision 0)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import java.util.List;
+
+/**
+ * Representation of a List in a query.
+ * 
+ * @param <T> Java type being represented here
+ * @param <E> Element type of the List being represented here
+ */
+public interface ListExpression<T extends List<E>, E> extends CollectionExpression<T, E>
+{
+    /**
+     * Method returning the element at this position in the List.
+     * @param posExpr The position expression
+     * @return The element at this position in the List
+     */
+    Expression get(NumericExpression<Integer> posExpr);
+
+    /**
+     * Method returning the element at this position in the List.
+     * @param pos The position
+     * @return The element at this position in the List
+     */
+    Expression get(int pos);
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/MapExpression.java
===================================================================
--- src/java/javax/jdo/query/MapExpression.java	(revision 0)
+++ src/java/javax/jdo/query/MapExpression.java	(revision 0)
@@ -0,0 +1,83 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+/**
+ * Representation of a map in a query.
+ * 
+ * @param <T> Java type being represented here
+ * @param <K> Key type of the map being represented here
+ * @param <V> Value type of the map being represented here
+ */
+public interface MapExpression<T extends Map<K, V>, K, V> extends Expression<T>
+{
+    /**
+     * Method returning whether the specified key expression is contained in this map.
+     * @param expr The key expression
+     * @return Whether it is contained here
+     */
+    BooleanExpression containsKey(Expression expr);
+
+    /**
+     * Method returning whether the specified key is contained in this map.
+     * @param key The key
+     * @return Whether it is contained here
+     */
+    BooleanExpression containsKey(K key);
+
+    /**
+     * Method returning whether the specified value expression is contained in this map.
+     * @param expr The value expression
+     * @return Whether it is contained here
+     */
+    BooleanExpression containsValue(Expression expr);
+
+    /**
+     * Method returning whether the specified value is contained in this map.
+     * @param value The value
+     * @return Whether it is contained here
+     */
+    BooleanExpression containsValue(V value);
+
+    /**
+     * Method returning whether the specified entry expression is contained in this map.
+     * @param expr The entry expression
+     * @return Whether it is contained here
+     */
+    BooleanExpression containsEntry(Expression expr);
+
+    /**
+     * Method returning whether the specified entry is contained in this map.
+     * @param entry The entry expression
+     * @return Whether it is contained here
+     */
+    BooleanExpression containsEntry(Map.Entry<K, V> entry);
+
+    /**
+     * Method returning whether the map is empty.
+     * @return Whether it is empty
+     */
+    BooleanExpression isEmpty();
+
+    /**
+     * Method returning an expression for the size of the map
+     * @return The size
+     */
+    NumericExpression<Integer> size();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/NumericExpression.java
===================================================================
--- src/java/javax/jdo/query/NumericExpression.java	(revision 0)
+++ src/java/javax/jdo/query/NumericExpression.java	(revision 0)
@@ -0,0 +1,179 @@
+/*
+ * 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 a numeric expression.
+ * 
+ * @param <T> Number type
+ */
+public interface NumericExpression<T> extends ComparableExpression<Number>
+{
+    /**
+     * Method to return an expression for this expression added to the passed expression.
+     * @param expr The other expression
+     * @return The summation
+     */
+    NumericExpression add(Expression expr);
+
+    /**
+     * Method to return an expression for this expression added to the passed number.
+     * @param num Number to add
+     * @return The summation
+     */
+    NumericExpression add(Number num);
+
+    /**
+     * Method to return an expression for this expression subtracting the passed expression.
+     * @param expr The other expression
+     * @return The difference
+     */
+    NumericExpression sub(Expression expr);
+
+    /**
+     * Method to return an expression for this expression subtracting the passed number.
+     * @param num Number to subtract
+     * @return The difference
+     */
+    NumericExpression sub(Number num);
+
+    /**
+     * Method to return an expression for this expression multiplied by the passed expression.
+     * @param expr The other expression
+     * @return The multiplication
+     */
+    NumericExpression mul(Expression expr);
+
+    /**
+     * Method to return an expression for this expression multiplied by the passed number.
+     * @param num Number
+     * @return The multiplication
+     */
+    NumericExpression mul(Number num);
+
+    /**
+     * Method to return an expression for this expression divided by the passed expression.
+     * @param expr The other expression
+     * @return The division
+     */
+    NumericExpression div(Expression expr);
+
+    /**
+     * Method to return an expression for this expression divided by the passed number.
+     * @param num Number to divide by
+     * @return The division
+     */
+    NumericExpression div(Number num);
+
+    /**
+     * Method to return an expression for this expression modulus the passed expression (<pre>a % b</pre>).
+     * @param expr The other expression
+     * @return The modulus
+     */
+    NumericExpression mod(Expression expr);
+
+    /**
+     * Method to return an expression for this expression modulus the passed number.
+     * @param num Number
+     * @return The modulus
+     */
+    NumericExpression mod(Number num);
+
+    /**
+     * Method to return a numeric expression representing the aggregated average of this expression.
+     * @return Numeric expression for the average
+     */
+    NumericExpression avg();
+
+    /**
+     * Method to return a numeric expression representing the aggregated sum of this expression.
+     * @return Numeric expression for the sum
+     */
+    NumericExpression sum();
+
+    /**
+     * Method to return the absolute value expression of this expression.
+     * @return The absolute value expression
+     */
+    NumericExpression abs();
+
+    /**
+     * Method to return the square-root value expression of this expression.
+     * @return The square-root value expression
+     */
+    NumericExpression sqrt();
+
+    /**
+     * Method to return the arc cosine value expression of this expression.
+     * @return The arc cosine value expression
+     */
+    NumericExpression acos();
+
+    /**
+     * Method to return the arc sine value expression of this expression.
+     * @return The arc sine value expression
+     */
+    NumericExpression asin();
+
+    /**
+     * Method to return the arc tangent value expression of this expression.
+     * @return The arc tangent value expression
+     */
+    NumericExpression atan();
+
+    /**
+     * Method to return the sine value expression of this expression.
+     * @return The sine value expression
+     */
+    NumericExpression sin();
+
+    /**
+     * Method to return the cosine value expression of this expression.
+     * @return The cosine value expression
+     */
+    NumericExpression cos();
+
+    /**
+     * Method to return the tangent value expression of this expression.
+     * @return The tangent value expression
+     */
+    NumericExpression tan();
+
+    /**
+     * Method to return the exponential value expression of this expression.
+     * @return The exponential value expression
+     */
+    NumericExpression exp();
+
+    /**
+     * Method to return the logarithm value expression of this expression.
+     * @return The logarithm value expression
+     */
+    NumericExpression log();
+
+    /**
+     * Method to return the ceiling value expression of this expression.
+     * @return The ceiling value expression
+     */
+    NumericExpression ceil();
+
+    /**
+     * Method to return the floor value expression of this expression.
+     * @return The floor value expression
+     */
+    NumericExpression floor();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/ObjectExpression.java
===================================================================
--- src/java/javax/jdo/query/ObjectExpression.java	(revision 0)
+++ src/java/javax/jdo/query/ObjectExpression.java	(revision 0)
@@ -0,0 +1,28 @@
+/*
+ * 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 Object as an expression.
+ * This handles all remaining Java types not handled by String, Numeric, Enum, Boolean, Collection, Map, etc.
+ * 
+ * @param <T> Java type
+ */
+public interface ObjectExpression<T> extends Expression<T>
+{
+
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/OrderExpression.java
===================================================================
--- src/java/javax/jdo/query/OrderExpression.java	(revision 0)
+++ src/java/javax/jdo/query/OrderExpression.java	(revision 0)
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+/**
+ * Expression representing the ordering using an expression and a direction.
+ * 
+ * @param <T> Java type of the expression being represented here
+ */
+public interface OrderExpression<T>
+{
+    public enum OrderDirection
+    {
+        ASC,
+        DESC
+    }
+
+    /**
+     * Accessor for the direction of the ordering with this expression.
+     * @return The direction
+     */
+    OrderDirection getDirection();
+
+    /**
+     * Accessor for the expression being used for ordering.
+     * @return Ordering expression
+     */
+    Expression<T> getExpression();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/PersistableExpression.java
===================================================================
--- src/java/javax/jdo/query/PersistableExpression.java	(revision 0)
+++ src/java/javax/jdo/query/PersistableExpression.java	(revision 0)
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+/**
+ * Expression representing a persistable object in a query (e.g alias.persistableField).
+ *
+ * @param <T> (Persistable) Java type being represented here
+ */
+public interface PersistableExpression<T> extends Expression<T>
+{
+    /**
+     * Method to return an expression for the identity of this persistable object.
+     * TODO Only applicable to JDOQL so move to language specific interface
+     * @return The identity expression
+     */
+    Expression jdoObjectId();
+
+    /**
+     * Method to return an expression for the version of this persistable object.
+     * TODO Only applicable to JDOQL so move to language specific interface
+     * @return The version expression
+     */
+    Expression jdoVersion();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/StringExpression.java
===================================================================
--- src/java/javax/jdo/query/StringExpression.java	(revision 0)
+++ src/java/javax/jdo/query/StringExpression.java	(revision 0)
@@ -0,0 +1,188 @@
+/*
+ * 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 a string in a query.
+ */
+public interface StringExpression extends ComparableExpression<String>
+{
+    /**
+     * Method to return an expression for this expression added to the passed expression (String concatenation).
+     * @param expr The other expression
+     * @return The summation
+     */
+    StringExpression add(Expression expr);
+
+    /**
+     * Method to return an expression for the character at a position of this string expression.
+     * @param pos The position
+     * @return Expression for the character
+     */
+    CharacterExpression charAt(int pos);
+
+    /**
+     * Method to return an expression for the character at a position of this string expression.
+     * @param pos The position
+     * @return Expression for the character
+     */
+    CharacterExpression charAt(NumericExpression pos);
+
+    /**
+     * Method returning an expression for whether this string expression ends with the passed string expression.
+     * @param expr The expression that it ends with.
+     * @return Whether it ends with the other string
+     */
+    BooleanExpression endsWith(StringExpression expr);
+
+    /**
+     * Method returning an expression for whether this string expression ends with the passed string expression.
+     * @param str The string that it ends with.
+     * @return Whether it ends with the other string
+     */
+    BooleanExpression endsWith(String str);
+
+    /**
+     * Method returning an expression for whether this string expression is equal to (ignoring case) the 
+     * passed string expression.
+     * @param expr The expression
+     * @return Whether they are equal
+     */
+    BooleanExpression equalsIgnoreCase(StringExpression expr);
+
+    /**
+     * Method returning an expression for whether this string expression is equal to (ignoring case) the 
+     * passed string.
+     * @param str The string
+     * @return Whether they are equal
+     */
+    BooleanExpression equalsIgnoreCase(String str);
+
+    /**
+     * Method to return an expression for the position of the passed string in this string.
+     * @param expr The other string
+     * @return Expression for the position of the passed string
+     */
+    NumericExpression indexOf(StringExpression expr);
+
+    /**
+     * Method to return an expression for the position of the passed string in this string.
+     * @param str The other string
+     * @return Expression for the position of the passed string
+     */
+    NumericExpression indexOf(String str);
+
+    /**
+     * Method to return an expression for the position of the passed string in this string after a position.
+     * @param expr The other string
+     * @param pos Start point of the search
+     * @return Expression for the position of the passed string
+     */
+    NumericExpression indexOf(StringExpression expr, NumericExpression pos);
+
+    /**
+     * Method to return an expression for the position of the passed string in this string after a position.
+     * @param str The other string
+     * @param pos Start point of the search
+     * @return Expression for the position of the passed string
+     */
+    NumericExpression indexOf(String str, NumericExpression pos);
+
+    /**
+     * Method to return an expression for the position of the passed string in this string after a position.
+     * @param str The other string
+     * @param pos Start point of the search
+     * @return Expression for the position of the passed string
+     */
+    NumericExpression indexOf(String str, int pos);
+
+    /**
+     * Method to return an expression for the position of the passed string in this string after a position.
+     * @param expr The other string
+     * @param pos Start point of the search
+     * @return Expression for the position of the passed string
+     */
+    NumericExpression indexOf(StringExpression expr, int pos);
+
+    /**
+     * Method returning a expression for the length of this string.
+     * @return Expression for the length
+     */
+    NumericExpression length();
+
+    /**
+     * Method returning an expression for whether this string expression starts with the passed string expression.
+     * @param expr The expression that it starts with.
+     * @return Whether it starts with the other string
+     */
+    BooleanExpression startsWith(StringExpression expr);
+
+    /**
+     * Method returning an expression for whether this string expression starts with the passed string.
+     * @param str The string that it starts with.
+     * @return Whether it starts with the other string
+     */
+    BooleanExpression startsWith(String str);
+
+    /**
+     * Method to return an expression for the substring of this string expression.
+     * @param pos The position of the start point of the substring
+     * @return Expression for the substring
+     */
+    StringExpression substring(NumericExpression pos);
+
+    /**
+     * Method to return an expression for the substring of this string expression.
+     * @param pos The position of the start point of the substring
+     * @return Expression for the substring
+     */
+    StringExpression substring(int pos);
+
+    /**
+     * Method to return an expression for the substring of this string expression.
+     * @param startPos The position of the start point of the substring (inclusive, origin 0)
+     * @param endPos The position of the end point of the substring (exclusive, origin 0)
+     * @return Expression for the substring
+     */
+    StringExpression substring(NumericExpression startPos, NumericExpression endPos);
+
+    /**
+     * Method to return an expression for the substring of this string expression.
+     * @param startPos The position of the start point of the substring (inclusive, origin 0)
+     * @param endPos The position of the end point of the substring (exclusive, origin 0)
+     * @return Expression for the substring
+     */
+    StringExpression substring(int startPos, int endPos);
+
+    /**
+     * Method to return a StringExpression representing this string expression in lower case.
+     * @return The lower case expression
+     */
+    StringExpression toLowerCase();
+
+    /**
+     * Method to return a StringExpression representing this string expression in upper case.
+     * @return The upper case expression
+     */
+    StringExpression toUpperCase();
+
+    /**
+     * Method returning a string expression with whitespace trimmed from start and end.
+     * @return String expression with whitespace trimmed
+     */
+    StringExpression trim();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/SubqueryExpression.java
===================================================================
--- src/java/javax/jdo/query/SubqueryExpression.java	(revision 0)
+++ src/java/javax/jdo/query/SubqueryExpression.java	(revision 0)
@@ -0,0 +1,25 @@
+/*
+ * 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 a subquery in a query.
+ */
+public interface SubqueryExpression
+{
+
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/TemporalExpression.java
===================================================================
--- src/java/javax/jdo/query/TemporalExpression.java	(revision 0)
+++ src/java/javax/jdo/query/TemporalExpression.java	(revision 0)
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import java.util.Date;
+
+/**
+ * Representation of a temporal type in a query.
+ * 
+ * @param <T> Temporal type
+ */
+public interface TemporalExpression<T> extends ComparableExpression<Date>
+{
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/TimeExpression.java
===================================================================
--- src/java/javax/jdo/query/TimeExpression.java	(revision 0)
+++ src/java/javax/jdo/query/TimeExpression.java	(revision 0)
@@ -0,0 +1,43 @@
+/*
+ * 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 a time in a query.
+ * 
+ * @param <T> time type
+ */
+public interface TimeExpression<T> extends TemporalExpression<T>
+{
+    /**
+     * Accessor for the hour of this time.
+     * @return Expression for the hour
+     */
+    NumericExpression<Integer> getHour();
+
+    /**
+     * Accessor for the minute of this time.
+     * @return Expression for the minute
+     */
+    NumericExpression<Integer> getMinute();
+
+    /**
+     * Accessor for the second of this time.
+     * @return Expression for the second
+     */
+    NumericExpression<Integer> getSecond();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/TypesafeQuery.java
===================================================================
--- src/java/javax/jdo/query/TypesafeQuery.java	(revision 0)
+++ src/java/javax/jdo/query/TypesafeQuery.java	(revision 0)
@@ -0,0 +1,368 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import javax.jdo.FetchPlan;
+import javax.jdo.PersistenceManager;
+
+/**
+ * Interface for a type-safe query, using a fluent API.
+ * Designed to handle JDO query requirements as a whole.
+ */
+public interface TypesafeQuery<T>
+{
+    public static final String QUERY_CLASS_PREFIX = "Q";
+
+    /**
+     * Method to return an expression for the candidate of the query.
+     * Cast the returned expression to the candidate "Q" type to be able to call methods on it.
+     * This calls the method "Q{type}.candidate(null)"
+     * The preference is to use the "Q{type}.candidate()" method for real type-safe handling.
+     * @return Expression for the candidate
+     */
+    PersistableExpression candidate();
+
+    /**
+     * Method to return a parameter for the query.
+     * Cast the returned parameter to the right type to be able to call methods on it.
+     * The preference is to use the "xxxParameter(String)" methods for real type-safe handling.
+     * @param name Name of the parameter
+     * @param type Java type of the parameter
+     * @return Expression for the parameter
+     */
+    Expression parameter(String name, Class type);
+
+    /**
+     * Method to return a string parameter for the query.
+     * @param name Name of the parameter
+     * @return StringExpression for the parameter
+     */
+    StringExpression stringParameter(String name);
+
+    /**
+     * Method to return a character parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    CharacterExpression characterParameter(String name);
+
+    /**
+     * Method to return a numeric parameter for the query.
+     * @param name Name of the parameter
+     * @return NumericExpression for the parameter
+     */
+    NumericExpression<Long> longParameter(String name);
+
+    /**
+     * Method to return a numeric parameter for the query.
+     * @param name Name of the parameter
+     * @return NumericExpression for the parameter
+     */
+    NumericExpression<Integer> integerParameter(String name);
+
+    /**
+     * Method to return a numeric parameter for the query.
+     * @param name Name of the parameter
+     * @return NumericExpression for the parameter
+     */
+    NumericExpression<Short> shortParameter(String name);
+
+    /**
+     * Method to return a numeric parameter for the query.
+     * @param name Name of the parameter
+     * @return NumericExpression for the parameter
+     */
+    NumericExpression<Double> doubleParameter(String name);
+
+    /**
+     * Method to return a numeric parameter for the query.
+     * @param name Name of the parameter
+     * @return NumericExpression for the parameter
+     */
+    NumericExpression<Float> floatParameter(String name);
+
+    /**
+     * Method to return a date parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    DateExpression<java.sql.Date> dateParameter(String name);
+
+    /**
+     * Method to return a time parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    TimeExpression<java.sql.Time> timeParameter(String name);
+
+    /**
+     * Method to return a datetime parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    DateTimeExpression<Date> datetimeParameter(String name);
+
+    /**
+     * Method to return a collection parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    CollectionExpression collectionParameter(String name);
+
+    /**
+     * Method to return a map parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    MapExpression mapParameter(String name);
+
+    /**
+     * Method to return a list parameter for the query.
+     * @param name Name of the parameter
+     * @return Expression for the parameter
+     */
+    ListExpression listParameter(String name);
+
+    /**
+     * Method to return a variable for this query.
+     * Cast the returned variable to the right type to be able to call methods on it.
+     * @param name Name of the variable
+     * @param type Type of the variable
+     * @return Expression for the variable
+     */
+    Expression variable(String name, Class type);
+
+    /**
+     * Accessor for the PersistenceManager for this query
+     * @return The PersistenceManager
+     */
+    PersistenceManager getPersistenceManager();
+
+    /**
+     * Accessor for the FetchPlan for this query
+     * @return The FetchPlan
+     */
+    FetchPlan getFetchPlan();
+
+    /**
+     * Whether the query should ignore the cache and go straight to the datastore.
+     * @param ignore Ignore the cache flag
+     * @return The query
+     */
+    TypesafeQuery<T> setIgnoreCache(boolean ignore);
+
+    /**
+     * Method to set the candidates to use over which we are querying.
+     * If no candidates are set then the query is performed on the datastore.
+     * @param candidates The candidates
+     * @return The query
+     */
+    TypesafeQuery<T> setCandidates(Collection<T> candidates);
+
+    /**
+     * Method to remove subclasses (of the candidate) from the query
+     * @return The query
+     */
+    TypesafeQuery<T> excludeSubclasses();
+
+    /**
+     * Method to include subclasses (of the candidate) to the query
+     * @return The query
+     */
+    TypesafeQuery<T> includeSubclasses();
+
+    /**
+     * Method to set the filter of the query.
+     * @param expr Filter expression
+     * @return The query
+     */
+    TypesafeQuery<T> filter(BooleanExpression expr);
+
+    /**
+     * Method to set the grouping(s) for the query.
+     * @param exprs Grouping expression(s)
+     * @return The query
+     */
+    TypesafeQuery<T> groupBy(Expression... exprs);
+
+    /**
+     * Method to set the having clause of the query.
+     * @param expr Having expression
+     * @return The query
+     */
+    TypesafeQuery<T> having(Expression expr);
+
+    /**
+     * Method to set the ordering of the query.
+     * @param orderExprs Ordering expression(s)
+     * @return The query
+     */
+    TypesafeQuery<T> orderBy(OrderExpression... orderExprs);
+
+    /**
+     * Method to set the range of any required results, using expressions.
+     * @param lowerInclExpr The position of the first result (inclusive)
+     * @param upperExclExpr The position of the last result (exclusive)
+     * @return The query
+     */
+    TypesafeQuery<T> range(NumericExpression lowerInclExpr, NumericExpression upperExclExpr);
+
+    /**
+     * Method to set the range of any required results, using long values.
+     * @param lowerIncl The position of the first result (inclusive)
+     * @param upperExcl The position of the last result (exclusive)
+     * @return The query
+     */
+    TypesafeQuery<T> range(long lowerIncl, long upperExcl);
+
+    /**
+     * Method to set the range of any required results, using parameters (expressions).
+     * @param paramLowerInclExpr Expression for a parameter defining the position of the first result (inclusive)
+     * @param paramUpperExclExpr Expression for a parameter defining the position of the last result (exclusive)
+     * @return The query
+     */
+    TypesafeQuery<T> range(Expression paramLowerInclExpr, Expression paramUpperExclExpr);
+
+    /**
+     * Method to return a subquery for use in this query using the same candidate class as this query.
+     * To obtain the expression for the subquery to link it back to this query, call "result(...)" on the subquery.
+     * @param candidateAlias Alias for the candidate
+     * @return The subquery
+     */
+    TypesafeSubquery<T> subquery(String candidateAlias);
+
+    /**
+     * Method to return a subquery for use in this query.
+     * To obtain the expression for the subquery to link it back to this query, call "result(...)" on the subquery.
+     * @param candidateClass Candidate for the subquery
+     * @param candidateAlias Alias for the candidate
+     * @return The subquery
+     */
+    <S> TypesafeSubquery<S> subquery(Class<S> candidate, String candidateAlias);
+
+    /**
+     * Method to set a parameter value for use when executing the query.
+     * @param paramExpr Parameter expression
+     * @param value The value
+     * @return The query
+     */
+    TypesafeQuery<T> setParameter(Expression paramExpr, Object value);
+
+    /**
+     * Method to set a parameter value for use when executing the query.
+     * @param paramName Parameter name
+     * @param value The value
+     * @return The query
+     */
+    TypesafeQuery<T> setParameter(String paramName, Object value);
+
+    /**
+     * Add a vendor-specific extension to this query. The key and value are not standard.
+     * An implementation must ignore keys that are not recognized.
+     * @param key the key of the extension
+     * @param value the value of the extension
+     * @return The query
+     */
+    TypesafeQuery<T> addExtension (String key, Object value);
+
+    /**
+     * Set multiple extensions, or use null to clear all extensions. Map keys and values are not standard.
+     * @param extensions the map of extensions
+     * @return The query
+     * @see #addExtension
+     */
+    TypesafeQuery<T> setExtensions (Map<String, Object> extensions);
+
+    /**
+     * Method to execute the query where there are (potentially) multiple rows and we are returning
+     * the candidate type.
+     * @return The results
+     */
+    List<T> executeList();
+
+    /**
+     * Method to execute the query where there is a single row and we are returning the candidate type.
+     * @return The result
+     */
+    T executeUnique();
+
+    /**
+     * Method to execute the query where there are (potentially) multiple rows and we are returning either a
+     * result type or the candidate type.
+     * @param resultCls Result class
+     * @param distinct Whether to provide distinct results
+     * @param exprs Result expression(s)
+     * @return The results
+     */
+    <R> List<R> executeResultList(Class<R> resultCls, boolean distinct, Expression... exprs);
+
+    /**
+     * Method to execute the query where there is a single row and we are returning either a result type
+     * or the candidate type.
+     * @param resultCls Result class
+     * @param distinct Whether to provide distinct results
+     * @param exprs Result expression(s)
+     * @return The result
+     */
+    <R> R executeResultUnique(Class<R> resultCls, boolean distinct, Expression... exprs);
+
+    /**
+     * Method to execute the query where there are (potentially) multiple rows and we have a result defined
+     * but no result class.
+     * @param distinct Whether to provide distinct results
+     * @param exprs Result expression(s)
+     * @return The results
+     */
+    List<Object[]> executeResultList(boolean distinct, Expression... exprs);
+
+    /**
+     * Method to execute the query where there is a single row and we have a result defined
+     * but no result class.
+     * @param distinct Whether to provide distinct results
+     * @param exprs Result expression(s)
+     * @return The results
+     */
+    Object[] executeResultUnique(boolean distinct, Expression... exprs);
+
+    /**
+     * Method to execute the query deleting the affected instances.
+     * @return The number of objects deleted
+     */
+    long deletePersistentAll();
+
+    /**
+     * Method to close the specified query result.
+     * @param result The result
+     */
+    void close(Object result);
+
+    /**
+     * Method to close all query results from this query.
+     */
+    void closeAll();
+
+    /**
+     * Method to return the equivalent String form of this query (if applicable for the query language).
+     * @return The single-string form of this query
+     */
+    String toString();
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/TypesafeSubquery.java
===================================================================
--- src/java/javax/jdo/query/TypesafeSubquery.java	(revision 0)
+++ src/java/javax/jdo/query/TypesafeSubquery.java	(revision 0)
@@ -0,0 +1,104 @@
+/*
+ * 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;
+
+/**
+ * Interface for a type-safe subquery, using a fluent API.
+ * Users should call methods on the subquery instance and end with a select of what the subquery returns; this
+ * returns the expression that they use to link it with the owning query.
+ * 
+ * <T> (Candidate) type being represented
+ */
+public interface TypesafeSubquery<T>
+{
+    /**
+     * Method to return an expression for the candidate of the subquery.
+     * Cast the returned expression to the candidate "Q" type to be able to call methods on it.
+     * @return Expression for the candidate
+     */
+    PersistableExpression candidate();
+
+    /**
+     * Method to set the filter of the query.
+     * @param expr Filter expression
+     * @return The query
+     */
+    TypesafeSubquery filter(BooleanExpression expr);
+
+    /**
+     * Method to set the grouping(s) for the query.
+     * @param exprs Grouping expression(s)
+     * @return The query
+     */
+    TypesafeSubquery groupBy(Expression... exprs);
+
+    /**
+     * Method to set the having clause of the query.
+     * @param expr Having expression
+     * @return The query
+     */
+    TypesafeSubquery having(Expression expr);
+
+    /**
+     * Accessor for the subquery (numeric) expression from the subquery when the subquery returns a single value.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    <S> NumericExpression<S> selectUnique(NumericExpression<S> expr);
+
+    /**
+     * Accessor for the subquery (string) expression from the subquery when the subquery returns a single value.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    StringExpression selectUnique(StringExpression expr);
+
+    /**
+     * Accessor for the subquery (date) expression from the subquery when the subquery returns a single value.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    <S> DateExpression<S> selectUnique(DateExpression<S> expr);
+
+    /**
+     * Accessor for the subquery (datetime) expression from the subquery when the subquery returns a single value.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    <S> DateTimeExpression<S> selectUnique(DateTimeExpression<S> expr);
+
+    /**
+     * Accessor for the subquery (time) expression from the subquery when the subquery returns a single value.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    <S> TimeExpression<S> selectUnique(TimeExpression<S> expr);
+
+    /**
+     * Accessor for the subquery (character) expression from the subquery when the subquery returns a single value.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    CharacterExpression selectUnique(CharacterExpression expr);
+
+    /**
+     * Accessor for the subquery (collection) expression from the subquery.
+     * @param expr The expression
+     * @return Expression for the typesafe query
+     */
+    CollectionExpression select(CollectionExpression expr);
+}
\ No newline at end of file
Index: src/java/javax/jdo/query/package.html
===================================================================
--- src/java/javax/jdo/query/package.html	(revision 0)
+++ src/java/javax/jdo/query/package.html	(revision 0)
@@ -0,0 +1,19 @@
+<BODY>
+    Package providing a typesafe query mechanism.
+    Fields/Params/Vars of a persistable type are represented as <i>PathExpression</i>. 
+	This type is extended by all "query" classes, to provide access to persistable fields.
+    Fields/Params/Vars of a container type are represented as <i>CollectionExpression</i>, 
+	<i>MapExpression</i>. Fields/Params/Vars of other types, or literals are represented by
+    <ul>
+        <li>StringExpression</li>
+        <li>EnumExpression</li>
+        <li>NumericExpression</li>
+        <li>BooleanExpression</li>
+        <li>ByteExpression</li>
+        <li>CharacterExpression</li>
+        <li>DateTimeExpression</li>
+        <li>DateExpression</li>
+        <li>TimeExpression</li>
+        <li>ObjectExpression</li>
+    </ul>
+</BODY>
\ No newline at end of file
