1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.ORMException;
26  import com.liferay.portal.kernel.dao.orm.Query;
27  import com.liferay.portal.kernel.dao.orm.ScrollableResults;
28  import com.liferay.portal.kernel.util.ListUtil;
29  import com.liferay.portal.kernel.util.UnmodifiableList;
30  
31  import java.io.Serializable;
32  
33  import java.sql.Timestamp;
34  
35  import java.util.Iterator;
36  import java.util.List;
37  
38  /**
39   * <a href="QueryImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
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(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 setDouble(int pos, double value) {
108         _query.setDouble(pos, value);
109 
110         return this;
111     }
112 
113     public Query setFirstResult(int firstResult) {
114         _query.setFirstResult(firstResult);
115 
116         return this;
117     }
118 
119     public Query setFloat(int pos, float value) {
120         _query.setFloat(pos, value);
121 
122         return this;
123     }
124 
125     public Query setInteger(int pos, int value) {
126         _query.setInteger(pos, value);
127 
128         return this;
129     }
130 
131     public Query setLong(int pos, long value) {
132         _query.setLong(pos, value);
133 
134         return this;
135     }
136 
137     public Query setMaxResults(int maxResults) {
138         _query.setMaxResults(maxResults);
139 
140         return this;
141     }
142 
143     public Query setSerializable(int pos, Serializable value) {
144         _query.setSerializable(pos, value);
145 
146         return this;
147     }
148 
149     public Query setShort(int pos, short value) {
150         _query.setShort(pos, value);
151 
152         return this;
153     }
154 
155     public Query setString(int pos, String value) {
156         _query.setString(pos, value);
157 
158         return this;
159     }
160 
161     public Query setTimestamp(int pos, Timestamp value) {
162         _query.setTimestamp(pos, value);
163 
164         return this;
165     }
166 
167     public Object uniqueResult() throws ORMException {
168         try {
169             return _query.uniqueResult();
170         }
171         catch (Exception e) {
172             throw ExceptionTranslator.translate(e);
173         }
174     }
175 
176     private org.hibernate.Query _query;
177 
178 }