This is an automated email from the ASF dual-hosted git repository.

mgentry pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne-website.git


The following commit(s) were added to refs/heads/master by this push:
     new c49d819  Added MySQL-specific instructions for iterated queries.
c49d819 is described below

commit c49d8193a66af6c46cea674223afe6d2f37a12d6
Author: Michael Gentry <blackn...@gmail.com>
AuthorDate: Thu Apr 16 21:05:34 2020 -0400

    Added MySQL-specific instructions for iterated queries.
---
 src/main/site/content/docs/4.1/cayenne-guide.html | 40 +++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/main/site/content/docs/4.1/cayenne-guide.html 
b/src/main/site/content/docs/4.1/cayenne-guide.html
index d2d3f1c..528b856 100644
--- a/src/main/site/content/docs/4.1/cayenne-guide.html
+++ b/src/main/site/content/docs/4.1/cayenne-guide.html
@@ -2444,10 +2444,46 @@ for(DataRow row : rows) {
     <h4 id="iterated-queries"><a class="anchor" 
href="#iterated-queries"></a>2.8.4. Iterated Queries</h4> 
     <div class="paragraph"> 
      <p>While contemporary hardware may easily allow applications to fetch 
hundreds of thousands or even millions of objects into memory, it doesn’t mean 
this is always a good idea to do so. You can optimize processing of very large 
result sets with two techniques discussed in this and the following chapter - 
iterated and paginated queries.</p> 
-    </div> 
+    </div>
     <div class="paragraph"> 
      <p>Iterated query is not actually a special query. Any selecting query 
can be executed in iterated mode by an ObjectContext. ObjectContext creates an 
object called <code>ResultIterator</code> that is backed by an open ResultSet. 
Iterator provides constant memory performance for arbitrarily large ResultSets. 
This is true at least on the Cayenne end, as JDBC driver may still decide to 
bring the entire ResultSet into the JVM memory.</p> 
-    </div> 
+    </div>
+    <div class="admonitionblock note"> 
+        <table> 
+            <tbody>
+                <tr>
+                    <td class="icon"> <i class="fa fa-info-circle fa-2x" 
title="Note"></i> </td> 
+                    <td class="content">
+                        <div>
+                            The MySQL JDBC driver is known to pull the entire 
ResultSet into memory.
+                            In order to get the driver to stream the results, 
append the JDBC parameter
+                            <code class="language-java java" 
data-lang="java">useCursorFetch=true</code>
+                            to the JDBC URL.
+                        </div>
+                        <br/>
+                        <div>
+                            A fetch size must also be set when doing the query 
using
+                            <code class="language-java java" 
data-lang="java">ObjectSelect.statementFetchSize(..)</code>,
+                            for example:
+                        </div>
+                        <div class="listingblock">
+                            <div class="content">
+                                <pre class="highlight" style="margin-bottom: 
0px">
+                                    <code class="language-Java Java" 
data-lang="Java" style="font-size: 120%">ObjectSelect.query(queryClass)
+    .statementFetchSize(50000)
+    .iterate(objectContext, cayenneObject -> ...</code>
+                                </pre>
+                            </div> 
+                        </div> 
+                        <div>
+                            Adjust the value of the fetch size to fit 
requirements.  A larger value is more
+                            performant, but consumes more memory as well.
+                        </div>
+                    </td>
+                </tr> 
+            </tbody>
+        </table> 
+    </div>
     <div class="paragraph"> 
      <p>Data is read from ResultIterator one row/object at a time until it is 
exhausted. There are two styles of accessing ResultIterator - direct access 
which requires explicit closing to avoid JDBC resources leak, or a callback 
that lets Cayenne handle resource management. In both cases iteration can be 
performed using "for" loop, as ResultIterator is "Iterable".</p> 
     </div> 

Reply via email to