openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r807398 - in /openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence: ./ criteria/
Date Mon, 24 Aug 2009 22:02:18 GMT
Author: ppoddar
Date: Mon Aug 24 22:02:18 2009
New Revision: 807398

URL: http://svn.apache.org/viewvc?rev=807398&view=rev
Log:
OPENJA-1262: EA7 Update.
  Fetch method signature changed. 
  nullLiteral() method added

Modified:
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.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/CriteriaQueryImpl.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/FetchPathImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java?rev=807398&r1=807397&r2=807398&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
Mon Aug 24 22:02:18 2009
@@ -42,8 +42,6 @@
 import javax.persistence.NonUniqueResultException;
 import javax.persistence.Parameter;
 import javax.persistence.Query;
-import javax.persistence.Result;
-import javax.persistence.ResultItem;
 import javax.persistence.TemporalType;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.ParameterExpression;

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=807398&r1=807397&r2=807398&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
Mon Aug 24 22:02:18 2009
@@ -685,6 +685,11 @@
     public Predicate isNull(Expression<?> x) {
         return new Expressions.IsNull((ExpressionImpl<?> )x);
     }
+    
+    public <T> Expression<T> nullLiteral(Class<T> t) {
+        return new Expressions.Constant<T>(t, (T)null);
+    }
+
 
     /**
      * Define a tuple-valued selection item

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=807398&r1=807397&r2=807398&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
Mon Aug 24 22:02:18 2009
@@ -84,8 +84,7 @@
     private Map<Selection<?>,Value> _variables = new HashMap<Selection<?>,
Value>();
     private Map<Selection<?>,Value> _values    = new HashMap<Selection<?>,
Value>();
     private Map<Selection<?>,String> _aliases  = null;
-    private Map<Selection<?>,Value> _rootVariables = 
-        new HashMap<Selection<?>, Value>();
+    private Map<Selection<?>,Value> _rootVariables = new HashMap<Selection<?>,
Value>();
     
     // SubqueryContext
     private Stack<Context> _contexts = null;
@@ -467,7 +466,7 @@
         
     }
 
-    public Value getRegisteredVariable(Selection<?> selection) {
+    Value getRegisteredVariable(Selection<?> selection) {
         Value var = getVariable(selection);
         if (var != null)
             return var;
@@ -483,7 +482,7 @@
 
     }
 
-    public Value getRegisteredValue(Selection<?> selection) {
+    Value getRegisteredValue(Selection<?> selection) {
         Value var = getValue(selection);
         if (var != null)
             return var;
@@ -499,18 +498,18 @@
 
     }
 
-    public void registerRoot(Root<?> root, Value var) {
+    void registerRoot(Root<?> root, Value var) {
         _rootVariables.put(root, var);
         String alias = var.getName();
         ctx().addSchema(alias, var.getMetaData());
         ctx().addVariable(alias, var);
     }
     
-    public Value getRootVariable(Root<?> root) {
+    Value getRootVariable(Root<?> root) {
         return _rootVariables.get(root);
     }
     
-    public Value getRegisteredRootVariable(Root<?> root) {
+    Value getRegisteredRootVariable(Root<?> root) {
         Value var = getRootVariable(root);
         if (var != null)
             return var;

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=807398&r1=807397&r2=807398&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
Mon Aug 24 22:02:18 2009
@@ -574,7 +574,7 @@
         }
         
         public <X> Equal(Expression<X> x, Object y) {
-            this(x, new Constant<Object>(Object.class, y));
+            this(x, new Constant(y));
         }
         
         @Override
@@ -598,7 +598,7 @@
         }
         
         public <X> GreaterThan(Expression<X> x, Object y) {
-            this(x, new Constant<Object>(Object.class, y));
+            this(x, new Constant(y));
         }
         
         @Override
@@ -617,7 +617,7 @@
         }
         
         public <X> GreaterThanEqual(Expression<X> x, Object y) {
-            this(x, new Constant<Object>(Object.class, y));
+            this(x, new Constant(y));
         }
         
         @Override
@@ -636,7 +636,7 @@
         }
         
         public <X> LessThan(Expression<X> x, Object y) {
-            this(x, new Constant<Object>(Object.class, y));
+            this(x, new Constant(y));
         }
         
         @Override
@@ -655,7 +655,7 @@
         }
         
         public <X> LessThanEqual(Expression<X> x, Object y) {
-            this(x, new Constant<Object>(Object.class, y));
+            this(x, new Constant(y));
         }
         
         @Override
@@ -686,55 +686,53 @@
         }
         
         public Constant(X x) {
-            this((Class<X>)x.getClass(), x);
+            this(x == null ? null : (Class<X>)x.getClass(), x);
         }
         
         @Override
         public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?>
q) {
             Object value = arg;
+            Class<?> literalClass = getJavaType();
             if (arg instanceof ParameterExpressionImpl) {
                 return ((ParameterExpressionImpl)arg).toValue(factory, model, q);
             }
             int literalType = Literal.TYPE_UNKNOWN;
-            if (arg != null) {
-                Class<?> literalClass = value.getClass();
-                if (Number.class.isAssignableFrom(literalClass)) {
-                    literalType = Literal.TYPE_NUMBER;
-                } else if (Boolean.class.isAssignableFrom(literalClass)) {
-                    literalType = Literal.TYPE_BOOLEAN;
-                } else if (String.class.isAssignableFrom(literalClass)) {
-                    literalType = Literal.TYPE_STRING;
-                } else if (Enum.class.isAssignableFrom(literalClass)) {
-                    literalType = Literal.TYPE_ENUM;
-                } else if (Class.class.isAssignableFrom(literalClass)) {
-                    literalType = Literal.TYPE_CLASS;
-                    Literal lit = factory.newTypeLiteral(value, Literal.TYPE_CLASS);
-                    ClassMetaData can = ((Types.Entity<X>)q.getRoot().getModel()).meta;
-                    Class<?> candidate = can.getDescribedType();
-                    if (candidate.isAssignableFrom((Class)value)) {
-                       lit.setMetaData(model.repos.getMetaData((Class<?>)value, null,
true));
-                    } else {
-                        lit.setMetaData(can);
-                    }
-                    return lit;
-                } else if (Collection.class.isAssignableFrom(literalClass)) {
-                    literalType = Literal.TYPE_COLLECTION;
+            if (Number.class.isAssignableFrom(literalClass)) {
+                literalType = Literal.TYPE_NUMBER;
+            } else if (Boolean.class.isAssignableFrom(literalClass)) {
+                literalType = Literal.TYPE_BOOLEAN;
+            } else if (String.class.isAssignableFrom(literalClass)) {
+                literalType = Literal.TYPE_STRING;
+            } else if (Enum.class.isAssignableFrom(literalClass)) {
+                literalType = Literal.TYPE_ENUM;
+            } else if (Class.class.isAssignableFrom(literalClass)) {
+                literalType = Literal.TYPE_CLASS;
+                Literal lit = factory.newTypeLiteral(value, Literal.TYPE_CLASS);
+                ClassMetaData can = ((Types.Entity<X>)q.getRoot().getModel()).meta;
+                Class<?> candidate = can.getDescribedType();
+                if (candidate.isAssignableFrom((Class)value)) {
+                   lit.setMetaData(model.repos.getMetaData((Class<?>)value, null, true));
+                } else {
+                    lit.setMetaData(can);
                 }
+                return lit;
+            } else if (Collection.class.isAssignableFrom(literalClass)) {
+                literalType = Literal.TYPE_COLLECTION;
             }
             return factory.newLiteral(value, literalType);
         }
     }
     
-    public static class TypeConstant<X> extends Constant<X> {
-        public TypeConstant(X x) {
-            super((Class<X>)x.getClass(),x);
-        }
-        
-        @Override
-        public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?>
q) {
-            return factory.newTypeLiteral(arg, Literal.TYPE_CLASS);
-        }
-    }
+//    public static class TypeConstant<X> extends Constant<X> {
+//        public TypeConstant(X x) {
+//            super((Class<X>)x.getClass(),x);
+//        }
+//        
+//        @Override
+//        public Value toValue(ExpressionFactory factory, MetamodelImpl model, CriteriaQueryImpl<?>
q) {
+//            return factory.newTypeLiteral(arg, Literal.TYPE_CLASS);
+//        }
+//    }
     
     public static class IsEmpty extends PredicateImpl {
         final ExpressionImpl<?> collection;

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FetchPathImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FetchPathImpl.java?rev=807398&r1=807397&r2=807398&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FetchPathImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/FetchPathImpl.java
Mon Aug 24 22:02:18 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.persistence.criteria;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -39,7 +40,7 @@
  * @param <X> type of this
  */
 public class FetchPathImpl<Z,X> extends PathImpl<Z,X> implements Fetch<Z,
