openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r889801 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel: QueryImpl.java StoreQuery.java
Date Fri, 11 Dec 2009 20:33:32 GMT
Author: ppoddar
Date: Fri Dec 11 20:33:32 2009
New Revision: 889801

URL: http://svn.apache.org/viewvc?rev=889801&view=rev
Log:
OPENJPA-1050: Use generic types whenever possible. Replace ordered map with native implementation
wrapper. 

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java?rev=889801&r1=889800&r2=889801&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/QueryImpl.java Fri
Dec 11 20:33:32 2009
@@ -29,21 +29,19 @@
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
+import java.util.concurrent.locks.ReentrantLock;
 
-import org.apache.commons.collections.map.LinkedMap;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.kernel.exps.AggregateListener;
-import org.apache.openjpa.kernel.exps.FilterListener;
 import org.apache.openjpa.kernel.exps.Constant;
+import org.apache.openjpa.kernel.exps.FilterListener;
 import org.apache.openjpa.kernel.exps.Literal;
-import org.apache.openjpa.kernel.exps.Parameter;
 import org.apache.openjpa.kernel.exps.Path;
 import org.apache.openjpa.kernel.exps.QueryExpressions;
 import org.apache.openjpa.kernel.exps.Val;
-import org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.rop.EagerResultList;
 import org.apache.openjpa.lib.rop.MergedResultObjectProvider;
@@ -52,20 +50,21 @@
 import org.apache.openjpa.lib.rop.ResultObjectProvider;
 import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.lib.util.OrderedMap;
 import org.apache.openjpa.lib.util.ReferenceHashSet;
-import java.util.concurrent.locks.ReentrantLock;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.util.GeneralException;
+import org.apache.openjpa.util.ImplHelper;
 import org.apache.openjpa.util.InvalidStateException;
-import org.apache.openjpa.util.NonUniqueResultException;
 import org.apache.openjpa.util.NoResultException;
+import org.apache.openjpa.util.NonUniqueResultException;
 import org.apache.openjpa.util.OpenJPAException;
 import org.apache.openjpa.util.UnsupportedException;
 import org.apache.openjpa.util.UserException;
-import org.apache.openjpa.util.ImplHelper;
+
 import serp.util.Numbers;
 import serp.util.Strings;
 
@@ -75,6 +74,7 @@
  * @author Abe White
  * @nojavadoc
  */
