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