X> {
-    Set<Fetch<X,?>> _fetches;
+    Set<Fetch<?,?>> _fetches;
     JoinType joinType;
     
     
@@ -76,7 +77,7 @@
         return addFetch((Members.Member<? super X,Y>)assoc, JoinType.INNER);
     }
 
-    public <Y> Fetch<X, Y> fetch(String assocName) {
+    public <X,Y> Fetch<X, Y> fetch(String assocName) {
         return fetch(assocName, JoinType.INNER);
     }
 
@@ -84,26 +85,27 @@
         return addFetch((Members.Member<? super X,Y>)assoc, jt);
     }
 
-    public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> assoc,
-            JoinType jt) {
+    public <Y> Fetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> assoc,
JoinType jt) {
         return addFetch((Members.Member<? super X,Y>)assoc, jt);
     }
 
-    public <Y> Fetch<X, Y> fetch(String assocName, JoinType jt) {
-        Attribute<? super X, ?> assoc = ((ManagedType<X>)_member.getType())
-        .getAttribute(assocName);
+    public <X,Y> Fetch<X, Y> fetch(String assocName, JoinType jt) {
+        Attribute<? super X, ?> assoc = ((ManagedType<X>)_member.getType()).getAttribute(assocName);
         return addFetch((Members.Member<? super X,Y>)assoc, jt);
     }
 
     public Set<Fetch<X, ?>> getFetches() {
-        return _fetches;
+        Set<Fetch<X,?>> result = new HashSet<Fetch<X,?>>();
+        for (Fetch f : _fetches) {
+            result.add(f);
+        }
+        return result;
     }
     
-    private <Y> Fetch<X,Y> addFetch(Members.Member<? super X, Y> member,

-            JoinType jt) {
+    private <X,Y> Fetch<X,Y> addFetch(Members.Member<? super X, Y> member,
JoinType jt) {
         Fetch<X,Y> fetch = new FetchPathImpl(this, member, jt);
         if (_fetches == null)
-            _fetches = new HashSet<Fetch<X,?>>();
+            _fetches = new HashSet<Fetch<?,?>>();
         _fetches.add(fetch);
         return fetch;
     }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java?rev=807398&r1=807397&r2=807398&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SubqueryImpl.java
Mon Aug 24 22:02:18 2009
@@ -194,9 +194,9 @@
         return _corrJoins;
     }
     
-    public <X,Y> Join<X,Y> correlate(Join<X,Y> join) {
-        Join corrJoin = clone(join);
-        ((PathImpl<?,?>)corrJoin).setCorrelatedPath((PathImpl<?,?>)join);
+    public <X,Y> Join<X,Y> correlate(Join<X,Y> parentJoin) {
+        Join corrJoin = clone(parentJoin);
+        ((PathImpl<?,?>)corrJoin).setCorrelatedPath((PathImpl<?,?>)parentJoin);
         if (_corrJoins == null)
             _corrJoins = new ArrayList<Join<?,?>>();
         _corrJoins.add(corrJoin);
@@ -204,8 +204,7 @@
     }
     
     private Join<?,?> clone(Join<?,?> join) {
-        List<Members.SingularAttributeImpl<?,?>> members = 
-            new ArrayList<Members.SingularAttributeImpl<?,?>>();
+        List<Members.SingularAttributeImpl<?,?>> members = new ArrayList<Members.SingularAttributeImpl<?,?>>();
         List<JoinType> jts = new ArrayList<JoinType>();
         FromImpl<?,?> root = getMembers(join, members, jts);
         Members.SingularAttributeImpl<?,?> member = members.get(0);
@@ -224,8 +223,8 @@
     private FromImpl<?,?> getMembers(Join<?,?> join, List<Members.SingularAttributeImpl<?,?>>
members, 
         List<JoinType> jts) {
         PathImpl<?,?> parent = (PathImpl<?,?>)join.getParentPath();
-        Members.SingularAttributeImpl<?,?> member = 
-            (Members.SingularAttributeImpl<?,?>)((Joins.SingularJoin<?,?>)join).getMember();
+        Members.SingularAttributeImpl<?,?> member = (Members.SingularAttributeImpl<?,?>)((Joins.SingularJoin<?,?>)join)
+            .getMember();
         JoinType jt = join.getJoinType();
         FromImpl<?,?> root = null;
         if (parent instanceof RootImpl) {
@@ -239,6 +238,7 @@
         jts.add(jt);
         return root;
     }
+    
     public <X,Y> CollectionJoin<X,Y> correlate(CollectionJoin<X,Y> join)
{
         _delegate.from(join.getModel().getBindableJavaType());
         return join;
@@ -263,7 +263,7 @@
         return _joins;
     }
     
-    public org.apache.openjpa.kernel.exps.Subquery getSubQ() {
+    org.apache.openjpa.kernel.exps.Subquery getSubQ() {
         return _subq;
     }
 
@@ -283,8 +283,7 @@
         Context context = new Context(null, _subq, contexts.peek());
         contexts.push(context);
         _delegate.setContexts(contexts);
-        QueryExpressions subexp = exprBuilder.getQueryExpressions(factory, 
-                _delegate);
+        QueryExpressions subexp = exprBuilder.getQueryExpressions(factory, _delegate);
         _subq.setQueryExpressions(subexp);
         if (subexp.projections.length > 0)
             JPQLExpressionBuilder.checkEmbeddable(subexp.projections[0], null);
@@ -331,4 +330,8 @@
         return from._member.fmd.getDeclaredTypeMetaData();
         
     }
+    
+    public Class<T> getResultType() {
+        return getJavaType();
+    }
 }



Mime
View raw message