cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454050 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi: CjpaNativeQuery.java CjpaQuery.java
Date Sun, 08 Oct 2006 00:29:27 GMT
Author: aadamchik
Date: Sat Oct  7 17:29:27 2006
New Revision: 454050

URL: http://svn.apache.org/viewvc?view=rev&rev=454050
Log:
switching jpa queries from DataContext to ObjectContext

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaNativeQuery.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaQuery.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaNativeQuery.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaNativeQuery.java?view=diff&rev=454050&r1=454049&r2=454050
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaNativeQuery.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaNativeQuery.java
Sat Oct  7 17:29:27 2006
@@ -21,7 +21,7 @@
 
 import javax.persistence.Query;
 
-import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.query.SQLTemplate;
 
@@ -29,14 +29,14 @@
 
     private static final String POSITIONAL_PARAM_PREFIX = "positional_";
 
-    public CjpaNativeQuery(DataContext ctxt, String sqlString, Class resultClass) {
-        super(ctxt);
+    public CjpaNativeQuery(ObjectContext context, String sqlString, Class resultClass) {
+        super(context);
         setQuery(new SQLTemplate(resultClass, processSQLString(sqlString)));
     }
 
-    public CjpaNativeQuery(DataContext ctxt, String sqlString, String dataMapName) {
-        super(ctxt);
-        DataMap map = ctxt.getEntityResolver().getDataMap(dataMapName);
+    public CjpaNativeQuery(ObjectContext context, String sqlString, String dataMapName) {
+        super(context);
+        DataMap map = context.getEntityResolver().getDataMap(dataMapName);
         setQuery(new SQLTemplate(map, processSQLString(sqlString)));
     }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaQuery.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaQuery.java?view=diff&rev=454050&r1=454049&r2=454050
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaQuery.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/cspi/CjpaQuery.java
Sat Oct  7 17:29:27 2006
@@ -16,8 +16,6 @@
  *  specific language governing permissions and limitations
  *  under the License.
  ****************************************************************/
-
-
 package org.apache.cayenne.jpa.cspi;
 
 import java.util.Calendar;
@@ -32,22 +30,23 @@
 import javax.persistence.TemporalType;
 import javax.persistence.TransactionRequiredException;
 
-import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.query.ParameterizedQuery;
 import org.apache.cayenne.query.ProcedureQuery;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
 
 /**
- * A jpa Query that wraps a Cayenne Query.
+ * A JPA Query that wraps a Cayenne Query.
  */
 public class CjpaQuery implements Query {
 
     protected Map<String, Object> parameters = new HashMap<String, Object>();
     protected org.apache.cayenne.query.Query cayenneQuery;
-    protected DataContext context;
+    protected ObjectContext context;
 
-    public CjpaQuery(DataContext ctxt) {
+    public CjpaQuery(ObjectContext ctxt) {
         this.context = ctxt;
     }
 
@@ -57,11 +56,10 @@
      * @param ctxt
      * @param name
      */
-    public CjpaQuery(DataContext context, String name) {
+    public CjpaQuery(ObjectContext context, String name) {
         this(context);
 
-        org.apache.cayenne.query.Query q = context.getEntityResolver().lookupQuery(
-                name);
+        org.apache.cayenne.query.Query q = context.getEntityResolver().lookupQuery(name);
 
         if (q == null) {
             throw new IllegalArgumentException("Non-existing query: " + name);
@@ -108,7 +106,14 @@
      */
     public int executeUpdate() {
         // TODO: check transaction
-        int[] res = context.performNonSelectingQuery(queryWithParameters());
+
+        QueryResponse response = context.performGenericQuery(queryWithParameters());
+        int[] res = response.firstUpdateCount();
+
+        if (res == null) {
+            return -1;
+        }
+
         int num = 0;
         for (int i = 0; i < res.length; i++) {
             num = num + res[i];



Mime
View raw message