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 int executeUpdate() throws ORMException {
63          try {
64              return _sqlQuery.executeUpdate();
65          }
66          catch (Exception e) {
67              throw ExceptionTranslator.translate(e);
68          }
69      }
70  
71      public Iterator iterate() throws ORMException {
72          try {
73              return _sqlQuery.iterate();
74          }
75          catch (Exception e) {
76              throw ExceptionTranslator.translate(e);
77          }
78      }
79  
80      public List list() throws ORMException {
81          try {
82              return _sqlQuery.list();
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(_sqlQuery.scroll());
92          }
93          catch (Exception e) {
94              throw ExceptionTranslator.translate(e);
95          }
96      }
97  
98      public Query setBoolean(int pos, boolean value) {
99          _sqlQuery.setBoolean(pos, value);
100 
101         return this;
102     }
103 
104     public Query setDouble(int pos, double value) {
105         _sqlQuery.setDouble(pos, value);
106 
107         return this;
108     }
109 
110     public Query setFirstResult(int firstResult) {
111         _sqlQuery.setFirstResult(firstResult);
112 
113         return this;
114     }
115 
116     public Query setFloat(int pos, float value) {
117         _sqlQuery.setFloat(pos, value);
118 
119         return this;
120     }
121 
122     public Query setInteger(int pos, int value) {
123         _sqlQuery.setInteger(pos, value);
124 
125         return this;
126     }
127 
128     public Query setLong(int pos, long value) {
129         _sqlQuery.setLong(pos, value);
130 
131         return this;
132     }
133 
134     public Query setMaxResults(int maxResults) {
135         _sqlQuery.setMaxResults(maxResults);
136 
137         return this;
138     }
139 
140     public Query setSerializable(int pos, Serializable value) {
141         _sqlQuery.setSerializable(pos, value);
142 
143         return this;
144     }
145 
146     public Query setShort(int pos, short value) {
147         _sqlQuery.setShort(pos, value);
148 
149         return this;
150     }
151 
152     public Query setString(int pos, String value) {
153         _sqlQuery.setString(pos, value);
154 
155         return this;
156     }
157 
158     public Query setTimestamp(int pos, Timestamp value) {
159         _sqlQuery.setTimestamp(pos, value);
160 
161         return this;
162     }
163 
164     public Object uniqueResult() throws ORMException {
165         try {
166             return _sqlQuery.uniqueResult();
167         }
168         catch (Exception e) {
169             throw ExceptionTranslator.translate(e);
170         }
171     }
172 
173     private org.hibernate.SQLQuery _sqlQuery;
174 
175 }