#679 - Remove SqlQuery.setListener() ... migrate to SqlQuery.findEach() or SqlQuery.findEachWhile()

This commit is contained in:
Robin Bygrave
2016-04-29 08:43:30 +12:00
parent f867cd4c01
commit 840c5f8992
6 changed files with 1 additions and 105 deletions
@@ -102,19 +102,6 @@ public interface SqlQuery extends Serializable {
*/
SqlQuery setParameter(int position, Object value);
/**
* Set a listener to process the query on a row by row basis.
* <p>
* It this case the rows are not loaded into the persistence context and
* instead can be processed by the query listener.
* </p>
* <p>
* Use this when you want to process a large query and do not want to hold the
* entire query result in memory.
* </p>
*/
SqlQuery setListener(SqlQueryListener queryListener);
/**
* Set the index of the first row of the results to return.
*/
@@ -1,33 +0,0 @@
package com.avaje.ebean;
/**
* Provides a mechanism for processing a SqlQuery one SqlRow at a time.
* <p>
* This is useful when the query will return a large number of results and you
* want to process the beans one at a time rather than have all of the beans in
* memory at once.
* </p>
*
* <pre class="code">
* SqlQueryListener listener = ...;
*
* SqlQuery query = Ebean.createSqlQuery(&quot;my.large.query&quot;);
*
* // set the listener that will process each row one at a time
* query.setListener(listener);
*
* // execute the query. Note that the returned
* // list will be empty ... so don't bother assigning it...
* query.findList();
* </pre>
*/
public interface SqlQueryListener {
/**
* Process the bean that has just been read.
* <p>
* Note this bean will not be added to the List Set or Map.
* </p>
*/
void process(SqlRow bean);
}
@@ -3,7 +3,6 @@ package com.avaje.ebeaninternal.api;
import java.sql.PreparedStatement;
import com.avaje.ebean.SqlQuery;
import com.avaje.ebean.SqlQueryListener;
/**
* SQL query - Internal extension to SqlQuery.
@@ -20,11 +19,6 @@ public interface SpiSqlQuery extends SqlQuery {
*/
String getQuery();
/**
* Return the queryListener.
*/
SqlQueryListener getListener();
/**
* Return the first row to fetch.
*/
@@ -2,7 +2,6 @@ package com.avaje.ebeaninternal.server.query;
import com.avaje.ebean.QueryEachConsumer;
import com.avaje.ebean.QueryEachWhileConsumer;
import com.avaje.ebean.SqlQueryListener;
import com.avaje.ebean.SqlRow;
import com.avaje.ebeaninternal.api.SpiSqlQuery;
import com.avaje.ebeaninternal.server.core.Message;
@@ -90,7 +89,6 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
List<SqlRow> rows = new ArrayList<SqlRow>();
SpiSqlQuery query = request.getQuery();
SqlQueryListener listener = query.getListener();
while (request.next()) {
SqlRow bean;
@@ -101,11 +99,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
bean = readRow(request);
}
if (bean != null) {
if (listener != null) {
listener.process(bean);
} else {
rows.add(bean);
}
rows.add(bean);
loadRowCount++;
if (loadRowCount == maxRows) {
// break, as we have hit the max rows to fetch...
@@ -4,7 +4,6 @@ import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.QueryEachConsumer;
import com.avaje.ebean.QueryEachWhileConsumer;
import com.avaje.ebean.SqlFutureList;
import com.avaje.ebean.SqlQueryListener;
import com.avaje.ebean.SqlRow;
import com.avaje.ebeaninternal.api.BindParams;
import com.avaje.ebeaninternal.api.SpiSqlQuery;
@@ -23,8 +22,6 @@ public class DefaultRelationalQuery implements SpiSqlQuery {
private final transient EbeanServer server;
private transient SqlQueryListener queryListener;
private String query;
private int firstRow;
@@ -94,26 +91,6 @@ public class DefaultRelationalQuery implements SpiSqlQuery {
return this;
}
/**
* Return the findListener is one has been set.
*/
public SqlQueryListener getListener() {
return queryListener;
}
/**
* Set a listener. This is designed for large fetches
* where lots are rows are to be processed and instead of
* returning all the rows they are processed one at a time.
* <p>
* Note that the returning List Set or Map will be empty.
* </p>
*/
public DefaultRelationalQuery setListener(SqlQueryListener queryListener) {
this.queryListener = queryListener;
return this;
}
public String toString() {
return "SqlQuery [" + query + "]";
}