cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r709930 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/jdbc/ dba/hsqldb/ dba/mysql/ dba/oracle/ dba/postgres/
Date Sun, 02 Nov 2008 20:59:47 GMT
Author: aadamchik
Date: Sun Nov  2 12:59:47 2008
New Revision: 709930

URL: http://svn.apache.org/viewvc?rev=709930&view=rev
Log:
Add LIMIT / OFFSET clause generation method to SelectTranslator lifecycle

fixing in-memory offset processing for DBs that do not support the OFFSET clause and are suppressing
distinct

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/LimitResultIterator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.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

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=709930&r1=709929&r2=709930&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 Nov  2 12:59:47 2008
@@ -27,7 +27,6 @@
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.QueryLogger;
-import org.apache.cayenne.access.ResultIterator;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.Query;
@@ -70,9 +69,7 @@
         long t1 = System.currentTimeMillis();
 
         QueryMetadata metadata = query.getMetaData(getEntityResolver());
-        int i = getInitialCursorPosition(metadata.getFetchOffset());
-        while (i-- > 0 && resultSet.next())
-            ;
+       
 
         JDBCResultIterator resultReader = new JDBCResultIterator(
                 null,
@@ -80,7 +77,7 @@
                 resultSet,
                 descriptor);
         
-        LimitResultIterator it = new LimitResultIterator(resultReader,metadata.getFetchLimit());
+        LimitResultIterator it = new LimitResultIterator(resultReader, getInMemoryOffset(metadata.getFetchOffset()),
metadata.getFetchLimit());
 
         if (!delegate.isIteratedResult()) {
             List<DataRow> resultRows = it.dataRows(false);
@@ -116,7 +113,7 @@
      * 
      * @since 3.0
      */
-    protected int getInitialCursorPosition(int queryOffset) {
+    protected int getInMemoryOffset(int queryOffset) {
         return queryOffset;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java?rev=709930&r1=709929&r2=709930&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/LimitResultIterator.java
Sun Nov  2 12:59:47 2008
@@ -39,21 +39,31 @@
     protected Map<String, Object> nextDataObjectIds;
     
     protected int fetchLimit;
+    protected int offset;
     protected int fetchedSoFar  ;
 
     protected boolean nextRow;
     
-    public LimitResultIterator (ResultIterator wrappedIterator,int fetchLimit)
+    public LimitResultIterator (ResultIterator wrappedIterator, int offset, int fetchLimit)
         throws CayenneException{
         
         if (wrappedIterator == null) {
             throw new CayenneException("Null wrapped iterator.");
         }
         this.wrappedIterator = wrappedIterator;
+        this.offset = offset;
         this.fetchLimit = fetchLimit;
+        
+        checkOffset();
         checkNextRow();
         
     }
+    
+    private void checkOffset() throws CayenneException {
+        for (int i = 0; i < offset && wrappedIterator.hasNextRow(); i++) {
+            wrappedIterator.nextDataRow();
+        }
+    }
 
     private void checkNextRow() throws CayenneException {
         nextRow = false;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java?rev=709930&r1=709929&r2=709930&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
Sun Nov  2 12:59:47 2008
@@ -216,10 +216,6 @@
             long startTime) throws Exception {
 
         boolean iteratedResult = callback.isIteratedResult();
-
-        int i = getFetchOffset();
-        while (i-- > 0 && resultSet.next())
-            ;
         
         ExtendedTypeMap types = adapter.getExtendedTypes();
         RowDescriptorBuilder builder = configureRowDescriptorBuilder(compiled, resultSet);
@@ -230,7 +226,7 @@
                 resultSet,
                 builder.getDescriptor(types));
         
-        LimitResultIterator it = new LimitResultIterator(result,query.getFetchLimit());
+        LimitResultIterator it = new LimitResultIterator(result, getFetchOffset(), query.getFetchLimit());
         
         if (!iteratedResult) {
             List<DataRow> resultRows = it.dataRows(false);

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=709930&r1=709929&r2=709930&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 Nov  2 12:59:47 2008
@@ -72,10 +72,6 @@
         PreparedStatement prepStmt = translator.createStatement();
         ResultSet rs = prepStmt.executeQuery();
 
-        int i = getInitialCursorPosition(query.getFetchOffset());
-        while (i-- > 0 && rs.next())
-            ;
-
         RowDescriptor descriptor = new RowDescriptorBuilder().setColumns(
                 translator.getResultColumns()).getDescriptor(
                 getAdapter().getExtendedTypes());
@@ -143,11 +139,10 @@
         // result count does not directly correspind to the number of objects returned
         // from Cayenne.
 
-        // TODO: andrus, 11/2/2008 - shoudn't we apply the same rules to OFFSET
-        // processing?
         int fetchLimit = query.getFetchLimit();
-        if (fetchLimit > 0) {
-            it = new LimitResultIterator(it, fetchLimit);
+        int offset = getInMemoryOffset(query.getFetchOffset());
+        if (fetchLimit > 0 || offset > 0) {
+            it = new LimitResultIterator(it, offset, fetchLimit);
         }
 
         // TODO: Should do something about closing ResultSet and PreparedStatement in this

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=709930&r1=709929&r2=709930&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 Nov  2 12:59:47 2008
@@ -36,7 +36,7 @@
     }
 
     @Override
-    protected int getInitialCursorPosition(int queryOffset) {
+    protected int getInMemoryOffset(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=709930&r1=709929&r2=709930&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 Nov  2 12:59:47 2008
@@ -36,7 +36,7 @@
     }
 
     @Override
-    protected int getInitialCursorPosition(int queryOffset) {
+    protected int getInMemoryOffset(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=709930&r1=709929&r2=709930&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 Nov  2 12:59:47 2008
@@ -49,7 +49,7 @@
     }
 
     @Override
-    protected int getInitialCursorPosition(int queryOffset) {
+    protected int getInMemoryOffset(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=709930&r1=709929&r2=709930&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 Nov  2 12:59:47 2008
@@ -37,7 +37,7 @@
     }
 
     @Override
-    protected int getInitialCursorPosition(int queryOffset) {
+    protected int getInMemoryOffset(int queryOffset) {
         return 0;
     }
 



Mime
View raw message