openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r741398 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryResults.java openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java
Date Fri, 06 Feb 2009 04:31:18 GMT
Author: ppoddar
Date: Fri Feb  6 04:31:17 2009
New Revision: 741398

URL: http://svn.apache.org/viewvc?rev=741398&view=rev
Log:
DB2 optimization for Query.getSingleResult()

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryResults.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/QueryImpl.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryResults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryResults.java?rev=741398&r1=741397&r2=741398&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryResults.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryResults.java
Fri Feb  6 04:31:17 2009
@@ -22,6 +22,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.persistence.NoResultException;
+
 
 import org.apache.openjpa.persistence.query.common.apps.RuntimeTest1;
 import org.apache.openjpa.persistence.query.common.apps.RuntimeTest2;
@@ -256,10 +258,12 @@
         query =
             "SELECT DISTINCT r FROM RuntimeTest1 r WHERE r.stringField = \'xxxx\'";
         OpenJPAQuery q = em.createQuery(query);
-        List l = q.getResultList();
-        assertNotNull(
-            "expecting l to be null since there is no RuntimeTest1 instance with stringfield=xxxx",
-            l);
+        try {
+            Object l = q.getSingleResult();
+            fail("Expected NoResultException since there is no RuntimeTest1 instance with
stringfield=xxxx");
+        } catch (NoResultException e) {
+            // good
+        }
 
         q.closeAll();
         endTx(em);

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=741398&r1=741397&r2=741398&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
Fri Feb  6 04:31:17 2009
@@ -288,6 +288,7 @@
 	 */
 	public Object getSingleResult() {
 		_em.assertNotCloseInvoked();
+		setHint("openjpa.hint.OptimizeResultCount", 1); // for DB2 optimization
 		List result = getResultList();
 		if (result == null || result.isEmpty())
 			throw new NoResultException(_loc.get("no-result", getQueryString())
@@ -295,7 +296,12 @@
 		if (result.size() > 1)
 			throw new NonUniqueResultException(_loc.get("non-unique-result",
 				getQueryString(), result.size()).getMessage());
-		return result.get(0);
+		try {
+		    return result.get(0);
+		} catch (Exception e) {
+            throw new NoResultException(_loc.get("no-result", getQueryString())
+                .getMessage());
+		}
 	}
 
 	public int executeUpdate() {



Mime
View raw message