db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject cvs commit: db-torque/xdocs release-changes.xml
Date Fri, 06 Aug 2004 12:13:13 GMT
seade       2004/08/06 05:13:13

  Modified:    src/java/org/apache/torque/adapter Tag: TORQUE_3_1_BRANCH
                        DBDB2Net.java DB.java DBDB2App.java DBDB2400.java
               src/java/org/apache/torque/util Tag: TORQUE_3_1_BRANCH
                        BasePeer.java
               xdocs    Tag: TORQUE_3_1_BRANCH release-changes.xml
  Log:
  DB2 limit and offset support.  Thanks to Augustin Vidovic for the patch.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.5.4.3   +13 -1     db-torque/src/java/org/apache/torque/adapter/DBDB2Net.java
  
  Index: DBDB2Net.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/adapter/DBDB2Net.java,v
  retrieving revision 1.5.4.2
  retrieving revision 1.5.4.3
  diff -u -r1.5.4.2 -r1.5.4.3
  --- DBDB2Net.java	20 May 2004 04:35:15 -0000	1.5.4.2
  +++ DBDB2Net.java	6 Aug 2004 12:13:12 -0000	1.5.4.3
  @@ -28,6 +28,7 @@
    * </a>
    *
    * @author <a href="mailto:hakan42@gmx.de">Hakan Tandogan</a>
  + * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
    * @version $Id$
    */
   public class DBDB2Net
  @@ -100,5 +101,16 @@
        */
       public void unlockTable(Connection con, String table) throws SQLException
       {
  +    }
  +
  +    /**
  +     * This method is used to check whether the database supports
  +     * limiting the size of the resultset.
  +     *
  +     * @return LIMIT_STYLE_DB2.
  +     */
  +    public int getLimitStyle()
  +    {
  +        return DB.LIMIT_STYLE_DB2;
       }
   }
  
  
  
  1.31.2.3  +5 -1      db-torque/src/java/org/apache/torque/adapter/DB.java
  
  Index: DB.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/adapter/DB.java,v
  retrieving revision 1.31.2.2
  retrieving revision 1.31.2.3
  diff -u -r1.31.2.2 -r1.31.2.3
  --- DB.java	20 May 2004 04:35:15 -0000	1.31.2.2
  +++ DB.java	6 Aug 2004 12:13:12 -0000	1.31.2.3
  @@ -50,6 +50,7 @@
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  + * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
    * @version $Id$
    */
   public abstract class DB implements Serializable, IDMethod
  @@ -68,6 +69,9 @@
   
       /** <code><pre>SELECT ... WHERE ... AND ROWNUM < <limit></pre></code>
*/
       public static final int LIMIT_STYLE_ORACLE = 4;
  +
  +    /** <code><pre>SELECT ... WHERE ... AND ROW_NUMBER() OVER() < <limit></pre></code>
*/
  +    public static final int LIMIT_STYLE_DB2 = 5;
   
       /**
        * Empty constructor.
  
  
  
  1.5.4.3   +13 -1     db-torque/src/java/org/apache/torque/adapter/DBDB2App.java
  
  Index: DBDB2App.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/adapter/DBDB2App.java,v
  retrieving revision 1.5.4.2
  retrieving revision 1.5.4.3
  diff -u -r1.5.4.2 -r1.5.4.3
  --- DBDB2App.java	20 May 2004 04:35:15 -0000	1.5.4.2
  +++ DBDB2App.java	6 Aug 2004 12:13:12 -0000	1.5.4.3
  @@ -28,6 +28,7 @@
    * </a>
    *
    * @author <a href="mailto:hakan42@gmx.de">Hakan Tandogan</a>
  + * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
    * @version $Id$
    */
   public class DBDB2App extends DB
  @@ -99,5 +100,16 @@
        */
       public void unlockTable(Connection con, String table) throws SQLException
       {
  +    }
  +
  +    /**
  +     * This method is used to check whether the database supports
  +     * limiting the size of the resultset.
  +     *
  +     * @return LIMIT_STYLE_DB2.
  +     */
  +    public int getLimitStyle()
  +    {
  +        return DB.LIMIT_STYLE_DB2;
       }
   }
  
  
  
  1.4.2.3   +13 -1     db-torque/src/java/org/apache/torque/adapter/DBDB2400.java
  
  Index: DBDB2400.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/adapter/DBDB2400.java,v
  retrieving revision 1.4.2.2
  retrieving revision 1.4.2.3
  diff -u -r1.4.2.2 -r1.4.2.3
  --- DBDB2400.java	20 May 2004 04:35:15 -0000	1.4.2.2
  +++ DBDB2400.java	6 Aug 2004 12:13:12 -0000	1.4.2.3
  @@ -20,6 +20,7 @@
    * Torque Database Adapter for DB2/400 on the IBM AS400 platform.
    *
    * @author <a href="mailto:sweaver@rippe.com">Scott Weaver</a>
  + * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
    * @version $Id$
    */
   public class DBDB2400 extends DBDB2App
  @@ -72,5 +73,16 @@
       private String formatCase(String in)
       {
           return new StringBuffer(UCASE + "(").append(in).append(")").toString();
  +    }
  +
  +    /**
  +     * This method is used to check whether the database supports
  +     * limiting the size of the resultset.
  +     *
  +     * @return LIMIT_STYLE_DB2.
  +     */
  +    public int getLimitStyle()
  +    {
  +        return DB.LIMIT_STYLE_DB2;
       }
   }
  
  
  
  No                   revision
  No                   revision
  1.76.2.3  +77 -13    db-torque/src/java/org/apache/torque/util/BasePeer.java
  
  Index: BasePeer.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/BasePeer.java,v
  retrieving revision 1.76.2.2
  retrieving revision 1.76.2.3
  diff -u -r1.76.2.2 -r1.76.2.3
  --- BasePeer.java	20 May 2004 04:36:06 -0000	1.76.2.2
  +++ BasePeer.java	6 Aug 2004 12:13:12 -0000	1.76.2.3
  @@ -72,6 +72,7 @@
    * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
    * @author <a href="mailto:stephenh@chase3000.com">Stephen Haberman</a>
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  + * @author <a href="mailto:vido@ldh.org">Augustin Vidovic</a>
    * @version $Id$
    */
   public abstract class BasePeer implements java.io.Serializable
  @@ -933,6 +934,53 @@
       }
   
       /**
  +     * Build DB2 (OLAP) -style query with limit or offset.
  +     * If the original SQL is in variable: query then the requlting
  +     * SQL looks like this:
  +     * <pre>
  +     * SELECT B.* FROM (
  +     *          SELECT A.*, row_number() over() as TORQUE$ROWNUM FROM (
  +     *                  query
  +     *          ) A
  +     *     ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
  +     *     <= offset + limit
  +     * </pre>
  +     * 
  +     * @param query the query
  +     * @param limit 
  +     * @param offset
  +     * @return oracle-style query
  +     */ 
  +    private static String createDB2LimitOffsetQuery(Query query, 
  +            int limit, int offset)
  +    {
  +        StringBuffer buf = new StringBuffer();
  +        buf.append("SELECT B.* FROM ( ");
  +        buf.append("SELECT A.*, row_number() over() AS TORQUE$ROWNUM FROM ( ");
  +
  +        buf.append(query.toString());
  +        buf.append(" ) A ");
  +        buf.append(" ) B WHERE ");
  +
  +        if (offset > 0)
  +        {
  +            buf.append(" B.TORQUE$ROWNUM > ");
  +            buf.append(offset);
  +            if (limit > 0)
  +            {
  +                buf.append(" AND B.TORQUE$ROWNUM <= ");
  +                buf.append(offset + limit);
  +            }
  +        }
  +        else
  +        {
  +            buf.append(" B.TORQUE$ROWNUM <= ");
  +            buf.append(limit);
  +        }
  +        return buf.toString();
  +    }
  +
  +    /**
        * Method to create an SQL query for actual execution based on values in a
        * Criteria.
        *
  @@ -950,13 +998,21 @@
           int limit = criteria.getLimit();
           int offset = criteria.getOffset();
   
  -        String sql;
  -        if ((limit > 0 || offset > 0)
  -            && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
  +        String sql = null;
  +        if (limit > 0 || offset > 0)
           {
  -            sql = createOracleLimitOffsetQuery(query, limit, offset);
  -            criteria.setLimit(-1);
  -            criteria.setOffset(0);
  +            if (db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
  +            {
  +                sql = createOracleLimitOffsetQuery(query, limit, offset);
  +                criteria.setLimit(-1);
  +                criteria.setOffset(0);
  +            } 
  +            else if (db.getLimitStyle() == DB.LIMIT_STYLE_DB2)
  +            {
  +                sql = createDB2LimitOffsetQuery(query, limit, offset);
  +                criteria.setLimit(-1);
  +                criteria.setOffset(0);
  +            }
           }
           else
           {
  @@ -2511,13 +2567,21 @@
               }
           }
   
  -        String sql;
  -        if ((limit > 0 || offset > 0)
  -            && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
  +        String sql = null;
  +        if (limit > 0 || offset > 0) 
           {
  -            sql = createOracleLimitOffsetQuery(query, limit, offset);
  -            criteria.setLimit(-1);
  -            criteria.setOffset(0);
  +            if ( db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
  +            {
  +                sql = createOracleLimitOffsetQuery(query, limit, offset);
  +                criteria.setLimit(-1);
  +                criteria.setOffset(0);
  +            }
  +            else if ( db.getLimitStyle() == DB.LIMIT_STYLE_DB2)
  +            {
  +                sql = createDB2LimitOffsetQuery(query, limit, offset);
  +                criteria.setLimit(-1);
  +                criteria.setOffset(0);
  +            }
           }
           else
           {
  
  
  
  No                   revision
  No                   revision
  1.3.2.7   +3 -0      db-torque/xdocs/release-changes.xml
  
  Index: release-changes.xml
  ===================================================================
  RCS file: /home/cvs/db-torque/xdocs/release-changes.xml,v
  retrieving revision 1.3.2.6
  retrieving revision 1.3.2.7
  diff -u -r1.3.2.6 -r1.3.2.7
  --- release-changes.xml	19 Jun 2004 04:30:37 -0000	1.3.2.6
  +++ release-changes.xml	6 Aug 2004 12:13:13 -0000	1.3.2.7
  @@ -18,6 +18,9 @@
   <p>
     <ul>
       <li>
  +      DB2 limit and offset support.  Thanks to Augustin Vidovic for the patch.
  +    </li>
  +    <li>
         Upgraded to commons-pool-1.1 and commons-dbcp-1.1
       </li>
       <li>
  
  
  

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


Mime
View raw message