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