Coverage Report - org.apache.ojb.broker.accesslayer.RsQueryObject
 
Classes in this File Line Coverage Branch Coverage Complexity
RsQueryObject
N/A
N/A
1.455
 
 1  
 package org.apache.ojb.broker.accesslayer;
 2  
 
 3  
 /* Copyright 2003-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import org.apache.ojb.broker.query.Query;
 19  
 import org.apache.ojb.broker.query.QueryBySQL;
 20  
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 21  
 
 22  
 /**
 23  
  * Helper class for {@link RsIterator} queries.
 24  
  *
 25  
  * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
 26  
  * @version $Id: RsQueryObject.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
 27  
  */
 28  
 public class RsQueryObject
 29  
 {
 30  
     private Query query;
 31  
     private ClassDescriptor cld;
 32  
     private boolean isSQLBased;
 33  
 
 34  
     //*******************************************
 35  
     // static access methods
 36  
     //*******************************************
 37  
 
 38  
     /**
 39  
      * Returns a new instance of this class.
 40  
      */
 41  
     public static RsQueryObject get(ClassDescriptor cld, Query query)
 42  
     {
 43  
         return new RsQueryObject(cld, query);
 44  
     }
 45  
 
 46  
 
 47  
     //*******************************************
 48  
     // private constructors
 49  
     //*******************************************
 50  
     private RsQueryObject(ClassDescriptor cld, Query query)
 51  
     {
 52  
         this.query = query;
 53  
         this.cld = cld;
 54  
         if(query instanceof QueryBySQL)
 55  
         {
 56  
             isSQLBased = true;
 57  
         }
 58  
     }
 59  
 
 60  
     //*******************************************
 61  
     // public methods
 62  
     //*******************************************
 63  
     public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess)
 64  
     {
 65  
         if (isSQLBased())
 66  
         {
 67  
 
 68  
             return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), cld, Query.SCROLLABLE);
 69  
         }
 70  
         else
 71  
         {
 72  
             return jdbcAccess.executeQuery(query, cld);
 73  
         }
 74  
     }
 75  
 
 76  
     public boolean usePaging()
 77  
     {
 78  
         return query.usePaging();
 79  
     }
 80  
 
 81  
     public int getStartIndex()
 82  
     {
 83  
         return query.getStartAtIndex();
 84  
     }
 85  
 
 86  
     public int getEndIndex()
 87  
     {
 88  
         return query.getEndAtIndex();
 89  
     }
 90  
 
 91  
     public ClassDescriptor getClassDescriptor()
 92  
     {
 93  
         return cld;
 94  
     }
 95  
 
 96  
     public Query getQuery()
 97  
     {
 98  
         return query;
 99  
     }
 100  
 
 101  
     public boolean isSQLBased()
 102  
     {
 103  
         return isSQLBased;
 104  
     }
 105  
 
 106  
     public String getSQLBasedQuery()
 107  
     {
 108  
         if(isSQLBased())
 109  
         {
 110  
             return ((QueryBySQL)query).getSql();
 111  
         }
 112  
         else
 113  
         {
 114  
             return null;
 115  
         }
 116  
     }
 117  
 
 118  
     public String toString()
 119  
     {
 120  
         return this.getClass().getName() +
 121  
                 "[" + "query: " + query + ", class descriptor: " + cld.getClassNameOfObject() + "]";
 122  
     }
 123  
 }