cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r704100 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/dba/hsqldb/ test/java/org/apache/cayenne/access/jdbc/
Date Mon, 13 Oct 2008 12:55:25 GMT
Author: aadamchik
Date: Mon Oct 13 05:55:25 2008
New Revision: 704100

URL: http://svn.apache.org/viewvc?rev=704100&view=rev
Log:
CAY-1110 fetchLimit + DistinctResultIterator = fewer rows in the result 
patch by Dima Loiko - this one works across the board

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/BatchAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.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/HSQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.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=704100&r1=704099&r2=704100&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
Mon Oct 13 05:55:25 2008
@@ -27,6 +27,7 @@
 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;
@@ -77,11 +78,12 @@
                 null,
                 null,
                 resultSet,
-                descriptor,
-                metadata.getFetchLimit());
+                descriptor);
+        
+        LimitResultIterator it = new LimitResultIterator(resultReader,metadata.getFetchLimit());
 
         if (!delegate.isIteratedResult()) {
-            List<DataRow> resultRows = resultReader.dataRows(false);
+            List<DataRow> resultRows = it.dataRows(false);
             QueryLogger
                     .logSelectCount(resultRows.size(), System.currentTimeMillis() - t1);
 
@@ -90,12 +92,12 @@
         else {
             try {
                 resultReader.setClosingConnection(true);
-                delegate.nextDataRows(query, resultReader);
+                delegate.nextDataRows(query, it);
             }
             catch (Exception ex) {
 
                 try {
-                    resultReader.close();
+                    it.close();
                 }
                 catch (CayenneException cex) {
                     // ignore...

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java?rev=704100&r1=704099&r2=704100&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/BatchAction.java
Mon Oct 13 05:55:25 2008
@@ -298,8 +298,7 @@
                 null,
                 null,
                 keysRS,
-                keyRowDescriptor,
-                0);
+                keyRowDescriptor);
 
         observer.nextGeneratedDataRows(query, iterator);
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java?rev=704100&r1=704099&r2=704100&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/JDBCResultIterator.java
Mon Oct 13 05:55:25 2008
@@ -64,8 +64,6 @@
     protected boolean closed;
 
     protected boolean nextRow;
-    protected int fetchedSoFar;
-    protected int fetchLimit;
 
     private String[] labels;
     private int[] types;
@@ -74,14 +72,13 @@
      * Creates new JDBCResultIterator that reads from provided ResultSet.
      */
     public JDBCResultIterator(Connection connection, Statement statement,
-            ResultSet resultSet, RowDescriptor descriptor, int fetchLimit)
+            ResultSet resultSet, RowDescriptor descriptor)
             throws CayenneException {
 
         this.connection = connection;
         this.statement = statement;
         this.resultSet = resultSet;
         this.rowDescriptor = descriptor;
-        this.fetchLimit = fetchLimit;
 
         this.mapCapacity = (int) Math.ceil((descriptor.getWidth()) / 0.75);
 
@@ -143,7 +140,6 @@
 
         // rewind
         checkNextRow();
-
         return row;
     }
 
@@ -193,7 +189,6 @@
 
         // rewind
         checkNextRow();
-
         return id;
     }
 
@@ -270,9 +265,8 @@
     protected void checkNextRow() throws CayenneException {
         nextRow = false;
         try {
-            if ((fetchLimit <= 0 || fetchedSoFar < fetchLimit) && resultSet.next())
{
+            if (resultSet.next()) {
                 nextRow = true;
-                fetchedSoFar++;
             }
         }
         catch (SQLException e) {

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=704100&r1=704099&r2=704100&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
Mon Oct 13 05:55:25 2008
@@ -228,11 +228,12 @@
                 connection,
                 statement,
                 resultSet,
-                builder.getDescriptor(types),
-                query.getFetchLimit());
-
+                builder.getDescriptor(types));
+        
+        LimitResultIterator it = new LimitResultIterator(result,query.getFetchLimit());
+        
         if (!iteratedResult) {
-            List<DataRow> resultRows = result.dataRows(false);
+            List<DataRow> resultRows = it.dataRows(false);
             QueryLogger.logSelectCount(resultRows.size(), System.currentTimeMillis()
                     - startTime);
 
@@ -241,10 +242,10 @@
         else {
             try {
                 result.setClosingConnection(true);
-                callback.nextDataRows(query, result);
+                callback.nextDataRows(query, it);
             }
             catch (Exception ex) {
-                result.close();
+                it.close();
                 throw ex;
             }
         }

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=704100&r1=704099&r2=704100&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
Mon Oct 13 05:55:25 2008
@@ -84,8 +84,7 @@
                 connection,
                 prepStmt,
                 rs,
-                descriptor,
-                query.getFetchLimit());
+                descriptor);
 
         workerIterator.setPostProcessor(DataRowPostProcessor
                 .createPostProcessor(translator));
@@ -137,7 +136,12 @@
                     workerIterator,
                     translator.getRootDbEntity(),
                     compareFullRows[0]);
+            
+            
+            it = new LimitResultIterator(it,query.getFetchLimit());
         }
+        
+        
 
         // TODO: Should do something about closing ResultSet and PreparedStatement in this
         // method, instead of relying on DefaultResultIterator to do that later

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java?rev=704100&r1=704099&r2=704100&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
Mon Oct 13 05:55:25 2008
@@ -32,17 +32,18 @@
     public String createSqlString() throws Exception {
         String sql = super.createSqlString();
         QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
-        
-        // limit results
-        int offset = metadata.getFetchOffset();
-        int limit = metadata.getFetchLimit();
-        
-        if (offset > 0 || limit > 0) {
-            sql += " LIMIT ";
-            if (limit == 0) {
-                limit = Integer.MAX_VALUE;
+        if(!isSuppressingDistinct()){
+            // limit results
+            int offset = metadata.getFetchOffset();
+            int limit = metadata.getFetchLimit();
+            
+            if (offset > 0 || limit > 0) {
+                sql += " LIMIT ";
+                if (limit == 0) {
+                    limit = Integer.MAX_VALUE;
+                }
+                sql += limit + " OFFSET " +  offset; 
             }
-            sql += limit + " OFFSET " +  offset; 
         }
         return sql;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java?rev=704100&r1=704099&r2=704100&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/JDBCResultIteratorTest.java
Mon Oct 13 05:55:25 2008
@@ -68,7 +68,7 @@
                 .setResultSet(rs)
                 .getDescriptor(new ExtendedTypeMap());
 
-        JDBCResultIterator it = new JDBCResultIterator(c, s, rs, descriptor, 0);
+        JDBCResultIterator it = new JDBCResultIterator(c, s, rs, descriptor);
 
         assertFalse(rs.isClosed());
         assertFalse(s.isClosed());
@@ -94,7 +94,7 @@
         RowDescriptor descriptor = new RowDescriptorBuilder()
                 .setResultSet(rs)
                 .getDescriptor(new ExtendedTypeMap());
-        return new JDBCResultIterator(c, s, rs, descriptor, 0);
+        return new JDBCResultIterator(c, s, rs, descriptor);
     }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java?rev=704100&r1=704099&r2=704100&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SelectActionTest.java
Mon Oct 13 05:55:25 2008
@@ -48,7 +48,7 @@
         List<DataRow> resultRows = context.performQuery(select);
 
         assertNotNull(resultRows);
-        // assertEquals(25, resultRows.size());
+        assertEquals(25, resultRows.size());
     }
 
     protected void insertClobDb() {



Mime
View raw message