1   /**
2    * Copyright (c) 2000-2008 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.SQLQuery;
28  import com.liferay.portal.kernel.dao.orm.ScrollableResults;
29  import com.liferay.portal.kernel.dao.orm.Type;
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="SQLQueryImpl.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Brian Wing Shun Chan
42   *
43   */
44  public class SQLQueryImpl implements SQLQuery {
45  
46      public SQLQueryImpl(org.hibernate.SQLQuery sqlQuery) {
47          _sqlQuery = sqlQuery;
48      }
49  
50      public SQLQuery addEntity(String alias, Class entityClass) {
51          _sqlQuery.addEntity(alias, entityClass);
52  
53          return this;
54      }
55  
56      public SQLQuery addScalar(String columnAlias, Type type) {
57          _sqlQuery.addScalar(columnAlias, TypeTranslator.translate(type));
58  
59          return this;
60      }
61  
62      public Iterator iterate() throws ORMException {
63          try {
64              return _sqlQuery.iterate();
65          }
66          catch (Exception e) {
67              throw ExceptionTranslator.translate(e);
68          }
69      }
70  
71      public List list() throws ORMException {
72          try {
73              return _sqlQuery.list();
74          }
75          catch (Exception e) {
76              throw ExceptionTranslator.translate(e);
77          }
78      }
79  
80      public ScrollableResults scroll() throws ORMException {
81          try {
82              return new ScrollableResultsImpl(_sqlQuery.scroll());
83          }
84          catch (Exception e) {
85              throw ExceptionTranslator.translate(e);
86          }
87      }
88  
89      public Query setBoolean(int pos, boolean value) {
90          _sqlQuery.setBoolean(pos, value);
91  
92          return this;
93      }
94  
95      public Query setDouble(int pos, double value) {
96          _sqlQuery.setDouble(pos, value);
97  
98          return this;
99      }
100 
101     public Query setFirstResult(int firstResult) {
102         _sqlQuery.setFirstResult(firstResult);
103 
104         return this;
105     }
106 
107     public Query setFloat(int pos, float value) {
108         _sqlQuery.setFloat(pos, value);
109 
110         return this;
111     }
112 
113     public Query setInteger(int pos, int value) {
114         _sqlQuery.setInteger(pos, value);
115 
116         return this;
117     }
118 
119     public Query setLong(int pos, long value) {
120         _sqlQuery.setLong(pos, value);
121 
122         return this;
123     }
124 
125     public Query setMaxResults(int maxResults) {
126         _sqlQuery.setMaxResults(maxResults);
127 
128         return this;
129     }
130 
131     public Query setSerializable(int pos, Serializable value) {
132         _sqlQuery.setSerializable(pos, value);
133 
134         return this;
135     }
136 
137     public Query setShort(int pos, short value) {
138         _sqlQuery.setShort(pos, value);
139 
140         return this;
141     }
142 
143     public Query setString(int pos, String value) {
144         _sqlQuery.setString(pos, value);
145 
146         return this;
147     }
148 
149     public Query setTimestamp(int pos, Timestamp value) {
150         _sqlQuery.setTimestamp(pos, value);
151 
152         return this;
153     }
154 
155     public Object uniqueResult() throws ORMException {
156         try {
157             return _sqlQuery.uniqueResult();
158         }
159         catch (Exception e) {
160             throw ExceptionTranslator.translate(e);
161         }
162     }
163 
164     private org.hibernate.SQLQuery _sqlQuery;
165 
166 }