提交 fcab73c4 编写于 作者: T terrymanu

for #2441, refactor Limit's constructor

上级 9b02c913
......@@ -19,7 +19,6 @@ package org.apache.shardingsphere.core.route.limit;
import lombok.Getter;
import lombok.ToString;
import org.apache.shardingsphere.core.parse.exception.SQLParsingException;
import org.apache.shardingsphere.core.util.NumberUtil;
import java.util.HashMap;
......@@ -37,30 +36,19 @@ import java.util.Map;
@ToString
public final class Limit {
private LimitValue offset;
private final LimitValue offset;
private LimitValue rowCount;
private final LimitValue rowCount;
public Limit(final LimitValue offset, final LimitValue rowCount, final List<Object> parameters) {
this.offset = offset;
this.rowCount = rowCount;
fillParameters(parameters);
}
private void fillParameters(final List<Object> parameters) {
int offset = 0;
if (null != this.offset) {
offset = -1 == this.offset.getIndex() ? getOffsetValue() : NumberUtil.roundHalfUp(parameters.get(this.offset.getIndex()));
this.offset.setValue(offset);
if (null != offset) {
offset.setValue(-1 == offset.getIndex() ? getOffsetValue() : NumberUtil.roundHalfUp(parameters.get(offset.getIndex())));
}
int rowCount = 0;
if (null != this.rowCount) {
rowCount = -1 == this.rowCount.getIndex() ? getRowCountValue() : NumberUtil.roundHalfUp(parameters.get(this.rowCount.getIndex()));
this.rowCount.setValue(rowCount);
}
if (offset < 0 || rowCount < 0) {
throw new SQLParsingException("LIMIT offset and row count can not be a negative value.");
this.offset = offset;
if (null != rowCount) {
rowCount.setValue(-1 == rowCount.getIndex() ? getRowCountValue() : NumberUtil.roundHalfUp(parameters.get(rowCount.getIndex())));
}
this.rowCount = rowCount;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册