db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer RsIterator.java
Date Sun, 13 Nov 2005 16:22:49 GMT
brj         2005/11/13 08:22:49

  Modified:    src/test/org/apache/ojb/broker QueryTest.java
               src/java/org/apache/ojb/broker/accesslayer RsIterator.java
  Log:
  fix for Resultset#absolute(0)
  
  Revision  Changes    Path
  1.88      +14 -5     db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -r1.87 -r1.88
  --- QueryTest.java	29 Sep 2005 20:36:44 -0000	1.87
  +++ QueryTest.java	13 Nov 2005 16:22:49 -0000	1.88
  @@ -1097,29 +1097,38 @@
       }
   
       /**
  -     * Simple ReportQuery returning rows with 2 columns of Person
  +     * Simple ReportQuery returning rows with 3 columns of Person
        * needs SQL paging
        */
  -    public void _testReportQueryWithStartAndEnd()
  +    public void testReportQueryWithStartAndEnd()
       {
           Criteria crit = new Criteria();
           Collection results = new Vector();
           crit.addLike("firstname", "%o%");
  -        ReportQueryByCriteria q = ojb.getQueryFactory().newReportQuery(Person.class, crit);
  +        ReportQueryByCriteria q = QueryFactory.newReportQuery(Person.class, crit);
           q.setAttributes(new String[]{"id", "firstname", "count(*)"});
           q.addGroupBy(new String[]{"id", "firstname"});
   
           q.setStartAtIndex(3);
           q.setEndAtIndex(5);
           Iterator iter = broker.getReportQueryIteratorByQuery(q);
  -
           assertNotNull(iter);
           while(iter.hasNext())
           {
               results.add(iter.next());
           }
  -        assertTrue(results.size() == 4);
  +        assertTrue(results.size() == 3);
   
  +        results.clear();
  +        q.setStartAtIndex(1);
  +        q.setEndAtIndex(5);
  +        iter = broker.getReportQueryIteratorByQuery(q);
  +        assertNotNull(iter);
  +        while(iter.hasNext())
  +        {
  +            results.add(iter.next());
  +        }
  +        assertTrue(results.size() == 5);
       }
   
       /**
  
  
  
  1.81      +68 -37    db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- RsIterator.java	30 Sep 2005 21:45:15 -0000	1.80
  +++ RsIterator.java	13 Nov 2005 16:22:49 -0000	1.81
  @@ -408,7 +408,6 @@
           result = getCache().lookup(oid, SessionCache.LEVEL_DEEP);
           if (result == null)
           {
  -
               // map all field values from the current result set
               reader.readObjectArrayFrom(getRsAndStmt(), getRow());
   
  @@ -441,7 +440,7 @@
                            * actual class.
                            */
                           // fill reference and collection attributes
  -                            ClassDescriptor cld = getBroker().getClassDescriptor(result.getClass());
  +                        ClassDescriptor cld = getBroker().getClassDescriptor(result.getClass());
                           // don't force loading of reference
                           final boolean unforced = false;
                           // Maps ReferenceDescriptors to HashSets of owners
  @@ -620,62 +619,94 @@
        * respect to the beginning of the iterator. The first row is row 1, the
        * second is row 2, and so on.
        *
  -     * @param row
  -     *            the row to move to in this iterator, by absolute number
  +     * @param row  the row to move to in this iterator, by absolute number
        */
       public boolean absolute(int row) throws PersistenceBrokerException
       {
           boolean retval = false;
           if (supportsAdvancedJDBCCursorControl())
           {
  +            retval = absoluteAdvanced(row);
  +        }
  +        else
  +        {
  +            retval = absoluteBasic(row);
  +        }
  +        return retval;
  +    }
  +
  +    /**
  +     * absolute for basicJDBCSupport
  +     * @param row
  +     * @return
  +     */
  +    private boolean absoluteBasic(int row)
  +    {
  +        boolean retval = false;
  +        
  +        if (row > m_current_row)
  +        {
               try
               {
  -                if (getRsAndStmt().m_rs != null)
  +                while (m_current_row < row && getRsAndStmt().m_rs.next())
                   {
  -                    retval = getRsAndStmt().m_rs.absolute(row);
  -                    m_current_row = row;
  -                    setHasCalledCheck(false);
  +                    m_current_row++;
  +                }
  +                if (m_current_row == row)
  +                {
  +                    retval = true;
  +                }
  +                else
  +                {
  +                    setHasCalledCheck(true);
  +                    setHasNext(false);
  +                    retval = false;
  +                    autoReleaseDbResources();
                   }
               }
  -            catch (SQLException e)
  +            catch (Exception ex)
               {
  -                advancedJDBCSupport = false;
  +                setHasCalledCheck(true);
  +                setHasNext(false);
  +                retval = false;
               }
           }
           else
           {
  -            if (row > m_current_row)
  +            logger.info("Your driver does not support advanced JDBC Functionality, " +
  +                    "you cannot call absolute() with a position < current");
  +        }
  +        return retval;
  +    }
  +
  +    /**
  +     * absolute for advancedJDBCSupport
  +     * @param row
  +     * @return
  +     */
  +    private boolean absoluteAdvanced(int row)
  +    {
  +        boolean retval = false;
  +        
  +        try
  +        {
  +            if (getRsAndStmt().m_rs != null)
               {
  -                try
  +                if (row == 0)
                   {
  -                    while (m_current_row < row && getRsAndStmt().m_rs.next())
  -                    {
  -                        m_current_row++;
  -                    }
  -                    if (m_current_row == row)
  -                    {
  -                        retval = true;
  -                    }
  -                    else
  -                    {
  -                        setHasCalledCheck(true);
  -                        setHasNext(false);
  -                        retval = false;
  -                        autoReleaseDbResources();
  -                    }
  +                    getRsAndStmt().m_rs.beforeFirst();
                   }
  -                catch (Exception ex)
  +                else
                   {
  -                    setHasCalledCheck(true);
  -                    setHasNext(false);
  -                    retval = false;
  +                    retval = getRsAndStmt().m_rs.absolute(row);                       

                   }
  +                m_current_row = row;
  +                setHasCalledCheck(false);
               }
  -            else
  -            {
  -                logger.info(
  -                        "Your driver does not support advanced JDBC Functionality, you
cannot call absolute() with a position < current");
  -            }
  +        }
  +        catch (SQLException e)
  +        {
  +            advancedJDBCSupport = false;
           }
           return retval;
       }
  
  
  

---------------------------------------------------------------------
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