Fix for #86 - v4 - Remove deprecated QueryListener. You must convert to findIterate() or findVisit()

This commit is contained in:
Rob Bygrave
2014-04-20 17:18:13 +12:00
parent 811d298355
commit 18d9c53ce3
9 changed files with 13 additions and 161 deletions
@@ -259,15 +259,6 @@ public interface ExpressionList<T> extends Serializable {
*/
public Query<T> setMapKey(String mapKey);
/**
* Please migrate to using {@link #findIterate()} or {@link #findVisit(QueryResultVisitor)}.
* Set a QueryListener for bean by bean processing.
*
* @see Query#setListener(QueryListener)
* @deprecated Migrate to {@link #findIterate()} or {@link #findVisit(QueryResultVisitor)}
*/
public Query<T> setListener(QueryListener<T> queryListener);
/**
* Set to true to use the query for executing this query.
*
-30
View File
@@ -663,36 +663,6 @@ public interface Query<T> extends Serializable {
*/
public Query<T> setParameter(int position, Object value);
/**
* Please migrate to using {@link #findIterate()} or {@link #findVisit(QueryResultVisitor)}
* <p>
* Set a listener to process the query on a row by row basis.
* </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>
* <p>
* It this case the rows are not loaded into the persistence context and
* instead are processed by the query listener.
* </p>
*
* <pre class="code">
* QueryListener&lt;Order&gt; listener = ...;
*
* Query&lt;Order&gt; query = Ebean.createQuery(Order.class);
*
* // set the listener that will process each order one at a time
* query.setListener(listener);
*
* // execute the query. Note that the returned
* // list (emptyList) will be empty ...
* List&lt;Order&gt; emtyList = query.findList();
* </pre>
* @deprecated Deprecated in favor of {@link #findIterate()} and {@link #findVisit(QueryResultVisitor)}
*/
public Query<T> setListener(QueryListener<T> queryListener);
/**
* Set the Id value to query. This is used with findUnique().
* <p>
@@ -1,43 +0,0 @@
package com.avaje.ebean;
/**
* Deprecated, please migrate to using {@link #findIterate()} or {@link #findVisit(QueryResultVisitor)}
* <p>
* Provides a mechanism for processing a query one bean at a time.
* </p>
* <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 whole all of the beans in
* memory at once.
* </p>
*
* <pre class="code">
* QueryListener&lt;Order&gt; listener = ...;
*
* Query&lt;Order&gt; query = Ebean.createQuery(Order.class);
*
* // set the listener that will process each order 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>
*
* @param <T>
* the type of entity bean
* @deprecated Please migrate to using {@link #findIterate()} or
* {@link #findVisit(QueryResultVisitor)}
*/
public interface QueryListener<T> {
/**
* Process the bean that has just been read.
* <p>
* This bean will not be added to the List Set or Map and nor will it be put
* into the PersistenceContext. This is what makes this a good way to process
* a large result set (which could normally use a lot of memory).
* </p>
*/
public void process(T bean);
}
@@ -6,7 +6,6 @@ import java.util.List;
import com.avaje.ebean.ExpressionList;
import com.avaje.ebean.OrderBy;
import com.avaje.ebean.Query;
import com.avaje.ebean.QueryListener;
import com.avaje.ebean.bean.BeanCollectionTouched;
import com.avaje.ebean.bean.CallStack;
import com.avaje.ebean.bean.EntityBean;
@@ -545,11 +544,6 @@ public interface SpiQuery<T> extends Query<T> {
*/
public Object getId();
/**
* Return the queryListener.
*/
public QueryListener<T> getListener();
/**
* Return true if this query should use its own transaction.
* <p>
@@ -14,7 +14,6 @@ import com.avaje.ebean.Junction;
import com.avaje.ebean.OrderBy;
import com.avaje.ebean.PagingList;
import com.avaje.ebean.QueryIterator;
import com.avaje.ebean.QueryListener;
import com.avaje.ebean.QueryResultVisitor;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
@@ -383,11 +382,6 @@ abstract class JunctionExpression<T> implements Junction<T>, SpiExpression, Expr
return exprList.setFirstRow(firstRow);
}
@Deprecated
public com.avaje.ebean.Query<T> setListener(QueryListener<T> queryListener) {
return exprList.setListener(queryListener);
}
public com.avaje.ebean.Query<T> setMapKey(String mapKey) {
return exprList.setMapKey(mapKey);
}
@@ -12,8 +12,8 @@ import javax.persistence.PersistenceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.avaje.ebean.QueryIterator;
import com.avaje.ebean.QueryListener;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollectionAdd;
import com.avaje.ebean.bean.EntityBean;
@@ -23,7 +23,6 @@ import com.avaje.ebean.bean.NodeUsageListener;
import com.avaje.ebean.bean.ObjectGraphNode;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebeaninternal.api.LoadContext;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiExpressionList;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.api.SpiQuery.Mode;
@@ -40,7 +39,6 @@ import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
import com.avaje.ebeaninternal.server.transaction.DefaultPersistenceContext;
import com.avaje.ebeaninternal.server.type.DataBind;
import com.avaje.ebeaninternal.server.type.DataReader;
@@ -135,8 +133,6 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
private final SpiQuery<T> query;
private final QueryListener<T> queryListener;
private Map<String, String> currentPathMap;
private String currentPrefix;
@@ -277,20 +273,10 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
this.desc = request.getBeanDescriptor();
this.predicates = predicates;
this.queryListener = query.getListener();
if (queryListener == null) {
// normal, use the one from the transaction
this.persistenceContext = request.getPersistenceContext();
} else {
// 'Row Level Transaction Context'...
// local transaction context that will be reset
// after each 'master' bean is sent to the listener
this.persistenceContext = new DefaultPersistenceContext();
}
this.persistenceContext = request.getPersistenceContext();
this.maxRowsLimit = query.getMaxRows() > 0 ? query.getMaxRows() : GLOBAL_ROW_LIMIT;
this.backgroundFetchAfter = query.getBackgroundFetchAfter() > 0 ? query
.getBackgroundFetchAfter() : Integer.MAX_VALUE;
this.backgroundFetchAfter = query.getBackgroundFetchAfter() > 0 ? query.getBackgroundFetchAfter() : Integer.MAX_VALUE;
this.help = createHelp(request);
this.collection = (BeanCollection<T>) (help != null ? help.createEmpty(false) : null);
@@ -687,13 +673,8 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
@SuppressWarnings("unchecked")
private void readTheRows(boolean inForeground) throws SQLException {
while (hasNextBean(inForeground)) {
if (queryListener != null) {
queryListener.process((T)getLoadedBean());
} else {
// add to the list/set/map
help.add(collection, getLoadedBean());
}
// add to the list/set/map
help.add(collection, getLoadedBean());
}
}
@@ -21,7 +21,6 @@ import com.avaje.ebean.OrderBy.Property;
import com.avaje.ebean.PagingList;
import com.avaje.ebean.Query;
import com.avaje.ebean.QueryIterator;
import com.avaje.ebean.QueryListener;
import com.avaje.ebean.QueryResultVisitor;
import com.avaje.ebean.RawSql;
import com.avaje.ebean.bean.BeanCollectionTouched;
@@ -69,8 +68,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
*/
private transient ArrayList<EntityBean> contextAdditions;
private transient QueryListener<T> queryListener;
/**
* For lazy loading of ManyToMany we need to add a join to the intersection
* table. This is that join to the intersection table.
@@ -1016,26 +1013,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return this;
}
/**
* Return the findListener is one has been set.
*/
public QueryListener<T> getListener() {
return queryListener;
}
/**
* Set a FindListener. 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 DefaultOrmQuery<T> setListener(QueryListener<T> queryListener) {
this.queryListener = queryListener;
return this;
}
public Class<T> getBeanType() {
return beanType;
}
@@ -1044,13 +1021,13 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
this.detail = detail;
}
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail) {
return detail.tuneFetchProperties(tunedDetail);
}
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail) {
return detail.tuneFetchProperties(tunedDetail);
}
public OrmQueryDetail getDetail() {
return detail;
}
public OrmQueryDetail getDetail() {
return detail;
}
/**
* Return any beans that should be added to the persistence context prior to
@@ -1244,7 +1221,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
// their own transaction
return false;
}
if (backgroundFetchAfter > 0 || queryListener != null) {
if (backgroundFetchAfter > 0) {
// run in own transaction as we can't know how long
// the background fetching will continue etc
return true;
@@ -17,7 +17,6 @@ import com.avaje.ebean.OrderBy;
import com.avaje.ebean.PagingList;
import com.avaje.ebean.Query;
import com.avaje.ebean.QueryIterator;
import com.avaje.ebean.QueryListener;
import com.avaje.ebean.QueryResultVisitor;
import com.avaje.ebean.event.BeanQueryRequest;
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
@@ -221,11 +220,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return query.setMapKey(mapKey);
}
@Deprecated
public Query<T> setListener(QueryListener<T> queryListener) {
return query.setListener(queryListener);
}
public Query<T> setUseCache(boolean useCache) {
return query.setUseCache(useCache);
}
@@ -14,7 +14,6 @@ import com.avaje.ebean.FutureRowCount;
import com.avaje.ebean.OrderBy;
import com.avaje.ebean.PagingList;
import com.avaje.ebean.Query;
import com.avaje.ebean.QueryListener;
import com.avaje.ebeaninternal.api.SpiExpressionList;
import com.avaje.ebeaninternal.server.expression.FilterExprPath;
@@ -136,11 +135,6 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
return rootQuery.setFirstRow(firstRow);
}
@Deprecated
public Query<T> setListener(QueryListener<T> queryListener) {
return rootQuery.setListener(queryListener);
}
public Query<T> setMapKey(String mapKey) {
return rootQuery.setMapKey(mapKey);
}