Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:34:20+00:00 2026-06-08T18:34:20+00:00

I need help in the following design. I expose a web method that does

  • 0

I need help in the following design. I expose a web method that does an SQL select from a database. The problem is that the number of records can be huge and I don’t want to return all of the records in a single call.
So I can think of these options (to return the result in pages):
1) Provide a method with parameters so that the client requests recordStart and recordEnd each time.
2) Modify the method to accept a resultset of size X and somehow understand that each request is not a new one but return the next X records. To figure this out somekind of a token could be associated per client but the problem is I am not sure how long should this token be kept and then disposed of so as to treat an incoming request either as a first request or a continuation of a previous one.

So which design should I go for and how would I solve any relevant problems I mention?
Are there better ways to deal with these problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:34:23+00:00Added an answer on June 8, 2026 at 6:34 pm

    From my point of view:

    • each request may be encapsulated in a request object that basically will hold an offset and a page size;
    • each response may be encapsulated in a response object that basically will have a result list and a total, alternatively you could hold the request object used to build the response;

    Your interface to perform the selection on database will be similar to:

    public PageResponse getPage(PageRequest pageRequest);
    

    This approach turns easy the extension of your paging method, imagine in a few months you need to implement a sort to that method, you will need to change each invocation to it. With this approach you change the PageRequest object and gives a default sort, nothing will be broken and you can customize sort just in the invocation that really needs it.

    Within this method you will need two different DataBase selections:

    • one in order to retrieve the selection list (the one that will be hold by the response and accessed through the property resultList), this can be done using feature specific for each database to limit your result set (top for sybase, limit for mysql and PG, rownum with Oracle, this will vary from one database to other);
    • another one to get the total of selected records without paging, in order to perform paging of your data in case of big data sets.

    A good reference for your problem would be Spring Data, they have Page and PageRequest that is more or less what you need. Maybe you could use their API to implement your solution.


    Practically your request object could looks like:

    public class PageRequest {
    
        private int offset;
        private int pageSize;
    
        // getters and setters and convenience constructors with the given fields
    
    }
    
    public class PageResponse {
    
        private List<?> resultList;
        private int total;
    
        // getters and setters and convenience constructors with the given fields
    
    }
    

    Of course you could play a bit with Generics too in order to have response holding types you already requested, facilitating use of the response object like:

    public <T> PageResponse<T> getPage(PageRequest<T> pageRequest);
    

    having the objects for Request and Response like:

    public class PageRequest<T> {
    
        private int offset;
        private int pageSize;
    
        // getters and setters and convenience constructors with the given fields
    
    }
    
    public class PageResponse<T> {
    
        private List<T> resultList;
        private int total;
    
        // getters and setters and convenience constructors with the given fields
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help on the best way to design a database/tables for the following
I believe that I am having a bad database design and need some help
I need help with improving the performance of the following SQL query. The database
I need your help with my database design. I'm trying to develop a Result
I need help to design the best data structure for a GRAPH. The following
I need help with the following design. Basically I have a Main form which
I need help doing the following: a preprocessor macro label(x) shall output #x, e.g.,
I'm fixing bugs for some application, and I need help understanding the following lines
I need some help extracting the following bits of information using regular expressions. Here
I need syntax help with the following code logic: I have a code block

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.