001
014
015 package com.liferay.portlet.social.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.social.NoSuchRelationException;
043 import com.liferay.portlet.social.model.SocialRelation;
044 import com.liferay.portlet.social.model.impl.SocialRelationImpl;
045 import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
065 public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
066 implements SocialRelationPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
078 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
079 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
080 "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
082 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
083 SocialRelationImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
086 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
089 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
090 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findByUuid",
092 new String[] {
093 String.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
099 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
100 SocialRelationImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102 new String[] { String.class.getName() },
103 SocialRelationModelImpl.UUID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
105 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107 new String[] { String.class.getName() });
108
109
116 public List<SocialRelation> findByUuid(String uuid)
117 throws SystemException {
118 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<SocialRelation> findByUuid(String uuid, int start, int end)
135 throws SystemException {
136 return findByUuid(uuid, start, end, null);
137 }
138
139
153 public List<SocialRelation> findByUuid(String uuid, int start, int end,
154 OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid, start, end, orderByComparator };
168 }
169
170 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (SocialRelation socialRelation : list) {
175 if (!Validator.equals(uuid, socialRelation.getUuid())) {
176 list = null;
177
178 break;
179 }
180 }
181 }
182
183 if (list == null) {
184 StringBundler query = null;
185
186 if (orderByComparator != null) {
187 query = new StringBundler(3 +
188 (orderByComparator.getOrderByFields().length * 3));
189 }
190 else {
191 query = new StringBundler(3);
192 }
193
194 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
195
196 if (uuid == null) {
197 query.append(_FINDER_COLUMN_UUID_UUID_1);
198 }
199 else {
200 if (uuid.equals(StringPool.BLANK)) {
201 query.append(_FINDER_COLUMN_UUID_UUID_3);
202 }
203 else {
204 query.append(_FINDER_COLUMN_UUID_UUID_2);
205 }
206 }
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 if (uuid != null) {
229 qPos.add(uuid);
230 }
231
232 if (!pagination) {
233 list = (List<SocialRelation>)QueryUtil.list(q,
234 getDialect(), start, end, false);
235
236 Collections.sort(list);
237
238 list = new UnmodifiableList<SocialRelation>(list);
239 }
240 else {
241 list = (List<SocialRelation>)QueryUtil.list(q,
242 getDialect(), start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
271 public SocialRelation findByUuid_First(String uuid,
272 OrderByComparator orderByComparator)
273 throws NoSuchRelationException, SystemException {
274 SocialRelation socialRelation = fetchByUuid_First(uuid,
275 orderByComparator);
276
277 if (socialRelation != null) {
278 return socialRelation;
279 }
280
281 StringBundler msg = new StringBundler(4);
282
283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
284
285 msg.append("uuid=");
286 msg.append(uuid);
287
288 msg.append(StringPool.CLOSE_CURLY_BRACE);
289
290 throw new NoSuchRelationException(msg.toString());
291 }
292
293
301 public SocialRelation fetchByUuid_First(String uuid,
302 OrderByComparator orderByComparator) throws SystemException {
303 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
304
305 if (!list.isEmpty()) {
306 return list.get(0);
307 }
308
309 return null;
310 }
311
312
321 public SocialRelation findByUuid_Last(String uuid,
322 OrderByComparator orderByComparator)
323 throws NoSuchRelationException, SystemException {
324 SocialRelation socialRelation = fetchByUuid_Last(uuid, orderByComparator);
325
326 if (socialRelation != null) {
327 return socialRelation;
328 }
329
330 StringBundler msg = new StringBundler(4);
331
332 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
333
334 msg.append("uuid=");
335 msg.append(uuid);
336
337 msg.append(StringPool.CLOSE_CURLY_BRACE);
338
339 throw new NoSuchRelationException(msg.toString());
340 }
341
342
350 public SocialRelation fetchByUuid_Last(String uuid,
351 OrderByComparator orderByComparator) throws SystemException {
352 int count = countByUuid(uuid);
353
354 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
355 orderByComparator);
356
357 if (!list.isEmpty()) {
358 return list.get(0);
359 }
360
361 return null;
362 }
363
364
374 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
375 String uuid, OrderByComparator orderByComparator)
376 throws NoSuchRelationException, SystemException {
377 SocialRelation socialRelation = findByPrimaryKey(relationId);
378
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 SocialRelation[] array = new SocialRelationImpl[3];
385
386 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
387 orderByComparator, true);
388
389 array[1] = socialRelation;
390
391 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
392 orderByComparator, false);
393
394 return array;
395 }
396 catch (Exception e) {
397 throw processException(e);
398 }
399 finally {
400 closeSession(session);
401 }
402 }
403
404 protected SocialRelation getByUuid_PrevAndNext(Session session,
405 SocialRelation socialRelation, String uuid,
406 OrderByComparator orderByComparator, boolean previous) {
407 StringBundler query = null;
408
409 if (orderByComparator != null) {
410 query = new StringBundler(6 +
411 (orderByComparator.getOrderByFields().length * 6));
412 }
413 else {
414 query = new StringBundler(3);
415 }
416
417 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
418
419 if (uuid == null) {
420 query.append(_FINDER_COLUMN_UUID_UUID_1);
421 }
422 else {
423 if (uuid.equals(StringPool.BLANK)) {
424 query.append(_FINDER_COLUMN_UUID_UUID_3);
425 }
426 else {
427 query.append(_FINDER_COLUMN_UUID_UUID_2);
428 }
429 }
430
431 if (orderByComparator != null) {
432 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
433
434 if (orderByConditionFields.length > 0) {
435 query.append(WHERE_AND);
436 }
437
438 for (int i = 0; i < orderByConditionFields.length; i++) {
439 query.append(_ORDER_BY_ENTITY_ALIAS);
440 query.append(orderByConditionFields[i]);
441
442 if ((i + 1) < orderByConditionFields.length) {
443 if (orderByComparator.isAscending() ^ previous) {
444 query.append(WHERE_GREATER_THAN_HAS_NEXT);
445 }
446 else {
447 query.append(WHERE_LESSER_THAN_HAS_NEXT);
448 }
449 }
450 else {
451 if (orderByComparator.isAscending() ^ previous) {
452 query.append(WHERE_GREATER_THAN);
453 }
454 else {
455 query.append(WHERE_LESSER_THAN);
456 }
457 }
458 }
459
460 query.append(ORDER_BY_CLAUSE);
461
462 String[] orderByFields = orderByComparator.getOrderByFields();
463
464 for (int i = 0; i < orderByFields.length; i++) {
465 query.append(_ORDER_BY_ENTITY_ALIAS);
466 query.append(orderByFields[i]);
467
468 if ((i + 1) < orderByFields.length) {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(ORDER_BY_ASC_HAS_NEXT);
471 }
472 else {
473 query.append(ORDER_BY_DESC_HAS_NEXT);
474 }
475 }
476 else {
477 if (orderByComparator.isAscending() ^ previous) {
478 query.append(ORDER_BY_ASC);
479 }
480 else {
481 query.append(ORDER_BY_DESC);
482 }
483 }
484 }
485 }
486 else {
487 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
488 }
489
490 String sql = query.toString();
491
492 Query q = session.createQuery(sql);
493
494 q.setFirstResult(0);
495 q.setMaxResults(2);
496
497 QueryPos qPos = QueryPos.getInstance(q);
498
499 if (uuid != null) {
500 qPos.add(uuid);
501 }
502
503 if (orderByComparator != null) {
504 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
505
506 for (Object value : values) {
507 qPos.add(value);
508 }
509 }
510
511 List<SocialRelation> list = q.list();
512
513 if (list.size() == 2) {
514 return list.get(1);
515 }
516 else {
517 return null;
518 }
519 }
520
521
527 public void removeByUuid(String uuid) throws SystemException {
528 for (SocialRelation socialRelation : findByUuid(uuid,
529 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
530 remove(socialRelation);
531 }
532 }
533
534
541 public int countByUuid(String uuid) throws SystemException {
542 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
543
544 Object[] finderArgs = new Object[] { uuid };
545
546 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
547 this);
548
549 if (count == null) {
550 StringBundler query = new StringBundler(2);
551
552 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
553
554 if (uuid == null) {
555 query.append(_FINDER_COLUMN_UUID_UUID_1);
556 }
557 else {
558 if (uuid.equals(StringPool.BLANK)) {
559 query.append(_FINDER_COLUMN_UUID_UUID_3);
560 }
561 else {
562 query.append(_FINDER_COLUMN_UUID_UUID_2);
563 }
564 }
565
566 String sql = query.toString();
567
568 Session session = null;
569
570 try {
571 session = openSession();
572
573 Query q = session.createQuery(sql);
574
575 QueryPos qPos = QueryPos.getInstance(q);
576
577 if (uuid != null) {
578 qPos.add(uuid);
579 }
580
581 count = (Long)q.uniqueResult();
582
583 FinderCacheUtil.putResult(finderPath, finderArgs, count);
584 }
585 catch (Exception e) {
586 FinderCacheUtil.removeResult(finderPath, finderArgs);
587
588 throw processException(e);
589 }
590 finally {
591 closeSession(session);
592 }
593 }
594
595 return count.intValue();
596 }
597
598 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
599 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
600 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
601 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
602 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
603 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
604 "findByUuid_C",
605 new String[] {
606 String.class.getName(), Long.class.getName(),
607
608 Integer.class.getName(), Integer.class.getName(),
609 OrderByComparator.class.getName()
610 });
611 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
612 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
613 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
614 SocialRelationImpl.class,
615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
616 new String[] { String.class.getName(), Long.class.getName() },
617 SocialRelationModelImpl.UUID_COLUMN_BITMASK |
618 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
619 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
620 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
621 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
622 new String[] { String.class.getName(), Long.class.getName() });
623
624
632 public List<SocialRelation> findByUuid_C(String uuid, long companyId)
633 throws SystemException {
634 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
635 QueryUtil.ALL_POS, null);
636 }
637
638
652 public List<SocialRelation> findByUuid_C(String uuid, long companyId,
653 int start, int end) throws SystemException {
654 return findByUuid_C(uuid, companyId, start, end, null);
655 }
656
657
672 public List<SocialRelation> findByUuid_C(String uuid, long companyId,
673 int start, int end, OrderByComparator orderByComparator)
674 throws SystemException {
675 boolean pagination = true;
676 FinderPath finderPath = null;
677 Object[] finderArgs = null;
678
679 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
680 (orderByComparator == null)) {
681 pagination = false;
682 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
683 finderArgs = new Object[] { uuid, companyId };
684 }
685 else {
686 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
687 finderArgs = new Object[] {
688 uuid, companyId,
689
690 start, end, orderByComparator
691 };
692 }
693
694 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
695 finderArgs, this);
696
697 if ((list != null) && !list.isEmpty()) {
698 for (SocialRelation socialRelation : list) {
699 if (!Validator.equals(uuid, socialRelation.getUuid()) ||
700 (companyId != socialRelation.getCompanyId())) {
701 list = null;
702
703 break;
704 }
705 }
706 }
707
708 if (list == null) {
709 StringBundler query = null;
710
711 if (orderByComparator != null) {
712 query = new StringBundler(4 +
713 (orderByComparator.getOrderByFields().length * 3));
714 }
715 else {
716 query = new StringBundler(4);
717 }
718
719 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
720
721 if (uuid == null) {
722 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
723 }
724 else {
725 if (uuid.equals(StringPool.BLANK)) {
726 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
727 }
728 else {
729 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
730 }
731 }
732
733 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
734
735 if (orderByComparator != null) {
736 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
737 orderByComparator);
738 }
739 else
740 if (pagination) {
741 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
742 }
743
744 String sql = query.toString();
745
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 Query q = session.createQuery(sql);
752
753 QueryPos qPos = QueryPos.getInstance(q);
754
755 if (uuid != null) {
756 qPos.add(uuid);
757 }
758
759 qPos.add(companyId);
760
761 if (!pagination) {
762 list = (List<SocialRelation>)QueryUtil.list(q,
763 getDialect(), start, end, false);
764
765 Collections.sort(list);
766
767 list = new UnmodifiableList<SocialRelation>(list);
768 }
769 else {
770 list = (List<SocialRelation>)QueryUtil.list(q,
771 getDialect(), start, end);
772 }
773
774 cacheResult(list);
775
776 FinderCacheUtil.putResult(finderPath, finderArgs, list);
777 }
778 catch (Exception e) {
779 FinderCacheUtil.removeResult(finderPath, finderArgs);
780
781 throw processException(e);
782 }
783 finally {
784 closeSession(session);
785 }
786 }
787
788 return list;
789 }
790
791
801 public SocialRelation findByUuid_C_First(String uuid, long companyId,
802 OrderByComparator orderByComparator)
803 throws NoSuchRelationException, SystemException {
804 SocialRelation socialRelation = fetchByUuid_C_First(uuid, companyId,
805 orderByComparator);
806
807 if (socialRelation != null) {
808 return socialRelation;
809 }
810
811 StringBundler msg = new StringBundler(6);
812
813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
814
815 msg.append("uuid=");
816 msg.append(uuid);
817
818 msg.append(", companyId=");
819 msg.append(companyId);
820
821 msg.append(StringPool.CLOSE_CURLY_BRACE);
822
823 throw new NoSuchRelationException(msg.toString());
824 }
825
826
835 public SocialRelation fetchByUuid_C_First(String uuid, long companyId,
836 OrderByComparator orderByComparator) throws SystemException {
837 List<SocialRelation> list = findByUuid_C(uuid, companyId, 0, 1,
838 orderByComparator);
839
840 if (!list.isEmpty()) {
841 return list.get(0);
842 }
843
844 return null;
845 }
846
847
857 public SocialRelation findByUuid_C_Last(String uuid, long companyId,
858 OrderByComparator orderByComparator)
859 throws NoSuchRelationException, SystemException {
860 SocialRelation socialRelation = fetchByUuid_C_Last(uuid, companyId,
861 orderByComparator);
862
863 if (socialRelation != null) {
864 return socialRelation;
865 }
866
867 StringBundler msg = new StringBundler(6);
868
869 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
870
871 msg.append("uuid=");
872 msg.append(uuid);
873
874 msg.append(", companyId=");
875 msg.append(companyId);
876
877 msg.append(StringPool.CLOSE_CURLY_BRACE);
878
879 throw new NoSuchRelationException(msg.toString());
880 }
881
882
891 public SocialRelation fetchByUuid_C_Last(String uuid, long companyId,
892 OrderByComparator orderByComparator) throws SystemException {
893 int count = countByUuid_C(uuid, companyId);
894
895 List<SocialRelation> list = findByUuid_C(uuid, companyId, count - 1,
896 count, orderByComparator);
897
898 if (!list.isEmpty()) {
899 return list.get(0);
900 }
901
902 return null;
903 }
904
905
916 public SocialRelation[] findByUuid_C_PrevAndNext(long relationId,
917 String uuid, long companyId, OrderByComparator orderByComparator)
918 throws NoSuchRelationException, SystemException {
919 SocialRelation socialRelation = findByPrimaryKey(relationId);
920
921 Session session = null;
922
923 try {
924 session = openSession();
925
926 SocialRelation[] array = new SocialRelationImpl[3];
927
928 array[0] = getByUuid_C_PrevAndNext(session, socialRelation, uuid,
929 companyId, orderByComparator, true);
930
931 array[1] = socialRelation;
932
933 array[2] = getByUuid_C_PrevAndNext(session, socialRelation, uuid,
934 companyId, orderByComparator, false);
935
936 return array;
937 }
938 catch (Exception e) {
939 throw processException(e);
940 }
941 finally {
942 closeSession(session);
943 }
944 }
945
946 protected SocialRelation getByUuid_C_PrevAndNext(Session session,
947 SocialRelation socialRelation, String uuid, long companyId,
948 OrderByComparator orderByComparator, boolean previous) {
949 StringBundler query = null;
950
951 if (orderByComparator != null) {
952 query = new StringBundler(6 +
953 (orderByComparator.getOrderByFields().length * 6));
954 }
955 else {
956 query = new StringBundler(3);
957 }
958
959 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
960
961 if (uuid == null) {
962 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
963 }
964 else {
965 if (uuid.equals(StringPool.BLANK)) {
966 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
967 }
968 else {
969 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
970 }
971 }
972
973 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
974
975 if (orderByComparator != null) {
976 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
977
978 if (orderByConditionFields.length > 0) {
979 query.append(WHERE_AND);
980 }
981
982 for (int i = 0; i < orderByConditionFields.length; i++) {
983 query.append(_ORDER_BY_ENTITY_ALIAS);
984 query.append(orderByConditionFields[i]);
985
986 if ((i + 1) < orderByConditionFields.length) {
987 if (orderByComparator.isAscending() ^ previous) {
988 query.append(WHERE_GREATER_THAN_HAS_NEXT);
989 }
990 else {
991 query.append(WHERE_LESSER_THAN_HAS_NEXT);
992 }
993 }
994 else {
995 if (orderByComparator.isAscending() ^ previous) {
996 query.append(WHERE_GREATER_THAN);
997 }
998 else {
999 query.append(WHERE_LESSER_THAN);
1000 }
1001 }
1002 }
1003
1004 query.append(ORDER_BY_CLAUSE);
1005
1006 String[] orderByFields = orderByComparator.getOrderByFields();
1007
1008 for (int i = 0; i < orderByFields.length; i++) {
1009 query.append(_ORDER_BY_ENTITY_ALIAS);
1010 query.append(orderByFields[i]);
1011
1012 if ((i + 1) < orderByFields.length) {
1013 if (orderByComparator.isAscending() ^ previous) {
1014 query.append(ORDER_BY_ASC_HAS_NEXT);
1015 }
1016 else {
1017 query.append(ORDER_BY_DESC_HAS_NEXT);
1018 }
1019 }
1020 else {
1021 if (orderByComparator.isAscending() ^ previous) {
1022 query.append(ORDER_BY_ASC);
1023 }
1024 else {
1025 query.append(ORDER_BY_DESC);
1026 }
1027 }
1028 }
1029 }
1030 else {
1031 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1032 }
1033
1034 String sql = query.toString();
1035
1036 Query q = session.createQuery(sql);
1037
1038 q.setFirstResult(0);
1039 q.setMaxResults(2);
1040
1041 QueryPos qPos = QueryPos.getInstance(q);
1042
1043 if (uuid != null) {
1044 qPos.add(uuid);
1045 }
1046
1047 qPos.add(companyId);
1048
1049 if (orderByComparator != null) {
1050 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1051
1052 for (Object value : values) {
1053 qPos.add(value);
1054 }
1055 }
1056
1057 List<SocialRelation> list = q.list();
1058
1059 if (list.size() == 2) {
1060 return list.get(1);
1061 }
1062 else {
1063 return null;
1064 }
1065 }
1066
1067
1074 public void removeByUuid_C(String uuid, long companyId)
1075 throws SystemException {
1076 for (SocialRelation socialRelation : findByUuid_C(uuid, companyId,
1077 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1078 remove(socialRelation);
1079 }
1080 }
1081
1082
1090 public int countByUuid_C(String uuid, long companyId)
1091 throws SystemException {
1092 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1093
1094 Object[] finderArgs = new Object[] { uuid, companyId };
1095
1096 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1097 this);
1098
1099 if (count == null) {
1100 StringBundler query = new StringBundler(3);
1101
1102 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
1103
1104 if (uuid == null) {
1105 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1106 }
1107 else {
1108 if (uuid.equals(StringPool.BLANK)) {
1109 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1110 }
1111 else {
1112 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1113 }
1114 }
1115
1116 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1117
1118 String sql = query.toString();
1119
1120 Session session = null;
1121
1122 try {
1123 session = openSession();
1124
1125 Query q = session.createQuery(sql);
1126
1127 QueryPos qPos = QueryPos.getInstance(q);
1128
1129 if (uuid != null) {
1130 qPos.add(uuid);
1131 }
1132
1133 qPos.add(companyId);
1134
1135 count = (Long)q.uniqueResult();
1136
1137 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1138 }
1139 catch (Exception e) {
1140 FinderCacheUtil.removeResult(finderPath, finderArgs);
1141
1142 throw processException(e);
1143 }
1144 finally {
1145 closeSession(session);
1146 }
1147 }
1148
1149 return count.intValue();
1150 }
1151
1152 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "socialRelation.uuid IS NULL AND ";
1153 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "socialRelation.uuid = ? AND ";
1154 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?) AND ";
1155 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "socialRelation.companyId = ?";
1156 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1157 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1158 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1159 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1160 "findByCompanyId",
1161 new String[] {
1162 Long.class.getName(),
1163
1164 Integer.class.getName(), Integer.class.getName(),
1165 OrderByComparator.class.getName()
1166 });
1167 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1168 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1169 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1170 SocialRelationImpl.class,
1171 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1172 new String[] { Long.class.getName() },
1173 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
1174 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1175 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1176 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1177 new String[] { Long.class.getName() });
1178
1179
1186 public List<SocialRelation> findByCompanyId(long companyId)
1187 throws SystemException {
1188 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1189 null);
1190 }
1191
1192
1205 public List<SocialRelation> findByCompanyId(long companyId, int start,
1206 int end) throws SystemException {
1207 return findByCompanyId(companyId, start, end, null);
1208 }
1209
1210
1224 public List<SocialRelation> findByCompanyId(long companyId, int start,
1225 int end, OrderByComparator orderByComparator) throws SystemException {
1226 boolean pagination = true;
1227 FinderPath finderPath = null;
1228 Object[] finderArgs = null;
1229
1230 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1231 (orderByComparator == null)) {
1232 pagination = false;
1233 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1234 finderArgs = new Object[] { companyId };
1235 }
1236 else {
1237 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1238 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1239 }
1240
1241 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1242 finderArgs, this);
1243
1244 if ((list != null) && !list.isEmpty()) {
1245 for (SocialRelation socialRelation : list) {
1246 if ((companyId != socialRelation.getCompanyId())) {
1247 list = null;
1248
1249 break;
1250 }
1251 }
1252 }
1253
1254 if (list == null) {
1255 StringBundler query = null;
1256
1257 if (orderByComparator != null) {
1258 query = new StringBundler(3 +
1259 (orderByComparator.getOrderByFields().length * 3));
1260 }
1261 else {
1262 query = new StringBundler(3);
1263 }
1264
1265 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1266
1267 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1268
1269 if (orderByComparator != null) {
1270 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1271 orderByComparator);
1272 }
1273 else
1274 if (pagination) {
1275 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1276 }
1277
1278 String sql = query.toString();
1279
1280 Session session = null;
1281
1282 try {
1283 session = openSession();
1284
1285 Query q = session.createQuery(sql);
1286
1287 QueryPos qPos = QueryPos.getInstance(q);
1288
1289 qPos.add(companyId);
1290
1291 if (!pagination) {
1292 list = (List<SocialRelation>)QueryUtil.list(q,
1293 getDialect(), start, end, false);
1294
1295 Collections.sort(list);
1296
1297 list = new UnmodifiableList<SocialRelation>(list);
1298 }
1299 else {
1300 list = (List<SocialRelation>)QueryUtil.list(q,
1301 getDialect(), start, end);
1302 }
1303
1304 cacheResult(list);
1305
1306 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1307 }
1308 catch (Exception e) {
1309 FinderCacheUtil.removeResult(finderPath, finderArgs);
1310
1311 throw processException(e);
1312 }
1313 finally {
1314 closeSession(session);
1315 }
1316 }
1317
1318 return list;
1319 }
1320
1321
1330 public SocialRelation findByCompanyId_First(long companyId,
1331 OrderByComparator orderByComparator)
1332 throws NoSuchRelationException, SystemException {
1333 SocialRelation socialRelation = fetchByCompanyId_First(companyId,
1334 orderByComparator);
1335
1336 if (socialRelation != null) {
1337 return socialRelation;
1338 }
1339
1340 StringBundler msg = new StringBundler(4);
1341
1342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1343
1344 msg.append("companyId=");
1345 msg.append(companyId);
1346
1347 msg.append(StringPool.CLOSE_CURLY_BRACE);
1348
1349 throw new NoSuchRelationException(msg.toString());
1350 }
1351
1352
1360 public SocialRelation fetchByCompanyId_First(long companyId,
1361 OrderByComparator orderByComparator) throws SystemException {
1362 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1363 orderByComparator);
1364
1365 if (!list.isEmpty()) {
1366 return list.get(0);
1367 }
1368
1369 return null;
1370 }
1371
1372
1381 public SocialRelation findByCompanyId_Last(long companyId,
1382 OrderByComparator orderByComparator)
1383 throws NoSuchRelationException, SystemException {
1384 SocialRelation socialRelation = fetchByCompanyId_Last(companyId,
1385 orderByComparator);
1386
1387 if (socialRelation != null) {
1388 return socialRelation;
1389 }
1390
1391 StringBundler msg = new StringBundler(4);
1392
1393 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1394
1395 msg.append("companyId=");
1396 msg.append(companyId);
1397
1398 msg.append(StringPool.CLOSE_CURLY_BRACE);
1399
1400 throw new NoSuchRelationException(msg.toString());
1401 }
1402
1403
1411 public SocialRelation fetchByCompanyId_Last(long companyId,
1412 OrderByComparator orderByComparator) throws SystemException {
1413 int count = countByCompanyId(companyId);
1414
1415 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1416 count, orderByComparator);
1417
1418 if (!list.isEmpty()) {
1419 return list.get(0);
1420 }
1421
1422 return null;
1423 }
1424
1425
1435 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1436 long companyId, 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] = getByCompanyId_PrevAndNext(session, socialRelation,
1448 companyId, orderByComparator, true);
1449
1450 array[1] = socialRelation;
1451
1452 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1453 companyId, 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 getByCompanyId_PrevAndNext(Session session,
1466 SocialRelation socialRelation, long companyId,
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_COMPANYID_COMPANYID_2);
1481
1482 if (orderByComparator != null) {
1483 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1484
1485 if (orderByConditionFields.length > 0) {
1486 query.append(WHERE_AND);
1487 }
1488
1489 for (int i = 0; i < orderByConditionFields.length; i++) {
1490 query.append(_ORDER_BY_ENTITY_ALIAS);
1491 query.append(orderByConditionFields[i]);
1492
1493 if ((i + 1) < orderByConditionFields.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 String[] orderByFields = orderByComparator.getOrderByFields();
1514
1515 for (int i = 0; i < orderByFields.length; i++) {
1516 query.append(_ORDER_BY_ENTITY_ALIAS);
1517 query.append(orderByFields[i]);
1518
1519 if ((i + 1) < orderByFields.length) {
1520 if (orderByComparator.isAscending() ^ previous) {
1521 query.append(ORDER_BY_ASC_HAS_NEXT);
1522 }
1523 else {
1524 query.append(ORDER_BY_DESC_HAS_NEXT);
1525 }
1526 }
1527 else {
1528 if (orderByComparator.isAscending() ^ previous) {
1529 query.append(ORDER_BY_ASC);
1530 }
1531 else {
1532 query.append(ORDER_BY_DESC);
1533 }
1534 }
1535 }
1536 }
1537 else {
1538 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1539 }
1540
1541 String sql = query.toString();
1542
1543 Query q = session.createQuery(sql);
1544
1545 q.setFirstResult(0);
1546 q.setMaxResults(2);
1547
1548 QueryPos qPos = QueryPos.getInstance(q);
1549
1550 qPos.add(companyId);
1551
1552 if (orderByComparator != null) {
1553 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1554
1555 for (Object value : values) {
1556 qPos.add(value);
1557 }
1558 }
1559
1560 List<SocialRelation> list = q.list();
1561
1562 if (list.size() == 2) {
1563 return list.get(1);
1564 }
1565 else {
1566 return null;
1567 }
1568 }
1569
1570
1576 public void removeByCompanyId(long companyId) throws SystemException {
1577 for (SocialRelation socialRelation : findByCompanyId(companyId,
1578 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1579 remove(socialRelation);
1580 }
1581 }
1582
1583
1590 public int countByCompanyId(long companyId) throws SystemException {
1591 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1592
1593 Object[] finderArgs = new Object[] { companyId };
1594
1595 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1596 this);
1597
1598 if (count == null) {
1599 StringBundler query = new StringBundler(2);
1600
1601 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
1602
1603 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1604
1605 String sql = query.toString();
1606
1607 Session session = null;
1608
1609 try {
1610 session = openSession();
1611
1612 Query q = session.createQuery(sql);
1613
1614 QueryPos qPos = QueryPos.getInstance(q);
1615
1616 qPos.add(companyId);
1617
1618 count = (Long)q.uniqueResult();
1619
1620 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1621 }
1622 catch (Exception e) {
1623 FinderCacheUtil.removeResult(finderPath, finderArgs);
1624
1625 throw processException(e);
1626 }
1627 finally {
1628 closeSession(session);
1629 }
1630 }
1631
1632 return count.intValue();
1633 }
1634
1635 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
1636 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1637 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1638 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1639 "findByUserId1",
1640 new String[] {
1641 Long.class.getName(),
1642
1643 Integer.class.getName(), Integer.class.getName(),
1644 OrderByComparator.class.getName()
1645 });
1646 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1 =
1647 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1648 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1649 SocialRelationImpl.class,
1650 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId1",
1651 new String[] { Long.class.getName() },
1652 SocialRelationModelImpl.USERID1_COLUMN_BITMASK);
1653 public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1654 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1655 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId1",
1656 new String[] { Long.class.getName() });
1657
1658
1665 public List<SocialRelation> findByUserId1(long userId1)
1666 throws SystemException {
1667 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1668 }
1669
1670
1683 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1684 throws SystemException {
1685 return findByUserId1(userId1, start, end, null);
1686 }
1687
1688
1702 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1703 OrderByComparator orderByComparator) throws SystemException {
1704 boolean pagination = true;
1705 FinderPath finderPath = null;
1706 Object[] finderArgs = null;
1707
1708 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1709 (orderByComparator == null)) {
1710 pagination = false;
1711 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1712 finderArgs = new Object[] { userId1 };
1713 }
1714 else {
1715 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1716 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1717 }
1718
1719 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1720 finderArgs, this);
1721
1722 if ((list != null) && !list.isEmpty()) {
1723 for (SocialRelation socialRelation : list) {
1724 if ((userId1 != socialRelation.getUserId1())) {
1725 list = null;
1726
1727 break;
1728 }
1729 }
1730 }
1731
1732 if (list == null) {
1733 StringBundler query = null;
1734
1735 if (orderByComparator != null) {
1736 query = new StringBundler(3 +
1737 (orderByComparator.getOrderByFields().length * 3));
1738 }
1739 else {
1740 query = new StringBundler(3);
1741 }
1742
1743 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1744
1745 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1746
1747 if (orderByComparator != null) {
1748 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1749 orderByComparator);
1750 }
1751 else
1752 if (pagination) {
1753 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1754 }
1755
1756 String sql = query.toString();
1757
1758 Session session = null;
1759
1760 try {
1761 session = openSession();
1762
1763 Query q = session.createQuery(sql);
1764
1765 QueryPos qPos = QueryPos.getInstance(q);
1766
1767 qPos.add(userId1);
1768
1769 if (!pagination) {
1770 list = (List<SocialRelation>)QueryUtil.list(q,
1771 getDialect(), start, end, false);
1772
1773 Collections.sort(list);
1774
1775 list = new UnmodifiableList<SocialRelation>(list);
1776 }
1777 else {
1778 list = (List<SocialRelation>)QueryUtil.list(q,
1779 getDialect(), start, end);
1780 }
1781
1782 cacheResult(list);
1783
1784 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1785 }
1786 catch (Exception e) {
1787 FinderCacheUtil.removeResult(finderPath, finderArgs);
1788
1789 throw processException(e);
1790 }
1791 finally {
1792 closeSession(session);
1793 }
1794 }
1795
1796 return list;
1797 }
1798
1799
1808 public SocialRelation findByUserId1_First(long userId1,
1809 OrderByComparator orderByComparator)
1810 throws NoSuchRelationException, SystemException {
1811 SocialRelation socialRelation = fetchByUserId1_First(userId1,
1812 orderByComparator);
1813
1814 if (socialRelation != null) {
1815 return socialRelation;
1816 }
1817
1818 StringBundler msg = new StringBundler(4);
1819
1820 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1821
1822 msg.append("userId1=");
1823 msg.append(userId1);
1824
1825 msg.append(StringPool.CLOSE_CURLY_BRACE);
1826
1827 throw new NoSuchRelationException(msg.toString());
1828 }
1829
1830
1838 public SocialRelation fetchByUserId1_First(long userId1,
1839 OrderByComparator orderByComparator) throws SystemException {
1840 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1841 orderByComparator);
1842
1843 if (!list.isEmpty()) {
1844 return list.get(0);
1845 }
1846
1847 return null;
1848 }
1849
1850
1859 public SocialRelation findByUserId1_Last(long userId1,
1860 OrderByComparator orderByComparator)
1861 throws NoSuchRelationException, SystemException {
1862 SocialRelation socialRelation = fetchByUserId1_Last(userId1,
1863 orderByComparator);
1864
1865 if (socialRelation != null) {
1866 return socialRelation;
1867 }
1868
1869 StringBundler msg = new StringBundler(4);
1870
1871 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1872
1873 msg.append("userId1=");
1874 msg.append(userId1);
1875
1876 msg.append(StringPool.CLOSE_CURLY_BRACE);
1877
1878 throw new NoSuchRelationException(msg.toString());
1879 }
1880
1881
1889 public SocialRelation fetchByUserId1_Last(long userId1,
1890 OrderByComparator orderByComparator) throws SystemException {
1891 int count = countByUserId1(userId1);
1892
1893 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1894 orderByComparator);
1895
1896 if (!list.isEmpty()) {
1897 return list.get(0);
1898 }
1899
1900 return null;
1901 }
1902
1903
1913 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1914 long userId1, OrderByComparator orderByComparator)
1915 throws NoSuchRelationException, SystemException {
1916 SocialRelation socialRelation = findByPrimaryKey(relationId);
1917
1918 Session session = null;
1919
1920 try {
1921 session = openSession();
1922
1923 SocialRelation[] array = new SocialRelationImpl[3];
1924
1925 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1926 userId1, orderByComparator, true);
1927
1928 array[1] = socialRelation;
1929
1930 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1931 userId1, orderByComparator, false);
1932
1933 return array;
1934 }
1935 catch (Exception e) {
1936 throw processException(e);
1937 }
1938 finally {
1939 closeSession(session);
1940 }
1941 }
1942
1943 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1944 SocialRelation socialRelation, long userId1,
1945 OrderByComparator orderByComparator, boolean previous) {
1946 StringBundler query = null;
1947
1948 if (orderByComparator != null) {
1949 query = new StringBundler(6 +
1950 (orderByComparator.getOrderByFields().length * 6));
1951 }
1952 else {
1953 query = new StringBundler(3);
1954 }
1955
1956 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1957
1958 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1959
1960 if (orderByComparator != null) {
1961 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1962
1963 if (orderByConditionFields.length > 0) {
1964 query.append(WHERE_AND);
1965 }
1966
1967 for (int i = 0; i < orderByConditionFields.length; i++) {
1968 query.append(_ORDER_BY_ENTITY_ALIAS);
1969 query.append(orderByConditionFields[i]);
1970
1971 if ((i + 1) < orderByConditionFields.length) {
1972 if (orderByComparator.isAscending() ^ previous) {
1973 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1974 }
1975 else {
1976 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1977 }
1978 }
1979 else {
1980 if (orderByComparator.isAscending() ^ previous) {
1981 query.append(WHERE_GREATER_THAN);
1982 }
1983 else {
1984 query.append(WHERE_LESSER_THAN);
1985 }
1986 }
1987 }
1988
1989 query.append(ORDER_BY_CLAUSE);
1990
1991 String[] orderByFields = orderByComparator.getOrderByFields();
1992
1993 for (int i = 0; i < orderByFields.length; i++) {
1994 query.append(_ORDER_BY_ENTITY_ALIAS);
1995 query.append(orderByFields[i]);
1996
1997 if ((i + 1) < orderByFields.length) {
1998 if (orderByComparator.isAscending() ^ previous) {
1999 query.append(ORDER_BY_ASC_HAS_NEXT);
2000 }
2001 else {
2002 query.append(ORDER_BY_DESC_HAS_NEXT);
2003 }
2004 }
2005 else {
2006 if (orderByComparator.isAscending() ^ previous) {
2007 query.append(ORDER_BY_ASC);
2008 }
2009 else {
2010 query.append(ORDER_BY_DESC);
2011 }
2012 }
2013 }
2014 }
2015 else {
2016 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2017 }
2018
2019 String sql = query.toString();
2020
2021 Query q = session.createQuery(sql);
2022
2023 q.setFirstResult(0);
2024 q.setMaxResults(2);
2025
2026 QueryPos qPos = QueryPos.getInstance(q);
2027
2028 qPos.add(userId1);
2029
2030 if (orderByComparator != null) {
2031 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2032
2033 for (Object value : values) {
2034 qPos.add(value);
2035 }
2036 }
2037
2038 List<SocialRelation> list = q.list();
2039
2040 if (list.size() == 2) {
2041 return list.get(1);
2042 }
2043 else {
2044 return null;
2045 }
2046 }
2047
2048
2054 public void removeByUserId1(long userId1) throws SystemException {
2055 for (SocialRelation socialRelation : findByUserId1(userId1,
2056 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2057 remove(socialRelation);
2058 }
2059 }
2060
2061
2068 public int countByUserId1(long userId1) throws SystemException {
2069 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID1;
2070
2071 Object[] finderArgs = new Object[] { userId1 };
2072
2073 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2074 this);
2075
2076 if (count == null) {
2077 StringBundler query = new StringBundler(2);
2078
2079 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2080
2081 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
2082
2083 String sql = query.toString();
2084
2085 Session session = null;
2086
2087 try {
2088 session = openSession();
2089
2090 Query q = session.createQuery(sql);
2091
2092 QueryPos qPos = QueryPos.getInstance(q);
2093
2094 qPos.add(userId1);
2095
2096 count = (Long)q.uniqueResult();
2097
2098 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2099 }
2100 catch (Exception e) {
2101 FinderCacheUtil.removeResult(finderPath, finderArgs);
2102
2103 throw processException(e);
2104 }
2105 finally {
2106 closeSession(session);
2107 }
2108 }
2109
2110 return count.intValue();
2111 }
2112
2113 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
2114 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2115 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2116 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2117 "findByUserId2",
2118 new String[] {
2119 Long.class.getName(),
2120
2121 Integer.class.getName(), Integer.class.getName(),
2122 OrderByComparator.class.getName()
2123 });
2124 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2 =
2125 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2126 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2127 SocialRelationImpl.class,
2128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId2",
2129 new String[] { Long.class.getName() },
2130 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
2131 public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2132 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2133 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId2",
2134 new String[] { Long.class.getName() });
2135
2136
2143 public List<SocialRelation> findByUserId2(long userId2)
2144 throws SystemException {
2145 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2146 }
2147
2148
2161 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
2162 throws SystemException {
2163 return findByUserId2(userId2, start, end, null);
2164 }
2165
2166
2180 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
2181 OrderByComparator orderByComparator) throws SystemException {
2182 boolean pagination = true;
2183 FinderPath finderPath = null;
2184 Object[] finderArgs = null;
2185
2186 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2187 (orderByComparator == null)) {
2188 pagination = false;
2189 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
2190 finderArgs = new Object[] { userId2 };
2191 }
2192 else {
2193 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
2194 finderArgs = new Object[] { userId2, start, end, orderByComparator };
2195 }
2196
2197 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2198 finderArgs, this);
2199
2200 if ((list != null) && !list.isEmpty()) {
2201 for (SocialRelation socialRelation : list) {
2202 if ((userId2 != socialRelation.getUserId2())) {
2203 list = null;
2204
2205 break;
2206 }
2207 }
2208 }
2209
2210 if (list == null) {
2211 StringBundler query = null;
2212
2213 if (orderByComparator != null) {
2214 query = new StringBundler(3 +
2215 (orderByComparator.getOrderByFields().length * 3));
2216 }
2217 else {
2218 query = new StringBundler(3);
2219 }
2220
2221 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2222
2223 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2224
2225 if (orderByComparator != null) {
2226 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2227 orderByComparator);
2228 }
2229 else
2230 if (pagination) {
2231 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2232 }
2233
2234 String sql = query.toString();
2235
2236 Session session = null;
2237
2238 try {
2239 session = openSession();
2240
2241 Query q = session.createQuery(sql);
2242
2243 QueryPos qPos = QueryPos.getInstance(q);
2244
2245 qPos.add(userId2);
2246
2247 if (!pagination) {
2248 list = (List<SocialRelation>)QueryUtil.list(q,
2249 getDialect(), start, end, false);
2250
2251 Collections.sort(list);
2252
2253 list = new UnmodifiableList<SocialRelation>(list);
2254 }
2255 else {
2256 list = (List<SocialRelation>)QueryUtil.list(q,
2257 getDialect(), start, end);
2258 }
2259
2260 cacheResult(list);
2261
2262 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2263 }
2264 catch (Exception e) {
2265 FinderCacheUtil.removeResult(finderPath, finderArgs);
2266
2267 throw processException(e);
2268 }
2269 finally {
2270 closeSession(session);
2271 }
2272 }
2273
2274 return list;
2275 }
2276
2277
2286 public SocialRelation findByUserId2_First(long userId2,
2287 OrderByComparator orderByComparator)
2288 throws NoSuchRelationException, SystemException {
2289 SocialRelation socialRelation = fetchByUserId2_First(userId2,
2290 orderByComparator);
2291
2292 if (socialRelation != null) {
2293 return socialRelation;
2294 }
2295
2296 StringBundler msg = new StringBundler(4);
2297
2298 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2299
2300 msg.append("userId2=");
2301 msg.append(userId2);
2302
2303 msg.append(StringPool.CLOSE_CURLY_BRACE);
2304
2305 throw new NoSuchRelationException(msg.toString());
2306 }
2307
2308
2316 public SocialRelation fetchByUserId2_First(long userId2,
2317 OrderByComparator orderByComparator) throws SystemException {
2318 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2319 orderByComparator);
2320
2321 if (!list.isEmpty()) {
2322 return list.get(0);
2323 }
2324
2325 return null;
2326 }
2327
2328
2337 public SocialRelation findByUserId2_Last(long userId2,
2338 OrderByComparator orderByComparator)
2339 throws NoSuchRelationException, SystemException {
2340 SocialRelation socialRelation = fetchByUserId2_Last(userId2,
2341 orderByComparator);
2342
2343 if (socialRelation != null) {
2344 return socialRelation;
2345 }
2346
2347 StringBundler msg = new StringBundler(4);
2348
2349 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2350
2351 msg.append("userId2=");
2352 msg.append(userId2);
2353
2354 msg.append(StringPool.CLOSE_CURLY_BRACE);
2355
2356 throw new NoSuchRelationException(msg.toString());
2357 }
2358
2359
2367 public SocialRelation fetchByUserId2_Last(long userId2,
2368 OrderByComparator orderByComparator) throws SystemException {
2369 int count = countByUserId2(userId2);
2370
2371 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2372 orderByComparator);
2373
2374 if (!list.isEmpty()) {
2375 return list.get(0);
2376 }
2377
2378 return null;
2379 }
2380
2381
2391 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2392 long userId2, OrderByComparator orderByComparator)
2393 throws NoSuchRelationException, SystemException {
2394 SocialRelation socialRelation = findByPrimaryKey(relationId);
2395
2396 Session session = null;
2397
2398 try {
2399 session = openSession();
2400
2401 SocialRelation[] array = new SocialRelationImpl[3];
2402
2403 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2404 userId2, orderByComparator, true);
2405
2406 array[1] = socialRelation;
2407
2408 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2409 userId2, orderByComparator, false);
2410
2411 return array;
2412 }
2413 catch (Exception e) {
2414 throw processException(e);
2415 }
2416 finally {
2417 closeSession(session);
2418 }
2419 }
2420
2421 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2422 SocialRelation socialRelation, long userId2,
2423 OrderByComparator orderByComparator, boolean previous) {
2424 StringBundler query = null;
2425
2426 if (orderByComparator != null) {
2427 query = new StringBundler(6 +
2428 (orderByComparator.getOrderByFields().length * 6));
2429 }
2430 else {
2431 query = new StringBundler(3);
2432 }
2433
2434 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2435
2436 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2437
2438 if (orderByComparator != null) {
2439 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2440
2441 if (orderByConditionFields.length > 0) {
2442 query.append(WHERE_AND);
2443 }
2444
2445 for (int i = 0; i < orderByConditionFields.length; i++) {
2446 query.append(_ORDER_BY_ENTITY_ALIAS);
2447 query.append(orderByConditionFields[i]);
2448
2449 if ((i + 1) < orderByConditionFields.length) {
2450 if (orderByComparator.isAscending() ^ previous) {
2451 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2452 }
2453 else {
2454 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2455 }
2456 }
2457 else {
2458 if (orderByComparator.isAscending() ^ previous) {
2459 query.append(WHERE_GREATER_THAN);
2460 }
2461 else {
2462 query.append(WHERE_LESSER_THAN);
2463 }
2464 }
2465 }
2466
2467 query.append(ORDER_BY_CLAUSE);
2468
2469 String[] orderByFields = orderByComparator.getOrderByFields();
2470
2471 for (int i = 0; i < orderByFields.length; i++) {
2472 query.append(_ORDER_BY_ENTITY_ALIAS);
2473 query.append(orderByFields[i]);
2474
2475 if ((i + 1) < orderByFields.length) {
2476 if (orderByComparator.isAscending() ^ previous) {
2477 query.append(ORDER_BY_ASC_HAS_NEXT);
2478 }
2479 else {
2480 query.append(ORDER_BY_DESC_HAS_NEXT);
2481 }
2482 }
2483 else {
2484 if (orderByComparator.isAscending() ^ previous) {
2485 query.append(ORDER_BY_ASC);
2486 }
2487 else {
2488 query.append(ORDER_BY_DESC);
2489 }
2490 }
2491 }
2492 }
2493 else {
2494 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2495 }
2496
2497 String sql = query.toString();
2498
2499 Query q = session.createQuery(sql);
2500
2501 q.setFirstResult(0);
2502 q.setMaxResults(2);
2503
2504 QueryPos qPos = QueryPos.getInstance(q);
2505
2506 qPos.add(userId2);
2507
2508 if (orderByComparator != null) {
2509 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2510
2511 for (Object value : values) {
2512 qPos.add(value);
2513 }
2514 }
2515
2516 List<SocialRelation> list = q.list();
2517
2518 if (list.size() == 2) {
2519 return list.get(1);
2520 }
2521 else {
2522 return null;
2523 }
2524 }
2525
2526
2532 public void removeByUserId2(long userId2) throws SystemException {
2533 for (SocialRelation socialRelation : findByUserId2(userId2,
2534 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2535 remove(socialRelation);
2536 }
2537 }
2538
2539
2546 public int countByUserId2(long userId2) throws SystemException {
2547 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID2;
2548
2549 Object[] finderArgs = new Object[] { userId2 };
2550
2551 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2552 this);
2553
2554 if (count == null) {
2555 StringBundler query = new StringBundler(2);
2556
2557 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2558
2559 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2560
2561 String sql = query.toString();
2562
2563 Session session = null;
2564
2565 try {
2566 session = openSession();
2567
2568 Query q = session.createQuery(sql);
2569
2570 QueryPos qPos = QueryPos.getInstance(q);
2571
2572 qPos.add(userId2);
2573
2574 count = (Long)q.uniqueResult();
2575
2576 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2577 }
2578 catch (Exception e) {
2579 FinderCacheUtil.removeResult(finderPath, finderArgs);
2580
2581 throw processException(e);
2582 }
2583 finally {
2584 closeSession(session);
2585 }
2586 }
2587
2588 return count.intValue();
2589 }
2590
2591 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
2592 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2593 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2594 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2595 "findByType",
2596 new String[] {
2597 Integer.class.getName(),
2598
2599 Integer.class.getName(), Integer.class.getName(),
2600 OrderByComparator.class.getName()
2601 });
2602 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2603 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2604 SocialRelationImpl.class,
2605 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
2606 new String[] { Integer.class.getName() },
2607 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
2608 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2609 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2610 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
2611 new String[] { Integer.class.getName() });
2612
2613
2620 public List<SocialRelation> findByType(int type) throws SystemException {
2621 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2622 }
2623
2624
2637 public List<SocialRelation> findByType(int type, int start, int end)
2638 throws SystemException {
2639 return findByType(type, start, end, null);
2640 }
2641
2642
2656 public List<SocialRelation> findByType(int type, int start, int end,
2657 OrderByComparator orderByComparator) throws SystemException {
2658 boolean pagination = true;
2659 FinderPath finderPath = null;
2660 Object[] finderArgs = null;
2661
2662 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2663 (orderByComparator == null)) {
2664 pagination = false;
2665 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2666 finderArgs = new Object[] { type };
2667 }
2668 else {
2669 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2670 finderArgs = new Object[] { type, start, end, orderByComparator };
2671 }
2672
2673 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2674 finderArgs, this);
2675
2676 if ((list != null) && !list.isEmpty()) {
2677 for (SocialRelation socialRelation : list) {
2678 if ((type != socialRelation.getType())) {
2679 list = null;
2680
2681 break;
2682 }
2683 }
2684 }
2685
2686 if (list == null) {
2687 StringBundler query = null;
2688
2689 if (orderByComparator != null) {
2690 query = new StringBundler(3 +
2691 (orderByComparator.getOrderByFields().length * 3));
2692 }
2693 else {
2694 query = new StringBundler(3);
2695 }
2696
2697 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2698
2699 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2700
2701 if (orderByComparator != null) {
2702 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2703 orderByComparator);
2704 }
2705 else
2706 if (pagination) {
2707 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2708 }
2709
2710 String sql = query.toString();
2711
2712 Session session = null;
2713
2714 try {
2715 session = openSession();
2716
2717 Query q = session.createQuery(sql);
2718
2719 QueryPos qPos = QueryPos.getInstance(q);
2720
2721 qPos.add(type);
2722
2723 if (!pagination) {
2724 list = (List<SocialRelation>)QueryUtil.list(q,
2725 getDialect(), start, end, false);
2726
2727 Collections.sort(list);
2728
2729 list = new UnmodifiableList<SocialRelation>(list);
2730 }
2731 else {
2732 list = (List<SocialRelation>)QueryUtil.list(q,
2733 getDialect(), start, end);
2734 }
2735
2736 cacheResult(list);
2737
2738 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2739 }
2740 catch (Exception e) {
2741 FinderCacheUtil.removeResult(finderPath, finderArgs);
2742
2743 throw processException(e);
2744 }
2745 finally {
2746 closeSession(session);
2747 }
2748 }
2749
2750 return list;
2751 }
2752
2753
2762 public SocialRelation findByType_First(int type,
2763 OrderByComparator orderByComparator)
2764 throws NoSuchRelationException, SystemException {
2765 SocialRelation socialRelation = fetchByType_First(type,
2766 orderByComparator);
2767
2768 if (socialRelation != null) {
2769 return socialRelation;
2770 }
2771
2772 StringBundler msg = new StringBundler(4);
2773
2774 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2775
2776 msg.append("type=");
2777 msg.append(type);
2778
2779 msg.append(StringPool.CLOSE_CURLY_BRACE);
2780
2781 throw new NoSuchRelationException(msg.toString());
2782 }
2783
2784
2792 public SocialRelation fetchByType_First(int type,
2793 OrderByComparator orderByComparator) throws SystemException {
2794 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2795
2796 if (!list.isEmpty()) {
2797 return list.get(0);
2798 }
2799
2800 return null;
2801 }
2802
2803
2812 public SocialRelation findByType_Last(int type,
2813 OrderByComparator orderByComparator)
2814 throws NoSuchRelationException, SystemException {
2815 SocialRelation socialRelation = fetchByType_Last(type, orderByComparator);
2816
2817 if (socialRelation != null) {
2818 return socialRelation;
2819 }
2820
2821 StringBundler msg = new StringBundler(4);
2822
2823 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2824
2825 msg.append("type=");
2826 msg.append(type);
2827
2828 msg.append(StringPool.CLOSE_CURLY_BRACE);
2829
2830 throw new NoSuchRelationException(msg.toString());
2831 }
2832
2833
2841 public SocialRelation fetchByType_Last(int type,
2842 OrderByComparator orderByComparator) throws SystemException {
2843 int count = countByType(type);
2844
2845 List<SocialRelation> list = findByType(type, count - 1, count,
2846 orderByComparator);
2847
2848 if (!list.isEmpty()) {
2849 return list.get(0);
2850 }
2851
2852 return null;
2853 }
2854
2855
2865 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2866 OrderByComparator orderByComparator)
2867 throws NoSuchRelationException, SystemException {
2868 SocialRelation socialRelation = findByPrimaryKey(relationId);
2869
2870 Session session = null;
2871
2872 try {
2873 session = openSession();
2874
2875 SocialRelation[] array = new SocialRelationImpl[3];
2876
2877 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2878 orderByComparator, true);
2879
2880 array[1] = socialRelation;
2881
2882 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2883 orderByComparator, false);
2884
2885 return array;
2886 }
2887 catch (Exception e) {
2888 throw processException(e);
2889 }
2890 finally {
2891 closeSession(session);
2892 }
2893 }
2894
2895 protected SocialRelation getByType_PrevAndNext(Session session,
2896 SocialRelation socialRelation, int type,
2897 OrderByComparator orderByComparator, boolean previous) {
2898 StringBundler query = null;
2899
2900 if (orderByComparator != null) {
2901 query = new StringBundler(6 +
2902 (orderByComparator.getOrderByFields().length * 6));
2903 }
2904 else {
2905 query = new StringBundler(3);
2906 }
2907
2908 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2909
2910 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2911
2912 if (orderByComparator != null) {
2913 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2914
2915 if (orderByConditionFields.length > 0) {
2916 query.append(WHERE_AND);
2917 }
2918
2919 for (int i = 0; i < orderByConditionFields.length; i++) {
2920 query.append(_ORDER_BY_ENTITY_ALIAS);
2921 query.append(orderByConditionFields[i]);
2922
2923 if ((i + 1) < orderByConditionFields.length) {
2924 if (orderByComparator.isAscending() ^ previous) {
2925 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2926 }
2927 else {
2928 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2929 }
2930 }
2931 else {
2932 if (orderByComparator.isAscending() ^ previous) {
2933 query.append(WHERE_GREATER_THAN);
2934 }
2935 else {
2936 query.append(WHERE_LESSER_THAN);
2937 }
2938 }
2939 }
2940
2941 query.append(ORDER_BY_CLAUSE);
2942
2943 String[] orderByFields = orderByComparator.getOrderByFields();
2944
2945 for (int i = 0; i < orderByFields.length; i++) {
2946 query.append(_ORDER_BY_ENTITY_ALIAS);
2947 query.append(orderByFields[i]);
2948
2949 if ((i + 1) < orderByFields.length) {
2950 if (orderByComparator.isAscending() ^ previous) {
2951 query.append(ORDER_BY_ASC_HAS_NEXT);
2952 }
2953 else {
2954 query.append(ORDER_BY_DESC_HAS_NEXT);
2955 }
2956 }
2957 else {
2958 if (orderByComparator.isAscending() ^ previous) {
2959 query.append(ORDER_BY_ASC);
2960 }
2961 else {
2962 query.append(ORDER_BY_DESC);
2963 }
2964 }
2965 }
2966 }
2967 else {
2968 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2969 }
2970
2971 String sql = query.toString();
2972
2973 Query q = session.createQuery(sql);
2974
2975 q.setFirstResult(0);
2976 q.setMaxResults(2);
2977
2978 QueryPos qPos = QueryPos.getInstance(q);
2979
2980 qPos.add(type);
2981
2982 if (orderByComparator != null) {
2983 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2984
2985 for (Object value : values) {
2986 qPos.add(value);
2987 }
2988 }
2989
2990 List<SocialRelation> list = q.list();
2991
2992 if (list.size() == 2) {
2993 return list.get(1);
2994 }
2995 else {
2996 return null;
2997 }
2998 }
2999
3000
3006 public void removeByType(int type) throws SystemException {
3007 for (SocialRelation socialRelation : findByType(type,
3008 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3009 remove(socialRelation);
3010 }
3011 }
3012
3013
3020 public int countByType(int type) throws SystemException {
3021 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
3022
3023 Object[] finderArgs = new Object[] { type };
3024
3025 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3026 this);
3027
3028 if (count == null) {
3029 StringBundler query = new StringBundler(2);
3030
3031 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3032
3033 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3034
3035 String sql = query.toString();
3036
3037 Session session = null;
3038
3039 try {
3040 session = openSession();
3041
3042 Query q = session.createQuery(sql);
3043
3044 QueryPos qPos = QueryPos.getInstance(q);
3045
3046 qPos.add(type);
3047
3048 count = (Long)q.uniqueResult();
3049
3050 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3051 }
3052 catch (Exception e) {
3053 FinderCacheUtil.removeResult(finderPath, finderArgs);
3054
3055 throw processException(e);
3056 }
3057 finally {
3058 closeSession(session);
3059 }
3060 }
3061
3062 return count.intValue();
3063 }
3064
3065 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
3066 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3067 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3068 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3069 "findByC_T",
3070 new String[] {
3071 Long.class.getName(), Integer.class.getName(),
3072
3073 Integer.class.getName(), Integer.class.getName(),
3074 OrderByComparator.class.getName()
3075 });
3076 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3077 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3078 SocialRelationImpl.class,
3079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
3080 new String[] { Long.class.getName(), Integer.class.getName() },
3081 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK |
3082 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
3083 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3084 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
3086 new String[] { Long.class.getName(), Integer.class.getName() });
3087
3088
3096 public List<SocialRelation> findByC_T(long companyId, int type)
3097 throws SystemException {
3098 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3099 null);
3100 }
3101
3102
3116 public List<SocialRelation> findByC_T(long companyId, int type, int start,
3117 int end) throws SystemException {
3118 return findByC_T(companyId, type, start, end, null);
3119 }
3120
3121
3136 public List<SocialRelation> findByC_T(long companyId, int type, int start,
3137 int end, OrderByComparator orderByComparator) throws SystemException {
3138 boolean pagination = true;
3139 FinderPath finderPath = null;
3140 Object[] finderArgs = null;
3141
3142 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3143 (orderByComparator == null)) {
3144 pagination = false;
3145 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
3146 finderArgs = new Object[] { companyId, type };
3147 }
3148 else {
3149 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
3150 finderArgs = new Object[] {
3151 companyId, type,
3152
3153 start, end, orderByComparator
3154 };
3155 }
3156
3157 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3158 finderArgs, this);
3159
3160 if ((list != null) && !list.isEmpty()) {
3161 for (SocialRelation socialRelation : list) {
3162 if ((companyId != socialRelation.getCompanyId()) ||
3163 (type != socialRelation.getType())) {
3164 list = null;
3165
3166 break;
3167 }
3168 }
3169 }
3170
3171 if (list == null) {
3172 StringBundler query = null;
3173
3174 if (orderByComparator != null) {
3175 query = new StringBundler(4 +
3176 (orderByComparator.getOrderByFields().length * 3));
3177 }
3178 else {
3179 query = new StringBundler(4);
3180 }
3181
3182 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3183
3184 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3185
3186 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3187
3188 if (orderByComparator != null) {
3189 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3190 orderByComparator);
3191 }
3192 else
3193 if (pagination) {
3194 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3195 }
3196
3197 String sql = query.toString();
3198
3199 Session session = null;
3200
3201 try {
3202 session = openSession();
3203
3204 Query q = session.createQuery(sql);
3205
3206 QueryPos qPos = QueryPos.getInstance(q);
3207
3208 qPos.add(companyId);
3209
3210 qPos.add(type);
3211
3212 if (!pagination) {
3213 list = (List<SocialRelation>)QueryUtil.list(q,
3214 getDialect(), start, end, false);
3215
3216 Collections.sort(list);
3217
3218 list = new UnmodifiableList<SocialRelation>(list);
3219 }
3220 else {
3221 list = (List<SocialRelation>)QueryUtil.list(q,
3222 getDialect(), start, end);
3223 }
3224
3225 cacheResult(list);
3226
3227 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3228 }
3229 catch (Exception e) {
3230 FinderCacheUtil.removeResult(finderPath, finderArgs);
3231
3232 throw processException(e);
3233 }
3234 finally {
3235 closeSession(session);
3236 }
3237 }
3238
3239 return list;
3240 }
3241
3242
3252 public SocialRelation findByC_T_First(long companyId, int type,
3253 OrderByComparator orderByComparator)
3254 throws NoSuchRelationException, SystemException {
3255 SocialRelation socialRelation = fetchByC_T_First(companyId, type,
3256 orderByComparator);
3257
3258 if (socialRelation != null) {
3259 return socialRelation;
3260 }
3261
3262 StringBundler msg = new StringBundler(6);
3263
3264 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3265
3266 msg.append("companyId=");
3267 msg.append(companyId);
3268
3269 msg.append(", type=");
3270 msg.append(type);
3271
3272 msg.append(StringPool.CLOSE_CURLY_BRACE);
3273
3274 throw new NoSuchRelationException(msg.toString());
3275 }
3276
3277
3286 public SocialRelation fetchByC_T_First(long companyId, int type,
3287 OrderByComparator orderByComparator) throws SystemException {
3288 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
3289 orderByComparator);
3290
3291 if (!list.isEmpty()) {
3292 return list.get(0);
3293 }
3294
3295 return null;
3296 }
3297
3298
3308 public SocialRelation findByC_T_Last(long companyId, int type,
3309 OrderByComparator orderByComparator)
3310 throws NoSuchRelationException, SystemException {
3311 SocialRelation socialRelation = fetchByC_T_Last(companyId, type,
3312 orderByComparator);
3313
3314 if (socialRelation != null) {
3315 return socialRelation;
3316 }
3317
3318 StringBundler msg = new StringBundler(6);
3319
3320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3321
3322 msg.append("companyId=");
3323 msg.append(companyId);
3324
3325 msg.append(", type=");
3326 msg.append(type);
3327
3328 msg.append(StringPool.CLOSE_CURLY_BRACE);
3329
3330 throw new NoSuchRelationException(msg.toString());
3331 }
3332
3333
3342 public SocialRelation fetchByC_T_Last(long companyId, int type,
3343 OrderByComparator orderByComparator) throws SystemException {
3344 int count = countByC_T(companyId, type);
3345
3346 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
3347 count, orderByComparator);
3348
3349 if (!list.isEmpty()) {
3350 return list.get(0);
3351 }
3352
3353 return null;
3354 }
3355
3356
3367 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
3368 long companyId, int type, OrderByComparator orderByComparator)
3369 throws NoSuchRelationException, SystemException {
3370 SocialRelation socialRelation = findByPrimaryKey(relationId);
3371
3372 Session session = null;
3373
3374 try {
3375 session = openSession();
3376
3377 SocialRelation[] array = new SocialRelationImpl[3];
3378
3379 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3380 type, orderByComparator, true);
3381
3382 array[1] = socialRelation;
3383
3384 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3385 type, orderByComparator, false);
3386
3387 return array;
3388 }
3389 catch (Exception e) {
3390 throw processException(e);
3391 }
3392 finally {
3393 closeSession(session);
3394 }
3395 }
3396
3397 protected SocialRelation getByC_T_PrevAndNext(Session session,
3398 SocialRelation socialRelation, long companyId, int type,
3399 OrderByComparator orderByComparator, boolean previous) {
3400 StringBundler query = null;
3401
3402 if (orderByComparator != null) {
3403 query = new StringBundler(6 +
3404 (orderByComparator.getOrderByFields().length * 6));
3405 }
3406 else {
3407 query = new StringBundler(3);
3408 }
3409
3410 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3411
3412 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3413
3414 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3415
3416 if (orderByComparator != null) {
3417 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3418
3419 if (orderByConditionFields.length > 0) {
3420 query.append(WHERE_AND);
3421 }
3422
3423 for (int i = 0; i < orderByConditionFields.length; i++) {
3424 query.append(_ORDER_BY_ENTITY_ALIAS);
3425 query.append(orderByConditionFields[i]);
3426
3427 if ((i + 1) < orderByConditionFields.length) {
3428 if (orderByComparator.isAscending() ^ previous) {
3429 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3430 }
3431 else {
3432 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3433 }
3434 }
3435 else {
3436 if (orderByComparator.isAscending() ^ previous) {
3437 query.append(WHERE_GREATER_THAN);
3438 }
3439 else {
3440 query.append(WHERE_LESSER_THAN);
3441 }
3442 }
3443 }
3444
3445 query.append(ORDER_BY_CLAUSE);
3446
3447 String[] orderByFields = orderByComparator.getOrderByFields();
3448
3449 for (int i = 0; i < orderByFields.length; i++) {
3450 query.append(_ORDER_BY_ENTITY_ALIAS);
3451 query.append(orderByFields[i]);
3452
3453 if ((i + 1) < orderByFields.length) {
3454 if (orderByComparator.isAscending() ^ previous) {
3455 query.append(ORDER_BY_ASC_HAS_NEXT);
3456 }
3457 else {
3458 query.append(ORDER_BY_DESC_HAS_NEXT);
3459 }
3460 }
3461 else {
3462 if (orderByComparator.isAscending() ^ previous) {
3463 query.append(ORDER_BY_ASC);
3464 }
3465 else {
3466 query.append(ORDER_BY_DESC);
3467 }
3468 }
3469 }
3470 }
3471 else {
3472 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3473 }
3474
3475 String sql = query.toString();
3476
3477 Query q = session.createQuery(sql);
3478
3479 q.setFirstResult(0);
3480 q.setMaxResults(2);
3481
3482 QueryPos qPos = QueryPos.getInstance(q);
3483
3484 qPos.add(companyId);
3485
3486 qPos.add(type);
3487
3488 if (orderByComparator != null) {
3489 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3490
3491 for (Object value : values) {
3492 qPos.add(value);
3493 }
3494 }
3495
3496 List<SocialRelation> list = q.list();
3497
3498 if (list.size() == 2) {
3499 return list.get(1);
3500 }
3501 else {
3502 return null;
3503 }
3504 }
3505
3506
3513 public void removeByC_T(long companyId, int type) throws SystemException {
3514 for (SocialRelation socialRelation : findByC_T(companyId, type,
3515 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3516 remove(socialRelation);
3517 }
3518 }
3519
3520
3528 public int countByC_T(long companyId, int type) throws SystemException {
3529 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
3530
3531 Object[] finderArgs = new Object[] { companyId, type };
3532
3533 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3534 this);
3535
3536 if (count == null) {
3537 StringBundler query = new StringBundler(3);
3538
3539 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3540
3541 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3542
3543 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3544
3545 String sql = query.toString();
3546
3547 Session session = null;
3548
3549 try {
3550 session = openSession();
3551
3552 Query q = session.createQuery(sql);
3553
3554 QueryPos qPos = QueryPos.getInstance(q);
3555
3556 qPos.add(companyId);
3557
3558 qPos.add(type);
3559
3560 count = (Long)q.uniqueResult();
3561
3562 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3563 }
3564 catch (Exception e) {
3565 FinderCacheUtil.removeResult(finderPath, finderArgs);
3566
3567 throw processException(e);
3568 }
3569 finally {
3570 closeSession(session);
3571 }
3572 }
3573
3574 return count.intValue();
3575 }
3576
3577 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
3578 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
3579 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3580 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3581 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3582 "findByU1_U2",
3583 new String[] {
3584 Long.class.getName(), Long.class.getName(),
3585
3586 Integer.class.getName(), Integer.class.getName(),
3587 OrderByComparator.class.getName()
3588 });
3589 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3590 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3591 SocialRelationImpl.class,
3592 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_U2",
3593 new String[] { Long.class.getName(), Long.class.getName() },
3594 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
3595 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
3596 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3597 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3598 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2",
3599 new String[] { Long.class.getName(), Long.class.getName() });
3600
3601
3609 public List<SocialRelation> findByU1_U2(long userId1, long userId2)
3610 throws SystemException {
3611 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
3612 QueryUtil.ALL_POS, null);
3613 }
3614
3615
3629 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3630 int start, int end) throws SystemException {
3631 return findByU1_U2(userId1, userId2, start, end, null);
3632 }
3633
3634
3649 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3650 int start, int end, OrderByComparator orderByComparator)
3651 throws SystemException {
3652 boolean pagination = true;
3653 FinderPath finderPath = null;
3654 Object[] finderArgs = null;
3655
3656 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3657 (orderByComparator == null)) {
3658 pagination = false;
3659 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3660 finderArgs = new Object[] { userId1, userId2 };
3661 }
3662 else {
3663 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3664 finderArgs = new Object[] {
3665 userId1, userId2,
3666
3667 start, end, orderByComparator
3668 };
3669 }
3670
3671 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3672 finderArgs, this);
3673
3674 if ((list != null) && !list.isEmpty()) {
3675 for (SocialRelation socialRelation : list) {
3676 if ((userId1 != socialRelation.getUserId1()) ||
3677 (userId2 != socialRelation.getUserId2())) {
3678 list = null;
3679
3680 break;
3681 }
3682 }
3683 }
3684
3685 if (list == null) {
3686 StringBundler query = null;
3687
3688 if (orderByComparator != null) {
3689 query = new StringBundler(4 +
3690 (orderByComparator.getOrderByFields().length * 3));
3691 }
3692 else {
3693 query = new StringBundler(4);
3694 }
3695
3696 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3697
3698 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3699
3700 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3701
3702 if (orderByComparator != null) {
3703 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3704 orderByComparator);
3705 }
3706 else
3707 if (pagination) {
3708 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3709 }
3710
3711 String sql = query.toString();
3712
3713 Session session = null;
3714
3715 try {
3716 session = openSession();
3717
3718 Query q = session.createQuery(sql);
3719
3720 QueryPos qPos = QueryPos.getInstance(q);
3721
3722 qPos.add(userId1);
3723
3724 qPos.add(userId2);
3725
3726 if (!pagination) {
3727 list = (List<SocialRelation>)QueryUtil.list(q,
3728 getDialect(), start, end, false);
3729
3730 Collections.sort(list);
3731
3732 list = new UnmodifiableList<SocialRelation>(list);
3733 }
3734 else {
3735 list = (List<SocialRelation>)QueryUtil.list(q,
3736 getDialect(), start, end);
3737 }
3738
3739 cacheResult(list);
3740
3741 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3742 }
3743 catch (Exception e) {
3744 FinderCacheUtil.removeResult(finderPath, finderArgs);
3745
3746 throw processException(e);
3747 }
3748 finally {
3749 closeSession(session);
3750 }
3751 }
3752
3753 return list;
3754 }
3755
3756
3766 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3767 OrderByComparator orderByComparator)
3768 throws NoSuchRelationException, SystemException {
3769 SocialRelation socialRelation = fetchByU1_U2_First(userId1, userId2,
3770 orderByComparator);
3771
3772 if (socialRelation != null) {
3773 return socialRelation;
3774 }
3775
3776 StringBundler msg = new StringBundler(6);
3777
3778 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3779
3780 msg.append("userId1=");
3781 msg.append(userId1);
3782
3783 msg.append(", userId2=");
3784 msg.append(userId2);
3785
3786 msg.append(StringPool.CLOSE_CURLY_BRACE);
3787
3788 throw new NoSuchRelationException(msg.toString());
3789 }
3790
3791
3800 public SocialRelation fetchByU1_U2_First(long userId1, long userId2,
3801 OrderByComparator orderByComparator) throws SystemException {
3802 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3803 orderByComparator);
3804
3805 if (!list.isEmpty()) {
3806 return list.get(0);
3807 }
3808
3809 return null;
3810 }
3811
3812
3822 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3823 OrderByComparator orderByComparator)
3824 throws NoSuchRelationException, SystemException {
3825 SocialRelation socialRelation = fetchByU1_U2_Last(userId1, userId2,
3826 orderByComparator);
3827
3828 if (socialRelation != null) {
3829 return socialRelation;
3830 }
3831
3832 StringBundler msg = new StringBundler(6);
3833
3834 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3835
3836 msg.append("userId1=");
3837 msg.append(userId1);
3838
3839 msg.append(", userId2=");
3840 msg.append(userId2);
3841
3842 msg.append(StringPool.CLOSE_CURLY_BRACE);
3843
3844 throw new NoSuchRelationException(msg.toString());
3845 }
3846
3847
3856 public SocialRelation fetchByU1_U2_Last(long userId1, long userId2,
3857 OrderByComparator orderByComparator) throws SystemException {
3858 int count = countByU1_U2(userId1, userId2);
3859
3860 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3861 count, orderByComparator);
3862
3863 if (!list.isEmpty()) {
3864 return list.get(0);
3865 }
3866
3867 return null;
3868 }
3869
3870
3881 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3882 long userId1, long userId2, OrderByComparator orderByComparator)
3883 throws NoSuchRelationException, SystemException {
3884 SocialRelation socialRelation = findByPrimaryKey(relationId);
3885
3886 Session session = null;
3887
3888 try {
3889 session = openSession();
3890
3891 SocialRelation[] array = new SocialRelationImpl[3];
3892
3893 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3894 userId2, orderByComparator, true);
3895
3896 array[1] = socialRelation;
3897
3898 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3899 userId2, orderByComparator, false);
3900
3901 return array;
3902 }
3903 catch (Exception e) {
3904 throw processException(e);
3905 }
3906 finally {
3907 closeSession(session);
3908 }
3909 }
3910
3911 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3912 SocialRelation socialRelation, long userId1, long userId2,
3913 OrderByComparator orderByComparator, boolean previous) {
3914 StringBundler query = null;
3915
3916 if (orderByComparator != null) {
3917 query = new StringBundler(6 +
3918 (orderByComparator.getOrderByFields().length * 6));
3919 }
3920 else {
3921 query = new StringBundler(3);
3922 }
3923
3924 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3925
3926 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3927
3928 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3929
3930 if (orderByComparator != null) {
3931 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3932
3933 if (orderByConditionFields.length > 0) {
3934 query.append(WHERE_AND);
3935 }
3936
3937 for (int i = 0; i < orderByConditionFields.length; i++) {
3938 query.append(_ORDER_BY_ENTITY_ALIAS);
3939 query.append(orderByConditionFields[i]);
3940
3941 if ((i + 1) < orderByConditionFields.length) {
3942 if (orderByComparator.isAscending() ^ previous) {
3943 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3944 }
3945 else {
3946 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3947 }
3948 }
3949 else {
3950 if (orderByComparator.isAscending() ^ previous) {
3951 query.append(WHERE_GREATER_THAN);
3952 }
3953 else {
3954 query.append(WHERE_LESSER_THAN);
3955 }
3956 }
3957 }
3958
3959 query.append(ORDER_BY_CLAUSE);
3960
3961 String[] orderByFields = orderByComparator.getOrderByFields();
3962
3963 for (int i = 0; i < orderByFields.length; i++) {
3964 query.append(_ORDER_BY_ENTITY_ALIAS);
3965 query.append(orderByFields[i]);
3966
3967 if ((i + 1) < orderByFields.length) {
3968 if (orderByComparator.isAscending() ^ previous) {
3969 query.append(ORDER_BY_ASC_HAS_NEXT);
3970 }
3971 else {
3972 query.append(ORDER_BY_DESC_HAS_NEXT);
3973 }
3974 }
3975 else {
3976 if (orderByComparator.isAscending() ^ previous) {
3977 query.append(ORDER_BY_ASC);
3978 }
3979 else {
3980 query.append(ORDER_BY_DESC);
3981 }
3982 }
3983 }
3984 }
3985 else {
3986 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3987 }
3988
3989 String sql = query.toString();
3990
3991 Query q = session.createQuery(sql);
3992
3993 q.setFirstResult(0);
3994 q.setMaxResults(2);
3995
3996 QueryPos qPos = QueryPos.getInstance(q);
3997
3998 qPos.add(userId1);
3999
4000 qPos.add(userId2);
4001
4002 if (orderByComparator != null) {
4003 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4004
4005 for (Object value : values) {
4006 qPos.add(value);
4007 }
4008 }
4009
4010 List<SocialRelation> list = q.list();
4011
4012 if (list.size() == 2) {
4013 return list.get(1);
4014 }
4015 else {
4016 return null;
4017 }
4018 }
4019
4020
4027 public void removeByU1_U2(long userId1, long userId2)
4028 throws SystemException {
4029 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2,
4030 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4031 remove(socialRelation);
4032 }
4033 }
4034
4035
4043 public int countByU1_U2(long userId1, long userId2)
4044 throws SystemException {
4045 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_U2;
4046
4047 Object[] finderArgs = new Object[] { userId1, userId2 };
4048
4049 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4050 this);
4051
4052 if (count == null) {
4053 StringBundler query = new StringBundler(3);
4054
4055 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4056
4057 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
4058
4059 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
4060
4061 String sql = query.toString();
4062
4063 Session session = null;
4064
4065 try {
4066 session = openSession();
4067
4068 Query q = session.createQuery(sql);
4069
4070 QueryPos qPos = QueryPos.getInstance(q);
4071
4072 qPos.add(userId1);
4073
4074 qPos.add(userId2);
4075
4076 count = (Long)q.uniqueResult();
4077
4078 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4079 }
4080 catch (Exception e) {
4081 FinderCacheUtil.removeResult(finderPath, finderArgs);
4082
4083 throw processException(e);
4084 }
4085 finally {
4086 closeSession(session);
4087 }
4088 }
4089
4090 return count.intValue();
4091 }
4092
4093 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
4094 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
4095 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4096 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4097 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4098 "findByU1_T",
4099 new String[] {
4100 Long.class.getName(), Integer.class.getName(),
4101
4102 Integer.class.getName(), Integer.class.getName(),
4103 OrderByComparator.class.getName()
4104 });
4105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4106 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4107 SocialRelationImpl.class,
4108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_T",
4109 new String[] { Long.class.getName(), Integer.class.getName() },
4110 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
4111 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
4112 public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4113 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_T",
4115 new String[] { Long.class.getName(), Integer.class.getName() });
4116
4117
4125 public List<SocialRelation> findByU1_T(long userId1, int type)
4126 throws SystemException {
4127 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4128 null);
4129 }
4130
4131
4145 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
4146 int end) throws SystemException {
4147 return findByU1_T(userId1, type, start, end, null);
4148 }
4149
4150
4165 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
4166 int end, OrderByComparator orderByComparator) throws SystemException {
4167 boolean pagination = true;
4168 FinderPath finderPath = null;
4169 Object[] finderArgs = null;
4170
4171 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4172 (orderByComparator == null)) {
4173 pagination = false;
4174 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
4175 finderArgs = new Object[] { userId1, type };
4176 }
4177 else {
4178 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
4179 finderArgs = new Object[] {
4180 userId1, type,
4181
4182 start, end, orderByComparator
4183 };
4184 }
4185
4186 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4187 finderArgs, this);
4188
4189 if ((list != null) && !list.isEmpty()) {
4190 for (SocialRelation socialRelation : list) {
4191 if ((userId1 != socialRelation.getUserId1()) ||
4192 (type != socialRelation.getType())) {
4193 list = null;
4194
4195 break;
4196 }
4197 }
4198 }
4199
4200 if (list == null) {
4201 StringBundler query = null;
4202
4203 if (orderByComparator != null) {
4204 query = new StringBundler(4 +
4205 (orderByComparator.getOrderByFields().length * 3));
4206 }
4207 else {
4208 query = new StringBundler(4);
4209 }
4210
4211 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4212
4213 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4214
4215 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4216
4217 if (orderByComparator != null) {
4218 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4219 orderByComparator);
4220 }
4221 else
4222 if (pagination) {
4223 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4224 }
4225
4226 String sql = query.toString();
4227
4228 Session session = null;
4229
4230 try {
4231 session = openSession();
4232
4233 Query q = session.createQuery(sql);
4234
4235 QueryPos qPos = QueryPos.getInstance(q);
4236
4237 qPos.add(userId1);
4238
4239 qPos.add(type);
4240
4241 if (!pagination) {
4242 list = (List<SocialRelation>)QueryUtil.list(q,
4243 getDialect(), start, end, false);
4244
4245 Collections.sort(list);
4246
4247 list = new UnmodifiableList<SocialRelation>(list);
4248 }
4249 else {
4250 list = (List<SocialRelation>)QueryUtil.list(q,
4251 getDialect(), start, end);
4252 }
4253
4254 cacheResult(list);
4255
4256 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4257 }
4258 catch (Exception e) {
4259 FinderCacheUtil.removeResult(finderPath, finderArgs);
4260
4261 throw processException(e);
4262 }
4263 finally {
4264 closeSession(session);
4265 }
4266 }
4267
4268 return list;
4269 }
4270
4271
4281 public SocialRelation findByU1_T_First(long userId1, int type,
4282 OrderByComparator orderByComparator)
4283 throws NoSuchRelationException, SystemException {
4284 SocialRelation socialRelation = fetchByU1_T_First(userId1, type,
4285 orderByComparator);
4286
4287 if (socialRelation != null) {
4288 return socialRelation;
4289 }
4290
4291 StringBundler msg = new StringBundler(6);
4292
4293 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4294
4295 msg.append("userId1=");
4296 msg.append(userId1);
4297
4298 msg.append(", type=");
4299 msg.append(type);
4300
4301 msg.append(StringPool.CLOSE_CURLY_BRACE);
4302
4303 throw new NoSuchRelationException(msg.toString());
4304 }
4305
4306
4315 public SocialRelation fetchByU1_T_First(long userId1, int type,
4316 OrderByComparator orderByComparator) throws SystemException {
4317 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
4318 orderByComparator);
4319
4320 if (!list.isEmpty()) {
4321 return list.get(0);
4322 }
4323
4324 return null;
4325 }
4326
4327
4337 public SocialRelation findByU1_T_Last(long userId1, int type,
4338 OrderByComparator orderByComparator)
4339 throws NoSuchRelationException, SystemException {
4340 SocialRelation socialRelation = fetchByU1_T_Last(userId1, type,
4341 orderByComparator);
4342
4343 if (socialRelation != null) {
4344 return socialRelation;
4345 }
4346
4347 StringBundler msg = new StringBundler(6);
4348
4349 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4350
4351 msg.append("userId1=");
4352 msg.append(userId1);
4353
4354 msg.append(", type=");
4355 msg.append(type);
4356
4357 msg.append(StringPool.CLOSE_CURLY_BRACE);
4358
4359 throw new NoSuchRelationException(msg.toString());
4360 }
4361
4362
4371 public SocialRelation fetchByU1_T_Last(long userId1, int type,
4372 OrderByComparator orderByComparator) throws SystemException {
4373 int count = countByU1_T(userId1, type);
4374
4375 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
4376 orderByComparator);
4377
4378 if (!list.isEmpty()) {
4379 return list.get(0);
4380 }
4381
4382 return null;
4383 }
4384
4385
4396 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
4397 long userId1, int type, OrderByComparator orderByComparator)
4398 throws NoSuchRelationException, SystemException {
4399 SocialRelation socialRelation = findByPrimaryKey(relationId);
4400
4401 Session session = null;
4402
4403 try {
4404 session = openSession();
4405
4406 SocialRelation[] array = new SocialRelationImpl[3];
4407
4408 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
4409 type, orderByComparator, true);
4410
4411 array[1] = socialRelation;
4412
4413 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
4414 type, orderByComparator, false);
4415
4416 return array;
4417 }
4418 catch (Exception e) {
4419 throw processException(e);
4420 }
4421 finally {
4422 closeSession(session);
4423 }
4424 }
4425
4426 protected SocialRelation getByU1_T_PrevAndNext(Session session,
4427 SocialRelation socialRelation, long userId1, int type,
4428 OrderByComparator orderByComparator, boolean previous) {
4429 StringBundler query = null;
4430
4431 if (orderByComparator != null) {
4432 query = new StringBundler(6 +
4433 (orderByComparator.getOrderByFields().length * 6));
4434 }
4435 else {
4436 query = new StringBundler(3);
4437 }
4438
4439 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4440
4441 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4442
4443 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4444
4445 if (orderByComparator != null) {
4446 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4447
4448 if (orderByConditionFields.length > 0) {
4449 query.append(WHERE_AND);
4450 }
4451
4452 for (int i = 0; i < orderByConditionFields.length; i++) {
4453 query.append(_ORDER_BY_ENTITY_ALIAS);
4454 query.append(orderByConditionFields[i]);
4455
4456 if ((i + 1) < orderByConditionFields.length) {
4457 if (orderByComparator.isAscending() ^ previous) {
4458 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4459 }
4460 else {
4461 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4462 }
4463 }
4464 else {
4465 if (orderByComparator.isAscending() ^ previous) {
4466 query.append(WHERE_GREATER_THAN);
4467 }
4468 else {
4469 query.append(WHERE_LESSER_THAN);
4470 }
4471 }
4472 }
4473
4474 query.append(ORDER_BY_CLAUSE);
4475
4476 String[] orderByFields = orderByComparator.getOrderByFields();
4477
4478 for (int i = 0; i < orderByFields.length; i++) {
4479 query.append(_ORDER_BY_ENTITY_ALIAS);
4480 query.append(orderByFields[i]);
4481
4482 if ((i + 1) < orderByFields.length) {
4483 if (orderByComparator.isAscending() ^ previous) {
4484 query.append(ORDER_BY_ASC_HAS_NEXT);
4485 }
4486 else {
4487 query.append(ORDER_BY_DESC_HAS_NEXT);
4488 }
4489 }
4490 else {
4491 if (orderByComparator.isAscending() ^ previous) {
4492 query.append(ORDER_BY_ASC);
4493 }
4494 else {
4495 query.append(ORDER_BY_DESC);
4496 }
4497 }
4498 }
4499 }
4500 else {
4501 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4502 }
4503
4504 String sql = query.toString();
4505
4506 Query q = session.createQuery(sql);
4507
4508 q.setFirstResult(0);
4509 q.setMaxResults(2);
4510
4511 QueryPos qPos = QueryPos.getInstance(q);
4512
4513 qPos.add(userId1);
4514
4515 qPos.add(type);
4516
4517 if (orderByComparator != null) {
4518 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4519
4520 for (Object value : values) {
4521 qPos.add(value);
4522 }
4523 }
4524
4525 List<SocialRelation> list = q.list();
4526
4527 if (list.size() == 2) {
4528 return list.get(1);
4529 }
4530 else {
4531 return null;
4532 }
4533 }
4534
4535
4542 public void removeByU1_T(long userId1, int type) throws SystemException {
4543 for (SocialRelation socialRelation : findByU1_T(userId1, type,
4544 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4545 remove(socialRelation);
4546 }
4547 }
4548
4549
4557 public int countByU1_T(long userId1, int type) throws SystemException {
4558 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_T;
4559
4560 Object[] finderArgs = new Object[] { userId1, type };
4561
4562 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4563 this);
4564
4565 if (count == null) {
4566 StringBundler query = new StringBundler(3);
4567
4568 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4569
4570 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4571
4572 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4573
4574 String sql = query.toString();
4575
4576 Session session = null;
4577
4578 try {
4579 session = openSession();
4580
4581 Query q = session.createQuery(sql);
4582
4583 QueryPos qPos = QueryPos.getInstance(q);
4584
4585 qPos.add(userId1);
4586
4587 qPos.add(type);
4588
4589 count = (Long)q.uniqueResult();
4590
4591 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4592 }
4593 catch (Exception e) {
4594 FinderCacheUtil.removeResult(finderPath, finderArgs);
4595
4596 throw processException(e);
4597 }
4598 finally {
4599 closeSession(session);
4600 }
4601 }
4602
4603 return count.intValue();
4604 }
4605
4606 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4607 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
4608 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4609 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4610 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4611 "findByU2_T",
4612 new String[] {
4613 Long.class.getName(), Integer.class.getName(),
4614
4615 Integer.class.getName(), Integer.class.getName(),
4616 OrderByComparator.class.getName()
4617 });
4618 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4619 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4620 SocialRelationImpl.class,
4621 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU2_T",
4622 new String[] { Long.class.getName(), Integer.class.getName() },
4623 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
4624 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
4625 public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4626 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4627 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU2_T",
4628 new String[] { Long.class.getName(), Integer.class.getName() });
4629
4630
4638 public List<SocialRelation> findByU2_T(long userId2, int type)
4639 throws SystemException {
4640 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4641 null);
4642 }
4643
4644
4658 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4659 int end) throws SystemException {
4660 return findByU2_T(userId2, type, start, end, null);
4661 }
4662
4663
4678 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4679 int end, OrderByComparator orderByComparator) throws SystemException {
4680 boolean pagination = true;
4681 FinderPath finderPath = null;
4682 Object[] finderArgs = null;
4683
4684 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4685 (orderByComparator == null)) {
4686 pagination = false;
4687 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
4688 finderArgs = new Object[] { userId2, type };
4689 }
4690 else {
4691 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
4692 finderArgs = new Object[] {
4693 userId2, type,
4694
4695 start, end, orderByComparator
4696 };
4697 }
4698
4699 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4700 finderArgs, this);
4701
4702 if ((list != null) && !list.isEmpty()) {
4703 for (SocialRelation socialRelation : list) {
4704 if ((userId2 != socialRelation.getUserId2()) ||
4705 (type != socialRelation.getType())) {
4706 list = null;
4707
4708 break;
4709 }
4710 }
4711 }
4712
4713 if (list == null) {
4714 StringBundler query = null;
4715
4716 if (orderByComparator != null) {
4717 query = new StringBundler(4 +
4718 (orderByComparator.getOrderByFields().length * 3));
4719 }
4720 else {
4721 query = new StringBundler(4);
4722 }
4723
4724 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4725
4726 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4727
4728 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4729
4730 if (orderByComparator != null) {
4731 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4732 orderByComparator);
4733 }
4734 else
4735 if (pagination) {
4736 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4737 }
4738
4739 String sql = query.toString();
4740
4741 Session session = null;
4742
4743 try {
4744 session = openSession();
4745
4746 Query q = session.createQuery(sql);
4747
4748 QueryPos qPos = QueryPos.getInstance(q);
4749
4750 qPos.add(userId2);
4751
4752 qPos.add(type);
4753
4754 if (!pagination) {
4755 list = (List<SocialRelation>)QueryUtil.list(q,
4756 getDialect(), start, end, false);
4757
4758 Collections.sort(list);
4759
4760 list = new UnmodifiableList<SocialRelation>(list);
4761 }
4762 else {
4763 list = (List<SocialRelation>)QueryUtil.list(q,
4764 getDialect(), start, end);
4765 }
4766
4767 cacheResult(list);
4768
4769 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4770 }
4771 catch (Exception e) {
4772 FinderCacheUtil.removeResult(finderPath, finderArgs);
4773
4774 throw processException(e);
4775 }
4776 finally {
4777 closeSession(session);
4778 }
4779 }
4780
4781 return list;
4782 }
4783
4784
4794 public SocialRelation findByU2_T_First(long userId2, int type,
4795 OrderByComparator orderByComparator)
4796 throws NoSuchRelationException, SystemException {
4797 SocialRelation socialRelation = fetchByU2_T_First(userId2, type,
4798 orderByComparator);
4799
4800 if (socialRelation != null) {
4801 return socialRelation;
4802 }
4803
4804 StringBundler msg = new StringBundler(6);
4805
4806 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4807
4808 msg.append("userId2=");
4809 msg.append(userId2);
4810
4811 msg.append(", type=");
4812 msg.append(type);
4813
4814 msg.append(StringPool.CLOSE_CURLY_BRACE);
4815
4816 throw new NoSuchRelationException(msg.toString());
4817 }
4818
4819
4828 public SocialRelation fetchByU2_T_First(long userId2, int type,
4829 OrderByComparator orderByComparator) throws SystemException {
4830 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
4831 orderByComparator);
4832
4833 if (!list.isEmpty()) {
4834 return list.get(0);
4835 }
4836
4837 return null;
4838 }
4839
4840
4850 public SocialRelation findByU2_T_Last(long userId2, int type,
4851 OrderByComparator orderByComparator)
4852 throws NoSuchRelationException, SystemException {
4853 SocialRelation socialRelation = fetchByU2_T_Last(userId2, type,
4854 orderByComparator);
4855
4856 if (socialRelation != null) {
4857 return socialRelation;
4858 }
4859
4860 StringBundler msg = new StringBundler(6);
4861
4862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4863
4864 msg.append("userId2=");
4865 msg.append(userId2);
4866
4867 msg.append(", type=");
4868 msg.append(type);
4869
4870 msg.append(StringPool.CLOSE_CURLY_BRACE);
4871
4872 throw new NoSuchRelationException(msg.toString());
4873 }
4874
4875
4884 public SocialRelation fetchByU2_T_Last(long userId2, int type,
4885 OrderByComparator orderByComparator) throws SystemException {
4886 int count = countByU2_T(userId2, type);
4887
4888 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
4889 orderByComparator);
4890
4891 if (!list.isEmpty()) {
4892 return list.get(0);
4893 }
4894
4895 return null;
4896 }
4897
4898
4909 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
4910 long userId2, int type, OrderByComparator orderByComparator)
4911 throws NoSuchRelationException, SystemException {
4912 SocialRelation socialRelation = findByPrimaryKey(relationId);
4913
4914 Session session = null;
4915
4916 try {
4917 session = openSession();
4918
4919 SocialRelation[] array = new SocialRelationImpl[3];
4920
4921 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4922 type, orderByComparator, true);
4923
4924 array[1] = socialRelation;
4925
4926 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4927 type, orderByComparator, false);
4928
4929 return array;
4930 }
4931 catch (Exception e) {
4932 throw processException(e);
4933 }
4934 finally {
4935 closeSession(session);
4936 }
4937 }
4938
4939 protected SocialRelation getByU2_T_PrevAndNext(Session session,
4940 SocialRelation socialRelation, long userId2, int type,
4941 OrderByComparator orderByComparator, boolean previous) {
4942 StringBundler query = null;
4943
4944 if (orderByComparator != null) {
4945 query = new StringBundler(6 +
4946 (orderByComparator.getOrderByFields().length * 6));
4947 }
4948 else {
4949 query = new StringBundler(3);
4950 }
4951
4952 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4953
4954 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4955
4956 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4957
4958 if (orderByComparator != null) {
4959 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4960
4961 if (orderByConditionFields.length > 0) {
4962 query.append(WHERE_AND);
4963 }
4964
4965 for (int i = 0; i < orderByConditionFields.length; i++) {
4966 query.append(_ORDER_BY_ENTITY_ALIAS);
4967 query.append(orderByConditionFields[i]);
4968
4969 if ((i + 1) < orderByConditionFields.length) {
4970 if (orderByComparator.isAscending() ^ previous) {
4971 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4972 }
4973 else {
4974 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4975 }
4976 }
4977 else {
4978 if (orderByComparator.isAscending() ^ previous) {
4979 query.append(WHERE_GREATER_THAN);
4980 }
4981 else {
4982 query.append(WHERE_LESSER_THAN);
4983 }
4984 }
4985 }
4986
4987 query.append(ORDER_BY_CLAUSE);
4988
4989 String[] orderByFields = orderByComparator.getOrderByFields();
4990
4991 for (int i = 0; i < orderByFields.length; i++) {
4992 query.append(_ORDER_BY_ENTITY_ALIAS);
4993 query.append(orderByFields[i]);
4994
4995 if ((i + 1) < orderByFields.length) {
4996 if (orderByComparator.isAscending() ^ previous) {
4997 query.append(ORDER_BY_ASC_HAS_NEXT);
4998 }
4999 else {
5000 query.append(ORDER_BY_DESC_HAS_NEXT);
5001 }
5002 }
5003 else {
5004 if (orderByComparator.isAscending() ^ previous) {
5005 query.append(ORDER_BY_ASC);
5006 }
5007 else {
5008 query.append(ORDER_BY_DESC);
5009 }
5010 }
5011 }
5012 }
5013 else {
5014 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
5015 }
5016
5017 String sql = query.toString();
5018
5019 Query q = session.createQuery(sql);
5020
5021 q.setFirstResult(0);
5022 q.setMaxResults(2);
5023
5024 QueryPos qPos = QueryPos.getInstance(q);
5025
5026 qPos.add(userId2);
5027
5028 qPos.add(type);
5029
5030 if (orderByComparator != null) {
5031 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
5032
5033 for (Object value : values) {
5034 qPos.add(value);
5035 }
5036 }
5037
5038 List<SocialRelation> list = q.list();
5039
5040 if (list.size() == 2) {
5041 return list.get(1);
5042 }
5043 else {
5044 return null;
5045 }
5046 }
5047
5048
5055 public void removeByU2_T(long userId2, int type) throws SystemException {
5056 for (SocialRelation socialRelation : findByU2_T(userId2, type,
5057 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5058 remove(socialRelation);
5059 }
5060 }
5061
5062
5070 public int countByU2_T(long userId2, int type) throws SystemException {
5071 FinderPath finderPath = FINDER_PATH_COUNT_BY_U2_T;
5072
5073 Object[] finderArgs = new Object[] { userId2, type };
5074
5075 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5076 this);
5077
5078 if (count == null) {
5079 StringBundler query = new StringBundler(3);
5080
5081 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5082
5083 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
5084
5085 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
5086
5087 String sql = query.toString();
5088
5089 Session session = null;
5090
5091 try {
5092 session = openSession();
5093
5094 Query q = session.createQuery(sql);
5095
5096 QueryPos qPos = QueryPos.getInstance(q);
5097
5098 qPos.add(userId2);
5099
5100 qPos.add(type);
5101
5102 count = (Long)q.uniqueResult();
5103
5104 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5105 }
5106 catch (Exception e) {
5107 FinderCacheUtil.removeResult(finderPath, finderArgs);
5108
5109 throw processException(e);
5110 }
5111 finally {
5112 closeSession(session);
5113 }
5114 }
5115
5116 return count.intValue();
5117 }
5118
5119 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5120 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5121 public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5122 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
5123 SocialRelationImpl.class, FINDER_CLASS_NAME_ENTITY,
5124 "fetchByU1_U2_T",
5125 new String[] {
5126 Long.class.getName(), Long.class.getName(),
5127 Integer.class.getName()
5128 },
5129 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
5130 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
5131 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
5132 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5133 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5134 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2_T",
5135 new String[] {
5136 Long.class.getName(), Long.class.getName(),
5137 Integer.class.getName()
5138 });
5139
5140
5150 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
5151 throws NoSuchRelationException, SystemException {
5152 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
5153
5154 if (socialRelation == null) {
5155 StringBundler msg = new StringBundler(8);
5156
5157 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5158
5159 msg.append("userId1=");
5160 msg.append(userId1);
5161
5162 msg.append(", userId2=");
5163 msg.append(userId2);
5164
5165 msg.append(", type=");
5166 msg.append(type);
5167
5168 msg.append(StringPool.CLOSE_CURLY_BRACE);
5169
5170 if (_log.isWarnEnabled()) {
5171 _log.warn(msg.toString());
5172 }
5173
5174 throw new NoSuchRelationException(msg.toString());
5175 }
5176
5177 return socialRelation;
5178 }
5179
5180
5189 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
5190 throws SystemException {
5191 return fetchByU1_U2_T(userId1, userId2, type, true);
5192 }
5193
5194
5204 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
5205 boolean retrieveFromCache) throws SystemException {
5206 Object[] finderArgs = new Object[] { userId1, userId2, type };
5207
5208 Object result = null;
5209
5210 if (retrieveFromCache) {
5211 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5212 finderArgs, this);
5213 }
5214
5215 if (result instanceof SocialRelation) {
5216 SocialRelation socialRelation = (SocialRelation)result;
5217
5218 if ((userId1 != socialRelation.getUserId1()) ||
5219 (userId2 != socialRelation.getUserId2()) ||
5220 (type != socialRelation.getType())) {
5221 result = null;
5222 }
5223 }
5224
5225 if (result == null) {
5226 StringBundler query = new StringBundler(5);
5227
5228 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
5229
5230 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5231
5232 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5233
5234 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5235
5236 String sql = query.toString();
5237
5238 Session session = null;
5239
5240 try {
5241 session = openSession();
5242
5243 Query q = session.createQuery(sql);
5244
5245 QueryPos qPos = QueryPos.getInstance(q);
5246
5247 qPos.add(userId1);
5248
5249 qPos.add(userId2);
5250
5251 qPos.add(type);
5252
5253 List<SocialRelation> list = q.list();
5254
5255 if (list.isEmpty()) {
5256 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5257 finderArgs, list);
5258 }
5259 else {
5260 SocialRelation socialRelation = list.get(0);
5261
5262 result = socialRelation;
5263
5264 cacheResult(socialRelation);
5265
5266 if ((socialRelation.getUserId1() != userId1) ||
5267 (socialRelation.getUserId2() != userId2) ||
5268 (socialRelation.getType() != type)) {
5269 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5270 finderArgs, socialRelation);
5271 }
5272 }
5273 }
5274 catch (Exception e) {
5275 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5276 finderArgs);
5277
5278 throw processException(e);
5279 }
5280 finally {
5281 closeSession(session);
5282 }
5283 }
5284
5285 if (result instanceof List<?>) {
5286 return null;
5287 }
5288 else {
5289 return (SocialRelation)result;
5290 }
5291 }
5292
5293
5302 public SocialRelation removeByU1_U2_T(long userId1, long userId2, int type)
5303 throws NoSuchRelationException, SystemException {
5304 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
5305
5306 return remove(socialRelation);
5307 }
5308
5309
5318 public int countByU1_U2_T(long userId1, long userId2, int type)
5319 throws SystemException {
5320 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_U2_T;
5321
5322 Object[] finderArgs = new Object[] { userId1, userId2, type };
5323
5324 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5325 this);
5326
5327 if (count == null) {
5328 StringBundler query = new StringBundler(4);
5329
5330 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5331
5332 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5333
5334 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5335
5336 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5337
5338 String sql = query.toString();
5339
5340 Session session = null;
5341
5342 try {
5343 session = openSession();
5344
5345 Query q = session.createQuery(sql);
5346
5347 QueryPos qPos = QueryPos.getInstance(q);
5348
5349 qPos.add(userId1);
5350
5351 qPos.add(userId2);
5352
5353 qPos.add(type);
5354
5355 count = (Long)q.uniqueResult();
5356
5357 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5358 }
5359 catch (Exception e) {
5360 FinderCacheUtil.removeResult(finderPath, finderArgs);
5361
5362 throw processException(e);
5363 }
5364 finally {
5365 closeSession(session);
5366 }
5367 }
5368
5369 return count.intValue();
5370 }
5371
5372 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5373 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5374 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5375
5376
5381 public void cacheResult(SocialRelation socialRelation) {
5382 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5383 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
5384 socialRelation);
5385
5386 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5387 new Object[] {
5388 Long.valueOf(socialRelation.getUserId1()),
5389 Long.valueOf(socialRelation.getUserId2()),
5390 Integer.valueOf(socialRelation.getType())
5391 }, socialRelation);
5392
5393 socialRelation.resetOriginalValues();
5394 }
5395
5396
5401 public void cacheResult(List<SocialRelation> socialRelations) {
5402 for (SocialRelation socialRelation : socialRelations) {
5403 if (EntityCacheUtil.getResult(
5404 SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5405 SocialRelationImpl.class, socialRelation.getPrimaryKey()) == null) {
5406 cacheResult(socialRelation);
5407 }
5408 else {
5409 socialRelation.resetOriginalValues();
5410 }
5411 }
5412 }
5413
5414
5421 @Override
5422 public void clearCache() {
5423 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
5424 CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
5425 }
5426
5427 EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
5428
5429 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5430 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5431 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5432 }
5433
5434
5441 @Override
5442 public void clearCache(SocialRelation socialRelation) {
5443 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5444 SocialRelationImpl.class, socialRelation.getPrimaryKey());
5445
5446 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5447 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5448
5449 clearUniqueFindersCache(socialRelation);
5450 }
5451
5452 @Override
5453 public void clearCache(List<SocialRelation> socialRelations) {
5454 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5455 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5456
5457 for (SocialRelation socialRelation : socialRelations) {
5458 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5459 SocialRelationImpl.class, socialRelation.getPrimaryKey());
5460
5461 clearUniqueFindersCache(socialRelation);
5462 }
5463 }
5464
5465 protected void cacheUniqueFindersCache(SocialRelation socialRelation) {
5466 if (socialRelation.isNew()) {
5467 Object[] args = new Object[] {
5468 Long.valueOf(socialRelation.getUserId1()),
5469 Long.valueOf(socialRelation.getUserId2()),
5470 Integer.valueOf(socialRelation.getType())
5471 };
5472
5473 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
5474 Long.valueOf(1));
5475 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
5476 socialRelation);
5477 }
5478 else {
5479 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5480
5481 if ((socialRelationModelImpl.getColumnBitmask() &
5482 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
5483 Object[] args = new Object[] {
5484 Long.valueOf(socialRelation.getUserId1()),
5485 Long.valueOf(socialRelation.getUserId2()),
5486 Integer.valueOf(socialRelation.getType())
5487 };
5488
5489 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
5490 Long.valueOf(1));
5491 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
5492 socialRelation);
5493 }
5494 }
5495 }
5496
5497 protected void clearUniqueFindersCache(SocialRelation socialRelation) {
5498 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5499
5500 Object[] args = new Object[] {
5501 Long.valueOf(socialRelation.getUserId1()),
5502 Long.valueOf(socialRelation.getUserId2()),
5503 Integer.valueOf(socialRelation.getType())
5504 };
5505
5506 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
5507 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
5508
5509 if ((socialRelationModelImpl.getColumnBitmask() &
5510 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
5511 args = new Object[] {
5512 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
5513 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
5514 Integer.valueOf(socialRelationModelImpl.getOriginalType())
5515 };
5516
5517 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
5518 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
5519 }
5520 }
5521
5522
5528 public SocialRelation create(long relationId) {
5529 SocialRelation socialRelation = new SocialRelationImpl();
5530
5531 socialRelation.setNew(true);
5532 socialRelation.setPrimaryKey(relationId);
5533
5534 String uuid = PortalUUIDUtil.generate();
5535
5536 socialRelation.setUuid(uuid);
5537
5538 return socialRelation;
5539 }
5540
5541
5549 public SocialRelation remove(long relationId)
5550 throws NoSuchRelationException, SystemException {
5551 return remove(Long.valueOf(relationId));
5552 }
5553
5554
5562 @Override
5563 public SocialRelation remove(Serializable primaryKey)
5564 throws NoSuchRelationException, SystemException {
5565 Session session = null;
5566
5567 try {
5568 session = openSession();
5569
5570 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5571 primaryKey);
5572
5573 if (socialRelation == null) {
5574 if (_log.isWarnEnabled()) {
5575 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5576 }
5577
5578 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5579 primaryKey);
5580 }
5581
5582 return remove(socialRelation);
5583 }
5584 catch (NoSuchRelationException nsee) {
5585 throw nsee;
5586 }
5587 catch (Exception e) {
5588 throw processException(e);
5589 }
5590 finally {
5591 closeSession(session);
5592 }
5593 }
5594
5595 @Override
5596 protected SocialRelation removeImpl(SocialRelation socialRelation)
5597 throws SystemException {
5598 socialRelation = toUnwrappedModel(socialRelation);
5599
5600 Session session = null;
5601
5602 try {
5603 session = openSession();
5604
5605 if (!session.contains(socialRelation)) {
5606 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5607 socialRelation.getPrimaryKeyObj());
5608 }
5609
5610 if (socialRelation != null) {
5611 session.delete(socialRelation);
5612 }
5613 }
5614 catch (Exception e) {
5615 throw processException(e);
5616 }
5617 finally {
5618 closeSession(session);
5619 }
5620
5621 if (socialRelation != null) {
5622 clearCache(socialRelation);
5623 }
5624
5625 return socialRelation;
5626 }
5627
5628 @Override
5629 public SocialRelation updateImpl(
5630 com.liferay.portlet.social.model.SocialRelation socialRelation)
5631 throws SystemException {
5632 socialRelation = toUnwrappedModel(socialRelation);
5633
5634 boolean isNew = socialRelation.isNew();
5635
5636 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5637
5638 if (Validator.isNull(socialRelation.getUuid())) {
5639 String uuid = PortalUUIDUtil.generate();
5640
5641 socialRelation.setUuid(uuid);
5642 }
5643
5644 Session session = null;
5645
5646 try {
5647 session = openSession();
5648
5649 if (socialRelation.isNew()) {
5650 session.save(socialRelation);
5651
5652 socialRelation.setNew(false);
5653 }
5654 else {
5655 session.merge(socialRelation);
5656 }
5657 }
5658 catch (Exception e) {
5659 throw processException(e);
5660 }
5661 finally {
5662 closeSession(session);
5663 }
5664
5665 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5666
5667 if (isNew || !SocialRelationModelImpl.COLUMN_BITMASK_ENABLED) {
5668 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5669 }
5670
5671 else {
5672 if ((socialRelationModelImpl.getColumnBitmask() &
5673 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5674 Object[] args = new Object[] {
5675 socialRelationModelImpl.getOriginalUuid()
5676 };
5677
5678 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5679 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5680 args);
5681
5682 args = new Object[] { socialRelationModelImpl.getUuid() };
5683
5684 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5685 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5686 args);
5687 }
5688
5689 if ((socialRelationModelImpl.getColumnBitmask() &
5690 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5691 Object[] args = new Object[] {
5692 socialRelationModelImpl.getOriginalUuid(),
5693 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId())
5694 };
5695
5696 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5697 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5698 args);
5699
5700 args = new Object[] {
5701 socialRelationModelImpl.getUuid(),
5702 Long.valueOf(socialRelationModelImpl.getCompanyId())
5703 };
5704
5705 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5706 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5707 args);
5708 }
5709
5710 if ((socialRelationModelImpl.getColumnBitmask() &
5711 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
5712 Object[] args = new Object[] {
5713 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId())
5714 };
5715
5716 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5717 args);
5718 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5719 args);
5720
5721 args = new Object[] {
5722 Long.valueOf(socialRelationModelImpl.getCompanyId())
5723 };
5724
5725 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5726 args);
5727 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5728 args);
5729 }
5730
5731 if ((socialRelationModelImpl.getColumnBitmask() &
5732 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1.getColumnBitmask()) != 0) {
5733 Object[] args = new Object[] {
5734 Long.valueOf(socialRelationModelImpl.getOriginalUserId1())
5735 };
5736
5737 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
5738 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
5739 args);
5740
5741 args = new Object[] {
5742 Long.valueOf(socialRelationModelImpl.getUserId1())
5743 };
5744
5745 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
5746 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
5747 args);
5748 }
5749
5750 if ((socialRelationModelImpl.getColumnBitmask() &
5751 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2.getColumnBitmask()) != 0) {
5752 Object[] args = new Object[] {
5753 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
5754 };
5755
5756 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
5757 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
5758 args);
5759
5760 args = new Object[] {
5761 Long.valueOf(socialRelationModelImpl.getUserId2())
5762 };
5763
5764 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
5765 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
5766 args);
5767 }
5768
5769 if ((socialRelationModelImpl.getColumnBitmask() &
5770 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
5771 Object[] args = new Object[] {
5772 Integer.valueOf(socialRelationModelImpl.getOriginalType())
5773 };
5774
5775 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
5776 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
5777 args);
5778
5779 args = new Object[] {
5780 Integer.valueOf(socialRelationModelImpl.getType())
5781 };
5782
5783 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
5784 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
5785 args);
5786 }
5787
5788 if ((socialRelationModelImpl.getColumnBitmask() &
5789 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
5790 Object[] args = new Object[] {
5791 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId()),
5792 Integer.valueOf(socialRelationModelImpl.getOriginalType())
5793 };
5794
5795 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
5796 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
5797 args);
5798
5799 args = new Object[] {
5800 Long.valueOf(socialRelationModelImpl.getCompanyId()),
5801 Integer.valueOf(socialRelationModelImpl.getType())
5802 };
5803
5804 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
5805 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
5806 args);
5807 }
5808
5809 if ((socialRelationModelImpl.getColumnBitmask() &
5810 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2.getColumnBitmask()) != 0) {
5811 Object[] args = new Object[] {
5812 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
5813 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
5814 };
5815
5816 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
5817 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
5818 args);
5819
5820 args = new Object[] {
5821 Long.valueOf(socialRelationModelImpl.getUserId1()),
5822 Long.valueOf(socialRelationModelImpl.getUserId2())
5823 };
5824
5825 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
5826 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
5827 args);
5828 }
5829
5830 if ((socialRelationModelImpl.getColumnBitmask() &
5831 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T.getColumnBitmask()) != 0) {
5832 Object[] args = new Object[] {
5833 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
5834 Integer.valueOf(socialRelationModelImpl.getOriginalType())
5835 };
5836
5837 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
5838 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
5839 args);
5840
5841 args = new Object[] {
5842 Long.valueOf(socialRelationModelImpl.getUserId1()),
5843 Integer.valueOf(socialRelationModelImpl.getType())
5844 };
5845
5846 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
5847 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
5848 args);
5849 }
5850
5851 if ((socialRelationModelImpl.getColumnBitmask() &
5852 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T.getColumnBitmask()) != 0) {
5853 Object[] args = new Object[] {
5854 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
5855 Integer.valueOf(socialRelationModelImpl.getOriginalType())
5856 };
5857
5858 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
5859 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
5860 args);
5861
5862 args = new Object[] {
5863 Long.valueOf(socialRelationModelImpl.getUserId2()),
5864 Integer.valueOf(socialRelationModelImpl.getType())
5865 };
5866
5867 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
5868 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
5869 args);
5870 }
5871 }
5872
5873 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5874 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
5875 socialRelation);
5876
5877 clearUniqueFindersCache(socialRelation);
5878 cacheUniqueFindersCache(socialRelation);
5879
5880 return socialRelation;
5881 }
5882
5883 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
5884 if (socialRelation instanceof SocialRelationImpl) {
5885 return socialRelation;
5886 }
5887
5888 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
5889
5890 socialRelationImpl.setNew(socialRelation.isNew());
5891 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
5892
5893 socialRelationImpl.setUuid(socialRelation.getUuid());
5894 socialRelationImpl.setRelationId(socialRelation.getRelationId());
5895 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
5896 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
5897 socialRelationImpl.setUserId1(socialRelation.getUserId1());
5898 socialRelationImpl.setUserId2(socialRelation.getUserId2());
5899 socialRelationImpl.setType(socialRelation.getType());
5900
5901 return socialRelationImpl;
5902 }
5903
5904
5912 @Override
5913 public SocialRelation findByPrimaryKey(Serializable primaryKey)
5914 throws NoSuchModelException, SystemException {
5915 return findByPrimaryKey(((Long)primaryKey).longValue());
5916 }
5917
5918
5926 public SocialRelation findByPrimaryKey(long relationId)
5927 throws NoSuchRelationException, SystemException {
5928 SocialRelation socialRelation = fetchByPrimaryKey(relationId);
5929
5930 if (socialRelation == null) {
5931 if (_log.isWarnEnabled()) {
5932 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
5933 }
5934
5935 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5936 relationId);
5937 }
5938
5939 return socialRelation;
5940 }
5941
5942
5949 @Override
5950 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
5951 throws SystemException {
5952 return fetchByPrimaryKey(((Long)primaryKey).longValue());
5953 }
5954
5955
5962 public SocialRelation fetchByPrimaryKey(long relationId)
5963 throws SystemException {
5964 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5965 SocialRelationImpl.class, relationId);
5966
5967 if (socialRelation == _nullSocialRelation) {
5968 return null;
5969 }
5970
5971 if (socialRelation == null) {
5972 Session session = null;
5973
5974 try {
5975 session = openSession();
5976
5977 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5978 Long.valueOf(relationId));
5979
5980 if (socialRelation != null) {
5981 cacheResult(socialRelation);
5982 }
5983 else {
5984 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5985 SocialRelationImpl.class, relationId,
5986 _nullSocialRelation);
5987 }
5988 }
5989 catch (Exception e) {
5990 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5991 SocialRelationImpl.class, relationId);
5992
5993 throw processException(e);
5994 }
5995 finally {
5996 closeSession(session);
5997 }
5998 }
5999
6000 return socialRelation;
6001 }
6002
6003
6009 public List<SocialRelation> findAll() throws SystemException {
6010 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6011 }
6012
6013
6025 public List<SocialRelation> findAll(int start, int end)
6026 throws SystemException {
6027 return findAll(start, end, null);
6028 }
6029
6030
6043 public List<SocialRelation> findAll(int start, int end,
6044 OrderByComparator orderByComparator) throws SystemException {
6045 boolean pagination = true;
6046 FinderPath finderPath = null;
6047 Object[] finderArgs = null;
6048
6049 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6050 (orderByComparator == null)) {
6051 pagination = false;
6052 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6053 finderArgs = FINDER_ARGS_EMPTY;
6054 }
6055 else {
6056 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6057 finderArgs = new Object[] { start, end, orderByComparator };
6058 }
6059
6060 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
6061 finderArgs, this);
6062
6063 if (list == null) {
6064 StringBundler query = null;
6065 String sql = null;
6066
6067 if (orderByComparator != null) {
6068 query = new StringBundler(2 +
6069 (orderByComparator.getOrderByFields().length * 3));
6070
6071 query.append(_SQL_SELECT_SOCIALRELATION);
6072
6073 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6074 orderByComparator);
6075
6076 sql = query.toString();
6077 }
6078 else {
6079 sql = _SQL_SELECT_SOCIALRELATION;
6080
6081 if (pagination) {
6082 sql = sql.concat(SocialRelationModelImpl.ORDER_BY_JPQL);
6083 }
6084 }
6085
6086 Session session = null;
6087
6088 try {
6089 session = openSession();
6090
6091 Query q = session.createQuery(sql);
6092
6093 if (!pagination) {
6094 list = (List<SocialRelation>)QueryUtil.list(q,
6095 getDialect(), start, end, false);
6096
6097 Collections.sort(list);
6098
6099 list = new UnmodifiableList<SocialRelation>(list);
6100 }
6101 else {
6102 list = (List<SocialRelation>)QueryUtil.list(q,
6103 getDialect(), start, end);
6104 }
6105
6106 cacheResult(list);
6107
6108 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6109 }
6110 catch (Exception e) {
6111 FinderCacheUtil.removeResult(finderPath, finderArgs);
6112
6113 throw processException(e);
6114 }
6115 finally {
6116 closeSession(session);
6117 }
6118 }
6119
6120 return list;
6121 }
6122
6123
6128 public void removeAll() throws SystemException {
6129 for (SocialRelation socialRelation : findAll()) {
6130 remove(socialRelation);
6131 }
6132 }
6133
6134
6140 public int countAll() throws SystemException {
6141 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6142 FINDER_ARGS_EMPTY, this);
6143
6144 if (count == null) {
6145 Session session = null;
6146
6147 try {
6148 session = openSession();
6149
6150 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
6151
6152 count = (Long)q.uniqueResult();
6153
6154 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6155 FINDER_ARGS_EMPTY, count);
6156 }
6157 catch (Exception e) {
6158 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
6159 FINDER_ARGS_EMPTY);
6160
6161 throw processException(e);
6162 }
6163 finally {
6164 closeSession(session);
6165 }
6166 }
6167
6168 return count.intValue();
6169 }
6170
6171
6174 public void afterPropertiesSet() {
6175 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6176 com.liferay.portal.util.PropsUtil.get(
6177 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
6178
6179 if (listenerClassNames.length > 0) {
6180 try {
6181 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
6182
6183 for (String listenerClassName : listenerClassNames) {
6184 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
6185 listenerClassName));
6186 }
6187
6188 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6189 }
6190 catch (Exception e) {
6191 _log.error(e);
6192 }
6193 }
6194 }
6195
6196 public void destroy() {
6197 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
6198 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6199 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6200 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6201 }
6202
6203 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
6204 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
6205 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
6206 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
6207 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
6208 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
6209 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
6210 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6211 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
6212 private static SocialRelation _nullSocialRelation = new SocialRelationImpl() {
6213 @Override
6214 public Object clone() {
6215 return this;
6216 }
6217
6218 @Override
6219 public CacheModel<SocialRelation> toCacheModel() {
6220 return _nullSocialRelationCacheModel;
6221 }
6222 };
6223
6224 private static CacheModel<SocialRelation> _nullSocialRelationCacheModel = new CacheModel<SocialRelation>() {
6225 public SocialRelation toEntityModel() {
6226 return _nullSocialRelation;
6227 }
6228 };
6229 }