spring - How to disable count when Specification and Pageable are used together? -


The methods that come with are inadequate, none of them can give me:

 < Code> page's & lt; T & gt; Search all (Specify & lt; T & gt; Specific, Page-worthy Page Eligible) List & lt; T & gt; Search all (Specification & lt; T & gt; spec) list & lt; T & gt; The first method performs the paged query and counting query (Specification & lt; T & gt; spec, sort sort)  

Panning on the next 2 pages does not happen at all. What I want is one of the following:

  slice & lt; T & gt; Search all (Specify & lt; T & gt; Specific, Page-worthy Page Eligible) List & lt; T & gt; Without expanding the JApaSpecificationExecutor, I was able to execute both questions, but this was also a counting query. In my case, it is important to avoid the counting query because it is very expensive. The question is how?   

see findAll (Specification, Pages) and reading Pages (typed diplomacy, page qualified, specialty) Methods It seems that the implementation of the spring always executes a counting query and checks whether the preliminary search query is out of bounds before executing: < / P>

  Protected page & lt; T & gt; ReadPage (TypedQuery & lt; T & gt; Query, PageLable, Specification & lt; T & gt; spec) {query.setFirstResult (pageable.getOffset ()); Query.setMaxResults (pageable.getPageSize ()); Long Total = QueryUtils.executeCountQuery (getCountQuery (spec)); & Lt; T & gt; Content = total & gt; Pageplegateoffet ()? Query.getResultList (): Archive. & Lt; T & gt; EmptyList (); New Pageimple return & lt; T & gt; (Content, page qualified, total); }  

I do not believe that this is always the best practice. In the case of my use, for example, we are happy to execute counter queries once in the future call, because we know that new data is not repeated enough to guarantee a countdown update And calculation is very expensive to execute the query.

The Spring data parameter can provide a flag or an alternative method to disable calculation for the query, so it would be great.

In the mean time, here's my work-around solution:

Simplify the sub-sections of the JPEG repository to make an internal class override readPage to disable the counting query Make a DAO, annotate it with the regeneration and instantiate this internal class to pass the entity manager. Finally, inject this DAO where "no-count" criteria search is not applicable anywhere:

Repository public class criteria NoCountDao {@PersistenceContext protected EntityManager; Public & lt; T, ID serial expanded & gt; The page's & lt; T & gt; Search all (Specification & lt; T & gt; Speak, PageLabel Page Qualified, Class & lt; T & gt; Clause) {Simple Penpanotechnology & lt; T, ID & gt; NoCountDao = New SimplePanocont Repository & lt; T, ID & gt; (Claude, AM); Return noCountDao.findAll (idea, page qualified); } / ** * Custom repository type that disables the count query * / Public static class SimpleJpaNoCountRepository & lt; T, ID serial & gt; Simple zipporatory & lt; T, ID & gt; {Public Simple JPNocontroller Repository (Class <> Domain Class, Entity Manager M) {Super (Domain Class, AM); } / ** * Override {@link SimpleJpaRepository # readPage (typed password, page qualified, specificity)} * / Protected page & lt; T & gt; ReadPage (TypedQuery & lt; T & gt; Query, PageLable, Specification & lt; T & gt; spec) {query.setFirstResult (pageable.getOffset ()); Query.setMaxResults (pageable.getPageSize ()); & Lt; T & gt; Content = query.getResultList (); New Pageimple return & lt; T & gt; (Content, page qualified, content.size ()); }}}

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -