1 /*
2 * Hibernate, Relational Persistence for Idiomatic Java
3 *
4 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
5 * indicated by the @author tags or express copyright attribution
6 * statements applied by the authors. All third-party contributions are
7 * distributed under license by Red Hat Middleware LLC.
8 *
9 * This copyrighted material is made available to anyone wishing to use, modify,
10 * copy, or redistribute it subject to the terms and conditions of the GNU
11 * Lesser General Public License, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this distribution; if not, write to:
20 * Free Software Foundation, Inc.
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301 USA
23 *
24 */
25 package org.hibernate.impl;
26
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.hibernate.FlushMode;
33 import org.hibernate.HibernateException;
34 import org.hibernate.LockMode;
35 import org.hibernate.Query;
36 import org.hibernate.ScrollMode;
37 import org.hibernate.ScrollableResults;
38 import org.hibernate.engine.QueryParameters;
39 import org.hibernate.engine.SessionImplementor;
40 import org.hibernate.engine.query.ParameterMetadata;
41
42 /**
43 * default implementation of the <tt>Query</tt> interface,
44 * for "ordinary" HQL queries (not collection filters)
45 * @see CollectionFilterImpl
46 * @author Gavin King
47 */
48 public class QueryImpl extends AbstractQueryImpl {
49
50 private Map lockModes = new HashMap(2);
51
52 public QueryImpl(
53 String queryString,
54 FlushMode flushMode,
55 SessionImplementor session,
56 ParameterMetadata parameterMetadata) {
57 super( queryString, flushMode, session, parameterMetadata );
58 }
59
60 public QueryImpl(String queryString, SessionImplementor session, ParameterMetadata parameterMetadata) {
61 this( queryString, null, session, parameterMetadata );
62 }
63
64 public Iterator iterate() throws HibernateException {
65 verifyParameters();
66 Map namedParams = getNamedParams();
67 before();
68 try {
69 return getSession().iterate(
70 expandParameterLists(namedParams),
71 getQueryParameters(namedParams)
72 );
73 }
74 finally {
75 after();
76 }
77 }
78
79 public ScrollableResults scroll() throws HibernateException {
80 return scroll( ScrollMode.SCROLL_INSENSITIVE );
81 }
82
83 public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException {
84 verifyParameters();
85 Map namedParams = getNamedParams();
86 before();
87 QueryParameters qp = getQueryParameters(namedParams);
88 qp.setScrollMode(scrollMode);
89 try {
90 return getSession().scroll( expandParameterLists(namedParams), qp );
91 }
92 finally {
93 after();
94 }
95 }
96
97 public List list() throws HibernateException {
98 verifyParameters();
99 Map namedParams = getNamedParams();
100 before();
101 try {
102 return getSession().list(
103 expandParameterLists(namedParams),
104 getQueryParameters(namedParams)
105 );
106 }
107 finally {
108 after();
109 }
110 }
111
112 public int executeUpdate() throws HibernateException {
113 verifyParameters();
114 Map namedParams = getNamedParams();
115 before();
116 try {
117 return getSession().executeUpdate(
118 expandParameterLists( namedParams ),
119 getQueryParameters( namedParams )
120 );
121 }
122 finally {
123 after();
124 }
125 }
126
127 public Query setLockMode(String alias, LockMode lockMode) {
128 lockModes.put(alias, lockMode);
129 return this;
130 }
131
132 protected Map getLockModes() {
133 return lockModes;
134 }
135
136 }
137
138
139
140
141
142