001 package org.apache.ojb.broker.accesslayer;
002
003 /* Copyright 2003-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import org.apache.ojb.broker.query.Query;
019 import org.apache.ojb.broker.query.QueryBySQL;
020 import org.apache.ojb.broker.metadata.ClassDescriptor;
021
022 /**
023 * Helper class for {@link RsIterator} queries.
024 *
025 * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
026 * @version $Id: RsQueryObject.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
027 */
028 public class RsQueryObject
029 {
030 private Query query;
031 private ClassDescriptor cld;
032 private boolean isSQLBased;
033
034 //*******************************************
035 // static access methods
036 //*******************************************
037
038 /**
039 * Returns a new instance of this class.
040 */
041 public static RsQueryObject get(ClassDescriptor cld, Query query)
042 {
043 return new RsQueryObject(cld, query);
044 }
045
046
047 //*******************************************
048 // private constructors
049 //*******************************************
050 private RsQueryObject(ClassDescriptor cld, Query query)
051 {
052 this.query = query;
053 this.cld = cld;
054 if(query instanceof QueryBySQL)
055 {
056 isSQLBased = true;
057 }
058 }
059
060 //*******************************************
061 // public methods
062 //*******************************************
063 public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess)
064 {
065 if (isSQLBased())
066 {
067
068 return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), cld, Query.SCROLLABLE);
069 }
070 else
071 {
072 return jdbcAccess.executeQuery(query, cld);
073 }
074 }
075
076 public boolean usePaging()
077 {
078 return query.usePaging();
079 }
080
081 public int getStartIndex()
082 {
083 return query.getStartAtIndex();
084 }
085
086 public int getEndIndex()
087 {
088 return query.getEndAtIndex();
089 }
090
091 public ClassDescriptor getClassDescriptor()
092 {
093 return cld;
094 }
095
096 public Query getQuery()
097 {
098 return query;
099 }
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 }