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