cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r709923 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/trans/SelectTranslator.java dba/hsqldb/HSQLActionBuilder.java dba/hsqldb/HSQLSelectAction.java dba/hsqldb/HSQLSelectTranslator.java
Date Sun, 02 Nov 2008 20:54:40 GMT
Author: aadamchik
Date: Sun Nov  2 12:54:40 2008
New Revision: 709923

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

new lifecycle method in SelectTranslator; switching HSQLDB to use it

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLActionBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectTranslator.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java?rev=709923&r1=709922&r2=709923&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
Sun Nov  2 12:54:40 2008
@@ -182,9 +182,23 @@
             queryBuf.append(" ORDER BY ").append(orderingBuffer);
         }
 
+        if (!isSuppressingDistinct()) {
+            appendLimitAndOffsetClauses(queryBuf);
+        }
+
         return queryBuf.toString();
     }
 
+    /**
+     * Handles appending optional limit and offset clauses. This implementation does
+     * nothing, deferring to subclasses to define the LIMIT/OFFSET clause syntax.
+     * 
+     * @since 3.0
+     */
+    protected void appendLimitAndOffsetClauses(StringBuilder buffer) {
+
+    }
+
     @Override
     public String getCurrentAlias() {
         return joinStack.getCurrentAlias();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLActionBuilder.java?rev=709923&r1=709922&r2=709923&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLActionBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLActionBuilder.java
Sun Nov  2 12:54:40 2008
@@ -23,7 +23,6 @@
 
 import org.apache.cayenne.access.jdbc.ProcedureAction;
 import org.apache.cayenne.access.trans.ProcedureTranslator;
-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;
@@ -39,20 +38,9 @@
 
     @Override
     public SQLAction objectSelectAction(SelectQuery query) {
-        return new HSQLSelectAction(query, adapter, entityResolver) {
-
-            @Override
-            protected SelectTranslator createTranslator(Connection connection) {
-                SelectTranslator translator = new HSQLSelectTranslator();
-                translator.setQuery(query);
-                translator.setAdapter(adapter);
-                translator.setEntityResolver(getEntityResolver());
-                translator.setConnection(connection);
-                return translator;
-            }
-        };
+        return new HSQLSelectAction(query, adapter, entityResolver);
     }
-    
+
     @Override
     public SQLAction procedureAction(ProcedureQuery query) {
         return new ProcedureAction(query, adapter, entityResolver) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java?rev=709923&r1=709922&r2=709923&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLSelectAction.java
Sun Nov  2 12:54:40 2008
@@ -18,7 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.dba.hsqldb;
 
+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;
@@ -37,4 +40,13 @@
         return 0;
     }
 
+    @Override
+    protected SelectTranslator createTranslator(Connection connection) {
+        SelectTranslator translator = new HSQLSelectTranslator();
+        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/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=709923&r1=709922&r2=709923&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:54:40 2008
@@ -26,26 +26,23 @@
  * @since 1.2
  * @author Andrus Adamchik
  */
-public class HSQLSelectTranslator extends SelectTranslator {
+class HSQLSelectTranslator 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;
+            // OFFSET can't be speciafied without LIMIT
+            if (limit == 0) {
+                limit = Integer.MAX_VALUE;
             }
+
+            buffer.append(limit).append(" OFFSET ").append(offset);
         }
-        return sql;
     }
 }



Mime
View raw message