Skip to content

Instantly share code, notes, and snippets.

@bytor99999
Created September 13, 2012 22:58
Show Gist options
  • Save bytor99999/3718376 to your computer and use it in GitHub Desktop.
Save bytor99999/3718376 to your computer and use it in GitHub Desktop.
ThreadLocal object to store page and size info from the client UI to pass down to data access objects. or Anywhere.
package com.perfectworldprogramming.eventgate.utils;
import org.springframework.data.domain.PageRequest;
/**
* User: Mark Spritzler
* Date: 2/5/12
* Time: 10:32 AM
*/
public class PageRequestHandler {
private static ThreadLocal<PageRequest> pageRequestThreadLocal = new ThreadLocal<PageRequest>();
private static int defaultPageSize = 200;
private static int defaultPage = 0;
public static void setPageRequest(int page, int size) {
PageRequest pageRequest = new PageRequest(page, size);
pageRequestThreadLocal.set(pageRequest);
}
public static void setPageRequest(PageRequest pageRequest) {
pageRequestThreadLocal.set(pageRequest);
}
public static PageRequest getPageRequest() {
PageRequest pageRequest = pageRequestThreadLocal.get();
if (pageRequest == null) {
pageRequest = new PageRequest(defaultPage, defaultPageSize);
setPageRequest(pageRequest);
}
return pageRequest;
}
public static void setDefaultPage(int page) {
defaultPage = page;
}
public static void setDefaultPageSize(int pageSize) {
pageSize = pageSize;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment