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