db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpoes...@apache.org
Subject cvs commit: db-torque/src/java/org/apache/torque/util BasePeer.java
Date Tue, 24 Jun 2003 12:23:04 GMT
mpoeschl    2003/06/24 05:23:04

  Modified:    src/java/org/apache/torque/util BasePeer.java
  Log:
  move creation of oracle style limit offset query to a private method to avoid code duplication
  
  Revision  Changes    Path
  1.69      +50 -69    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.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- BasePeer.java	20 Jun 2003 08:30:07 -0000	1.68
  +++ BasePeer.java	24 Jun 2003 12:23:03 -0000	1.69
  @@ -904,6 +904,53 @@
       }
   
       /**
  +     * Build Oracle-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.*, rownum 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 createOracleLimitOffsetQuery(Query query, 
  +            int limit, int offset)
  +    {
  +        StringBuffer buf = new StringBuffer();
  +        buf.append("SELECT B.* FROM ( ");
  +        buf.append("SELECT A.*, rownum 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.
        *
  @@ -925,42 +972,9 @@
           if ((limit > 0 || offset > 0)
               && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
           {
  -            // Build Oracle-style query with limit or offset.
  -            // If the original SQL is in variable: query then the requlting
  -            // SQL looks like this:
  -            // SELECT B.* FROM (
  -            //          SELECT A.*, rownum as TORQUE$ROWNUM FROM (
  -            //                  query
  -            //          ) A
  -            //     ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
  -            //     <= offset + limit
  -            StringBuffer buf = new StringBuffer();
  -            buf.append("SELECT B.* FROM ( ");
  -            buf.append("SELECT A.*, rownum 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);
  -            }
  +            sql = createOracleLimitOffsetQuery(query, limit, offset);
               criteria.setLimit(-1);
               criteria.setOffset(0);
  -
  -            sql = buf.toString();
           }
           else
           {
  @@ -2512,42 +2526,9 @@
           if ((limit > 0 || offset > 0)
               && db.getLimitStyle() == DB.LIMIT_STYLE_ORACLE)
           {
  -            // Build Oracle-style query with limit or offset.
  -            // If the original SQL is in variable: query then the requlting
  -            // SQL looks like this:
  -            // SELECT B.* FROM (
  -            //          SELECT A.*, rownum as TORQUE$ROWNUM FROM (
  -            //                  query
  -            //          ) A
  -            //     ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
  -            //     <= offset + limit
  -            StringBuffer buf = new StringBuffer();
  -            buf.append("SELECT B.* FROM ( ");
  -            buf.append("SELECT A.*, rownum 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);
  -            }
  +            sql = createOracleLimitOffsetQuery(query, limit, offset);
               criteria.setLimit(-1);
               criteria.setOffset(0);
  -
  -            sql = buf.toString();
           }
           else
           {
  
  
  

Mime
View raw message