cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] 03/05: the TOP query is used for null db version
Date Thu, 25 Feb 2021 12:21:50 GMT
This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit ed86e5d770867bf1c25c6462be1db7cdea510026
Author: andreykravchenko <andrey.kravchenko@objectstyle.com>
AuthorDate: Wed Feb 10 17:26:39 2021 +0300

    the TOP query is used for null db version
---
 .../dba/sqlserver/SQLServerActionBuilder.java       | 21 +++++++++++++++++++--
 .../cayenne/dba/sqlserver/SQLServerAdapter.java     |  6 ++++--
 .../dba/sqlserver/SQLServerTreeProcessor.java       |  2 +-
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerActionBuilder.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerActionBuilder.java
index f19a671..bd43ee9 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerActionBuilder.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerActionBuilder.java
@@ -29,6 +29,13 @@ import org.apache.cayenne.query.*;
 public class SQLServerActionBuilder extends JdbcActionBuilder {
 
 	/**
+	 * Stores the major version of the database.
+	 *
+	 * @since 4.2
+	 */
+	private Integer version;
+
+	/**
 	 * @since 4.0
 	 */
 	public SQLServerActionBuilder(DataNode dataNode) {
@@ -57,7 +64,8 @@ public class SQLServerActionBuilder extends JdbcActionBuilder {
 	 */
 	@Override
 	public <T> SQLAction objectSelectAction(SelectQuery<T> query) {
-		if (query.getOrderings() == null || query.getOrderings().size() == 0) {
+		if (query.getOrderings() == null || query.getOrderings().size() == 0 ||
+				version == null || version < 12) {
 			return new SQLServerSelectAction(query, dataNode, true);
 		}
 
@@ -69,10 +77,19 @@ public class SQLServerActionBuilder extends JdbcActionBuilder {
 	 */
 	@Override
 	public <T> SQLAction objectSelectAction(FluentSelect<T> query) {
-		if (query.getOrderings() == null || query.getOrderings().size() == 0) {
+		if (query.getOrderings() == null || query.getOrderings().size() == 0 ||
+				version == null || version < 12) {
 			return new SQLServerSelectAction(query, dataNode, true);
 		}
 
 		return new SQLServerSelectAction(query, dataNode, false);
 	}
+
+	public Integer getVersion() {
+		return version;
+	}
+
+	public void setVersion(Integer version) {
+		this.version = version;
+	}
 }
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java
index 67871df..9805e0d 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapter.java
@@ -81,7 +81,7 @@ public class SQLServerAdapter extends SybaseAdapter {
 	 *
 	 * @since 4.2
 	 */
-	protected Integer version;
+	private Integer version;
 
 	/**
 	 * @deprecated since 4.2 unused
@@ -130,7 +130,9 @@ public class SQLServerAdapter extends SybaseAdapter {
 	 */
 	@Override
 	public SQLAction getAction(Query query, DataNode node) {
-		return query.createSQLAction(new SQLServerActionBuilder(node));
+		SQLServerActionBuilder sqlServerActionBuilder = new SQLServerActionBuilder(node);
+		sqlServerActionBuilder.setVersion(this.version);
+		return query.createSQLAction(sqlServerActionBuilder);
 	}
 
 	@Override
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTreeProcessor.java
b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTreeProcessor.java
index c1c8c98..347da1f 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTreeProcessor.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/sqlserver/SQLServerTreeProcessor.java
@@ -38,7 +38,7 @@ public class SQLServerTreeProcessor extends SybaseSQLTreeProcessor {
 
     @Override
     protected void onLimitOffsetNode(Node parent, LimitOffsetNode child, int index) {
-        if (version == null || version >= 12) {
+        if (version != null && version >= 12) {
             for (int i = 0; i < parent.getChildrenCount(); i++) {
                 if (parent.getChild(i) instanceof OrderByNode) {
                     replaceChild(parent, index,  new SQLServerLimitOffsetNode(child.getLimit(),
child.getOffset()), false);


Mime
View raw message