KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > impl > QueryImpl


1 //$Id: QueryImpl.java,v 1.13 2005/07/11 15:32:27 steveebersole Exp $
2
package org.hibernate.impl;
3
4 import java.util.HashMap JavaDoc;
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import org.hibernate.FlushMode;
10 import org.hibernate.HibernateException;
11 import org.hibernate.LockMode;
12 import org.hibernate.Query;
13 import org.hibernate.ScrollMode;
14 import org.hibernate.ScrollableResults;
15 import org.hibernate.engine.QueryParameters;
16 import org.hibernate.engine.SessionImplementor;
17
18 /**
19  * default implementation of the <tt>Query</tt> interface,
20  * for "ordinary" HQL queries (not collection filters)
21  * @see CollectionFilterImpl
22  * @author Gavin King
23  */

24 public class QueryImpl extends AbstractQueryImpl {
25
26     private Map JavaDoc lockModes = new HashMap JavaDoc(2);
27
28     public QueryImpl(String JavaDoc queryString, FlushMode flushMode, SessionImplementor session) {
29         super(queryString, flushMode, session);
30     }
31
32     public QueryImpl(String JavaDoc queryString, SessionImplementor session) {
33         this(queryString, null, session);
34     }
35
36     public Iterator JavaDoc iterate() throws HibernateException {
37         verifyParameters();
38         Map JavaDoc namedParams = getNamedParams();
39         before();
40         try {
41             return getSession().iterate(
42                     bindParameterLists(namedParams),
43                     getQueryParameters(namedParams)
44             );
45         }
46         finally {
47             after();
48         }
49     }
50
51     public ScrollableResults scroll() throws HibernateException {
52         return scroll( ScrollMode.SCROLL_INSENSITIVE );
53     }
54
55     public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException {
56         verifyParameters();
57         Map JavaDoc namedParams = getNamedParams();
58         before();
59         QueryParameters qp = getQueryParameters(namedParams);
60         qp.setScrollMode(scrollMode);
61         try {
62             return getSession().scroll( bindParameterLists(namedParams), qp );
63         }
64         finally {
65             after();
66         }
67     }
68
69     public List JavaDoc list() throws HibernateException {
70         verifyParameters();
71         Map JavaDoc namedParams = getNamedParams();
72         before();
73         try {
74             return getSession().list(
75                     bindParameterLists(namedParams),
76                     getQueryParameters(namedParams)
77             );
78         }
79         finally {
80             after();
81         }
82     }
83
84     public int executeUpdate() throws HibernateException {
85         verifyParameters();
86         Map JavaDoc namedParams = getNamedParams();
87         before();
88         try {
89             return getSession().executeUpdate(
90                     bindParameterLists( namedParams ),
91                     getQueryParameters( namedParams )
92             );
93         }
94         finally {
95             after();
96         }
97     }
98
99     public Query setLockMode(String JavaDoc alias, LockMode lockMode) {
100         lockModes.put(alias, lockMode);
101         return this;
102     }
103
104     protected Map JavaDoc getLockModes() {
105         return lockModes;
106     }
107
108 }
109
110
111
112
113
114
115
Popular Tags