Override findAll() Spring Data Gemfire Repo Queries

心已入冬 提交于 2019-12-25 08:08:33

问题


I have millions of objects populated in GemFire regions. I don't want default findAll() SDR query to be executed to retrieve the millions of objects in one shot. I am trying to figure out if there is a way to override the default findAll query and provide the LIMIT param to restrict the number of objects retrieved from GemFire Regions. Here is an example of what I want to do:

NoRepositoryBean
public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> {

/**
 * Returns all instances of the type.
 * 
 * @return all entities
 */
Iterable<T> findAll();
}


public interface MyRepository extends CrudRepository<MyRepoObject, String> {


@Query("SELECT * FROM MyRegion LIMIT $1")
Iterable<CellTower> findAll(@Param("limit") String limit);

} 

Currently, I am on Spring Data Gemfire 1.4.0.BUILD-SNAPSHOT and Spring Data REST 2.0.0.BUILD-SNAPSHOT version


回答1:


This handy getting started guide on Accessing GemFire Data with REST (https://spring.io/guides/gs/accessing-gemfire-data-rest/) was written not long ago and may help with your particular use case.




回答2:


The following worked for me. Try using an Integer instead of a String as your parameter to findAll

 @Query("SELECT * FROM /Customer LIMIT $1")
    List<Customer> findAll(@Param("limit") Integer max);


来源:https://stackoverflow.com/questions/21942773/override-findall-spring-data-gemfire-repo-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!