4.10. Large Result Sets

By default, Kodo uses standard forward-only JDBC result sets, and completely instantiates the results of database queries on execution. When using a JDBC driver that supports version 2.0 or higher of the JDBC specification, however, you can configure Kodo to use scrolling result sets that may not bring all results into memory at once. You can also configure the number of result objects Kodo keeps references to, allowing you to traverse potentially enormous amounts of data without exhausting JVM memory.


You can also configure on-demand loading for individual collection and map fields via large result set proxies. See Section, “Large Result Set Proxies”.

Use the following properties to configure Kodo's handling of result sets:

Example 4.14. Specifying Result Set Defaults

JPA XML format:

<property name="kodo.FetchBatchSize" value="20"/>
<property name="kodo.jdbc.ResultSetType" value="scroll-insensitive"/>
<property name="kodo.jdbc.FetchDirection" value="forward"/>
<property name="kodo.jdbc.LRSSize" value="last"/>

JDO properties format:

kodo.FetchBatchSize: 20
kodo.jdbc.ResultSetType: scroll-insensitive
kodo.jdbc.FetchDirection: forward
kodo.jdbc.LRSSize: last

Many Kodo runtime components also have methods to configure these properties on a case-by-case basis through their fetch configuration. See Chapter 9, Runtime Extensions.

Example 4.15. Specifying Result Set Behavior at Runtime


import java.sql.*;
import kodo.persistence.jdbc.*;


Query q = em.createQuery ("select m from Magazine m where m.title = 'JDJ'");
KodoQuery kq = KodoPersistence.cast (q);
JDBCFetchPlan fetch = (JDBCFetchPlan) kq.getFetchPlan ();
fetch.setFetchSize (20);
fetch.setResultSetType (ResultSet.TYPE_SCROLL_INSENSITIVE);
fetch.setFetchDirection (ResultSet.FETCH_FORWARD);
fetch.setLRSSize (JDBCFetchPlan.SIZE_LAST);
List results = (List) q.getResultList ();


import java.sql.*;
import kodo.jdo.jdbc.*;


Query q = pm.newQuery (Magazine.class, "title == 'JDJ'");
JDBCFetchPlan fetch = (JDBCFetchPlan) q.getFetchPlan ();
fetch.setFetchSize (20);
fetch.setResultSetType (ResultSet.TYPE_SCROLL_INSENSITIVE);
fetch.setFetchDirection (ResultSet.FETCH_FORWARD);
fetch.setLRSSize (JDBCFetchPlan.SIZE_LAST);
List results = (List) q.execute ();


Skip navigation bar   Back to Top