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