mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for Issue 56 - Using findIterate with MySQL streams the entire
result set at once
This commit is contained in:
@@ -343,7 +343,21 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare bind and execute query with Forward only hints.
|
||||
*/
|
||||
public boolean prepareBindExecuteQueryForwardOnly() throws SQLException {
|
||||
return prepareBindExecuteQueryWithOption(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare bind and execute the query normally.
|
||||
*/
|
||||
public boolean prepareBindExecuteQuery() throws SQLException {
|
||||
return prepareBindExecuteQueryWithOption(false);
|
||||
}
|
||||
|
||||
private boolean prepareBindExecuteQueryWithOption(boolean forward) throws SQLException {
|
||||
|
||||
synchronized (this) {
|
||||
if (cancelled || query.isCancelled()) {
|
||||
@@ -357,7 +371,12 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
// prepare
|
||||
SpiTransaction t = request.getTransaction();
|
||||
Connection conn = t.getInternalConnection();
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
if (forward) {
|
||||
// Hints required for mysql for large resultset processing (Issue 56)
|
||||
pstmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
} else {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
}
|
||||
|
||||
if (query.getTimeout() > 0) {
|
||||
pstmt.setQueryTimeout(query.getTimeout());
|
||||
|
||||
@@ -122,7 +122,7 @@ public class CQueryEngine {
|
||||
|
||||
try {
|
||||
|
||||
if (!cquery.prepareBindExecuteQuery()) {
|
||||
if (!cquery.prepareBindExecuteQueryForwardOnly()) {
|
||||
// query has been cancelled already
|
||||
logger.trace("Future fetch already cancelled");
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user