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