1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portal.dao.orm.hibernate;
16  
17  import com.liferay.portal.kernel.dao.orm.CacheMode;
18  import com.liferay.portal.kernel.dao.orm.ORMException;
19  import com.liferay.portal.kernel.dao.orm.Query;
20  import com.liferay.portal.kernel.dao.orm.ScrollableResults;
21  import com.liferay.portal.kernel.util.ListUtil;
22  import com.liferay.portal.kernel.util.UnmodifiableList;
23  
24  import java.io.Serializable;
25  
26  import java.sql.Timestamp;
27  
28  import java.util.Iterator;
29  import java.util.List;
30  
31  /**
32   * <a href="QueryImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class QueryImpl implements Query {
37  
38      public QueryImpl(org.hibernate.Query query) {
39          _query = query;
40      }
41  
42      public int executeUpdate() throws ORMException {
43          try {
44              return _query.executeUpdate();
45          }
46          catch (Exception e) {
47              throw ExceptionTranslator.translate(e);
48          }
49      }
50  
51      public Iterator<?> iterate() throws ORMException {
52          return iterate(true);
53      }
54  
55      public Iterator<?> iterate(boolean unmodifiable) throws ORMException {
56          try {
57              return list(unmodifiable).iterator();
58          }
59          catch (Exception e) {
60              throw ExceptionTranslator.translate(e);
61          }
62      }
63  
64      public List<?> list() throws ORMException {
65          return list(true);
66      }
67  
68      public List<?> list(boolean unmodifiable) throws ORMException {
69          try {
70              List<?> list = _query.list();
71  
72              if (unmodifiable) {
73                  return new UnmodifiableList<Object>(list);
74              }
75              else {
76                  return ListUtil.copy(list);
77              }
78          }
79          catch (Exception e) {
80              throw ExceptionTranslator.translate(e);
81          }
82      }
83  
84      public ScrollableResults scroll() throws ORMException {
85          try {
86              return new ScrollableResultsImpl(_query.scroll());
87          }
88          catch (Exception e) {
89              throw ExceptionTranslator.translate(e);
90          }
91      }
92  
93      public Query setBoolean(int pos, boolean value) {
94          _query.setBoolean(pos, value);
95  
96          return this;
97      }
98  
99      public Query setCacheable(boolean cacheable) {
100         _query.setCacheable(cacheable);
101 
102         return this;
103     }
104 
105     public Query setCacheMode(CacheMode cacheMode) {
106         _query.setCacheMode(CacheModeTranslator.translate(cacheMode));
107 
108         return this;
109     }
110 
111     public Query setCacheRegion(String cacheRegion) {
112         _query.setCacheRegion(cacheRegion);
113 
114         return this;
115     }
116 
117     public Query setDouble(int pos, double value) {
118         _query.setDouble(pos, value);
119 
120         return this;
121     }
122 
123     public Query setFirstResult(int firstResult) {
124         _query.setFirstResult(firstResult);
125 
126         return this;
127     }
128 
129     public Query setFloat(int pos, float value) {
130         _query.setFloat(pos, value);
131 
132         return this;
133     }
134 
135     public Query setInteger(int pos, int value) {
136         _query.setInteger(pos, value);
137 
138         return this;
139     }
140 
141     public Query setLong(int pos, long value) {
142         _query.setLong(pos, value);
143 
144         return this;
145     }
146 
147     public Query setMaxResults(int maxResults) {
148         _query.setMaxResults(maxResults);
149 
150         return this;
151     }
152 
153     public Query setSerializable(int pos, Serializable value) {
154         _query.setSerializable(pos, value);
155 
156         return this;
157     }
158 
159     public Query setShort(int pos, short value) {
160         _query.setShort(pos, value);
161 
162         return this;
163     }
164 
165     public Query setString(int pos, String value) {
166         _query.setString(pos, value);
167 
168         return this;
169     }
170 
171     public Query setTimestamp(int pos, Timestamp value) {
172         _query.setTimestamp(pos, value);
173 
174         return this;
175     }
176 
177     public Object uniqueResult() throws ORMException {
178         try {
179             return _query.uniqueResult();
180         }
181         catch (Exception e) {
182             throw ExceptionTranslator.translate(e);
183         }
184     }
185 
186     private org.hibernate.Query _query;
187 
188 }