Created
November 20, 2014 08:21
-
-
Save gurbuzali/cc633e7f7d974b80f551 to your computer and use it in GitHub Desktop.
paging-predicate-test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static void testPagingPredicate() { | |
| HazelcastInstance instance = Hazelcast.newHazelcastInstance(); | |
| IMap<Object, Object> map = instance.getMap("map"); | |
| for (int i = 0; i < 20; i++) { | |
| map.put(i, i); | |
| } | |
| PagingPredicate pagingPredicate = getPagingPredicate(0, 10, null); | |
| Collection<Object> values = map.values(pagingPredicate); | |
| for (Object value : values) { | |
| System.err.println("value: " + value); | |
| } | |
| System.err.println("nextPage"); | |
| pagingPredicate.nextPage(); | |
| values = map.values(pagingPredicate); | |
| for (Object value : values) { | |
| System.err.println("value: " + value); | |
| } | |
| } | |
| public static PagingPredicate getPagingPredicate(int offset, int limit, SqlPredicate sqlPredicate) { | |
| final int pageSize = limit - offset; | |
| final PagingPredicate pagingPredicate; | |
| if (sqlPredicate == null) { | |
| pagingPredicate = new PagingPredicate(pageSize); | |
| } else { | |
| pagingPredicate = new PagingPredicate(sqlPredicate, pageSize); | |
| } | |
| if (pagingPredicate.getPageSize() >= 0) { | |
| for (int index = 0; index < offset; index = index + pageSize) { | |
| pagingPredicate.nextPage(); | |
| } | |
| } | |
| return pagingPredicate; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment