1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portal.dao.orm.hibernate;
21  
22  import com.liferay.portal.kernel.dao.orm.ORMException;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.ScrollableResults;
25  import com.liferay.portal.kernel.util.ListUtil;
26  import com.liferay.portal.kernel.util.UnmodifiableList;
27  
28  import java.io.Serializable;
29  
30  import java.sql.Timestamp;
31  
32  import java.util.Iterator;
33  import java.util.List;
34  
35  /**
36   * <a href="QueryImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Brian Wing Shun Chan
39   *
40   */
41  public class QueryImpl implements Query {
42  
43      public QueryImpl(org.hibernate.Query query) {
44          _query = query;
45      }
46  
47      public int executeUpdate() throws ORMException {
48          try {
49              return _query.executeUpdate();
50          }
51          catch (Exception e) {
52              throw ExceptionTranslator.translate(e);
53          }
54      }
55  
56      public Iterator iterate() throws ORMException {
57          return iterate(true);
58      }
59  
60      public Iterator iterate(boolean unmodifiable) throws ORMException {
61          try {
62              return list(unmodifiable).iterator();
63          }
64          catch (Exception e) {
65              throw ExceptionTranslator.translate(e);
66          }
67      }
68  
69      public List list() throws ORMException {
70          return list(true);
71      }
72  
73      public List list(boolean unmodifiable) throws ORMException {
74          try {
75              List list = _query.list();
76  
77              if (unmodifiable) {
78                  return new UnmodifiableList(list);
79              }
80              else {
81                  return ListUtil.copy(list);
82              }
83          }
84          catch (Exception e) {
85              throw ExceptionTranslator.translate(e);
86          }
87      }
88  
89      public ScrollableResults scroll() throws ORMException {
90          try {
91              return new ScrollableResultsImpl(_query.scroll());
92          }
93          catch (Exception e) {
94              throw ExceptionTranslator.translate(e);
95          }
96      }
97  
98      public Query setBoolean(int pos, boolean value) {
99          _query.setBoolean(pos, value);
100 
101         return this;
102     }
103 
104     public Query setDouble(int pos, double value) {
105         _query.setDouble(pos, value);
106 
107         return this;
108     }
109 
110     public Query setFirstResult(int firstResult) {
111         _query.setFirstResult(firstResult);
112 
113         return this;
114     }
115 
116     public Query setFloat(int pos, float value) {
117         _query.setFloat(pos, value);
118 
119         return this;
120     }
121 
122     public Query setInteger(int pos, int value) {
123         _query.setInteger(pos, value);
124 
125         return this;
126     }
127 
128     public Query setLong(int pos, long value) {
129         _query.setLong(pos, value);
130 
131         return this;
132     }
133 
134     public Query setMaxResults(int maxResults) {
135         _query.setMaxResults(maxResults);
136 
137         return this;
138     }
139 
140     public Query setSerializable(int pos, Serializable value) {
141         _query.setSerializable(pos, value);
142 
143         return this;
144     }
145 
146     public Query setShort(int pos, short value) {
147         _query.setShort(pos, value);
148 
149         return this;
150     }
151 
152     public Query setString(int pos, String value) {
153         _query.setString(pos, value);
154 
155         return this;
156     }
157 
158     public Query setTimestamp(int pos, Timestamp value) {
159         _query.setTimestamp(pos, value);
160 
161         return this;
162     }
163 
164     public Object uniqueResult() throws ORMException {
165         try {
166             return _query.uniqueResult();
167         }
168         catch (Exception e) {
169             throw ExceptionTranslator.translate(e);
170         }
171     }
172 
173     private org.hibernate.Query _query;
174 
175 }