KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > hql > QueryTranslator


1 //$Id: QueryTranslator.java,v 1.21 2005/06/20 19:36:56 steveebersole Exp $
2
package org.hibernate.hql;
3
4 import org.hibernate.HibernateException;
5 import org.hibernate.MappingException;
6 import org.hibernate.QueryException;
7 import org.hibernate.ScrollableResults;
8 import org.hibernate.engine.QueryParameters;
9 import org.hibernate.engine.SessionImplementor;
10 import org.hibernate.event.EventSource;
11 import org.hibernate.type.Type;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17
18 /**
19  * Defines the constract of an HQL->SQL translator.
20  *
21  * @author josh Mar 14, 2004 11:14:21 AM
22  */

23 public interface QueryTranslator {
24     // Error message constants.
25

26     String JavaDoc ERROR_CANNOT_FETCH_WITH_ITERATE = "fetch may not be used with scroll() or iterate()";
27     String JavaDoc ERROR_NAMED_PARAMETER_DOES_NOT_APPEAR = "Named parameter does not appear in Query: ";
28     String JavaDoc ERROR_CANNOT_DETERMINE_TYPE = "Could not determine type of: ";
29     String JavaDoc ERROR_CANNOT_FORMAT_LITERAL = "Could not format constant value to SQL literal: ";
30
31     /**
32      * Compile a "normal" query. This method may be called multiple
33      * times. Subsequent invocations are no-ops.
34      *
35      * @param replacements Defined query substitutions.
36      * @param shallow Does this represent a shallow (scalar or entity-id) select?
37      * @throws QueryException There was a problem parsing the query string.
38      * @throws MappingException There was a problem querying defined mappings.
39      */

40     void compile(Map JavaDoc replacements, boolean shallow) throws QueryException, MappingException;
41
42     /**
43      * Perform a list operation given the underlying query definition.
44      *
45      * @param session The session owning this query.
46      * @param queryParameters The query bind parameters.
47      * @return The query list results.
48      * @throws HibernateException
49      */

50     List JavaDoc list(SessionImplementor session, QueryParameters queryParameters)
51             throws HibernateException;
52
53     /**
54      * Perform an iterate operation given the underlying query defintion.
55      *
56      * @param queryParameters The query bind parameters.
57      * @param session The session owning this query.
58      * @return An iterator over the query results.
59      * @throws HibernateException
60      */

61     Iterator JavaDoc iterate(QueryParameters queryParameters, EventSource session)
62             throws HibernateException;
63
64     /**
65      * Perform a scroll operation given the underlying query defintion.
66      *
67      * @param queryParameters The query bind parameters.
68      * @param session The session owning this query.
69      * @return The ScrollableResults wrapper around the query results.
70      * @throws HibernateException
71      */

72     ScrollableResults scroll(QueryParameters queryParameters, SessionImplementor session)
73             throws HibernateException;
74
75     /**
76      * Perform a bulk update/delete operation given the underlying query defintion.
77      *
78      * @param queryParameters The query bind parameters.
79      * @param session The session owning this query.
80      * @return The number of entities updated or deleted.
81      * @throws HibernateException
82      */

83     int executeUpdate(QueryParameters queryParameters, SessionImplementor session)
84             throws HibernateException;
85
86     /**
87      * Returns the set of query spaces (table names) that the query referrs to.
88      *
89      * @return A set of query spaces (table names).
90      */

91     Set JavaDoc getQuerySpaces();
92
93     /**
94      * Returns the SQL string generated by the translator.
95      *
96      * @return the SQL string generated by the translator.
97      */

98     String JavaDoc getSQLString();
99
100     /**
101      * Returns the HQL string processed by the translator.
102      *
103      * @return the HQL string processed by the translator.
104      */

105     String JavaDoc getQueryString();
106
107     /**
108      * Returns the filters enabled for this query translator.
109      *
110      * @return Filters enabled for this query execution.
111      */

112     Map JavaDoc getEnabledFilters();
113
114     /**
115      * Returns an array of Types represented in the query result.
116      *
117      * @return Query return types.
118      */

119     Type[] getReturnTypes();
120     
121     /**
122      * Returns an array of HQL aliases
123      */

124     String JavaDoc[] getReturnAliases();
125
126     /**
127      * Returns the column names in the generated SQL.
128      *
129      * @return the column names in the generated SQL.
130      */

131     String JavaDoc[][] getColumnNames();
132
133     /**
134      * Returns the locations of the specified named parameter in the SQL.
135      * @param name The name of the named parameter.
136      * @return the locations of the specified named parameter in the SQL.
137      * @throws QueryException if something goes wrong.
138      */

139     int[] getNamedParameterLocs(String JavaDoc name) throws QueryException;
140
141     void validateScrollability() throws HibernateException;
142
143     boolean containsCollectionFetches();
144 }
145
Popular Tags