001: package org.apache.ojb.broker.query;
002:
003: /* Copyright 2002-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 java.util.List;
019:
020: /**
021: * represents Queries that can be used by the OJB PersistenceBroker
022: * to retrieve Objects from the underlying DB.
023: * Until now there are two implementations:
024: * 1. QueryByCriteria, represents SELECT * FROM ... WHERE ... queries
025: * 2. QueryByIdentity, uses Example objects or OIDs
026: * as templates for the db lookup
027: * there could additional implementations, e.g for user defined SQL
028: *
029: * For the Criteria API I reused code from the COBRA project,
030: * as you will see by their class comments.
031: *
032: * I removed all stuff that relies on knowlegde of the DataDictionary
033: * or MetaData layer. The Query and Criteria classes thus don't know
034: * how to build SQL statements, as in the COBRA original sources.
035: * I use the this classes as mere data-structures, that are
036: * processed by the OJB Accesslayer (SqlGenerator, JdbcAccess).
037: *
038: * This design will allow to reuse the org.apache.ojb.broker.query package in other
039: * projects without breaking any references. I hope this will be
040: * useful for someone.
041: *
042: * @author Thomas Mahler
043: * @version $Id: Query.java,v 1.17.2.3 2005/12/21 22:27:09 tomdz Exp $
044: */
045: public interface Query extends java.io.Serializable {
046: static final long serialVersionUID = 7616997212439931319L;
047:
048: public static final int NO_START_AT_INDEX = 0;
049: public static final int NO_END_AT_INDEX = 0;
050: public static final boolean SCROLLABLE = true;
051: public static final boolean NOT_SCROLLABLE = false;
052:
053: /**
054: * return the criteria of the query if present or null.
055: */
056: public abstract Criteria getCriteria();
057:
058: /**
059: * return the criteria of the query if present or null.
060: */
061: public abstract Criteria getHavingCriteria();
062:
063: /**
064: * return the template Object if present or null
065: */
066: public abstract Object getExampleObject();
067:
068: /**
069: * return the target class, representing the extend to be searched
070: */
071: public abstract Class getSearchClass();
072:
073: /**
074: * return the base class, with respect to which all paths are done
075: */
076: public abstract Class getBaseClass();
077:
078: /**
079: * return true if select DISTINCT should be used
080: */
081: public boolean isDistinct();
082:
083: /**
084: * Answer the orderBy of all Criteria and Sub Criteria the elements are of
085: * class FieldHelper
086: * @return List of FieldHelper
087: */
088: public List getOrderBy();
089:
090: /**
091: * Gets the groupby for ReportQueries of all Criteria and Sub Criteria
092: * the elements are of class FieldHelper
093: * @return List of FieldHelper
094: */
095: public List getGroupBy();
096:
097: /**
098: *
099: * @return the row at which the query should start retrieving results.
100: * If the start at index is 0, then ignore all cursor control.
101: */
102: int getStartAtIndex();
103:
104: /**
105: * Set the row at which the query should start retrieving results, inclusive
106: * first row is 1
107: * @param startAtIndex starting index, inclusive.
108: */
109: void setStartAtIndex(int startAtIndex);
110:
111: /**
112: *
113: * @return the row at which the query should stop retrieving results.
114: * If the end at index is 0, ignore all cursor control
115: */
116: int getEndAtIndex();
117:
118: /**
119: * Set the row at which the query should stop retrieving results, inclusive.
120: * first row is 1
121: * @param endAtIndex ending index, inclusive
122: */
123: void setEndAtIndex(int endAtIndex);
124:
125: /**
126: * Returns the names of Relationships to be prefetched
127: * @return List of Strings
128: */
129: public List getPrefetchedRelationships();
130:
131: /**
132: * @deprecated
133: * @param size
134: */
135: void fullSize(int size);
136:
137: /**
138: * @deprecated use OJBIterator.fullSize()
139: * @return
140: */
141: int fullSize();
142:
143: void setWithExtents(boolean withExtents);
144:
145: boolean getWithExtents();
146:
147: /**
148: * Answer true if start- and endIndex is set
149: * @return
150: */
151: public boolean usePaging();
152:
153: /**
154: * Set fetchSize hint for this Query. Passed to the JDBC driver on the
155: * Statement level. It is JDBC driver-dependant if this function has
156: * any effect at all, since fetchSize is only a hint.
157: * @param fetchSize the fetch size specific to this query
158: */
159: void setFetchSize(int fetchSize);
160:
161: /**
162: * Returns the fetchSize hint for this Query
163: * @return the fetch size hint specific to this query
164: * (or 0 if not set / using driver default)
165: */
166: int getFetchSize();
167:
168: }
|