1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.social.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.InstanceFactory;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.kernel.util.Validator;
37  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.BatchSessionUtil;
40  import com.liferay.portal.service.persistence.ResourcePersistence;
41  import com.liferay.portal.service.persistence.UserPersistence;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import com.liferay.portlet.social.NoSuchRequestException;
45  import com.liferay.portlet.social.model.SocialRequest;
46  import com.liferay.portlet.social.model.impl.SocialRequestImpl;
47  import com.liferay.portlet.social.model.impl.SocialRequestModelImpl;
48  
49  import java.io.Serializable;
50  
51  import java.util.ArrayList;
52  import java.util.Collections;
53  import java.util.List;
54  
55  /**
56   * <a href="SocialRequestPersistenceImpl.java.html"><b><i>View Source</i></b></a>
57   *
58   * <p>
59   * ServiceBuilder generated this class. Modifications in this class will be
60   * overwritten the next time is generated.
61   * </p>
62   *
63   * @author    Brian Wing Shun Chan
64   * @see       SocialRequestPersistence
65   * @see       SocialRequestUtil
66   * @generated
67   */
68  public class SocialRequestPersistenceImpl extends BasePersistenceImpl<SocialRequest>
69      implements SocialRequestPersistence {
70      public static final String FINDER_CLASS_NAME_ENTITY = SocialRequestImpl.class.getName();
71      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
72          ".List";
73      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
74              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
75              FINDER_CLASS_NAME_LIST, "findByUuid",
76              new String[] {
77                  String.class.getName(),
78                  
79              "java.lang.Integer", "java.lang.Integer",
80                  "com.liferay.portal.kernel.util.OrderByComparator"
81              });
82      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
83              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
84              FINDER_CLASS_NAME_LIST, "countByUuid",
85              new String[] { String.class.getName() });
86      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
87              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
88              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
89              new String[] { String.class.getName(), Long.class.getName() });
90      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
91              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
92              FINDER_CLASS_NAME_LIST, "countByUUID_G",
93              new String[] { String.class.getName(), Long.class.getName() });
94      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
95              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
96              FINDER_CLASS_NAME_LIST, "findByCompanyId",
97              new String[] {
98                  Long.class.getName(),
99                  
100             "java.lang.Integer", "java.lang.Integer",
101                 "com.liferay.portal.kernel.util.OrderByComparator"
102             });
103     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
104             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
105             FINDER_CLASS_NAME_LIST, "countByCompanyId",
106             new String[] { Long.class.getName() });
107     public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
108             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
109             FINDER_CLASS_NAME_LIST, "findByUserId",
110             new String[] {
111                 Long.class.getName(),
112                 
113             "java.lang.Integer", "java.lang.Integer",
114                 "com.liferay.portal.kernel.util.OrderByComparator"
115             });
116     public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
117             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
118             FINDER_CLASS_NAME_LIST, "countByUserId",
119             new String[] { Long.class.getName() });
120     public static final FinderPath FINDER_PATH_FIND_BY_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
121             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
122             FINDER_CLASS_NAME_LIST, "findByReceiverUserId",
123             new String[] {
124                 Long.class.getName(),
125                 
126             "java.lang.Integer", "java.lang.Integer",
127                 "com.liferay.portal.kernel.util.OrderByComparator"
128             });
129     public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
130             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
131             FINDER_CLASS_NAME_LIST, "countByReceiverUserId",
132             new String[] { Long.class.getName() });
133     public static final FinderPath FINDER_PATH_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
134             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
135             FINDER_CLASS_NAME_LIST, "findByU_S",
136             new String[] {
137                 Long.class.getName(), Integer.class.getName(),
138                 
139             "java.lang.Integer", "java.lang.Integer",
140                 "com.liferay.portal.kernel.util.OrderByComparator"
141             });
142     public static final FinderPath FINDER_PATH_COUNT_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
143             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
144             FINDER_CLASS_NAME_LIST, "countByU_S",
145             new String[] { Long.class.getName(), Integer.class.getName() });
146     public static final FinderPath FINDER_PATH_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
147             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
148             FINDER_CLASS_NAME_LIST, "findByR_S",
149             new String[] {
150                 Long.class.getName(), Integer.class.getName(),
151                 
152             "java.lang.Integer", "java.lang.Integer",
153                 "com.liferay.portal.kernel.util.OrderByComparator"
154             });
155     public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
156             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
157             FINDER_CLASS_NAME_LIST, "countByR_S",
158             new String[] { Long.class.getName(), Integer.class.getName() });
159     public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
160             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
161             FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C_T_R",
162             new String[] {
163                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
164                 Integer.class.getName(), Long.class.getName()
165             });
166     public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
167             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
168             FINDER_CLASS_NAME_LIST, "countByU_C_C_T_R",
169             new String[] {
170                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
171                 Integer.class.getName(), Long.class.getName()
172             });
173     public static final FinderPath FINDER_PATH_FIND_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
174             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
175             FINDER_CLASS_NAME_LIST, "findByU_C_C_T_S",
176             new String[] {
177                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
178                 Integer.class.getName(), Integer.class.getName(),
179                 
180             "java.lang.Integer", "java.lang.Integer",
181                 "com.liferay.portal.kernel.util.OrderByComparator"
182             });
183     public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
184             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
185             FINDER_CLASS_NAME_LIST, "countByU_C_C_T_S",
186             new String[] {
187                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
188                 Integer.class.getName(), Integer.class.getName()
189             });
190     public static final FinderPath FINDER_PATH_FIND_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
191             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
192             FINDER_CLASS_NAME_LIST, "findByC_C_T_R_S",
193             new String[] {
194                 Long.class.getName(), Long.class.getName(),
195                 Integer.class.getName(), Long.class.getName(),
196                 Integer.class.getName(),
197                 
198             "java.lang.Integer", "java.lang.Integer",
199                 "com.liferay.portal.kernel.util.OrderByComparator"
200             });
201     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
202             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
203             FINDER_CLASS_NAME_LIST, "countByC_C_T_R_S",
204             new String[] {
205                 Long.class.getName(), Long.class.getName(),
206                 Integer.class.getName(), Long.class.getName(),
207                 Integer.class.getName()
208             });
209     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
210             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
211             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
212     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
213             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
214             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
215 
216     public void cacheResult(SocialRequest socialRequest) {
217         EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
218             SocialRequestImpl.class, socialRequest.getPrimaryKey(),
219             socialRequest);
220 
221         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
222             new Object[] {
223                 socialRequest.getUuid(), new Long(socialRequest.getGroupId())
224             }, socialRequest);
225 
226         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
227             new Object[] {
228                 new Long(socialRequest.getUserId()),
229                 new Long(socialRequest.getClassNameId()),
230                 new Long(socialRequest.getClassPK()),
231                 new Integer(socialRequest.getType()),
232                 new Long(socialRequest.getReceiverUserId())
233             }, socialRequest);
234     }
235 
236     public void cacheResult(List<SocialRequest> socialRequests) {
237         for (SocialRequest socialRequest : socialRequests) {
238             if (EntityCacheUtil.getResult(
239                         SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
240                         SocialRequestImpl.class, socialRequest.getPrimaryKey(),
241                         this) == null) {
242                 cacheResult(socialRequest);
243             }
244         }
245     }
246 
247     public void clearCache() {
248         CacheRegistry.clear(SocialRequestImpl.class.getName());
249         EntityCacheUtil.clearCache(SocialRequestImpl.class.getName());
250         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
251         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252     }
253 
254     public void clearCache(SocialRequest socialRequest) {
255         EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
256             SocialRequestImpl.class, socialRequest.getPrimaryKey());
257 
258         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
259             new Object[] {
260                 socialRequest.getUuid(), new Long(socialRequest.getGroupId())
261             });
262 
263         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
264             new Object[] {
265                 new Long(socialRequest.getUserId()),
266                 new Long(socialRequest.getClassNameId()),
267                 new Long(socialRequest.getClassPK()),
268                 new Integer(socialRequest.getType()),
269                 new Long(socialRequest.getReceiverUserId())
270             });
271     }
272 
273     public SocialRequest create(long requestId) {
274         SocialRequest socialRequest = new SocialRequestImpl();
275 
276         socialRequest.setNew(true);
277         socialRequest.setPrimaryKey(requestId);
278 
279         String uuid = PortalUUIDUtil.generate();
280 
281         socialRequest.setUuid(uuid);
282 
283         return socialRequest;
284     }
285 
286     public SocialRequest remove(Serializable primaryKey)
287         throws NoSuchModelException, SystemException {
288         return remove(((Long)primaryKey).longValue());
289     }
290 
291     public SocialRequest remove(long requestId)
292         throws NoSuchRequestException, SystemException {
293         Session session = null;
294 
295         try {
296             session = openSession();
297 
298             SocialRequest socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
299                     new Long(requestId));
300 
301             if (socialRequest == null) {
302                 if (_log.isWarnEnabled()) {
303                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + requestId);
304                 }
305 
306                 throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
307                     requestId);
308             }
309 
310             return remove(socialRequest);
311         }
312         catch (NoSuchRequestException nsee) {
313             throw nsee;
314         }
315         catch (Exception e) {
316             throw processException(e);
317         }
318         finally {
319             closeSession(session);
320         }
321     }
322 
323     protected SocialRequest removeImpl(SocialRequest socialRequest)
324         throws SystemException {
325         socialRequest = toUnwrappedModel(socialRequest);
326 
327         Session session = null;
328 
329         try {
330             session = openSession();
331 
332             BatchSessionUtil.delete(session, socialRequest);
333         }
334         catch (Exception e) {
335             throw processException(e);
336         }
337         finally {
338             closeSession(session);
339         }
340 
341         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
342 
343         SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
344 
345         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
346             new Object[] {
347                 socialRequestModelImpl.getOriginalUuid(),
348                 new Long(socialRequestModelImpl.getOriginalGroupId())
349             });
350 
351         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
352             new Object[] {
353                 new Long(socialRequestModelImpl.getOriginalUserId()),
354                 new Long(socialRequestModelImpl.getOriginalClassNameId()),
355                 new Long(socialRequestModelImpl.getOriginalClassPK()),
356                 new Integer(socialRequestModelImpl.getOriginalType()),
357                 new Long(socialRequestModelImpl.getOriginalReceiverUserId())
358             });
359 
360         EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
361             SocialRequestImpl.class, socialRequest.getPrimaryKey());
362 
363         return socialRequest;
364     }
365 
366     /**
367      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
368      */
369     public SocialRequest update(SocialRequest socialRequest)
370         throws SystemException {
371         if (_log.isWarnEnabled()) {
372             _log.warn(
373                 "Using the deprecated update(SocialRequest socialRequest) method. Use update(SocialRequest socialRequest, boolean merge) instead.");
374         }
375 
376         return update(socialRequest, false);
377     }
378 
379     public SocialRequest updateImpl(
380         com.liferay.portlet.social.model.SocialRequest socialRequest,
381         boolean merge) throws SystemException {
382         socialRequest = toUnwrappedModel(socialRequest);
383 
384         boolean isNew = socialRequest.isNew();
385 
386         SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
387 
388         if (Validator.isNull(socialRequest.getUuid())) {
389             String uuid = PortalUUIDUtil.generate();
390 
391             socialRequest.setUuid(uuid);
392         }
393 
394         Session session = null;
395 
396         try {
397             session = openSession();
398 
399             BatchSessionUtil.update(session, socialRequest, merge);
400 
401             socialRequest.setNew(false);
402         }
403         catch (Exception e) {
404             throw processException(e);
405         }
406         finally {
407             closeSession(session);
408         }
409 
410         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
411 
412         EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
413             SocialRequestImpl.class, socialRequest.getPrimaryKey(),
414             socialRequest);
415 
416         if (!isNew &&
417                 (!Validator.equals(socialRequest.getUuid(),
418                     socialRequestModelImpl.getOriginalUuid()) ||
419                 (socialRequest.getGroupId() != socialRequestModelImpl.getOriginalGroupId()))) {
420             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
421                 new Object[] {
422                     socialRequestModelImpl.getOriginalUuid(),
423                     new Long(socialRequestModelImpl.getOriginalGroupId())
424                 });
425         }
426 
427         if (isNew ||
428                 (!Validator.equals(socialRequest.getUuid(),
429                     socialRequestModelImpl.getOriginalUuid()) ||
430                 (socialRequest.getGroupId() != socialRequestModelImpl.getOriginalGroupId()))) {
431             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
432                 new Object[] {
433                     socialRequest.getUuid(),
434                     new Long(socialRequest.getGroupId())
435                 }, socialRequest);
436         }
437 
438         if (!isNew &&
439                 ((socialRequest.getUserId() != socialRequestModelImpl.getOriginalUserId()) ||
440                 (socialRequest.getClassNameId() != socialRequestModelImpl.getOriginalClassNameId()) ||
441                 (socialRequest.getClassPK() != socialRequestModelImpl.getOriginalClassPK()) ||
442                 (socialRequest.getType() != socialRequestModelImpl.getOriginalType()) ||
443                 (socialRequest.getReceiverUserId() != socialRequestModelImpl.getOriginalReceiverUserId()))) {
444             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
445                 new Object[] {
446                     new Long(socialRequestModelImpl.getOriginalUserId()),
447                     new Long(socialRequestModelImpl.getOriginalClassNameId()),
448                     new Long(socialRequestModelImpl.getOriginalClassPK()),
449                     new Integer(socialRequestModelImpl.getOriginalType()),
450                     new Long(socialRequestModelImpl.getOriginalReceiverUserId())
451                 });
452         }
453 
454         if (isNew ||
455                 ((socialRequest.getUserId() != socialRequestModelImpl.getOriginalUserId()) ||
456                 (socialRequest.getClassNameId() != socialRequestModelImpl.getOriginalClassNameId()) ||
457                 (socialRequest.getClassPK() != socialRequestModelImpl.getOriginalClassPK()) ||
458                 (socialRequest.getType() != socialRequestModelImpl.getOriginalType()) ||
459                 (socialRequest.getReceiverUserId() != socialRequestModelImpl.getOriginalReceiverUserId()))) {
460             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
461                 new Object[] {
462                     new Long(socialRequest.getUserId()),
463                     new Long(socialRequest.getClassNameId()),
464                     new Long(socialRequest.getClassPK()),
465                     new Integer(socialRequest.getType()),
466                     new Long(socialRequest.getReceiverUserId())
467                 }, socialRequest);
468         }
469 
470         return socialRequest;
471     }
472 
473     protected SocialRequest toUnwrappedModel(SocialRequest socialRequest) {
474         if (socialRequest instanceof SocialRequestImpl) {
475             return socialRequest;
476         }
477 
478         SocialRequestImpl socialRequestImpl = new SocialRequestImpl();
479 
480         socialRequestImpl.setNew(socialRequest.isNew());
481         socialRequestImpl.setPrimaryKey(socialRequest.getPrimaryKey());
482 
483         socialRequestImpl.setUuid(socialRequest.getUuid());
484         socialRequestImpl.setRequestId(socialRequest.getRequestId());
485         socialRequestImpl.setGroupId(socialRequest.getGroupId());
486         socialRequestImpl.setCompanyId(socialRequest.getCompanyId());
487         socialRequestImpl.setUserId(socialRequest.getUserId());
488         socialRequestImpl.setCreateDate(socialRequest.getCreateDate());
489         socialRequestImpl.setModifiedDate(socialRequest.getModifiedDate());
490         socialRequestImpl.setClassNameId(socialRequest.getClassNameId());
491         socialRequestImpl.setClassPK(socialRequest.getClassPK());
492         socialRequestImpl.setType(socialRequest.getType());
493         socialRequestImpl.setExtraData(socialRequest.getExtraData());
494         socialRequestImpl.setReceiverUserId(socialRequest.getReceiverUserId());
495         socialRequestImpl.setStatus(socialRequest.getStatus());
496 
497         return socialRequestImpl;
498     }
499 
500     public SocialRequest findByPrimaryKey(Serializable primaryKey)
501         throws NoSuchModelException, SystemException {
502         return findByPrimaryKey(((Long)primaryKey).longValue());
503     }
504 
505     public SocialRequest findByPrimaryKey(long requestId)
506         throws NoSuchRequestException, SystemException {
507         SocialRequest socialRequest = fetchByPrimaryKey(requestId);
508 
509         if (socialRequest == null) {
510             if (_log.isWarnEnabled()) {
511                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + requestId);
512             }
513 
514             throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
515                 requestId);
516         }
517 
518         return socialRequest;
519     }
520 
521     public SocialRequest fetchByPrimaryKey(Serializable primaryKey)
522         throws SystemException {
523         return fetchByPrimaryKey(((Long)primaryKey).longValue());
524     }
525 
526     public SocialRequest fetchByPrimaryKey(long requestId)
527         throws SystemException {
528         SocialRequest socialRequest = (SocialRequest)EntityCacheUtil.getResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
529                 SocialRequestImpl.class, requestId, this);
530 
531         if (socialRequest == null) {
532             Session session = null;
533 
534             try {
535                 session = openSession();
536 
537                 socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
538                         new Long(requestId));
539             }
540             catch (Exception e) {
541                 throw processException(e);
542             }
543             finally {
544                 if (socialRequest != null) {
545                     cacheResult(socialRequest);
546                 }
547 
548                 closeSession(session);
549             }
550         }
551 
552         return socialRequest;
553     }
554 
555     public List<SocialRequest> findByUuid(String uuid)
556         throws SystemException {
557         return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
558     }
559 
560     public List<SocialRequest> findByUuid(String uuid, int start, int end)
561         throws SystemException {
562         return findByUuid(uuid, start, end, null);
563     }
564 
565     public List<SocialRequest> findByUuid(String uuid, int start, int end,
566         OrderByComparator orderByComparator) throws SystemException {
567         Object[] finderArgs = new Object[] {
568                 uuid,
569                 
570                 String.valueOf(start), String.valueOf(end),
571                 String.valueOf(orderByComparator)
572             };
573 
574         List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
575                 finderArgs, this);
576 
577         if (list == null) {
578             StringBundler query = null;
579 
580             if (orderByComparator != null) {
581                 query = new StringBundler(3 +
582                         (orderByComparator.getOrderByFields().length * 3));
583             }
584             else {
585                 query = new StringBundler(3);
586             }
587 
588             query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
589 
590             if (uuid == null) {
591                 query.append(_FINDER_COLUMN_UUID_UUID_1);
592             }
593             else {
594                 if (uuid.equals(StringPool.BLANK)) {
595                     query.append(_FINDER_COLUMN_UUID_UUID_3);
596                 }
597                 else {
598                     query.append(_FINDER_COLUMN_UUID_UUID_2);
599                 }
600             }
601 
602             if (orderByComparator != null) {
603                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
604                     orderByComparator);
605             }
606 
607             else {
608                 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
609             }
610 
611             String sql = query.toString();
612 
613             Session session = null;
614 
615             try {
616                 session = openSession();
617 
618                 Query q = session.createQuery(sql);
619 
620                 QueryPos qPos = QueryPos.getInstance(q);
621 
622                 if (uuid != null) {
623                     qPos.add(uuid);
624                 }
625 
626                 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
627                         start, end);
628             }
629             catch (Exception e) {
630                 throw processException(e);
631             }
632             finally {
633                 if (list == null) {
634                     list = new ArrayList<SocialRequest>();
635                 }
636 
637                 cacheResult(list);
638 
639                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
640                     list);
641 
642                 closeSession(session);
643             }
644         }
645 
646         return list;
647     }
648 
649     public SocialRequest findByUuid_First(String uuid,
650         OrderByComparator orderByComparator)
651         throws NoSuchRequestException, SystemException {
652         List<SocialRequest> list = findByUuid(uuid, 0, 1, orderByComparator);
653 
654         if (list.isEmpty()) {
655             StringBundler msg = new StringBundler(4);
656 
657             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
658 
659             msg.append("uuid=");
660             msg.append(uuid);
661 
662             msg.append(StringPool.CLOSE_CURLY_BRACE);
663 
664             throw new NoSuchRequestException(msg.toString());
665         }
666         else {
667             return list.get(0);
668         }
669     }
670 
671     public SocialRequest findByUuid_Last(String uuid,
672         OrderByComparator orderByComparator)
673         throws NoSuchRequestException, SystemException {
674         int count = countByUuid(uuid);
675 
676         List<SocialRequest> list = findByUuid(uuid, count - 1, count,
677                 orderByComparator);
678 
679         if (list.isEmpty()) {
680             StringBundler msg = new StringBundler(4);
681 
682             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
683 
684             msg.append("uuid=");
685             msg.append(uuid);
686 
687             msg.append(StringPool.CLOSE_CURLY_BRACE);
688 
689             throw new NoSuchRequestException(msg.toString());
690         }
691         else {
692             return list.get(0);
693         }
694     }
695 
696     public SocialRequest[] findByUuid_PrevAndNext(long requestId, String uuid,
697         OrderByComparator orderByComparator)
698         throws NoSuchRequestException, SystemException {
699         SocialRequest socialRequest = findByPrimaryKey(requestId);
700 
701         Session session = null;
702 
703         try {
704             session = openSession();
705 
706             SocialRequest[] array = new SocialRequestImpl[3];
707 
708             array[0] = getByUuid_PrevAndNext(session, socialRequest, uuid,
709                     orderByComparator, true);
710 
711             array[1] = socialRequest;
712 
713             array[2] = getByUuid_PrevAndNext(session, socialRequest, uuid,
714                     orderByComparator, false);
715 
716             return array;
717         }
718         catch (Exception e) {
719             throw processException(e);
720         }
721         finally {
722             closeSession(session);
723         }
724     }
725 
726     protected SocialRequest getByUuid_PrevAndNext(Session session,
727         SocialRequest socialRequest, String uuid,
728         OrderByComparator orderByComparator, boolean previous) {
729         StringBundler query = null;
730 
731         if (orderByComparator != null) {
732             query = new StringBundler(6 +
733                     (orderByComparator.getOrderByFields().length * 6));
734         }
735         else {
736             query = new StringBundler(3);
737         }
738 
739         query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
740 
741         if (uuid == null) {
742             query.append(_FINDER_COLUMN_UUID_UUID_1);
743         }
744         else {
745             if (uuid.equals(StringPool.BLANK)) {
746                 query.append(_FINDER_COLUMN_UUID_UUID_3);
747             }
748             else {
749                 query.append(_FINDER_COLUMN_UUID_UUID_2);
750             }
751         }
752 
753         if (orderByComparator != null) {
754             String[] orderByFields = orderByComparator.getOrderByFields();
755 
756             if (orderByFields.length > 0) {
757                 query.append(WHERE_AND);
758             }
759 
760             for (int i = 0; i < orderByFields.length; i++) {
761                 query.append(_ORDER_BY_ENTITY_ALIAS);
762                 query.append(orderByFields[i]);
763 
764                 if ((i + 1) < orderByFields.length) {
765                     if (orderByComparator.isAscending() ^ previous) {
766                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
767                     }
768                     else {
769                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
770                     }
771                 }
772                 else {
773                     if (orderByComparator.isAscending() ^ previous) {
774                         query.append(WHERE_GREATER_THAN);
775                     }
776                     else {
777                         query.append(WHERE_LESSER_THAN);
778                     }
779                 }
780             }
781 
782             query.append(ORDER_BY_CLAUSE);
783 
784             for (int i = 0; i < orderByFields.length; i++) {
785                 query.append(_ORDER_BY_ENTITY_ALIAS);
786                 query.append(orderByFields[i]);
787 
788                 if ((i + 1) < orderByFields.length) {
789                     if (orderByComparator.isAscending() ^ previous) {
790                         query.append(ORDER_BY_ASC_HAS_NEXT);
791                     }
792                     else {
793                         query.append(ORDER_BY_DESC_HAS_NEXT);
794                     }
795                 }
796                 else {
797                     if (orderByComparator.isAscending() ^ previous) {
798                         query.append(ORDER_BY_ASC);
799                     }
800                     else {
801                         query.append(ORDER_BY_DESC);
802                     }
803                 }
804             }
805         }
806 
807         else {
808             query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
809         }
810 
811         String sql = query.toString();
812 
813         Query q = session.createQuery(sql);
814 
815         q.setFirstResult(0);
816         q.setMaxResults(2);
817 
818         QueryPos qPos = QueryPos.getInstance(q);
819 
820         if (uuid != null) {
821             qPos.add(uuid);
822         }
823 
824         if (orderByComparator != null) {
825             Object[] values = orderByComparator.getOrderByValues(socialRequest);
826 
827             for (Object value : values) {
828                 qPos.add(value);
829             }
830         }
831 
832         List<SocialRequest> list = q.list();
833 
834         if (list.size() == 2) {
835             return list.get(1);
836         }
837         else {
838             return null;
839         }
840     }
841 
842     public SocialRequest findByUUID_G(String uuid, long groupId)
843         throws NoSuchRequestException, SystemException {
844         SocialRequest socialRequest = fetchByUUID_G(uuid, groupId);
845 
846         if (socialRequest == null) {
847             StringBundler msg = new StringBundler(6);
848 
849             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
850 
851             msg.append("uuid=");
852             msg.append(uuid);
853 
854             msg.append(", groupId=");
855             msg.append(groupId);
856 
857             msg.append(StringPool.CLOSE_CURLY_BRACE);
858 
859             if (_log.isWarnEnabled()) {
860                 _log.warn(msg.toString());
861             }
862 
863             throw new NoSuchRequestException(msg.toString());
864         }
865 
866         return socialRequest;
867     }
868 
869     public SocialRequest fetchByUUID_G(String uuid, long groupId)
870         throws SystemException {
871         return fetchByUUID_G(uuid, groupId, true);
872     }
873 
874     public SocialRequest fetchByUUID_G(String uuid, long groupId,
875         boolean retrieveFromCache) throws SystemException {
876         Object[] finderArgs = new Object[] { uuid, groupId };
877 
878         Object result = null;
879 
880         if (retrieveFromCache) {
881             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
882                     finderArgs, this);
883         }
884 
885         if (result == null) {
886             StringBundler query = new StringBundler(4);
887 
888             query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
889 
890             if (uuid == null) {
891                 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
892             }
893             else {
894                 if (uuid.equals(StringPool.BLANK)) {
895                     query.append(_FINDER_COLUMN_UUID_G_UUID_3);
896                 }
897                 else {
898                     query.append(_FINDER_COLUMN_UUID_G_UUID_2);
899                 }
900             }
901 
902             query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
903 
904             query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
905 
906             String sql = query.toString();
907 
908             Session session = null;
909 
910             try {
911                 session = openSession();
912 
913                 Query q = session.createQuery(sql);
914 
915                 QueryPos qPos = QueryPos.getInstance(q);
916 
917                 if (uuid != null) {
918                     qPos.add(uuid);
919                 }
920 
921                 qPos.add(groupId);
922 
923                 List<SocialRequest> list = q.list();
924 
925                 result = list;
926 
927                 SocialRequest socialRequest = null;
928 
929                 if (list.isEmpty()) {
930                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
931                         finderArgs, list);
932                 }
933                 else {
934                     socialRequest = list.get(0);
935 
936                     cacheResult(socialRequest);
937 
938                     if ((socialRequest.getUuid() == null) ||
939                             !socialRequest.getUuid().equals(uuid) ||
940                             (socialRequest.getGroupId() != groupId)) {
941                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
942                             finderArgs, socialRequest);
943                     }
944                 }
945 
946                 return socialRequest;
947             }
948             catch (Exception e) {
949                 throw processException(e);
950             }
951             finally {
952                 if (result == null) {
953                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
954                         finderArgs, new ArrayList<SocialRequest>());
955                 }
956 
957                 closeSession(session);
958             }
959         }
960         else {
961             if (result instanceof List<?>) {
962                 return null;
963             }
964             else {
965                 return (SocialRequest)result;
966             }
967         }
968     }
969 
970     public List<SocialRequest> findByCompanyId(long companyId)
971         throws SystemException {
972         return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
973             null);
974     }
975 
976     public List<SocialRequest> findByCompanyId(long companyId, int start,
977         int end) throws SystemException {
978         return findByCompanyId(companyId, start, end, null);
979     }
980 
981     public List<SocialRequest> findByCompanyId(long companyId, int start,
982         int end, OrderByComparator orderByComparator) throws SystemException {
983         Object[] finderArgs = new Object[] {
984                 companyId,
985                 
986                 String.valueOf(start), String.valueOf(end),
987                 String.valueOf(orderByComparator)
988             };
989 
990         List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
991                 finderArgs, this);
992 
993         if (list == null) {
994             StringBundler query = null;
995 
996             if (orderByComparator != null) {
997                 query = new StringBundler(3 +
998                         (orderByComparator.getOrderByFields().length * 3));
999             }
1000            else {
1001                query = new StringBundler(3);
1002            }
1003
1004            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1005
1006            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1007
1008            if (orderByComparator != null) {
1009                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1010                    orderByComparator);
1011            }
1012
1013            else {
1014                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1015            }
1016
1017            String sql = query.toString();
1018
1019            Session session = null;
1020
1021            try {
1022                session = openSession();
1023
1024                Query q = session.createQuery(sql);
1025
1026                QueryPos qPos = QueryPos.getInstance(q);
1027
1028                qPos.add(companyId);
1029
1030                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1031                        start, end);
1032            }
1033            catch (Exception e) {
1034                throw processException(e);
1035            }
1036            finally {
1037                if (list == null) {
1038                    list = new ArrayList<SocialRequest>();
1039                }
1040
1041                cacheResult(list);
1042
1043                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1044                    finderArgs, list);
1045
1046                closeSession(session);
1047            }
1048        }
1049
1050        return list;
1051    }
1052
1053    public SocialRequest findByCompanyId_First(long companyId,
1054        OrderByComparator orderByComparator)
1055        throws NoSuchRequestException, SystemException {
1056        List<SocialRequest> list = findByCompanyId(companyId, 0, 1,
1057                orderByComparator);
1058
1059        if (list.isEmpty()) {
1060            StringBundler msg = new StringBundler(4);
1061
1062            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1063
1064            msg.append("companyId=");
1065            msg.append(companyId);
1066
1067            msg.append(StringPool.CLOSE_CURLY_BRACE);
1068
1069            throw new NoSuchRequestException(msg.toString());
1070        }
1071        else {
1072            return list.get(0);
1073        }
1074    }
1075
1076    public SocialRequest findByCompanyId_Last(long companyId,
1077        OrderByComparator orderByComparator)
1078        throws NoSuchRequestException, SystemException {
1079        int count = countByCompanyId(companyId);
1080
1081        List<SocialRequest> list = findByCompanyId(companyId, count - 1, count,
1082                orderByComparator);
1083
1084        if (list.isEmpty()) {
1085            StringBundler msg = new StringBundler(4);
1086
1087            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1088
1089            msg.append("companyId=");
1090            msg.append(companyId);
1091
1092            msg.append(StringPool.CLOSE_CURLY_BRACE);
1093
1094            throw new NoSuchRequestException(msg.toString());
1095        }
1096        else {
1097            return list.get(0);
1098        }
1099    }
1100
1101    public SocialRequest[] findByCompanyId_PrevAndNext(long requestId,
1102        long companyId, OrderByComparator orderByComparator)
1103        throws NoSuchRequestException, SystemException {
1104        SocialRequest socialRequest = findByPrimaryKey(requestId);
1105
1106        Session session = null;
1107
1108        try {
1109            session = openSession();
1110
1111            SocialRequest[] array = new SocialRequestImpl[3];
1112
1113            array[0] = getByCompanyId_PrevAndNext(session, socialRequest,
1114                    companyId, orderByComparator, true);
1115
1116            array[1] = socialRequest;
1117
1118            array[2] = getByCompanyId_PrevAndNext(session, socialRequest,
1119                    companyId, orderByComparator, false);
1120
1121            return array;
1122        }
1123        catch (Exception e) {
1124            throw processException(e);
1125        }
1126        finally {
1127            closeSession(session);
1128        }
1129    }
1130
1131    protected SocialRequest getByCompanyId_PrevAndNext(Session session,
1132        SocialRequest socialRequest, long companyId,
1133        OrderByComparator orderByComparator, boolean previous) {
1134        StringBundler query = null;
1135
1136        if (orderByComparator != null) {
1137            query = new StringBundler(6 +
1138                    (orderByComparator.getOrderByFields().length * 6));
1139        }
1140        else {
1141            query = new StringBundler(3);
1142        }
1143
1144        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1145
1146        query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1147
1148        if (orderByComparator != null) {
1149            String[] orderByFields = orderByComparator.getOrderByFields();
1150
1151            if (orderByFields.length > 0) {
1152                query.append(WHERE_AND);
1153            }
1154
1155            for (int i = 0; i < orderByFields.length; i++) {
1156                query.append(_ORDER_BY_ENTITY_ALIAS);
1157                query.append(orderByFields[i]);
1158
1159                if ((i + 1) < orderByFields.length) {
1160                    if (orderByComparator.isAscending() ^ previous) {
1161                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1162                    }
1163                    else {
1164                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1165                    }
1166                }
1167                else {
1168                    if (orderByComparator.isAscending() ^ previous) {
1169                        query.append(WHERE_GREATER_THAN);
1170                    }
1171                    else {
1172                        query.append(WHERE_LESSER_THAN);
1173                    }
1174                }
1175            }
1176
1177            query.append(ORDER_BY_CLAUSE);
1178
1179            for (int i = 0; i < orderByFields.length; i++) {
1180                query.append(_ORDER_BY_ENTITY_ALIAS);
1181                query.append(orderByFields[i]);
1182
1183                if ((i + 1) < orderByFields.length) {
1184                    if (orderByComparator.isAscending() ^ previous) {
1185                        query.append(ORDER_BY_ASC_HAS_NEXT);
1186                    }
1187                    else {
1188                        query.append(ORDER_BY_DESC_HAS_NEXT);
1189                    }
1190                }
1191                else {
1192                    if (orderByComparator.isAscending() ^ previous) {
1193                        query.append(ORDER_BY_ASC);
1194                    }
1195                    else {
1196                        query.append(ORDER_BY_DESC);
1197                    }
1198                }
1199            }
1200        }
1201
1202        else {
1203            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1204        }
1205
1206        String sql = query.toString();
1207
1208        Query q = session.createQuery(sql);
1209
1210        q.setFirstResult(0);
1211        q.setMaxResults(2);
1212
1213        QueryPos qPos = QueryPos.getInstance(q);
1214
1215        qPos.add(companyId);
1216
1217        if (orderByComparator != null) {
1218            Object[] values = orderByComparator.getOrderByValues(socialRequest);
1219
1220            for (Object value : values) {
1221                qPos.add(value);
1222            }
1223        }
1224
1225        List<SocialRequest> list = q.list();
1226
1227        if (list.size() == 2) {
1228            return list.get(1);
1229        }
1230        else {
1231            return null;
1232        }
1233    }
1234
1235    public List<SocialRequest> findByUserId(long userId)
1236        throws SystemException {
1237        return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1238    }
1239
1240    public List<SocialRequest> findByUserId(long userId, int start, int end)
1241        throws SystemException {
1242        return findByUserId(userId, start, end, null);
1243    }
1244
1245    public List<SocialRequest> findByUserId(long userId, int start, int end,
1246        OrderByComparator orderByComparator) throws SystemException {
1247        Object[] finderArgs = new Object[] {
1248                userId,
1249                
1250                String.valueOf(start), String.valueOf(end),
1251                String.valueOf(orderByComparator)
1252            };
1253
1254        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
1255                finderArgs, this);
1256
1257        if (list == null) {
1258            StringBundler query = null;
1259
1260            if (orderByComparator != null) {
1261                query = new StringBundler(3 +
1262                        (orderByComparator.getOrderByFields().length * 3));
1263            }
1264            else {
1265                query = new StringBundler(3);
1266            }
1267
1268            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1269
1270            query.append(_FINDER_COLUMN_USERID_USERID_2);
1271
1272            if (orderByComparator != null) {
1273                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1274                    orderByComparator);
1275            }
1276
1277            else {
1278                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1279            }
1280
1281            String sql = query.toString();
1282
1283            Session session = null;
1284
1285            try {
1286                session = openSession();
1287
1288                Query q = session.createQuery(sql);
1289
1290                QueryPos qPos = QueryPos.getInstance(q);
1291
1292                qPos.add(userId);
1293
1294                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1295                        start, end);
1296            }
1297            catch (Exception e) {
1298                throw processException(e);
1299            }
1300            finally {
1301                if (list == null) {
1302                    list = new ArrayList<SocialRequest>();
1303                }
1304
1305                cacheResult(list);
1306
1307                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
1308                    finderArgs, list);
1309
1310                closeSession(session);
1311            }
1312        }
1313
1314        return list;
1315    }
1316
1317    public SocialRequest findByUserId_First(long userId,
1318        OrderByComparator orderByComparator)
1319        throws NoSuchRequestException, SystemException {
1320        List<SocialRequest> list = findByUserId(userId, 0, 1, orderByComparator);
1321
1322        if (list.isEmpty()) {
1323            StringBundler msg = new StringBundler(4);
1324
1325            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1326
1327            msg.append("userId=");
1328            msg.append(userId);
1329
1330            msg.append(StringPool.CLOSE_CURLY_BRACE);
1331
1332            throw new NoSuchRequestException(msg.toString());
1333        }
1334        else {
1335            return list.get(0);
1336        }
1337    }
1338
1339    public SocialRequest findByUserId_Last(long userId,
1340        OrderByComparator orderByComparator)
1341        throws NoSuchRequestException, SystemException {
1342        int count = countByUserId(userId);
1343
1344        List<SocialRequest> list = findByUserId(userId, count - 1, count,
1345                orderByComparator);
1346
1347        if (list.isEmpty()) {
1348            StringBundler msg = new StringBundler(4);
1349
1350            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351
1352            msg.append("userId=");
1353            msg.append(userId);
1354
1355            msg.append(StringPool.CLOSE_CURLY_BRACE);
1356
1357            throw new NoSuchRequestException(msg.toString());
1358        }
1359        else {
1360            return list.get(0);
1361        }
1362    }
1363
1364    public SocialRequest[] findByUserId_PrevAndNext(long requestId,
1365        long userId, OrderByComparator orderByComparator)
1366        throws NoSuchRequestException, SystemException {
1367        SocialRequest socialRequest = findByPrimaryKey(requestId);
1368
1369        Session session = null;
1370
1371        try {
1372            session = openSession();
1373
1374            SocialRequest[] array = new SocialRequestImpl[3];
1375
1376            array[0] = getByUserId_PrevAndNext(session, socialRequest, userId,
1377                    orderByComparator, true);
1378
1379            array[1] = socialRequest;
1380
1381            array[2] = getByUserId_PrevAndNext(session, socialRequest, userId,
1382                    orderByComparator, false);
1383
1384            return array;
1385        }
1386        catch (Exception e) {
1387            throw processException(e);
1388        }
1389        finally {
1390            closeSession(session);
1391        }
1392    }
1393
1394    protected SocialRequest getByUserId_PrevAndNext(Session session,
1395        SocialRequest socialRequest, long userId,
1396        OrderByComparator orderByComparator, boolean previous) {
1397        StringBundler query = null;
1398
1399        if (orderByComparator != null) {
1400            query = new StringBundler(6 +
1401                    (orderByComparator.getOrderByFields().length * 6));
1402        }
1403        else {
1404            query = new StringBundler(3);
1405        }
1406
1407        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1408
1409        query.append(_FINDER_COLUMN_USERID_USERID_2);
1410
1411        if (orderByComparator != null) {
1412            String[] orderByFields = orderByComparator.getOrderByFields();
1413
1414            if (orderByFields.length > 0) {
1415                query.append(WHERE_AND);
1416            }
1417
1418            for (int i = 0; i < orderByFields.length; i++) {
1419                query.append(_ORDER_BY_ENTITY_ALIAS);
1420                query.append(orderByFields[i]);
1421
1422                if ((i + 1) < orderByFields.length) {
1423                    if (orderByComparator.isAscending() ^ previous) {
1424                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1425                    }
1426                    else {
1427                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1428                    }
1429                }
1430                else {
1431                    if (orderByComparator.isAscending() ^ previous) {
1432                        query.append(WHERE_GREATER_THAN);
1433                    }
1434                    else {
1435                        query.append(WHERE_LESSER_THAN);
1436                    }
1437                }
1438            }
1439
1440            query.append(ORDER_BY_CLAUSE);
1441
1442            for (int i = 0; i < orderByFields.length; i++) {
1443                query.append(_ORDER_BY_ENTITY_ALIAS);
1444                query.append(orderByFields[i]);
1445
1446                if ((i + 1) < orderByFields.length) {
1447                    if (orderByComparator.isAscending() ^ previous) {
1448                        query.append(ORDER_BY_ASC_HAS_NEXT);
1449                    }
1450                    else {
1451                        query.append(ORDER_BY_DESC_HAS_NEXT);
1452                    }
1453                }
1454                else {
1455                    if (orderByComparator.isAscending() ^ previous) {
1456                        query.append(ORDER_BY_ASC);
1457                    }
1458                    else {
1459                        query.append(ORDER_BY_DESC);
1460                    }
1461                }
1462            }
1463        }
1464
1465        else {
1466            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1467        }
1468
1469        String sql = query.toString();
1470
1471        Query q = session.createQuery(sql);
1472
1473        q.setFirstResult(0);
1474        q.setMaxResults(2);
1475
1476        QueryPos qPos = QueryPos.getInstance(q);
1477
1478        qPos.add(userId);
1479
1480        if (orderByComparator != null) {
1481            Object[] values = orderByComparator.getOrderByValues(socialRequest);
1482
1483            for (Object value : values) {
1484                qPos.add(value);
1485            }
1486        }
1487
1488        List<SocialRequest> list = q.list();
1489
1490        if (list.size() == 2) {
1491            return list.get(1);
1492        }
1493        else {
1494            return null;
1495        }
1496    }
1497
1498    public List<SocialRequest> findByReceiverUserId(long receiverUserId)
1499        throws SystemException {
1500        return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
1501            QueryUtil.ALL_POS, null);
1502    }
1503
1504    public List<SocialRequest> findByReceiverUserId(long receiverUserId,
1505        int start, int end) throws SystemException {
1506        return findByReceiverUserId(receiverUserId, start, end, null);
1507    }
1508
1509    public List<SocialRequest> findByReceiverUserId(long receiverUserId,
1510        int start, int end, OrderByComparator orderByComparator)
1511        throws SystemException {
1512        Object[] finderArgs = new Object[] {
1513                receiverUserId,
1514                
1515                String.valueOf(start), String.valueOf(end),
1516                String.valueOf(orderByComparator)
1517            };
1518
1519        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RECEIVERUSERID,
1520                finderArgs, this);
1521
1522        if (list == null) {
1523            StringBundler query = null;
1524
1525            if (orderByComparator != null) {
1526                query = new StringBundler(3 +
1527                        (orderByComparator.getOrderByFields().length * 3));
1528            }
1529            else {
1530                query = new StringBundler(3);
1531            }
1532
1533            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1534
1535            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
1536
1537            if (orderByComparator != null) {
1538                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1539                    orderByComparator);
1540            }
1541
1542            else {
1543                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1544            }
1545
1546            String sql = query.toString();
1547
1548            Session session = null;
1549
1550            try {
1551                session = openSession();
1552
1553                Query q = session.createQuery(sql);
1554
1555                QueryPos qPos = QueryPos.getInstance(q);
1556
1557                qPos.add(receiverUserId);
1558
1559                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1560                        start, end);
1561            }
1562            catch (Exception e) {
1563                throw processException(e);
1564            }
1565            finally {
1566                if (list == null) {
1567                    list = new ArrayList<SocialRequest>();
1568                }
1569
1570                cacheResult(list);
1571
1572                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RECEIVERUSERID,
1573                    finderArgs, list);
1574
1575                closeSession(session);
1576            }
1577        }
1578
1579        return list;
1580    }
1581
1582    public SocialRequest findByReceiverUserId_First(long receiverUserId,
1583        OrderByComparator orderByComparator)
1584        throws NoSuchRequestException, SystemException {
1585        List<SocialRequest> list = findByReceiverUserId(receiverUserId, 0, 1,
1586                orderByComparator);
1587
1588        if (list.isEmpty()) {
1589            StringBundler msg = new StringBundler(4);
1590
1591            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1592
1593            msg.append("receiverUserId=");
1594            msg.append(receiverUserId);
1595
1596            msg.append(StringPool.CLOSE_CURLY_BRACE);
1597
1598            throw new NoSuchRequestException(msg.toString());
1599        }
1600        else {
1601            return list.get(0);
1602        }
1603    }
1604
1605    public SocialRequest findByReceiverUserId_Last(long receiverUserId,
1606        OrderByComparator orderByComparator)
1607        throws NoSuchRequestException, SystemException {
1608        int count = countByReceiverUserId(receiverUserId);
1609
1610        List<SocialRequest> list = findByReceiverUserId(receiverUserId,
1611                count - 1, count, orderByComparator);
1612
1613        if (list.isEmpty()) {
1614            StringBundler msg = new StringBundler(4);
1615
1616            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1617
1618            msg.append("receiverUserId=");
1619            msg.append(receiverUserId);
1620
1621            msg.append(StringPool.CLOSE_CURLY_BRACE);
1622
1623            throw new NoSuchRequestException(msg.toString());
1624        }
1625        else {
1626            return list.get(0);
1627        }
1628    }
1629
1630    public SocialRequest[] findByReceiverUserId_PrevAndNext(long requestId,
1631        long receiverUserId, OrderByComparator orderByComparator)
1632        throws NoSuchRequestException, SystemException {
1633        SocialRequest socialRequest = findByPrimaryKey(requestId);
1634
1635        Session session = null;
1636
1637        try {
1638            session = openSession();
1639
1640            SocialRequest[] array = new SocialRequestImpl[3];
1641
1642            array[0] = getByReceiverUserId_PrevAndNext(session, socialRequest,
1643                    receiverUserId, orderByComparator, true);
1644
1645            array[1] = socialRequest;
1646
1647            array[2] = getByReceiverUserId_PrevAndNext(session, socialRequest,
1648                    receiverUserId, orderByComparator, false);
1649
1650            return array;
1651        }
1652        catch (Exception e) {
1653            throw processException(e);
1654        }
1655        finally {
1656            closeSession(session);
1657        }
1658    }
1659
1660    protected SocialRequest getByReceiverUserId_PrevAndNext(Session session,
1661        SocialRequest socialRequest, long receiverUserId,
1662        OrderByComparator orderByComparator, boolean previous) {
1663        StringBundler query = null;
1664
1665        if (orderByComparator != null) {
1666            query = new StringBundler(6 +
1667                    (orderByComparator.getOrderByFields().length * 6));
1668        }
1669        else {
1670            query = new StringBundler(3);
1671        }
1672
1673        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1674
1675        query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
1676
1677        if (orderByComparator != null) {
1678            String[] orderByFields = orderByComparator.getOrderByFields();
1679
1680            if (orderByFields.length > 0) {
1681                query.append(WHERE_AND);
1682            }
1683
1684            for (int i = 0; i < orderByFields.length; i++) {
1685                query.append(_ORDER_BY_ENTITY_ALIAS);
1686                query.append(orderByFields[i]);
1687
1688                if ((i + 1) < orderByFields.length) {
1689                    if (orderByComparator.isAscending() ^ previous) {
1690                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1691                    }
1692                    else {
1693                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1694                    }
1695                }
1696                else {
1697                    if (orderByComparator.isAscending() ^ previous) {
1698                        query.append(WHERE_GREATER_THAN);
1699                    }
1700                    else {
1701                        query.append(WHERE_LESSER_THAN);
1702                    }
1703                }
1704            }
1705
1706            query.append(ORDER_BY_CLAUSE);
1707
1708            for (int i = 0; i < orderByFields.length; i++) {
1709                query.append(_ORDER_BY_ENTITY_ALIAS);
1710                query.append(orderByFields[i]);
1711
1712                if ((i + 1) < orderByFields.length) {
1713                    if (orderByComparator.isAscending() ^ previous) {
1714                        query.append(ORDER_BY_ASC_HAS_NEXT);
1715                    }
1716                    else {
1717                        query.append(ORDER_BY_DESC_HAS_NEXT);
1718                    }
1719                }
1720                else {
1721                    if (orderByComparator.isAscending() ^ previous) {
1722                        query.append(ORDER_BY_ASC);
1723                    }
1724                    else {
1725                        query.append(ORDER_BY_DESC);
1726                    }
1727                }
1728            }
1729        }
1730
1731        else {
1732            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1733        }
1734
1735        String sql = query.toString();
1736
1737        Query q = session.createQuery(sql);
1738
1739        q.setFirstResult(0);
1740        q.setMaxResults(2);
1741
1742        QueryPos qPos = QueryPos.getInstance(q);
1743
1744        qPos.add(receiverUserId);
1745
1746        if (orderByComparator != null) {
1747            Object[] values = orderByComparator.getOrderByValues(socialRequest);
1748
1749            for (Object value : values) {
1750                qPos.add(value);
1751            }
1752        }
1753
1754        List<SocialRequest> list = q.list();
1755
1756        if (list.size() == 2) {
1757            return list.get(1);
1758        }
1759        else {
1760            return null;
1761        }
1762    }
1763
1764    public List<SocialRequest> findByU_S(long userId, int status)
1765        throws SystemException {
1766        return findByU_S(userId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1767            null);
1768    }
1769
1770    public List<SocialRequest> findByU_S(long userId, int status, int start,
1771        int end) throws SystemException {
1772        return findByU_S(userId, status, start, end, null);
1773    }
1774
1775    public List<SocialRequest> findByU_S(long userId, int status, int start,
1776        int end, OrderByComparator orderByComparator) throws SystemException {
1777        Object[] finderArgs = new Object[] {
1778                userId, status,
1779                
1780                String.valueOf(start), String.valueOf(end),
1781                String.valueOf(orderByComparator)
1782            };
1783
1784        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_S,
1785                finderArgs, this);
1786
1787        if (list == null) {
1788            StringBundler query = null;
1789
1790            if (orderByComparator != null) {
1791                query = new StringBundler(4 +
1792                        (orderByComparator.getOrderByFields().length * 3));
1793            }
1794            else {
1795                query = new StringBundler(4);
1796            }
1797
1798            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1799
1800            query.append(_FINDER_COLUMN_U_S_USERID_2);
1801
1802            query.append(_FINDER_COLUMN_U_S_STATUS_2);
1803
1804            if (orderByComparator != null) {
1805                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1806                    orderByComparator);
1807            }
1808
1809            else {
1810                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1811            }
1812
1813            String sql = query.toString();
1814
1815            Session session = null;
1816
1817            try {
1818                session = openSession();
1819
1820                Query q = session.createQuery(sql);
1821
1822                QueryPos qPos = QueryPos.getInstance(q);
1823
1824                qPos.add(userId);
1825
1826                qPos.add(status);
1827
1828                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1829                        start, end);
1830            }
1831            catch (Exception e) {
1832                throw processException(e);
1833            }
1834            finally {
1835                if (list == null) {
1836                    list = new ArrayList<SocialRequest>();
1837                }
1838
1839                cacheResult(list);
1840
1841                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_S, finderArgs,
1842                    list);
1843
1844                closeSession(session);
1845            }
1846        }
1847
1848        return list;
1849    }
1850
1851    public SocialRequest findByU_S_First(long userId, int status,
1852        OrderByComparator orderByComparator)
1853        throws NoSuchRequestException, SystemException {
1854        List<SocialRequest> list = findByU_S(userId, status, 0, 1,
1855                orderByComparator);
1856
1857        if (list.isEmpty()) {
1858            StringBundler msg = new StringBundler(6);
1859
1860            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1861
1862            msg.append("userId=");
1863            msg.append(userId);
1864
1865            msg.append(", status=");
1866            msg.append(status);
1867
1868            msg.append(StringPool.CLOSE_CURLY_BRACE);
1869
1870            throw new NoSuchRequestException(msg.toString());
1871        }
1872        else {
1873            return list.get(0);
1874        }
1875    }
1876
1877    public SocialRequest findByU_S_Last(long userId, int status,
1878        OrderByComparator orderByComparator)
1879        throws NoSuchRequestException, SystemException {
1880        int count = countByU_S(userId, status);
1881
1882        List<SocialRequest> list = findByU_S(userId, status, count - 1, count,
1883                orderByComparator);
1884
1885        if (list.isEmpty()) {
1886            StringBundler msg = new StringBundler(6);
1887
1888            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1889
1890            msg.append("userId=");
1891            msg.append(userId);
1892
1893            msg.append(", status=");
1894            msg.append(status);
1895
1896            msg.append(StringPool.CLOSE_CURLY_BRACE);
1897
1898            throw new NoSuchRequestException(msg.toString());
1899        }
1900        else {
1901            return list.get(0);
1902        }
1903    }
1904
1905    public SocialRequest[] findByU_S_PrevAndNext(long requestId, long userId,
1906        int status, OrderByComparator orderByComparator)
1907        throws NoSuchRequestException, SystemException {
1908        SocialRequest socialRequest = findByPrimaryKey(requestId);
1909
1910        Session session = null;
1911
1912        try {
1913            session = openSession();
1914
1915            SocialRequest[] array = new SocialRequestImpl[3];
1916
1917            array[0] = getByU_S_PrevAndNext(session, socialRequest, userId,
1918                    status, orderByComparator, true);
1919
1920            array[1] = socialRequest;
1921
1922            array[2] = getByU_S_PrevAndNext(session, socialRequest, userId,
1923                    status, orderByComparator, false);
1924
1925            return array;
1926        }
1927        catch (Exception e) {
1928            throw processException(e);
1929        }
1930        finally {
1931            closeSession(session);
1932        }
1933    }
1934
1935    protected SocialRequest getByU_S_PrevAndNext(Session session,
1936        SocialRequest socialRequest, long userId, int status,
1937        OrderByComparator orderByComparator, boolean previous) {
1938        StringBundler query = null;
1939
1940        if (orderByComparator != null) {
1941            query = new StringBundler(6 +
1942                    (orderByComparator.getOrderByFields().length * 6));
1943        }
1944        else {
1945            query = new StringBundler(3);
1946        }
1947
1948        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1949
1950        query.append(_FINDER_COLUMN_U_S_USERID_2);
1951
1952        query.append(_FINDER_COLUMN_U_S_STATUS_2);
1953
1954        if (orderByComparator != null) {
1955            String[] orderByFields = orderByComparator.getOrderByFields();
1956
1957            if (orderByFields.length > 0) {
1958                query.append(WHERE_AND);
1959            }
1960
1961            for (int i = 0; i < orderByFields.length; i++) {
1962                query.append(_ORDER_BY_ENTITY_ALIAS);
1963                query.append(orderByFields[i]);
1964
1965                if ((i + 1) < orderByFields.length) {
1966                    if (orderByComparator.isAscending() ^ previous) {
1967                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1968                    }
1969                    else {
1970                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1971                    }
1972                }
1973                else {
1974                    if (orderByComparator.isAscending() ^ previous) {
1975                        query.append(WHERE_GREATER_THAN);
1976                    }
1977                    else {
1978                        query.append(WHERE_LESSER_THAN);
1979                    }
1980                }
1981            }
1982
1983            query.append(ORDER_BY_CLAUSE);
1984
1985            for (int i = 0; i < orderByFields.length; i++) {
1986                query.append(_ORDER_BY_ENTITY_ALIAS);
1987                query.append(orderByFields[i]);
1988
1989                if ((i + 1) < orderByFields.length) {
1990                    if (orderByComparator.isAscending() ^ previous) {
1991                        query.append(ORDER_BY_ASC_HAS_NEXT);
1992                    }
1993                    else {
1994                        query.append(ORDER_BY_DESC_HAS_NEXT);
1995                    }
1996                }
1997                else {
1998                    if (orderByComparator.isAscending() ^ previous) {
1999                        query.append(ORDER_BY_ASC);
2000                    }
2001                    else {
2002                        query.append(ORDER_BY_DESC);
2003                    }
2004                }
2005            }
2006        }
2007
2008        else {
2009            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2010        }
2011
2012        String sql = query.toString();
2013
2014        Query q = session.createQuery(sql);
2015
2016        q.setFirstResult(0);
2017        q.setMaxResults(2);
2018
2019        QueryPos qPos = QueryPos.getInstance(q);
2020
2021        qPos.add(userId);
2022
2023        qPos.add(status);
2024
2025        if (orderByComparator != null) {
2026            Object[] values = orderByComparator.getOrderByValues(socialRequest);
2027
2028            for (Object value : values) {
2029                qPos.add(value);
2030            }
2031        }
2032
2033        List<SocialRequest> list = q.list();
2034
2035        if (list.size() == 2) {
2036            return list.get(1);
2037        }
2038        else {
2039            return null;
2040        }
2041    }
2042
2043    public List<SocialRequest> findByR_S(long receiverUserId, int status)
2044        throws SystemException {
2045        return findByR_S(receiverUserId, status, QueryUtil.ALL_POS,
2046            QueryUtil.ALL_POS, null);
2047    }
2048
2049    public List<SocialRequest> findByR_S(long receiverUserId, int status,
2050        int start, int end) throws SystemException {
2051        return findByR_S(receiverUserId, status, start, end, null);
2052    }
2053
2054    public List<SocialRequest> findByR_S(long receiverUserId, int status,
2055        int start, int end, OrderByComparator orderByComparator)
2056        throws SystemException {
2057        Object[] finderArgs = new Object[] {
2058                receiverUserId, status,
2059                
2060                String.valueOf(start), String.valueOf(end),
2061                String.valueOf(orderByComparator)
2062            };
2063
2064        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_S,
2065                finderArgs, this);
2066
2067        if (list == null) {
2068            StringBundler query = null;
2069
2070            if (orderByComparator != null) {
2071                query = new StringBundler(4 +
2072                        (orderByComparator.getOrderByFields().length * 3));
2073            }
2074            else {
2075                query = new StringBundler(4);
2076            }
2077
2078            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2079
2080            query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
2081
2082            query.append(_FINDER_COLUMN_R_S_STATUS_2);
2083
2084            if (orderByComparator != null) {
2085                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2086                    orderByComparator);
2087            }
2088
2089            else {
2090                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2091            }
2092
2093            String sql = query.toString();
2094
2095            Session session = null;
2096
2097            try {
2098                session = openSession();
2099
2100                Query q = session.createQuery(sql);
2101
2102                QueryPos qPos = QueryPos.getInstance(q);
2103
2104                qPos.add(receiverUserId);
2105
2106                qPos.add(status);
2107
2108                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2109                        start, end);
2110            }
2111            catch (Exception e) {
2112                throw processException(e);
2113            }
2114            finally {
2115                if (list == null) {
2116                    list = new ArrayList<SocialRequest>();
2117                }
2118
2119                cacheResult(list);
2120
2121                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_S, finderArgs,
2122                    list);
2123
2124                closeSession(session);
2125            }
2126        }
2127
2128        return list;
2129    }
2130
2131    public SocialRequest findByR_S_First(long receiverUserId, int status,
2132        OrderByComparator orderByComparator)
2133        throws NoSuchRequestException, SystemException {
2134        List<SocialRequest> list = findByR_S(receiverUserId, status, 0, 1,
2135                orderByComparator);
2136
2137        if (list.isEmpty()) {
2138            StringBundler msg = new StringBundler(6);
2139
2140            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2141
2142            msg.append("receiverUserId=");
2143            msg.append(receiverUserId);
2144
2145            msg.append(", status=");
2146            msg.append(status);
2147
2148            msg.append(StringPool.CLOSE_CURLY_BRACE);
2149
2150            throw new NoSuchRequestException(msg.toString());
2151        }
2152        else {
2153            return list.get(0);
2154        }
2155    }
2156
2157    public SocialRequest findByR_S_Last(long receiverUserId, int status,
2158        OrderByComparator orderByComparator)
2159        throws NoSuchRequestException, SystemException {
2160        int count = countByR_S(receiverUserId, status);
2161
2162        List<SocialRequest> list = findByR_S(receiverUserId, status, count - 1,
2163                count, orderByComparator);
2164
2165        if (list.isEmpty()) {
2166            StringBundler msg = new StringBundler(6);
2167
2168            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2169
2170            msg.append("receiverUserId=");
2171            msg.append(receiverUserId);
2172
2173            msg.append(", status=");
2174            msg.append(status);
2175
2176            msg.append(StringPool.CLOSE_CURLY_BRACE);
2177
2178            throw new NoSuchRequestException(msg.toString());
2179        }
2180        else {
2181            return list.get(0);
2182        }
2183    }
2184
2185    public SocialRequest[] findByR_S_PrevAndNext(long requestId,
2186        long receiverUserId, int status, OrderByComparator orderByComparator)
2187        throws NoSuchRequestException, SystemException {
2188        SocialRequest socialRequest = findByPrimaryKey(requestId);
2189
2190        Session session = null;
2191
2192        try {
2193            session = openSession();
2194
2195            SocialRequest[] array = new SocialRequestImpl[3];
2196
2197            array[0] = getByR_S_PrevAndNext(session, socialRequest,
2198                    receiverUserId, status, orderByComparator, true);
2199
2200            array[1] = socialRequest;
2201
2202            array[2] = getByR_S_PrevAndNext(session, socialRequest,
2203                    receiverUserId, status, orderByComparator, false);
2204
2205            return array;
2206        }
2207        catch (Exception e) {
2208            throw processException(e);
2209        }
2210        finally {
2211            closeSession(session);
2212        }
2213    }
2214
2215    protected SocialRequest getByR_S_PrevAndNext(Session session,
2216        SocialRequest socialRequest, long receiverUserId, int status,
2217        OrderByComparator orderByComparator, boolean previous) {
2218        StringBundler query = null;
2219
2220        if (orderByComparator != null) {
2221            query = new StringBundler(6 +
2222                    (orderByComparator.getOrderByFields().length * 6));
2223        }
2224        else {
2225            query = new StringBundler(3);
2226        }
2227
2228        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2229
2230        query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
2231
2232        query.append(_FINDER_COLUMN_R_S_STATUS_2);
2233
2234        if (orderByComparator != null) {
2235            String[] orderByFields = orderByComparator.getOrderByFields();
2236
2237            if (orderByFields.length > 0) {
2238                query.append(WHERE_AND);
2239            }
2240
2241            for (int i = 0; i < orderByFields.length; i++) {
2242                query.append(_ORDER_BY_ENTITY_ALIAS);
2243                query.append(orderByFields[i]);
2244
2245                if ((i + 1) < orderByFields.length) {
2246                    if (orderByComparator.isAscending() ^ previous) {
2247                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
2248                    }
2249                    else {
2250                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
2251                    }
2252                }
2253                else {
2254                    if (orderByComparator.isAscending() ^ previous) {
2255                        query.append(WHERE_GREATER_THAN);
2256                    }
2257                    else {
2258                        query.append(WHERE_LESSER_THAN);
2259                    }
2260                }
2261            }
2262
2263            query.append(ORDER_BY_CLAUSE);
2264
2265            for (int i = 0; i < orderByFields.length; i++) {
2266                query.append(_ORDER_BY_ENTITY_ALIAS);
2267                query.append(orderByFields[i]);
2268
2269                if ((i + 1) < orderByFields.length) {
2270                    if (orderByComparator.isAscending() ^ previous) {
2271                        query.append(ORDER_BY_ASC_HAS_NEXT);
2272                    }
2273                    else {
2274                        query.append(ORDER_BY_DESC_HAS_NEXT);
2275                    }
2276                }
2277                else {
2278                    if (orderByComparator.isAscending() ^ previous) {
2279                        query.append(ORDER_BY_ASC);
2280                    }
2281                    else {
2282                        query.append(ORDER_BY_DESC);
2283                    }
2284                }
2285            }
2286        }
2287
2288        else {
2289            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2290        }
2291
2292        String sql = query.toString();
2293
2294        Query q = session.createQuery(sql);
2295
2296        q.setFirstResult(0);
2297        q.setMaxResults(2);
2298
2299        QueryPos qPos = QueryPos.getInstance(q);
2300
2301        qPos.add(receiverUserId);
2302
2303        qPos.add(status);
2304
2305        if (orderByComparator != null) {
2306            Object[] values = orderByComparator.getOrderByValues(socialRequest);
2307
2308            for (Object value : values) {
2309                qPos.add(value);
2310            }
2311        }
2312
2313        List<SocialRequest> list = q.list();
2314
2315        if (list.size() == 2) {
2316            return list.get(1);
2317        }
2318        else {
2319            return null;
2320        }
2321    }
2322
2323    public SocialRequest findByU_C_C_T_R(long userId, long classNameId,
2324        long classPK, int type, long receiverUserId)
2325        throws NoSuchRequestException, SystemException {
2326        SocialRequest socialRequest = fetchByU_C_C_T_R(userId, classNameId,
2327                classPK, type, receiverUserId);
2328
2329        if (socialRequest == null) {
2330            StringBundler msg = new StringBundler(12);
2331
2332            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2333
2334            msg.append("userId=");
2335            msg.append(userId);
2336
2337            msg.append(", classNameId=");
2338            msg.append(classNameId);
2339
2340            msg.append(", classPK=");
2341            msg.append(classPK);
2342
2343            msg.append(", type=");
2344            msg.append(type);
2345
2346            msg.append(", receiverUserId=");
2347            msg.append(receiverUserId);
2348
2349            msg.append(StringPool.CLOSE_CURLY_BRACE);
2350
2351            if (_log.isWarnEnabled()) {
2352                _log.warn(msg.toString());
2353            }
2354
2355            throw new NoSuchRequestException(msg.toString());
2356        }
2357
2358        return socialRequest;
2359    }
2360
2361    public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
2362        long classPK, int type, long receiverUserId) throws SystemException {
2363        return fetchByU_C_C_T_R(userId, classNameId, classPK, type,
2364            receiverUserId, true);
2365    }
2366
2367    public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
2368        long classPK, int type, long receiverUserId, boolean retrieveFromCache)
2369        throws SystemException {
2370        Object[] finderArgs = new Object[] {
2371                userId, classNameId, classPK, type, receiverUserId
2372            };
2373
2374        Object result = null;
2375
2376        if (retrieveFromCache) {
2377            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2378                    finderArgs, this);
2379        }
2380
2381        if (result == null) {
2382            StringBundler query = new StringBundler(7);
2383
2384            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2385
2386            query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
2387
2388            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
2389
2390            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
2391
2392            query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
2393
2394            query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
2395
2396            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2397
2398            String sql = query.toString();
2399
2400            Session session = null;
2401
2402            try {
2403                session = openSession();
2404
2405                Query q = session.createQuery(sql);
2406
2407                QueryPos qPos = QueryPos.getInstance(q);
2408
2409                qPos.add(userId);
2410
2411                qPos.add(classNameId);
2412
2413                qPos.add(classPK);
2414
2415                qPos.add(type);
2416
2417                qPos.add(receiverUserId);
2418
2419                List<SocialRequest> list = q.list();
2420
2421                result = list;
2422
2423                SocialRequest socialRequest = null;
2424
2425                if (list.isEmpty()) {
2426                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2427                        finderArgs, list);
2428                }
2429                else {
2430                    socialRequest = list.get(0);
2431
2432                    cacheResult(socialRequest);
2433
2434                    if ((socialRequest.getUserId() != userId) ||
2435                            (socialRequest.getClassNameId() != classNameId) ||
2436                            (socialRequest.getClassPK() != classPK) ||
2437                            (socialRequest.getType() != type) ||
2438                            (socialRequest.getReceiverUserId() != receiverUserId)) {
2439                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2440                            finderArgs, socialRequest);
2441                    }
2442                }
2443
2444                return socialRequest;
2445            }
2446            catch (Exception e) {
2447                throw processException(e);
2448            }
2449            finally {
2450                if (result == null) {
2451                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2452                        finderArgs, new ArrayList<SocialRequest>());
2453                }
2454
2455                closeSession(session);
2456            }
2457        }
2458        else {
2459            if (result instanceof List<?>) {
2460                return null;
2461            }
2462            else {
2463                return (SocialRequest)result;
2464            }
2465        }
2466    }
2467
2468    public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
2469        long classPK, int type, int status) throws SystemException {
2470        return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
2471            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2472    }
2473
2474    public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
2475        long classPK, int type, int status, int start, int end)
2476        throws SystemException {
2477        return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
2478            start, end, null);
2479    }
2480
2481    public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
2482        long classPK, int type, int status, int start, int end,
2483        OrderByComparator orderByComparator) throws SystemException {
2484        Object[] finderArgs = new Object[] {
2485                userId, classNameId, classPK, type, status,
2486                
2487                String.valueOf(start), String.valueOf(end),
2488                String.valueOf(orderByComparator)
2489            };
2490
2491        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_C_C_T_S,
2492                finderArgs, this);
2493
2494        if (list == null) {
2495            StringBundler query = null;
2496
2497            if (orderByComparator != null) {
2498                query = new StringBundler(7 +
2499                        (orderByComparator.getOrderByFields().length * 3));
2500            }
2501            else {
2502                query = new StringBundler(7);
2503            }
2504
2505            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2506
2507            query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
2508
2509            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
2510
2511            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
2512
2513            query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
2514
2515            query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
2516
2517            if (orderByComparator != null) {
2518                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2519                    orderByComparator);
2520            }
2521
2522            else {
2523                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2524            }
2525
2526            String sql = query.toString();
2527
2528            Session session = null;
2529
2530            try {
2531                session = openSession();
2532
2533                Query q = session.createQuery(sql);
2534
2535                QueryPos qPos = QueryPos.getInstance(q);
2536
2537                qPos.add(userId);
2538
2539                qPos.add(classNameId);
2540
2541                qPos.add(classPK);
2542
2543                qPos.add(type);
2544
2545                qPos.add(status);
2546
2547                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2548                        start, end);
2549            }
2550            catch (Exception e) {
2551                throw processException(e);
2552            }
2553            finally {
2554                if (list == null) {
2555                    list = new ArrayList<SocialRequest>();
2556                }
2557
2558                cacheResult(list);
2559
2560                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_C_C_T_S,
2561                    finderArgs, list);
2562
2563                closeSession(session);
2564            }
2565        }
2566
2567        return list;
2568    }
2569
2570    public SocialRequest findByU_C_C_T_S_First(long userId, long classNameId,
2571        long classPK, int type, int status, OrderByComparator orderByComparator)
2572        throws NoSuchRequestException, SystemException {
2573        List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
2574                classPK, type, status, 0, 1, orderByComparator);
2575
2576        if (list.isEmpty()) {
2577            StringBundler msg = new StringBundler(12);
2578
2579            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2580
2581            msg.append("userId=");
2582            msg.append(userId);
2583
2584            msg.append(", classNameId=");
2585            msg.append(classNameId);
2586
2587            msg.append(", classPK=");
2588            msg.append(classPK);
2589
2590            msg.append(", type=");
2591            msg.append(type);
2592
2593            msg.append(", status=");
2594            msg.append(status);
2595
2596            msg.append(StringPool.CLOSE_CURLY_BRACE);
2597
2598            throw new NoSuchRequestException(msg.toString());
2599        }
2600        else {
2601            return list.get(0);
2602        }
2603    }
2604
2605    public SocialRequest findByU_C_C_T_S_Last(long userId, long classNameId,
2606        long classPK, int type, int status, OrderByComparator orderByComparator)
2607        throws NoSuchRequestException, SystemException {
2608        int count = countByU_C_C_T_S(userId, classNameId, classPK, type, status);
2609
2610        List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
2611                classPK, type, status, count - 1, count, orderByComparator);
2612
2613        if (list.isEmpty()) {
2614            StringBundler msg = new StringBundler(12);
2615
2616            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2617
2618            msg.append("userId=");
2619            msg.append(userId);
2620
2621            msg.append(", classNameId=");
2622            msg.append(classNameId);
2623
2624            msg.append(", classPK=");
2625            msg.append(classPK);
2626
2627            msg.append(", type=");
2628            msg.append(type);
2629
2630            msg.append(", status=");
2631            msg.append(status);
2632
2633            msg.append(StringPool.CLOSE_CURLY_BRACE);
2634
2635            throw new NoSuchRequestException(msg.toString());
2636        }
2637        else {
2638            return list.get(0);
2639        }
2640    }
2641
2642    public SocialRequest[] findByU_C_C_T_S_PrevAndNext(long requestId,
2643        long userId, long classNameId, long classPK, int type, int status,
2644        OrderByComparator orderByComparator)
2645        throws NoSuchRequestException, SystemException {
2646        SocialRequest socialRequest = findByPrimaryKey(requestId);
2647
2648        Session session = null;
2649
2650        try {
2651            session = openSession();
2652
2653            SocialRequest[] array = new SocialRequestImpl[3];
2654
2655            array[0] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
2656                    userId, classNameId, classPK, type, status,
2657                    orderByComparator, true);
2658
2659            array[1] = socialRequest;
2660
2661            array[2] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
2662                    userId, classNameId, classPK, type, status,
2663                    orderByComparator, false);
2664
2665            return array;
2666        }
2667        catch (Exception e) {
2668            throw processException(e);
2669        }
2670        finally {
2671            closeSession(session);
2672        }
2673    }
2674
2675    protected SocialRequest getByU_C_C_T_S_PrevAndNext(Session session,
2676        SocialRequest socialRequest, long userId, long classNameId,
2677        long classPK, int type, int status,
2678        OrderByComparator orderByComparator, boolean previous) {
2679        StringBundler query = null;
2680
2681        if (orderByComparator != null) {
2682            query = new StringBundler(6 +
2683                    (orderByComparator.getOrderByFields().length * 6));
2684        }
2685        else {
2686            query = new StringBundler(3);
2687        }
2688
2689        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2690
2691        query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
2692
2693        query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
2694
2695        query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
2696
2697        query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
2698
2699        query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
2700
2701        if (orderByComparator != null) {
2702            String[] orderByFields = orderByComparator.getOrderByFields();
2703
2704            if (orderByFields.length > 0) {
2705                query.append(WHERE_AND);
2706            }
2707
2708            for (int i = 0; i < orderByFields.length; i++) {
2709                query.append(_ORDER_BY_ENTITY_ALIAS);
2710                query.append(orderByFields[i]);
2711
2712                if ((i + 1) < orderByFields.length) {
2713                    if (orderByComparator.isAscending() ^ previous) {
2714                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
2715                    }
2716                    else {
2717                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
2718                    }
2719                }
2720                else {
2721                    if (orderByComparator.isAscending() ^ previous) {
2722                        query.append(WHERE_GREATER_THAN);
2723                    }
2724                    else {
2725                        query.append(WHERE_LESSER_THAN);
2726                    }
2727                }
2728            }
2729
2730            query.append(ORDER_BY_CLAUSE);
2731
2732            for (int i = 0; i < orderByFields.length; i++) {
2733                query.append(_ORDER_BY_ENTITY_ALIAS);
2734                query.append(orderByFields[i]);
2735
2736                if ((i + 1) < orderByFields.length) {
2737                    if (orderByComparator.isAscending() ^ previous) {
2738                        query.append(ORDER_BY_ASC_HAS_NEXT);
2739                    }
2740                    else {
2741                        query.append(ORDER_BY_DESC_HAS_NEXT);
2742                    }
2743                }
2744                else {
2745                    if (orderByComparator.isAscending() ^ previous) {
2746                        query.append(ORDER_BY_ASC);
2747                    }
2748                    else {
2749                        query.append(ORDER_BY_DESC);
2750                    }
2751                }
2752            }
2753        }
2754
2755        else {
2756            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2757        }
2758
2759        String sql = query.toString();
2760
2761        Query q = session.createQuery(sql);
2762
2763        q.setFirstResult(0);
2764        q.setMaxResults(2);
2765
2766        QueryPos qPos = QueryPos.getInstance(q);
2767
2768        qPos.add(userId);
2769
2770        qPos.add(classNameId);
2771
2772        qPos.add(classPK);
2773
2774        qPos.add(type);
2775
2776        qPos.add(status);
2777
2778        if (orderByComparator != null) {
2779            Object[] values = orderByComparator.getOrderByValues(socialRequest);
2780
2781            for (Object value : values) {
2782                qPos.add(value);
2783            }
2784        }
2785
2786        List<SocialRequest> list = q.list();
2787
2788        if (list.size() == 2) {
2789            return list.get(1);
2790        }
2791        else {
2792            return null;
2793        }
2794    }
2795
2796    public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
2797        int type, long receiverUserId, int status) throws SystemException {
2798        return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
2799            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2800    }
2801
2802    public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
2803        int type, long receiverUserId, int status, int start, int end)
2804        throws SystemException {
2805        return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
2806            status, start, end, null);
2807    }
2808
2809    public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
2810        int type, long receiverUserId, int status, int start, int end,
2811        OrderByComparator orderByComparator) throws SystemException {
2812        Object[] finderArgs = new Object[] {
2813                classNameId, classPK, type, receiverUserId, status,
2814                
2815                String.valueOf(start), String.valueOf(end),
2816                String.valueOf(orderByComparator)
2817            };
2818
2819        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_T_R_S,
2820                finderArgs, this);
2821
2822        if (list == null) {
2823            StringBundler query = null;
2824
2825            if (orderByComparator != null) {
2826                query = new StringBundler(7 +
2827                        (orderByComparator.getOrderByFields().length * 3));
2828            }
2829            else {
2830                query = new StringBundler(7);
2831            }
2832
2833            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2834
2835            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
2836
2837            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
2838
2839            query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
2840
2841            query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
2842
2843            query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
2844
2845            if (orderByComparator != null) {
2846                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2847                    orderByComparator);
2848            }
2849
2850            else {
2851                query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2852            }
2853
2854            String sql = query.toString();
2855
2856            Session session = null;
2857
2858            try {
2859                session = openSession();
2860
2861                Query q = session.createQuery(sql);
2862
2863                QueryPos qPos = QueryPos.getInstance(q);
2864
2865                qPos.add(classNameId);
2866
2867                qPos.add(classPK);
2868
2869                qPos.add(type);
2870
2871                qPos.add(receiverUserId);
2872
2873                qPos.add(status);
2874
2875                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2876                        start, end);
2877            }
2878            catch (Exception e) {
2879                throw processException(e);
2880            }
2881            finally {
2882                if (list == null) {
2883                    list = new ArrayList<SocialRequest>();
2884                }
2885
2886                cacheResult(list);
2887
2888                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_T_R_S,
2889                    finderArgs, list);
2890
2891                closeSession(session);
2892            }
2893        }
2894
2895        return list;
2896    }
2897
2898    public SocialRequest findByC_C_T_R_S_First(long classNameId, long classPK,
2899        int type, long receiverUserId, int status,
2900        OrderByComparator orderByComparator)
2901        throws NoSuchRequestException, SystemException {
2902        List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
2903                receiverUserId, status, 0, 1, orderByComparator);
2904
2905        if (list.isEmpty()) {
2906            StringBundler msg = new StringBundler(12);
2907
2908            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2909
2910            msg.append("classNameId=");
2911            msg.append(classNameId);
2912
2913            msg.append(", classPK=");
2914            msg.append(classPK);
2915
2916            msg.append(", type=");
2917            msg.append(type);
2918
2919            msg.append(", receiverUserId=");
2920            msg.append(receiverUserId);
2921
2922            msg.append(", status=");
2923            msg.append(status);
2924
2925            msg.append(StringPool.CLOSE_CURLY_BRACE);
2926
2927            throw new NoSuchRequestException(msg.toString());
2928        }
2929        else {
2930            return list.get(0);
2931        }
2932    }
2933
2934    public SocialRequest findByC_C_T_R_S_Last(long classNameId, long classPK,
2935        int type, long receiverUserId, int status,
2936        OrderByComparator orderByComparator)
2937        throws NoSuchRequestException, SystemException {
2938        int count = countByC_C_T_R_S(classNameId, classPK, type,
2939                receiverUserId, status);
2940
2941        List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
2942                receiverUserId, status, count - 1, count, orderByComparator);
2943
2944        if (list.isEmpty()) {
2945            StringBundler msg = new StringBundler(12);
2946
2947            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2948
2949            msg.append("classNameId=");
2950            msg.append(classNameId);
2951
2952            msg.append(", classPK=");
2953            msg.append(classPK);
2954
2955            msg.append(", type=");
2956            msg.append(type);
2957
2958            msg.append(", receiverUserId=");
2959            msg.append(receiverUserId);
2960
2961            msg.append(", status=");
2962            msg.append(status);
2963
2964            msg.append(StringPool.CLOSE_CURLY_BRACE);
2965
2966            throw new NoSuchRequestException(msg.toString());
2967        }
2968        else {
2969            return list.get(0);
2970        }
2971    }
2972
2973    public SocialRequest[] findByC_C_T_R_S_PrevAndNext(long requestId,
2974        long classNameId, long classPK, int type, long receiverUserId,
2975        int status, OrderByComparator orderByComparator)
2976        throws NoSuchRequestException, SystemException {
2977        SocialRequest socialRequest = findByPrimaryKey(requestId);
2978
2979        Session session = null;
2980
2981        try {
2982            session = openSession();
2983
2984            SocialRequest[] array = new SocialRequestImpl[3];
2985
2986            array[0] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
2987                    classNameId, classPK, type, receiverUserId, status,
2988                    orderByComparator, true);
2989
2990            array[1] = socialRequest;
2991
2992            array[2] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
2993                    classNameId, classPK, type, receiverUserId, status,
2994                    orderByComparator, false);
2995
2996            return array;
2997        }
2998        catch (Exception e) {
2999            throw processException(e);
3000        }
3001        finally {
3002            closeSession(session);
3003        }
3004    }
3005
3006    protected SocialRequest getByC_C_T_R_S_PrevAndNext(Session session,
3007        SocialRequest socialRequest, long classNameId, long classPK, int type,
3008        long receiverUserId, int status, OrderByComparator orderByComparator,
3009        boolean previous) {
3010        StringBundler query = null;
3011
3012        if (orderByComparator != null) {
3013            query = new StringBundler(6 +
3014                    (orderByComparator.getOrderByFields().length * 6));
3015        }
3016        else {
3017            query = new StringBundler(3);
3018        }
3019
3020        query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3021
3022        query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
3023
3024        query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
3025
3026        query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
3027
3028        query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
3029
3030        query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
3031
3032        if (orderByComparator != null) {
3033            String[] orderByFields = orderByComparator.getOrderByFields();
3034
3035            if (orderByFields.length > 0) {
3036                query.append(WHERE_AND);
3037            }
3038
3039            for (int i = 0; i < orderByFields.length; i++) {
3040                query.append(_ORDER_BY_ENTITY_ALIAS);
3041                query.append(orderByFields[i]);
3042
3043                if ((i + 1) < orderByFields.length) {
3044                    if (orderByComparator.isAscending() ^ previous) {
3045                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
3046                    }
3047                    else {
3048                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
3049                    }
3050                }
3051                else {
3052                    if (orderByComparator.isAscending() ^ previous) {
3053                        query.append(WHERE_GREATER_THAN);
3054                    }
3055                    else {
3056                        query.append(WHERE_LESSER_THAN);
3057                    }
3058                }
3059            }
3060
3061            query.append(ORDER_BY_CLAUSE);
3062
3063            for (int i = 0; i < orderByFields.length; i++) {
3064                query.append(_ORDER_BY_ENTITY_ALIAS);
3065                query.append(orderByFields[i]);
3066
3067                if ((i + 1) < orderByFields.length) {
3068                    if (orderByComparator.isAscending() ^ previous) {
3069                        query.append(ORDER_BY_ASC_HAS_NEXT);
3070                    }
3071                    else {
3072                        query.append(ORDER_BY_DESC_HAS_NEXT);
3073                    }
3074                }
3075                else {
3076                    if (orderByComparator.isAscending() ^ previous) {
3077                        query.append(ORDER_BY_ASC);
3078                    }
3079                    else {
3080                        query.append(ORDER_BY_DESC);
3081                    }
3082                }
3083            }
3084        }
3085
3086        else {
3087            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3088        }
3089
3090        String sql = query.toString();
3091
3092        Query q = session.createQuery(sql);
3093
3094        q.setFirstResult(0);
3095        q.setMaxResults(2);
3096
3097        QueryPos qPos = QueryPos.getInstance(q);
3098
3099        qPos.add(classNameId);
3100
3101        qPos.add(classPK);
3102
3103        qPos.add(type);
3104
3105        qPos.add(receiverUserId);
3106
3107        qPos.add(status);
3108
3109        if (orderByComparator != null) {
3110            Object[] values = orderByComparator.getOrderByValues(socialRequest);
3111
3112            for (Object value : values) {
3113                qPos.add(value);
3114            }
3115        }
3116
3117        List<SocialRequest> list = q.list();
3118
3119        if (list.size() == 2) {
3120            return list.get(1);
3121        }
3122        else {
3123            return null;
3124        }
3125    }
3126
3127    public List<SocialRequest> findAll() throws SystemException {
3128        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3129    }
3130
3131    public List<SocialRequest> findAll(int start, int end)
3132        throws SystemException {
3133        return findAll(start, end, null);
3134    }
3135
3136    public List<SocialRequest> findAll(int start, int end,
3137        OrderByComparator orderByComparator) throws SystemException {
3138        Object[] finderArgs = new Object[] {
3139                String.valueOf(start), String.valueOf(end),
3140                String.valueOf(orderByComparator)
3141            };
3142
3143        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3144                finderArgs, this);
3145
3146        if (list == null) {
3147            StringBundler query = null;
3148            String sql = null;
3149
3150            if (orderByComparator != null) {
3151                query = new StringBundler(2 +
3152                        (orderByComparator.getOrderByFields().length * 3));
3153
3154                query.append(_SQL_SELECT_SOCIALREQUEST);
3155
3156                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3157                    orderByComparator);
3158
3159                sql = query.toString();
3160            }
3161            else {
3162                sql = _SQL_SELECT_SOCIALREQUEST.concat(SocialRequestModelImpl.ORDER_BY_JPQL);
3163            }
3164
3165            Session session = null;
3166
3167            try {
3168                session = openSession();
3169
3170                Query q = session.createQuery(sql);
3171
3172                if (orderByComparator == null) {
3173                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3174                            start, end, false);
3175
3176                    Collections.sort(list);
3177                }
3178                else {
3179                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3180                            start, end);
3181                }
3182            }
3183            catch (Exception e) {
3184                throw processException(e);
3185            }
3186            finally {
3187                if (list == null) {
3188                    list = new ArrayList<SocialRequest>();
3189                }
3190
3191                cacheResult(list);
3192
3193                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3194
3195                closeSession(session);
3196            }
3197        }
3198
3199        return list;
3200    }
3201
3202    public void removeByUuid(String uuid) throws SystemException {
3203        for (SocialRequest socialRequest : findByUuid(uuid)) {
3204            remove(socialRequest);
3205        }
3206    }
3207
3208    public void removeByUUID_G(String uuid, long groupId)
3209        throws NoSuchRequestException, SystemException {
3210        SocialRequest socialRequest = findByUUID_G(uuid, groupId);
3211
3212        remove(socialRequest);
3213    }
3214
3215    public void removeByCompanyId(long companyId) throws SystemException {
3216        for (SocialRequest socialRequest : findByCompanyId(companyId)) {
3217            remove(socialRequest);
3218        }
3219    }
3220
3221    public void removeByUserId(long userId) throws SystemException {
3222        for (SocialRequest socialRequest : findByUserId(userId)) {
3223            remove(socialRequest);
3224        }
3225    }
3226
3227    public void removeByReceiverUserId(long receiverUserId)
3228        throws SystemException {
3229        for (SocialRequest socialRequest : findByReceiverUserId(receiverUserId)) {
3230            remove(socialRequest);
3231        }
3232    }
3233
3234    public void removeByU_S(long userId, int status) throws SystemException {
3235        for (SocialRequest socialRequest : findByU_S(userId, status)) {
3236            remove(socialRequest);
3237        }
3238    }
3239
3240    public void removeByR_S(long receiverUserId, int status)
3241        throws SystemException {
3242        for (SocialRequest socialRequest : findByR_S(receiverUserId, status)) {
3243            remove(socialRequest);
3244        }
3245    }
3246
3247    public void removeByU_C_C_T_R(long userId, long classNameId, long classPK,
3248        int type, long receiverUserId)
3249        throws NoSuchRequestException, SystemException {
3250        SocialRequest socialRequest = findByU_C_C_T_R(userId, classNameId,
3251                classPK, type, receiverUserId);
3252
3253        remove(socialRequest);
3254    }
3255
3256    public void removeByU_C_C_T_S(long userId, long classNameId, long classPK,
3257        int type, int status) throws SystemException {
3258        for (SocialRequest socialRequest : findByU_C_C_T_S(userId, classNameId,
3259                classPK, type, status)) {
3260            remove(socialRequest);
3261        }
3262    }
3263
3264    public void removeByC_C_T_R_S(long classNameId, long classPK, int type,
3265        long receiverUserId, int status) throws SystemException {
3266        for (SocialRequest socialRequest : findByC_C_T_R_S(classNameId,
3267                classPK, type, receiverUserId, status)) {
3268            remove(socialRequest);
3269        }
3270    }
3271
3272    public void removeAll() throws SystemException {
3273        for (SocialRequest socialRequest : findAll()) {
3274            remove(socialRequest);
3275        }
3276    }
3277
3278    public int countByUuid(String uuid) throws SystemException {
3279        Object[] finderArgs = new Object[] { uuid };
3280
3281        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3282                finderArgs, this);
3283
3284        if (count == null) {
3285            StringBundler query = new StringBundler(2);
3286
3287            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3288
3289            if (uuid == null) {
3290                query.append(_FINDER_COLUMN_UUID_UUID_1);
3291            }
3292            else {
3293                if (uuid.equals(StringPool.BLANK)) {
3294                    query.append(_FINDER_COLUMN_UUID_UUID_3);
3295                }
3296                else {
3297                    query.append(_FINDER_COLUMN_UUID_UUID_2);
3298                }
3299            }
3300
3301            String sql = query.toString();
3302
3303            Session session = null;
3304
3305            try {
3306                session = openSession();
3307
3308                Query q = session.createQuery(sql);
3309
3310                QueryPos qPos = QueryPos.getInstance(q);
3311
3312                if (uuid != null) {
3313                    qPos.add(uuid);
3314                }
3315
3316                count = (Long)q.uniqueResult();
3317            }
3318            catch (Exception e) {
3319                throw processException(e);
3320            }
3321            finally {
3322                if (count == null) {
3323                    count = Long.valueOf(0);
3324                }
3325
3326                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3327                    finderArgs, count);
3328
3329                closeSession(session);
3330            }
3331        }
3332
3333        return count.intValue();
3334    }
3335
3336    public int countByUUID_G(String uuid, long groupId)
3337        throws SystemException {
3338        Object[] finderArgs = new Object[] { uuid, groupId };
3339
3340        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3341                finderArgs, this);
3342
3343        if (count == null) {
3344            StringBundler query = new StringBundler(3);
3345
3346            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3347
3348            if (uuid == null) {
3349                query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3350            }
3351            else {
3352                if (uuid.equals(StringPool.BLANK)) {
3353                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3354                }
3355                else {
3356                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3357                }
3358            }
3359
3360            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3361
3362            String sql = query.toString();
3363
3364            Session session = null;
3365
3366            try {
3367                session = openSession();
3368
3369                Query q = session.createQuery(sql);
3370
3371                QueryPos qPos = QueryPos.getInstance(q);
3372
3373                if (uuid != null) {
3374                    qPos.add(uuid);
3375                }
3376
3377                qPos.add(groupId);
3378
3379                count = (Long)q.uniqueResult();
3380            }
3381            catch (Exception e) {
3382                throw processException(e);
3383            }
3384            finally {
3385                if (count == null) {
3386                    count = Long.valueOf(0);
3387                }
3388
3389                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3390                    finderArgs, count);
3391
3392                closeSession(session);
3393            }
3394        }
3395
3396        return count.intValue();
3397    }
3398
3399    public int countByCompanyId(long companyId) throws SystemException {
3400        Object[] finderArgs = new Object[] { companyId };
3401
3402        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3403                finderArgs, this);
3404
3405        if (count == null) {
3406            StringBundler query = new StringBundler(2);
3407
3408            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3409
3410            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3411
3412            String sql = query.toString();
3413
3414            Session session = null;
3415
3416            try {
3417                session = openSession();
3418
3419                Query q = session.createQuery(sql);
3420
3421                QueryPos qPos = QueryPos.getInstance(q);
3422
3423                qPos.add(companyId);
3424
3425                count = (Long)q.uniqueResult();
3426            }
3427            catch (Exception e) {
3428                throw processException(e);
3429            }
3430            finally {
3431                if (count == null) {
3432                    count = Long.valueOf(0);
3433                }
3434
3435                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3436                    finderArgs, count);
3437
3438                closeSession(session);
3439            }
3440        }
3441
3442        return count.intValue();
3443    }
3444
3445    public int countByUserId(long userId) throws SystemException {
3446        Object[] finderArgs = new Object[] { userId };
3447
3448        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
3449                finderArgs, this);
3450
3451        if (count == null) {
3452            StringBundler query = new StringBundler(2);
3453
3454            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3455
3456            query.append(_FINDER_COLUMN_USERID_USERID_2);
3457
3458            String sql = query.toString();
3459
3460            Session session = null;
3461
3462            try {
3463                session = openSession();
3464
3465                Query q = session.createQuery(sql);
3466
3467                QueryPos qPos = QueryPos.getInstance(q);
3468
3469                qPos.add(userId);
3470
3471                count = (Long)q.uniqueResult();
3472            }
3473            catch (Exception e) {
3474                throw processException(e);
3475            }
3476            finally {
3477                if (count == null) {
3478                    count = Long.valueOf(0);
3479                }
3480
3481                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
3482                    finderArgs, count);
3483
3484                closeSession(session);
3485            }
3486        }
3487
3488        return count.intValue();
3489    }
3490
3491    public int countByReceiverUserId(long receiverUserId)
3492        throws SystemException {
3493        Object[] finderArgs = new Object[] { receiverUserId };
3494
3495        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
3496                finderArgs, this);
3497
3498        if (count == null) {
3499            StringBundler query = new StringBundler(2);
3500
3501            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3502
3503            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
3504
3505            String sql = query.toString();
3506
3507            Session session = null;
3508
3509            try {
3510                session = openSession();
3511
3512                Query q = session.createQuery(sql);
3513
3514                QueryPos qPos = QueryPos.getInstance(q);
3515
3516                qPos.add(receiverUserId);
3517
3518                count = (Long)q.uniqueResult();
3519            }
3520            catch (Exception e) {
3521                throw processException(e);
3522            }
3523            finally {
3524                if (count == null) {
3525                    count = Long.valueOf(0);
3526                }
3527
3528                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
3529                    finderArgs, count);
3530
3531                closeSession(session);
3532            }
3533        }
3534
3535        return count.intValue();
3536    }
3537
3538    public int countByU_S(long userId, int status) throws SystemException {
3539        Object[] finderArgs = new Object[] { userId, status };
3540
3541        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_S,
3542                finderArgs, this);
3543
3544        if (count == null) {
3545            StringBundler query = new StringBundler(3);
3546
3547            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3548
3549            query.append(_FINDER_COLUMN_U_S_USERID_2);
3550
3551            query.append(_FINDER_COLUMN_U_S_STATUS_2);
3552
3553            String sql = query.toString();
3554
3555            Session session = null;
3556
3557            try {
3558                session = openSession();
3559
3560                Query q = session.createQuery(sql);
3561
3562                QueryPos qPos = QueryPos.getInstance(q);
3563
3564                qPos.add(userId);
3565
3566                qPos.add(status);
3567
3568                count = (Long)q.uniqueResult();
3569            }
3570            catch (Exception e) {
3571                throw processException(e);
3572            }
3573            finally {
3574                if (count == null) {
3575                    count = Long.valueOf(0);
3576                }
3577
3578                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_S, finderArgs,
3579                    count);
3580
3581                closeSession(session);
3582            }
3583        }
3584
3585        return count.intValue();
3586    }
3587
3588    public int countByR_S(long receiverUserId, int status)
3589        throws SystemException {
3590        Object[] finderArgs = new Object[] { receiverUserId, status };
3591
3592        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_S,
3593                finderArgs, this);
3594
3595        if (count == null) {
3596            StringBundler query = new StringBundler(3);
3597
3598            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3599
3600            query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
3601
3602            query.append(_FINDER_COLUMN_R_S_STATUS_2);
3603
3604            String sql = query.toString();
3605
3606            Session session = null;
3607
3608            try {
3609                session = openSession();
3610
3611                Query q = session.createQuery(sql);
3612
3613                QueryPos qPos = QueryPos.getInstance(q);
3614
3615                qPos.add(receiverUserId);
3616
3617                qPos.add(status);
3618
3619                count = (Long)q.uniqueResult();
3620            }
3621            catch (Exception e) {
3622                throw processException(e);
3623            }
3624            finally {
3625                if (count == null) {
3626                    count = Long.valueOf(0);
3627                }
3628
3629                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_S, finderArgs,
3630                    count);
3631
3632                closeSession(session);
3633            }
3634        }
3635
3636        return count.intValue();
3637    }
3638
3639    public int countByU_C_C_T_R(long userId, long classNameId, long classPK,
3640        int type, long receiverUserId) throws SystemException {
3641        Object[] finderArgs = new Object[] {
3642                userId, classNameId, classPK, type, receiverUserId
3643            };
3644
3645        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_T_R,
3646                finderArgs, this);
3647
3648        if (count == null) {
3649            StringBundler query = new StringBundler(6);
3650
3651            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3652
3653            query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
3654
3655            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
3656
3657            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
3658
3659            query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
3660
3661            query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
3662
3663            String sql = query.toString();
3664
3665            Session session = null;
3666
3667            try {
3668                session = openSession();
3669
3670                Query q = session.createQuery(sql);
3671
3672                QueryPos qPos = QueryPos.getInstance(q);
3673
3674                qPos.add(userId);
3675
3676                qPos.add(classNameId);
3677
3678                qPos.add(classPK);
3679
3680                qPos.add(type);
3681
3682                qPos.add(receiverUserId);
3683
3684                count = (Long)q.uniqueResult();
3685            }
3686            catch (Exception e) {
3687                throw processException(e);
3688            }
3689            finally {
3690                if (count == null) {
3691                    count = Long.valueOf(0);
3692                }
3693
3694                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R,
3695                    finderArgs, count);
3696
3697                closeSession(session);
3698            }
3699        }
3700
3701        return count.intValue();
3702    }
3703
3704    public int countByU_C_C_T_S(long userId, long classNameId, long classPK,
3705        int type, int status) throws SystemException {
3706        Object[] finderArgs = new Object[] {
3707                userId, classNameId, classPK, type, status
3708            };
3709
3710        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
3711                finderArgs, this);
3712
3713        if (count == null) {
3714            StringBundler query = new StringBundler(6);
3715
3716            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3717
3718            query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
3719
3720            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
3721
3722            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
3723
3724            query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
3725
3726            query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
3727
3728            String sql = query.toString();
3729
3730            Session session = null;
3731
3732            try {
3733                session = openSession();
3734
3735                Query q = session.createQuery(sql);
3736
3737                QueryPos qPos = QueryPos.getInstance(q);
3738
3739                qPos.add(userId);
3740
3741                qPos.add(classNameId);
3742
3743                qPos.add(classPK);
3744
3745                qPos.add(type);
3746
3747                qPos.add(status);
3748
3749                count = (Long)q.uniqueResult();
3750            }
3751            catch (Exception e) {
3752                throw processException(e);
3753            }
3754            finally {
3755                if (count == null) {
3756                    count = Long.valueOf(0);
3757                }
3758
3759                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
3760                    finderArgs, count);
3761
3762                closeSession(session);
3763            }
3764        }
3765
3766        return count.intValue();
3767    }
3768
3769    public int countByC_C_T_R_S(long classNameId, long classPK, int type,
3770        long receiverUserId, int status) throws SystemException {
3771        Object[] finderArgs = new Object[] {
3772                classNameId, classPK, type, receiverUserId, status
3773            };
3774
3775        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
3776                finderArgs, this);
3777
3778        if (count == null) {
3779            StringBundler query = new StringBundler(6);
3780
3781            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3782
3783            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
3784
3785            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
3786
3787            query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
3788
3789            query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
3790
3791            query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
3792
3793            String sql = query.toString();
3794
3795            Session session = null;
3796
3797            try {
3798                session = openSession();
3799
3800                Query q = session.createQuery(sql);
3801
3802                QueryPos qPos = QueryPos.getInstance(q);
3803
3804                qPos.add(classNameId);
3805
3806                qPos.add(classPK);
3807
3808                qPos.add(type);
3809
3810                qPos.add(receiverUserId);
3811
3812                qPos.add(status);
3813
3814                count = (Long)q.uniqueResult();
3815            }
3816            catch (Exception e) {
3817                throw processException(e);
3818            }
3819            finally {
3820                if (count == null) {
3821                    count = Long.valueOf(0);
3822                }
3823
3824                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
3825                    finderArgs, count);
3826
3827                closeSession(session);
3828            }
3829        }
3830
3831        return count.intValue();
3832    }
3833
3834    public int countAll() throws SystemException {
3835        Object[] finderArgs = new Object[0];
3836
3837        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3838                finderArgs, this);
3839
3840        if (count == null) {
3841            Session session = null;
3842
3843            try {
3844                session = openSession();
3845
3846                Query q = session.createQuery(_SQL_COUNT_SOCIALREQUEST);
3847
3848                count = (Long)q.uniqueResult();
3849            }
3850            catch (Exception e) {
3851                throw processException(e);
3852            }
3853            finally {
3854                if (count == null) {
3855                    count = Long.valueOf(0);
3856                }
3857
3858                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3859                    count);
3860
3861                closeSession(session);
3862            }
3863        }
3864
3865        return count.intValue();
3866    }
3867
3868    public void afterPropertiesSet() {
3869        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3870                    com.liferay.portal.util.PropsUtil.get(
3871                        "value.object.listener.com.liferay.portlet.social.model.SocialRequest")));
3872
3873        if (listenerClassNames.length > 0) {
3874            try {
3875                List<ModelListener<SocialRequest>> listenersList = new ArrayList<ModelListener<SocialRequest>>();
3876
3877                for (String listenerClassName : listenerClassNames) {
3878                    listenersList.add((ModelListener<SocialRequest>)InstanceFactory.newInstance(
3879                            listenerClassName));
3880                }
3881
3882                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3883            }
3884            catch (Exception e) {
3885                _log.error(e);
3886            }
3887        }
3888    }
3889
3890    public void destroy() {
3891        EntityCacheUtil.removeCache(SocialRequestImpl.class.getName());
3892        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3893        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3894    }
3895
3896    @BeanReference(type = SocialActivityPersistence.class)
3897    protected SocialActivityPersistence socialActivityPersistence;
3898    @BeanReference(type = SocialRelationPersistence.class)
3899    protected SocialRelationPersistence socialRelationPersistence;
3900    @BeanReference(type = SocialRequestPersistence.class)
3901    protected SocialRequestPersistence socialRequestPersistence;
3902    @BeanReference(type = ResourcePersistence.class)
3903    protected ResourcePersistence resourcePersistence;
3904    @BeanReference(type = UserPersistence.class)
3905    protected UserPersistence userPersistence;
3906    private static final String _SQL_SELECT_SOCIALREQUEST = "SELECT socialRequest FROM SocialRequest socialRequest";
3907    private static final String _SQL_SELECT_SOCIALREQUEST_WHERE = "SELECT socialRequest FROM SocialRequest socialRequest WHERE ";
3908    private static final String _SQL_COUNT_SOCIALREQUEST = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest";
3909    private static final String _SQL_COUNT_SOCIALREQUEST_WHERE = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest WHERE ";
3910    private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRequest.uuid IS NULL";
3911    private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRequest.uuid = ?";
3912    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = ?)";
3913    private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "socialRequest.uuid IS NULL AND ";
3914    private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "socialRequest.uuid = ? AND ";
3915    private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = ?) AND ";
3916    private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "socialRequest.groupId = ?";
3917    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRequest.companyId = ?";
3918    private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialRequest.userId = ?";
3919    private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
3920    private static final String _FINDER_COLUMN_U_S_USERID_2 = "socialRequest.userId = ? AND ";
3921    private static final String _FINDER_COLUMN_U_S_STATUS_2 = "socialRequest.status = ?";
3922    private static final String _FINDER_COLUMN_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
3923    private static final String _FINDER_COLUMN_R_S_STATUS_2 = "socialRequest.status = ?";
3924    private static final String _FINDER_COLUMN_U_C_C_T_R_USERID_2 = "socialRequest.userId = ? AND ";
3925    private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
3926    private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSPK_2 = "socialRequest.classPK = ? AND ";
3927    private static final String _FINDER_COLUMN_U_C_C_T_R_TYPE_2 = "socialRequest.type = ? AND ";
3928    private static final String _FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
3929    private static final String _FINDER_COLUMN_U_C_C_T_S_USERID_2 = "socialRequest.userId = ? AND ";
3930    private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
3931    private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
3932    private static final String _FINDER_COLUMN_U_C_C_T_S_TYPE_2 = "socialRequest.type = ? AND ";
3933    private static final String _FINDER_COLUMN_U_C_C_T_S_STATUS_2 = "socialRequest.status = ?";
3934    private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
3935    private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
3936    private static final String _FINDER_COLUMN_C_C_T_R_S_TYPE_2 = "socialRequest.type = ? AND ";
3937    private static final String _FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
3938    private static final String _FINDER_COLUMN_C_C_T_R_S_STATUS_2 = "socialRequest.status = ?";
3939    private static final String _ORDER_BY_ENTITY_ALIAS = "socialRequest.";
3940    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRequest exists with the primary key ";
3941    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRequest exists with the key {";
3942    private static Log _log = LogFactoryUtil.getLog(SocialRequestPersistenceImpl.class);
3943}