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.5.2.2 2005/12/21 22:22:58 tomdz Exp $
027: */
028: public class RsQueryObject {
029: private Query query;
030: private ClassDescriptor cld;
031: private boolean isSQLBased;
032:
033: //*******************************************
034: // static access methods
035: //*******************************************
036:
037: /**
038: * Returns a new instance of this class.
039: */
040: public static RsQueryObject get(ClassDescriptor cld, Query query) {
041: return new RsQueryObject(cld, query);
042: }
043:
044: //*******************************************
045: // private constructors
046: //*******************************************
047: private RsQueryObject(ClassDescriptor cld, Query query) {
048: this .query = query;
049: this .cld = cld;
050: if (query instanceof QueryBySQL) {
051: isSQLBased = true;
052: }
053: }
054:
055: //*******************************************
056: // public methods
057: //*******************************************
058: public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess) {
059: if (isSQLBased()) {
060:
061: return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(),
062: cld, Query.SCROLLABLE);
063: } else {
064: return jdbcAccess.executeQuery(query, cld);
065: }
066: }
067:
068: public boolean usePaging() {
069: return query.usePaging();
070: }
071:
072: public int getStartIndex() {
073: return query.getStartAtIndex();
074: }
075:
076: public int getEndIndex() {
077: return query.getEndAtIndex();
078: }
079:
080: public ClassDescriptor getClassDescriptor() {
081: return cld;
082: }
083:
084: public Query getQuery() {
085: return query;
086: }
087:
088: public boolean isSQLBased() {
089: return isSQLBased;
090: }
091:
092: public String getSQLBasedQuery() {
093: if (isSQLBased()) {
094: return ((QueryBySQL) query).getSql();
095: } else {
096: return null;
097: }
098: }
099:
100: public String toString() {
101: return this .getClass().getName() + "[" + "query: " + query
102: + ", class descriptor: " + cld.getClassNameOfObject()
103: + "]";
104: }
105: }
|