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