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