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