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