001
014
015 package com.liferay.portlet.social.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.BatchSessionUtil;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.social.NoSuchRelationException;
045 import com.liferay.portlet.social.model.SocialRelation;
046 import com.liferay.portlet.social.model.impl.SocialRelationImpl;
047 import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
071 public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
072 implements SocialRelationPersistence {
073 public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075 ".List";
076 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
077 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
078 FINDER_CLASS_NAME_LIST, "findByUuid",
079 new String[] {
080 String.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
086 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
087 FINDER_CLASS_NAME_LIST, "countByUuid",
088 new String[] { String.class.getName() });
089 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
090 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
091 FINDER_CLASS_NAME_LIST, "findByCompanyId",
092 new String[] {
093 Long.class.getName(),
094
095 "java.lang.Integer", "java.lang.Integer",
096 "com.liferay.portal.kernel.util.OrderByComparator"
097 });
098 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
099 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
100 FINDER_CLASS_NAME_LIST, "countByCompanyId",
101 new String[] { Long.class.getName() });
102 public static final FinderPath FINDER_PATH_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
103 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
104 FINDER_CLASS_NAME_LIST, "findByUserId1",
105 new String[] {
106 Long.class.getName(),
107
108 "java.lang.Integer", "java.lang.Integer",
109 "com.liferay.portal.kernel.util.OrderByComparator"
110 });
111 public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
112 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
113 FINDER_CLASS_NAME_LIST, "countByUserId1",
114 new String[] { Long.class.getName() });
115 public static final FinderPath FINDER_PATH_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
116 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
117 FINDER_CLASS_NAME_LIST, "findByUserId2",
118 new String[] {
119 Long.class.getName(),
120
121 "java.lang.Integer", "java.lang.Integer",
122 "com.liferay.portal.kernel.util.OrderByComparator"
123 });
124 public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
125 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
126 FINDER_CLASS_NAME_LIST, "countByUserId2",
127 new String[] { Long.class.getName() });
128 public static final FinderPath FINDER_PATH_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
129 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
130 FINDER_CLASS_NAME_LIST, "findByType",
131 new String[] {
132 Integer.class.getName(),
133
134 "java.lang.Integer", "java.lang.Integer",
135 "com.liferay.portal.kernel.util.OrderByComparator"
136 });
137 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
138 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
139 FINDER_CLASS_NAME_LIST, "countByType",
140 new String[] { Integer.class.getName() });
141 public static final FinderPath FINDER_PATH_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
142 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
143 FINDER_CLASS_NAME_LIST, "findByC_T",
144 new String[] {
145 Long.class.getName(), Integer.class.getName(),
146
147 "java.lang.Integer", "java.lang.Integer",
148 "com.liferay.portal.kernel.util.OrderByComparator"
149 });
150 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
151 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
152 FINDER_CLASS_NAME_LIST, "countByC_T",
153 new String[] { Long.class.getName(), Integer.class.getName() });
154 public static final FinderPath FINDER_PATH_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
155 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
156 FINDER_CLASS_NAME_LIST, "findByU1_T",
157 new String[] {
158 Long.class.getName(), Integer.class.getName(),
159
160 "java.lang.Integer", "java.lang.Integer",
161 "com.liferay.portal.kernel.util.OrderByComparator"
162 });
163 public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
164 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
165 FINDER_CLASS_NAME_LIST, "countByU1_T",
166 new String[] { Long.class.getName(), Integer.class.getName() });
167 public static final FinderPath FINDER_PATH_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
168 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
169 FINDER_CLASS_NAME_LIST, "findByU2_T",
170 new String[] {
171 Long.class.getName(), Integer.class.getName(),
172
173 "java.lang.Integer", "java.lang.Integer",
174 "com.liferay.portal.kernel.util.OrderByComparator"
175 });
176 public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
177 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
178 FINDER_CLASS_NAME_LIST, "countByU2_T",
179 new String[] { Long.class.getName(), Integer.class.getName() });
180 public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
181 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
182 FINDER_CLASS_NAME_ENTITY, "fetchByU1_U2_T",
183 new String[] {
184 Long.class.getName(), Long.class.getName(),
185 Integer.class.getName()
186 });
187 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
188 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
189 FINDER_CLASS_NAME_LIST, "countByU1_U2_T",
190 new String[] {
191 Long.class.getName(), Long.class.getName(),
192 Integer.class.getName()
193 });
194 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
195 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
196 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
197 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
198 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
199 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
200
201
206 public void cacheResult(SocialRelation socialRelation) {
207 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
208 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
209 socialRelation);
210
211 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
212 new Object[] {
213 new Long(socialRelation.getUserId1()),
214 new Long(socialRelation.getUserId2()),
215 new Integer(socialRelation.getType())
216 }, socialRelation);
217 }
218
219
224 public void cacheResult(List<SocialRelation> socialRelations) {
225 for (SocialRelation socialRelation : socialRelations) {
226 if (EntityCacheUtil.getResult(
227 SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
228 SocialRelationImpl.class,
229 socialRelation.getPrimaryKey(), this) == null) {
230 cacheResult(socialRelation);
231 }
232 }
233 }
234
235
242 public void clearCache() {
243 CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
244 EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
245 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
246 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
247 }
248
249
256 public void clearCache(SocialRelation socialRelation) {
257 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
258 SocialRelationImpl.class, socialRelation.getPrimaryKey());
259
260 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
261 new Object[] {
262 new Long(socialRelation.getUserId1()),
263 new Long(socialRelation.getUserId2()),
264 new Integer(socialRelation.getType())
265 });
266 }
267
268
274 public SocialRelation create(long relationId) {
275 SocialRelation socialRelation = new SocialRelationImpl();
276
277 socialRelation.setNew(true);
278 socialRelation.setPrimaryKey(relationId);
279
280 String uuid = PortalUUIDUtil.generate();
281
282 socialRelation.setUuid(uuid);
283
284 return socialRelation;
285 }
286
287
295 public SocialRelation remove(Serializable primaryKey)
296 throws NoSuchModelException, SystemException {
297 return remove(((Long)primaryKey).longValue());
298 }
299
300
308 public SocialRelation remove(long relationId)
309 throws NoSuchRelationException, SystemException {
310 Session session = null;
311
312 try {
313 session = openSession();
314
315 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
316 new Long(relationId));
317
318 if (socialRelation == null) {
319 if (_log.isWarnEnabled()) {
320 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
321 }
322
323 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
324 relationId);
325 }
326
327 return remove(socialRelation);
328 }
329 catch (NoSuchRelationException nsee) {
330 throw nsee;
331 }
332 catch (Exception e) {
333 throw processException(e);
334 }
335 finally {
336 closeSession(session);
337 }
338 }
339
340 protected SocialRelation removeImpl(SocialRelation socialRelation)
341 throws SystemException {
342 socialRelation = toUnwrappedModel(socialRelation);
343
344 Session session = null;
345
346 try {
347 session = openSession();
348
349 BatchSessionUtil.delete(session, socialRelation);
350 }
351 catch (Exception e) {
352 throw processException(e);
353 }
354 finally {
355 closeSession(session);
356 }
357
358 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
359
360 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
361
362 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
363 new Object[] {
364 new Long(socialRelationModelImpl.getUserId1()),
365 new Long(socialRelationModelImpl.getUserId2()),
366 new Integer(socialRelationModelImpl.getType())
367 });
368
369 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
370 SocialRelationImpl.class, socialRelation.getPrimaryKey());
371
372 return socialRelation;
373 }
374
375 public SocialRelation updateImpl(
376 com.liferay.portlet.social.model.SocialRelation socialRelation,
377 boolean merge) throws SystemException {
378 socialRelation = toUnwrappedModel(socialRelation);
379
380 boolean isNew = socialRelation.isNew();
381
382 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
383
384 if (Validator.isNull(socialRelation.getUuid())) {
385 String uuid = PortalUUIDUtil.generate();
386
387 socialRelation.setUuid(uuid);
388 }
389
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 BatchSessionUtil.update(session, socialRelation, merge);
396
397 socialRelation.setNew(false);
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405
406 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
407
408 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
409 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
410 socialRelation);
411
412 if (!isNew &&
413 ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
414 (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
415 (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
416 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
417 new Object[] {
418 new Long(socialRelationModelImpl.getOriginalUserId1()),
419 new Long(socialRelationModelImpl.getOriginalUserId2()),
420 new Integer(socialRelationModelImpl.getOriginalType())
421 });
422 }
423
424 if (isNew ||
425 ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
426 (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
427 (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
429 new Object[] {
430 new Long(socialRelation.getUserId1()),
431 new Long(socialRelation.getUserId2()),
432 new Integer(socialRelation.getType())
433 }, socialRelation);
434 }
435
436 return socialRelation;
437 }
438
439 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
440 if (socialRelation instanceof SocialRelationImpl) {
441 return socialRelation;
442 }
443
444 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
445
446 socialRelationImpl.setNew(socialRelation.isNew());
447 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
448
449 socialRelationImpl.setUuid(socialRelation.getUuid());
450 socialRelationImpl.setRelationId(socialRelation.getRelationId());
451 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
452 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
453 socialRelationImpl.setUserId1(socialRelation.getUserId1());
454 socialRelationImpl.setUserId2(socialRelation.getUserId2());
455 socialRelationImpl.setType(socialRelation.getType());
456
457 return socialRelationImpl;
458 }
459
460
468 public SocialRelation findByPrimaryKey(Serializable primaryKey)
469 throws NoSuchModelException, SystemException {
470 return findByPrimaryKey(((Long)primaryKey).longValue());
471 }
472
473
481 public SocialRelation findByPrimaryKey(long relationId)
482 throws NoSuchRelationException, SystemException {
483 SocialRelation socialRelation = fetchByPrimaryKey(relationId);
484
485 if (socialRelation == null) {
486 if (_log.isWarnEnabled()) {
487 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
488 }
489
490 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
491 relationId);
492 }
493
494 return socialRelation;
495 }
496
497
504 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
505 throws SystemException {
506 return fetchByPrimaryKey(((Long)primaryKey).longValue());
507 }
508
509
516 public SocialRelation fetchByPrimaryKey(long relationId)
517 throws SystemException {
518 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
519 SocialRelationImpl.class, relationId, this);
520
521 if (socialRelation == null) {
522 Session session = null;
523
524 try {
525 session = openSession();
526
527 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
528 new Long(relationId));
529 }
530 catch (Exception e) {
531 throw processException(e);
532 }
533 finally {
534 if (socialRelation != null) {
535 cacheResult(socialRelation);
536 }
537
538 closeSession(session);
539 }
540 }
541
542 return socialRelation;
543 }
544
545
552 public List<SocialRelation> findByUuid(String uuid)
553 throws SystemException {
554 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
555 }
556
557
570 public List<SocialRelation> findByUuid(String uuid, int start, int end)
571 throws SystemException {
572 return findByUuid(uuid, start, end, null);
573 }
574
575
589 public List<SocialRelation> findByUuid(String uuid, int start, int end,
590 OrderByComparator orderByComparator) throws SystemException {
591 Object[] finderArgs = new Object[] {
592 uuid,
593
594 String.valueOf(start), String.valueOf(end),
595 String.valueOf(orderByComparator)
596 };
597
598 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
599 finderArgs, this);
600
601 if (list == null) {
602 StringBundler query = null;
603
604 if (orderByComparator != null) {
605 query = new StringBundler(3 +
606 (orderByComparator.getOrderByFields().length * 3));
607 }
608 else {
609 query = new StringBundler(2);
610 }
611
612 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
613
614 if (uuid == null) {
615 query.append(_FINDER_COLUMN_UUID_UUID_1);
616 }
617 else {
618 if (uuid.equals(StringPool.BLANK)) {
619 query.append(_FINDER_COLUMN_UUID_UUID_3);
620 }
621 else {
622 query.append(_FINDER_COLUMN_UUID_UUID_2);
623 }
624 }
625
626 if (orderByComparator != null) {
627 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
628 orderByComparator);
629 }
630
631 String sql = query.toString();
632
633 Session session = null;
634
635 try {
636 session = openSession();
637
638 Query q = session.createQuery(sql);
639
640 QueryPos qPos = QueryPos.getInstance(q);
641
642 if (uuid != null) {
643 qPos.add(uuid);
644 }
645
646 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
647 start, end);
648 }
649 catch (Exception e) {
650 throw processException(e);
651 }
652 finally {
653 if (list == null) {
654 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
655 finderArgs);
656 }
657 else {
658 cacheResult(list);
659
660 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
661 finderArgs, list);
662 }
663
664 closeSession(session);
665 }
666 }
667
668 return list;
669 }
670
671
684 public SocialRelation findByUuid_First(String uuid,
685 OrderByComparator orderByComparator)
686 throws NoSuchRelationException, SystemException {
687 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
688
689 if (list.isEmpty()) {
690 StringBundler msg = new StringBundler(4);
691
692 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
693
694 msg.append("uuid=");
695 msg.append(uuid);
696
697 msg.append(StringPool.CLOSE_CURLY_BRACE);
698
699 throw new NoSuchRelationException(msg.toString());
700 }
701 else {
702 return list.get(0);
703 }
704 }
705
706
719 public SocialRelation findByUuid_Last(String uuid,
720 OrderByComparator orderByComparator)
721 throws NoSuchRelationException, SystemException {
722 int count = countByUuid(uuid);
723
724 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
725 orderByComparator);
726
727 if (list.isEmpty()) {
728 StringBundler msg = new StringBundler(4);
729
730 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
731
732 msg.append("uuid=");
733 msg.append(uuid);
734
735 msg.append(StringPool.CLOSE_CURLY_BRACE);
736
737 throw new NoSuchRelationException(msg.toString());
738 }
739 else {
740 return list.get(0);
741 }
742 }
743
744
758 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
759 String uuid, OrderByComparator orderByComparator)
760 throws NoSuchRelationException, SystemException {
761 SocialRelation socialRelation = findByPrimaryKey(relationId);
762
763 Session session = null;
764
765 try {
766 session = openSession();
767
768 SocialRelation[] array = new SocialRelationImpl[3];
769
770 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
771 orderByComparator, true);
772
773 array[1] = socialRelation;
774
775 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
776 orderByComparator, false);
777
778 return array;
779 }
780 catch (Exception e) {
781 throw processException(e);
782 }
783 finally {
784 closeSession(session);
785 }
786 }
787
788 protected SocialRelation getByUuid_PrevAndNext(Session session,
789 SocialRelation socialRelation, String uuid,
790 OrderByComparator orderByComparator, boolean previous) {
791 StringBundler query = null;
792
793 if (orderByComparator != null) {
794 query = new StringBundler(6 +
795 (orderByComparator.getOrderByFields().length * 6));
796 }
797 else {
798 query = new StringBundler(3);
799 }
800
801 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
802
803 if (uuid == null) {
804 query.append(_FINDER_COLUMN_UUID_UUID_1);
805 }
806 else {
807 if (uuid.equals(StringPool.BLANK)) {
808 query.append(_FINDER_COLUMN_UUID_UUID_3);
809 }
810 else {
811 query.append(_FINDER_COLUMN_UUID_UUID_2);
812 }
813 }
814
815 if (orderByComparator != null) {
816 String[] orderByFields = orderByComparator.getOrderByFields();
817
818 if (orderByFields.length > 0) {
819 query.append(WHERE_AND);
820 }
821
822 for (int i = 0; i < orderByFields.length; i++) {
823 query.append(_ORDER_BY_ENTITY_ALIAS);
824 query.append(orderByFields[i]);
825
826 if ((i + 1) < orderByFields.length) {
827 if (orderByComparator.isAscending() ^ previous) {
828 query.append(WHERE_GREATER_THAN_HAS_NEXT);
829 }
830 else {
831 query.append(WHERE_LESSER_THAN_HAS_NEXT);
832 }
833 }
834 else {
835 if (orderByComparator.isAscending() ^ previous) {
836 query.append(WHERE_GREATER_THAN);
837 }
838 else {
839 query.append(WHERE_LESSER_THAN);
840 }
841 }
842 }
843
844 query.append(ORDER_BY_CLAUSE);
845
846 for (int i = 0; i < orderByFields.length; i++) {
847 query.append(_ORDER_BY_ENTITY_ALIAS);
848 query.append(orderByFields[i]);
849
850 if ((i + 1) < orderByFields.length) {
851 if (orderByComparator.isAscending() ^ previous) {
852 query.append(ORDER_BY_ASC_HAS_NEXT);
853 }
854 else {
855 query.append(ORDER_BY_DESC_HAS_NEXT);
856 }
857 }
858 else {
859 if (orderByComparator.isAscending() ^ previous) {
860 query.append(ORDER_BY_ASC);
861 }
862 else {
863 query.append(ORDER_BY_DESC);
864 }
865 }
866 }
867 }
868
869 String sql = query.toString();
870
871 Query q = session.createQuery(sql);
872
873 q.setFirstResult(0);
874 q.setMaxResults(2);
875
876 QueryPos qPos = QueryPos.getInstance(q);
877
878 if (uuid != null) {
879 qPos.add(uuid);
880 }
881
882 if (orderByComparator != null) {
883 Object[] values = orderByComparator.getOrderByValues(socialRelation);
884
885 for (Object value : values) {
886 qPos.add(value);
887 }
888 }
889
890 List<SocialRelation> list = q.list();
891
892 if (list.size() == 2) {
893 return list.get(1);
894 }
895 else {
896 return null;
897 }
898 }
899
900
907 public List<SocialRelation> findByCompanyId(long companyId)
908 throws SystemException {
909 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
910 null);
911 }
912
913
926 public List<SocialRelation> findByCompanyId(long companyId, int start,
927 int end) throws SystemException {
928 return findByCompanyId(companyId, start, end, null);
929 }
930
931
945 public List<SocialRelation> findByCompanyId(long companyId, int start,
946 int end, OrderByComparator orderByComparator) throws SystemException {
947 Object[] finderArgs = new Object[] {
948 companyId,
949
950 String.valueOf(start), String.valueOf(end),
951 String.valueOf(orderByComparator)
952 };
953
954 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
955 finderArgs, this);
956
957 if (list == null) {
958 StringBundler query = null;
959
960 if (orderByComparator != null) {
961 query = new StringBundler(3 +
962 (orderByComparator.getOrderByFields().length * 3));
963 }
964 else {
965 query = new StringBundler(2);
966 }
967
968 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
969
970 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
971
972 if (orderByComparator != null) {
973 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
974 orderByComparator);
975 }
976
977 String sql = query.toString();
978
979 Session session = null;
980
981 try {
982 session = openSession();
983
984 Query q = session.createQuery(sql);
985
986 QueryPos qPos = QueryPos.getInstance(q);
987
988 qPos.add(companyId);
989
990 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
991 start, end);
992 }
993 catch (Exception e) {
994 throw processException(e);
995 }
996 finally {
997 if (list == null) {
998 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
999 finderArgs);
1000 }
1001 else {
1002 cacheResult(list);
1003
1004 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1005 finderArgs, list);
1006 }
1007
1008 closeSession(session);
1009 }
1010 }
1011
1012 return list;
1013 }
1014
1015
1028 public SocialRelation findByCompanyId_First(long companyId,
1029 OrderByComparator orderByComparator)
1030 throws NoSuchRelationException, SystemException {
1031 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1032 orderByComparator);
1033
1034 if (list.isEmpty()) {
1035 StringBundler msg = new StringBundler(4);
1036
1037 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1038
1039 msg.append("companyId=");
1040 msg.append(companyId);
1041
1042 msg.append(StringPool.CLOSE_CURLY_BRACE);
1043
1044 throw new NoSuchRelationException(msg.toString());
1045 }
1046 else {
1047 return list.get(0);
1048 }
1049 }
1050
1051
1064 public SocialRelation findByCompanyId_Last(long companyId,
1065 OrderByComparator orderByComparator)
1066 throws NoSuchRelationException, SystemException {
1067 int count = countByCompanyId(companyId);
1068
1069 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1070 count, orderByComparator);
1071
1072 if (list.isEmpty()) {
1073 StringBundler msg = new StringBundler(4);
1074
1075 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1076
1077 msg.append("companyId=");
1078 msg.append(companyId);
1079
1080 msg.append(StringPool.CLOSE_CURLY_BRACE);
1081
1082 throw new NoSuchRelationException(msg.toString());
1083 }
1084 else {
1085 return list.get(0);
1086 }
1087 }
1088
1089
1103 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1104 long companyId, OrderByComparator orderByComparator)
1105 throws NoSuchRelationException, SystemException {
1106 SocialRelation socialRelation = findByPrimaryKey(relationId);
1107
1108 Session session = null;
1109
1110 try {
1111 session = openSession();
1112
1113 SocialRelation[] array = new SocialRelationImpl[3];
1114
1115 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1116 companyId, orderByComparator, true);
1117
1118 array[1] = socialRelation;
1119
1120 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1121 companyId, orderByComparator, false);
1122
1123 return array;
1124 }
1125 catch (Exception e) {
1126 throw processException(e);
1127 }
1128 finally {
1129 closeSession(session);
1130 }
1131 }
1132
1133 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1134 SocialRelation socialRelation, long companyId,
1135 OrderByComparator orderByComparator, boolean previous) {
1136 StringBundler query = null;
1137
1138 if (orderByComparator != null) {
1139 query = new StringBundler(6 +
1140 (orderByComparator.getOrderByFields().length * 6));
1141 }
1142 else {
1143 query = new StringBundler(3);
1144 }
1145
1146 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1147
1148 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1149
1150 if (orderByComparator != null) {
1151 String[] orderByFields = orderByComparator.getOrderByFields();
1152
1153 if (orderByFields.length > 0) {
1154 query.append(WHERE_AND);
1155 }
1156
1157 for (int i = 0; i < orderByFields.length; i++) {
1158 query.append(_ORDER_BY_ENTITY_ALIAS);
1159 query.append(orderByFields[i]);
1160
1161 if ((i + 1) < orderByFields.length) {
1162 if (orderByComparator.isAscending() ^ previous) {
1163 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1164 }
1165 else {
1166 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1167 }
1168 }
1169 else {
1170 if (orderByComparator.isAscending() ^ previous) {
1171 query.append(WHERE_GREATER_THAN);
1172 }
1173 else {
1174 query.append(WHERE_LESSER_THAN);
1175 }
1176 }
1177 }
1178
1179 query.append(ORDER_BY_CLAUSE);
1180
1181 for (int i = 0; i < orderByFields.length; i++) {
1182 query.append(_ORDER_BY_ENTITY_ALIAS);
1183 query.append(orderByFields[i]);
1184
1185 if ((i + 1) < orderByFields.length) {
1186 if (orderByComparator.isAscending() ^ previous) {
1187 query.append(ORDER_BY_ASC_HAS_NEXT);
1188 }
1189 else {
1190 query.append(ORDER_BY_DESC_HAS_NEXT);
1191 }
1192 }
1193 else {
1194 if (orderByComparator.isAscending() ^ previous) {
1195 query.append(ORDER_BY_ASC);
1196 }
1197 else {
1198 query.append(ORDER_BY_DESC);
1199 }
1200 }
1201 }
1202 }
1203
1204 String sql = query.toString();
1205
1206 Query q = session.createQuery(sql);
1207
1208 q.setFirstResult(0);
1209 q.setMaxResults(2);
1210
1211 QueryPos qPos = QueryPos.getInstance(q);
1212
1213 qPos.add(companyId);
1214
1215 if (orderByComparator != null) {
1216 Object[] values = orderByComparator.getOrderByValues(socialRelation);
1217
1218 for (Object value : values) {
1219 qPos.add(value);
1220 }
1221 }
1222
1223 List<SocialRelation> list = q.list();
1224
1225 if (list.size() == 2) {
1226 return list.get(1);
1227 }
1228 else {
1229 return null;
1230 }
1231 }
1232
1233
1240 public List<SocialRelation> findByUserId1(long userId1)
1241 throws SystemException {
1242 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1243 }
1244
1245
1258 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1259 throws SystemException {
1260 return findByUserId1(userId1, start, end, null);
1261 }
1262
1263
1277 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1278 OrderByComparator orderByComparator) throws SystemException {
1279 Object[] finderArgs = new Object[] {
1280 userId1,
1281
1282 String.valueOf(start), String.valueOf(end),
1283 String.valueOf(orderByComparator)
1284 };
1285
1286 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID1,
1287 finderArgs, this);
1288
1289 if (list == null) {
1290 StringBundler query = null;
1291
1292 if (orderByComparator != null) {
1293 query = new StringBundler(3 +
1294 (orderByComparator.getOrderByFields().length * 3));
1295 }
1296 else {
1297 query = new StringBundler(2);
1298 }
1299
1300 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1301
1302 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1303
1304 if (orderByComparator != null) {
1305 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1306 orderByComparator);
1307 }
1308
1309 String sql = query.toString();
1310
1311 Session session = null;
1312
1313 try {
1314 session = openSession();
1315
1316 Query q = session.createQuery(sql);
1317
1318 QueryPos qPos = QueryPos.getInstance(q);
1319
1320 qPos.add(userId1);
1321
1322 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1323 start, end);
1324 }
1325 catch (Exception e) {
1326 throw processException(e);
1327 }
1328 finally {
1329 if (list == null) {
1330 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID1,
1331 finderArgs);
1332 }
1333 else {
1334 cacheResult(list);
1335
1336 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID1,
1337 finderArgs, list);
1338 }
1339
1340 closeSession(session);
1341 }
1342 }
1343
1344 return list;
1345 }
1346
1347
1360 public SocialRelation findByUserId1_First(long userId1,
1361 OrderByComparator orderByComparator)
1362 throws NoSuchRelationException, SystemException {
1363 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1364 orderByComparator);
1365
1366 if (list.isEmpty()) {
1367 StringBundler msg = new StringBundler(4);
1368
1369 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1370
1371 msg.append("userId1=");
1372 msg.append(userId1);
1373
1374 msg.append(StringPool.CLOSE_CURLY_BRACE);
1375
1376 throw new NoSuchRelationException(msg.toString());
1377 }
1378 else {
1379 return list.get(0);
1380 }
1381 }
1382
1383
1396 public SocialRelation findByUserId1_Last(long userId1,
1397 OrderByComparator orderByComparator)
1398 throws NoSuchRelationException, SystemException {
1399 int count = countByUserId1(userId1);
1400
1401 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1402 orderByComparator);
1403
1404 if (list.isEmpty()) {
1405 StringBundler msg = new StringBundler(4);
1406
1407 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1408
1409 msg.append("userId1=");
1410 msg.append(userId1);
1411
1412 msg.append(StringPool.CLOSE_CURLY_BRACE);
1413
1414 throw new NoSuchRelationException(msg.toString());
1415 }
1416 else {
1417 return list.get(0);
1418 }
1419 }
1420
1421
1435 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1436 long userId1, OrderByComparator orderByComparator)
1437 throws NoSuchRelationException, SystemException {
1438 SocialRelation socialRelation = findByPrimaryKey(relationId);
1439
1440 Session session = null;
1441
1442 try {
1443 session = openSession();
1444
1445 SocialRelation[] array = new SocialRelationImpl[3];
1446
1447 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1448 userId1, orderByComparator, true);
1449
1450 array[1] = socialRelation;
1451
1452 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1453 userId1, orderByComparator, false);
1454
1455 return array;
1456 }
1457 catch (Exception e) {
1458 throw processException(e);
1459 }
1460 finally {
1461 closeSession(session);
1462 }
1463 }
1464
1465 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1466 SocialRelation socialRelation, long userId1,
1467 OrderByComparator orderByComparator, boolean previous) {
1468 StringBundler query = null;
1469
1470 if (orderByComparator != null) {
1471 query = new StringBundler(6 +
1472 (orderByComparator.getOrderByFields().length * 6));
1473 }
1474 else {
1475 query = new StringBundler(3);
1476 }
1477
1478 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1479
1480 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1481
1482 if (orderByComparator != null) {
1483 String[] orderByFields = orderByComparator.getOrderByFields();
1484
1485 if (orderByFields.length > 0) {
1486 query.append(WHERE_AND);
1487 }
1488
1489 for (int i = 0; i < orderByFields.length; i++) {
1490 query.append(_ORDER_BY_ENTITY_ALIAS);
1491 query.append(orderByFields[i]);
1492
1493 if ((i + 1) < orderByFields.length) {
1494 if (orderByComparator.isAscending() ^ previous) {
1495 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1496 }
1497 else {
1498 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1499 }
1500 }
1501 else {
1502 if (orderByComparator.isAscending() ^ previous) {
1503 query.append(WHERE_GREATER_THAN);
1504 }
1505 else {
1506 query.append(WHERE_LESSER_THAN);
1507 }
1508 }
1509 }
1510
1511 query.append(ORDER_BY_CLAUSE);
1512
1513 for (int i = 0; i < orderByFields.length; i++) {
1514 query.append(_ORDER_BY_ENTITY_ALIAS);
1515 query.append(orderByFields[i]);
1516
1517 if ((i + 1) < orderByFields.length) {
1518 if (orderByComparator.isAscending() ^ previous) {
1519 query.append(ORDER_BY_ASC_HAS_NEXT);
1520 }
1521 else {
1522 query.append(ORDER_BY_DESC_HAS_NEXT);
1523 }
1524 }
1525 else {
1526 if (orderByComparator.isAscending() ^ previous) {
1527 query.append(ORDER_BY_ASC);
1528 }
1529 else {
1530 query.append(ORDER_BY_DESC);
1531 }
1532 }
1533 }
1534 }
1535
1536 String sql = query.toString();
1537
1538 Query q = session.createQuery(sql);
1539
1540 q.setFirstResult(0);
1541 q.setMaxResults(2);
1542
1543 QueryPos qPos = QueryPos.getInstance(q);
1544
1545 qPos.add(userId1);
1546
1547 if (orderByComparator != null) {
1548 Object[] values = orderByComparator.getOrderByValues(socialRelation);
1549
1550 for (Object value : values) {
1551 qPos.add(value);
1552 }
1553 }
1554
1555 List<SocialRelation> list = q.list();
1556
1557 if (list.size() == 2) {
1558 return list.get(1);
1559 }
1560 else {
1561 return null;
1562 }
1563 }
1564
1565
1572 public List<SocialRelation> findByUserId2(long userId2)
1573 throws SystemException {
1574 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1575 }
1576
1577
1590 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
1591 throws SystemException {
1592 return findByUserId2(userId2, start, end, null);
1593 }
1594
1595
1609 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
1610 OrderByComparator orderByComparator) throws SystemException {
1611 Object[] finderArgs = new Object[] {
1612 userId2,
1613
1614 String.valueOf(start), String.valueOf(end),
1615 String.valueOf(orderByComparator)
1616 };
1617
1618 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID2,
1619 finderArgs, this);
1620
1621 if (list == null) {
1622 StringBundler query = null;
1623
1624 if (orderByComparator != null) {
1625 query = new StringBundler(3 +
1626 (orderByComparator.getOrderByFields().length * 3));
1627 }
1628 else {
1629 query = new StringBundler(2);
1630 }
1631
1632 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1633
1634 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1635
1636 if (orderByComparator != null) {
1637 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1638 orderByComparator);
1639 }
1640
1641 String sql = query.toString();
1642
1643 Session session = null;
1644
1645 try {
1646 session = openSession();
1647
1648 Query q = session.createQuery(sql);
1649
1650 QueryPos qPos = QueryPos.getInstance(q);
1651
1652 qPos.add(userId2);
1653
1654 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1655 start, end);
1656 }
1657 catch (Exception e) {
1658 throw processException(e);
1659 }
1660 finally {
1661 if (list == null) {
1662 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID2,
1663 finderArgs);
1664 }
1665 else {
1666 cacheResult(list);
1667
1668 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID2,
1669 finderArgs, list);
1670 }
1671
1672 closeSession(session);
1673 }
1674 }
1675
1676 return list;
1677 }
1678
1679
1692 public SocialRelation findByUserId2_First(long userId2,
1693 OrderByComparator orderByComparator)
1694 throws NoSuchRelationException, SystemException {
1695 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
1696 orderByComparator);
1697
1698 if (list.isEmpty()) {
1699 StringBundler msg = new StringBundler(4);
1700
1701 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1702
1703 msg.append("userId2=");
1704 msg.append(userId2);
1705
1706 msg.append(StringPool.CLOSE_CURLY_BRACE);
1707
1708 throw new NoSuchRelationException(msg.toString());
1709 }
1710 else {
1711 return list.get(0);
1712 }
1713 }
1714
1715
1728 public SocialRelation findByUserId2_Last(long userId2,
1729 OrderByComparator orderByComparator)
1730 throws NoSuchRelationException, SystemException {
1731 int count = countByUserId2(userId2);
1732
1733 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
1734 orderByComparator);
1735
1736 if (list.isEmpty()) {
1737 StringBundler msg = new StringBundler(4);
1738
1739 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1740
1741 msg.append("userId2=");
1742 msg.append(userId2);
1743
1744 msg.append(StringPool.CLOSE_CURLY_BRACE);
1745
1746 throw new NoSuchRelationException(msg.toString());
1747 }
1748 else {
1749 return list.get(0);
1750 }
1751 }
1752
1753
1767 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
1768 long userId2, OrderByComparator orderByComparator)
1769 throws NoSuchRelationException, SystemException {
1770 SocialRelation socialRelation = findByPrimaryKey(relationId);
1771
1772 Session session = null;
1773
1774 try {
1775 session = openSession();
1776
1777 SocialRelation[] array = new SocialRelationImpl[3];
1778
1779 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
1780 userId2, orderByComparator, true);
1781
1782 array[1] = socialRelation;
1783
1784 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
1785 userId2, orderByComparator, false);
1786
1787 return array;
1788 }
1789 catch (Exception e) {
1790 throw processException(e);
1791 }
1792 finally {
1793 closeSession(session);
1794 }
1795 }
1796
1797 protected SocialRelation getByUserId2_PrevAndNext(Session session,
1798 SocialRelation socialRelation, long userId2,
1799 OrderByComparator orderByComparator, boolean previous) {
1800 StringBundler query = null;
1801
1802 if (orderByComparator != null) {
1803 query = new StringBundler(6 +
1804 (orderByComparator.getOrderByFields().length * 6));
1805 }
1806 else {
1807 query = new StringBundler(3);
1808 }
1809
1810 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1811
1812 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1813
1814 if (orderByComparator != null) {
1815 String[] orderByFields = orderByComparator.getOrderByFields();
1816
1817 if (orderByFields.length > 0) {
1818 query.append(WHERE_AND);
1819 }
1820
1821 for (int i = 0; i < orderByFields.length; i++) {
1822 query.append(_ORDER_BY_ENTITY_ALIAS);
1823 query.append(orderByFields[i]);
1824
1825 if ((i + 1) < orderByFields.length) {
1826 if (orderByComparator.isAscending() ^ previous) {
1827 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1828 }
1829 else {
1830 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1831 }
1832 }
1833 else {
1834 if (orderByComparator.isAscending() ^ previous) {
1835 query.append(WHERE_GREATER_THAN);
1836 }
1837 else {
1838 query.append(WHERE_LESSER_THAN);
1839 }
1840 }
1841 }
1842
1843 query.append(ORDER_BY_CLAUSE);
1844
1845 for (int i = 0; i < orderByFields.length; i++) {
1846 query.append(_ORDER_BY_ENTITY_ALIAS);
1847 query.append(orderByFields[i]);
1848
1849 if ((i + 1) < orderByFields.length) {
1850 if (orderByComparator.isAscending() ^ previous) {
1851 query.append(ORDER_BY_ASC_HAS_NEXT);
1852 }
1853 else {
1854 query.append(ORDER_BY_DESC_HAS_NEXT);
1855 }
1856 }
1857 else {
1858 if (orderByComparator.isAscending() ^ previous) {
1859 query.append(ORDER_BY_ASC);
1860 }
1861 else {
1862 query.append(ORDER_BY_DESC);
1863 }
1864 }
1865 }
1866 }
1867
1868 String sql = query.toString();
1869
1870 Query q = session.createQuery(sql);
1871
1872 q.setFirstResult(0);
1873 q.setMaxResults(2);
1874
1875 QueryPos qPos = QueryPos.getInstance(q);
1876
1877 qPos.add(userId2);
1878
1879 if (orderByComparator != null) {
1880 Object[] values = orderByComparator.getOrderByValues(socialRelation);
1881
1882 for (Object value : values) {
1883 qPos.add(value);
1884 }
1885 }
1886
1887 List<SocialRelation> list = q.list();
1888
1889 if (list.size() == 2) {
1890 return list.get(1);
1891 }
1892 else {
1893 return null;
1894 }
1895 }
1896
1897
1904 public List<SocialRelation> findByType(int type) throws SystemException {
1905 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1906 }
1907
1908
1921 public List<SocialRelation> findByType(int type, int start, int end)
1922 throws SystemException {
1923 return findByType(type, start, end, null);
1924 }
1925
1926
1940 public List<SocialRelation> findByType(int type, int start, int end,
1941 OrderByComparator orderByComparator) throws SystemException {
1942 Object[] finderArgs = new Object[] {
1943 type,
1944
1945 String.valueOf(start), String.valueOf(end),
1946 String.valueOf(orderByComparator)
1947 };
1948
1949 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TYPE,
1950 finderArgs, this);
1951
1952 if (list == null) {
1953 StringBundler query = null;
1954
1955 if (orderByComparator != null) {
1956 query = new StringBundler(3 +
1957 (orderByComparator.getOrderByFields().length * 3));
1958 }
1959 else {
1960 query = new StringBundler(2);
1961 }
1962
1963 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1964
1965 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1966
1967 if (orderByComparator != null) {
1968 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1969 orderByComparator);
1970 }
1971
1972 String sql = query.toString();
1973
1974 Session session = null;
1975
1976 try {
1977 session = openSession();
1978
1979 Query q = session.createQuery(sql);
1980
1981 QueryPos qPos = QueryPos.getInstance(q);
1982
1983 qPos.add(type);
1984
1985 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1986 start, end);
1987 }
1988 catch (Exception e) {
1989 throw processException(e);
1990 }
1991 finally {
1992 if (list == null) {
1993 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_TYPE,
1994 finderArgs);
1995 }
1996 else {
1997 cacheResult(list);
1998
1999 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TYPE,
2000 finderArgs, list);
2001 }
2002
2003 closeSession(session);
2004 }
2005 }
2006
2007 return list;
2008 }
2009
2010
2023 public SocialRelation findByType_First(int type,
2024 OrderByComparator orderByComparator)
2025 throws NoSuchRelationException, SystemException {
2026 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2027
2028 if (list.isEmpty()) {
2029 StringBundler msg = new StringBundler(4);
2030
2031 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2032
2033 msg.append("type=");
2034 msg.append(type);
2035
2036 msg.append(StringPool.CLOSE_CURLY_BRACE);
2037
2038 throw new NoSuchRelationException(msg.toString());
2039 }
2040 else {
2041 return list.get(0);
2042 }
2043 }
2044
2045
2058 public SocialRelation findByType_Last(int type,
2059 OrderByComparator orderByComparator)
2060 throws NoSuchRelationException, SystemException {
2061 int count = countByType(type);
2062
2063 List<SocialRelation> list = findByType(type, count - 1, count,
2064 orderByComparator);
2065
2066 if (list.isEmpty()) {
2067 StringBundler msg = new StringBundler(4);
2068
2069 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2070
2071 msg.append("type=");
2072 msg.append(type);
2073
2074 msg.append(StringPool.CLOSE_CURLY_BRACE);
2075
2076 throw new NoSuchRelationException(msg.toString());
2077 }
2078 else {
2079 return list.get(0);
2080 }
2081 }
2082
2083
2097 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2098 OrderByComparator orderByComparator)
2099 throws NoSuchRelationException, SystemException {
2100 SocialRelation socialRelation = findByPrimaryKey(relationId);
2101
2102 Session session = null;
2103
2104 try {
2105 session = openSession();
2106
2107 SocialRelation[] array = new SocialRelationImpl[3];
2108
2109 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2110 orderByComparator, true);
2111
2112 array[1] = socialRelation;
2113
2114 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2115 orderByComparator, false);
2116
2117 return array;
2118 }
2119 catch (Exception e) {
2120 throw processException(e);
2121 }
2122 finally {
2123 closeSession(session);
2124 }
2125 }
2126
2127 protected SocialRelation getByType_PrevAndNext(Session session,
2128 SocialRelation socialRelation, int type,
2129 OrderByComparator orderByComparator, boolean previous) {
2130 StringBundler query = null;
2131
2132 if (orderByComparator != null) {
2133 query = new StringBundler(6 +
2134 (orderByComparator.getOrderByFields().length * 6));
2135 }
2136 else {
2137 query = new StringBundler(3);
2138 }
2139
2140 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2141
2142 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2143
2144 if (orderByComparator != null) {
2145 String[] orderByFields = orderByComparator.getOrderByFields();
2146
2147 if (orderByFields.length > 0) {
2148 query.append(WHERE_AND);
2149 }
2150
2151 for (int i = 0; i < orderByFields.length; i++) {
2152 query.append(_ORDER_BY_ENTITY_ALIAS);
2153 query.append(orderByFields[i]);
2154
2155 if ((i + 1) < orderByFields.length) {
2156 if (orderByComparator.isAscending() ^ previous) {
2157 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2158 }
2159 else {
2160 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2161 }
2162 }
2163 else {
2164 if (orderByComparator.isAscending() ^ previous) {
2165 query.append(WHERE_GREATER_THAN);
2166 }
2167 else {
2168 query.append(WHERE_LESSER_THAN);
2169 }
2170 }
2171 }
2172
2173 query.append(ORDER_BY_CLAUSE);
2174
2175 for (int i = 0; i < orderByFields.length; i++) {
2176 query.append(_ORDER_BY_ENTITY_ALIAS);
2177 query.append(orderByFields[i]);
2178
2179 if ((i + 1) < orderByFields.length) {
2180 if (orderByComparator.isAscending() ^ previous) {
2181 query.append(ORDER_BY_ASC_HAS_NEXT);
2182 }
2183 else {
2184 query.append(ORDER_BY_DESC_HAS_NEXT);
2185 }
2186 }
2187 else {
2188 if (orderByComparator.isAscending() ^ previous) {
2189 query.append(ORDER_BY_ASC);
2190 }
2191 else {
2192 query.append(ORDER_BY_DESC);
2193 }
2194 }
2195 }
2196 }
2197
2198 String sql = query.toString();
2199
2200 Query q = session.createQuery(sql);
2201
2202 q.setFirstResult(0);
2203 q.setMaxResults(2);
2204
2205 QueryPos qPos = QueryPos.getInstance(q);
2206
2207 qPos.add(type);
2208
2209 if (orderByComparator != null) {
2210 Object[] values = orderByComparator.getOrderByValues(socialRelation);
2211
2212 for (Object value : values) {
2213 qPos.add(value);
2214 }
2215 }
2216
2217 List<SocialRelation> list = q.list();
2218
2219 if (list.size() == 2) {
2220 return list.get(1);
2221 }
2222 else {
2223 return null;
2224 }
2225 }
2226
2227
2235 public List<SocialRelation> findByC_T(long companyId, int type)
2236 throws SystemException {
2237 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2238 null);
2239 }
2240
2241
2255 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2256 int end) throws SystemException {
2257 return findByC_T(companyId, type, start, end, null);
2258 }
2259
2260
2275 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2276 int end, OrderByComparator orderByComparator) throws SystemException {
2277 Object[] finderArgs = new Object[] {
2278 companyId, type,
2279
2280 String.valueOf(start), String.valueOf(end),
2281 String.valueOf(orderByComparator)
2282 };
2283
2284 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_T,
2285 finderArgs, this);
2286
2287 if (list == null) {
2288 StringBundler query = null;
2289
2290 if (orderByComparator != null) {
2291 query = new StringBundler(4 +
2292 (orderByComparator.getOrderByFields().length * 3));
2293 }
2294 else {
2295 query = new StringBundler(3);
2296 }
2297
2298 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2299
2300 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2301
2302 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2303
2304 if (orderByComparator != null) {
2305 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2306 orderByComparator);
2307 }
2308
2309 String sql = query.toString();
2310
2311 Session session = null;
2312
2313 try {
2314 session = openSession();
2315
2316 Query q = session.createQuery(sql);
2317
2318 QueryPos qPos = QueryPos.getInstance(q);
2319
2320 qPos.add(companyId);
2321
2322 qPos.add(type);
2323
2324 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2325 start, end);
2326 }
2327 catch (Exception e) {
2328 throw processException(e);
2329 }
2330 finally {
2331 if (list == null) {
2332 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_T,
2333 finderArgs);
2334 }
2335 else {
2336 cacheResult(list);
2337
2338 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_T,
2339 finderArgs, list);
2340 }
2341
2342 closeSession(session);
2343 }
2344 }
2345
2346 return list;
2347 }
2348
2349
2363 public SocialRelation findByC_T_First(long companyId, int type,
2364 OrderByComparator orderByComparator)
2365 throws NoSuchRelationException, SystemException {
2366 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
2367 orderByComparator);
2368
2369 if (list.isEmpty()) {
2370 StringBundler msg = new StringBundler(6);
2371
2372 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2373
2374 msg.append("companyId=");
2375 msg.append(companyId);
2376
2377 msg.append(", type=");
2378 msg.append(type);
2379
2380 msg.append(StringPool.CLOSE_CURLY_BRACE);
2381
2382 throw new NoSuchRelationException(msg.toString());
2383 }
2384 else {
2385 return list.get(0);
2386 }
2387 }
2388
2389
2403 public SocialRelation findByC_T_Last(long companyId, int type,
2404 OrderByComparator orderByComparator)
2405 throws NoSuchRelationException, SystemException {
2406 int count = countByC_T(companyId, type);
2407
2408 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
2409 count, orderByComparator);
2410
2411 if (list.isEmpty()) {
2412 StringBundler msg = new StringBundler(6);
2413
2414 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2415
2416 msg.append("companyId=");
2417 msg.append(companyId);
2418
2419 msg.append(", type=");
2420 msg.append(type);
2421
2422 msg.append(StringPool.CLOSE_CURLY_BRACE);
2423
2424 throw new NoSuchRelationException(msg.toString());
2425 }
2426 else {
2427 return list.get(0);
2428 }
2429 }
2430
2431
2446 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
2447 long companyId, int type, OrderByComparator orderByComparator)
2448 throws NoSuchRelationException, SystemException {
2449 SocialRelation socialRelation = findByPrimaryKey(relationId);
2450
2451 Session session = null;
2452
2453 try {
2454 session = openSession();
2455
2456 SocialRelation[] array = new SocialRelationImpl[3];
2457
2458 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2459 type, orderByComparator, true);
2460
2461 array[1] = socialRelation;
2462
2463 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2464 type, orderByComparator, false);
2465
2466 return array;
2467 }
2468 catch (Exception e) {
2469 throw processException(e);
2470 }
2471 finally {
2472 closeSession(session);
2473 }
2474 }
2475
2476 protected SocialRelation getByC_T_PrevAndNext(Session session,
2477 SocialRelation socialRelation, long companyId, int type,
2478 OrderByComparator orderByComparator, boolean previous) {
2479 StringBundler query = null;
2480
2481 if (orderByComparator != null) {
2482 query = new StringBundler(6 +
2483 (orderByComparator.getOrderByFields().length * 6));
2484 }
2485 else {
2486 query = new StringBundler(3);
2487 }
2488
2489 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2490
2491 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2492
2493 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2494
2495 if (orderByComparator != null) {
2496 String[] orderByFields = orderByComparator.getOrderByFields();
2497
2498 if (orderByFields.length > 0) {
2499 query.append(WHERE_AND);
2500 }
2501
2502 for (int i = 0; i < orderByFields.length; i++) {
2503 query.append(_ORDER_BY_ENTITY_ALIAS);
2504 query.append(orderByFields[i]);
2505
2506 if ((i + 1) < orderByFields.length) {
2507 if (orderByComparator.isAscending() ^ previous) {
2508 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2509 }
2510 else {
2511 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2512 }
2513 }
2514 else {
2515 if (orderByComparator.isAscending() ^ previous) {
2516 query.append(WHERE_GREATER_THAN);
2517 }
2518 else {
2519 query.append(WHERE_LESSER_THAN);
2520 }
2521 }
2522 }
2523
2524 query.append(ORDER_BY_CLAUSE);
2525
2526 for (int i = 0; i < orderByFields.length; i++) {
2527 query.append(_ORDER_BY_ENTITY_ALIAS);
2528 query.append(orderByFields[i]);
2529
2530 if ((i + 1) < orderByFields.length) {
2531 if (orderByComparator.isAscending() ^ previous) {
2532 query.append(ORDER_BY_ASC_HAS_NEXT);
2533 }
2534 else {
2535 query.append(ORDER_BY_DESC_HAS_NEXT);
2536 }
2537 }
2538 else {
2539 if (orderByComparator.isAscending() ^ previous) {
2540 query.append(ORDER_BY_ASC);
2541 }
2542 else {
2543 query.append(ORDER_BY_DESC);
2544 }
2545 }
2546 }
2547 }
2548
2549 String sql = query.toString();
2550
2551 Query q = session.createQuery(sql);
2552
2553 q.setFirstResult(0);
2554 q.setMaxResults(2);
2555
2556 QueryPos qPos = QueryPos.getInstance(q);
2557
2558 qPos.add(companyId);
2559
2560 qPos.add(type);
2561
2562 if (orderByComparator != null) {
2563 Object[] values = orderByComparator.getOrderByValues(socialRelation);
2564
2565 for (Object value : values) {
2566 qPos.add(value);
2567 }
2568 }
2569
2570 List<SocialRelation> list = q.list();
2571
2572 if (list.size() == 2) {
2573 return list.get(1);
2574 }
2575 else {
2576 return null;
2577 }
2578 }
2579
2580
2588 public List<SocialRelation> findByU1_T(long userId1, int type)
2589 throws SystemException {
2590 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2591 null);
2592 }
2593
2594
2608 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
2609 int end) throws SystemException {
2610 return findByU1_T(userId1, type, start, end, null);
2611 }
2612
2613
2628 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
2629 int end, OrderByComparator orderByComparator) throws SystemException {
2630 Object[] finderArgs = new Object[] {
2631 userId1, type,
2632
2633 String.valueOf(start), String.valueOf(end),
2634 String.valueOf(orderByComparator)
2635 };
2636
2637 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U1_T,
2638 finderArgs, this);
2639
2640 if (list == null) {
2641 StringBundler query = null;
2642
2643 if (orderByComparator != null) {
2644 query = new StringBundler(4 +
2645 (orderByComparator.getOrderByFields().length * 3));
2646 }
2647 else {
2648 query = new StringBundler(3);
2649 }
2650
2651 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2652
2653 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2654
2655 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2656
2657 if (orderByComparator != null) {
2658 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2659 orderByComparator);
2660 }
2661
2662 String sql = query.toString();
2663
2664 Session session = null;
2665
2666 try {
2667 session = openSession();
2668
2669 Query q = session.createQuery(sql);
2670
2671 QueryPos qPos = QueryPos.getInstance(q);
2672
2673 qPos.add(userId1);
2674
2675 qPos.add(type);
2676
2677 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2678 start, end);
2679 }
2680 catch (Exception e) {
2681 throw processException(e);
2682 }
2683 finally {
2684 if (list == null) {
2685 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_U1_T,
2686 finderArgs);
2687 }
2688 else {
2689 cacheResult(list);
2690
2691 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U1_T,
2692 finderArgs, list);
2693 }
2694
2695 closeSession(session);
2696 }
2697 }
2698
2699 return list;
2700 }
2701
2702
2716 public SocialRelation findByU1_T_First(long userId1, int type,
2717 OrderByComparator orderByComparator)
2718 throws NoSuchRelationException, SystemException {
2719 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
2720 orderByComparator);
2721
2722 if (list.isEmpty()) {
2723 StringBundler msg = new StringBundler(6);
2724
2725 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2726
2727 msg.append("userId1=");
2728 msg.append(userId1);
2729
2730 msg.append(", type=");
2731 msg.append(type);
2732
2733 msg.append(StringPool.CLOSE_CURLY_BRACE);
2734
2735 throw new NoSuchRelationException(msg.toString());
2736 }
2737 else {
2738 return list.get(0);
2739 }
2740 }
2741
2742
2756 public SocialRelation findByU1_T_Last(long userId1, int type,
2757 OrderByComparator orderByComparator)
2758 throws NoSuchRelationException, SystemException {
2759 int count = countByU1_T(userId1, type);
2760
2761 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
2762 orderByComparator);
2763
2764 if (list.isEmpty()) {
2765 StringBundler msg = new StringBundler(6);
2766
2767 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2768
2769 msg.append("userId1=");
2770 msg.append(userId1);
2771
2772 msg.append(", type=");
2773 msg.append(type);
2774
2775 msg.append(StringPool.CLOSE_CURLY_BRACE);
2776
2777 throw new NoSuchRelationException(msg.toString());
2778 }
2779 else {
2780 return list.get(0);
2781 }
2782 }
2783
2784
2799 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
2800 long userId1, int type, OrderByComparator orderByComparator)
2801 throws NoSuchRelationException, SystemException {
2802 SocialRelation socialRelation = findByPrimaryKey(relationId);
2803
2804 Session session = null;
2805
2806 try {
2807 session = openSession();
2808
2809 SocialRelation[] array = new SocialRelationImpl[3];
2810
2811 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
2812 type, orderByComparator, true);
2813
2814 array[1] = socialRelation;
2815
2816 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
2817 type, orderByComparator, false);
2818
2819 return array;
2820 }
2821 catch (Exception e) {
2822 throw processException(e);
2823 }
2824 finally {
2825 closeSession(session);
2826 }
2827 }
2828
2829 protected SocialRelation getByU1_T_PrevAndNext(Session session,
2830 SocialRelation socialRelation, long userId1, int type,
2831 OrderByComparator orderByComparator, boolean previous) {
2832 StringBundler query = null;
2833
2834 if (orderByComparator != null) {
2835 query = new StringBundler(6 +
2836 (orderByComparator.getOrderByFields().length * 6));
2837 }
2838 else {
2839 query = new StringBundler(3);
2840 }
2841
2842 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2843
2844 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2845
2846 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2847
2848 if (orderByComparator != null) {
2849 String[] orderByFields = orderByComparator.getOrderByFields();
2850
2851 if (orderByFields.length > 0) {
2852 query.append(WHERE_AND);
2853 }
2854
2855 for (int i = 0; i < orderByFields.length; i++) {
2856 query.append(_ORDER_BY_ENTITY_ALIAS);
2857 query.append(orderByFields[i]);
2858
2859 if ((i + 1) < orderByFields.length) {
2860 if (orderByComparator.isAscending() ^ previous) {
2861 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2862 }
2863 else {
2864 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2865 }
2866 }
2867 else {
2868 if (orderByComparator.isAscending() ^ previous) {
2869 query.append(WHERE_GREATER_THAN);
2870 }
2871 else {
2872 query.append(WHERE_LESSER_THAN);
2873 }
2874 }
2875 }
2876
2877 query.append(ORDER_BY_CLAUSE);
2878
2879 for (int i = 0; i < orderByFields.length; i++) {
2880 query.append(_ORDER_BY_ENTITY_ALIAS);
2881 query.append(orderByFields[i]);
2882
2883 if ((i + 1) < orderByFields.length) {
2884 if (orderByComparator.isAscending() ^ previous) {
2885 query.append(ORDER_BY_ASC_HAS_NEXT);
2886 }
2887 else {
2888 query.append(ORDER_BY_DESC_HAS_NEXT);
2889 }
2890 }
2891 else {
2892 if (orderByComparator.isAscending() ^ previous) {
2893 query.append(ORDER_BY_ASC);
2894 }
2895 else {
2896 query.append(ORDER_BY_DESC);
2897 }
2898 }
2899 }
2900 }
2901
2902 String sql = query.toString();
2903
2904 Query q = session.createQuery(sql);
2905
2906 q.setFirstResult(0);
2907 q.setMaxResults(2);
2908
2909 QueryPos qPos = QueryPos.getInstance(q);
2910
2911 qPos.add(userId1);
2912
2913 qPos.add(type);
2914
2915 if (orderByComparator != null) {
2916 Object[] values = orderByComparator.getOrderByValues(socialRelation);
2917
2918 for (Object value : values) {
2919 qPos.add(value);
2920 }
2921 }
2922
2923 List<SocialRelation> list = q.list();
2924
2925 if (list.size() == 2) {
2926 return list.get(1);
2927 }
2928 else {
2929 return null;
2930 }
2931 }
2932
2933
2941 public List<SocialRelation> findByU2_T(long userId2, int type)
2942 throws SystemException {
2943 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2944 null);
2945 }
2946
2947
2961 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2962 int end) throws SystemException {
2963 return findByU2_T(userId2, type, start, end, null);
2964 }
2965
2966
2981 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2982 int end, OrderByComparator orderByComparator) throws SystemException {
2983 Object[] finderArgs = new Object[] {
2984 userId2, type,
2985
2986 String.valueOf(start), String.valueOf(end),
2987 String.valueOf(orderByComparator)
2988 };
2989
2990 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U2_T,
2991 finderArgs, this);
2992
2993 if (list == null) {
2994 StringBundler query = null;
2995
2996 if (orderByComparator != null) {
2997 query = new StringBundler(4 +
2998 (orderByComparator.getOrderByFields().length * 3));
2999 }
3000 else {
3001 query = new StringBundler(3);
3002 }
3003
3004 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3005
3006 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3007
3008 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3009
3010 if (orderByComparator != null) {
3011 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3012 orderByComparator);
3013 }
3014
3015 String sql = query.toString();
3016
3017 Session session = null;
3018
3019 try {
3020 session = openSession();
3021
3022 Query q = session.createQuery(sql);
3023
3024 QueryPos qPos = QueryPos.getInstance(q);
3025
3026 qPos.add(userId2);
3027
3028 qPos.add(type);
3029
3030 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3031 start, end);
3032 }
3033 catch (Exception e) {
3034 throw processException(e);
3035 }
3036 finally {
3037 if (list == null) {
3038 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_U2_T,
3039 finderArgs);
3040 }
3041 else {
3042 cacheResult(list);
3043
3044 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U2_T,
3045 finderArgs, list);
3046 }
3047
3048 closeSession(session);
3049 }
3050 }
3051
3052 return list;
3053 }
3054
3055
3069 public SocialRelation findByU2_T_First(long userId2, int type,
3070 OrderByComparator orderByComparator)
3071 throws NoSuchRelationException, SystemException {
3072 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
3073 orderByComparator);
3074
3075 if (list.isEmpty()) {
3076 StringBundler msg = new StringBundler(6);
3077
3078 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3079
3080 msg.append("userId2=");
3081 msg.append(userId2);
3082
3083 msg.append(", type=");
3084 msg.append(type);
3085
3086 msg.append(StringPool.CLOSE_CURLY_BRACE);
3087
3088 throw new NoSuchRelationException(msg.toString());
3089 }
3090 else {
3091 return list.get(0);
3092 }
3093 }
3094
3095
3109 public SocialRelation findByU2_T_Last(long userId2, int type,
3110 OrderByComparator orderByComparator)
3111 throws NoSuchRelationException, SystemException {
3112 int count = countByU2_T(userId2, type);
3113
3114 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
3115 orderByComparator);
3116
3117 if (list.isEmpty()) {
3118 StringBundler msg = new StringBundler(6);
3119
3120 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3121
3122 msg.append("userId2=");
3123 msg.append(userId2);
3124
3125 msg.append(", type=");
3126 msg.append(type);
3127
3128 msg.append(StringPool.CLOSE_CURLY_BRACE);
3129
3130 throw new NoSuchRelationException(msg.toString());
3131 }
3132 else {
3133 return list.get(0);
3134 }
3135 }
3136
3137
3152 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
3153 long userId2, int type, OrderByComparator orderByComparator)
3154 throws NoSuchRelationException, SystemException {
3155 SocialRelation socialRelation = findByPrimaryKey(relationId);
3156
3157 Session session = null;
3158
3159 try {
3160 session = openSession();
3161
3162 SocialRelation[] array = new SocialRelationImpl[3];
3163
3164 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3165 type, orderByComparator, true);
3166
3167 array[1] = socialRelation;
3168
3169 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3170 type, orderByComparator, false);
3171
3172 return array;
3173 }
3174 catch (Exception e) {
3175 throw processException(e);
3176 }
3177 finally {
3178 closeSession(session);
3179 }
3180 }
3181
3182 protected SocialRelation getByU2_T_PrevAndNext(Session session,
3183 SocialRelation socialRelation, long userId2, int type,
3184 OrderByComparator orderByComparator, boolean previous) {
3185 StringBundler query = null;
3186
3187 if (orderByComparator != null) {
3188 query = new StringBundler(6 +
3189 (orderByComparator.getOrderByFields().length * 6));
3190 }
3191 else {
3192 query = new StringBundler(3);
3193 }
3194
3195 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3196
3197 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3198
3199 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3200
3201 if (orderByComparator != null) {
3202 String[] orderByFields = orderByComparator.getOrderByFields();
3203
3204 if (orderByFields.length > 0) {
3205 query.append(WHERE_AND);
3206 }
3207
3208 for (int i = 0; i < orderByFields.length; i++) {
3209 query.append(_ORDER_BY_ENTITY_ALIAS);
3210 query.append(orderByFields[i]);
3211
3212 if ((i + 1) < orderByFields.length) {
3213 if (orderByComparator.isAscending() ^ previous) {
3214 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3215 }
3216 else {
3217 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3218 }
3219 }
3220 else {
3221 if (orderByComparator.isAscending() ^ previous) {
3222 query.append(WHERE_GREATER_THAN);
3223 }
3224 else {
3225 query.append(WHERE_LESSER_THAN);
3226 }
3227 }
3228 }
3229
3230 query.append(ORDER_BY_CLAUSE);
3231
3232 for (int i = 0; i < orderByFields.length; i++) {
3233 query.append(_ORDER_BY_ENTITY_ALIAS);
3234 query.append(orderByFields[i]);
3235
3236 if ((i + 1) < orderByFields.length) {
3237 if (orderByComparator.isAscending() ^ previous) {
3238 query.append(ORDER_BY_ASC_HAS_NEXT);
3239 }
3240 else {
3241 query.append(ORDER_BY_DESC_HAS_NEXT);
3242 }
3243 }
3244 else {
3245 if (orderByComparator.isAscending() ^ previous) {
3246 query.append(ORDER_BY_ASC);
3247 }
3248 else {
3249 query.append(ORDER_BY_DESC);
3250 }
3251 }
3252 }
3253 }
3254
3255 String sql = query.toString();
3256
3257 Query q = session.createQuery(sql);
3258
3259 q.setFirstResult(0);
3260 q.setMaxResults(2);
3261
3262 QueryPos qPos = QueryPos.getInstance(q);
3263
3264 qPos.add(userId2);
3265
3266 qPos.add(type);
3267
3268 if (orderByComparator != null) {
3269 Object[] values = orderByComparator.getOrderByValues(socialRelation);
3270
3271 for (Object value : values) {
3272 qPos.add(value);
3273 }
3274 }
3275
3276 List<SocialRelation> list = q.list();
3277
3278 if (list.size() == 2) {
3279 return list.get(1);
3280 }
3281 else {
3282 return null;
3283 }
3284 }
3285
3286
3296 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
3297 throws NoSuchRelationException, SystemException {
3298 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
3299
3300 if (socialRelation == null) {
3301 StringBundler msg = new StringBundler(8);
3302
3303 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3304
3305 msg.append("userId1=");
3306 msg.append(userId1);
3307
3308 msg.append(", userId2=");
3309 msg.append(userId2);
3310
3311 msg.append(", type=");
3312 msg.append(type);
3313
3314 msg.append(StringPool.CLOSE_CURLY_BRACE);
3315
3316 if (_log.isWarnEnabled()) {
3317 _log.warn(msg.toString());
3318 }
3319
3320 throw new NoSuchRelationException(msg.toString());
3321 }
3322
3323 return socialRelation;
3324 }
3325
3326
3335 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
3336 throws SystemException {
3337 return fetchByU1_U2_T(userId1, userId2, type, true);
3338 }
3339
3340
3349 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
3350 boolean retrieveFromCache) throws SystemException {
3351 Object[] finderArgs = new Object[] { userId1, userId2, type };
3352
3353 Object result = null;
3354
3355 if (retrieveFromCache) {
3356 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3357 finderArgs, this);
3358 }
3359
3360 if (result == null) {
3361 StringBundler query = new StringBundler(4);
3362
3363 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3364
3365 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
3366
3367 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
3368
3369 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
3370
3371 String sql = query.toString();
3372
3373 Session session = null;
3374
3375 try {
3376 session = openSession();
3377
3378 Query q = session.createQuery(sql);
3379
3380 QueryPos qPos = QueryPos.getInstance(q);
3381
3382 qPos.add(userId1);
3383
3384 qPos.add(userId2);
3385
3386 qPos.add(type);
3387
3388 List<SocialRelation> list = q.list();
3389
3390 result = list;
3391
3392 SocialRelation socialRelation = null;
3393
3394 if (list.isEmpty()) {
3395 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3396 finderArgs, list);
3397 }
3398 else {
3399 socialRelation = list.get(0);
3400
3401 cacheResult(socialRelation);
3402
3403 if ((socialRelation.getUserId1() != userId1) ||
3404 (socialRelation.getUserId2() != userId2) ||
3405 (socialRelation.getType() != type)) {
3406 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3407 finderArgs, socialRelation);
3408 }
3409 }
3410
3411 return socialRelation;
3412 }
3413 catch (Exception e) {
3414 throw processException(e);
3415 }
3416 finally {
3417 if (result == null) {
3418 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3419 finderArgs);
3420 }
3421
3422 closeSession(session);
3423 }
3424 }
3425 else {
3426 if (result instanceof List<?>) {
3427 return null;
3428 }
3429 else {
3430 return (SocialRelation)result;
3431 }
3432 }
3433 }
3434
3435
3441 public List<SocialRelation> findAll() throws SystemException {
3442 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3443 }
3444
3445
3457 public List<SocialRelation> findAll(int start, int end)
3458 throws SystemException {
3459 return findAll(start, end, null);
3460 }
3461
3462
3475 public List<SocialRelation> findAll(int start, int end,
3476 OrderByComparator orderByComparator) throws SystemException {
3477 Object[] finderArgs = new Object[] {
3478 String.valueOf(start), String.valueOf(end),
3479 String.valueOf(orderByComparator)
3480 };
3481
3482 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3483 finderArgs, this);
3484
3485 if (list == null) {
3486 StringBundler query = null;
3487 String sql = null;
3488
3489 if (orderByComparator != null) {
3490 query = new StringBundler(2 +
3491 (orderByComparator.getOrderByFields().length * 3));
3492
3493 query.append(_SQL_SELECT_SOCIALRELATION);
3494
3495 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3496 orderByComparator);
3497
3498 sql = query.toString();
3499 }
3500 else {
3501 sql = _SQL_SELECT_SOCIALRELATION;
3502 }
3503
3504 Session session = null;
3505
3506 try {
3507 session = openSession();
3508
3509 Query q = session.createQuery(sql);
3510
3511 if (orderByComparator == null) {
3512 list = (List<SocialRelation>)QueryUtil.list(q,
3513 getDialect(), start, end, false);
3514
3515 Collections.sort(list);
3516 }
3517 else {
3518 list = (List<SocialRelation>)QueryUtil.list(q,
3519 getDialect(), start, end);
3520 }
3521 }
3522 catch (Exception e) {
3523 throw processException(e);
3524 }
3525 finally {
3526 if (list == null) {
3527 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
3528 finderArgs);
3529 }
3530 else {
3531 cacheResult(list);
3532
3533 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
3534 list);
3535 }
3536
3537 closeSession(session);
3538 }
3539 }
3540
3541 return list;
3542 }
3543
3544
3550 public void removeByUuid(String uuid) throws SystemException {
3551 for (SocialRelation socialRelation : findByUuid(uuid)) {
3552 remove(socialRelation);
3553 }
3554 }
3555
3556
3562 public void removeByCompanyId(long companyId) throws SystemException {
3563 for (SocialRelation socialRelation : findByCompanyId(companyId)) {
3564 remove(socialRelation);
3565 }
3566 }
3567
3568
3574 public void removeByUserId1(long userId1) throws SystemException {
3575 for (SocialRelation socialRelation : findByUserId1(userId1)) {
3576 remove(socialRelation);
3577 }
3578 }
3579
3580
3586 public void removeByUserId2(long userId2) throws SystemException {
3587 for (SocialRelation socialRelation : findByUserId2(userId2)) {
3588 remove(socialRelation);
3589 }
3590 }
3591
3592
3598 public void removeByType(int type) throws SystemException {
3599 for (SocialRelation socialRelation : findByType(type)) {
3600 remove(socialRelation);
3601 }
3602 }
3603
3604
3611 public void removeByC_T(long companyId, int type) throws SystemException {
3612 for (SocialRelation socialRelation : findByC_T(companyId, type)) {
3613 remove(socialRelation);
3614 }
3615 }
3616
3617
3624 public void removeByU1_T(long userId1, int type) throws SystemException {
3625 for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
3626 remove(socialRelation);
3627 }
3628 }
3629
3630
3637 public void removeByU2_T(long userId2, int type) throws SystemException {
3638 for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
3639 remove(socialRelation);
3640 }
3641 }
3642
3643
3651 public void removeByU1_U2_T(long userId1, long userId2, int type)
3652 throws NoSuchRelationException, SystemException {
3653 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
3654
3655 remove(socialRelation);
3656 }
3657
3658
3663 public void removeAll() throws SystemException {
3664 for (SocialRelation socialRelation : findAll()) {
3665 remove(socialRelation);
3666 }
3667 }
3668
3669
3676 public int countByUuid(String uuid) throws SystemException {
3677 Object[] finderArgs = new Object[] { uuid };
3678
3679 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3680 finderArgs, this);
3681
3682 if (count == null) {
3683 StringBundler query = new StringBundler(2);
3684
3685 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3686
3687 if (uuid == null) {
3688 query.append(_FINDER_COLUMN_UUID_UUID_1);
3689 }
3690 else {
3691 if (uuid.equals(StringPool.BLANK)) {
3692 query.append(_FINDER_COLUMN_UUID_UUID_3);
3693 }
3694 else {
3695 query.append(_FINDER_COLUMN_UUID_UUID_2);
3696 }
3697 }
3698
3699 String sql = query.toString();
3700
3701 Session session = null;
3702
3703 try {
3704 session = openSession();
3705
3706 Query q = session.createQuery(sql);
3707
3708 QueryPos qPos = QueryPos.getInstance(q);
3709
3710 if (uuid != null) {
3711 qPos.add(uuid);
3712 }
3713
3714 count = (Long)q.uniqueResult();
3715 }
3716 catch (Exception e) {
3717 throw processException(e);
3718 }
3719 finally {
3720 if (count == null) {
3721 count = Long.valueOf(0);
3722 }
3723
3724 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3725 finderArgs, count);
3726
3727 closeSession(session);
3728 }
3729 }
3730
3731 return count.intValue();
3732 }
3733
3734
3741 public int countByCompanyId(long companyId) throws SystemException {
3742 Object[] finderArgs = new Object[] { companyId };
3743
3744 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3745 finderArgs, this);
3746
3747 if (count == null) {
3748 StringBundler query = new StringBundler(2);
3749
3750 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3751
3752 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3753
3754 String sql = query.toString();
3755
3756 Session session = null;
3757
3758 try {
3759 session = openSession();
3760
3761 Query q = session.createQuery(sql);
3762
3763 QueryPos qPos = QueryPos.getInstance(q);
3764
3765 qPos.add(companyId);
3766
3767 count = (Long)q.uniqueResult();
3768 }
3769 catch (Exception e) {
3770 throw processException(e);
3771 }
3772 finally {
3773 if (count == null) {
3774 count = Long.valueOf(0);
3775 }
3776
3777 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3778 finderArgs, count);
3779
3780 closeSession(session);
3781 }
3782 }
3783
3784 return count.intValue();
3785 }
3786
3787
3794 public int countByUserId1(long userId1) throws SystemException {
3795 Object[] finderArgs = new Object[] { userId1 };
3796
3797 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
3798 finderArgs, this);
3799
3800 if (count == null) {
3801 StringBundler query = new StringBundler(2);
3802
3803 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3804
3805 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
3806
3807 String sql = query.toString();
3808
3809 Session session = null;
3810
3811 try {
3812 session = openSession();
3813
3814 Query q = session.createQuery(sql);
3815
3816 QueryPos qPos = QueryPos.getInstance(q);
3817
3818 qPos.add(userId1);
3819
3820 count = (Long)q.uniqueResult();
3821 }
3822 catch (Exception e) {
3823 throw processException(e);
3824 }
3825 finally {
3826 if (count == null) {
3827 count = Long.valueOf(0);
3828 }
3829
3830 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
3831 finderArgs, count);
3832
3833 closeSession(session);
3834 }
3835 }
3836
3837 return count.intValue();
3838 }
3839
3840
3847 public int countByUserId2(long userId2) throws SystemException {
3848 Object[] finderArgs = new Object[] { userId2 };
3849
3850 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
3851 finderArgs, this);
3852
3853 if (count == null) {
3854 StringBundler query = new StringBundler(2);
3855
3856 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3857
3858 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
3859
3860 String sql = query.toString();
3861
3862 Session session = null;
3863
3864 try {
3865 session = openSession();
3866
3867 Query q = session.createQuery(sql);
3868
3869 QueryPos qPos = QueryPos.getInstance(q);
3870
3871 qPos.add(userId2);
3872
3873 count = (Long)q.uniqueResult();
3874 }
3875 catch (Exception e) {
3876 throw processException(e);
3877 }
3878 finally {
3879 if (count == null) {
3880 count = Long.valueOf(0);
3881 }
3882
3883 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
3884 finderArgs, count);
3885
3886 closeSession(session);
3887 }
3888 }
3889
3890 return count.intValue();
3891 }
3892
3893
3900 public int countByType(int type) throws SystemException {
3901 Object[] finderArgs = new Object[] { type };
3902
3903 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
3904 finderArgs, this);
3905
3906 if (count == null) {
3907 StringBundler query = new StringBundler(2);
3908
3909 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3910
3911 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3912
3913 String sql = query.toString();
3914
3915 Session session = null;
3916
3917 try {
3918 session = openSession();
3919
3920 Query q = session.createQuery(sql);
3921
3922 QueryPos qPos = QueryPos.getInstance(q);
3923
3924 qPos.add(type);
3925
3926 count = (Long)q.uniqueResult();
3927 }
3928 catch (Exception e) {
3929 throw processException(e);
3930 }
3931 finally {
3932 if (count == null) {
3933 count = Long.valueOf(0);
3934 }
3935
3936 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
3937 finderArgs, count);
3938
3939 closeSession(session);
3940 }
3941 }
3942
3943 return count.intValue();
3944 }
3945
3946
3954 public int countByC_T(long companyId, int type) throws SystemException {
3955 Object[] finderArgs = new Object[] { companyId, type };
3956
3957 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
3958 finderArgs, this);
3959
3960 if (count == null) {
3961 StringBundler query = new StringBundler(3);
3962
3963 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3964
3965 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3966
3967 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3968
3969 String sql = query.toString();
3970
3971 Session session = null;
3972
3973 try {
3974 session = openSession();
3975
3976 Query q = session.createQuery(sql);
3977
3978 QueryPos qPos = QueryPos.getInstance(q);
3979
3980 qPos.add(companyId);
3981
3982 qPos.add(type);
3983
3984 count = (Long)q.uniqueResult();
3985 }
3986 catch (Exception e) {
3987 throw processException(e);
3988 }
3989 finally {
3990 if (count == null) {
3991 count = Long.valueOf(0);
3992 }
3993
3994 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
3995 count);
3996
3997 closeSession(session);
3998 }
3999 }
4000
4001 return count.intValue();
4002 }
4003
4004
4012 public int countByU1_T(long userId1, int type) throws SystemException {
4013 Object[] finderArgs = new Object[] { userId1, type };
4014
4015 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
4016 finderArgs, this);
4017
4018 if (count == null) {
4019 StringBundler query = new StringBundler(3);
4020
4021 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4022
4023 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4024
4025 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4026
4027 String sql = query.toString();
4028
4029 Session session = null;
4030
4031 try {
4032 session = openSession();
4033
4034 Query q = session.createQuery(sql);
4035
4036 QueryPos qPos = QueryPos.getInstance(q);
4037
4038 qPos.add(userId1);
4039
4040 qPos.add(type);
4041
4042 count = (Long)q.uniqueResult();
4043 }
4044 catch (Exception e) {
4045 throw processException(e);
4046 }
4047 finally {
4048 if (count == null) {
4049 count = Long.valueOf(0);
4050 }
4051
4052 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
4053 finderArgs, count);
4054
4055 closeSession(session);
4056 }
4057 }
4058
4059 return count.intValue();
4060 }
4061
4062
4070 public int countByU2_T(long userId2, int type) throws SystemException {
4071 Object[] finderArgs = new Object[] { userId2, type };
4072
4073 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
4074 finderArgs, this);
4075
4076 if (count == null) {
4077 StringBundler query = new StringBundler(3);
4078
4079 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4080
4081 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4082
4083 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4084
4085 String sql = query.toString();
4086
4087 Session session = null;
4088
4089 try {
4090 session = openSession();
4091
4092 Query q = session.createQuery(sql);
4093
4094 QueryPos qPos = QueryPos.getInstance(q);
4095
4096 qPos.add(userId2);
4097
4098 qPos.add(type);
4099
4100 count = (Long)q.uniqueResult();
4101 }
4102 catch (Exception e) {
4103 throw processException(e);
4104 }
4105 finally {
4106 if (count == null) {
4107 count = Long.valueOf(0);
4108 }
4109
4110 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
4111 finderArgs, count);
4112
4113 closeSession(session);
4114 }
4115 }
4116
4117 return count.intValue();
4118 }
4119
4120
4129 public int countByU1_U2_T(long userId1, long userId2, int type)
4130 throws SystemException {
4131 Object[] finderArgs = new Object[] { userId1, userId2, type };
4132
4133 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
4134 finderArgs, this);
4135
4136 if (count == null) {
4137 StringBundler query = new StringBundler(4);
4138
4139 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4140
4141 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4142
4143 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4144
4145 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4146
4147 String sql = query.toString();
4148
4149 Session session = null;
4150
4151 try {
4152 session = openSession();
4153
4154 Query q = session.createQuery(sql);
4155
4156 QueryPos qPos = QueryPos.getInstance(q);
4157
4158 qPos.add(userId1);
4159
4160 qPos.add(userId2);
4161
4162 qPos.add(type);
4163
4164 count = (Long)q.uniqueResult();
4165 }
4166 catch (Exception e) {
4167 throw processException(e);
4168 }
4169 finally {
4170 if (count == null) {
4171 count = Long.valueOf(0);
4172 }
4173
4174 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
4175 finderArgs, count);
4176
4177 closeSession(session);
4178 }
4179 }
4180
4181 return count.intValue();
4182 }
4183
4184
4190 public int countAll() throws SystemException {
4191 Object[] finderArgs = new Object[0];
4192
4193 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4194 finderArgs, this);
4195
4196 if (count == null) {
4197 Session session = null;
4198
4199 try {
4200 session = openSession();
4201
4202 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
4203
4204 count = (Long)q.uniqueResult();
4205 }
4206 catch (Exception e) {
4207 throw processException(e);
4208 }
4209 finally {
4210 if (count == null) {
4211 count = Long.valueOf(0);
4212 }
4213
4214 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4215 count);
4216
4217 closeSession(session);
4218 }
4219 }
4220
4221 return count.intValue();
4222 }
4223
4224
4227 public void afterPropertiesSet() {
4228 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4229 com.liferay.portal.util.PropsUtil.get(
4230 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
4231
4232 if (listenerClassNames.length > 0) {
4233 try {
4234 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
4235
4236 for (String listenerClassName : listenerClassNames) {
4237 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
4238 listenerClassName));
4239 }
4240
4241 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4242 }
4243 catch (Exception e) {
4244 _log.error(e);
4245 }
4246 }
4247 }
4248
4249 public void destroy() {
4250 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
4251 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4252 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
4253 }
4254
4255 @BeanReference(type = SocialActivityPersistence.class)
4256 protected SocialActivityPersistence socialActivityPersistence;
4257 @BeanReference(type = SocialEquityAssetEntryPersistence.class)
4258 protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
4259 @BeanReference(type = SocialEquityGroupSettingPersistence.class)
4260 protected SocialEquityGroupSettingPersistence socialEquityGroupSettingPersistence;
4261 @BeanReference(type = SocialEquityHistoryPersistence.class)
4262 protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
4263 @BeanReference(type = SocialEquityLogPersistence.class)
4264 protected SocialEquityLogPersistence socialEquityLogPersistence;
4265 @BeanReference(type = SocialEquitySettingPersistence.class)
4266 protected SocialEquitySettingPersistence socialEquitySettingPersistence;
4267 @BeanReference(type = SocialEquityUserPersistence.class)
4268 protected SocialEquityUserPersistence socialEquityUserPersistence;
4269 @BeanReference(type = SocialRelationPersistence.class)
4270 protected SocialRelationPersistence socialRelationPersistence;
4271 @BeanReference(type = SocialRequestPersistence.class)
4272 protected SocialRequestPersistence socialRequestPersistence;
4273 @BeanReference(type = ResourcePersistence.class)
4274 protected ResourcePersistence resourcePersistence;
4275 @BeanReference(type = UserPersistence.class)
4276 protected UserPersistence userPersistence;
4277 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
4278 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
4279 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
4280 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
4281 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
4282 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
4283 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
4284 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
4285 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
4286 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
4287 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
4288 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
4289 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
4290 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4291 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
4292 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
4293 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
4294 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4295 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
4296 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
4297 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
4298 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
4299 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
4300 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
4301 }