cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r709925 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba: hsqldb/HSQLSelectTranslator.java mysql/MySQLActionBuilder.java mysql/MySQLSelectAction.java mysql/MySQLSelectTranslator.java
Date Sun, 02 Nov 2008 20:55:47 GMT
Author: aadamchik
Date: Sun Nov  2 12:55:47 2008
New Revision: 709925

URL: http://svn.apache.org/viewvc?rev=709925&view=rev
Log:
Add LIMIT / OFFSET clause generation method to SelectTranslator lifecycle

 switching MySQL to the new lifecycle method for LIMIT/OFFSET

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLActionBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java?rev=709925&r1=709924&r2=709925&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java
Sun Nov  2 12:55:47 2008
@@ -37,7 +37,8 @@
         if (offset > 0 || limit > 0) {
             buffer.append(" LIMIT ");
 
-            // OFFSET can't be speciafied without LIMIT
+            // both OFFSET and LIMIT must be present, so come up with defaults if one of
+            // them is not set by the user
             if (limit == 0) {
                 limit = Integer.MAX_VALUE;
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLActionBuilder.java?rev=709925&r1=709924&r2=709925&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLActionBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLActionBuilder.java
Sun Nov  2 12:55:47 2008
@@ -19,10 +19,6 @@
 
 package org.apache.cayenne.dba.mysql;
 
-import java.sql.Connection;
-
-import org.apache.cayenne.access.jdbc.SelectAction;
-import org.apache.cayenne.access.trans.SelectTranslator;
 import org.apache.cayenne.dba.JdbcActionBuilder;
 import org.apache.cayenne.dba.JdbcAdapter;
 import org.apache.cayenne.map.EntityResolver;
@@ -42,18 +38,7 @@
 
     @Override
     public SQLAction objectSelectAction(SelectQuery query) {
-        return new MySQLSelectAction(query, adapter, entityResolver) {
-
-            @Override
-            protected SelectTranslator createTranslator(Connection connection) {
-                SelectTranslator translator = new MySQLSelectTranslator();
-                translator.setQuery(query);
-                translator.setAdapter(adapter);
-                translator.setEntityResolver(getEntityResolver());
-                translator.setConnection(connection);
-                return translator;
-            }
-        };
+        return new MySQLSelectAction(query, adapter, entityResolver);
     }
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java?rev=709925&r1=709924&r2=709925&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectAction.java
Sun Nov  2 12:55:47 2008
@@ -18,7 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.dba.mysql;
 
+import java.sql.Connection;
+
 import org.apache.cayenne.access.jdbc.SelectAction;
+import org.apache.cayenne.access.trans.SelectTranslator;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.SelectQuery;
@@ -36,4 +39,14 @@
     protected int getInitialCursorPosition(int queryOffset) {
         return 0;
     }
+
+    @Override
+    protected SelectTranslator createTranslator(Connection connection) {
+        SelectTranslator translator = new MySQLSelectTranslator();
+        translator.setQuery(query);
+        translator.setAdapter(adapter);
+        translator.setEntityResolver(getEntityResolver());
+        translator.setConnection(connection);
+        return translator;
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java?rev=709925&r1=709924&r2=709925&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLSelectTranslator.java
Sun Nov  2 12:55:47 2008
@@ -26,26 +26,24 @@
  * @since 1.2
  * @author Andrus Adamchik
  */
-public class MySQLSelectTranslator extends SelectTranslator {
+class MySQLSelectTranslator extends SelectTranslator {
 
     @Override
-    public String createSqlString() throws Exception {
-        String sql = super.createSqlString();
+    protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
+        QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
+        int offset = metadata.getFetchOffset();
+        int limit = metadata.getFetchLimit();
 
-        if (!isSuppressingDistinct()) {
-            // limit results
-            QueryMetadata metadata = getQuery().getMetaData(getEntityResolver());
-            int offset = metadata.getFetchOffset();
-            int limit = metadata.getFetchLimit();
+        if (offset > 0 || limit > 0) {
+            buffer.append(" LIMIT ");
 
-            if (offset > 0 || limit > 0) {
-                sql += " LIMIT ";
-                if (limit == 0) {
-                    limit = Integer.MAX_VALUE;
-                }
-                sql += limit + " OFFSET " + offset;
+            // both OFFSET and LIMIT must be present, so come up with defaults if one of
+            // them is not set by the user
+            if (limit == 0) {
+                limit = Integer.MAX_VALUE;
             }
+
+            buffer.append(limit).append(" OFFSET ").append(offset);
         }
-        return sql;
     }
 }



Mime
View raw message