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