From 5bc71b77dded9d5256ee4d422114b9a45582be85 Mon Sep 17 00:00:00 2001 From: fjn <1194361820@qq.com> Date: Wed, 2 Dec 2020 09:45:11 +0800 Subject: [PATCH] =?UTF-8?q?*=20=E5=AF=B9offset=20fetch=20next=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=EF=BC=8C=E4=BB=A5=E5=85=BC=E5=AE=B9sqlserver2012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialect/internal/SQLServerDialect.java | 41 ++++--------------- .../OffsetFetchFirstOnlyLimitHandler.java | 15 +++++-- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/SQLServerDialect.java b/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/SQLServerDialect.java index bff5eb098..729ea13dc 100644 --- a/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/SQLServerDialect.java +++ b/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/SQLServerDialect.java @@ -108,6 +108,7 @@ public boolean isBindLimitParametersFirst() { public static class SQLServer2000Dialect extends AbstractTransactSQLDialect { public SQLServer2000Dialect() { setLimitHandler(new TopLimitHandler()); + setDelegate(null); } @Override @@ -140,6 +141,7 @@ public boolean isBindLimitParametersFirst() { public static class SQLServer2005Dialect extends AbstractTransactSQLDialect { public SQLServer2005Dialect() { setLimitHandler(new SQLServer2005LimitHandler()); + setDelegate(null); } @Override @@ -175,45 +177,20 @@ public char getAfterQuote() { @Name("sqlserver2008") public static class SQLServer2008Dialect extends SQLServer2005Dialect { - public SQLServer2008Dialect() { - setLimitHandler(new OffsetFetchFirstOnlyLimitHandler()); - } - - @Override - public boolean isSupportsLimit() { - return true; - } - - @Override - public boolean isUseMaxForLimit() { - return true; - } - - @Override - public boolean isSupportsLimitOffset() { - return true; - } - - @Override - public boolean isSupportsVariableLimit() { - return true; - } + } - @Override - public char getBeforeQuote() { - return '['; + @Name("sqlserver2012") + public static class SQLServer2012Dialect extends SQLServer2008Dialect { + public SQLServer2012Dialect() { + setLimitHandler(new OffsetFetchFirstOnlyLimitHandler().setSupportSimplifyFirstOnly(false)); } @Override - public char getAfterQuote() { - return ']'; + public boolean isBindLimitParametersInReverseOrder() { + return false; } } - @Name("sqlserver2012") - public static class SQLServer2012Dialect extends SQLServer2008Dialect { - } - @Name("sqlserver2014") public static class SQLServer2014Dialect extends SQLServer2012Dialect { } diff --git a/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/limit/OffsetFetchFirstOnlyLimitHandler.java b/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/limit/OffsetFetchFirstOnlyLimitHandler.java index 4fb7eb10b..ef2db30d1 100644 --- a/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/limit/OffsetFetchFirstOnlyLimitHandler.java +++ b/sqlhelper-dialect/src/main/java/com/jn/sqlhelper/dialect/internal/limit/OffsetFetchFirstOnlyLimitHandler.java @@ -82,13 +82,13 @@ protected String getLimitString(String sql, long offset, int limit) { sql2.append(sql); if (getDialect().isUseLimitInVariableMode()) { - if (hasOffset) { + if (hasOffset || !supportSimplifyFirstOnly) { sql2.append(" OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); } else { sql2.append(" FETCH FIRST ? ROWS ONLY"); } } else { - if (hasOffset) { + if (hasOffset || !supportSimplifyFirstOnly) { sql2.append(" OFFSET " + offset + " ROWS FETCH NEXT " + limit + " ROWS ONLY"); } else { sql2.append(" FETCH FIRST " + limit + " ROWS ONLY"); @@ -107,7 +107,7 @@ protected String getLimitString(String sql, long offset, int limit) { private boolean isSupportUsingIndexClauseInSelectEnd = false; private boolean supportForUpdate = true; private boolean supportWithInSelectEnd = true; - + private boolean supportSimplifyFirstOnly = true; public boolean isSupportUsingIndexClauseInSelectEnd() { return isSupportUsingIndexClauseInSelectEnd; } @@ -134,4 +134,13 @@ public OffsetFetchFirstOnlyLimitHandler setSupportWithInSelectEnd(boolean suppor this.supportWithInSelectEnd = supportWithInSelectEnd; return this; } + + public boolean isSupportSimplifyFirstOnly() { + return supportSimplifyFirstOnly; + } + + public OffsetFetchFirstOnlyLimitHandler setSupportSimplifyFirstOnly(boolean supportSimplifyFirstOnly) { + this.supportSimplifyFirstOnly = supportSimplifyFirstOnly; + return this; + } }