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