001
014
015 package com.liferay.portlet.social.service.persistence.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryPos;
018 import com.liferay.portal.kernel.dao.orm.QueryUtil;
019 import com.liferay.portal.kernel.dao.orm.SQLQuery;
020 import com.liferay.portal.kernel.dao.orm.Session;
021 import com.liferay.portal.kernel.dao.orm.Type;
022 import com.liferay.portal.kernel.exception.SystemException;
023 import com.liferay.portlet.social.model.impl.SocialActivitySetImpl;
024 import com.liferay.social.kernel.model.SocialActivitySet;
025 import com.liferay.social.kernel.service.persistence.SocialActivitySetFinder;
026 import com.liferay.util.dao.orm.CustomSQLUtil;
027
028 import java.util.Iterator;
029 import java.util.List;
030
031
034 public class SocialActivitySetFinderImpl
035 extends SocialActivitySetFinderBaseImpl implements SocialActivitySetFinder {
036
037 public static final String COUNT_BY_RELATION =
038 SocialActivitySetFinder.class.getName() + ".countByRelation";
039
040 public static final String COUNT_BY_RELATION_TYPE =
041 SocialActivitySetFinder.class.getName() + ".countByRelationType";
042
043 public static final String COUNT_BY_USER =
044 SocialActivitySetFinder.class.getName() + ".countByUser";
045
046 public static final String COUNT_BY_USER_GROUPS =
047 SocialActivitySetFinder.class.getName() + ".countByUserGroups";
048
049 public static final String FIND_BY_ORGANIZATION_ID =
050 SocialActivitySetFinder.class.getName() + ".findByOrganizationId";
051
052 public static final String FIND_BY_RELATION =
053 SocialActivitySetFinder.class.getName() + ".findByRelation";
054
055 public static final String FIND_BY_RELATION_TYPE =
056 SocialActivitySetFinder.class.getName() + ".findByRelationType";
057
058 public static final String FIND_BY_USER =
059 SocialActivitySetFinder.class.getName() + ".findByUser";
060
061 public static final String FIND_BY_USER_GROUPS =
062 SocialActivitySetFinder.class.getName() + ".findByUserGroups";
063
064 @Override
065 public int countByRelation(long userId) {
066 Session session = null;
067
068 try {
069 session = openSession();
070
071 String sql = CustomSQLUtil.get(COUNT_BY_RELATION);
072
073 SQLQuery q = session.createSynchronizedSQLQuery(sql);
074
075 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
076
077 QueryPos qPos = QueryPos.getInstance(q);
078
079 qPos.add(userId);
080
081 Iterator<Long> itr = q.iterate();
082
083 if (itr.hasNext()) {
084 Long count = itr.next();
085
086 if (count != null) {
087 return count.intValue();
088 }
089 }
090
091 return 0;
092 }
093 catch (Exception e) {
094 throw new SystemException(e);
095 }
096 finally {
097 closeSession(session);
098 }
099 }
100
101 @Override
102 public int countByRelationType(long userId, int type) {
103 Session session = null;
104
105 try {
106 session = openSession();
107
108 String sql = CustomSQLUtil.get(COUNT_BY_RELATION_TYPE);
109
110 SQLQuery q = session.createSynchronizedSQLQuery(sql);
111
112 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
113
114 QueryPos qPos = QueryPos.getInstance(q);
115
116 qPos.add(userId);
117 qPos.add(type);
118
119 Iterator<Long> itr = q.iterate();
120
121 if (itr.hasNext()) {
122 Long count = itr.next();
123
124 if (count != null) {
125 return count.intValue();
126 }
127 }
128
129 return 0;
130 }
131 catch (Exception e) {
132 throw new SystemException(e);
133 }
134 finally {
135 closeSession(session);
136 }
137 }
138
139 @Override
140 public int countByUser(long userId) {
141 Session session = null;
142
143 try {
144 session = openSession();
145
146 String sql = CustomSQLUtil.get(COUNT_BY_USER);
147
148 SQLQuery q = session.createSynchronizedSQLQuery(sql);
149
150 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
151
152 QueryPos qPos = QueryPos.getInstance(q);
153
154 qPos.add(userId);
155 qPos.add(userId);
156 qPos.add(userId);
157 qPos.add(userId);
158 qPos.add(userId);
159
160 Iterator<Long> itr = q.iterate();
161
162 if (itr.hasNext()) {
163 Long count = itr.next();
164
165 if (count != null) {
166 return count.intValue();
167 }
168 }
169
170 return 0;
171 }
172 catch (Exception e) {
173 throw new SystemException(e);
174 }
175 finally {
176 closeSession(session);
177 }
178 }
179
180 @Override
181 public int countByUserGroups(long userId) {
182 Session session = null;
183
184 try {
185 session = openSession();
186
187 String sql = CustomSQLUtil.get(COUNT_BY_USER_GROUPS);
188
189 SQLQuery q = session.createSynchronizedSQLQuery(sql);
190
191 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
192
193 QueryPos qPos = QueryPos.getInstance(q);
194
195 qPos.add(userId);
196 qPos.add(userId);
197 qPos.add(userId);
198
199 Iterator<Long> itr = q.iterate();
200
201 if (itr.hasNext()) {
202 Long count = itr.next();
203
204 if (count != null) {
205 return count.intValue();
206 }
207 }
208
209 return 0;
210 }
211 catch (Exception e) {
212 throw new SystemException(e);
213 }
214 finally {
215 closeSession(session);
216 }
217 }
218
219 @Override
220 public List<SocialActivitySet> findByOrganizationId(
221 long organizationId, int start, int end) {
222
223 Session session = null;
224
225 try {
226 session = openSession();
227
228 String sql = CustomSQLUtil.get(FIND_BY_ORGANIZATION_ID);
229
230 SQLQuery q = session.createSynchronizedSQLQuery(sql);
231
232 q.addEntity("SocialActivitySet", SocialActivitySetImpl.class);
233
234 QueryPos qPos = QueryPos.getInstance(q);
235
236 qPos.add(organizationId);
237
238 return (List<SocialActivitySet>)QueryUtil.list(
239 q, getDialect(), start, end);
240 }
241 catch (Exception e) {
242 throw new SystemException(e);
243 }
244 finally {
245 closeSession(session);
246 }
247 }
248
249 @Override
250 public List<SocialActivitySet> findByRelation(
251 long userId, int start, int end) {
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 String sql = CustomSQLUtil.get(FIND_BY_RELATION);
259
260 SQLQuery q = session.createSynchronizedSQLQuery(sql);
261
262 q.addEntity("SocialActivitySet", SocialActivitySetImpl.class);
263
264 QueryPos qPos = QueryPos.getInstance(q);
265
266 qPos.add(userId);
267
268 return (List<SocialActivitySet>)QueryUtil.list(
269 q, getDialect(), start, end);
270 }
271 catch (Exception e) {
272 throw new SystemException(e);
273 }
274 finally {
275 closeSession(session);
276 }
277 }
278
279 @Override
280 public List<SocialActivitySet> findByRelationType(
281 long userId, int type, int start, int end) {
282
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 String sql = CustomSQLUtil.get(FIND_BY_RELATION_TYPE);
289
290 SQLQuery q = session.createSynchronizedSQLQuery(sql);
291
292 q.addEntity("SocialActivitySet", SocialActivitySetImpl.class);
293
294 QueryPos qPos = QueryPos.getInstance(q);
295
296 qPos.add(userId);
297 qPos.add(type);
298
299 return (List<SocialActivitySet>)QueryUtil.list(
300 q, getDialect(), start, end);
301 }
302 catch (Exception e) {
303 throw new SystemException(e);
304 }
305 finally {
306 closeSession(session);
307 }
308 }
309
310 @Override
311 public List<SocialActivitySet> findByUser(long userId, int start, int end) {
312 Session session = null;
313
314 try {
315 session = openSession();
316
317 String sql = CustomSQLUtil.get(FIND_BY_USER);
318
319 SQLQuery q = session.createSynchronizedSQLQuery(sql);
320
321 q.addEntity("SocialActivitySet", SocialActivitySetImpl.class);
322
323 QueryPos qPos = QueryPos.getInstance(q);
324
325 qPos.add(userId);
326 qPos.add(userId);
327 qPos.add(userId);
328 qPos.add(userId);
329 qPos.add(userId);
330
331 return (List<SocialActivitySet>)QueryUtil.list(
332 q, getDialect(), start, end);
333 }
334 catch (Exception e) {
335 throw new SystemException(e);
336 }
337 finally {
338 closeSession(session);
339 }
340 }
341
342 @Override
343 public List<SocialActivitySet> findByUserGroups(
344 long userId, int start, int end) {
345
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 String sql = CustomSQLUtil.get(FIND_BY_USER_GROUPS);
352
353 SQLQuery q = session.createSynchronizedSQLQuery(sql);
354
355 q.addEntity("SocialActivitySet", SocialActivitySetImpl.class);
356
357 QueryPos qPos = QueryPos.getInstance(q);
358
359 qPos.add(userId);
360 qPos.add(userId);
361 qPos.add(userId);
362
363 return (List<SocialActivitySet>)QueryUtil.list(
364 q, getDialect(), start, end);
365 }
366 catch (Exception e) {
367 throw new SystemException(e);
368 }
369 finally {
370 closeSession(session);
371 }
372 }
373
374 }