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.1 2007-08-24 22:17:36 ewestfal Exp $
044 */
045 public interface Query extends java.io.Serializable
046 {
047 static final long serialVersionUID = 7616997212439931319L;
048
049 public static final int NO_START_AT_INDEX = 0;
050 public static final int NO_END_AT_INDEX = 0;
051 public static final boolean SCROLLABLE = true;
052 public static final boolean NOT_SCROLLABLE = false;
053
054 /**
055 * return the criteria of the query if present or null.
056 */
057 public abstract Criteria getCriteria();
058
059 /**
060 * return the criteria of the query if present or null.
061 */
062 public abstract Criteria getHavingCriteria();
063
064 /**
065 * return the template Object if present or null
066 */
067 public abstract Object getExampleObject();
068
069 /**
070 * return the target class, representing the extend to be searched
071 */
072 public abstract Class getSearchClass();
073
074 /**
075 * return the base class, with respect to which all paths are done
076 */
077 public abstract Class getBaseClass();
078
079 /**
080 * return true if select DISTINCT should be used
081 */
082 public boolean isDistinct();
083
084 /**
085 * Answer the orderBy of all Criteria and Sub Criteria the elements are of
086 * class FieldHelper
087 * @return List of FieldHelper
088 */
089 public List getOrderBy();
090
091 /**
092 * Gets the groupby for ReportQueries of all Criteria and Sub Criteria
093 * the elements are of class FieldHelper
094 * @return List of FieldHelper
095 */
096 public List getGroupBy();
097
098 /**
099 *
100 * @return the row at which the query should start retrieving results.
101 * If the start at index is 0, then ignore all cursor control.
102 */
103 int getStartAtIndex();
104
105 /**
106 * Set the row at which the query should start retrieving results, inclusive
107 * first row is 1
108 * @param startAtIndex starting index, inclusive.
109 */
110 void setStartAtIndex(int startAtIndex);
111
112 /**
113 *
114 * @return the row at which the query should stop retrieving results.
115 * If the end at index is 0, ignore all cursor control
116 */
117 int getEndAtIndex();
118
119 /**
120 * Set the row at which the query should stop retrieving results, inclusive.
121 * first row is 1
122 * @param endAtIndex ending index, inclusive
123 */
124 void setEndAtIndex(int endAtIndex);
125
126 /**
127 * Returns the names of Relationships to be prefetched
128 * @return List of Strings
129 */
130 public List getPrefetchedRelationships();
131
132 /**
133 * @deprecated
134 * @param size
135 */
136 void fullSize(int size);
137 /**
138 * @deprecated use OJBIterator.fullSize()
139 * @return
140 */
141 int fullSize();
142
143 void setWithExtents(boolean withExtents);
144 boolean getWithExtents();
145
146 /**
147 * Answer true if start- and endIndex is set
148 * @return
149 */
150 public boolean usePaging();
151
152 /**
153 * Set fetchSize hint for this Query. Passed to the JDBC driver on the
154 * Statement level. It is JDBC driver-dependant if this function has
155 * any effect at all, since fetchSize is only a hint.
156 * @param fetchSize the fetch size specific to this query
157 */
158 void setFetchSize(int fetchSize);
159
160 /**
161 * Returns the fetchSize hint for this Query
162 * @return the fetch size hint specific to this query
163 * (or 0 if not set / using driver default)
164 */
165 int getFetchSize();
166
167 }