1
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.SQLQuery;
21 import com.liferay.portal.kernel.dao.orm.ScrollableResults;
22 import com.liferay.portal.kernel.dao.orm.Type;
23 import com.liferay.portal.kernel.util.ListUtil;
24 import com.liferay.portal.kernel.util.UnmodifiableList;
25
26 import java.io.Serializable;
27
28 import java.sql.Timestamp;
29
30 import java.util.Iterator;
31 import java.util.List;
32
33
38 public class SQLQueryImpl implements SQLQuery {
39
40 public SQLQueryImpl(org.hibernate.SQLQuery sqlQuery) {
41 _sqlQuery = sqlQuery;
42 }
43
44 public SQLQuery addEntity(String alias, Class<?> entityClass) {
45 _sqlQuery.addEntity(alias, entityClass);
46
47 return this;
48 }
49
50 public SQLQuery addScalar(String columnAlias, Type type) {
51 _sqlQuery.addScalar(columnAlias, TypeTranslator.translate(type));
52
53 return this;
54 }
55
56 public int executeUpdate() throws ORMException {
57 try {
58 return _sqlQuery.executeUpdate();
59 }
60 catch (Exception e) {
61 throw ExceptionTranslator.translate(e);
62 }
63 }
64
65 @SuppressWarnings("unchecked")
66 public Iterator iterate() throws ORMException {
67 return iterate(true);
68 }
69
70 @SuppressWarnings("unchecked")
71 public Iterator iterate(boolean unmodifiable) throws ORMException {
72 try {
73 return list(unmodifiable).iterator();
74 }
75 catch (Exception e) {
76 throw ExceptionTranslator.translate(e);
77 }
78 }
79
80 @SuppressWarnings("unchecked")
81 public List list() throws ORMException {
82 return list(true);
83 }
84
85 @SuppressWarnings("unchecked")
86 public List list(boolean unmodifiable) throws ORMException {
87 try {
88 List list = _sqlQuery.list();
89
90 if (unmodifiable) {
91 return new UnmodifiableList(list);
92 }
93 else {
94 return ListUtil.copy(list);
95 }
96 }
97 catch (Exception e) {
98 throw ExceptionTranslator.translate(e);
99 }
100 }
101
102 public ScrollableResults scroll() throws ORMException {
103 try {
104 return new ScrollableResultsImpl(_sqlQuery.scroll());
105 }
106 catch (Exception e) {
107 throw ExceptionTranslator.translate(e);
108 }
109 }
110
111 public Query setBoolean(int pos, boolean value) {
112 _sqlQuery.setBoolean(pos, value);
113
114 return this;
115 }
116
117 public Query setCacheable(boolean cacheable) {
118 _sqlQuery.setCacheable(cacheable);
119
120 return this;
121 }
122
123 public Query setCacheMode(CacheMode cacheMode) {
124 _sqlQuery.setCacheMode(CacheModeTranslator.translate(cacheMode));
125
126 return this;
127 }
128
129 public Query setCacheRegion(String cacheRegion) {
130 _sqlQuery.setCacheRegion(cacheRegion);
131
132 return this;
133 }
134
135 public Query setDouble(int pos, double value) {
136 _sqlQuery.setDouble(pos, value);
137
138 return this;
139 }
140
141 public Query setFirstResult(int firstResult) {
142 _sqlQuery.setFirstResult(firstResult);
143
144 return this;
145 }
146
147 public Query setFloat(int pos, float value) {
148 _sqlQuery.setFloat(pos, value);
149
150 return this;
151 }
152
153 public Query setInteger(int pos, int value) {
154 _sqlQuery.setInteger(pos, value);
155
156 return this;
157 }
158
159 public Query setLong(int pos, long value) {
160 _sqlQuery.setLong(pos, value);
161
162 return this;
163 }
164
165 public Query setMaxResults(int maxResults) {
166 _sqlQuery.setMaxResults(maxResults);
167
168 return this;
169 }
170
171 public Query setSerializable(int pos, Serializable value) {
172 _sqlQuery.setSerializable(pos, value);
173
174 return this;
175 }
176
177 public Query setShort(int pos, short value) {
178 _sqlQuery.setShort(pos, value);
179
180 return this;
181 }
182
183 public Query setString(int pos, String value) {
184 _sqlQuery.setString(pos, value);
185
186 return this;
187 }
188
189 public Query setTimestamp(int pos, Timestamp value) {
190 _sqlQuery.setTimestamp(pos, value);
191
192 return this;
193 }
194
195 public Object uniqueResult() throws ORMException {
196 try {
197 return _sqlQuery.uniqueResult();
198 }
199 catch (Exception e) {
200 throw ExceptionTranslator.translate(e);
201 }
202 }
203
204 private org.hibernate.SQLQuery _sqlQuery;
205
206 }