+@SuppressWarnings("serial")
 public class QueryImpl
     implements Query {
 
@@ -90,7 +90,7 @@
     private ReentrantLock _lock;
 
     // unparsed state
-    private Class _class = null;
+    private Class<?> _class = null;
     private boolean _subclasses = true;
     private boolean _readOnly = false;
     private String _query = null;
@@ -102,31 +102,30 @@
     private transient ResultPacker _packer = null;
 
     // candidates
-    private transient Collection _collection = null;
+    private transient Collection<?> _collection = null;
     private transient Extent _extent = null;
 
     // listeners
-    private Map _filtListeners = null;
-    private Map _aggListeners = null;
+    private Map<String,FilterListener> _filtListeners = null;
+    private Map<String,AggregateListener> _aggListeners = null;
 
     // configuration for loading objects
     private FetchConfiguration _fc = null;
     private boolean _ignoreChanges = false;
-    private Class _resultMappingScope = null;
+    private Class<?> _resultMappingScope = null;
     private String _resultMappingName = null;
 
     // these fields should only be used directly after we have a compilation,
     // because their values may be encoded in the query string
     private Boolean _unique = null;
-    private Class _resultClass = null;
+    private Class<?> _resultClass = null;
     private transient long _startIdx = 0;
     private transient long _endIdx = Long.MAX_VALUE;
     private transient boolean _rangeSet = false;
 
     // remember the list of all the results we have returned so we
     // can free their resources when close or closeAll is called
-    private transient final Collection _resultLists = new ReferenceHashSet
-        (ReferenceHashSet.WEAK);
+    private transient final Collection<ResultList<?>> _resultLists = new ReferenceHashSet(ReferenceHashSet.WEAK);
 
     /**
      * Construct a query managed by the given broker.
@@ -211,7 +210,7 @@
             assertOpen();
             assertNotReadOnly();
             if (_filtListeners == null)
-                _filtListeners = new HashMap(5);
+                _filtListeners = new HashMap<String,FilterListener>(5);
             _filtListeners.put(listener.getTag(), listener);
         } finally {
             unlock();
@@ -230,9 +229,11 @@
         }
     }
 
-    public Collection getFilterListeners() {
-        return (_filtListeners == null) ? Collections.EMPTY_LIST
-            : _filtListeners.values();
+    public Collection<FilterListener> getFilterListeners() {
+        if (_filtListeners == null) 
+            return Collections.emptyList();
+        else
+            return _filtListeners.values();
     }
 
     public FilterListener getFilterListener(String tag) {
@@ -260,7 +261,7 @@
             assertOpen();
             assertNotReadOnly();
             if (_aggListeners == null)
-                _aggListeners = new HashMap(5);
+                _aggListeners = new HashMap<String,AggregateListener>(5);
             _aggListeners.put(listener.getTag(), listener);
         } finally {
             unlock();
@@ -279,9 +280,11 @@
         }
     }
 
-    public Collection getAggregateListeners() {
-        return (_aggListeners == null) ? Collections.EMPTY_LIST
-            : _aggListeners.values();
+    public Collection<AggregateListener> getAggregateListeners() {
+        if (_aggListeners == null) 
+            return Collections.emptyList();
+        else
+            return _aggListeners.values();
     }
 
     public AggregateListener getAggregateListener(String tag) {
@@ -311,7 +314,7 @@
         // in case the user has a reference to it and might use it)
         lock();
         try {
-            Class cls = getCandidateType();
+            Class<?> cls = getCandidateType();
             if (_extent == null && _collection == null && _broker != null
                 && cls != null) {
                 _extent = _broker.newExtent(cls, _subclasses);
@@ -361,12 +364,12 @@
         }
     }
 
-    public Collection getCandidateCollection() {
+    public Collection<?> getCandidateCollection() {
         assertOpen();
         return _collection;
     }
 
-    public void setCandidateCollection(Collection candidateCollection) {
+    public void setCandidateCollection(Collection<?> candidateCollection) {
         if (!_storeQuery.supportsInMemoryExecution())
             throw new UnsupportedException(_loc.get("query-nosupport",
                 _language));
@@ -428,7 +431,7 @@
         return _resultMappingScope;
     }
 
-    public void setResultMapping(Class scope, String name) {
+    public void setResultMapping(Class<?> scope, String name) {
         lock();
         try {
             assertOpen();
@@ -1170,13 +1173,12 @@
     /**
      * Trace log that the query is executing.
      */
-    private void logExecution(int op, LinkedMap types, Object[] params) {
-        Map pmap = Collections.EMPTY_MAP;
+    private void logExecution(int op, OrderedMap<Object, Class<?>> types, Object[]
params) {
+        OrderedMap<Object, Object> pmap = new OrderedMap<Object, Object>();
         if (params.length > 0) {
-            pmap = new HashMap((int) (params.length * 1.33 + 1));
             if (types != null && types.size() == params.length) {
                 int i = 0;
-                for (Iterator itr = types.keySet().iterator(); itr.hasNext();)
+                for (Iterator<Object> itr = types.keySet().iterator(); itr.hasNext();)
                     pmap.put(itr.next(), params[i++]);
             } else {
                 for (int i = 0; i < params.length; i++)
@@ -1189,7 +1191,7 @@
     /**
      * Trace log that the query is executing.
      */
-    private void logExecution(int op, Map params) {
+    private void logExecution(int op, Map<?, ?> params) {
         String s = _query;
         if (StringUtils.isEmpty(s))
             s = toString();
@@ -1542,7 +1544,7 @@
         }
     }
 
-    public LinkedMap getParameterTypes() {
+    public OrderedMap<Object,Class<?>> getParameterTypes() {
         lock();
         try {
             return compileForExecutor().getParameterTypes(_storeQuery);
@@ -1702,28 +1704,26 @@
         if (!q.requiresParameterDeclarations() || !isParsedQuery())
             return;
 
-        LinkedMap paramTypes = ex.getParameterTypes(q);
+        OrderedMap<Object,Class<?>> paramTypes = ex.getParameterTypes(q);
         int typeCount = paramTypes.size();
         if (typeCount > params.length)
             throw new UserException(_loc.get("unbound-params",
                 paramTypes.keySet()));
 
-        Iterator itr = paramTypes.entrySet().iterator();
-        Map.Entry entry;
+        Iterator<Map.Entry<Object,Class<?>>> itr = paramTypes.entrySet().iterator();
+        Map.Entry<Object,Class<?>> entry;
         for (int i = 0; itr.hasNext(); i++) {
-            entry = (Map.Entry) itr.next();
-            if (((Class) entry.getValue()).isPrimitive() && params[i] == null)
-                throw new UserException(_loc.get("null-primitive-param",
-                    entry.getKey()));
+            entry = itr.next();
+            if (entry.getValue().isPrimitive() && params[i] == null)
+                throw new UserException(_loc.get("null-primitive-param", entry.getKey()));
         }
     }
     
-    protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, 
-        Map params) {
+    protected void assertParameters(StoreQuery q, StoreQuery.Executor ex, Map params) {
         if (!q.requiresParameterDeclarations())
             return;
 
-        LinkedMap paramTypes = ex.getParameterTypes(q);
+        OrderedMap<Object,Class<?>> paramTypes = ex.getParameterTypes(q);
         for (Object actual : params.keySet()) {
             if (!paramTypes.containsKey(actual))
             throw new UserException(_loc.get("unbound-params",
@@ -1735,14 +1735,13 @@
                 expected, params.keySet()));
         }
 
-        Iterator itr = paramTypes.entrySet().iterator();
-        Map.Entry entry;
+        Iterator<Map.Entry<Object, Class<?>>> itr = paramTypes.entrySet().iterator();
+        Map.Entry<Object, Class<?>> entry;
         for (int i = 0; itr.hasNext(); i++) {
-            entry = (Map.Entry) itr.next();
-            if (((Class) entry.getValue()).isPrimitive() 
+            entry = itr.next();
+            if (entry.getValue().isPrimitive() 
                 && params.get(entry.getKey()) == null)
-                throw new UserException(_loc.get("null-primitive-param",
-                    entry.getKey()));
+                throw new UserException(_loc.get("null-primitive-param", entry.getKey()));
         }
     }
 
@@ -1987,7 +1986,7 @@
             return _executors[0].hasGrouping(q);
         }
 
-        public LinkedMap getParameterTypes(StoreQuery q) {
+        public OrderedMap<Object,Class<?>> getParameterTypes(StoreQuery q) {
             return _executors[0].getParameterTypes(q);
         }
         

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java?rev=889801&r1=889800&r2=889801&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StoreQuery.java Fri
Dec 11 20:33:32 2009
@@ -27,7 +27,9 @@
 import org.apache.openjpa.kernel.exps.Constant;
 import org.apache.openjpa.kernel.exps.FilterListener;
 import org.apache.openjpa.kernel.exps.QueryExpressions;
+import org.apache.openjpa.kernel.exps.Value;
 import org.apache.openjpa.lib.rop.ResultObjectProvider;
+import org.apache.openjpa.lib.util.OrderedMap;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 
@@ -43,11 +45,11 @@
     extends QueryOperations, Serializable {
 
     // linkedmap doesn't allow a size of 0, so use 1
-    public static final LinkedMap EMPTY_PARAMS = new LinkedMap(1, 1F);
+    public static final OrderedMap<Object, Class<?>> EMPTY_PARAMS = new OrderedMap<Object,
Class<?>>();
     public static final ClassMetaData[] EMPTY_METAS = new ClassMetaData[0];
     public static final String[] EMPTY_STRINGS = new String[0];
     public static final Object[] EMPTY_OBJECTS = new Object[0];
-    public static final Class[] EMPTY_CLASSES = new Class[0];
+    public static final Class<?>[] EMPTY_CLASSES = new Class[0];
     public static final boolean[] EMPTY_BOOLEANS = new boolean[0];
 
     /**
@@ -280,7 +282,7 @@
          * Return the expected types of the projections used by this query,
          * or an empty array if not a projection.
          */
-        public Class[] getProjectionTypes(StoreQuery q);
+        public Class<?>[] getProjectionTypes(StoreQuery q);
 
         /**
          * Return an array of all persistent classes used in this query, or
@@ -310,7 +312,7 @@
          * {@link Map#entrySet}'s {@link Iterator} must return values in the
          * order in which they were declared or used.
          */
-        public LinkedMap getParameterTypes(StoreQuery q);
+        public OrderedMap<Object, Class<?>> getParameterTypes(StoreQuery q);
         
         /**
          * Return an array from the given user parameter values.
@@ -324,12 +326,12 @@
          * 
          * @since 2.0.0
          */
-        public Object[] toParameterArray(StoreQuery q, Map userParams);
+        public Object[] toParameterArray(StoreQuery q, Map<?,?> userParams);
 
         /**
          * Returns the result class, if any.
          */
-        public Class getResultClass(StoreQuery q);
+        public Class<?> getResultClass(StoreQuery q);
         
         public ResultShape<?> getResultShape(StoreQuery q);
 
@@ -337,7 +339,7 @@
          * Return a map of {@link FieldMetaData} to update
          * {@link Constant}s, in cases where this query is for a bulk update.
 	 	 */
-		public Map getUpdates (StoreQuery q);
+		public Map<FieldMetaData,Value> getUpdates (StoreQuery q);
 		
         /**
          * Return the parsed query expressions for our candidate types.



Mime
View raw message