001
014
015 package com.liferay.portlet.social.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
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 import java.util.Set;
053
054
066 public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
067 implements SocialRelationPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
079 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
080 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
081 "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
083 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
084 SocialRelationImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
087 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
090 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
091 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
092 "findByUuid",
093 new String[] {
094 String.class.getName(),
095
096 Integer.class.getName(), Integer.class.getName(),
097 OrderByComparator.class.getName()
098 });
099 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
100 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
101 SocialRelationImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
103 new String[] { String.class.getName() },
104 SocialRelationModelImpl.UUID_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
106 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
108 new String[] { String.class.getName() });
109
110
117 public List<SocialRelation> findByUuid(String uuid)
118 throws SystemException {
119 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120 }
121
122
135 public List<SocialRelation> findByUuid(String uuid, int start, int end)
136 throws SystemException {
137 return findByUuid(uuid, start, end, null);
138 }
139
140
154 public List<SocialRelation> findByUuid(String uuid, int start, int end,
155 OrderByComparator orderByComparator) throws SystemException {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
164 finderArgs = new Object[] { uuid };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid, start, end, orderByComparator };
169 }
170
171 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (SocialRelation socialRelation : list) {
176 if (!Validator.equals(uuid, socialRelation.getUuid())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
196
197 boolean bindUuid = false;
198
199 if (uuid == null) {
200 query.append(_FINDER_COLUMN_UUID_UUID_1);
201 }
202 else if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 bindUuid = true;
207
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindUuid) {
232 qPos.add(uuid);
233 }
234
235 if (!pagination) {
236 list = (List<SocialRelation>)QueryUtil.list(q,
237 getDialect(), start, end, false);
238
239 Collections.sort(list);
240
241 list = new UnmodifiableList<SocialRelation>(list);
242 }
243 else {
244 list = (List<SocialRelation>)QueryUtil.list(q,
245 getDialect(), start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
274 public SocialRelation findByUuid_First(String uuid,
275 OrderByComparator orderByComparator)
276 throws NoSuchRelationException, SystemException {
277 SocialRelation socialRelation = fetchByUuid_First(uuid,
278 orderByComparator);
279
280 if (socialRelation != null) {
281 return socialRelation;
282 }
283
284 StringBundler msg = new StringBundler(4);
285
286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
287
288 msg.append("uuid=");
289 msg.append(uuid);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchRelationException(msg.toString());
294 }
295
296
304 public SocialRelation fetchByUuid_First(String uuid,
305 OrderByComparator orderByComparator) throws SystemException {
306 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
307
308 if (!list.isEmpty()) {
309 return list.get(0);
310 }
311
312 return null;
313 }
314
315
324 public SocialRelation findByUuid_Last(String uuid,
325 OrderByComparator orderByComparator)
326 throws NoSuchRelationException, SystemException {
327 SocialRelation socialRelation = fetchByUuid_Last(uuid, orderByComparator);
328
329 if (socialRelation != null) {
330 return socialRelation;
331 }
332
333 StringBundler msg = new StringBundler(4);
334
335 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336
337 msg.append("uuid=");
338 msg.append(uuid);
339
340 msg.append(StringPool.CLOSE_CURLY_BRACE);
341
342 throw new NoSuchRelationException(msg.toString());
343 }
344
345
353 public SocialRelation fetchByUuid_Last(String uuid,
354 OrderByComparator orderByComparator) throws SystemException {
355 int count = countByUuid(uuid);
356
357 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
358 orderByComparator);
359
360 if (!list.isEmpty()) {
361 return list.get(0);
362 }
363
364 return null;
365 }
366
367
377 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
378 String uuid, OrderByComparator orderByComparator)
379 throws NoSuchRelationException, SystemException {
380 SocialRelation socialRelation = findByPrimaryKey(relationId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 SocialRelation[] array = new SocialRelationImpl[3];
388
389 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
390 orderByComparator, true);
391
392 array[1] = socialRelation;
393
394 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
395 orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected SocialRelation getByUuid_PrevAndNext(Session session,
408 SocialRelation socialRelation, String uuid,
409 OrderByComparator orderByComparator, boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
421
422 boolean bindUuid = false;
423
424 if (uuid == null) {
425 query.append(_FINDER_COLUMN_UUID_UUID_1);
426 }
427 else if (uuid.equals(StringPool.BLANK)) {
428 query.append(_FINDER_COLUMN_UUID_UUID_3);
429 }
430 else {
431 bindUuid = true;
432
433 query.append(_FINDER_COLUMN_UUID_UUID_2);
434 }
435
436 if (orderByComparator != null) {
437 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438
439 if (orderByConditionFields.length > 0) {
440 query.append(WHERE_AND);
441 }
442
443 for (int i = 0; i < orderByConditionFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByConditionFields[i]);
446
447 if ((i + 1) < orderByConditionFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(WHERE_GREATER_THAN_HAS_NEXT);
450 }
451 else {
452 query.append(WHERE_LESSER_THAN_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN);
461 }
462 }
463 }
464
465 query.append(ORDER_BY_CLAUSE);
466
467 String[] orderByFields = orderByComparator.getOrderByFields();
468
469 for (int i = 0; i < orderByFields.length; i++) {
470 query.append(_ORDER_BY_ENTITY_ALIAS);
471 query.append(orderByFields[i]);
472
473 if ((i + 1) < orderByFields.length) {
474 if (orderByComparator.isAscending() ^ previous) {
475 query.append(ORDER_BY_ASC_HAS_NEXT);
476 }
477 else {
478 query.append(ORDER_BY_DESC_HAS_NEXT);
479 }
480 }
481 else {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC);
484 }
485 else {
486 query.append(ORDER_BY_DESC);
487 }
488 }
489 }
490 }
491 else {
492 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
493 }
494
495 String sql = query.toString();
496
497 Query q = session.createQuery(sql);
498
499 q.setFirstResult(0);
500 q.setMaxResults(2);
501
502 QueryPos qPos = QueryPos.getInstance(q);
503
504 if (bindUuid) {
505 qPos.add(uuid);
506 }
507
508 if (orderByComparator != null) {
509 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
510
511 for (Object value : values) {
512 qPos.add(value);
513 }
514 }
515
516 List<SocialRelation> list = q.list();
517
518 if (list.size() == 2) {
519 return list.get(1);
520 }
521 else {
522 return null;
523 }
524 }
525
526
532 public void removeByUuid(String uuid) throws SystemException {
533 for (SocialRelation socialRelation : findByUuid(uuid,
534 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
535 remove(socialRelation);
536 }
537 }
538
539
546 public int countByUuid(String uuid) throws SystemException {
547 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
548
549 Object[] finderArgs = new Object[] { uuid };
550
551 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552 this);
553
554 if (count == null) {
555 StringBundler query = new StringBundler(2);
556
557 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
558
559 boolean bindUuid = false;
560
561 if (uuid == null) {
562 query.append(_FINDER_COLUMN_UUID_UUID_1);
563 }
564 else if (uuid.equals(StringPool.BLANK)) {
565 query.append(_FINDER_COLUMN_UUID_UUID_3);
566 }
567 else {
568 bindUuid = true;
569
570 query.append(_FINDER_COLUMN_UUID_UUID_2);
571 }
572
573 String sql = query.toString();
574
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 Query q = session.createQuery(sql);
581
582 QueryPos qPos = QueryPos.getInstance(q);
583
584 if (bindUuid) {
585 qPos.add(uuid);
586 }
587
588 count = (Long)q.uniqueResult();
589
590 FinderCacheUtil.putResult(finderPath, finderArgs, count);
591 }
592 catch (Exception e) {
593 FinderCacheUtil.removeResult(finderPath, finderArgs);
594
595 throw processException(e);
596 }
597 finally {
598 closeSession(session);
599 }
600 }
601
602 return count.intValue();
603 }
604
605 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
606 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
607 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = '')";
608 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
609 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
610 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
611 "findByUuid_C",
612 new String[] {
613 String.class.getName(), Long.class.getName(),
614
615 Integer.class.getName(), Integer.class.getName(),
616 OrderByComparator.class.getName()
617 });
618 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
619 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
620 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
621 SocialRelationImpl.class,
622 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
623 new String[] { String.class.getName(), Long.class.getName() },
624 SocialRelationModelImpl.UUID_COLUMN_BITMASK |
625 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
626 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
627 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
628 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
629 new String[] { String.class.getName(), Long.class.getName() });
630
631
639 public List<SocialRelation> findByUuid_C(String uuid, long companyId)
640 throws SystemException {
641 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
642 QueryUtil.ALL_POS, null);
643 }
644
645
659 public List<SocialRelation> findByUuid_C(String uuid, long companyId,
660 int start, int end) throws SystemException {
661 return findByUuid_C(uuid, companyId, start, end, null);
662 }
663
664
679 public List<SocialRelation> findByUuid_C(String uuid, long companyId,
680 int start, int end, OrderByComparator orderByComparator)
681 throws SystemException {
682 boolean pagination = true;
683 FinderPath finderPath = null;
684 Object[] finderArgs = null;
685
686 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
687 (orderByComparator == null)) {
688 pagination = false;
689 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
690 finderArgs = new Object[] { uuid, companyId };
691 }
692 else {
693 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
694 finderArgs = new Object[] {
695 uuid, companyId,
696
697 start, end, orderByComparator
698 };
699 }
700
701 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
702 finderArgs, this);
703
704 if ((list != null) && !list.isEmpty()) {
705 for (SocialRelation socialRelation : list) {
706 if (!Validator.equals(uuid, socialRelation.getUuid()) ||
707 (companyId != socialRelation.getCompanyId())) {
708 list = null;
709
710 break;
711 }
712 }
713 }
714
715 if (list == null) {
716 StringBundler query = null;
717
718 if (orderByComparator != null) {
719 query = new StringBundler(4 +
720 (orderByComparator.getOrderByFields().length * 3));
721 }
722 else {
723 query = new StringBundler(4);
724 }
725
726 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
727
728 boolean bindUuid = false;
729
730 if (uuid == null) {
731 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
732 }
733 else if (uuid.equals(StringPool.BLANK)) {
734 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
735 }
736 else {
737 bindUuid = true;
738
739 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
740 }
741
742 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
743
744 if (orderByComparator != null) {
745 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
746 orderByComparator);
747 }
748 else
749 if (pagination) {
750 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
751 }
752
753 String sql = query.toString();
754
755 Session session = null;
756
757 try {
758 session = openSession();
759
760 Query q = session.createQuery(sql);
761
762 QueryPos qPos = QueryPos.getInstance(q);
763
764 if (bindUuid) {
765 qPos.add(uuid);
766 }
767
768 qPos.add(companyId);
769
770 if (!pagination) {
771 list = (List<SocialRelation>)QueryUtil.list(q,
772 getDialect(), start, end, false);
773
774 Collections.sort(list);
775
776 list = new UnmodifiableList<SocialRelation>(list);
777 }
778 else {
779 list = (List<SocialRelation>)QueryUtil.list(q,
780 getDialect(), start, end);
781 }
782
783 cacheResult(list);
784
785 FinderCacheUtil.putResult(finderPath, finderArgs, list);
786 }
787 catch (Exception e) {
788 FinderCacheUtil.removeResult(finderPath, finderArgs);
789
790 throw processException(e);
791 }
792 finally {
793 closeSession(session);
794 }
795 }
796
797 return list;
798 }
799
800
810 public SocialRelation findByUuid_C_First(String uuid, long companyId,
811 OrderByComparator orderByComparator)
812 throws NoSuchRelationException, SystemException {
813 SocialRelation socialRelation = fetchByUuid_C_First(uuid, companyId,
814 orderByComparator);
815
816 if (socialRelation != null) {
817 return socialRelation;
818 }
819
820 StringBundler msg = new StringBundler(6);
821
822 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
823
824 msg.append("uuid=");
825 msg.append(uuid);
826
827 msg.append(", companyId=");
828 msg.append(companyId);
829
830 msg.append(StringPool.CLOSE_CURLY_BRACE);
831
832 throw new NoSuchRelationException(msg.toString());
833 }
834
835
844 public SocialRelation fetchByUuid_C_First(String uuid, long companyId,
845 OrderByComparator orderByComparator) throws SystemException {
846 List<SocialRelation> list = findByUuid_C(uuid, companyId, 0, 1,
847 orderByComparator);
848
849 if (!list.isEmpty()) {
850 return list.get(0);
851 }
852
853 return null;
854 }
855
856
866 public SocialRelation findByUuid_C_Last(String uuid, long companyId,
867 OrderByComparator orderByComparator)
868 throws NoSuchRelationException, SystemException {
869 SocialRelation socialRelation = fetchByUuid_C_Last(uuid, companyId,
870 orderByComparator);
871
872 if (socialRelation != null) {
873 return socialRelation;
874 }
875
876 StringBundler msg = new StringBundler(6);
877
878 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
879
880 msg.append("uuid=");
881 msg.append(uuid);
882
883 msg.append(", companyId=");
884 msg.append(companyId);
885
886 msg.append(StringPool.CLOSE_CURLY_BRACE);
887
888 throw new NoSuchRelationException(msg.toString());
889 }
890
891
900 public SocialRelation fetchByUuid_C_Last(String uuid, long companyId,
901 OrderByComparator orderByComparator) throws SystemException {
902 int count = countByUuid_C(uuid, companyId);
903
904 List<SocialRelation> list = findByUuid_C(uuid, companyId, count - 1,
905 count, orderByComparator);
906
907 if (!list.isEmpty()) {
908 return list.get(0);
909 }
910
911 return null;
912 }
913
914
925 public SocialRelation[] findByUuid_C_PrevAndNext(long relationId,
926 String uuid, long companyId, OrderByComparator orderByComparator)
927 throws NoSuchRelationException, SystemException {
928 SocialRelation socialRelation = findByPrimaryKey(relationId);
929
930 Session session = null;
931
932 try {
933 session = openSession();
934
935 SocialRelation[] array = new SocialRelationImpl[3];
936
937 array[0] = getByUuid_C_PrevAndNext(session, socialRelation, uuid,
938 companyId, orderByComparator, true);
939
940 array[1] = socialRelation;
941
942 array[2] = getByUuid_C_PrevAndNext(session, socialRelation, uuid,
943 companyId, orderByComparator, false);
944
945 return array;
946 }
947 catch (Exception e) {
948 throw processException(e);
949 }
950 finally {
951 closeSession(session);
952 }
953 }
954
955 protected SocialRelation getByUuid_C_PrevAndNext(Session session,
956 SocialRelation socialRelation, String uuid, long companyId,
957 OrderByComparator orderByComparator, boolean previous) {
958 StringBundler query = null;
959
960 if (orderByComparator != null) {
961 query = new StringBundler(6 +
962 (orderByComparator.getOrderByFields().length * 6));
963 }
964 else {
965 query = new StringBundler(3);
966 }
967
968 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
969
970 boolean bindUuid = false;
971
972 if (uuid == null) {
973 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
974 }
975 else if (uuid.equals(StringPool.BLANK)) {
976 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
977 }
978 else {
979 bindUuid = true;
980
981 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
982 }
983
984 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
985
986 if (orderByComparator != null) {
987 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
988
989 if (orderByConditionFields.length > 0) {
990 query.append(WHERE_AND);
991 }
992
993 for (int i = 0; i < orderByConditionFields.length; i++) {
994 query.append(_ORDER_BY_ENTITY_ALIAS);
995 query.append(orderByConditionFields[i]);
996
997 if ((i + 1) < orderByConditionFields.length) {
998 if (orderByComparator.isAscending() ^ previous) {
999 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1000 }
1001 else {
1002 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1003 }
1004 }
1005 else {
1006 if (orderByComparator.isAscending() ^ previous) {
1007 query.append(WHERE_GREATER_THAN);
1008 }
1009 else {
1010 query.append(WHERE_LESSER_THAN);
1011 }
1012 }
1013 }
1014
1015 query.append(ORDER_BY_CLAUSE);
1016
1017 String[] orderByFields = orderByComparator.getOrderByFields();
1018
1019 for (int i = 0; i < orderByFields.length; i++) {
1020 query.append(_ORDER_BY_ENTITY_ALIAS);
1021 query.append(orderByFields[i]);
1022
1023 if ((i + 1) < orderByFields.length) {
1024 if (orderByComparator.isAscending() ^ previous) {
1025 query.append(ORDER_BY_ASC_HAS_NEXT);
1026 }
1027 else {
1028 query.append(ORDER_BY_DESC_HAS_NEXT);
1029 }
1030 }
1031 else {
1032 if (orderByComparator.isAscending() ^ previous) {
1033 query.append(ORDER_BY_ASC);
1034 }
1035 else {
1036 query.append(ORDER_BY_DESC);
1037 }
1038 }
1039 }
1040 }
1041 else {
1042 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1043 }
1044
1045 String sql = query.toString();
1046
1047 Query q = session.createQuery(sql);
1048
1049 q.setFirstResult(0);
1050 q.setMaxResults(2);
1051
1052 QueryPos qPos = QueryPos.getInstance(q);
1053
1054 if (bindUuid) {
1055 qPos.add(uuid);
1056 }
1057
1058 qPos.add(companyId);
1059
1060 if (orderByComparator != null) {
1061 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1062
1063 for (Object value : values) {
1064 qPos.add(value);
1065 }
1066 }
1067
1068 List<SocialRelation> list = q.list();
1069
1070 if (list.size() == 2) {
1071 return list.get(1);
1072 }
1073 else {
1074 return null;
1075 }
1076 }
1077
1078
1085 public void removeByUuid_C(String uuid, long companyId)
1086 throws SystemException {
1087 for (SocialRelation socialRelation : findByUuid_C(uuid, companyId,
1088 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1089 remove(socialRelation);
1090 }
1091 }
1092
1093
1101 public int countByUuid_C(String uuid, long companyId)
1102 throws SystemException {
1103 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1104
1105 Object[] finderArgs = new Object[] { uuid, companyId };
1106
1107 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1108 this);
1109
1110 if (count == null) {
1111 StringBundler query = new StringBundler(3);
1112
1113 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
1114
1115 boolean bindUuid = false;
1116
1117 if (uuid == null) {
1118 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1119 }
1120 else if (uuid.equals(StringPool.BLANK)) {
1121 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1122 }
1123 else {
1124 bindUuid = true;
1125
1126 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1127 }
1128
1129 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1130
1131 String sql = query.toString();
1132
1133 Session session = null;
1134
1135 try {
1136 session = openSession();
1137
1138 Query q = session.createQuery(sql);
1139
1140 QueryPos qPos = QueryPos.getInstance(q);
1141
1142 if (bindUuid) {
1143 qPos.add(uuid);
1144 }
1145
1146 qPos.add(companyId);
1147
1148 count = (Long)q.uniqueResult();
1149
1150 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1151 }
1152 catch (Exception e) {
1153 FinderCacheUtil.removeResult(finderPath, finderArgs);
1154
1155 throw processException(e);
1156 }
1157 finally {
1158 closeSession(session);
1159 }
1160 }
1161
1162 return count.intValue();
1163 }
1164
1165 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "socialRelation.uuid IS NULL AND ";
1166 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "socialRelation.uuid = ? AND ";
1167 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = '') AND ";
1168 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "socialRelation.companyId = ?";
1169 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1170 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1171 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1172 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1173 "findByCompanyId",
1174 new String[] {
1175 Long.class.getName(),
1176
1177 Integer.class.getName(), Integer.class.getName(),
1178 OrderByComparator.class.getName()
1179 });
1180 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1181 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1182 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1183 SocialRelationImpl.class,
1184 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1185 new String[] { Long.class.getName() },
1186 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
1187 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1188 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1189 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1190 new String[] { Long.class.getName() });
1191
1192
1199 public List<SocialRelation> findByCompanyId(long companyId)
1200 throws SystemException {
1201 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1202 null);
1203 }
1204
1205
1218 public List<SocialRelation> findByCompanyId(long companyId, int start,
1219 int end) throws SystemException {
1220 return findByCompanyId(companyId, start, end, null);
1221 }
1222
1223
1237 public List<SocialRelation> findByCompanyId(long companyId, int start,
1238 int end, OrderByComparator orderByComparator) throws SystemException {
1239 boolean pagination = true;
1240 FinderPath finderPath = null;
1241 Object[] finderArgs = null;
1242
1243 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1244 (orderByComparator == null)) {
1245 pagination = false;
1246 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1247 finderArgs = new Object[] { companyId };
1248 }
1249 else {
1250 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1251 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1252 }
1253
1254 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1255 finderArgs, this);
1256
1257 if ((list != null) && !list.isEmpty()) {
1258 for (SocialRelation socialRelation : list) {
1259 if ((companyId != socialRelation.getCompanyId())) {
1260 list = null;
1261
1262 break;
1263 }
1264 }
1265 }
1266
1267 if (list == null) {
1268 StringBundler query = null;
1269
1270 if (orderByComparator != null) {
1271 query = new StringBundler(3 +
1272 (orderByComparator.getOrderByFields().length * 3));
1273 }
1274 else {
1275 query = new StringBundler(3);
1276 }
1277
1278 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1279
1280 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1281
1282 if (orderByComparator != null) {
1283 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1284 orderByComparator);
1285 }
1286 else
1287 if (pagination) {
1288 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1289 }
1290
1291 String sql = query.toString();
1292
1293 Session session = null;
1294
1295 try {
1296 session = openSession();
1297
1298 Query q = session.createQuery(sql);
1299
1300 QueryPos qPos = QueryPos.getInstance(q);
1301
1302 qPos.add(companyId);
1303
1304 if (!pagination) {
1305 list = (List<SocialRelation>)QueryUtil.list(q,
1306 getDialect(), start, end, false);
1307
1308 Collections.sort(list);
1309
1310 list = new UnmodifiableList<SocialRelation>(list);
1311 }
1312 else {
1313 list = (List<SocialRelation>)QueryUtil.list(q,
1314 getDialect(), start, end);
1315 }
1316
1317 cacheResult(list);
1318
1319 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1320 }
1321 catch (Exception e) {
1322 FinderCacheUtil.removeResult(finderPath, finderArgs);
1323
1324 throw processException(e);
1325 }
1326 finally {
1327 closeSession(session);
1328 }
1329 }
1330
1331 return list;
1332 }
1333
1334
1343 public SocialRelation findByCompanyId_First(long companyId,
1344 OrderByComparator orderByComparator)
1345 throws NoSuchRelationException, SystemException {
1346 SocialRelation socialRelation = fetchByCompanyId_First(companyId,
1347 orderByComparator);
1348
1349 if (socialRelation != null) {
1350 return socialRelation;
1351 }
1352
1353 StringBundler msg = new StringBundler(4);
1354
1355 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1356
1357 msg.append("companyId=");
1358 msg.append(companyId);
1359
1360 msg.append(StringPool.CLOSE_CURLY_BRACE);
1361
1362 throw new NoSuchRelationException(msg.toString());
1363 }
1364
1365
1373 public SocialRelation fetchByCompanyId_First(long companyId,
1374 OrderByComparator orderByComparator) throws SystemException {
1375 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1376 orderByComparator);
1377
1378 if (!list.isEmpty()) {
1379 return list.get(0);
1380 }
1381
1382 return null;
1383 }
1384
1385
1394 public SocialRelation findByCompanyId_Last(long companyId,
1395 OrderByComparator orderByComparator)
1396 throws NoSuchRelationException, SystemException {
1397 SocialRelation socialRelation = fetchByCompanyId_Last(companyId,
1398 orderByComparator);
1399
1400 if (socialRelation != null) {
1401 return socialRelation;
1402 }
1403
1404 StringBundler msg = new StringBundler(4);
1405
1406 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1407
1408 msg.append("companyId=");
1409 msg.append(companyId);
1410
1411 msg.append(StringPool.CLOSE_CURLY_BRACE);
1412
1413 throw new NoSuchRelationException(msg.toString());
1414 }
1415
1416
1424 public SocialRelation fetchByCompanyId_Last(long companyId,
1425 OrderByComparator orderByComparator) throws SystemException {
1426 int count = countByCompanyId(companyId);
1427
1428 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1429 count, orderByComparator);
1430
1431 if (!list.isEmpty()) {
1432 return list.get(0);
1433 }
1434
1435 return null;
1436 }
1437
1438
1448 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1449 long companyId, OrderByComparator orderByComparator)
1450 throws NoSuchRelationException, SystemException {
1451 SocialRelation socialRelation = findByPrimaryKey(relationId);
1452
1453 Session session = null;
1454
1455 try {
1456 session = openSession();
1457
1458 SocialRelation[] array = new SocialRelationImpl[3];
1459
1460 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1461 companyId, orderByComparator, true);
1462
1463 array[1] = socialRelation;
1464
1465 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1466 companyId, orderByComparator, false);
1467
1468 return array;
1469 }
1470 catch (Exception e) {
1471 throw processException(e);
1472 }
1473 finally {
1474 closeSession(session);
1475 }
1476 }
1477
1478 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1479 SocialRelation socialRelation, long companyId,
1480 OrderByComparator orderByComparator, boolean previous) {
1481 StringBundler query = null;
1482
1483 if (orderByComparator != null) {
1484 query = new StringBundler(6 +
1485 (orderByComparator.getOrderByFields().length * 6));
1486 }
1487 else {
1488 query = new StringBundler(3);
1489 }
1490
1491 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1492
1493 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1494
1495 if (orderByComparator != null) {
1496 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1497
1498 if (orderByConditionFields.length > 0) {
1499 query.append(WHERE_AND);
1500 }
1501
1502 for (int i = 0; i < orderByConditionFields.length; i++) {
1503 query.append(_ORDER_BY_ENTITY_ALIAS);
1504 query.append(orderByConditionFields[i]);
1505
1506 if ((i + 1) < orderByConditionFields.length) {
1507 if (orderByComparator.isAscending() ^ previous) {
1508 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1509 }
1510 else {
1511 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1512 }
1513 }
1514 else {
1515 if (orderByComparator.isAscending() ^ previous) {
1516 query.append(WHERE_GREATER_THAN);
1517 }
1518 else {
1519 query.append(WHERE_LESSER_THAN);
1520 }
1521 }
1522 }
1523
1524 query.append(ORDER_BY_CLAUSE);
1525
1526 String[] orderByFields = orderByComparator.getOrderByFields();
1527
1528 for (int i = 0; i < orderByFields.length; i++) {
1529 query.append(_ORDER_BY_ENTITY_ALIAS);
1530 query.append(orderByFields[i]);
1531
1532 if ((i + 1) < orderByFields.length) {
1533 if (orderByComparator.isAscending() ^ previous) {
1534 query.append(ORDER_BY_ASC_HAS_NEXT);
1535 }
1536 else {
1537 query.append(ORDER_BY_DESC_HAS_NEXT);
1538 }
1539 }
1540 else {
1541 if (orderByComparator.isAscending() ^ previous) {
1542 query.append(ORDER_BY_ASC);
1543 }
1544 else {
1545 query.append(ORDER_BY_DESC);
1546 }
1547 }
1548 }
1549 }
1550 else {
1551 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1552 }
1553
1554 String sql = query.toString();
1555
1556 Query q = session.createQuery(sql);
1557
1558 q.setFirstResult(0);
1559 q.setMaxResults(2);
1560
1561 QueryPos qPos = QueryPos.getInstance(q);
1562
1563 qPos.add(companyId);
1564
1565 if (orderByComparator != null) {
1566 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1567
1568 for (Object value : values) {
1569 qPos.add(value);
1570 }
1571 }
1572
1573 List<SocialRelation> list = q.list();
1574
1575 if (list.size() == 2) {
1576 return list.get(1);
1577 }
1578 else {
1579 return null;
1580 }
1581 }
1582
1583
1589 public void removeByCompanyId(long companyId) throws SystemException {
1590 for (SocialRelation socialRelation : findByCompanyId(companyId,
1591 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1592 remove(socialRelation);
1593 }
1594 }
1595
1596
1603 public int countByCompanyId(long companyId) throws SystemException {
1604 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1605
1606 Object[] finderArgs = new Object[] { companyId };
1607
1608 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1609 this);
1610
1611 if (count == null) {
1612 StringBundler query = new StringBundler(2);
1613
1614 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
1615
1616 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1617
1618 String sql = query.toString();
1619
1620 Session session = null;
1621
1622 try {
1623 session = openSession();
1624
1625 Query q = session.createQuery(sql);
1626
1627 QueryPos qPos = QueryPos.getInstance(q);
1628
1629 qPos.add(companyId);
1630
1631 count = (Long)q.uniqueResult();
1632
1633 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1634 }
1635 catch (Exception e) {
1636 FinderCacheUtil.removeResult(finderPath, finderArgs);
1637
1638 throw processException(e);
1639 }
1640 finally {
1641 closeSession(session);
1642 }
1643 }
1644
1645 return count.intValue();
1646 }
1647
1648 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
1649 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1650 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1651 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1652 "findByUserId1",
1653 new String[] {
1654 Long.class.getName(),
1655
1656 Integer.class.getName(), Integer.class.getName(),
1657 OrderByComparator.class.getName()
1658 });
1659 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1 =
1660 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1661 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1662 SocialRelationImpl.class,
1663 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId1",
1664 new String[] { Long.class.getName() },
1665 SocialRelationModelImpl.USERID1_COLUMN_BITMASK);
1666 public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1667 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1668 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId1",
1669 new String[] { Long.class.getName() });
1670
1671
1678 public List<SocialRelation> findByUserId1(long userId1)
1679 throws SystemException {
1680 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1681 }
1682
1683
1696 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1697 throws SystemException {
1698 return findByUserId1(userId1, start, end, null);
1699 }
1700
1701
1715 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1716 OrderByComparator orderByComparator) throws SystemException {
1717 boolean pagination = true;
1718 FinderPath finderPath = null;
1719 Object[] finderArgs = null;
1720
1721 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1722 (orderByComparator == null)) {
1723 pagination = false;
1724 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1725 finderArgs = new Object[] { userId1 };
1726 }
1727 else {
1728 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1729 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1730 }
1731
1732 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1733 finderArgs, this);
1734
1735 if ((list != null) && !list.isEmpty()) {
1736 for (SocialRelation socialRelation : list) {
1737 if ((userId1 != socialRelation.getUserId1())) {
1738 list = null;
1739
1740 break;
1741 }
1742 }
1743 }
1744
1745 if (list == null) {
1746 StringBundler query = null;
1747
1748 if (orderByComparator != null) {
1749 query = new StringBundler(3 +
1750 (orderByComparator.getOrderByFields().length * 3));
1751 }
1752 else {
1753 query = new StringBundler(3);
1754 }
1755
1756 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1757
1758 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1759
1760 if (orderByComparator != null) {
1761 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1762 orderByComparator);
1763 }
1764 else
1765 if (pagination) {
1766 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1767 }
1768
1769 String sql = query.toString();
1770
1771 Session session = null;
1772
1773 try {
1774 session = openSession();
1775
1776 Query q = session.createQuery(sql);
1777
1778 QueryPos qPos = QueryPos.getInstance(q);
1779
1780 qPos.add(userId1);
1781
1782 if (!pagination) {
1783 list = (List<SocialRelation>)QueryUtil.list(q,
1784 getDialect(), start, end, false);
1785
1786 Collections.sort(list);
1787
1788 list = new UnmodifiableList<SocialRelation>(list);
1789 }
1790 else {
1791 list = (List<SocialRelation>)QueryUtil.list(q,
1792 getDialect(), start, end);
1793 }
1794
1795 cacheResult(list);
1796
1797 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1798 }
1799 catch (Exception e) {
1800 FinderCacheUtil.removeResult(finderPath, finderArgs);
1801
1802 throw processException(e);
1803 }
1804 finally {
1805 closeSession(session);
1806 }
1807 }
1808
1809 return list;
1810 }
1811
1812
1821 public SocialRelation findByUserId1_First(long userId1,
1822 OrderByComparator orderByComparator)
1823 throws NoSuchRelationException, SystemException {
1824 SocialRelation socialRelation = fetchByUserId1_First(userId1,
1825 orderByComparator);
1826
1827 if (socialRelation != null) {
1828 return socialRelation;
1829 }
1830
1831 StringBundler msg = new StringBundler(4);
1832
1833 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1834
1835 msg.append("userId1=");
1836 msg.append(userId1);
1837
1838 msg.append(StringPool.CLOSE_CURLY_BRACE);
1839
1840 throw new NoSuchRelationException(msg.toString());
1841 }
1842
1843
1851 public SocialRelation fetchByUserId1_First(long userId1,
1852 OrderByComparator orderByComparator) throws SystemException {
1853 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1854 orderByComparator);
1855
1856 if (!list.isEmpty()) {
1857 return list.get(0);
1858 }
1859
1860 return null;
1861 }
1862
1863
1872 public SocialRelation findByUserId1_Last(long userId1,
1873 OrderByComparator orderByComparator)
1874 throws NoSuchRelationException, SystemException {
1875 SocialRelation socialRelation = fetchByUserId1_Last(userId1,
1876 orderByComparator);
1877
1878 if (socialRelation != null) {
1879 return socialRelation;
1880 }
1881
1882 StringBundler msg = new StringBundler(4);
1883
1884 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1885
1886 msg.append("userId1=");
1887 msg.append(userId1);
1888
1889 msg.append(StringPool.CLOSE_CURLY_BRACE);
1890
1891 throw new NoSuchRelationException(msg.toString());
1892 }
1893
1894
1902 public SocialRelation fetchByUserId1_Last(long userId1,
1903 OrderByComparator orderByComparator) throws SystemException {
1904 int count = countByUserId1(userId1);
1905
1906 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1907 orderByComparator);
1908
1909 if (!list.isEmpty()) {
1910 return list.get(0);
1911 }
1912
1913 return null;
1914 }
1915
1916
1926 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1927 long userId1, OrderByComparator orderByComparator)
1928 throws NoSuchRelationException, SystemException {
1929 SocialRelation socialRelation = findByPrimaryKey(relationId);
1930
1931 Session session = null;
1932
1933 try {
1934 session = openSession();
1935
1936 SocialRelation[] array = new SocialRelationImpl[3];
1937
1938 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1939 userId1, orderByComparator, true);
1940
1941 array[1] = socialRelation;
1942
1943 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1944 userId1, orderByComparator, false);
1945
1946 return array;
1947 }
1948 catch (Exception e) {
1949 throw processException(e);
1950 }
1951 finally {
1952 closeSession(session);
1953 }
1954 }
1955
1956 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1957 SocialRelation socialRelation, long userId1,
1958 OrderByComparator orderByComparator, boolean previous) {
1959 StringBundler query = null;
1960
1961 if (orderByComparator != null) {
1962 query = new StringBundler(6 +
1963 (orderByComparator.getOrderByFields().length * 6));
1964 }
1965 else {
1966 query = new StringBundler(3);
1967 }
1968
1969 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1970
1971 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1972
1973 if (orderByComparator != null) {
1974 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1975
1976 if (orderByConditionFields.length > 0) {
1977 query.append(WHERE_AND);
1978 }
1979
1980 for (int i = 0; i < orderByConditionFields.length; i++) {
1981 query.append(_ORDER_BY_ENTITY_ALIAS);
1982 query.append(orderByConditionFields[i]);
1983
1984 if ((i + 1) < orderByConditionFields.length) {
1985 if (orderByComparator.isAscending() ^ previous) {
1986 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1987 }
1988 else {
1989 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1990 }
1991 }
1992 else {
1993 if (orderByComparator.isAscending() ^ previous) {
1994 query.append(WHERE_GREATER_THAN);
1995 }
1996 else {
1997 query.append(WHERE_LESSER_THAN);
1998 }
1999 }
2000 }
2001
2002 query.append(ORDER_BY_CLAUSE);
2003
2004 String[] orderByFields = orderByComparator.getOrderByFields();
2005
2006 for (int i = 0; i < orderByFields.length; i++) {
2007 query.append(_ORDER_BY_ENTITY_ALIAS);
2008 query.append(orderByFields[i]);
2009
2010 if ((i + 1) < orderByFields.length) {
2011 if (orderByComparator.isAscending() ^ previous) {
2012 query.append(ORDER_BY_ASC_HAS_NEXT);
2013 }
2014 else {
2015 query.append(ORDER_BY_DESC_HAS_NEXT);
2016 }
2017 }
2018 else {
2019 if (orderByComparator.isAscending() ^ previous) {
2020 query.append(ORDER_BY_ASC);
2021 }
2022 else {
2023 query.append(ORDER_BY_DESC);
2024 }
2025 }
2026 }
2027 }
2028 else {
2029 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2030 }
2031
2032 String sql = query.toString();
2033
2034 Query q = session.createQuery(sql);
2035
2036 q.setFirstResult(0);
2037 q.setMaxResults(2);
2038
2039 QueryPos qPos = QueryPos.getInstance(q);
2040
2041 qPos.add(userId1);
2042
2043 if (orderByComparator != null) {
2044 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2045
2046 for (Object value : values) {
2047 qPos.add(value);
2048 }
2049 }
2050
2051 List<SocialRelation> list = q.list();
2052
2053 if (list.size() == 2) {
2054 return list.get(1);
2055 }
2056 else {
2057 return null;
2058 }
2059 }
2060
2061
2067 public void removeByUserId1(long userId1) throws SystemException {
2068 for (SocialRelation socialRelation : findByUserId1(userId1,
2069 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2070 remove(socialRelation);
2071 }
2072 }
2073
2074
2081 public int countByUserId1(long userId1) throws SystemException {
2082 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID1;
2083
2084 Object[] finderArgs = new Object[] { userId1 };
2085
2086 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2087 this);
2088
2089 if (count == null) {
2090 StringBundler query = new StringBundler(2);
2091
2092 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2093
2094 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
2095
2096 String sql = query.toString();
2097
2098 Session session = null;
2099
2100 try {
2101 session = openSession();
2102
2103 Query q = session.createQuery(sql);
2104
2105 QueryPos qPos = QueryPos.getInstance(q);
2106
2107 qPos.add(userId1);
2108
2109 count = (Long)q.uniqueResult();
2110
2111 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2112 }
2113 catch (Exception e) {
2114 FinderCacheUtil.removeResult(finderPath, finderArgs);
2115
2116 throw processException(e);
2117 }
2118 finally {
2119 closeSession(session);
2120 }
2121 }
2122
2123 return count.intValue();
2124 }
2125
2126 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
2127 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2128 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2129 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2130 "findByUserId2",
2131 new String[] {
2132 Long.class.getName(),
2133
2134 Integer.class.getName(), Integer.class.getName(),
2135 OrderByComparator.class.getName()
2136 });
2137 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2 =
2138 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2139 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2140 SocialRelationImpl.class,
2141 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId2",
2142 new String[] { Long.class.getName() },
2143 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
2144 public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2145 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2146 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId2",
2147 new String[] { Long.class.getName() });
2148
2149
2156 public List<SocialRelation> findByUserId2(long userId2)
2157 throws SystemException {
2158 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2159 }
2160
2161
2174 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
2175 throws SystemException {
2176 return findByUserId2(userId2, start, end, null);
2177 }
2178
2179
2193 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
2194 OrderByComparator orderByComparator) throws SystemException {
2195 boolean pagination = true;
2196 FinderPath finderPath = null;
2197 Object[] finderArgs = null;
2198
2199 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2200 (orderByComparator == null)) {
2201 pagination = false;
2202 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
2203 finderArgs = new Object[] { userId2 };
2204 }
2205 else {
2206 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
2207 finderArgs = new Object[] { userId2, start, end, orderByComparator };
2208 }
2209
2210 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2211 finderArgs, this);
2212
2213 if ((list != null) && !list.isEmpty()) {
2214 for (SocialRelation socialRelation : list) {
2215 if ((userId2 != socialRelation.getUserId2())) {
2216 list = null;
2217
2218 break;
2219 }
2220 }
2221 }
2222
2223 if (list == null) {
2224 StringBundler query = null;
2225
2226 if (orderByComparator != null) {
2227 query = new StringBundler(3 +
2228 (orderByComparator.getOrderByFields().length * 3));
2229 }
2230 else {
2231 query = new StringBundler(3);
2232 }
2233
2234 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2235
2236 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2237
2238 if (orderByComparator != null) {
2239 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2240 orderByComparator);
2241 }
2242 else
2243 if (pagination) {
2244 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2245 }
2246
2247 String sql = query.toString();
2248
2249 Session session = null;
2250
2251 try {
2252 session = openSession();
2253
2254 Query q = session.createQuery(sql);
2255
2256 QueryPos qPos = QueryPos.getInstance(q);
2257
2258 qPos.add(userId2);
2259
2260 if (!pagination) {
2261 list = (List<SocialRelation>)QueryUtil.list(q,
2262 getDialect(), start, end, false);
2263
2264 Collections.sort(list);
2265
2266 list = new UnmodifiableList<SocialRelation>(list);
2267 }
2268 else {
2269 list = (List<SocialRelation>)QueryUtil.list(q,
2270 getDialect(), start, end);
2271 }
2272
2273 cacheResult(list);
2274
2275 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2276 }
2277 catch (Exception e) {
2278 FinderCacheUtil.removeResult(finderPath, finderArgs);
2279
2280 throw processException(e);
2281 }
2282 finally {
2283 closeSession(session);
2284 }
2285 }
2286
2287 return list;
2288 }
2289
2290
2299 public SocialRelation findByUserId2_First(long userId2,
2300 OrderByComparator orderByComparator)
2301 throws NoSuchRelationException, SystemException {
2302 SocialRelation socialRelation = fetchByUserId2_First(userId2,
2303 orderByComparator);
2304
2305 if (socialRelation != null) {
2306 return socialRelation;
2307 }
2308
2309 StringBundler msg = new StringBundler(4);
2310
2311 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2312
2313 msg.append("userId2=");
2314 msg.append(userId2);
2315
2316 msg.append(StringPool.CLOSE_CURLY_BRACE);
2317
2318 throw new NoSuchRelationException(msg.toString());
2319 }
2320
2321
2329 public SocialRelation fetchByUserId2_First(long userId2,
2330 OrderByComparator orderByComparator) throws SystemException {
2331 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2332 orderByComparator);
2333
2334 if (!list.isEmpty()) {
2335 return list.get(0);
2336 }
2337
2338 return null;
2339 }
2340
2341
2350 public SocialRelation findByUserId2_Last(long userId2,
2351 OrderByComparator orderByComparator)
2352 throws NoSuchRelationException, SystemException {
2353 SocialRelation socialRelation = fetchByUserId2_Last(userId2,
2354 orderByComparator);
2355
2356 if (socialRelation != null) {
2357 return socialRelation;
2358 }
2359
2360 StringBundler msg = new StringBundler(4);
2361
2362 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2363
2364 msg.append("userId2=");
2365 msg.append(userId2);
2366
2367 msg.append(StringPool.CLOSE_CURLY_BRACE);
2368
2369 throw new NoSuchRelationException(msg.toString());
2370 }
2371
2372
2380 public SocialRelation fetchByUserId2_Last(long userId2,
2381 OrderByComparator orderByComparator) throws SystemException {
2382 int count = countByUserId2(userId2);
2383
2384 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2385 orderByComparator);
2386
2387 if (!list.isEmpty()) {
2388 return list.get(0);
2389 }
2390
2391 return null;
2392 }
2393
2394
2404 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2405 long userId2, OrderByComparator orderByComparator)
2406 throws NoSuchRelationException, SystemException {
2407 SocialRelation socialRelation = findByPrimaryKey(relationId);
2408
2409 Session session = null;
2410
2411 try {
2412 session = openSession();
2413
2414 SocialRelation[] array = new SocialRelationImpl[3];
2415
2416 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2417 userId2, orderByComparator, true);
2418
2419 array[1] = socialRelation;
2420
2421 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2422 userId2, orderByComparator, false);
2423
2424 return array;
2425 }
2426 catch (Exception e) {
2427 throw processException(e);
2428 }
2429 finally {
2430 closeSession(session);
2431 }
2432 }
2433
2434 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2435 SocialRelation socialRelation, long userId2,
2436 OrderByComparator orderByComparator, boolean previous) {
2437 StringBundler query = null;
2438
2439 if (orderByComparator != null) {
2440 query = new StringBundler(6 +
2441 (orderByComparator.getOrderByFields().length * 6));
2442 }
2443 else {
2444 query = new StringBundler(3);
2445 }
2446
2447 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2448
2449 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2450
2451 if (orderByComparator != null) {
2452 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2453
2454 if (orderByConditionFields.length > 0) {
2455 query.append(WHERE_AND);
2456 }
2457
2458 for (int i = 0; i < orderByConditionFields.length; i++) {
2459 query.append(_ORDER_BY_ENTITY_ALIAS);
2460 query.append(orderByConditionFields[i]);
2461
2462 if ((i + 1) < orderByConditionFields.length) {
2463 if (orderByComparator.isAscending() ^ previous) {
2464 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2465 }
2466 else {
2467 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2468 }
2469 }
2470 else {
2471 if (orderByComparator.isAscending() ^ previous) {
2472 query.append(WHERE_GREATER_THAN);
2473 }
2474 else {
2475 query.append(WHERE_LESSER_THAN);
2476 }
2477 }
2478 }
2479
2480 query.append(ORDER_BY_CLAUSE);
2481
2482 String[] orderByFields = orderByComparator.getOrderByFields();
2483
2484 for (int i = 0; i < orderByFields.length; i++) {
2485 query.append(_ORDER_BY_ENTITY_ALIAS);
2486 query.append(orderByFields[i]);
2487
2488 if ((i + 1) < orderByFields.length) {
2489 if (orderByComparator.isAscending() ^ previous) {
2490 query.append(ORDER_BY_ASC_HAS_NEXT);
2491 }
2492 else {
2493 query.append(ORDER_BY_DESC_HAS_NEXT);
2494 }
2495 }
2496 else {
2497 if (orderByComparator.isAscending() ^ previous) {
2498 query.append(ORDER_BY_ASC);
2499 }
2500 else {
2501 query.append(ORDER_BY_DESC);
2502 }
2503 }
2504 }
2505 }
2506 else {
2507 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2508 }
2509
2510 String sql = query.toString();
2511
2512 Query q = session.createQuery(sql);
2513
2514 q.setFirstResult(0);
2515 q.setMaxResults(2);
2516
2517 QueryPos qPos = QueryPos.getInstance(q);
2518
2519 qPos.add(userId2);
2520
2521 if (orderByComparator != null) {
2522 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2523
2524 for (Object value : values) {
2525 qPos.add(value);
2526 }
2527 }
2528
2529 List<SocialRelation> list = q.list();
2530
2531 if (list.size() == 2) {
2532 return list.get(1);
2533 }
2534 else {
2535 return null;
2536 }
2537 }
2538
2539
2545 public void removeByUserId2(long userId2) throws SystemException {
2546 for (SocialRelation socialRelation : findByUserId2(userId2,
2547 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2548 remove(socialRelation);
2549 }
2550 }
2551
2552
2559 public int countByUserId2(long userId2) throws SystemException {
2560 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID2;
2561
2562 Object[] finderArgs = new Object[] { userId2 };
2563
2564 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2565 this);
2566
2567 if (count == null) {
2568 StringBundler query = new StringBundler(2);
2569
2570 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2571
2572 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2573
2574 String sql = query.toString();
2575
2576 Session session = null;
2577
2578 try {
2579 session = openSession();
2580
2581 Query q = session.createQuery(sql);
2582
2583 QueryPos qPos = QueryPos.getInstance(q);
2584
2585 qPos.add(userId2);
2586
2587 count = (Long)q.uniqueResult();
2588
2589 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2590 }
2591 catch (Exception e) {
2592 FinderCacheUtil.removeResult(finderPath, finderArgs);
2593
2594 throw processException(e);
2595 }
2596 finally {
2597 closeSession(session);
2598 }
2599 }
2600
2601 return count.intValue();
2602 }
2603
2604 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
2605 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2606 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2607 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2608 "findByType",
2609 new String[] {
2610 Integer.class.getName(),
2611
2612 Integer.class.getName(), Integer.class.getName(),
2613 OrderByComparator.class.getName()
2614 });
2615 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2616 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2617 SocialRelationImpl.class,
2618 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
2619 new String[] { Integer.class.getName() },
2620 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
2621 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2622 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
2624 new String[] { Integer.class.getName() });
2625
2626
2633 public List<SocialRelation> findByType(int type) throws SystemException {
2634 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2635 }
2636
2637
2650 public List<SocialRelation> findByType(int type, int start, int end)
2651 throws SystemException {
2652 return findByType(type, start, end, null);
2653 }
2654
2655
2669 public List<SocialRelation> findByType(int type, int start, int end,
2670 OrderByComparator orderByComparator) throws SystemException {
2671 boolean pagination = true;
2672 FinderPath finderPath = null;
2673 Object[] finderArgs = null;
2674
2675 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2676 (orderByComparator == null)) {
2677 pagination = false;
2678 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2679 finderArgs = new Object[] { type };
2680 }
2681 else {
2682 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2683 finderArgs = new Object[] { type, start, end, orderByComparator };
2684 }
2685
2686 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2687 finderArgs, this);
2688
2689 if ((list != null) && !list.isEmpty()) {
2690 for (SocialRelation socialRelation : list) {
2691 if ((type != socialRelation.getType())) {
2692 list = null;
2693
2694 break;
2695 }
2696 }
2697 }
2698
2699 if (list == null) {
2700 StringBundler query = null;
2701
2702 if (orderByComparator != null) {
2703 query = new StringBundler(3 +
2704 (orderByComparator.getOrderByFields().length * 3));
2705 }
2706 else {
2707 query = new StringBundler(3);
2708 }
2709
2710 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2711
2712 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2713
2714 if (orderByComparator != null) {
2715 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2716 orderByComparator);
2717 }
2718 else
2719 if (pagination) {
2720 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2721 }
2722
2723 String sql = query.toString();
2724
2725 Session session = null;
2726
2727 try {
2728 session = openSession();
2729
2730 Query q = session.createQuery(sql);
2731
2732 QueryPos qPos = QueryPos.getInstance(q);
2733
2734 qPos.add(type);
2735
2736 if (!pagination) {
2737 list = (List<SocialRelation>)QueryUtil.list(q,
2738 getDialect(), start, end, false);
2739
2740 Collections.sort(list);
2741
2742 list = new UnmodifiableList<SocialRelation>(list);
2743 }
2744 else {
2745 list = (List<SocialRelation>)QueryUtil.list(q,
2746 getDialect(), start, end);
2747 }
2748
2749 cacheResult(list);
2750
2751 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2752 }
2753 catch (Exception e) {
2754 FinderCacheUtil.removeResult(finderPath, finderArgs);
2755
2756 throw processException(e);
2757 }
2758 finally {
2759 closeSession(session);
2760 }
2761 }
2762
2763 return list;
2764 }
2765
2766
2775 public SocialRelation findByType_First(int type,
2776 OrderByComparator orderByComparator)
2777 throws NoSuchRelationException, SystemException {
2778 SocialRelation socialRelation = fetchByType_First(type,
2779 orderByComparator);
2780
2781 if (socialRelation != null) {
2782 return socialRelation;
2783 }
2784
2785 StringBundler msg = new StringBundler(4);
2786
2787 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2788
2789 msg.append("type=");
2790 msg.append(type);
2791
2792 msg.append(StringPool.CLOSE_CURLY_BRACE);
2793
2794 throw new NoSuchRelationException(msg.toString());
2795 }
2796
2797
2805 public SocialRelation fetchByType_First(int type,
2806 OrderByComparator orderByComparator) throws SystemException {
2807 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2808
2809 if (!list.isEmpty()) {
2810 return list.get(0);
2811 }
2812
2813 return null;
2814 }
2815
2816
2825 public SocialRelation findByType_Last(int type,
2826 OrderByComparator orderByComparator)
2827 throws NoSuchRelationException, SystemException {
2828 SocialRelation socialRelation = fetchByType_Last(type, orderByComparator);
2829
2830 if (socialRelation != null) {
2831 return socialRelation;
2832 }
2833
2834 StringBundler msg = new StringBundler(4);
2835
2836 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2837
2838 msg.append("type=");
2839 msg.append(type);
2840
2841 msg.append(StringPool.CLOSE_CURLY_BRACE);
2842
2843 throw new NoSuchRelationException(msg.toString());
2844 }
2845
2846
2854 public SocialRelation fetchByType_Last(int type,
2855 OrderByComparator orderByComparator) throws SystemException {
2856 int count = countByType(type);
2857
2858 List<SocialRelation> list = findByType(type, count - 1, count,
2859 orderByComparator);
2860
2861 if (!list.isEmpty()) {
2862 return list.get(0);
2863 }
2864
2865 return null;
2866 }
2867
2868
2878 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2879 OrderByComparator orderByComparator)
2880 throws NoSuchRelationException, SystemException {
2881 SocialRelation socialRelation = findByPrimaryKey(relationId);
2882
2883 Session session = null;
2884
2885 try {
2886 session = openSession();
2887
2888 SocialRelation[] array = new SocialRelationImpl[3];
2889
2890 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2891 orderByComparator, true);
2892
2893 array[1] = socialRelation;
2894
2895 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2896 orderByComparator, false);
2897
2898 return array;
2899 }
2900 catch (Exception e) {
2901 throw processException(e);
2902 }
2903 finally {
2904 closeSession(session);
2905 }
2906 }
2907
2908 protected SocialRelation getByType_PrevAndNext(Session session,
2909 SocialRelation socialRelation, int type,
2910 OrderByComparator orderByComparator, boolean previous) {
2911 StringBundler query = null;
2912
2913 if (orderByComparator != null) {
2914 query = new StringBundler(6 +
2915 (orderByComparator.getOrderByFields().length * 6));
2916 }
2917 else {
2918 query = new StringBundler(3);
2919 }
2920
2921 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2922
2923 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2924
2925 if (orderByComparator != null) {
2926 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2927
2928 if (orderByConditionFields.length > 0) {
2929 query.append(WHERE_AND);
2930 }
2931
2932 for (int i = 0; i < orderByConditionFields.length; i++) {
2933 query.append(_ORDER_BY_ENTITY_ALIAS);
2934 query.append(orderByConditionFields[i]);
2935
2936 if ((i + 1) < orderByConditionFields.length) {
2937 if (orderByComparator.isAscending() ^ previous) {
2938 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2939 }
2940 else {
2941 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2942 }
2943 }
2944 else {
2945 if (orderByComparator.isAscending() ^ previous) {
2946 query.append(WHERE_GREATER_THAN);
2947 }
2948 else {
2949 query.append(WHERE_LESSER_THAN);
2950 }
2951 }
2952 }
2953
2954 query.append(ORDER_BY_CLAUSE);
2955
2956 String[] orderByFields = orderByComparator.getOrderByFields();
2957
2958 for (int i = 0; i < orderByFields.length; i++) {
2959 query.append(_ORDER_BY_ENTITY_ALIAS);
2960 query.append(orderByFields[i]);
2961
2962 if ((i + 1) < orderByFields.length) {
2963 if (orderByComparator.isAscending() ^ previous) {
2964 query.append(ORDER_BY_ASC_HAS_NEXT);
2965 }
2966 else {
2967 query.append(ORDER_BY_DESC_HAS_NEXT);
2968 }
2969 }
2970 else {
2971 if (orderByComparator.isAscending() ^ previous) {
2972 query.append(ORDER_BY_ASC);
2973 }
2974 else {
2975 query.append(ORDER_BY_DESC);
2976 }
2977 }
2978 }
2979 }
2980 else {
2981 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2982 }
2983
2984 String sql = query.toString();
2985
2986 Query q = session.createQuery(sql);
2987
2988 q.setFirstResult(0);
2989 q.setMaxResults(2);
2990
2991 QueryPos qPos = QueryPos.getInstance(q);
2992
2993 qPos.add(type);
2994
2995 if (orderByComparator != null) {
2996 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2997
2998 for (Object value : values) {
2999 qPos.add(value);
3000 }
3001 }
3002
3003 List<SocialRelation> list = q.list();
3004
3005 if (list.size() == 2) {
3006 return list.get(1);
3007 }
3008 else {
3009 return null;
3010 }
3011 }
3012
3013
3019 public void removeByType(int type) throws SystemException {
3020 for (SocialRelation socialRelation : findByType(type,
3021 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3022 remove(socialRelation);
3023 }
3024 }
3025
3026
3033 public int countByType(int type) throws SystemException {
3034 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
3035
3036 Object[] finderArgs = new Object[] { type };
3037
3038 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3039 this);
3040
3041 if (count == null) {
3042 StringBundler query = new StringBundler(2);
3043
3044 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3045
3046 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3047
3048 String sql = query.toString();
3049
3050 Session session = null;
3051
3052 try {
3053 session = openSession();
3054
3055 Query q = session.createQuery(sql);
3056
3057 QueryPos qPos = QueryPos.getInstance(q);
3058
3059 qPos.add(type);
3060
3061 count = (Long)q.uniqueResult();
3062
3063 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3064 }
3065 catch (Exception e) {
3066 FinderCacheUtil.removeResult(finderPath, finderArgs);
3067
3068 throw processException(e);
3069 }
3070 finally {
3071 closeSession(session);
3072 }
3073 }
3074
3075 return count.intValue();
3076 }
3077
3078 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
3079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3080 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3081 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3082 "findByC_T",
3083 new String[] {
3084 Long.class.getName(), Integer.class.getName(),
3085
3086 Integer.class.getName(), Integer.class.getName(),
3087 OrderByComparator.class.getName()
3088 });
3089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3090 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3091 SocialRelationImpl.class,
3092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
3093 new String[] { Long.class.getName(), Integer.class.getName() },
3094 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK |
3095 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
3096 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3097 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
3099 new String[] { Long.class.getName(), Integer.class.getName() });
3100
3101
3109 public List<SocialRelation> findByC_T(long companyId, int type)
3110 throws SystemException {
3111 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3112 null);
3113 }
3114
3115
3129 public List<SocialRelation> findByC_T(long companyId, int type, int start,
3130 int end) throws SystemException {
3131 return findByC_T(companyId, type, start, end, null);
3132 }
3133
3134
3149 public List<SocialRelation> findByC_T(long companyId, int type, int start,
3150 int end, OrderByComparator orderByComparator) throws SystemException {
3151 boolean pagination = true;
3152 FinderPath finderPath = null;
3153 Object[] finderArgs = null;
3154
3155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3156 (orderByComparator == null)) {
3157 pagination = false;
3158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
3159 finderArgs = new Object[] { companyId, type };
3160 }
3161 else {
3162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
3163 finderArgs = new Object[] {
3164 companyId, type,
3165
3166 start, end, orderByComparator
3167 };
3168 }
3169
3170 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3171 finderArgs, this);
3172
3173 if ((list != null) && !list.isEmpty()) {
3174 for (SocialRelation socialRelation : list) {
3175 if ((companyId != socialRelation.getCompanyId()) ||
3176 (type != socialRelation.getType())) {
3177 list = null;
3178
3179 break;
3180 }
3181 }
3182 }
3183
3184 if (list == null) {
3185 StringBundler query = null;
3186
3187 if (orderByComparator != null) {
3188 query = new StringBundler(4 +
3189 (orderByComparator.getOrderByFields().length * 3));
3190 }
3191 else {
3192 query = new StringBundler(4);
3193 }
3194
3195 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3196
3197 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3198
3199 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3200
3201 if (orderByComparator != null) {
3202 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3203 orderByComparator);
3204 }
3205 else
3206 if (pagination) {
3207 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3208 }
3209
3210 String sql = query.toString();
3211
3212 Session session = null;
3213
3214 try {
3215 session = openSession();
3216
3217 Query q = session.createQuery(sql);
3218
3219 QueryPos qPos = QueryPos.getInstance(q);
3220
3221 qPos.add(companyId);
3222
3223 qPos.add(type);
3224
3225 if (!pagination) {
3226 list = (List<SocialRelation>)QueryUtil.list(q,
3227 getDialect(), start, end, false);
3228
3229 Collections.sort(list);
3230
3231 list = new UnmodifiableList<SocialRelation>(list);
3232 }
3233 else {
3234 list = (List<SocialRelation>)QueryUtil.list(q,
3235 getDialect(), start, end);
3236 }
3237
3238 cacheResult(list);
3239
3240 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3241 }
3242 catch (Exception e) {
3243 FinderCacheUtil.removeResult(finderPath, finderArgs);
3244
3245 throw processException(e);
3246 }
3247 finally {
3248 closeSession(session);
3249 }
3250 }
3251
3252 return list;
3253 }
3254
3255
3265 public SocialRelation findByC_T_First(long companyId, int type,
3266 OrderByComparator orderByComparator)
3267 throws NoSuchRelationException, SystemException {
3268 SocialRelation socialRelation = fetchByC_T_First(companyId, type,
3269 orderByComparator);
3270
3271 if (socialRelation != null) {
3272 return socialRelation;
3273 }
3274
3275 StringBundler msg = new StringBundler(6);
3276
3277 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3278
3279 msg.append("companyId=");
3280 msg.append(companyId);
3281
3282 msg.append(", type=");
3283 msg.append(type);
3284
3285 msg.append(StringPool.CLOSE_CURLY_BRACE);
3286
3287 throw new NoSuchRelationException(msg.toString());
3288 }
3289
3290
3299 public SocialRelation fetchByC_T_First(long companyId, int type,
3300 OrderByComparator orderByComparator) throws SystemException {
3301 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
3302 orderByComparator);
3303
3304 if (!list.isEmpty()) {
3305 return list.get(0);
3306 }
3307
3308 return null;
3309 }
3310
3311
3321 public SocialRelation findByC_T_Last(long companyId, int type,
3322 OrderByComparator orderByComparator)
3323 throws NoSuchRelationException, SystemException {
3324 SocialRelation socialRelation = fetchByC_T_Last(companyId, type,
3325 orderByComparator);
3326
3327 if (socialRelation != null) {
3328 return socialRelation;
3329 }
3330
3331 StringBundler msg = new StringBundler(6);
3332
3333 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3334
3335 msg.append("companyId=");
3336 msg.append(companyId);
3337
3338 msg.append(", type=");
3339 msg.append(type);
3340
3341 msg.append(StringPool.CLOSE_CURLY_BRACE);
3342
3343 throw new NoSuchRelationException(msg.toString());
3344 }
3345
3346
3355 public SocialRelation fetchByC_T_Last(long companyId, int type,
3356 OrderByComparator orderByComparator) throws SystemException {
3357 int count = countByC_T(companyId, type);
3358
3359 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
3360 count, orderByComparator);
3361
3362 if (!list.isEmpty()) {
3363 return list.get(0);
3364 }
3365
3366 return null;
3367 }
3368
3369
3380 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
3381 long companyId, int type, OrderByComparator orderByComparator)
3382 throws NoSuchRelationException, SystemException {
3383 SocialRelation socialRelation = findByPrimaryKey(relationId);
3384
3385 Session session = null;
3386
3387 try {
3388 session = openSession();
3389
3390 SocialRelation[] array = new SocialRelationImpl[3];
3391
3392 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3393 type, orderByComparator, true);
3394
3395 array[1] = socialRelation;
3396
3397 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3398 type, orderByComparator, false);
3399
3400 return array;
3401 }
3402 catch (Exception e) {
3403 throw processException(e);
3404 }
3405 finally {
3406 closeSession(session);
3407 }
3408 }
3409
3410 protected SocialRelation getByC_T_PrevAndNext(Session session,
3411 SocialRelation socialRelation, long companyId, int type,
3412 OrderByComparator orderByComparator, boolean previous) {
3413 StringBundler query = null;
3414
3415 if (orderByComparator != null) {
3416 query = new StringBundler(6 +
3417 (orderByComparator.getOrderByFields().length * 6));
3418 }
3419 else {
3420 query = new StringBundler(3);
3421 }
3422
3423 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3424
3425 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3426
3427 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3428
3429 if (orderByComparator != null) {
3430 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3431
3432 if (orderByConditionFields.length > 0) {
3433 query.append(WHERE_AND);
3434 }
3435
3436 for (int i = 0; i < orderByConditionFields.length; i++) {
3437 query.append(_ORDER_BY_ENTITY_ALIAS);
3438 query.append(orderByConditionFields[i]);
3439
3440 if ((i + 1) < orderByConditionFields.length) {
3441 if (orderByComparator.isAscending() ^ previous) {
3442 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3443 }
3444 else {
3445 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3446 }
3447 }
3448 else {
3449 if (orderByComparator.isAscending() ^ previous) {
3450 query.append(WHERE_GREATER_THAN);
3451 }
3452 else {
3453 query.append(WHERE_LESSER_THAN);
3454 }
3455 }
3456 }
3457
3458 query.append(ORDER_BY_CLAUSE);
3459
3460 String[] orderByFields = orderByComparator.getOrderByFields();
3461
3462 for (int i = 0; i < orderByFields.length; i++) {
3463 query.append(_ORDER_BY_ENTITY_ALIAS);
3464 query.append(orderByFields[i]);
3465
3466 if ((i + 1) < orderByFields.length) {
3467 if (orderByComparator.isAscending() ^ previous) {
3468 query.append(ORDER_BY_ASC_HAS_NEXT);
3469 }
3470 else {
3471 query.append(ORDER_BY_DESC_HAS_NEXT);
3472 }
3473 }
3474 else {
3475 if (orderByComparator.isAscending() ^ previous) {
3476 query.append(ORDER_BY_ASC);
3477 }
3478 else {
3479 query.append(ORDER_BY_DESC);
3480 }
3481 }
3482 }
3483 }
3484 else {
3485 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3486 }
3487
3488 String sql = query.toString();
3489
3490 Query q = session.createQuery(sql);
3491
3492 q.setFirstResult(0);
3493 q.setMaxResults(2);
3494
3495 QueryPos qPos = QueryPos.getInstance(q);
3496
3497 qPos.add(companyId);
3498
3499 qPos.add(type);
3500
3501 if (orderByComparator != null) {
3502 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3503
3504 for (Object value : values) {
3505 qPos.add(value);
3506 }
3507 }
3508
3509 List<SocialRelation> list = q.list();
3510
3511 if (list.size() == 2) {
3512 return list.get(1);
3513 }
3514 else {
3515 return null;
3516 }
3517 }
3518
3519
3526 public void removeByC_T(long companyId, int type) throws SystemException {
3527 for (SocialRelation socialRelation : findByC_T(companyId, type,
3528 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3529 remove(socialRelation);
3530 }
3531 }
3532
3533
3541 public int countByC_T(long companyId, int type) throws SystemException {
3542 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
3543
3544 Object[] finderArgs = new Object[] { companyId, type };
3545
3546 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3547 this);
3548
3549 if (count == null) {
3550 StringBundler query = new StringBundler(3);
3551
3552 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3553
3554 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3555
3556 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3557
3558 String sql = query.toString();
3559
3560 Session session = null;
3561
3562 try {
3563 session = openSession();
3564
3565 Query q = session.createQuery(sql);
3566
3567 QueryPos qPos = QueryPos.getInstance(q);
3568
3569 qPos.add(companyId);
3570
3571 qPos.add(type);
3572
3573 count = (Long)q.uniqueResult();
3574
3575 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3576 }
3577 catch (Exception e) {
3578 FinderCacheUtil.removeResult(finderPath, finderArgs);
3579
3580 throw processException(e);
3581 }
3582 finally {
3583 closeSession(session);
3584 }
3585 }
3586
3587 return count.intValue();
3588 }
3589
3590 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
3591 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
3592 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3593 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3594 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3595 "findByU1_U2",
3596 new String[] {
3597 Long.class.getName(), Long.class.getName(),
3598
3599 Integer.class.getName(), Integer.class.getName(),
3600 OrderByComparator.class.getName()
3601 });
3602 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3603 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3604 SocialRelationImpl.class,
3605 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_U2",
3606 new String[] { Long.class.getName(), Long.class.getName() },
3607 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
3608 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
3609 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3610 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3611 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2",
3612 new String[] { Long.class.getName(), Long.class.getName() });
3613
3614
3622 public List<SocialRelation> findByU1_U2(long userId1, long userId2)
3623 throws SystemException {
3624 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
3625 QueryUtil.ALL_POS, null);
3626 }
3627
3628
3642 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3643 int start, int end) throws SystemException {
3644 return findByU1_U2(userId1, userId2, start, end, null);
3645 }
3646
3647
3662 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3663 int start, int end, OrderByComparator orderByComparator)
3664 throws SystemException {
3665 boolean pagination = true;
3666 FinderPath finderPath = null;
3667 Object[] finderArgs = null;
3668
3669 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3670 (orderByComparator == null)) {
3671 pagination = false;
3672 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3673 finderArgs = new Object[] { userId1, userId2 };
3674 }
3675 else {
3676 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3677 finderArgs = new Object[] {
3678 userId1, userId2,
3679
3680 start, end, orderByComparator
3681 };
3682 }
3683
3684 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3685 finderArgs, this);
3686
3687 if ((list != null) && !list.isEmpty()) {
3688 for (SocialRelation socialRelation : list) {
3689 if ((userId1 != socialRelation.getUserId1()) ||
3690 (userId2 != socialRelation.getUserId2())) {
3691 list = null;
3692
3693 break;
3694 }
3695 }
3696 }
3697
3698 if (list == null) {
3699 StringBundler query = null;
3700
3701 if (orderByComparator != null) {
3702 query = new StringBundler(4 +
3703 (orderByComparator.getOrderByFields().length * 3));
3704 }
3705 else {
3706 query = new StringBundler(4);
3707 }
3708
3709 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3710
3711 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3712
3713 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3714
3715 if (orderByComparator != null) {
3716 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3717 orderByComparator);
3718 }
3719 else
3720 if (pagination) {
3721 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3722 }
3723
3724 String sql = query.toString();
3725
3726 Session session = null;
3727
3728 try {
3729 session = openSession();
3730
3731 Query q = session.createQuery(sql);
3732
3733 QueryPos qPos = QueryPos.getInstance(q);
3734
3735 qPos.add(userId1);
3736
3737 qPos.add(userId2);
3738
3739 if (!pagination) {
3740 list = (List<SocialRelation>)QueryUtil.list(q,
3741 getDialect(), start, end, false);
3742
3743 Collections.sort(list);
3744
3745 list = new UnmodifiableList<SocialRelation>(list);
3746 }
3747 else {
3748 list = (List<SocialRelation>)QueryUtil.list(q,
3749 getDialect(), start, end);
3750 }
3751
3752 cacheResult(list);
3753
3754 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3755 }
3756 catch (Exception e) {
3757 FinderCacheUtil.removeResult(finderPath, finderArgs);
3758
3759 throw processException(e);
3760 }
3761 finally {
3762 closeSession(session);
3763 }
3764 }
3765
3766 return list;
3767 }
3768
3769
3779 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3780 OrderByComparator orderByComparator)
3781 throws NoSuchRelationException, SystemException {
3782 SocialRelation socialRelation = fetchByU1_U2_First(userId1, userId2,
3783 orderByComparator);
3784
3785 if (socialRelation != null) {
3786 return socialRelation;
3787 }
3788
3789 StringBundler msg = new StringBundler(6);
3790
3791 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3792
3793 msg.append("userId1=");
3794 msg.append(userId1);
3795
3796 msg.append(", userId2=");
3797 msg.append(userId2);
3798
3799 msg.append(StringPool.CLOSE_CURLY_BRACE);
3800
3801 throw new NoSuchRelationException(msg.toString());
3802 }
3803
3804
3813 public SocialRelation fetchByU1_U2_First(long userId1, long userId2,
3814 OrderByComparator orderByComparator) throws SystemException {
3815 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3816 orderByComparator);
3817
3818 if (!list.isEmpty()) {
3819 return list.get(0);
3820 }
3821
3822 return null;
3823 }
3824
3825
3835 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3836 OrderByComparator orderByComparator)
3837 throws NoSuchRelationException, SystemException {
3838 SocialRelation socialRelation = fetchByU1_U2_Last(userId1, userId2,
3839 orderByComparator);
3840
3841 if (socialRelation != null) {
3842 return socialRelation;
3843 }
3844
3845 StringBundler msg = new StringBundler(6);
3846
3847 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3848
3849 msg.append("userId1=");
3850 msg.append(userId1);
3851
3852 msg.append(", userId2=");
3853 msg.append(userId2);
3854
3855 msg.append(StringPool.CLOSE_CURLY_BRACE);
3856
3857 throw new NoSuchRelationException(msg.toString());
3858 }
3859
3860
3869 public SocialRelation fetchByU1_U2_Last(long userId1, long userId2,
3870 OrderByComparator orderByComparator) throws SystemException {
3871 int count = countByU1_U2(userId1, userId2);
3872
3873 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3874 count, orderByComparator);
3875
3876 if (!list.isEmpty()) {
3877 return list.get(0);
3878 }
3879
3880 return null;
3881 }
3882
3883
3894 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3895 long userId1, long userId2, OrderByComparator orderByComparator)
3896 throws NoSuchRelationException, SystemException {
3897 SocialRelation socialRelation = findByPrimaryKey(relationId);
3898
3899 Session session = null;
3900
3901 try {
3902 session = openSession();
3903
3904 SocialRelation[] array = new SocialRelationImpl[3];
3905
3906 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3907 userId2, orderByComparator, true);
3908
3909 array[1] = socialRelation;
3910
3911 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3912 userId2, orderByComparator, false);
3913
3914 return array;
3915 }
3916 catch (Exception e) {
3917 throw processException(e);
3918 }
3919 finally {
3920 closeSession(session);
3921 }
3922 }
3923
3924 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3925 SocialRelation socialRelation, long userId1, long userId2,
3926 OrderByComparator orderByComparator, boolean previous) {
3927 StringBundler query = null;
3928
3929 if (orderByComparator != null) {
3930 query = new StringBundler(6 +
3931 (orderByComparator.getOrderByFields().length * 6));
3932 }
3933 else {
3934 query = new StringBundler(3);
3935 }
3936
3937 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3938
3939 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3940
3941 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3942
3943 if (orderByComparator != null) {
3944 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3945
3946 if (orderByConditionFields.length > 0) {
3947 query.append(WHERE_AND);
3948 }
3949
3950 for (int i = 0; i < orderByConditionFields.length; i++) {
3951 query.append(_ORDER_BY_ENTITY_ALIAS);
3952 query.append(orderByConditionFields[i]);
3953
3954 if ((i + 1) < orderByConditionFields.length) {
3955 if (orderByComparator.isAscending() ^ previous) {
3956 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3957 }
3958 else {
3959 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3960 }
3961 }
3962 else {
3963 if (orderByComparator.isAscending() ^ previous) {
3964 query.append(WHERE_GREATER_THAN);
3965 }
3966 else {
3967 query.append(WHERE_LESSER_THAN);
3968 }
3969 }
3970 }
3971
3972 query.append(ORDER_BY_CLAUSE);
3973
3974 String[] orderByFields = orderByComparator.getOrderByFields();
3975
3976 for (int i = 0; i < orderByFields.length; i++) {
3977 query.append(_ORDER_BY_ENTITY_ALIAS);
3978 query.append(orderByFields[i]);
3979
3980 if ((i + 1) < orderByFields.length) {
3981 if (orderByComparator.isAscending() ^ previous) {
3982 query.append(ORDER_BY_ASC_HAS_NEXT);
3983 }
3984 else {
3985 query.append(ORDER_BY_DESC_HAS_NEXT);
3986 }
3987 }
3988 else {
3989 if (orderByComparator.isAscending() ^ previous) {
3990 query.append(ORDER_BY_ASC);
3991 }
3992 else {
3993 query.append(ORDER_BY_DESC);
3994 }
3995 }
3996 }
3997 }
3998 else {
3999 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4000 }
4001
4002 String sql = query.toString();
4003
4004 Query q = session.createQuery(sql);
4005
4006 q.setFirstResult(0);
4007 q.setMaxResults(2);
4008
4009 QueryPos qPos = QueryPos.getInstance(q);
4010
4011 qPos.add(userId1);
4012
4013 qPos.add(userId2);
4014
4015 if (orderByComparator != null) {
4016 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4017
4018 for (Object value : values) {
4019 qPos.add(value);
4020 }
4021 }
4022
4023 List<SocialRelation> list = q.list();
4024
4025 if (list.size() == 2) {
4026 return list.get(1);
4027 }
4028 else {
4029 return null;
4030 }
4031 }
4032
4033
4040 public void removeByU1_U2(long userId1, long userId2)
4041 throws SystemException {
4042 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2,
4043 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4044 remove(socialRelation);
4045 }
4046 }
4047
4048
4056 public int countByU1_U2(long userId1, long userId2)
4057 throws SystemException {
4058 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_U2;
4059
4060 Object[] finderArgs = new Object[] { userId1, userId2 };
4061
4062 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4063 this);
4064
4065 if (count == null) {
4066 StringBundler query = new StringBundler(3);
4067
4068 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4069
4070 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
4071
4072 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
4073
4074 String sql = query.toString();
4075
4076 Session session = null;
4077
4078 try {
4079 session = openSession();
4080
4081 Query q = session.createQuery(sql);
4082
4083 QueryPos qPos = QueryPos.getInstance(q);
4084
4085 qPos.add(userId1);
4086
4087 qPos.add(userId2);
4088
4089 count = (Long)q.uniqueResult();
4090
4091 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4092 }
4093 catch (Exception e) {
4094 FinderCacheUtil.removeResult(finderPath, finderArgs);
4095
4096 throw processException(e);
4097 }
4098 finally {
4099 closeSession(session);
4100 }
4101 }
4102
4103 return count.intValue();
4104 }
4105
4106 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
4107 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
4108 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4109 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4110 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4111 "findByU1_T",
4112 new String[] {
4113 Long.class.getName(), Integer.class.getName(),
4114
4115 Integer.class.getName(), Integer.class.getName(),
4116 OrderByComparator.class.getName()
4117 });
4118 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4119 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4120 SocialRelationImpl.class,
4121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_T",
4122 new String[] { Long.class.getName(), Integer.class.getName() },
4123 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
4124 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
4125 public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4126 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4127 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_T",
4128 new String[] { Long.class.getName(), Integer.class.getName() });
4129
4130
4138 public List<SocialRelation> findByU1_T(long userId1, int type)
4139 throws SystemException {
4140 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4141 null);
4142 }
4143
4144
4158 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
4159 int end) throws SystemException {
4160 return findByU1_T(userId1, type, start, end, null);
4161 }
4162
4163
4178 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
4179 int end, OrderByComparator orderByComparator) throws SystemException {
4180 boolean pagination = true;
4181 FinderPath finderPath = null;
4182 Object[] finderArgs = null;
4183
4184 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4185 (orderByComparator == null)) {
4186 pagination = false;
4187 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
4188 finderArgs = new Object[] { userId1, type };
4189 }
4190 else {
4191 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
4192 finderArgs = new Object[] {
4193 userId1, type,
4194
4195 start, end, orderByComparator
4196 };
4197 }
4198
4199 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4200 finderArgs, this);
4201
4202 if ((list != null) && !list.isEmpty()) {
4203 for (SocialRelation socialRelation : list) {
4204 if ((userId1 != socialRelation.getUserId1()) ||
4205 (type != socialRelation.getType())) {
4206 list = null;
4207
4208 break;
4209 }
4210 }
4211 }
4212
4213 if (list == null) {
4214 StringBundler query = null;
4215
4216 if (orderByComparator != null) {
4217 query = new StringBundler(4 +
4218 (orderByComparator.getOrderByFields().length * 3));
4219 }
4220 else {
4221 query = new StringBundler(4);
4222 }
4223
4224 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4225
4226 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4227
4228 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4229
4230 if (orderByComparator != null) {
4231 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4232 orderByComparator);
4233 }
4234 else
4235 if (pagination) {
4236 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4237 }
4238
4239 String sql = query.toString();
4240
4241 Session session = null;
4242
4243 try {
4244 session = openSession();
4245
4246 Query q = session.createQuery(sql);
4247
4248 QueryPos qPos = QueryPos.getInstance(q);
4249
4250 qPos.add(userId1);
4251
4252 qPos.add(type);
4253
4254 if (!pagination) {
4255 list = (List<SocialRelation>)QueryUtil.list(q,
4256 getDialect(), start, end, false);
4257
4258 Collections.sort(list);
4259
4260 list = new UnmodifiableList<SocialRelation>(list);
4261 }
4262 else {
4263 list = (List<SocialRelation>)QueryUtil.list(q,
4264 getDialect(), start, end);
4265 }
4266
4267 cacheResult(list);
4268
4269 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4270 }
4271 catch (Exception e) {
4272 FinderCacheUtil.removeResult(finderPath, finderArgs);
4273
4274 throw processException(e);
4275 }
4276 finally {
4277 closeSession(session);
4278 }
4279 }
4280
4281 return list;
4282 }
4283
4284
4294 public SocialRelation findByU1_T_First(long userId1, int type,
4295 OrderByComparator orderByComparator)
4296 throws NoSuchRelationException, SystemException {
4297 SocialRelation socialRelation = fetchByU1_T_First(userId1, type,
4298 orderByComparator);
4299
4300 if (socialRelation != null) {
4301 return socialRelation;
4302 }
4303
4304 StringBundler msg = new StringBundler(6);
4305
4306 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4307
4308 msg.append("userId1=");
4309 msg.append(userId1);
4310
4311 msg.append(", type=");
4312 msg.append(type);
4313
4314 msg.append(StringPool.CLOSE_CURLY_BRACE);
4315
4316 throw new NoSuchRelationException(msg.toString());
4317 }
4318
4319
4328 public SocialRelation fetchByU1_T_First(long userId1, int type,
4329 OrderByComparator orderByComparator) throws SystemException {
4330 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
4331 orderByComparator);
4332
4333 if (!list.isEmpty()) {
4334 return list.get(0);
4335 }
4336
4337 return null;
4338 }
4339
4340
4350 public SocialRelation findByU1_T_Last(long userId1, int type,
4351 OrderByComparator orderByComparator)
4352 throws NoSuchRelationException, SystemException {
4353 SocialRelation socialRelation = fetchByU1_T_Last(userId1, type,
4354 orderByComparator);
4355
4356 if (socialRelation != null) {
4357 return socialRelation;
4358 }
4359
4360 StringBundler msg = new StringBundler(6);
4361
4362 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4363
4364 msg.append("userId1=");
4365 msg.append(userId1);
4366
4367 msg.append(", type=");
4368 msg.append(type);
4369
4370 msg.append(StringPool.CLOSE_CURLY_BRACE);
4371
4372 throw new NoSuchRelationException(msg.toString());
4373 }
4374
4375
4384 public SocialRelation fetchByU1_T_Last(long userId1, int type,
4385 OrderByComparator orderByComparator) throws SystemException {
4386 int count = countByU1_T(userId1, type);
4387
4388 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
4389 orderByComparator);
4390
4391 if (!list.isEmpty()) {
4392 return list.get(0);
4393 }
4394
4395 return null;
4396 }
4397
4398
4409 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
4410 long userId1, int type, OrderByComparator orderByComparator)
4411 throws NoSuchRelationException, SystemException {
4412 SocialRelation socialRelation = findByPrimaryKey(relationId);
4413
4414 Session session = null;
4415
4416 try {
4417 session = openSession();
4418
4419 SocialRelation[] array = new SocialRelationImpl[3];
4420
4421 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
4422 type, orderByComparator, true);
4423
4424 array[1] = socialRelation;
4425
4426 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
4427 type, orderByComparator, false);
4428
4429 return array;
4430 }
4431 catch (Exception e) {
4432 throw processException(e);
4433 }
4434 finally {
4435 closeSession(session);
4436 }
4437 }
4438
4439 protected SocialRelation getByU1_T_PrevAndNext(Session session,
4440 SocialRelation socialRelation, long userId1, int type,
4441 OrderByComparator orderByComparator, boolean previous) {
4442 StringBundler query = null;
4443
4444 if (orderByComparator != null) {
4445 query = new StringBundler(6 +
4446 (orderByComparator.getOrderByFields().length * 6));
4447 }
4448 else {
4449 query = new StringBundler(3);
4450 }
4451
4452 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4453
4454 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4455
4456 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4457
4458 if (orderByComparator != null) {
4459 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4460
4461 if (orderByConditionFields.length > 0) {
4462 query.append(WHERE_AND);
4463 }
4464
4465 for (int i = 0; i < orderByConditionFields.length; i++) {
4466 query.append(_ORDER_BY_ENTITY_ALIAS);
4467 query.append(orderByConditionFields[i]);
4468
4469 if ((i + 1) < orderByConditionFields.length) {
4470 if (orderByComparator.isAscending() ^ previous) {
4471 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4472 }
4473 else {
4474 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4475 }
4476 }
4477 else {
4478 if (orderByComparator.isAscending() ^ previous) {
4479 query.append(WHERE_GREATER_THAN);
4480 }
4481 else {
4482 query.append(WHERE_LESSER_THAN);
4483 }
4484 }
4485 }
4486
4487 query.append(ORDER_BY_CLAUSE);
4488
4489 String[] orderByFields = orderByComparator.getOrderByFields();
4490
4491 for (int i = 0; i < orderByFields.length; i++) {
4492 query.append(_ORDER_BY_ENTITY_ALIAS);
4493 query.append(orderByFields[i]);
4494
4495 if ((i + 1) < orderByFields.length) {
4496 if (orderByComparator.isAscending() ^ previous) {
4497 query.append(ORDER_BY_ASC_HAS_NEXT);
4498 }
4499 else {
4500 query.append(ORDER_BY_DESC_HAS_NEXT);
4501 }
4502 }
4503 else {
4504 if (orderByComparator.isAscending() ^ previous) {
4505 query.append(ORDER_BY_ASC);
4506 }
4507 else {
4508 query.append(ORDER_BY_DESC);
4509 }
4510 }
4511 }
4512 }
4513 else {
4514 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4515 }
4516
4517 String sql = query.toString();
4518
4519 Query q = session.createQuery(sql);
4520
4521 q.setFirstResult(0);
4522 q.setMaxResults(2);
4523
4524 QueryPos qPos = QueryPos.getInstance(q);
4525
4526 qPos.add(userId1);
4527
4528 qPos.add(type);
4529
4530 if (orderByComparator != null) {
4531 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4532
4533 for (Object value : values) {
4534 qPos.add(value);
4535 }
4536 }
4537
4538 List<SocialRelation> list = q.list();
4539
4540 if (list.size() == 2) {
4541 return list.get(1);
4542 }
4543 else {
4544 return null;
4545 }
4546 }
4547
4548
4555 public void removeByU1_T(long userId1, int type) throws SystemException {
4556 for (SocialRelation socialRelation : findByU1_T(userId1, type,
4557 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4558 remove(socialRelation);
4559 }
4560 }
4561
4562
4570 public int countByU1_T(long userId1, int type) throws SystemException {
4571 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_T;
4572
4573 Object[] finderArgs = new Object[] { userId1, type };
4574
4575 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4576 this);
4577
4578 if (count == null) {
4579 StringBundler query = new StringBundler(3);
4580
4581 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4582
4583 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4584
4585 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4586
4587 String sql = query.toString();
4588
4589 Session session = null;
4590
4591 try {
4592 session = openSession();
4593
4594 Query q = session.createQuery(sql);
4595
4596 QueryPos qPos = QueryPos.getInstance(q);
4597
4598 qPos.add(userId1);
4599
4600 qPos.add(type);
4601
4602 count = (Long)q.uniqueResult();
4603
4604 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4605 }
4606 catch (Exception e) {
4607 FinderCacheUtil.removeResult(finderPath, finderArgs);
4608
4609 throw processException(e);
4610 }
4611 finally {
4612 closeSession(session);
4613 }
4614 }
4615
4616 return count.intValue();
4617 }
4618
4619 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4620 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
4621 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4622 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4623 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4624 "findByU2_T",
4625 new String[] {
4626 Long.class.getName(), Integer.class.getName(),
4627
4628 Integer.class.getName(), Integer.class.getName(),
4629 OrderByComparator.class.getName()
4630 });
4631 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4632 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4633 SocialRelationImpl.class,
4634 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU2_T",
4635 new String[] { Long.class.getName(), Integer.class.getName() },
4636 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
4637 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
4638 public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4639 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4640 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU2_T",
4641 new String[] { Long.class.getName(), Integer.class.getName() });
4642
4643
4651 public List<SocialRelation> findByU2_T(long userId2, int type)
4652 throws SystemException {
4653 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4654 null);
4655 }
4656
4657
4671 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4672 int end) throws SystemException {
4673 return findByU2_T(userId2, type, start, end, null);
4674 }
4675
4676
4691 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4692 int end, OrderByComparator orderByComparator) throws SystemException {
4693 boolean pagination = true;
4694 FinderPath finderPath = null;
4695 Object[] finderArgs = null;
4696
4697 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4698 (orderByComparator == null)) {
4699 pagination = false;
4700 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
4701 finderArgs = new Object[] { userId2, type };
4702 }
4703 else {
4704 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
4705 finderArgs = new Object[] {
4706 userId2, type,
4707
4708 start, end, orderByComparator
4709 };
4710 }
4711
4712 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4713 finderArgs, this);
4714
4715 if ((list != null) && !list.isEmpty()) {
4716 for (SocialRelation socialRelation : list) {
4717 if ((userId2 != socialRelation.getUserId2()) ||
4718 (type != socialRelation.getType())) {
4719 list = null;
4720
4721 break;
4722 }
4723 }
4724 }
4725
4726 if (list == null) {
4727 StringBundler query = null;
4728
4729 if (orderByComparator != null) {
4730 query = new StringBundler(4 +
4731 (orderByComparator.getOrderByFields().length * 3));
4732 }
4733 else {
4734 query = new StringBundler(4);
4735 }
4736
4737 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4738
4739 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4740
4741 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4742
4743 if (orderByComparator != null) {
4744 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4745 orderByComparator);
4746 }
4747 else
4748 if (pagination) {
4749 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4750 }
4751
4752 String sql = query.toString();
4753
4754 Session session = null;
4755
4756 try {
4757 session = openSession();
4758
4759 Query q = session.createQuery(sql);
4760
4761 QueryPos qPos = QueryPos.getInstance(q);
4762
4763 qPos.add(userId2);
4764
4765 qPos.add(type);
4766
4767 if (!pagination) {
4768 list = (List<SocialRelation>)QueryUtil.list(q,
4769 getDialect(), start, end, false);
4770
4771 Collections.sort(list);
4772
4773 list = new UnmodifiableList<SocialRelation>(list);
4774 }
4775 else {
4776 list = (List<SocialRelation>)QueryUtil.list(q,
4777 getDialect(), start, end);
4778 }
4779
4780 cacheResult(list);
4781
4782 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4783 }
4784 catch (Exception e) {
4785 FinderCacheUtil.removeResult(finderPath, finderArgs);
4786
4787 throw processException(e);
4788 }
4789 finally {
4790 closeSession(session);
4791 }
4792 }
4793
4794 return list;
4795 }
4796
4797
4807 public SocialRelation findByU2_T_First(long userId2, int type,
4808 OrderByComparator orderByComparator)
4809 throws NoSuchRelationException, SystemException {
4810 SocialRelation socialRelation = fetchByU2_T_First(userId2, type,
4811 orderByComparator);
4812
4813 if (socialRelation != null) {
4814 return socialRelation;
4815 }
4816
4817 StringBundler msg = new StringBundler(6);
4818
4819 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4820
4821 msg.append("userId2=");
4822 msg.append(userId2);
4823
4824 msg.append(", type=");
4825 msg.append(type);
4826
4827 msg.append(StringPool.CLOSE_CURLY_BRACE);
4828
4829 throw new NoSuchRelationException(msg.toString());
4830 }
4831
4832
4841 public SocialRelation fetchByU2_T_First(long userId2, int type,
4842 OrderByComparator orderByComparator) throws SystemException {
4843 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
4844 orderByComparator);
4845
4846 if (!list.isEmpty()) {
4847 return list.get(0);
4848 }
4849
4850 return null;
4851 }
4852
4853
4863 public SocialRelation findByU2_T_Last(long userId2, int type,
4864 OrderByComparator orderByComparator)
4865 throws NoSuchRelationException, SystemException {
4866 SocialRelation socialRelation = fetchByU2_T_Last(userId2, type,
4867 orderByComparator);
4868
4869 if (socialRelation != null) {
4870 return socialRelation;
4871 }
4872
4873 StringBundler msg = new StringBundler(6);
4874
4875 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4876
4877 msg.append("userId2=");
4878 msg.append(userId2);
4879
4880 msg.append(", type=");
4881 msg.append(type);
4882
4883 msg.append(StringPool.CLOSE_CURLY_BRACE);
4884
4885 throw new NoSuchRelationException(msg.toString());
4886 }
4887
4888
4897 public SocialRelation fetchByU2_T_Last(long userId2, int type,
4898 OrderByComparator orderByComparator) throws SystemException {
4899 int count = countByU2_T(userId2, type);
4900
4901 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
4902 orderByComparator);
4903
4904 if (!list.isEmpty()) {
4905 return list.get(0);
4906 }
4907
4908 return null;
4909 }
4910
4911
4922 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
4923 long userId2, int type, OrderByComparator orderByComparator)
4924 throws NoSuchRelationException, SystemException {
4925 SocialRelation socialRelation = findByPrimaryKey(relationId);
4926
4927 Session session = null;
4928
4929 try {
4930 session = openSession();
4931
4932 SocialRelation[] array = new SocialRelationImpl[3];
4933
4934 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4935 type, orderByComparator, true);
4936
4937 array[1] = socialRelation;
4938
4939 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4940 type, orderByComparator, false);
4941
4942 return array;
4943 }
4944 catch (Exception e) {
4945 throw processException(e);
4946 }
4947 finally {
4948 closeSession(session);
4949 }
4950 }
4951
4952 protected SocialRelation getByU2_T_PrevAndNext(Session session,
4953 SocialRelation socialRelation, long userId2, int type,
4954 OrderByComparator orderByComparator, boolean previous) {
4955 StringBundler query = null;
4956
4957 if (orderByComparator != null) {
4958 query = new StringBundler(6 +
4959 (orderByComparator.getOrderByFields().length * 6));
4960 }
4961 else {
4962 query = new StringBundler(3);
4963 }
4964
4965 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4966
4967 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4968
4969 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4970
4971 if (orderByComparator != null) {
4972 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4973
4974 if (orderByConditionFields.length > 0) {
4975 query.append(WHERE_AND);
4976 }
4977
4978 for (int i = 0; i < orderByConditionFields.length; i++) {
4979 query.append(_ORDER_BY_ENTITY_ALIAS);
4980 query.append(orderByConditionFields[i]);
4981
4982 if ((i + 1) < orderByConditionFields.length) {
4983 if (orderByComparator.isAscending() ^ previous) {
4984 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4985 }
4986 else {
4987 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4988 }
4989 }
4990 else {
4991 if (orderByComparator.isAscending() ^ previous) {
4992 query.append(WHERE_GREATER_THAN);
4993 }
4994 else {
4995 query.append(WHERE_LESSER_THAN);
4996 }
4997 }
4998 }
4999
5000 query.append(ORDER_BY_CLAUSE);
5001
5002 String[] orderByFields = orderByComparator.getOrderByFields();
5003
5004 for (int i = 0; i < orderByFields.length; i++) {
5005 query.append(_ORDER_BY_ENTITY_ALIAS);
5006 query.append(orderByFields[i]);
5007
5008 if ((i + 1) < orderByFields.length) {
5009 if (orderByComparator.isAscending() ^ previous) {
5010 query.append(ORDER_BY_ASC_HAS_NEXT);
5011 }
5012 else {
5013 query.append(ORDER_BY_DESC_HAS_NEXT);
5014 }
5015 }
5016 else {
5017 if (orderByComparator.isAscending() ^ previous) {
5018 query.append(ORDER_BY_ASC);
5019 }
5020 else {
5021 query.append(ORDER_BY_DESC);
5022 }
5023 }
5024 }
5025 }
5026 else {
5027 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
5028 }
5029
5030 String sql = query.toString();
5031
5032 Query q = session.createQuery(sql);
5033
5034 q.setFirstResult(0);
5035 q.setMaxResults(2);
5036
5037 QueryPos qPos = QueryPos.getInstance(q);
5038
5039 qPos.add(userId2);
5040
5041 qPos.add(type);
5042
5043 if (orderByComparator != null) {
5044 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
5045
5046 for (Object value : values) {
5047 qPos.add(value);
5048 }
5049 }
5050
5051 List<SocialRelation> list = q.list();
5052
5053 if (list.size() == 2) {
5054 return list.get(1);
5055 }
5056 else {
5057 return null;
5058 }
5059 }
5060
5061
5068 public void removeByU2_T(long userId2, int type) throws SystemException {
5069 for (SocialRelation socialRelation : findByU2_T(userId2, type,
5070 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5071 remove(socialRelation);
5072 }
5073 }
5074
5075
5083 public int countByU2_T(long userId2, int type) throws SystemException {
5084 FinderPath finderPath = FINDER_PATH_COUNT_BY_U2_T;
5085
5086 Object[] finderArgs = new Object[] { userId2, type };
5087
5088 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5089 this);
5090
5091 if (count == null) {
5092 StringBundler query = new StringBundler(3);
5093
5094 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5095
5096 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
5097
5098 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
5099
5100 String sql = query.toString();
5101
5102 Session session = null;
5103
5104 try {
5105 session = openSession();
5106
5107 Query q = session.createQuery(sql);
5108
5109 QueryPos qPos = QueryPos.getInstance(q);
5110
5111 qPos.add(userId2);
5112
5113 qPos.add(type);
5114
5115 count = (Long)q.uniqueResult();
5116
5117 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5118 }
5119 catch (Exception e) {
5120 FinderCacheUtil.removeResult(finderPath, finderArgs);
5121
5122 throw processException(e);
5123 }
5124 finally {
5125 closeSession(session);
5126 }
5127 }
5128
5129 return count.intValue();
5130 }
5131
5132 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5133 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5134 public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5135 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
5136 SocialRelationImpl.class, FINDER_CLASS_NAME_ENTITY,
5137 "fetchByU1_U2_T",
5138 new String[] {
5139 Long.class.getName(), Long.class.getName(),
5140 Integer.class.getName()
5141 },
5142 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
5143 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
5144 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
5145 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5146 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5147 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2_T",
5148 new String[] {
5149 Long.class.getName(), Long.class.getName(),
5150 Integer.class.getName()
5151 });
5152
5153
5163 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
5164 throws NoSuchRelationException, SystemException {
5165 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
5166
5167 if (socialRelation == null) {
5168 StringBundler msg = new StringBundler(8);
5169
5170 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5171
5172 msg.append("userId1=");
5173 msg.append(userId1);
5174
5175 msg.append(", userId2=");
5176 msg.append(userId2);
5177
5178 msg.append(", type=");
5179 msg.append(type);
5180
5181 msg.append(StringPool.CLOSE_CURLY_BRACE);
5182
5183 if (_log.isWarnEnabled()) {
5184 _log.warn(msg.toString());
5185 }
5186
5187 throw new NoSuchRelationException(msg.toString());
5188 }
5189
5190 return socialRelation;
5191 }
5192
5193
5202 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
5203 throws SystemException {
5204 return fetchByU1_U2_T(userId1, userId2, type, true);
5205 }
5206
5207
5217 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
5218 boolean retrieveFromCache) throws SystemException {
5219 Object[] finderArgs = new Object[] { userId1, userId2, type };
5220
5221 Object result = null;
5222
5223 if (retrieveFromCache) {
5224 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5225 finderArgs, this);
5226 }
5227
5228 if (result instanceof SocialRelation) {
5229 SocialRelation socialRelation = (SocialRelation)result;
5230
5231 if ((userId1 != socialRelation.getUserId1()) ||
5232 (userId2 != socialRelation.getUserId2()) ||
5233 (type != socialRelation.getType())) {
5234 result = null;
5235 }
5236 }
5237
5238 if (result == null) {
5239 StringBundler query = new StringBundler(5);
5240
5241 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
5242
5243 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5244
5245 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5246
5247 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5248
5249 String sql = query.toString();
5250
5251 Session session = null;
5252
5253 try {
5254 session = openSession();
5255
5256 Query q = session.createQuery(sql);
5257
5258 QueryPos qPos = QueryPos.getInstance(q);
5259
5260 qPos.add(userId1);
5261
5262 qPos.add(userId2);
5263
5264 qPos.add(type);
5265
5266 List<SocialRelation> list = q.list();
5267
5268 if (list.isEmpty()) {
5269 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5270 finderArgs, list);
5271 }
5272 else {
5273 SocialRelation socialRelation = list.get(0);
5274
5275 result = socialRelation;
5276
5277 cacheResult(socialRelation);
5278
5279 if ((socialRelation.getUserId1() != userId1) ||
5280 (socialRelation.getUserId2() != userId2) ||
5281 (socialRelation.getType() != type)) {
5282 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5283 finderArgs, socialRelation);
5284 }
5285 }
5286 }
5287 catch (Exception e) {
5288 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5289 finderArgs);
5290
5291 throw processException(e);
5292 }
5293 finally {
5294 closeSession(session);
5295 }
5296 }
5297
5298 if (result instanceof List<?>) {
5299 return null;
5300 }
5301 else {
5302 return (SocialRelation)result;
5303 }
5304 }
5305
5306
5315 public SocialRelation removeByU1_U2_T(long userId1, long userId2, int type)
5316 throws NoSuchRelationException, SystemException {
5317 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
5318
5319 return remove(socialRelation);
5320 }
5321
5322
5331 public int countByU1_U2_T(long userId1, long userId2, int type)
5332 throws SystemException {
5333 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_U2_T;
5334
5335 Object[] finderArgs = new Object[] { userId1, userId2, type };
5336
5337 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5338 this);
5339
5340 if (count == null) {
5341 StringBundler query = new StringBundler(4);
5342
5343 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5344
5345 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5346
5347 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5348
5349 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5350
5351 String sql = query.toString();
5352
5353 Session session = null;
5354
5355 try {
5356 session = openSession();
5357
5358 Query q = session.createQuery(sql);
5359
5360 QueryPos qPos = QueryPos.getInstance(q);
5361
5362 qPos.add(userId1);
5363
5364 qPos.add(userId2);
5365
5366 qPos.add(type);
5367
5368 count = (Long)q.uniqueResult();
5369
5370 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5371 }
5372 catch (Exception e) {
5373 FinderCacheUtil.removeResult(finderPath, finderArgs);
5374
5375 throw processException(e);
5376 }
5377 finally {
5378 closeSession(session);
5379 }
5380 }
5381
5382 return count.intValue();
5383 }
5384
5385 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5386 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5387 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5388
5389
5394 public void cacheResult(SocialRelation socialRelation) {
5395 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5396 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
5397 socialRelation);
5398
5399 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5400 new Object[] {
5401 socialRelation.getUserId1(), socialRelation.getUserId2(),
5402 socialRelation.getType()
5403 }, socialRelation);
5404
5405 socialRelation.resetOriginalValues();
5406 }
5407
5408
5413 public void cacheResult(List<SocialRelation> socialRelations) {
5414 for (SocialRelation socialRelation : socialRelations) {
5415 if (EntityCacheUtil.getResult(
5416 SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5417 SocialRelationImpl.class, socialRelation.getPrimaryKey()) == null) {
5418 cacheResult(socialRelation);
5419 }
5420 else {
5421 socialRelation.resetOriginalValues();
5422 }
5423 }
5424 }
5425
5426
5433 @Override
5434 public void clearCache() {
5435 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
5436 CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
5437 }
5438
5439 EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
5440
5441 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5442 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5443 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5444 }
5445
5446
5453 @Override
5454 public void clearCache(SocialRelation socialRelation) {
5455 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5456 SocialRelationImpl.class, socialRelation.getPrimaryKey());
5457
5458 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5459 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5460
5461 clearUniqueFindersCache(socialRelation);
5462 }
5463
5464 @Override
5465 public void clearCache(List<SocialRelation> socialRelations) {
5466 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5467 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5468
5469 for (SocialRelation socialRelation : socialRelations) {
5470 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5471 SocialRelationImpl.class, socialRelation.getPrimaryKey());
5472
5473 clearUniqueFindersCache(socialRelation);
5474 }
5475 }
5476
5477 protected void cacheUniqueFindersCache(SocialRelation socialRelation) {
5478 if (socialRelation.isNew()) {
5479 Object[] args = new Object[] {
5480 socialRelation.getUserId1(), socialRelation.getUserId2(),
5481 socialRelation.getType()
5482 };
5483
5484 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
5485 Long.valueOf(1));
5486 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
5487 socialRelation);
5488 }
5489 else {
5490 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5491
5492 if ((socialRelationModelImpl.getColumnBitmask() &
5493 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
5494 Object[] args = new Object[] {
5495 socialRelation.getUserId1(), socialRelation.getUserId2(),
5496 socialRelation.getType()
5497 };
5498
5499 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
5500 Long.valueOf(1));
5501 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
5502 socialRelation);
5503 }
5504 }
5505 }
5506
5507 protected void clearUniqueFindersCache(SocialRelation socialRelation) {
5508 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5509
5510 Object[] args = new Object[] {
5511 socialRelation.getUserId1(), socialRelation.getUserId2(),
5512 socialRelation.getType()
5513 };
5514
5515 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
5516 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
5517
5518 if ((socialRelationModelImpl.getColumnBitmask() &
5519 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
5520 args = new Object[] {
5521 socialRelationModelImpl.getOriginalUserId1(),
5522 socialRelationModelImpl.getOriginalUserId2(),
5523 socialRelationModelImpl.getOriginalType()
5524 };
5525
5526 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
5527 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
5528 }
5529 }
5530
5531
5537 public SocialRelation create(long relationId) {
5538 SocialRelation socialRelation = new SocialRelationImpl();
5539
5540 socialRelation.setNew(true);
5541 socialRelation.setPrimaryKey(relationId);
5542
5543 String uuid = PortalUUIDUtil.generate();
5544
5545 socialRelation.setUuid(uuid);
5546
5547 return socialRelation;
5548 }
5549
5550
5558 public SocialRelation remove(long relationId)
5559 throws NoSuchRelationException, SystemException {
5560 return remove((Serializable)relationId);
5561 }
5562
5563
5571 @Override
5572 public SocialRelation remove(Serializable primaryKey)
5573 throws NoSuchRelationException, SystemException {
5574 Session session = null;
5575
5576 try {
5577 session = openSession();
5578
5579 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5580 primaryKey);
5581
5582 if (socialRelation == null) {
5583 if (_log.isWarnEnabled()) {
5584 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5585 }
5586
5587 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5588 primaryKey);
5589 }
5590
5591 return remove(socialRelation);
5592 }
5593 catch (NoSuchRelationException nsee) {
5594 throw nsee;
5595 }
5596 catch (Exception e) {
5597 throw processException(e);
5598 }
5599 finally {
5600 closeSession(session);
5601 }
5602 }
5603
5604 @Override
5605 protected SocialRelation removeImpl(SocialRelation socialRelation)
5606 throws SystemException {
5607 socialRelation = toUnwrappedModel(socialRelation);
5608
5609 Session session = null;
5610
5611 try {
5612 session = openSession();
5613
5614 if (!session.contains(socialRelation)) {
5615 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5616 socialRelation.getPrimaryKeyObj());
5617 }
5618
5619 if (socialRelation != null) {
5620 session.delete(socialRelation);
5621 }
5622 }
5623 catch (Exception e) {
5624 throw processException(e);
5625 }
5626 finally {
5627 closeSession(session);
5628 }
5629
5630 if (socialRelation != null) {
5631 clearCache(socialRelation);
5632 }
5633
5634 return socialRelation;
5635 }
5636
5637 @Override
5638 public SocialRelation updateImpl(
5639 com.liferay.portlet.social.model.SocialRelation socialRelation)
5640 throws SystemException {
5641 socialRelation = toUnwrappedModel(socialRelation);
5642
5643 boolean isNew = socialRelation.isNew();
5644
5645 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5646
5647 if (Validator.isNull(socialRelation.getUuid())) {
5648 String uuid = PortalUUIDUtil.generate();
5649
5650 socialRelation.setUuid(uuid);
5651 }
5652
5653 Session session = null;
5654
5655 try {
5656 session = openSession();
5657
5658 if (socialRelation.isNew()) {
5659 session.save(socialRelation);
5660
5661 socialRelation.setNew(false);
5662 }
5663 else {
5664 session.merge(socialRelation);
5665 }
5666 }
5667 catch (Exception e) {
5668 throw processException(e);
5669 }
5670 finally {
5671 closeSession(session);
5672 }
5673
5674 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5675
5676 if (isNew || !SocialRelationModelImpl.COLUMN_BITMASK_ENABLED) {
5677 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5678 }
5679
5680 else {
5681 if ((socialRelationModelImpl.getColumnBitmask() &
5682 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5683 Object[] args = new Object[] {
5684 socialRelationModelImpl.getOriginalUuid()
5685 };
5686
5687 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5688 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5689 args);
5690
5691 args = new Object[] { socialRelationModelImpl.getUuid() };
5692
5693 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5694 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5695 args);
5696 }
5697
5698 if ((socialRelationModelImpl.getColumnBitmask() &
5699 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5700 Object[] args = new Object[] {
5701 socialRelationModelImpl.getOriginalUuid(),
5702 socialRelationModelImpl.getOriginalCompanyId()
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 args = new Object[] {
5710 socialRelationModelImpl.getUuid(),
5711 socialRelationModelImpl.getCompanyId()
5712 };
5713
5714 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5715 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5716 args);
5717 }
5718
5719 if ((socialRelationModelImpl.getColumnBitmask() &
5720 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
5721 Object[] args = new Object[] {
5722 socialRelationModelImpl.getOriginalCompanyId()
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 args = new Object[] { socialRelationModelImpl.getCompanyId() };
5731
5732 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5733 args);
5734 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5735 args);
5736 }
5737
5738 if ((socialRelationModelImpl.getColumnBitmask() &
5739 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1.getColumnBitmask()) != 0) {
5740 Object[] args = new Object[] {
5741 socialRelationModelImpl.getOriginalUserId1()
5742 };
5743
5744 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
5745 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
5746 args);
5747
5748 args = new Object[] { socialRelationModelImpl.getUserId1() };
5749
5750 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
5751 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
5752 args);
5753 }
5754
5755 if ((socialRelationModelImpl.getColumnBitmask() &
5756 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2.getColumnBitmask()) != 0) {
5757 Object[] args = new Object[] {
5758 socialRelationModelImpl.getOriginalUserId2()
5759 };
5760
5761 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
5762 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
5763 args);
5764
5765 args = new Object[] { socialRelationModelImpl.getUserId2() };
5766
5767 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
5768 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
5769 args);
5770 }
5771
5772 if ((socialRelationModelImpl.getColumnBitmask() &
5773 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
5774 Object[] args = new Object[] {
5775 socialRelationModelImpl.getOriginalType()
5776 };
5777
5778 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
5779 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
5780 args);
5781
5782 args = new Object[] { socialRelationModelImpl.getType() };
5783
5784 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
5785 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
5786 args);
5787 }
5788
5789 if ((socialRelationModelImpl.getColumnBitmask() &
5790 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
5791 Object[] args = new Object[] {
5792 socialRelationModelImpl.getOriginalCompanyId(),
5793 socialRelationModelImpl.getOriginalType()
5794 };
5795
5796 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
5797 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
5798 args);
5799
5800 args = new Object[] {
5801 socialRelationModelImpl.getCompanyId(),
5802 socialRelationModelImpl.getType()
5803 };
5804
5805 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
5806 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
5807 args);
5808 }
5809
5810 if ((socialRelationModelImpl.getColumnBitmask() &
5811 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2.getColumnBitmask()) != 0) {
5812 Object[] args = new Object[] {
5813 socialRelationModelImpl.getOriginalUserId1(),
5814 socialRelationModelImpl.getOriginalUserId2()
5815 };
5816
5817 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
5818 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
5819 args);
5820
5821 args = new Object[] {
5822 socialRelationModelImpl.getUserId1(),
5823 socialRelationModelImpl.getUserId2()
5824 };
5825
5826 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
5827 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
5828 args);
5829 }
5830
5831 if ((socialRelationModelImpl.getColumnBitmask() &
5832 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T.getColumnBitmask()) != 0) {
5833 Object[] args = new Object[] {
5834 socialRelationModelImpl.getOriginalUserId1(),
5835 socialRelationModelImpl.getOriginalType()
5836 };
5837
5838 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
5839 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
5840 args);
5841
5842 args = new Object[] {
5843 socialRelationModelImpl.getUserId1(),
5844 socialRelationModelImpl.getType()
5845 };
5846
5847 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
5848 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
5849 args);
5850 }
5851
5852 if ((socialRelationModelImpl.getColumnBitmask() &
5853 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T.getColumnBitmask()) != 0) {
5854 Object[] args = new Object[] {
5855 socialRelationModelImpl.getOriginalUserId2(),
5856 socialRelationModelImpl.getOriginalType()
5857 };
5858
5859 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
5860 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
5861 args);
5862
5863 args = new Object[] {
5864 socialRelationModelImpl.getUserId2(),
5865 socialRelationModelImpl.getType()
5866 };
5867
5868 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
5869 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
5870 args);
5871 }
5872 }
5873
5874 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5875 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
5876 socialRelation);
5877
5878 clearUniqueFindersCache(socialRelation);
5879 cacheUniqueFindersCache(socialRelation);
5880
5881 return socialRelation;
5882 }
5883
5884 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
5885 if (socialRelation instanceof SocialRelationImpl) {
5886 return socialRelation;
5887 }
5888
5889 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
5890
5891 socialRelationImpl.setNew(socialRelation.isNew());
5892 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
5893
5894 socialRelationImpl.setUuid(socialRelation.getUuid());
5895 socialRelationImpl.setRelationId(socialRelation.getRelationId());
5896 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
5897 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
5898 socialRelationImpl.setUserId1(socialRelation.getUserId1());
5899 socialRelationImpl.setUserId2(socialRelation.getUserId2());
5900 socialRelationImpl.setType(socialRelation.getType());
5901
5902 return socialRelationImpl;
5903 }
5904
5905
5913 @Override
5914 public SocialRelation findByPrimaryKey(Serializable primaryKey)
5915 throws NoSuchRelationException, SystemException {
5916 SocialRelation socialRelation = fetchByPrimaryKey(primaryKey);
5917
5918 if (socialRelation == null) {
5919 if (_log.isWarnEnabled()) {
5920 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5921 }
5922
5923 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5924 primaryKey);
5925 }
5926
5927 return socialRelation;
5928 }
5929
5930
5938 public SocialRelation findByPrimaryKey(long relationId)
5939 throws NoSuchRelationException, SystemException {
5940 return findByPrimaryKey((Serializable)relationId);
5941 }
5942
5943
5950 @Override
5951 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
5952 throws SystemException {
5953 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5954 SocialRelationImpl.class, primaryKey);
5955
5956 if (socialRelation == _nullSocialRelation) {
5957 return null;
5958 }
5959
5960 if (socialRelation == null) {
5961 Session session = null;
5962
5963 try {
5964 session = openSession();
5965
5966 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5967 primaryKey);
5968
5969 if (socialRelation != null) {
5970 cacheResult(socialRelation);
5971 }
5972 else {
5973 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5974 SocialRelationImpl.class, primaryKey,
5975 _nullSocialRelation);
5976 }
5977 }
5978 catch (Exception e) {
5979 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5980 SocialRelationImpl.class, primaryKey);
5981
5982 throw processException(e);
5983 }
5984 finally {
5985 closeSession(session);
5986 }
5987 }
5988
5989 return socialRelation;
5990 }
5991
5992
5999 public SocialRelation fetchByPrimaryKey(long relationId)
6000 throws SystemException {
6001 return fetchByPrimaryKey((Serializable)relationId);
6002 }
6003
6004
6010 public List<SocialRelation> findAll() throws SystemException {
6011 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6012 }
6013
6014
6026 public List<SocialRelation> findAll(int start, int end)
6027 throws SystemException {
6028 return findAll(start, end, null);
6029 }
6030
6031
6044 public List<SocialRelation> findAll(int start, int end,
6045 OrderByComparator orderByComparator) throws SystemException {
6046 boolean pagination = true;
6047 FinderPath finderPath = null;
6048 Object[] finderArgs = null;
6049
6050 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6051 (orderByComparator == null)) {
6052 pagination = false;
6053 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6054 finderArgs = FINDER_ARGS_EMPTY;
6055 }
6056 else {
6057 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6058 finderArgs = new Object[] { start, end, orderByComparator };
6059 }
6060
6061 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
6062 finderArgs, this);
6063
6064 if (list == null) {
6065 StringBundler query = null;
6066 String sql = null;
6067
6068 if (orderByComparator != null) {
6069 query = new StringBundler(2 +
6070 (orderByComparator.getOrderByFields().length * 3));
6071
6072 query.append(_SQL_SELECT_SOCIALRELATION);
6073
6074 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6075 orderByComparator);
6076
6077 sql = query.toString();
6078 }
6079 else {
6080 sql = _SQL_SELECT_SOCIALRELATION;
6081
6082 if (pagination) {
6083 sql = sql.concat(SocialRelationModelImpl.ORDER_BY_JPQL);
6084 }
6085 }
6086
6087 Session session = null;
6088
6089 try {
6090 session = openSession();
6091
6092 Query q = session.createQuery(sql);
6093
6094 if (!pagination) {
6095 list = (List<SocialRelation>)QueryUtil.list(q,
6096 getDialect(), start, end, false);
6097
6098 Collections.sort(list);
6099
6100 list = new UnmodifiableList<SocialRelation>(list);
6101 }
6102 else {
6103 list = (List<SocialRelation>)QueryUtil.list(q,
6104 getDialect(), start, end);
6105 }
6106
6107 cacheResult(list);
6108
6109 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6110 }
6111 catch (Exception e) {
6112 FinderCacheUtil.removeResult(finderPath, finderArgs);
6113
6114 throw processException(e);
6115 }
6116 finally {
6117 closeSession(session);
6118 }
6119 }
6120
6121 return list;
6122 }
6123
6124
6129 public void removeAll() throws SystemException {
6130 for (SocialRelation socialRelation : findAll()) {
6131 remove(socialRelation);
6132 }
6133 }
6134
6135
6141 public int countAll() throws SystemException {
6142 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6143 FINDER_ARGS_EMPTY, this);
6144
6145 if (count == null) {
6146 Session session = null;
6147
6148 try {
6149 session = openSession();
6150
6151 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
6152
6153 count = (Long)q.uniqueResult();
6154
6155 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6156 FINDER_ARGS_EMPTY, count);
6157 }
6158 catch (Exception e) {
6159 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
6160 FINDER_ARGS_EMPTY);
6161
6162 throw processException(e);
6163 }
6164 finally {
6165 closeSession(session);
6166 }
6167 }
6168
6169 return count.intValue();
6170 }
6171
6172 @Override
6173 protected Set<String> getBadColumnNames() {
6174 return _badColumnNames;
6175 }
6176
6177
6180 public void afterPropertiesSet() {
6181 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6182 com.liferay.portal.util.PropsUtil.get(
6183 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
6184
6185 if (listenerClassNames.length > 0) {
6186 try {
6187 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
6188
6189 for (String listenerClassName : listenerClassNames) {
6190 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
6191 getClassLoader(), listenerClassName));
6192 }
6193
6194 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6195 }
6196 catch (Exception e) {
6197 _log.error(e);
6198 }
6199 }
6200 }
6201
6202 public void destroy() {
6203 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
6204 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6205 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6206 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6207 }
6208
6209 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
6210 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
6211 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
6212 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
6213 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
6214 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
6215 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
6216 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6217 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
6218 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6219 "uuid", "type"
6220 });
6221 private static SocialRelation _nullSocialRelation = new SocialRelationImpl() {
6222 @Override
6223 public Object clone() {
6224 return this;
6225 }
6226
6227 @Override
6228 public CacheModel<SocialRelation> toCacheModel() {
6229 return _nullSocialRelationCacheModel;
6230 }
6231 };
6232
6233 private static CacheModel<SocialRelation> _nullSocialRelationCacheModel = new CacheModel<SocialRelation>() {
6234 public SocialRelation toEntityModel() {
6235 return _nullSocialRelation;
6236 }
6237 };
6238 }