openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r813514 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/...
Date Thu, 10 Sep 2009 16:58:46 GMT
Author: ppoddar
Date: Thu Sep 10 16:58:44 2009
New Revision: 813514

URL: http://svn.apache.org/viewvc?rev=813514&view=rev
Log:
OPENJPA-1288: alias() first version. Assumes in-place change and does not create new instance.
Retired TupleElementImpl.

Removed:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/TupleElementImpl.java
    openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/TestTupleImpl.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/AliasContext.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaExpression.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/CriteriaTest.java
Thu Sep 10 16:58:44 2009
@@ -76,7 +76,7 @@
         CriteriaTest.auditor = auditor;
     }
 
-    protected CriteriaBuilder getCriteriaBuilder() {
+    protected OpenJPACriteriaBuilder getCriteriaBuilder() {
         return cb;
     }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestMetaModelTypesafeCriteria.java
Thu Sep 10 16:58:44 2009
@@ -224,8 +224,8 @@
         Root<Customer> c = q.from(Customer.class);
         Join<Customer, Order> o = c.join(customer_.getSet("orders", Order.class));
         Join<Customer, Address> a = c.join(customer_.getSingularAttribute("address",
Address.class));
-        Expression<Double> taxedCost = cb.prod(o.get(order_.getSingularAttribute("totalCost",
Double.class)), 1.08);
-        taxedCost.alias("taxedCost");
+        Expression<Double> taxedCost = (Expression<Double>)cb.prod(o.get(order_.getSingularAttribute("totalCost",

+                Double.class)), 1.08).alias("taxedCost");
         q.where(cb.equal(a.get(address_.getSingularAttribute("state", String.class)), "CA"),

                 cb.equal(a.get(address_.getSingularAttribute("county", String.class)), "Santa
Clara"));
         q.multiselect(o.get(order_.getSingularAttribute("quantity", Integer.class)),
@@ -550,8 +550,8 @@
         Root<Customer> c = q.from(Customer.class);
         Join<Customer, Order> o = c.join(customer_.getSet("orders",  Order.class));
         Join<Customer, Address> a = c.join(customer_.getSingularAttribute("address",
Address.class));
-        Expression<Double> taxedCost = cb.prod(o.get(order_.getSingularAttribute("totalCost",
Double.class)), 1.08);
-        taxedCost.alias("taxedCost");
+        Expression<Double> taxedCost = (Expression<Double>)cb.prod(o.get(order_.getSingularAttribute("totalCost",

+                Double.class)), 1.08).alias("taxedCost");
         q.where(cb.equal(a.get(address_.getSingularAttribute("state", String.class)), "CA"),

                 cb.equal(a.get(address_.getSingularAttribute("county", String.class)), "Santa
Clara"));
         q.orderBy(cb.asc(o.get(order_.getSingularAttribute("quantity", Integer.class))),

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestStringCriteria.java
Thu Sep 10 16:58:44 2009
@@ -29,6 +29,7 @@
 import javax.persistence.criteria.ListJoin;
 import javax.persistence.criteria.MapJoin;
 import javax.persistence.criteria.ParameterExpression;
+import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.SetJoin;
 import javax.persistence.criteria.Subquery;
@@ -41,6 +42,7 @@
         String jpql = "select c from Customer c where c.name='Autowest Toyota'";
         CriteriaQuery<Customer> q = cb.createQuery(Customer.class);
         Root<Customer> customer = q.from(Customer.class);
+        Path<String> path = customer.<String>get("name");
         q.select(customer).where(cb.equal(customer.get("name"), "Autowest Toyota"));
 
         assertEquivalence(q, jpql);
@@ -138,8 +140,8 @@
         SetJoin<Customer, Order> o = c.joinSet("orders");
         Join<Customer, Address> a  = c.join("address");
         q.where(cb.equal(a.get("state"), "CA"), cb.equal(a.get("county"), "Santa Clara"));
-        Expression<Float> productTerm = cb.toFloat(cb.prod(o.get("totalCost").as(Float.class),
1.08));
-        productTerm.alias("taxedCost");
+        Expression<Float> productTerm = (Expression<Float>)cb.toFloat(cb.prod(o.get("totalCost").as(Float.class),
1.08))
+           .alias("taxedCost");
         q.multiselect(o.get("quantity"), productTerm, a.get("zipCode"));
 
         assertEquivalence(q, jpql);
@@ -387,8 +389,8 @@
         SetJoin<Customer, Order> o = c.joinSet("orders");
         Join<Customer, Address> a = c.join("address");
         q.where(cb.equal(a.get("state"), "CA"), cb.equal(a.get("county"), "Santa Clara"));
-        Expression<Float> productTerm = cb.toFloat(cb.prod(o.get("totalCost").as(Float.class),
1.08));
-        productTerm.alias("taxedCost");
+        Expression<Float> productTerm = (Expression<Float>)cb.toFloat(cb.prod(o.get("totalCost").as(Float.class),
1.08))
+            .alias("taxedCost");
         q.orderBy(cb.asc(o.get("quantity")), cb.asc(productTerm), cb.asc(a.get("zipCode")));
         q.multiselect(o.get("quantity"), productTerm, a.get("zipCode"));
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypeSafeCondExpression.java
Thu Sep 10 16:58:44 2009
@@ -789,5 +789,4 @@
         
         assertEquivalence(q, query);
     }
-
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/TestTypesafeCriteria.java
Thu Sep 10 16:58:44 2009
@@ -34,6 +34,7 @@
 import javax.persistence.criteria.MapJoin;
 import javax.persistence.criteria.ParameterExpression;
 import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Selection;
 import javax.persistence.criteria.SetJoin;
 import javax.persistence.criteria.Subquery;
 
@@ -806,8 +807,7 @@
         Root<Customer> c = q.from(Customer.class);
         Join<Customer, Order> o = c.join(Customer_.orders);
         Join<Customer, Address> a = c.join(Customer_.address);
-        Expression<Double> taxedCost = cb.prod(o.get(Order_.totalCost), 1.08);
-        taxedCost.alias("taxedCost");
+        Expression<Double> taxedCost = (Expression<Double>)cb.prod(o.get(Order_.totalCost),
1.08).alias("taxedCost");
         q.where(cb.equal(a.get(Address_.state), "CA"), 
                 cb.equal(a.get(Address_.county), "Santa Clara"));
         q.orderBy(cb.asc(o.get(Order_.quantity)), 
@@ -1260,4 +1260,19 @@
             assertEquals(jResult.get(i).getName(), cResult.get(i).getName());
         }
     }
+    
+    public void testAlias() {
+        String jpql = "SELECT AVG(a.balance) AS x FROM Account a ORDER BY x";
+
+        OpenJPACriteriaQuery<Double> c = cb.createQuery(Double.class);
+        Root<Account> account = c.from(Account.class);
+        Expression<Double> original = cb.avg(account.get(Account_.balance));
+        Expression<Double> aliased = (Expression<Double>)original.alias("x");
+        c.orderBy(cb.asc(aliased));
+        assertSame(original, aliased);
+        assertEquals("x", aliased.getAlias());
+        c.select(aliased);
+        assertEquivalence(c, jpql);
+        assertEquals(jpql, c.toCQL());
+    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/AliasContext.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/AliasContext.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/AliasContext.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/AliasContext.java
Thu Sep 10 16:58:44 2009
@@ -25,12 +25,13 @@
 
 /**
  * The context holds named variables for nodes of CriteriaQuery.
- * Creates unique alias for the nodes.
+ * Can create unique alias for the nodes that has not been aliased explicitly.
  *  
  * @author Pinaki Poddar
+ * @since 2.0.0
  *
  */
-public interface AliasContext {
+interface AliasContext {
     /**
      * Gets the alias for the given node.
      * If no alias is set on the given node then create an alias, assign it to
@@ -70,5 +71,4 @@
      * Return null if the node is not registered.     
      */
     Value getRegisteredValue(Selection<?> node);
-    
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaBuilder.java
Thu Sep 10 16:58:44 2009
@@ -41,6 +41,7 @@
 import javax.persistence.criteria.Subquery;
 import javax.persistence.metamodel.Attribute;
 import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.Metamodel;
 
 import org.apache.openjpa.kernel.ExpressionStoreQuery;
 import org.apache.openjpa.kernel.exps.ExpressionFactory;
@@ -71,6 +72,10 @@
         _model = model;
         return this;
     }
+    
+    public Metamodel getMetamodel() {
+        return _model;
+    }
 
     public QueryExpressions eval(Object parsed, ExpressionStoreQuery query,
         ExpressionFactory factory, ClassMetaData candidate) {
@@ -310,7 +315,7 @@
     }
 
     public <E, C extends Collection<E>> Predicate isMember(Expression<E>
e, Expression<C> c) {
-        return new Expressions.IsMember<E>((Class<E>)e.getJavaType(), e, c);
+        return new Expressions.IsMember<E>(e, c);
     }
 
     public <C extends Collection<?>> Predicate isNotEmpty(Expression<C>
collection) {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaExpression.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaExpression.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaExpression.java
Thu Sep 10 16:58:44 2009
@@ -19,7 +19,7 @@
 package org.apache.openjpa.persistence.criteria;
 
 /**
- * Interface to support Visitor pattern on Criteria Query nodes.
+ * Interface to support Visitor pattern and CQL conversion of Criteria Query nodes.
  * 
  * @author Pinaki Poddar
  * @since 2.0.0
@@ -42,4 +42,9 @@
      * Get a string representation of this node as a variable in the context of the given
query.
      */
     StringBuilder asVariable(AliasContext q);
+    
+    /**
+     * Get a string representation of this node as a projection term in the context of the
given query.
+     */
+    StringBuilder asProjection(AliasContext q);
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/CriteriaQueryImpl.java
Thu Sep 10 16:58:44 2009
@@ -467,7 +467,7 @@
     //
     
     /**
-     * Gets the alias of the given node. Creates if necessary.
+     * Gets the alias of the given node. Creates an automatic alias, if necessary.
      */
     public String getAlias(Selection<?> selection) {
         String alias = selection.getAlias();
@@ -478,7 +478,7 @@
         alias = ALIAS_BASE + (++aliasCount);
         while (_aliases.containsValue(alias))
             alias = ALIAS_BASE + (++aliasCount);
-        selection.alias(alias);
+        ((SelectionImpl<?>)selection).setAutoAlias(alias);
         _aliases.put(selection, alias);
         return _aliases.get(selection);
     }
@@ -652,7 +652,7 @@
     void render(StringBuilder buffer, Set<Root<?>> roots, List<Join<?,?>>
correlatedJoins) {
         buffer.append("SELECT ");
         if (isDistinct()) buffer.append(" DISTINCT ");
-        buffer.append(_selection != null ? ((CriteriaExpression)_selection).asValue(this)
: "*");
+        buffer.append(_selection != null ? ((CriteriaExpression)_selection).asProjection(this)
: "*");
         buffer.append(" FROM ");
         renderRoots(buffer, roots);
         renderJoins(buffer, correlatedJoins);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ExpressionImpl.java
Thu Sep 10 16:58:44 2009
@@ -29,7 +29,7 @@
 import org.apache.openjpa.persistence.meta.MetamodelImpl;
 
 /**
- * Expression for Criteria query.
+ * Expression node for Criteria query.
  * 
  * @param <X> the type of the value this expression represents.
  * 
@@ -45,20 +45,16 @@
     }
 
     /**
-     * Perform a typecast upon the expression.
-     * Warning: may result in a runtime failure.
-     * @param type 
-     * @return expression
+     * Creates a new expression of the given type. If the given type is same as this expression's
type then
+     * returns the same instance. 
+     * May cause runtime cast failure if this expression's immutable type is not convertible
to the given type. 
      */
     public <Y> Expression<Y> as(Class<Y> type) {
        return type == getJavaType() ? (Expression<Y>)this : new Expressions.CastAs<Y>(type,
this);
     }
 
     /**
-     * Apply a predicate to test whether the expression is a member
-     * of the argument list.
-     * @param values
-     * @return predicate testing for membership in the list
+     * Create a predicate to test whether this expression is a member of the given argument
values.
      */
    public Predicate in(Object... values) {
         In<X> result = new Expressions.In<X>(this);
@@ -68,10 +64,7 @@
     }
 
    /**
-    * Apply a predicate to test whether the expression is a member
-    * of the argument list.
-    * @param values
-    * @return predicate testing for membership
+    * Create a predicate to test whether this expression is a member of the given argument
expressions.
     */
     public Predicate in(Expression<?>... values) {
         In<X> result = new Expressions.In<X>(this);
@@ -81,10 +74,7 @@
     }
 
     /**
-     * Apply a predicate to test whether the expression is a member
-     * of the collection.
-     * @param values collection
-     * @return predicate testing for membership
+     * Create a predicate to test whether this expression is a member of the given collection
element values.
      */
     public Predicate in(Collection<?> values) {
         In<X> result = new Expressions.In<X>(this);
@@ -94,10 +84,7 @@
     }
 
     /**
-     * Apply a predicate to test whether the expression is a member
-     * of the collection.
-     * @param values expression corresponding to collection
-     * @return predicate testing for membership
+     * Create a predicate to test whether this expression is a member of the given expression
representing a collection.
      */
     public Predicate in(Expression<Collection<?>> values) {
         In<X> result = new Expressions.In<X>(this);
@@ -106,16 +93,14 @@
     }
 
     /**
-     *  Apply a predicate to test whether the expression is not null.
-     *  @return predicate testing whether the expression is not null.
+     *  Create a predicate to test whether this expression is not null.
      */
     public Predicate isNotNull() {
     	return new Expressions.IsNotNull(this);
     }
 
     /**
-     *  Apply a predicate to test whether the expression is null.
-     *  @return predicate testing whether the expression is null
+     *  Create a predicate to test whether this expression is null.
      */
     public Predicate isNull() {
     	return new Expressions.IsNull(this);

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/Expressions.java
Thu Sep 10 16:58:44 2009
@@ -268,12 +268,7 @@
             e1 = (ExpressionImpl<?>)x;
             e2 = (ExpressionImpl<?>)y;
         }
-        
-//        @Override
-//        public PredicateImpl clone() {
-//            return new BinaryLogicalExpression(e1, e2);
-//        }
-        
+                
         public void acceptVisit(CriteriaExpressionVisitor visitor) {
             Expressions.acceptVisit(visitor, this, e1, e2);
         }
@@ -535,27 +530,27 @@
         private ExpressionImpl<Integer> from;
         private ExpressionImpl<String> path;
         
-        public Locate(Expression<String> x, Expression<String> y, Expression<Integer>
from) {
+        public Locate(Expression<String> path, Expression<String> pattern, Expression<Integer>
from) {
             super(Integer.class);
-            path = (ExpressionImpl<String>)x;
-            pattern = (ExpressionImpl<String>)y;
+            this.path = (ExpressionImpl<String>)path;
+            this.pattern = (ExpressionImpl<String>)pattern;
             this.from = (ExpressionImpl<Integer>)from;
         }
 
-        public Locate(Expression<String> x, Expression<String> y) {
-            this(x, y, null);
+        public Locate(Expression<String> path, Expression<String> pattern) {
+            this(path, pattern, null);
          }
         
-        public Locate(Expression<String> x, String y) {
-            this(x, new Constant<String>(y), null);
+        public Locate(Expression<String> path, String pattern) {
+            this(path, new Constant<String>(pattern), null);
         }
         
-        public Locate(String x, Expression<String> y) {
-            this(new Constant<String>(x), y, null);
+        public Locate(String path, Expression<String> pattern) {
+            this(new Constant<String>(path), pattern, null);
         }
         
-        public Locate(Expression<String> x, String y, int from) {
-            this(x, new Constant<String>(y), new Constant<Integer>(from));
+        public Locate(Expression<String> path, String pattern, int from) {
+            this(path, new Constant<String>(pattern), new Constant<Integer>(from));
         }
 
         @Override
@@ -994,15 +989,15 @@
     }
 
     public static class Between<Y extends Comparable<Y>> extends PredicateImpl.And
{
-        private final ExpressionImpl<?> e;
-        private final ExpressionImpl<?> v1;
-        private final ExpressionImpl<?> v2;
+        private final ExpressionImpl<? extends Y> e;
+        private final ExpressionImpl<? extends Y> v1;
+        private final ExpressionImpl<? extends Y> v2;
         
         public Between(Expression<? extends Y> v, Expression<? extends Y> x,
Expression<? extends Y> y) {
             super(new GreaterThanEqual(v,x), new LessThanEqual(v,y));
-            e = (ExpressionImpl<?>)v;
-            v1 = (ExpressionImpl<?>)x;
-            v2 = (ExpressionImpl<?>)y;
+            e = (ExpressionImpl<? extends Y>)v;
+            v1 = (ExpressionImpl<? extends Y>)x;
+            v2 = (ExpressionImpl<? extends Y>)y;
         }
         
         public Between(Expression<? extends Y> v, Y x, Y y) {
@@ -1182,18 +1177,14 @@
         final ExpressionImpl<E> element;
         final ExpressionImpl<?> collection;
         
-        public IsMember(Class<E> t, Expression<E> element, Expression<?>
collection) {
+        public IsMember(Expression<E> element, Expression<?> collection) {
             super();
             this.element = (ExpressionImpl<E>)element;
             this.collection = (ExpressionImpl<?>)collection;
         }
         
-        public IsMember(Class<E> t, E element, Expression<?> collection) {
-            this(t, new Constant<E>(element), collection);
-        }
-        
         public IsMember(E element, Expression<?> collection) {
-            this((Class<E>)element.getClass(), element, collection);
+            this(new Constant<E>(element), collection);
         }
         
         @Override
@@ -1567,12 +1558,16 @@
             return caseOperand;
         }
 
-        public SimpleCase<C,R> when(C when, Expression<? extends R> then) {
-            whens.add(new Constant<C>(when));
+        public SimpleCase<C,R> when(Expression<C> when, Expression<? extends
R> then) {
+            whens.add(when);
             thens.add(then);
             return this;
         }
 
+        public SimpleCase<C,R> when(C when, Expression<? extends R> then) {
+            return when(new Constant<C>(when), then);
+        }
+
         public SimpleCase<C,R> when(C when, R then) {
             return when(when, new Expressions.Constant<R>(then));
         }
@@ -1828,27 +1823,4 @@
             Expressions.acceptVisit(visitor, this, _args);
         }
     }
-
-    public static class DelegatingExpression<X> extends ExpressionImpl<X> {
-        final ExpressionImpl<? extends X> _delegate;
-        public DelegatingExpression(ExpressionImpl<? extends X> del) {
-            super((Class<X>)del.getJavaType());
-            _delegate = del;
-        }
-        
-        @Override
-        Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?>
q) {
-            return _delegate.toValue(factory, model, q);
-        }
-        
-        @Override
-        public org.apache.openjpa.kernel.exps.Expression toKernelExpression(
-            ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?> q)
{
-            return _delegate.toKernelExpression(factory, model, q);
-        }
-        
-        public void acceptVisit(CriteriaExpressionVisitor visitor) {
-            Expressions.acceptVisit(visitor, this, _delegate);
-        }
-    }
 }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java
Thu Sep 10 16:58:44 2009
@@ -61,7 +61,12 @@
     }
     
     public StringBuilder asValue(AliasContext q) {
-        return e.asValue(q).append(_ascending ? "" : " DESC");
+        return (e.isAutoAliased() ? e.asValue(q) : new StringBuilder(e.getAlias()))
+            .append(_ascending ? "" : " DESC");
+    }
+    
+    public StringBuilder asProjection(AliasContext q) {
+        throw new IllegalStateException(this + " can not be rendered as projection");
     }
     
     public StringBuilder asVariable(AliasContext q) {

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java?rev=813514&r1=813513&r2=813514&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java
Thu Sep 10 16:58:44 2009
@@ -23,35 +23,85 @@
 import javax.persistence.criteria.Expression;
 import javax.persistence.criteria.Selection;
 
-import org.apache.openjpa.persistence.TupleElementImpl;
-
 /**
- * An item selected in the projection clause of  Criteria query.
+ * An item selected in the projection clause of Criteria query.
+ * Base implementation for all concrete expressions.
  * 
  * @author Pinaki Poddar
  *
  * @param <X>
  */
-public class SelectionImpl<X> extends TupleElementImpl<X> 
-    implements Selection<X>, CriteriaExpression {
+public abstract class SelectionImpl<X> implements Selection<X>, CriteriaExpression
{
+    private final Class<X> _cls;
+    private String _alias;
+    private Boolean _autoAliased;
     
+    /**
+     * Construct with the immutable type represented by this selection term.
+     */
     public SelectionImpl(Class<X> cls) {
-        super(cls);
+        _cls = cls;
     }
-
+    
+    /**
+     * Gets the immutable type represented by this selection term.
+     */
+    public Class<X> getJavaType() {
+        return _cls;
+    }
+    
+    /**
+     * Gets the alias set of this selection term.
+     */
+    public String getAlias() {
+        return _alias; 
+    }
+    
+    /**
+     * Sets the alias on this selection term.
+     */
     public Selection<X> alias(String alias) {
-        super.setAlias(alias);
+        _alias = alias;
+        _autoAliased = false;
         return this;
     }
-
+    
+    /**
+     * Sets the alias of this expression internally. Only valid if the expression is not
aliased explicitly
+     * by calling {@linkplain #alias(String)}.
+     */
+    void setAutoAlias(String alias) {
+        if (Boolean.FALSE.equals(_autoAliased))
+            throw new IllegalStateException(this + " has been aliased. Can not set alias
automatically");
+        _alias = alias;
+        _autoAliased = true;
+    }
+    
+    /**
+     * Affirms if the alias of this expression is assigned automatically.
+     */
+    boolean isAutoAliased() {
+        return _autoAliased == null ? true : _autoAliased.booleanValue();
+    }  
+
+    /**
+     * Throws IllegalStateException because a selection term, by default, consists of single
value.
+     */
     public List<Selection<?>> getCompoundSelectionItems() {
         throw new IllegalStateException(this + " is not a compound selection");
     }
 
+    /**
+     * Returns false because a selection term, by default, consists of single value.
+     */
     public boolean isCompoundSelection() {
         return false;
     }
     
+    //  ------------------------------------------------------------------------------------
+    //  Contract for CriteriaExpression implemented mostly as a no-op for easier derivation.
+    //  ------------------------------------------------------------------------------------
+    
     public StringBuilder asValue(AliasContext q) {
         throw new IllegalStateException(this.getClass().getSimpleName() + " can not be rendered
as value");
     }
@@ -60,8 +110,12 @@
         throw new IllegalStateException(this.getClass().getSimpleName() + " can not be rendered
as variable");
     }
     
+    public final StringBuilder asProjection(AliasContext q) {
+        String as = (isAutoAliased() ? "" : " AS " + getAlias());
+        return asValue(q).append(as);
+    }
+    
     public void acceptVisit(CriteriaExpressionVisitor visitor) {
         Expressions.acceptVisit(visitor, this, (Expression<?>[])null);
     }
-
 }



Mime
View raw message