forked from ImangazalievM/ReActiveAndroid
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Pagination.java
65 lines (46 loc) 路 1.57 KB
/
Pagination.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.reactiveandroid.query.api;
//pull request - bendothall
//Pagination API
import android.util.Log;
import com.reactiveandroid.query.QueryBase;
import com.reactiveandroid.query.Select;
import java.util.ArrayList;
import java.util.List;
public class Pagination<T> extends QueryBase<T> {
private Pagination() {
super(null, null);
}
public static int getTableRowCount(Class<?> table) {
if (table == null) {
throw new IllegalArgumentException("Database Table referenced not found.");
}
return Select.from(table).count();
}
public static List loadPaginationData(
String tableColumn,
int offset,
int limit,
String orderBy,
Class<?> table
){
if (tableColumn == null) {
throw new IllegalArgumentException("Database Table must be set");
}
if (limit == 0) {
throw new IllegalArgumentException("Limit cannot be set to 0");
}
if (orderBy == null || !(orderBy.contains("DESC") || orderBy.contains("ASC")) ) {
throw new IllegalArgumentException("Order must be set to DESC or ASC " + orderBy);
}
if (table == null) {
throw new IllegalArgumentException("Database Table Class referenced not found.");
}
List result = new ArrayList<>();
result = Select.from(table)
.orderBy(tableColumn + " " + orderBy)
.limit(limit)
.offset(offset)
.fetch();
return result;
}
}