Loading sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/context/limit/Limit.java +0 −12 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.dangdang.ddframe.rdb.sharding.parsing.parser.context.limit; import com.dangdang.ddframe.rdb.sharding.parsing.parser.exception.SQLParsingException; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; Loading @@ -35,7 +34,6 @@ import static com.dangdang.ddframe.rdb.sharding.util.NumberUtil.roundHalfUp; * @author caohao */ @RequiredArgsConstructor @AllArgsConstructor @Getter @Setter @ToString Loading @@ -47,16 +45,6 @@ public final class Limit { private RowCountLimit rowCountLimit; public Limit(final boolean rowCountRewriteFlag, final RowCountLimit rowCount) { this.rowCountRewriteFlag = rowCountRewriteFlag; this.rowCountLimit = rowCount; } public Limit(final boolean rowCountRewriteFlag, final OffsetLimit offsetLimit) { this.rowCountRewriteFlag = rowCountRewriteFlag; this.offsetLimit = offsetLimit; } /** * 获取分页偏移量. * Loading sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/mysql/MySQLParser.java +11 −3 Original line number Diff line number Diff line Loading @@ -77,7 +77,9 @@ public final class MySQLParser extends SQLParser { if (!isParameterForValue) { sqlStatement.getSqlTokens().add(new RowCountLimitToken(valueBeginPosition, value)); } return new Limit(true, new RowCountLimit(value, valueIndex)); Limit result = new Limit(true); result.setRowCountLimit(new RowCountLimit(value, valueIndex)); return result; } private Limit getLimitWithComma( Loading @@ -104,7 +106,10 @@ public final class MySQLParser extends SQLParser { if (!isParameterForRowCount) { sqlStatement.getSqlTokens().add(new RowCountLimitToken(rowCountBeginPosition, rowCount)); } return new Limit(true, new OffsetLimit(value, valueIndex), new RowCountLimit(rowCount, rowCountIndex)); Limit result = new Limit(true); result.setRowCountLimit(new RowCountLimit(rowCount, rowCountIndex)); result.setOffsetLimit(new OffsetLimit(value, valueIndex)); return result; } private Limit getLimitWithOffset( Loading @@ -131,6 +136,9 @@ public final class MySQLParser extends SQLParser { if (!isParameterForValue) { sqlStatement.getSqlTokens().add(new RowCountLimitToken(valueBeginPosition, value)); } return new Limit(true, new OffsetLimit(offset, offsetIndex), new RowCountLimit(value, valueIndex)); Limit result = new Limit(true); result.setRowCountLimit(new RowCountLimit(value, valueIndex)); result.setOffsetLimit(new OffsetLimit(offset, offsetIndex)); return result; } } sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/postgresql/PostgreSQLSelectParser.java +7 −7 Original line number Diff line number Diff line Loading @@ -122,7 +122,6 @@ public class PostgreSQLSelectParser extends AbstractSelectParser { } else if (getSqlParser().equalAny(Symbol.QUESTION)) { offsetParameterIndex = parameterIndex++; setParametersIndex(parameterIndex); offset = -1; } else { throw new SQLParsingException(getSqlParser().getLexer()); } Loading @@ -133,13 +132,14 @@ public class PostgreSQLSelectParser extends AbstractSelectParser { private void setLimit(final Optional<OffsetLimit> offsetLimit, final Optional<RowCountLimit> rowCountLimit) { if (offsetLimit.isPresent() && rowCountLimit.isPresent()) { getSelectStatement().setLimit(new Limit(true, offsetLimit.get(), rowCountLimit.get())); } else if (offsetLimit.isPresent()) { getSelectStatement().setLimit(new Limit(true, offsetLimit.get())); } else if (rowCountLimit.isPresent()) { getSelectStatement().setLimit(new Limit(true, rowCountLimit.get())); Limit limit = new Limit(true); if (offsetLimit.isPresent()) { limit.setOffsetLimit(offsetLimit.get()); } if (rowCountLimit.isPresent()) { limit.setRowCountLimit(rowCountLimit.get()); } getSelectStatement().setLimit(limit); } protected boolean hasDistinctOn() { Loading sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerParser.java +7 −4 Original line number Diff line number Diff line Loading @@ -74,7 +74,9 @@ public final class SQLServerParser extends SQLParser { throw new SQLParsingException(getLexer()); } if (null == sqlStatement.getLimit()) { sqlStatement.setLimit(new Limit(false, rowCountLimit)); Limit limit = new Limit(false); limit.setRowCountLimit(rowCountLimit); sqlStatement.setLimit(limit); } else { sqlStatement.getLimit().setRowCountLimit(rowCountLimit); } Loading Loading @@ -102,7 +104,7 @@ public final class SQLServerParser extends SQLParser { throw new SQLParsingException(getLexer()); } getLexer().nextToken(); Limit limit; Limit limit = new Limit(true); if (skipIfEqual(DefaultKeyword.FETCH)) { getLexer().nextToken(); int rowCount; Loading @@ -119,9 +121,10 @@ public final class SQLServerParser extends SQLParser { } getLexer().nextToken(); getLexer().nextToken(); limit = new Limit(true, new OffsetLimit(offset, offsetIndex), new RowCountLimit(rowCount, rowCountIndex)); limit.setRowCountLimit(new RowCountLimit(rowCount, rowCountIndex)); limit.setOffsetLimit(new OffsetLimit(offset, offsetIndex)); } else { limit = new Limit(true, new OffsetLimit(offset, offsetIndex)); limit.setOffsetLimit(new OffsetLimit(offset, offsetIndex)); } selectStatement.setLimit(limit); } Loading sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/merger/pipeline/reducer/IteratorResultSetTest.java +8 −2 Original line number Diff line number Diff line Loading @@ -49,7 +49,10 @@ public final class IteratorResultSetTest { @Test public void assertNextWithLimitForAllData() throws SQLException { SQLStatement selectStatement = new SelectStatement(); selectStatement.setLimit(new Limit(true, new OffsetLimit(1, -1), new RowCountLimit(10, -1))); Limit limit = new Limit(true); limit.setRowCountLimit(new RowCountLimit(10, -1)); limit.setOffsetLimit(new OffsetLimit(1, -1)); selectStatement.setLimit(limit); ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), selectStatement); int count = 0; while (resultSet.next()) { Loading @@ -61,7 +64,10 @@ public final class IteratorResultSetTest { @Test public void assertNextWithLimitForPartData() throws SQLException { SQLStatement selectStatement = new SelectStatement(); selectStatement.setLimit(new Limit(true, new OffsetLimit(1, -1), new RowCountLimit(1, -1))); Limit limit = new Limit(true); limit.setRowCountLimit(new RowCountLimit(1, -1)); limit.setOffsetLimit(new OffsetLimit(1, -1)); selectStatement.setLimit(limit); ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), selectStatement); int count = 0; while (resultSet.next()) { Loading Loading
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/context/limit/Limit.java +0 −12 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.dangdang.ddframe.rdb.sharding.parsing.parser.context.limit; import com.dangdang.ddframe.rdb.sharding.parsing.parser.exception.SQLParsingException; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; Loading @@ -35,7 +34,6 @@ import static com.dangdang.ddframe.rdb.sharding.util.NumberUtil.roundHalfUp; * @author caohao */ @RequiredArgsConstructor @AllArgsConstructor @Getter @Setter @ToString Loading @@ -47,16 +45,6 @@ public final class Limit { private RowCountLimit rowCountLimit; public Limit(final boolean rowCountRewriteFlag, final RowCountLimit rowCount) { this.rowCountRewriteFlag = rowCountRewriteFlag; this.rowCountLimit = rowCount; } public Limit(final boolean rowCountRewriteFlag, final OffsetLimit offsetLimit) { this.rowCountRewriteFlag = rowCountRewriteFlag; this.offsetLimit = offsetLimit; } /** * 获取分页偏移量. * Loading
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/mysql/MySQLParser.java +11 −3 Original line number Diff line number Diff line Loading @@ -77,7 +77,9 @@ public final class MySQLParser extends SQLParser { if (!isParameterForValue) { sqlStatement.getSqlTokens().add(new RowCountLimitToken(valueBeginPosition, value)); } return new Limit(true, new RowCountLimit(value, valueIndex)); Limit result = new Limit(true); result.setRowCountLimit(new RowCountLimit(value, valueIndex)); return result; } private Limit getLimitWithComma( Loading @@ -104,7 +106,10 @@ public final class MySQLParser extends SQLParser { if (!isParameterForRowCount) { sqlStatement.getSqlTokens().add(new RowCountLimitToken(rowCountBeginPosition, rowCount)); } return new Limit(true, new OffsetLimit(value, valueIndex), new RowCountLimit(rowCount, rowCountIndex)); Limit result = new Limit(true); result.setRowCountLimit(new RowCountLimit(rowCount, rowCountIndex)); result.setOffsetLimit(new OffsetLimit(value, valueIndex)); return result; } private Limit getLimitWithOffset( Loading @@ -131,6 +136,9 @@ public final class MySQLParser extends SQLParser { if (!isParameterForValue) { sqlStatement.getSqlTokens().add(new RowCountLimitToken(valueBeginPosition, value)); } return new Limit(true, new OffsetLimit(offset, offsetIndex), new RowCountLimit(value, valueIndex)); Limit result = new Limit(true); result.setRowCountLimit(new RowCountLimit(value, valueIndex)); result.setOffsetLimit(new OffsetLimit(offset, offsetIndex)); return result; } }
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/postgresql/PostgreSQLSelectParser.java +7 −7 Original line number Diff line number Diff line Loading @@ -122,7 +122,6 @@ public class PostgreSQLSelectParser extends AbstractSelectParser { } else if (getSqlParser().equalAny(Symbol.QUESTION)) { offsetParameterIndex = parameterIndex++; setParametersIndex(parameterIndex); offset = -1; } else { throw new SQLParsingException(getSqlParser().getLexer()); } Loading @@ -133,13 +132,14 @@ public class PostgreSQLSelectParser extends AbstractSelectParser { private void setLimit(final Optional<OffsetLimit> offsetLimit, final Optional<RowCountLimit> rowCountLimit) { if (offsetLimit.isPresent() && rowCountLimit.isPresent()) { getSelectStatement().setLimit(new Limit(true, offsetLimit.get(), rowCountLimit.get())); } else if (offsetLimit.isPresent()) { getSelectStatement().setLimit(new Limit(true, offsetLimit.get())); } else if (rowCountLimit.isPresent()) { getSelectStatement().setLimit(new Limit(true, rowCountLimit.get())); Limit limit = new Limit(true); if (offsetLimit.isPresent()) { limit.setOffsetLimit(offsetLimit.get()); } if (rowCountLimit.isPresent()) { limit.setRowCountLimit(rowCountLimit.get()); } getSelectStatement().setLimit(limit); } protected boolean hasDistinctOn() { Loading
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/parsing/parser/dialect/sqlserver/SQLServerParser.java +7 −4 Original line number Diff line number Diff line Loading @@ -74,7 +74,9 @@ public final class SQLServerParser extends SQLParser { throw new SQLParsingException(getLexer()); } if (null == sqlStatement.getLimit()) { sqlStatement.setLimit(new Limit(false, rowCountLimit)); Limit limit = new Limit(false); limit.setRowCountLimit(rowCountLimit); sqlStatement.setLimit(limit); } else { sqlStatement.getLimit().setRowCountLimit(rowCountLimit); } Loading Loading @@ -102,7 +104,7 @@ public final class SQLServerParser extends SQLParser { throw new SQLParsingException(getLexer()); } getLexer().nextToken(); Limit limit; Limit limit = new Limit(true); if (skipIfEqual(DefaultKeyword.FETCH)) { getLexer().nextToken(); int rowCount; Loading @@ -119,9 +121,10 @@ public final class SQLServerParser extends SQLParser { } getLexer().nextToken(); getLexer().nextToken(); limit = new Limit(true, new OffsetLimit(offset, offsetIndex), new RowCountLimit(rowCount, rowCountIndex)); limit.setRowCountLimit(new RowCountLimit(rowCount, rowCountIndex)); limit.setOffsetLimit(new OffsetLimit(offset, offsetIndex)); } else { limit = new Limit(true, new OffsetLimit(offset, offsetIndex)); limit.setOffsetLimit(new OffsetLimit(offset, offsetIndex)); } selectStatement.setLimit(limit); } Loading
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/merger/pipeline/reducer/IteratorResultSetTest.java +8 −2 Original line number Diff line number Diff line Loading @@ -49,7 +49,10 @@ public final class IteratorResultSetTest { @Test public void assertNextWithLimitForAllData() throws SQLException { SQLStatement selectStatement = new SelectStatement(); selectStatement.setLimit(new Limit(true, new OffsetLimit(1, -1), new RowCountLimit(10, -1))); Limit limit = new Limit(true); limit.setRowCountLimit(new RowCountLimit(10, -1)); limit.setOffsetLimit(new OffsetLimit(1, -1)); selectStatement.setLimit(limit); ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), selectStatement); int count = 0; while (resultSet.next()) { Loading @@ -61,7 +64,10 @@ public final class IteratorResultSetTest { @Test public void assertNextWithLimitForPartData() throws SQLException { SQLStatement selectStatement = new SelectStatement(); selectStatement.setLimit(new Limit(true, new OffsetLimit(1, -1), new RowCountLimit(1, -1))); Limit limit = new Limit(true); limit.setRowCountLimit(new RowCountLimit(1, -1)); limit.setOffsetLimit(new OffsetLimit(1, -1)); selectStatement.setLimit(limit); ResultSet resultSet = ResultSetFactory.getResultSet(Arrays.<ResultSet>asList(new MockResultSet<>(1), new MockResultSet<>(2, 4), new MockResultSet<Integer>()), selectStatement); int count = 0; while (resultSet.next()) { Loading