This commit is contained in:
@@ -532,7 +532,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的int值 例如请求URL /pipes/record/query/start:0/size:50 获取page参数: int start = request.getRequstURIPath("start:", 0); 获取size参数: int size = request.getRequstURIPath("size:", 20);
|
||||
* 获取请求URL分段中含prefix段的int值 例如请求URL /pipes/record/query/offset:0/limit:50 获取limit参数: int offset = request.getRequstURIPath("offset:", 0); 获取size参数: int limit = request.getRequstURIPath("limit:", 20);
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认int值
|
||||
|
||||
@@ -19,6 +19,23 @@ import javax.sql.ConnectionPoolDataSource;
|
||||
import javax.xml.stream.*;
|
||||
import org.redkale.util.*;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
import static org.redkale.source.FilterNode.formatToString;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -1830,11 +1847,11 @@ public final class DataDefaultSource implements DataSource, Function<Class, Enti
|
||||
final String sql = "SELECT a.* FROM " + info.getTable() + " a" + (join == null ? "" : join)
|
||||
+ ((where == null || where.length() == 0) ? "" : (" WHERE " + where)) + info.createSQLOrderby(flipper);
|
||||
if (debug.get() && info.isLoggable(Level.FINEST))
|
||||
logger.finest(clazz.getSimpleName() + " query sql=" + sql + (flipper == null ? "" : (" LIMIT " + flipper.getStart() + "," + flipper.getSize())));
|
||||
logger.finest(clazz.getSimpleName() + " query sql=" + sql + (flipper == null ? "" : (" LIMIT " + flipper.getOffset() + "," + flipper.getLimit())));
|
||||
final PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
final ResultSet set = ps.executeQuery();
|
||||
if (flipper != null && flipper.getStart() > 0) set.absolute(flipper.getStart());
|
||||
final int limit = flipper == null ? Integer.MAX_VALUE : flipper.getSize();
|
||||
if (flipper != null && flipper.getOffset() > 0) set.absolute(flipper.getOffset());
|
||||
final int limit = flipper == null ? Integer.MAX_VALUE : flipper.getLimit();
|
||||
int i = 0;
|
||||
while (set.next()) {
|
||||
i++;
|
||||
|
||||
@@ -303,7 +303,7 @@ public final class EntityCache<T> {
|
||||
Stream<T> stream = this.list.stream();
|
||||
if (filter != null) stream = stream.filter(filter);
|
||||
if (comparator != null) stream = stream.sorted(comparator);
|
||||
if (flipper != null) stream = stream.skip(flipper.getStart()).limit(flipper.getSize());
|
||||
if (flipper != null) stream = stream.skip(flipper.getOffset()).limit(flipper.getLimit());
|
||||
final List<T> rs = new ArrayList<>();
|
||||
if (selects == null) {
|
||||
Consumer<? super T> action = x -> rs.add(needcopy ? newReproduce.copy(creator.create(), x) : x);
|
||||
|
||||
@@ -16,89 +16,89 @@ import java.io.Serializable;
|
||||
*/
|
||||
public final class Flipper implements Serializable, Cloneable {
|
||||
|
||||
public static int DEFAULT_PAGESIZE = 20;
|
||||
public static int DEFAULT_LIMIT = 20;
|
||||
|
||||
private int size = DEFAULT_PAGESIZE;
|
||||
private int limit = DEFAULT_LIMIT;
|
||||
|
||||
private int start = 0;
|
||||
private int offset = 0;
|
||||
|
||||
private String sort = "";
|
||||
|
||||
public Flipper() {
|
||||
}
|
||||
|
||||
public Flipper(int pageSize) {
|
||||
this.size = pageSize;
|
||||
public Flipper(int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public Flipper(String sortColumn) {
|
||||
this.sort = sortColumn;
|
||||
}
|
||||
|
||||
public Flipper(int pageSize, int startIndex) {
|
||||
this.size = pageSize > 0 ? pageSize : DEFAULT_PAGESIZE;
|
||||
this.start = startIndex < 0 ? 0 : startIndex;
|
||||
public Flipper(int limit, int offset) {
|
||||
this.limit = limit > 0 ? limit : DEFAULT_LIMIT;
|
||||
this.offset = offset < 0 ? 0 : offset;
|
||||
}
|
||||
|
||||
public Flipper(int pageSize, int startIndex, String sortColumn) {
|
||||
this.size = pageSize > 0 ? pageSize : DEFAULT_PAGESIZE;
|
||||
this.start = startIndex < 0 ? 0 : startIndex;
|
||||
public Flipper(int limit, int offset, String sortColumn) {
|
||||
this.limit = limit > 0 ? limit : DEFAULT_LIMIT;
|
||||
this.offset = offset < 0 ? 0 : offset;
|
||||
this.sort = sortColumn;
|
||||
}
|
||||
|
||||
public void copyTo(Flipper copy) {
|
||||
if (copy == null) return;
|
||||
copy.start = this.start;
|
||||
copy.size = this.size;
|
||||
copy.offset = this.offset;
|
||||
copy.limit = this.limit;
|
||||
copy.sort = this.sort;
|
||||
}
|
||||
|
||||
public void copyFrom(Flipper copy) {
|
||||
if (copy == null) return;
|
||||
this.start = copy.start;
|
||||
this.size = copy.size;
|
||||
this.offset = copy.offset;
|
||||
this.limit = copy.limit;
|
||||
this.sort = copy.sort;
|
||||
}
|
||||
|
||||
public Flipper next() {
|
||||
this.start = getStart() + this.size;
|
||||
this.offset = getOffset() + this.limit;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("CloneDoesntCallSuperClone")
|
||||
public Flipper clone() {
|
||||
return new Flipper(this.size, this.start, this.sort);
|
||||
return new Flipper(this.limit, this.offset, this.sort);
|
||||
}
|
||||
|
||||
public int getStart() {
|
||||
return start;
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "{start:" + this.start + ", size=" + this.size + ", sort=" + this.sort + "}";
|
||||
return this.getClass().getSimpleName() + "{offset:" + this.offset + ", limit:" + this.limit + ", sort:" + this.sort + "}";
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
public int getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
if (size > 0) {
|
||||
this.size = size;
|
||||
public void setLimit(int limit) {
|
||||
if (limit > 0) {
|
||||
this.limit = limit;
|
||||
}
|
||||
}
|
||||
|
||||
public void setStart(int start) {
|
||||
this.start = start < 0 ? 0 : start;
|
||||
public void setOffset(int offset) {
|
||||
this.offset = offset < 0 ? 0 : offset;
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public Flipper sortIfEmpty(String sort) {
|
||||
public Flipper sortIfAbsent(String sort) {
|
||||
if (this.sort == null || this.sort.isEmpty()) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user