diff --git a/org.adempiere.base/src/org/compiere/model/Query.java b/org.adempiere.base/src/org/compiere/model/Query.java
index 9ad02eb43e..3520bc9638 100644
--- a/org.adempiere.base/src/org/compiere/model/Query.java
+++ b/org.adempiere.base/src/org/compiere/model/Query.java
@@ -649,24 +649,6 @@ public class Query
return false;
}
- /**
- * Return an Iterable implementation that can be used in a for expression. Example:
- *
{@code
- * Iterable query = new Query(...).iterable();
- *
- * for (MTable table : query) {
- * // Do stuff with the element
- * }
- *
- *
- * @return Iterable
- * @throws DBException
- */
- public Iterable iterable() throws DBException
- {
- return () -> iterate();
- }
-
/**
* Return an Stream implementation to fetch one PO at a time. This method will only create POs on-demand and
* they will become eligible for garbage collection once they have been consumed by the stream, so unlike
@@ -714,19 +696,51 @@ public class Query
}
/**
- * Return an Iterator implementation to fetch one PO at a time. This implementation is equivalent to
- * stream().iterator() and has similar performance benefits compared with {@link #list()}.
- * Useful if the downstream API requires an Iterator; otherwise the additional
- * of the {@link #stream()} interface is likely to be more useful.
- *
+ * Return an Iterator implementation to fetch one PO at a time. The implementation first retrieve
+ * all IDS that match the query criteria and issue sql query to fetch the PO when caller want to
+ * fetch the next PO. This minimize memory usage but it is slower than the list method.
* @return Iterator
* @throws DBException
- * @see #stream()
*/
- @SuppressWarnings("unchecked")
public Iterator iterate() throws DBException
{
- return (Iterator) stream().iterator();
+ String[] keys = table.getKeyColumns();
+ StringBuilder sqlBuffer = new StringBuilder(" SELECT ");
+ for (int i = 0; i < keys.length; i++) {
+ if (i > 0)
+ sqlBuffer.append(", ");
+ if (!joinClauseList.isEmpty())
+ sqlBuffer.append(table.getTableName()).append(".");
+ sqlBuffer.append(keys[i]);
+ }
+ sqlBuffer.append(" FROM ").append(table.getTableName());
+ String sql = buildSQL(sqlBuffer, true);
+
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+ List