cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r676405 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/dba/hsqldb/ main/java/org/apache/cayenne/dba/mysql/ main/java/org/apache/cayenne/dba/oracle/ m...
Date Sun, 13 Jul 2008 18:46:56 GMT
Author: aadamchik
Date: Sun Jul 13 11:46:55 2008
New Revision: 676405

URL: http://svn.apache.org/viewvc?rev=676405&view=rev
Log:
CAY-1068 Add support for start index/offset of queries
(support for PrecedureQuery with offset)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BaseSQLAction.java
Sun Jul 13 11:46:55 2008
@@ -30,6 +30,7 @@
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.QueryMetadata;
 import org.apache.cayenne.query.SQLAction;
 
 /**
@@ -66,12 +67,18 @@
             OperationObserver delegate) throws SQLException, Exception {
 
         long t1 = System.currentTimeMillis();
+
+        QueryMetadata metadata = query.getMetaData(getEntityResolver());
+        int i = getInitialCursorPosition(metadata.getFetchOffset());
+        while (i-- > 0 && resultSet.next())
+            ;
+
         JDBCResultIterator resultReader = new JDBCResultIterator(
                 null,
                 null,
                 resultSet,
                 descriptor,
-                query.getMetaData(getEntityResolver()).getFetchLimit());
+                metadata.getFetchLimit());
 
         if (!delegate.isIteratedResult()) {
             List<DataRow> resultRows = resultReader.dataRows(false);
@@ -98,4 +105,16 @@
             }
         }
     }
+
+    /**
+     * Returns a value of the offset that will be used to rewind the ResultSet within the
+     * SQL action before reading the result rows. The default implementation returns
+     * 'queryOffset' argument. If the adapter supports setting offset at the SQL level,
+     * this method must be overridden to return zero to suppress manual offset.
+     * 
+     * @since 3.0
+     */
+    protected int getInitialCursorPosition(int queryOffset) {
+        return queryOffset;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SelectAction.java
Sun Jul 13 11:46:55 2008
@@ -72,7 +72,7 @@
         PreparedStatement prepStmt = translator.createStatement();
         ResultSet rs = prepStmt.executeQuery();
 
-        int i = getFetchOffset();
+        int i = getInitialCursorPosition(query.getFetchOffset());
         while (i-- > 0 && rs.next())
             ;
 
@@ -162,15 +162,4 @@
             }
         }
     }
-
-    /**
-     * Returns a value of the offset that will be used to rewind the ResultSet before
-     * starting reading the result rows. If the adapter supports setting offset at the SQL
-     * level, this method must be overridden to return zero for no manual offset.
-     * 
-     * @since 3.0
-     */
-    protected int getFetchOffset() {
-        return query.getFetchOffset();
-    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
Sun Jul 13 11:46:55 2008
@@ -33,7 +33,7 @@
     }
 
     @Override
-    protected int getFetchOffset() {
+    protected int getInitialCursorPosition(int queryOffset) {
         return 0;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
Sun Jul 13 11:46:55 2008
@@ -33,7 +33,7 @@
     }
 
     @Override
-    protected int getFetchOffset() {
+    protected int getInitialCursorPosition(int queryOffset) {
         return 0;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectAction.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSelectAction.java
Sun Jul 13 11:46:55 2008
@@ -49,7 +49,7 @@
     }
 
     @Override
-    protected int getFetchOffset() {
+    protected int getInitialCursorPosition(int queryOffset) {
         return 0;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectAction.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/postgres/PostgresSelectAction.java
Sun Jul 13 11:46:55 2008
@@ -34,7 +34,7 @@
     }
 
     @Override
-    protected int getFetchOffset() {
+    protected int getInitialCursorPosition(int queryOffset) {
         return 0;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java?rev=676405&r1=676404&r2=676405&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextProcedureQueryTest.java
Sun Jul 13 11:46:55 2008
@@ -221,6 +221,45 @@
         assertEquals(2000, p.getEstimatedPrice().intValue());
     }
 
+    public void testFetchLimit() throws Exception {
+        if (!getAccessStackAdapter().supportsStoredProcedures()) {
+            return;
+        }
+
+        // create an artist with painting in the database
+        createArtist(1000.0);
+        createArtist(2000.0);
+        createArtist(3000.0);
+
+        ProcedureQuery q = new ProcedureQuery(SELECT_STORED_PROCEDURE);
+        q.addParameter("aName", "An Artist");
+        q.addParameter("paintingPrice", new Integer(3000));
+        q.setFetchLimit(2);
+        List artists = runProcedureSelect(q);
+
+        assertEquals(2, artists.size());
+    }
+    
+    public void testFetchOffset() throws Exception {
+        if (!getAccessStackAdapter().supportsStoredProcedures()) {
+            return;
+        }
+
+        // create an artist with painting in the database
+        createArtist(1000.0);
+        createArtist(2000.0);
+        createArtist(3000.0);
+
+        ProcedureQuery q = new ProcedureQuery(SELECT_STORED_PROCEDURE);
+        q.addParameter("aName", "An Artist");
+        q.addParameter("paintingPrice", new Integer(3000));
+        q.setFetchOffset(2);
+        List artists = runProcedureSelect(q);
+
+        assertEquals(1, artists.size());
+    }
+
+
     public void testOutParams() throws Exception {
         if (!getAccessStackAdapter().supportsStoredProcedures()) {
             return;



Mime
View raw message