db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r521071 - /db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java
Date Thu, 22 Mar 2007 01:22:32 GMT
Author: arminw
Date: Wed Mar 21 18:22:31 2007
New Revision: 521071

URL: http://svn.apache.org/viewvc?view=rev&rev=521071
Log:
add comment

Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java?view=diff&rev=521071&r1=521070&r2=521071
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/platforms/PlatformDb2Impl.java Wed Mar 21
18:22:31 2007
@@ -276,15 +276,57 @@
         return false;
     }
 
-    public StringBuffer addPagingSql(Query query, StringBuffer anSqlString)
+    public StringBuffer addPagingSql(Query query, StringBuffer sql)
     {
-        // TODO: native paging support
-        // not supported
         throw new UnsupportedOperationException("OFFSET is not supported by this platform"
+
                 " implementation class (" + this.getClass().getName() +
                 "), please disable the native limit/offset flag in the" +
                 " connection metadata mapping file using attribute 'nativeLimitOffset'" +
                 " then OJB will use specific paging/limit result set iterator to simulate
it!");
+
+        // TODO: native paging support
+        /*
+         arminw:
+         Below are two paging implementation versions. It would be great if someone
+         can check this against DB2.
+         To verify the implementation please run org.apache.ojb.broker.PaginationTest
+         from OJB's test suite.
+         Please check methods #buildLimit(...) and buildOffset(...) too (maybe need tweak).
+        */
+
+        /* Version A
+        int orderByIndex = sql.toString().toLowerCase().indexOf("order by");
+        int selectIndex = sql.toString().toLowerCase().indexOf("select");
+        boolean isOrderBy = orderByIndex > -1;
+
+        StringBuffer result = new StringBuffer().append("select * from ( select row_number()
over(");
+        if(!query.isDistinct() && isOrderBy)
+        {
+            result.append(sql.toString().substring(orderByIndex));
+    }
+        result.append(" ) as rownum_,");
+        if(query.isDistinct())
+        {
+            result.append(" row_.* from ( ").append(sql.toString()).append(" ) as row_");
+        }
+        else
+        {
+            result.append(sql.toString().substring(selectIndex + 6));
+        }
+        result.append(" ) as foo_ where rownum_ > ").append(buildOffset(query)).append("
and rownum_ <= ").append(buildLimit(query));
+        return result;
+        */
+
+        /* Version B
+        StringBuffer result = new StringBuffer();
+        result.append("select bar_.* from ( select foo_.*, row_number() over() as rownum_
from ( ")
+                .append(sql.toString())
+                .append(" ) as foo_ ) as bar_ where rownum_ > ")
+                .append(buildOffset(query))
+                .append(" and rownum_ <= ")
+                .append(buildLimit(query));
+        return result;
+        */
     }
 
     public int buildLimit(Query query)



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message