From 778e8e9449210bda0f3fad71081ae3dc954e8a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Fri, 1 Sep 2017 06:38:48 +0000 Subject: [PATCH] [OPENJPA-2598] Applying provided patch git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1806888 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/sql/SQLServerDictionary.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java index 4da2f1050..6d4e86dd3 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLServerDictionary.java @@ -72,7 +72,7 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary { String driverName = meta.getDriverName(); String url = meta.getURL(); if (driverVendor == null) { - // serverMajorVersion of 8==2000, 9==2005, 10==2008 + // serverMajorVersion of 8==2000, 9==2005, 10==2008, 11==2012 if (meta.getDatabaseMajorVersion() >= 9) setSupportsXMLColumn(true); if (meta.getDatabaseMajorVersion() >= 10) { @@ -83,6 +83,12 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary { timestampTypeName = "DATETIME2"; datePrecision = MICRO / 10; } + if (meta.getDatabaseMajorVersion() >= 11) { + //SQLServer 2012 supports range select + rangePosition = RANGE_POST_SELECT; + supportsSelectStartIndex = true; + supportsSelectEndIndex = true; + } if (driverName != null) { if (driverName.startsWith("Microsoft SQL Server")) { // v1.1, 1.2, 2.0 or 3.0 driver @@ -342,4 +348,19 @@ public class SQLServerDictionary extends AbstractSQLServerDictionary { } buf.append(")"); } + + @Override + protected void appendSelectRange(SQLBuffer buf, long start, long end, boolean subselect) { + //SQL Server 2012 supports range select + if (this.getMajorVersion() >= 11) { + //we need an order by clause.... + if (!buf.getSQL().contains(" ORDER BY ")) { + buf.append(" ORDER BY 1 "); + } + buf.append(" OFFSET ").append(Long.toString(start)).append(" ROWS "). + append(" FETCH NEXT ").append(Long.toString(end - start)).append(" ROWS ONLY "); + } else { + super.appendSelectRange(buf, start, end, subselect); + } + } }