提交 fcab73c4 编写于 作者: T terrymanu

for #2441, refactor Limit's constructor

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