/[Apache-SVN]/incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
ViewVC logotype

Diff of /incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java	2007/03/26 17:52:23	522580
+++ incubator/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java	2007/03/26 17:59:03	522581
@@ -279,24 +279,15 @@
      */
     public Object getSingleResult() {
         _em.assertNotCloseInvoked();
+        //Indicate that this query returns single result.Later copied into
+        //select.expectedResultCount
+        _query.setUnique(true);
+        try{
         Object ob = execute();
-        if (!(ob instanceof List))
-            return ob;
+           return ob;
 
-        List res = (List) ob;
-        try {
-            // don't use size() b/c can be inefficient under some LRS settings
-            Iterator itr = res.iterator();
-            if (!itr.hasNext())
-                throw new NoResultException(_loc.get("no-results",
-                    _query.getQueryString()).getMessage(), null, null, false);
-            Object ret = itr.next();
-            if (itr.hasNext())
-                throw new NonUniqueResultException(_loc.get("mult-results",
-                    _query.getQueryString()).getMessage(), null, null, false);
-            return ret;
         } finally {
-            OpenJPAPersistence.close(res);
+            _query.setUnique(false);
         }
     }
 
@@ -375,13 +366,29 @@
             } else if (k.startsWith("FetchPlan.")) {
                 k = k.substring("FetchPlan.".length());
                 Filters.hintToSetter(getFetchPlan(), k, value);
-            } else if (k.startsWith("hint."))
+            } else if (k.startsWith("hint.")){
+            	if("hint.OptimizeResultCount".equals(k)){
+            		if((!(value instanceof String)&&!(value instanceof Integer))
+                       ||  (value instanceof String &&(Integer.parseInt
+                       ((String)value)< 0))||((value instanceof Integer)
+                        && (((Integer)value).intValue()<0)) )
+            			    throw new ArgumentException(_loc.get
+                                      ("bad-hint-value", key),
+                                      null, null, false);
+                    if(value instanceof String)
+                        value = new Integer((String)value);
+         	}
                 _query.getFetchConfiguration().setHint(key, value);
+            }
             else
                 throw new ArgumentException(_loc.get("bad-query-hint", key),
                     null, null, false);
             return this;
-        } catch (Exception e) {
+        }catch(NumberFormatException e1){
+              throw new ArgumentException(_loc.get("bad-hint-value", key),
+                null, null, false); 
+        }
+         catch (Exception e) {
             throw PersistenceExceptions.toPersistenceException(e);
         }
     }

 

apache@apache.org
ViewVC Help
Powered by ViewVC 1.1.2