001
014
015 package com.liferay.portlet.social.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.OrderByComparator;
029 import com.liferay.portal.kernel.util.SetUtil;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
036
037 import com.liferay.portlet.social.NoSuchRelationException;
038 import com.liferay.portlet.social.model.SocialRelation;
039 import com.liferay.portlet.social.model.impl.SocialRelationImpl;
040 import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
041 import com.liferay.portlet.social.service.persistence.SocialRelationPersistence;
042
043 import java.io.Serializable;
044
045 import java.util.Collections;
046 import java.util.HashMap;
047 import java.util.HashSet;
048 import java.util.Iterator;
049 import java.util.List;
050 import java.util.Map;
051 import java.util.Set;
052
053
065 @ProviderType
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
116 @Override
117 public List<SocialRelation> findByUuid(String uuid) {
118 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
133 @Override
134 public List<SocialRelation> findByUuid(String uuid, int start, int end) {
135 return findByUuid(uuid, start, end, null);
136 }
137
138
151 @Override
152 public List<SocialRelation> findByUuid(String uuid, int start, int end,
153 OrderByComparator<SocialRelation> orderByComparator) {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162 finderArgs = new Object[] { uuid };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166 finderArgs = new Object[] { uuid, start, end, orderByComparator };
167 }
168
169 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (SocialRelation socialRelation : list) {
174 if (!Validator.equals(uuid, socialRelation.getUuid())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
194
195 boolean bindUuid = false;
196
197 if (uuid == null) {
198 query.append(_FINDER_COLUMN_UUID_UUID_1);
199 }
200 else if (uuid.equals(StringPool.BLANK)) {
201 query.append(_FINDER_COLUMN_UUID_UUID_3);
202 }
203 else {
204 bindUuid = true;
205
206 query.append(_FINDER_COLUMN_UUID_UUID_2);
207 }
208
209 if (orderByComparator != null) {
210 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
211 orderByComparator);
212 }
213 else
214 if (pagination) {
215 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
216 }
217
218 String sql = query.toString();
219
220 Session session = null;
221
222 try {
223 session = openSession();
224
225 Query q = session.createQuery(sql);
226
227 QueryPos qPos = QueryPos.getInstance(q);
228
229 if (bindUuid) {
230 qPos.add(uuid);
231 }
232
233 if (!pagination) {
234 list = (List<SocialRelation>)QueryUtil.list(q,
235 getDialect(), start, end, false);
236
237 Collections.sort(list);
238
239 list = Collections.unmodifiableList(list);
240 }
241 else {
242 list = (List<SocialRelation>)QueryUtil.list(q,
243 getDialect(), start, end);
244 }
245
246 cacheResult(list);
247
248 FinderCacheUtil.putResult(finderPath, finderArgs, list);
249 }
250 catch (Exception e) {
251 FinderCacheUtil.removeResult(finderPath, finderArgs);
252
253 throw processException(e);
254 }
255 finally {
256 closeSession(session);
257 }
258 }
259
260 return list;
261 }
262
263
271 @Override
272 public SocialRelation findByUuid_First(String uuid,
273 OrderByComparator<SocialRelation> orderByComparator)
274 throws NoSuchRelationException {
275 SocialRelation socialRelation = fetchByUuid_First(uuid,
276 orderByComparator);
277
278 if (socialRelation != null) {
279 return socialRelation;
280 }
281
282 StringBundler msg = new StringBundler(4);
283
284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285
286 msg.append("uuid=");
287 msg.append(uuid);
288
289 msg.append(StringPool.CLOSE_CURLY_BRACE);
290
291 throw new NoSuchRelationException(msg.toString());
292 }
293
294
301 @Override
302 public SocialRelation fetchByUuid_First(String uuid,
303 OrderByComparator<SocialRelation> orderByComparator) {
304 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
305
306 if (!list.isEmpty()) {
307 return list.get(0);
308 }
309
310 return null;
311 }
312
313
321 @Override
322 public SocialRelation findByUuid_Last(String uuid,
323 OrderByComparator<SocialRelation> orderByComparator)
324 throws NoSuchRelationException {
325 SocialRelation socialRelation = fetchByUuid_Last(uuid, orderByComparator);
326
327 if (socialRelation != null) {
328 return socialRelation;
329 }
330
331 StringBundler msg = new StringBundler(4);
332
333 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
334
335 msg.append("uuid=");
336 msg.append(uuid);
337
338 msg.append(StringPool.CLOSE_CURLY_BRACE);
339
340 throw new NoSuchRelationException(msg.toString());
341 }
342
343
350 @Override
351 public SocialRelation fetchByUuid_Last(String uuid,
352 OrderByComparator<SocialRelation> orderByComparator) {
353 int count = countByUuid(uuid);
354
355 if (count == 0) {
356 return null;
357 }
358
359 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
360 orderByComparator);
361
362 if (!list.isEmpty()) {
363 return list.get(0);
364 }
365
366 return null;
367 }
368
369
378 @Override
379 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
380 String uuid, OrderByComparator<SocialRelation> orderByComparator)
381 throws NoSuchRelationException {
382 SocialRelation socialRelation = findByPrimaryKey(relationId);
383
384 Session session = null;
385
386 try {
387 session = openSession();
388
389 SocialRelation[] array = new SocialRelationImpl[3];
390
391 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
392 orderByComparator, true);
393
394 array[1] = socialRelation;
395
396 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
397 orderByComparator, false);
398
399 return array;
400 }
401 catch (Exception e) {
402 throw processException(e);
403 }
404 finally {
405 closeSession(session);
406 }
407 }
408
409 protected SocialRelation getByUuid_PrevAndNext(Session session,
410 SocialRelation socialRelation, String uuid,
411 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
412 StringBundler query = null;
413
414 if (orderByComparator != null) {
415 query = new StringBundler(6 +
416 (orderByComparator.getOrderByFields().length * 6));
417 }
418 else {
419 query = new StringBundler(3);
420 }
421
422 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
423
424 boolean bindUuid = false;
425
426 if (uuid == null) {
427 query.append(_FINDER_COLUMN_UUID_UUID_1);
428 }
429 else if (uuid.equals(StringPool.BLANK)) {
430 query.append(_FINDER_COLUMN_UUID_UUID_3);
431 }
432 else {
433 bindUuid = true;
434
435 query.append(_FINDER_COLUMN_UUID_UUID_2);
436 }
437
438 if (orderByComparator != null) {
439 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
440
441 if (orderByConditionFields.length > 0) {
442 query.append(WHERE_AND);
443 }
444
445 for (int i = 0; i < orderByConditionFields.length; i++) {
446 query.append(_ORDER_BY_ENTITY_ALIAS);
447 query.append(orderByConditionFields[i]);
448
449 if ((i + 1) < orderByConditionFields.length) {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(WHERE_GREATER_THAN_HAS_NEXT);
452 }
453 else {
454 query.append(WHERE_LESSER_THAN_HAS_NEXT);
455 }
456 }
457 else {
458 if (orderByComparator.isAscending() ^ previous) {
459 query.append(WHERE_GREATER_THAN);
460 }
461 else {
462 query.append(WHERE_LESSER_THAN);
463 }
464 }
465 }
466
467 query.append(ORDER_BY_CLAUSE);
468
469 String[] orderByFields = orderByComparator.getOrderByFields();
470
471 for (int i = 0; i < orderByFields.length; i++) {
472 query.append(_ORDER_BY_ENTITY_ALIAS);
473 query.append(orderByFields[i]);
474
475 if ((i + 1) < orderByFields.length) {
476 if (orderByComparator.isAscending() ^ previous) {
477 query.append(ORDER_BY_ASC_HAS_NEXT);
478 }
479 else {
480 query.append(ORDER_BY_DESC_HAS_NEXT);
481 }
482 }
483 else {
484 if (orderByComparator.isAscending() ^ previous) {
485 query.append(ORDER_BY_ASC);
486 }
487 else {
488 query.append(ORDER_BY_DESC);
489 }
490 }
491 }
492 }
493 else {
494 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
495 }
496
497 String sql = query.toString();
498
499 Query q = session.createQuery(sql);
500
501 q.setFirstResult(0);
502 q.setMaxResults(2);
503
504 QueryPos qPos = QueryPos.getInstance(q);
505
506 if (bindUuid) {
507 qPos.add(uuid);
508 }
509
510 if (orderByComparator != null) {
511 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
512
513 for (Object value : values) {
514 qPos.add(value);
515 }
516 }
517
518 List<SocialRelation> list = q.list();
519
520 if (list.size() == 2) {
521 return list.get(1);
522 }
523 else {
524 return null;
525 }
526 }
527
528
533 @Override
534 public void removeByUuid(String uuid) {
535 for (SocialRelation socialRelation : findByUuid(uuid,
536 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
537 remove(socialRelation);
538 }
539 }
540
541
547 @Override
548 public int countByUuid(String uuid) {
549 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
550
551 Object[] finderArgs = new Object[] { uuid };
552
553 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
554 this);
555
556 if (count == null) {
557 StringBundler query = new StringBundler(2);
558
559 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
560
561 boolean bindUuid = false;
562
563 if (uuid == null) {
564 query.append(_FINDER_COLUMN_UUID_UUID_1);
565 }
566 else if (uuid.equals(StringPool.BLANK)) {
567 query.append(_FINDER_COLUMN_UUID_UUID_3);
568 }
569 else {
570 bindUuid = true;
571
572 query.append(_FINDER_COLUMN_UUID_UUID_2);
573 }
574
575 String sql = query.toString();
576
577 Session session = null;
578
579 try {
580 session = openSession();
581
582 Query q = session.createQuery(sql);
583
584 QueryPos qPos = QueryPos.getInstance(q);
585
586 if (bindUuid) {
587 qPos.add(uuid);
588 }
589
590 count = (Long)q.uniqueResult();
591
592 FinderCacheUtil.putResult(finderPath, finderArgs, count);
593 }
594 catch (Exception e) {
595 FinderCacheUtil.removeResult(finderPath, finderArgs);
596
597 throw processException(e);
598 }
599 finally {
600 closeSession(session);
601 }
602 }
603
604 return count.intValue();
605 }
606
607 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
608 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
609 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = '')";
610 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
611 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
612 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
613 "findByUuid_C",
614 new String[] {
615 String.class.getName(), Long.class.getName(),
616
617 Integer.class.getName(), Integer.class.getName(),
618 OrderByComparator.class.getName()
619 });
620 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
621 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
622 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
623 SocialRelationImpl.class,
624 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
625 new String[] { String.class.getName(), Long.class.getName() },
626 SocialRelationModelImpl.UUID_COLUMN_BITMASK |
627 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
628 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
629 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
630 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
631 new String[] { String.class.getName(), Long.class.getName() });
632
633
640 @Override
641 public List<SocialRelation> findByUuid_C(String uuid, long companyId) {
642 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
643 QueryUtil.ALL_POS, null);
644 }
645
646
659 @Override
660 public List<SocialRelation> findByUuid_C(String uuid, long companyId,
661 int start, int end) {
662 return findByUuid_C(uuid, companyId, start, end, null);
663 }
664
665
679 @Override
680 public List<SocialRelation> findByUuid_C(String uuid, long companyId,
681 int start, int end, OrderByComparator<SocialRelation> orderByComparator) {
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 = Collections.unmodifiableList(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
809 @Override
810 public SocialRelation findByUuid_C_First(String uuid, long companyId,
811 OrderByComparator<SocialRelation> orderByComparator)
812 throws NoSuchRelationException {
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
843 @Override
844 public SocialRelation fetchByUuid_C_First(String uuid, long companyId,
845 OrderByComparator<SocialRelation> orderByComparator) {
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
865 @Override
866 public SocialRelation findByUuid_C_Last(String uuid, long companyId,
867 OrderByComparator<SocialRelation> orderByComparator)
868 throws NoSuchRelationException {
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
899 @Override
900 public SocialRelation fetchByUuid_C_Last(String uuid, long companyId,
901 OrderByComparator<SocialRelation> orderByComparator) {
902 int count = countByUuid_C(uuid, companyId);
903
904 if (count == 0) {
905 return null;
906 }
907
908 List<SocialRelation> list = findByUuid_C(uuid, companyId, count - 1,
909 count, orderByComparator);
910
911 if (!list.isEmpty()) {
912 return list.get(0);
913 }
914
915 return null;
916 }
917
918
928 @Override
929 public SocialRelation[] findByUuid_C_PrevAndNext(long relationId,
930 String uuid, long companyId,
931 OrderByComparator<SocialRelation> orderByComparator)
932 throws NoSuchRelationException {
933 SocialRelation socialRelation = findByPrimaryKey(relationId);
934
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 SocialRelation[] array = new SocialRelationImpl[3];
941
942 array[0] = getByUuid_C_PrevAndNext(session, socialRelation, uuid,
943 companyId, orderByComparator, true);
944
945 array[1] = socialRelation;
946
947 array[2] = getByUuid_C_PrevAndNext(session, socialRelation, uuid,
948 companyId, orderByComparator, false);
949
950 return array;
951 }
952 catch (Exception e) {
953 throw processException(e);
954 }
955 finally {
956 closeSession(session);
957 }
958 }
959
960 protected SocialRelation getByUuid_C_PrevAndNext(Session session,
961 SocialRelation socialRelation, String uuid, long companyId,
962 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
963 StringBundler query = null;
964
965 if (orderByComparator != null) {
966 query = new StringBundler(6 +
967 (orderByComparator.getOrderByFields().length * 6));
968 }
969 else {
970 query = new StringBundler(3);
971 }
972
973 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
974
975 boolean bindUuid = false;
976
977 if (uuid == null) {
978 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
979 }
980 else if (uuid.equals(StringPool.BLANK)) {
981 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
982 }
983 else {
984 bindUuid = true;
985
986 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
987 }
988
989 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
990
991 if (orderByComparator != null) {
992 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
993
994 if (orderByConditionFields.length > 0) {
995 query.append(WHERE_AND);
996 }
997
998 for (int i = 0; i < orderByConditionFields.length; i++) {
999 query.append(_ORDER_BY_ENTITY_ALIAS);
1000 query.append(orderByConditionFields[i]);
1001
1002 if ((i + 1) < orderByConditionFields.length) {
1003 if (orderByComparator.isAscending() ^ previous) {
1004 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1005 }
1006 else {
1007 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1008 }
1009 }
1010 else {
1011 if (orderByComparator.isAscending() ^ previous) {
1012 query.append(WHERE_GREATER_THAN);
1013 }
1014 else {
1015 query.append(WHERE_LESSER_THAN);
1016 }
1017 }
1018 }
1019
1020 query.append(ORDER_BY_CLAUSE);
1021
1022 String[] orderByFields = orderByComparator.getOrderByFields();
1023
1024 for (int i = 0; i < orderByFields.length; i++) {
1025 query.append(_ORDER_BY_ENTITY_ALIAS);
1026 query.append(orderByFields[i]);
1027
1028 if ((i + 1) < orderByFields.length) {
1029 if (orderByComparator.isAscending() ^ previous) {
1030 query.append(ORDER_BY_ASC_HAS_NEXT);
1031 }
1032 else {
1033 query.append(ORDER_BY_DESC_HAS_NEXT);
1034 }
1035 }
1036 else {
1037 if (orderByComparator.isAscending() ^ previous) {
1038 query.append(ORDER_BY_ASC);
1039 }
1040 else {
1041 query.append(ORDER_BY_DESC);
1042 }
1043 }
1044 }
1045 }
1046 else {
1047 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1048 }
1049
1050 String sql = query.toString();
1051
1052 Query q = session.createQuery(sql);
1053
1054 q.setFirstResult(0);
1055 q.setMaxResults(2);
1056
1057 QueryPos qPos = QueryPos.getInstance(q);
1058
1059 if (bindUuid) {
1060 qPos.add(uuid);
1061 }
1062
1063 qPos.add(companyId);
1064
1065 if (orderByComparator != null) {
1066 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1067
1068 for (Object value : values) {
1069 qPos.add(value);
1070 }
1071 }
1072
1073 List<SocialRelation> list = q.list();
1074
1075 if (list.size() == 2) {
1076 return list.get(1);
1077 }
1078 else {
1079 return null;
1080 }
1081 }
1082
1083
1089 @Override
1090 public void removeByUuid_C(String uuid, long companyId) {
1091 for (SocialRelation socialRelation : findByUuid_C(uuid, companyId,
1092 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1093 remove(socialRelation);
1094 }
1095 }
1096
1097
1104 @Override
1105 public int countByUuid_C(String uuid, long companyId) {
1106 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1107
1108 Object[] finderArgs = new Object[] { uuid, companyId };
1109
1110 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1111 this);
1112
1113 if (count == null) {
1114 StringBundler query = new StringBundler(3);
1115
1116 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
1117
1118 boolean bindUuid = false;
1119
1120 if (uuid == null) {
1121 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1122 }
1123 else if (uuid.equals(StringPool.BLANK)) {
1124 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1125 }
1126 else {
1127 bindUuid = true;
1128
1129 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1130 }
1131
1132 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1133
1134 String sql = query.toString();
1135
1136 Session session = null;
1137
1138 try {
1139 session = openSession();
1140
1141 Query q = session.createQuery(sql);
1142
1143 QueryPos qPos = QueryPos.getInstance(q);
1144
1145 if (bindUuid) {
1146 qPos.add(uuid);
1147 }
1148
1149 qPos.add(companyId);
1150
1151 count = (Long)q.uniqueResult();
1152
1153 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1154 }
1155 catch (Exception e) {
1156 FinderCacheUtil.removeResult(finderPath, finderArgs);
1157
1158 throw processException(e);
1159 }
1160 finally {
1161 closeSession(session);
1162 }
1163 }
1164
1165 return count.intValue();
1166 }
1167
1168 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "socialRelation.uuid IS NULL AND ";
1169 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "socialRelation.uuid = ? AND ";
1170 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = '') AND ";
1171 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "socialRelation.companyId = ?";
1172 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1173 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1174 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1175 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1176 "findByCompanyId",
1177 new String[] {
1178 Long.class.getName(),
1179
1180 Integer.class.getName(), Integer.class.getName(),
1181 OrderByComparator.class.getName()
1182 });
1183 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1184 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1185 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1186 SocialRelationImpl.class,
1187 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1188 new String[] { Long.class.getName() },
1189 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
1190 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1191 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1192 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1193 new String[] { Long.class.getName() });
1194
1195
1201 @Override
1202 public List<SocialRelation> findByCompanyId(long companyId) {
1203 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1204 null);
1205 }
1206
1207
1219 @Override
1220 public List<SocialRelation> findByCompanyId(long companyId, int start,
1221 int end) {
1222 return findByCompanyId(companyId, start, end, null);
1223 }
1224
1225
1238 @Override
1239 public List<SocialRelation> findByCompanyId(long companyId, int start,
1240 int end, OrderByComparator<SocialRelation> orderByComparator) {
1241 boolean pagination = true;
1242 FinderPath finderPath = null;
1243 Object[] finderArgs = null;
1244
1245 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1246 (orderByComparator == null)) {
1247 pagination = false;
1248 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1249 finderArgs = new Object[] { companyId };
1250 }
1251 else {
1252 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1253 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1254 }
1255
1256 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1257 finderArgs, this);
1258
1259 if ((list != null) && !list.isEmpty()) {
1260 for (SocialRelation socialRelation : list) {
1261 if ((companyId != socialRelation.getCompanyId())) {
1262 list = null;
1263
1264 break;
1265 }
1266 }
1267 }
1268
1269 if (list == null) {
1270 StringBundler query = null;
1271
1272 if (orderByComparator != null) {
1273 query = new StringBundler(3 +
1274 (orderByComparator.getOrderByFields().length * 3));
1275 }
1276 else {
1277 query = new StringBundler(3);
1278 }
1279
1280 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1281
1282 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1283
1284 if (orderByComparator != null) {
1285 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1286 orderByComparator);
1287 }
1288 else
1289 if (pagination) {
1290 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1291 }
1292
1293 String sql = query.toString();
1294
1295 Session session = null;
1296
1297 try {
1298 session = openSession();
1299
1300 Query q = session.createQuery(sql);
1301
1302 QueryPos qPos = QueryPos.getInstance(q);
1303
1304 qPos.add(companyId);
1305
1306 if (!pagination) {
1307 list = (List<SocialRelation>)QueryUtil.list(q,
1308 getDialect(), start, end, false);
1309
1310 Collections.sort(list);
1311
1312 list = Collections.unmodifiableList(list);
1313 }
1314 else {
1315 list = (List<SocialRelation>)QueryUtil.list(q,
1316 getDialect(), start, end);
1317 }
1318
1319 cacheResult(list);
1320
1321 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1322 }
1323 catch (Exception e) {
1324 FinderCacheUtil.removeResult(finderPath, finderArgs);
1325
1326 throw processException(e);
1327 }
1328 finally {
1329 closeSession(session);
1330 }
1331 }
1332
1333 return list;
1334 }
1335
1336
1344 @Override
1345 public SocialRelation findByCompanyId_First(long companyId,
1346 OrderByComparator<SocialRelation> orderByComparator)
1347 throws NoSuchRelationException {
1348 SocialRelation socialRelation = fetchByCompanyId_First(companyId,
1349 orderByComparator);
1350
1351 if (socialRelation != null) {
1352 return socialRelation;
1353 }
1354
1355 StringBundler msg = new StringBundler(4);
1356
1357 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1358
1359 msg.append("companyId=");
1360 msg.append(companyId);
1361
1362 msg.append(StringPool.CLOSE_CURLY_BRACE);
1363
1364 throw new NoSuchRelationException(msg.toString());
1365 }
1366
1367
1374 @Override
1375 public SocialRelation fetchByCompanyId_First(long companyId,
1376 OrderByComparator<SocialRelation> orderByComparator) {
1377 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1378 orderByComparator);
1379
1380 if (!list.isEmpty()) {
1381 return list.get(0);
1382 }
1383
1384 return null;
1385 }
1386
1387
1395 @Override
1396 public SocialRelation findByCompanyId_Last(long companyId,
1397 OrderByComparator<SocialRelation> orderByComparator)
1398 throws NoSuchRelationException {
1399 SocialRelation socialRelation = fetchByCompanyId_Last(companyId,
1400 orderByComparator);
1401
1402 if (socialRelation != null) {
1403 return socialRelation;
1404 }
1405
1406 StringBundler msg = new StringBundler(4);
1407
1408 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1409
1410 msg.append("companyId=");
1411 msg.append(companyId);
1412
1413 msg.append(StringPool.CLOSE_CURLY_BRACE);
1414
1415 throw new NoSuchRelationException(msg.toString());
1416 }
1417
1418
1425 @Override
1426 public SocialRelation fetchByCompanyId_Last(long companyId,
1427 OrderByComparator<SocialRelation> orderByComparator) {
1428 int count = countByCompanyId(companyId);
1429
1430 if (count == 0) {
1431 return null;
1432 }
1433
1434 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1435 count, orderByComparator);
1436
1437 if (!list.isEmpty()) {
1438 return list.get(0);
1439 }
1440
1441 return null;
1442 }
1443
1444
1453 @Override
1454 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1455 long companyId, OrderByComparator<SocialRelation> orderByComparator)
1456 throws NoSuchRelationException {
1457 SocialRelation socialRelation = findByPrimaryKey(relationId);
1458
1459 Session session = null;
1460
1461 try {
1462 session = openSession();
1463
1464 SocialRelation[] array = new SocialRelationImpl[3];
1465
1466 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1467 companyId, orderByComparator, true);
1468
1469 array[1] = socialRelation;
1470
1471 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1472 companyId, orderByComparator, false);
1473
1474 return array;
1475 }
1476 catch (Exception e) {
1477 throw processException(e);
1478 }
1479 finally {
1480 closeSession(session);
1481 }
1482 }
1483
1484 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1485 SocialRelation socialRelation, long companyId,
1486 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
1487 StringBundler query = null;
1488
1489 if (orderByComparator != null) {
1490 query = new StringBundler(6 +
1491 (orderByComparator.getOrderByFields().length * 6));
1492 }
1493 else {
1494 query = new StringBundler(3);
1495 }
1496
1497 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1498
1499 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1500
1501 if (orderByComparator != null) {
1502 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1503
1504 if (orderByConditionFields.length > 0) {
1505 query.append(WHERE_AND);
1506 }
1507
1508 for (int i = 0; i < orderByConditionFields.length; i++) {
1509 query.append(_ORDER_BY_ENTITY_ALIAS);
1510 query.append(orderByConditionFields[i]);
1511
1512 if ((i + 1) < orderByConditionFields.length) {
1513 if (orderByComparator.isAscending() ^ previous) {
1514 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1515 }
1516 else {
1517 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1518 }
1519 }
1520 else {
1521 if (orderByComparator.isAscending() ^ previous) {
1522 query.append(WHERE_GREATER_THAN);
1523 }
1524 else {
1525 query.append(WHERE_LESSER_THAN);
1526 }
1527 }
1528 }
1529
1530 query.append(ORDER_BY_CLAUSE);
1531
1532 String[] orderByFields = orderByComparator.getOrderByFields();
1533
1534 for (int i = 0; i < orderByFields.length; i++) {
1535 query.append(_ORDER_BY_ENTITY_ALIAS);
1536 query.append(orderByFields[i]);
1537
1538 if ((i + 1) < orderByFields.length) {
1539 if (orderByComparator.isAscending() ^ previous) {
1540 query.append(ORDER_BY_ASC_HAS_NEXT);
1541 }
1542 else {
1543 query.append(ORDER_BY_DESC_HAS_NEXT);
1544 }
1545 }
1546 else {
1547 if (orderByComparator.isAscending() ^ previous) {
1548 query.append(ORDER_BY_ASC);
1549 }
1550 else {
1551 query.append(ORDER_BY_DESC);
1552 }
1553 }
1554 }
1555 }
1556 else {
1557 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1558 }
1559
1560 String sql = query.toString();
1561
1562 Query q = session.createQuery(sql);
1563
1564 q.setFirstResult(0);
1565 q.setMaxResults(2);
1566
1567 QueryPos qPos = QueryPos.getInstance(q);
1568
1569 qPos.add(companyId);
1570
1571 if (orderByComparator != null) {
1572 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1573
1574 for (Object value : values) {
1575 qPos.add(value);
1576 }
1577 }
1578
1579 List<SocialRelation> list = q.list();
1580
1581 if (list.size() == 2) {
1582 return list.get(1);
1583 }
1584 else {
1585 return null;
1586 }
1587 }
1588
1589
1594 @Override
1595 public void removeByCompanyId(long companyId) {
1596 for (SocialRelation socialRelation : findByCompanyId(companyId,
1597 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1598 remove(socialRelation);
1599 }
1600 }
1601
1602
1608 @Override
1609 public int countByCompanyId(long companyId) {
1610 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1611
1612 Object[] finderArgs = new Object[] { companyId };
1613
1614 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1615 this);
1616
1617 if (count == null) {
1618 StringBundler query = new StringBundler(2);
1619
1620 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
1621
1622 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1623
1624 String sql = query.toString();
1625
1626 Session session = null;
1627
1628 try {
1629 session = openSession();
1630
1631 Query q = session.createQuery(sql);
1632
1633 QueryPos qPos = QueryPos.getInstance(q);
1634
1635 qPos.add(companyId);
1636
1637 count = (Long)q.uniqueResult();
1638
1639 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1640 }
1641 catch (Exception e) {
1642 FinderCacheUtil.removeResult(finderPath, finderArgs);
1643
1644 throw processException(e);
1645 }
1646 finally {
1647 closeSession(session);
1648 }
1649 }
1650
1651 return count.intValue();
1652 }
1653
1654 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
1655 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1656 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1657 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1658 "findByUserId1",
1659 new String[] {
1660 Long.class.getName(),
1661
1662 Integer.class.getName(), Integer.class.getName(),
1663 OrderByComparator.class.getName()
1664 });
1665 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1 =
1666 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1667 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
1668 SocialRelationImpl.class,
1669 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId1",
1670 new String[] { Long.class.getName() },
1671 SocialRelationModelImpl.USERID1_COLUMN_BITMASK);
1672 public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
1673 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1674 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId1",
1675 new String[] { Long.class.getName() });
1676
1677
1683 @Override
1684 public List<SocialRelation> findByUserId1(long userId1) {
1685 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1686 }
1687
1688
1700 @Override
1701 public List<SocialRelation> findByUserId1(long userId1, int start, int end) {
1702 return findByUserId1(userId1, start, end, null);
1703 }
1704
1705
1718 @Override
1719 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1720 OrderByComparator<SocialRelation> orderByComparator) {
1721 boolean pagination = true;
1722 FinderPath finderPath = null;
1723 Object[] finderArgs = null;
1724
1725 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1726 (orderByComparator == null)) {
1727 pagination = false;
1728 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1729 finderArgs = new Object[] { userId1 };
1730 }
1731 else {
1732 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1733 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1734 }
1735
1736 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1737 finderArgs, this);
1738
1739 if ((list != null) && !list.isEmpty()) {
1740 for (SocialRelation socialRelation : list) {
1741 if ((userId1 != socialRelation.getUserId1())) {
1742 list = null;
1743
1744 break;
1745 }
1746 }
1747 }
1748
1749 if (list == null) {
1750 StringBundler query = null;
1751
1752 if (orderByComparator != null) {
1753 query = new StringBundler(3 +
1754 (orderByComparator.getOrderByFields().length * 3));
1755 }
1756 else {
1757 query = new StringBundler(3);
1758 }
1759
1760 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1761
1762 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1763
1764 if (orderByComparator != null) {
1765 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1766 orderByComparator);
1767 }
1768 else
1769 if (pagination) {
1770 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
1771 }
1772
1773 String sql = query.toString();
1774
1775 Session session = null;
1776
1777 try {
1778 session = openSession();
1779
1780 Query q = session.createQuery(sql);
1781
1782 QueryPos qPos = QueryPos.getInstance(q);
1783
1784 qPos.add(userId1);
1785
1786 if (!pagination) {
1787 list = (List<SocialRelation>)QueryUtil.list(q,
1788 getDialect(), start, end, false);
1789
1790 Collections.sort(list);
1791
1792 list = Collections.unmodifiableList(list);
1793 }
1794 else {
1795 list = (List<SocialRelation>)QueryUtil.list(q,
1796 getDialect(), start, end);
1797 }
1798
1799 cacheResult(list);
1800
1801 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1802 }
1803 catch (Exception e) {
1804 FinderCacheUtil.removeResult(finderPath, finderArgs);
1805
1806 throw processException(e);
1807 }
1808 finally {
1809 closeSession(session);
1810 }
1811 }
1812
1813 return list;
1814 }
1815
1816
1824 @Override
1825 public SocialRelation findByUserId1_First(long userId1,
1826 OrderByComparator<SocialRelation> orderByComparator)
1827 throws NoSuchRelationException {
1828 SocialRelation socialRelation = fetchByUserId1_First(userId1,
1829 orderByComparator);
1830
1831 if (socialRelation != null) {
1832 return socialRelation;
1833 }
1834
1835 StringBundler msg = new StringBundler(4);
1836
1837 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1838
1839 msg.append("userId1=");
1840 msg.append(userId1);
1841
1842 msg.append(StringPool.CLOSE_CURLY_BRACE);
1843
1844 throw new NoSuchRelationException(msg.toString());
1845 }
1846
1847
1854 @Override
1855 public SocialRelation fetchByUserId1_First(long userId1,
1856 OrderByComparator<SocialRelation> orderByComparator) {
1857 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1858 orderByComparator);
1859
1860 if (!list.isEmpty()) {
1861 return list.get(0);
1862 }
1863
1864 return null;
1865 }
1866
1867
1875 @Override
1876 public SocialRelation findByUserId1_Last(long userId1,
1877 OrderByComparator<SocialRelation> orderByComparator)
1878 throws NoSuchRelationException {
1879 SocialRelation socialRelation = fetchByUserId1_Last(userId1,
1880 orderByComparator);
1881
1882 if (socialRelation != null) {
1883 return socialRelation;
1884 }
1885
1886 StringBundler msg = new StringBundler(4);
1887
1888 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1889
1890 msg.append("userId1=");
1891 msg.append(userId1);
1892
1893 msg.append(StringPool.CLOSE_CURLY_BRACE);
1894
1895 throw new NoSuchRelationException(msg.toString());
1896 }
1897
1898
1905 @Override
1906 public SocialRelation fetchByUserId1_Last(long userId1,
1907 OrderByComparator<SocialRelation> orderByComparator) {
1908 int count = countByUserId1(userId1);
1909
1910 if (count == 0) {
1911 return null;
1912 }
1913
1914 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1915 orderByComparator);
1916
1917 if (!list.isEmpty()) {
1918 return list.get(0);
1919 }
1920
1921 return null;
1922 }
1923
1924
1933 @Override
1934 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1935 long userId1, OrderByComparator<SocialRelation> orderByComparator)
1936 throws NoSuchRelationException {
1937 SocialRelation socialRelation = findByPrimaryKey(relationId);
1938
1939 Session session = null;
1940
1941 try {
1942 session = openSession();
1943
1944 SocialRelation[] array = new SocialRelationImpl[3];
1945
1946 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1947 userId1, orderByComparator, true);
1948
1949 array[1] = socialRelation;
1950
1951 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1952 userId1, orderByComparator, false);
1953
1954 return array;
1955 }
1956 catch (Exception e) {
1957 throw processException(e);
1958 }
1959 finally {
1960 closeSession(session);
1961 }
1962 }
1963
1964 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1965 SocialRelation socialRelation, long userId1,
1966 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
1967 StringBundler query = null;
1968
1969 if (orderByComparator != null) {
1970 query = new StringBundler(6 +
1971 (orderByComparator.getOrderByFields().length * 6));
1972 }
1973 else {
1974 query = new StringBundler(3);
1975 }
1976
1977 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1978
1979 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1980
1981 if (orderByComparator != null) {
1982 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1983
1984 if (orderByConditionFields.length > 0) {
1985 query.append(WHERE_AND);
1986 }
1987
1988 for (int i = 0; i < orderByConditionFields.length; i++) {
1989 query.append(_ORDER_BY_ENTITY_ALIAS);
1990 query.append(orderByConditionFields[i]);
1991
1992 if ((i + 1) < orderByConditionFields.length) {
1993 if (orderByComparator.isAscending() ^ previous) {
1994 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1995 }
1996 else {
1997 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1998 }
1999 }
2000 else {
2001 if (orderByComparator.isAscending() ^ previous) {
2002 query.append(WHERE_GREATER_THAN);
2003 }
2004 else {
2005 query.append(WHERE_LESSER_THAN);
2006 }
2007 }
2008 }
2009
2010 query.append(ORDER_BY_CLAUSE);
2011
2012 String[] orderByFields = orderByComparator.getOrderByFields();
2013
2014 for (int i = 0; i < orderByFields.length; i++) {
2015 query.append(_ORDER_BY_ENTITY_ALIAS);
2016 query.append(orderByFields[i]);
2017
2018 if ((i + 1) < orderByFields.length) {
2019 if (orderByComparator.isAscending() ^ previous) {
2020 query.append(ORDER_BY_ASC_HAS_NEXT);
2021 }
2022 else {
2023 query.append(ORDER_BY_DESC_HAS_NEXT);
2024 }
2025 }
2026 else {
2027 if (orderByComparator.isAscending() ^ previous) {
2028 query.append(ORDER_BY_ASC);
2029 }
2030 else {
2031 query.append(ORDER_BY_DESC);
2032 }
2033 }
2034 }
2035 }
2036 else {
2037 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2038 }
2039
2040 String sql = query.toString();
2041
2042 Query q = session.createQuery(sql);
2043
2044 q.setFirstResult(0);
2045 q.setMaxResults(2);
2046
2047 QueryPos qPos = QueryPos.getInstance(q);
2048
2049 qPos.add(userId1);
2050
2051 if (orderByComparator != null) {
2052 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2053
2054 for (Object value : values) {
2055 qPos.add(value);
2056 }
2057 }
2058
2059 List<SocialRelation> list = q.list();
2060
2061 if (list.size() == 2) {
2062 return list.get(1);
2063 }
2064 else {
2065 return null;
2066 }
2067 }
2068
2069
2074 @Override
2075 public void removeByUserId1(long userId1) {
2076 for (SocialRelation socialRelation : findByUserId1(userId1,
2077 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2078 remove(socialRelation);
2079 }
2080 }
2081
2082
2088 @Override
2089 public int countByUserId1(long userId1) {
2090 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID1;
2091
2092 Object[] finderArgs = new Object[] { userId1 };
2093
2094 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2095 this);
2096
2097 if (count == null) {
2098 StringBundler query = new StringBundler(2);
2099
2100 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2101
2102 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
2103
2104 String sql = query.toString();
2105
2106 Session session = null;
2107
2108 try {
2109 session = openSession();
2110
2111 Query q = session.createQuery(sql);
2112
2113 QueryPos qPos = QueryPos.getInstance(q);
2114
2115 qPos.add(userId1);
2116
2117 count = (Long)q.uniqueResult();
2118
2119 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2120 }
2121 catch (Exception e) {
2122 FinderCacheUtil.removeResult(finderPath, finderArgs);
2123
2124 throw processException(e);
2125 }
2126 finally {
2127 closeSession(session);
2128 }
2129 }
2130
2131 return count.intValue();
2132 }
2133
2134 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
2135 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2136 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2137 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2138 "findByUserId2",
2139 new String[] {
2140 Long.class.getName(),
2141
2142 Integer.class.getName(), Integer.class.getName(),
2143 OrderByComparator.class.getName()
2144 });
2145 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2 =
2146 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2147 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2148 SocialRelationImpl.class,
2149 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId2",
2150 new String[] { Long.class.getName() },
2151 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
2152 public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2153 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2154 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId2",
2155 new String[] { Long.class.getName() });
2156
2157
2163 @Override
2164 public List<SocialRelation> findByUserId2(long userId2) {
2165 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2166 }
2167
2168
2180 @Override
2181 public List<SocialRelation> findByUserId2(long userId2, int start, int end) {
2182 return findByUserId2(userId2, start, end, null);
2183 }
2184
2185
2198 @Override
2199 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
2200 OrderByComparator<SocialRelation> orderByComparator) {
2201 boolean pagination = true;
2202 FinderPath finderPath = null;
2203 Object[] finderArgs = null;
2204
2205 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2206 (orderByComparator == null)) {
2207 pagination = false;
2208 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
2209 finderArgs = new Object[] { userId2 };
2210 }
2211 else {
2212 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
2213 finderArgs = new Object[] { userId2, start, end, orderByComparator };
2214 }
2215
2216 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2217 finderArgs, this);
2218
2219 if ((list != null) && !list.isEmpty()) {
2220 for (SocialRelation socialRelation : list) {
2221 if ((userId2 != socialRelation.getUserId2())) {
2222 list = null;
2223
2224 break;
2225 }
2226 }
2227 }
2228
2229 if (list == null) {
2230 StringBundler query = null;
2231
2232 if (orderByComparator != null) {
2233 query = new StringBundler(3 +
2234 (orderByComparator.getOrderByFields().length * 3));
2235 }
2236 else {
2237 query = new StringBundler(3);
2238 }
2239
2240 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2241
2242 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2243
2244 if (orderByComparator != null) {
2245 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2246 orderByComparator);
2247 }
2248 else
2249 if (pagination) {
2250 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2251 }
2252
2253 String sql = query.toString();
2254
2255 Session session = null;
2256
2257 try {
2258 session = openSession();
2259
2260 Query q = session.createQuery(sql);
2261
2262 QueryPos qPos = QueryPos.getInstance(q);
2263
2264 qPos.add(userId2);
2265
2266 if (!pagination) {
2267 list = (List<SocialRelation>)QueryUtil.list(q,
2268 getDialect(), start, end, false);
2269
2270 Collections.sort(list);
2271
2272 list = Collections.unmodifiableList(list);
2273 }
2274 else {
2275 list = (List<SocialRelation>)QueryUtil.list(q,
2276 getDialect(), start, end);
2277 }
2278
2279 cacheResult(list);
2280
2281 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2282 }
2283 catch (Exception e) {
2284 FinderCacheUtil.removeResult(finderPath, finderArgs);
2285
2286 throw processException(e);
2287 }
2288 finally {
2289 closeSession(session);
2290 }
2291 }
2292
2293 return list;
2294 }
2295
2296
2304 @Override
2305 public SocialRelation findByUserId2_First(long userId2,
2306 OrderByComparator<SocialRelation> orderByComparator)
2307 throws NoSuchRelationException {
2308 SocialRelation socialRelation = fetchByUserId2_First(userId2,
2309 orderByComparator);
2310
2311 if (socialRelation != null) {
2312 return socialRelation;
2313 }
2314
2315 StringBundler msg = new StringBundler(4);
2316
2317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2318
2319 msg.append("userId2=");
2320 msg.append(userId2);
2321
2322 msg.append(StringPool.CLOSE_CURLY_BRACE);
2323
2324 throw new NoSuchRelationException(msg.toString());
2325 }
2326
2327
2334 @Override
2335 public SocialRelation fetchByUserId2_First(long userId2,
2336 OrderByComparator<SocialRelation> orderByComparator) {
2337 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2338 orderByComparator);
2339
2340 if (!list.isEmpty()) {
2341 return list.get(0);
2342 }
2343
2344 return null;
2345 }
2346
2347
2355 @Override
2356 public SocialRelation findByUserId2_Last(long userId2,
2357 OrderByComparator<SocialRelation> orderByComparator)
2358 throws NoSuchRelationException {
2359 SocialRelation socialRelation = fetchByUserId2_Last(userId2,
2360 orderByComparator);
2361
2362 if (socialRelation != null) {
2363 return socialRelation;
2364 }
2365
2366 StringBundler msg = new StringBundler(4);
2367
2368 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2369
2370 msg.append("userId2=");
2371 msg.append(userId2);
2372
2373 msg.append(StringPool.CLOSE_CURLY_BRACE);
2374
2375 throw new NoSuchRelationException(msg.toString());
2376 }
2377
2378
2385 @Override
2386 public SocialRelation fetchByUserId2_Last(long userId2,
2387 OrderByComparator<SocialRelation> orderByComparator) {
2388 int count = countByUserId2(userId2);
2389
2390 if (count == 0) {
2391 return null;
2392 }
2393
2394 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2395 orderByComparator);
2396
2397 if (!list.isEmpty()) {
2398 return list.get(0);
2399 }
2400
2401 return null;
2402 }
2403
2404
2413 @Override
2414 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2415 long userId2, OrderByComparator<SocialRelation> orderByComparator)
2416 throws NoSuchRelationException {
2417 SocialRelation socialRelation = findByPrimaryKey(relationId);
2418
2419 Session session = null;
2420
2421 try {
2422 session = openSession();
2423
2424 SocialRelation[] array = new SocialRelationImpl[3];
2425
2426 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2427 userId2, orderByComparator, true);
2428
2429 array[1] = socialRelation;
2430
2431 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2432 userId2, orderByComparator, false);
2433
2434 return array;
2435 }
2436 catch (Exception e) {
2437 throw processException(e);
2438 }
2439 finally {
2440 closeSession(session);
2441 }
2442 }
2443
2444 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2445 SocialRelation socialRelation, long userId2,
2446 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
2447 StringBundler query = null;
2448
2449 if (orderByComparator != null) {
2450 query = new StringBundler(6 +
2451 (orderByComparator.getOrderByFields().length * 6));
2452 }
2453 else {
2454 query = new StringBundler(3);
2455 }
2456
2457 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2458
2459 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2460
2461 if (orderByComparator != null) {
2462 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2463
2464 if (orderByConditionFields.length > 0) {
2465 query.append(WHERE_AND);
2466 }
2467
2468 for (int i = 0; i < orderByConditionFields.length; i++) {
2469 query.append(_ORDER_BY_ENTITY_ALIAS);
2470 query.append(orderByConditionFields[i]);
2471
2472 if ((i + 1) < orderByConditionFields.length) {
2473 if (orderByComparator.isAscending() ^ previous) {
2474 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2475 }
2476 else {
2477 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2478 }
2479 }
2480 else {
2481 if (orderByComparator.isAscending() ^ previous) {
2482 query.append(WHERE_GREATER_THAN);
2483 }
2484 else {
2485 query.append(WHERE_LESSER_THAN);
2486 }
2487 }
2488 }
2489
2490 query.append(ORDER_BY_CLAUSE);
2491
2492 String[] orderByFields = orderByComparator.getOrderByFields();
2493
2494 for (int i = 0; i < orderByFields.length; i++) {
2495 query.append(_ORDER_BY_ENTITY_ALIAS);
2496 query.append(orderByFields[i]);
2497
2498 if ((i + 1) < orderByFields.length) {
2499 if (orderByComparator.isAscending() ^ previous) {
2500 query.append(ORDER_BY_ASC_HAS_NEXT);
2501 }
2502 else {
2503 query.append(ORDER_BY_DESC_HAS_NEXT);
2504 }
2505 }
2506 else {
2507 if (orderByComparator.isAscending() ^ previous) {
2508 query.append(ORDER_BY_ASC);
2509 }
2510 else {
2511 query.append(ORDER_BY_DESC);
2512 }
2513 }
2514 }
2515 }
2516 else {
2517 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2518 }
2519
2520 String sql = query.toString();
2521
2522 Query q = session.createQuery(sql);
2523
2524 q.setFirstResult(0);
2525 q.setMaxResults(2);
2526
2527 QueryPos qPos = QueryPos.getInstance(q);
2528
2529 qPos.add(userId2);
2530
2531 if (orderByComparator != null) {
2532 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2533
2534 for (Object value : values) {
2535 qPos.add(value);
2536 }
2537 }
2538
2539 List<SocialRelation> list = q.list();
2540
2541 if (list.size() == 2) {
2542 return list.get(1);
2543 }
2544 else {
2545 return null;
2546 }
2547 }
2548
2549
2554 @Override
2555 public void removeByUserId2(long userId2) {
2556 for (SocialRelation socialRelation : findByUserId2(userId2,
2557 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2558 remove(socialRelation);
2559 }
2560 }
2561
2562
2568 @Override
2569 public int countByUserId2(long userId2) {
2570 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID2;
2571
2572 Object[] finderArgs = new Object[] { userId2 };
2573
2574 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2575 this);
2576
2577 if (count == null) {
2578 StringBundler query = new StringBundler(2);
2579
2580 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2581
2582 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2583
2584 String sql = query.toString();
2585
2586 Session session = null;
2587
2588 try {
2589 session = openSession();
2590
2591 Query q = session.createQuery(sql);
2592
2593 QueryPos qPos = QueryPos.getInstance(q);
2594
2595 qPos.add(userId2);
2596
2597 count = (Long)q.uniqueResult();
2598
2599 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2600 }
2601 catch (Exception e) {
2602 FinderCacheUtil.removeResult(finderPath, finderArgs);
2603
2604 throw processException(e);
2605 }
2606 finally {
2607 closeSession(session);
2608 }
2609 }
2610
2611 return count.intValue();
2612 }
2613
2614 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
2615 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2616 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2617 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2618 "findByType",
2619 new String[] {
2620 Integer.class.getName(),
2621
2622 Integer.class.getName(), Integer.class.getName(),
2623 OrderByComparator.class.getName()
2624 });
2625 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2626 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
2627 SocialRelationImpl.class,
2628 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
2629 new String[] { Integer.class.getName() },
2630 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
2631 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
2632 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2633 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
2634 new String[] { Integer.class.getName() });
2635
2636
2642 @Override
2643 public List<SocialRelation> findByType(int type) {
2644 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2645 }
2646
2647
2659 @Override
2660 public List<SocialRelation> findByType(int type, int start, int end) {
2661 return findByType(type, start, end, null);
2662 }
2663
2664
2677 @Override
2678 public List<SocialRelation> findByType(int type, int start, int end,
2679 OrderByComparator<SocialRelation> orderByComparator) {
2680 boolean pagination = true;
2681 FinderPath finderPath = null;
2682 Object[] finderArgs = null;
2683
2684 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2685 (orderByComparator == null)) {
2686 pagination = false;
2687 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2688 finderArgs = new Object[] { type };
2689 }
2690 else {
2691 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2692 finderArgs = new Object[] { type, start, end, orderByComparator };
2693 }
2694
2695 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2696 finderArgs, this);
2697
2698 if ((list != null) && !list.isEmpty()) {
2699 for (SocialRelation socialRelation : list) {
2700 if ((type != socialRelation.getType())) {
2701 list = null;
2702
2703 break;
2704 }
2705 }
2706 }
2707
2708 if (list == null) {
2709 StringBundler query = null;
2710
2711 if (orderByComparator != null) {
2712 query = new StringBundler(3 +
2713 (orderByComparator.getOrderByFields().length * 3));
2714 }
2715 else {
2716 query = new StringBundler(3);
2717 }
2718
2719 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2720
2721 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2722
2723 if (orderByComparator != null) {
2724 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2725 orderByComparator);
2726 }
2727 else
2728 if (pagination) {
2729 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2730 }
2731
2732 String sql = query.toString();
2733
2734 Session session = null;
2735
2736 try {
2737 session = openSession();
2738
2739 Query q = session.createQuery(sql);
2740
2741 QueryPos qPos = QueryPos.getInstance(q);
2742
2743 qPos.add(type);
2744
2745 if (!pagination) {
2746 list = (List<SocialRelation>)QueryUtil.list(q,
2747 getDialect(), start, end, false);
2748
2749 Collections.sort(list);
2750
2751 list = Collections.unmodifiableList(list);
2752 }
2753 else {
2754 list = (List<SocialRelation>)QueryUtil.list(q,
2755 getDialect(), start, end);
2756 }
2757
2758 cacheResult(list);
2759
2760 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2761 }
2762 catch (Exception e) {
2763 FinderCacheUtil.removeResult(finderPath, finderArgs);
2764
2765 throw processException(e);
2766 }
2767 finally {
2768 closeSession(session);
2769 }
2770 }
2771
2772 return list;
2773 }
2774
2775
2783 @Override
2784 public SocialRelation findByType_First(int type,
2785 OrderByComparator<SocialRelation> orderByComparator)
2786 throws NoSuchRelationException {
2787 SocialRelation socialRelation = fetchByType_First(type,
2788 orderByComparator);
2789
2790 if (socialRelation != null) {
2791 return socialRelation;
2792 }
2793
2794 StringBundler msg = new StringBundler(4);
2795
2796 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2797
2798 msg.append("type=");
2799 msg.append(type);
2800
2801 msg.append(StringPool.CLOSE_CURLY_BRACE);
2802
2803 throw new NoSuchRelationException(msg.toString());
2804 }
2805
2806
2813 @Override
2814 public SocialRelation fetchByType_First(int type,
2815 OrderByComparator<SocialRelation> orderByComparator) {
2816 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2817
2818 if (!list.isEmpty()) {
2819 return list.get(0);
2820 }
2821
2822 return null;
2823 }
2824
2825
2833 @Override
2834 public SocialRelation findByType_Last(int type,
2835 OrderByComparator<SocialRelation> orderByComparator)
2836 throws NoSuchRelationException {
2837 SocialRelation socialRelation = fetchByType_Last(type, orderByComparator);
2838
2839 if (socialRelation != null) {
2840 return socialRelation;
2841 }
2842
2843 StringBundler msg = new StringBundler(4);
2844
2845 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2846
2847 msg.append("type=");
2848 msg.append(type);
2849
2850 msg.append(StringPool.CLOSE_CURLY_BRACE);
2851
2852 throw new NoSuchRelationException(msg.toString());
2853 }
2854
2855
2862 @Override
2863 public SocialRelation fetchByType_Last(int type,
2864 OrderByComparator<SocialRelation> orderByComparator) {
2865 int count = countByType(type);
2866
2867 if (count == 0) {
2868 return null;
2869 }
2870
2871 List<SocialRelation> list = findByType(type, count - 1, count,
2872 orderByComparator);
2873
2874 if (!list.isEmpty()) {
2875 return list.get(0);
2876 }
2877
2878 return null;
2879 }
2880
2881
2890 @Override
2891 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2892 OrderByComparator<SocialRelation> orderByComparator)
2893 throws NoSuchRelationException {
2894 SocialRelation socialRelation = findByPrimaryKey(relationId);
2895
2896 Session session = null;
2897
2898 try {
2899 session = openSession();
2900
2901 SocialRelation[] array = new SocialRelationImpl[3];
2902
2903 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2904 orderByComparator, true);
2905
2906 array[1] = socialRelation;
2907
2908 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2909 orderByComparator, false);
2910
2911 return array;
2912 }
2913 catch (Exception e) {
2914 throw processException(e);
2915 }
2916 finally {
2917 closeSession(session);
2918 }
2919 }
2920
2921 protected SocialRelation getByType_PrevAndNext(Session session,
2922 SocialRelation socialRelation, int type,
2923 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
2924 StringBundler query = null;
2925
2926 if (orderByComparator != null) {
2927 query = new StringBundler(6 +
2928 (orderByComparator.getOrderByFields().length * 6));
2929 }
2930 else {
2931 query = new StringBundler(3);
2932 }
2933
2934 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2935
2936 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2937
2938 if (orderByComparator != null) {
2939 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2940
2941 if (orderByConditionFields.length > 0) {
2942 query.append(WHERE_AND);
2943 }
2944
2945 for (int i = 0; i < orderByConditionFields.length; i++) {
2946 query.append(_ORDER_BY_ENTITY_ALIAS);
2947 query.append(orderByConditionFields[i]);
2948
2949 if ((i + 1) < orderByConditionFields.length) {
2950 if (orderByComparator.isAscending() ^ previous) {
2951 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2952 }
2953 else {
2954 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2955 }
2956 }
2957 else {
2958 if (orderByComparator.isAscending() ^ previous) {
2959 query.append(WHERE_GREATER_THAN);
2960 }
2961 else {
2962 query.append(WHERE_LESSER_THAN);
2963 }
2964 }
2965 }
2966
2967 query.append(ORDER_BY_CLAUSE);
2968
2969 String[] orderByFields = orderByComparator.getOrderByFields();
2970
2971 for (int i = 0; i < orderByFields.length; i++) {
2972 query.append(_ORDER_BY_ENTITY_ALIAS);
2973 query.append(orderByFields[i]);
2974
2975 if ((i + 1) < orderByFields.length) {
2976 if (orderByComparator.isAscending() ^ previous) {
2977 query.append(ORDER_BY_ASC_HAS_NEXT);
2978 }
2979 else {
2980 query.append(ORDER_BY_DESC_HAS_NEXT);
2981 }
2982 }
2983 else {
2984 if (orderByComparator.isAscending() ^ previous) {
2985 query.append(ORDER_BY_ASC);
2986 }
2987 else {
2988 query.append(ORDER_BY_DESC);
2989 }
2990 }
2991 }
2992 }
2993 else {
2994 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
2995 }
2996
2997 String sql = query.toString();
2998
2999 Query q = session.createQuery(sql);
3000
3001 q.setFirstResult(0);
3002 q.setMaxResults(2);
3003
3004 QueryPos qPos = QueryPos.getInstance(q);
3005
3006 qPos.add(type);
3007
3008 if (orderByComparator != null) {
3009 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3010
3011 for (Object value : values) {
3012 qPos.add(value);
3013 }
3014 }
3015
3016 List<SocialRelation> list = q.list();
3017
3018 if (list.size() == 2) {
3019 return list.get(1);
3020 }
3021 else {
3022 return null;
3023 }
3024 }
3025
3026
3031 @Override
3032 public void removeByType(int type) {
3033 for (SocialRelation socialRelation : findByType(type,
3034 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3035 remove(socialRelation);
3036 }
3037 }
3038
3039
3045 @Override
3046 public int countByType(int type) {
3047 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
3048
3049 Object[] finderArgs = new Object[] { type };
3050
3051 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3052 this);
3053
3054 if (count == null) {
3055 StringBundler query = new StringBundler(2);
3056
3057 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3058
3059 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3060
3061 String sql = query.toString();
3062
3063 Session session = null;
3064
3065 try {
3066 session = openSession();
3067
3068 Query q = session.createQuery(sql);
3069
3070 QueryPos qPos = QueryPos.getInstance(q);
3071
3072 qPos.add(type);
3073
3074 count = (Long)q.uniqueResult();
3075
3076 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3077 }
3078 catch (Exception e) {
3079 FinderCacheUtil.removeResult(finderPath, finderArgs);
3080
3081 throw processException(e);
3082 }
3083 finally {
3084 closeSession(session);
3085 }
3086 }
3087
3088 return count.intValue();
3089 }
3090
3091 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
3092 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3093 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3094 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3095 "findByC_T",
3096 new String[] {
3097 Long.class.getName(), Integer.class.getName(),
3098
3099 Integer.class.getName(), Integer.class.getName(),
3100 OrderByComparator.class.getName()
3101 });
3102 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3103 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3104 SocialRelationImpl.class,
3105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
3106 new String[] { Long.class.getName(), Integer.class.getName() },
3107 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK |
3108 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
3109 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3110 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
3112 new String[] { Long.class.getName(), Integer.class.getName() });
3113
3114
3121 @Override
3122 public List<SocialRelation> findByC_T(long companyId, int type) {
3123 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3124 null);
3125 }
3126
3127
3140 @Override
3141 public List<SocialRelation> findByC_T(long companyId, int type, int start,
3142 int end) {
3143 return findByC_T(companyId, type, start, end, null);
3144 }
3145
3146
3160 @Override
3161 public List<SocialRelation> findByC_T(long companyId, int type, int start,
3162 int end, OrderByComparator<SocialRelation> orderByComparator) {
3163 boolean pagination = true;
3164 FinderPath finderPath = null;
3165 Object[] finderArgs = null;
3166
3167 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3168 (orderByComparator == null)) {
3169 pagination = false;
3170 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
3171 finderArgs = new Object[] { companyId, type };
3172 }
3173 else {
3174 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
3175 finderArgs = new Object[] {
3176 companyId, type,
3177
3178 start, end, orderByComparator
3179 };
3180 }
3181
3182 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3183 finderArgs, this);
3184
3185 if ((list != null) && !list.isEmpty()) {
3186 for (SocialRelation socialRelation : list) {
3187 if ((companyId != socialRelation.getCompanyId()) ||
3188 (type != socialRelation.getType())) {
3189 list = null;
3190
3191 break;
3192 }
3193 }
3194 }
3195
3196 if (list == null) {
3197 StringBundler query = null;
3198
3199 if (orderByComparator != null) {
3200 query = new StringBundler(4 +
3201 (orderByComparator.getOrderByFields().length * 3));
3202 }
3203 else {
3204 query = new StringBundler(4);
3205 }
3206
3207 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3208
3209 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3210
3211 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3212
3213 if (orderByComparator != null) {
3214 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3215 orderByComparator);
3216 }
3217 else
3218 if (pagination) {
3219 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3220 }
3221
3222 String sql = query.toString();
3223
3224 Session session = null;
3225
3226 try {
3227 session = openSession();
3228
3229 Query q = session.createQuery(sql);
3230
3231 QueryPos qPos = QueryPos.getInstance(q);
3232
3233 qPos.add(companyId);
3234
3235 qPos.add(type);
3236
3237 if (!pagination) {
3238 list = (List<SocialRelation>)QueryUtil.list(q,
3239 getDialect(), start, end, false);
3240
3241 Collections.sort(list);
3242
3243 list = Collections.unmodifiableList(list);
3244 }
3245 else {
3246 list = (List<SocialRelation>)QueryUtil.list(q,
3247 getDialect(), start, end);
3248 }
3249
3250 cacheResult(list);
3251
3252 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3253 }
3254 catch (Exception e) {
3255 FinderCacheUtil.removeResult(finderPath, finderArgs);
3256
3257 throw processException(e);
3258 }
3259 finally {
3260 closeSession(session);
3261 }
3262 }
3263
3264 return list;
3265 }
3266
3267
3276 @Override
3277 public SocialRelation findByC_T_First(long companyId, int type,
3278 OrderByComparator<SocialRelation> orderByComparator)
3279 throws NoSuchRelationException {
3280 SocialRelation socialRelation = fetchByC_T_First(companyId, type,
3281 orderByComparator);
3282
3283 if (socialRelation != null) {
3284 return socialRelation;
3285 }
3286
3287 StringBundler msg = new StringBundler(6);
3288
3289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3290
3291 msg.append("companyId=");
3292 msg.append(companyId);
3293
3294 msg.append(", type=");
3295 msg.append(type);
3296
3297 msg.append(StringPool.CLOSE_CURLY_BRACE);
3298
3299 throw new NoSuchRelationException(msg.toString());
3300 }
3301
3302
3310 @Override
3311 public SocialRelation fetchByC_T_First(long companyId, int type,
3312 OrderByComparator<SocialRelation> orderByComparator) {
3313 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
3314 orderByComparator);
3315
3316 if (!list.isEmpty()) {
3317 return list.get(0);
3318 }
3319
3320 return null;
3321 }
3322
3323
3332 @Override
3333 public SocialRelation findByC_T_Last(long companyId, int type,
3334 OrderByComparator<SocialRelation> orderByComparator)
3335 throws NoSuchRelationException {
3336 SocialRelation socialRelation = fetchByC_T_Last(companyId, type,
3337 orderByComparator);
3338
3339 if (socialRelation != null) {
3340 return socialRelation;
3341 }
3342
3343 StringBundler msg = new StringBundler(6);
3344
3345 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3346
3347 msg.append("companyId=");
3348 msg.append(companyId);
3349
3350 msg.append(", type=");
3351 msg.append(type);
3352
3353 msg.append(StringPool.CLOSE_CURLY_BRACE);
3354
3355 throw new NoSuchRelationException(msg.toString());
3356 }
3357
3358
3366 @Override
3367 public SocialRelation fetchByC_T_Last(long companyId, int type,
3368 OrderByComparator<SocialRelation> orderByComparator) {
3369 int count = countByC_T(companyId, type);
3370
3371 if (count == 0) {
3372 return null;
3373 }
3374
3375 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
3376 count, orderByComparator);
3377
3378 if (!list.isEmpty()) {
3379 return list.get(0);
3380 }
3381
3382 return null;
3383 }
3384
3385
3395 @Override
3396 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
3397 long companyId, int type,
3398 OrderByComparator<SocialRelation> orderByComparator)
3399 throws NoSuchRelationException {
3400 SocialRelation socialRelation = findByPrimaryKey(relationId);
3401
3402 Session session = null;
3403
3404 try {
3405 session = openSession();
3406
3407 SocialRelation[] array = new SocialRelationImpl[3];
3408
3409 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3410 type, orderByComparator, true);
3411
3412 array[1] = socialRelation;
3413
3414 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3415 type, orderByComparator, false);
3416
3417 return array;
3418 }
3419 catch (Exception e) {
3420 throw processException(e);
3421 }
3422 finally {
3423 closeSession(session);
3424 }
3425 }
3426
3427 protected SocialRelation getByC_T_PrevAndNext(Session session,
3428 SocialRelation socialRelation, long companyId, int type,
3429 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
3430 StringBundler query = null;
3431
3432 if (orderByComparator != null) {
3433 query = new StringBundler(6 +
3434 (orderByComparator.getOrderByFields().length * 6));
3435 }
3436 else {
3437 query = new StringBundler(3);
3438 }
3439
3440 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3441
3442 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3443
3444 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3445
3446 if (orderByComparator != null) {
3447 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3448
3449 if (orderByConditionFields.length > 0) {
3450 query.append(WHERE_AND);
3451 }
3452
3453 for (int i = 0; i < orderByConditionFields.length; i++) {
3454 query.append(_ORDER_BY_ENTITY_ALIAS);
3455 query.append(orderByConditionFields[i]);
3456
3457 if ((i + 1) < orderByConditionFields.length) {
3458 if (orderByComparator.isAscending() ^ previous) {
3459 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3460 }
3461 else {
3462 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3463 }
3464 }
3465 else {
3466 if (orderByComparator.isAscending() ^ previous) {
3467 query.append(WHERE_GREATER_THAN);
3468 }
3469 else {
3470 query.append(WHERE_LESSER_THAN);
3471 }
3472 }
3473 }
3474
3475 query.append(ORDER_BY_CLAUSE);
3476
3477 String[] orderByFields = orderByComparator.getOrderByFields();
3478
3479 for (int i = 0; i < orderByFields.length; i++) {
3480 query.append(_ORDER_BY_ENTITY_ALIAS);
3481 query.append(orderByFields[i]);
3482
3483 if ((i + 1) < orderByFields.length) {
3484 if (orderByComparator.isAscending() ^ previous) {
3485 query.append(ORDER_BY_ASC_HAS_NEXT);
3486 }
3487 else {
3488 query.append(ORDER_BY_DESC_HAS_NEXT);
3489 }
3490 }
3491 else {
3492 if (orderByComparator.isAscending() ^ previous) {
3493 query.append(ORDER_BY_ASC);
3494 }
3495 else {
3496 query.append(ORDER_BY_DESC);
3497 }
3498 }
3499 }
3500 }
3501 else {
3502 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3503 }
3504
3505 String sql = query.toString();
3506
3507 Query q = session.createQuery(sql);
3508
3509 q.setFirstResult(0);
3510 q.setMaxResults(2);
3511
3512 QueryPos qPos = QueryPos.getInstance(q);
3513
3514 qPos.add(companyId);
3515
3516 qPos.add(type);
3517
3518 if (orderByComparator != null) {
3519 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3520
3521 for (Object value : values) {
3522 qPos.add(value);
3523 }
3524 }
3525
3526 List<SocialRelation> list = q.list();
3527
3528 if (list.size() == 2) {
3529 return list.get(1);
3530 }
3531 else {
3532 return null;
3533 }
3534 }
3535
3536
3542 @Override
3543 public void removeByC_T(long companyId, int type) {
3544 for (SocialRelation socialRelation : findByC_T(companyId, type,
3545 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3546 remove(socialRelation);
3547 }
3548 }
3549
3550
3557 @Override
3558 public int countByC_T(long companyId, int type) {
3559 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
3560
3561 Object[] finderArgs = new Object[] { companyId, type };
3562
3563 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3564 this);
3565
3566 if (count == null) {
3567 StringBundler query = new StringBundler(3);
3568
3569 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3570
3571 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3572
3573 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3574
3575 String sql = query.toString();
3576
3577 Session session = null;
3578
3579 try {
3580 session = openSession();
3581
3582 Query q = session.createQuery(sql);
3583
3584 QueryPos qPos = QueryPos.getInstance(q);
3585
3586 qPos.add(companyId);
3587
3588 qPos.add(type);
3589
3590 count = (Long)q.uniqueResult();
3591
3592 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3593 }
3594 catch (Exception e) {
3595 FinderCacheUtil.removeResult(finderPath, finderArgs);
3596
3597 throw processException(e);
3598 }
3599 finally {
3600 closeSession(session);
3601 }
3602 }
3603
3604 return count.intValue();
3605 }
3606
3607 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
3608 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
3609 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3610 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3611 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3612 "findByU1_U2",
3613 new String[] {
3614 Long.class.getName(), Long.class.getName(),
3615
3616 Integer.class.getName(), Integer.class.getName(),
3617 OrderByComparator.class.getName()
3618 });
3619 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3620 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
3621 SocialRelationImpl.class,
3622 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_U2",
3623 new String[] { Long.class.getName(), Long.class.getName() },
3624 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
3625 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
3626 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
3627 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3628 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2",
3629 new String[] { Long.class.getName(), Long.class.getName() });
3630
3631
3638 @Override
3639 public List<SocialRelation> findByU1_U2(long userId1, long userId2) {
3640 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
3641 QueryUtil.ALL_POS, null);
3642 }
3643
3644
3657 @Override
3658 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3659 int start, int end) {
3660 return findByU1_U2(userId1, userId2, start, end, null);
3661 }
3662
3663
3677 @Override
3678 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3679 int start, int end, OrderByComparator<SocialRelation> orderByComparator) {
3680 boolean pagination = true;
3681 FinderPath finderPath = null;
3682 Object[] finderArgs = null;
3683
3684 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3685 (orderByComparator == null)) {
3686 pagination = false;
3687 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3688 finderArgs = new Object[] { userId1, userId2 };
3689 }
3690 else {
3691 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3692 finderArgs = new Object[] {
3693 userId1, userId2,
3694
3695 start, end, orderByComparator
3696 };
3697 }
3698
3699 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3700 finderArgs, this);
3701
3702 if ((list != null) && !list.isEmpty()) {
3703 for (SocialRelation socialRelation : list) {
3704 if ((userId1 != socialRelation.getUserId1()) ||
3705 (userId2 != socialRelation.getUserId2())) {
3706 list = null;
3707
3708 break;
3709 }
3710 }
3711 }
3712
3713 if (list == null) {
3714 StringBundler query = null;
3715
3716 if (orderByComparator != null) {
3717 query = new StringBundler(4 +
3718 (orderByComparator.getOrderByFields().length * 3));
3719 }
3720 else {
3721 query = new StringBundler(4);
3722 }
3723
3724 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3725
3726 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3727
3728 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3729
3730 if (orderByComparator != null) {
3731 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3732 orderByComparator);
3733 }
3734 else
3735 if (pagination) {
3736 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
3737 }
3738
3739 String sql = query.toString();
3740
3741 Session session = null;
3742
3743 try {
3744 session = openSession();
3745
3746 Query q = session.createQuery(sql);
3747
3748 QueryPos qPos = QueryPos.getInstance(q);
3749
3750 qPos.add(userId1);
3751
3752 qPos.add(userId2);
3753
3754 if (!pagination) {
3755 list = (List<SocialRelation>)QueryUtil.list(q,
3756 getDialect(), start, end, false);
3757
3758 Collections.sort(list);
3759
3760 list = Collections.unmodifiableList(list);
3761 }
3762 else {
3763 list = (List<SocialRelation>)QueryUtil.list(q,
3764 getDialect(), start, end);
3765 }
3766
3767 cacheResult(list);
3768
3769 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3770 }
3771 catch (Exception e) {
3772 FinderCacheUtil.removeResult(finderPath, finderArgs);
3773
3774 throw processException(e);
3775 }
3776 finally {
3777 closeSession(session);
3778 }
3779 }
3780
3781 return list;
3782 }
3783
3784
3793 @Override
3794 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3795 OrderByComparator<SocialRelation> orderByComparator)
3796 throws NoSuchRelationException {
3797 SocialRelation socialRelation = fetchByU1_U2_First(userId1, userId2,
3798 orderByComparator);
3799
3800 if (socialRelation != null) {
3801 return socialRelation;
3802 }
3803
3804 StringBundler msg = new StringBundler(6);
3805
3806 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3807
3808 msg.append("userId1=");
3809 msg.append(userId1);
3810
3811 msg.append(", userId2=");
3812 msg.append(userId2);
3813
3814 msg.append(StringPool.CLOSE_CURLY_BRACE);
3815
3816 throw new NoSuchRelationException(msg.toString());
3817 }
3818
3819
3827 @Override
3828 public SocialRelation fetchByU1_U2_First(long userId1, long userId2,
3829 OrderByComparator<SocialRelation> orderByComparator) {
3830 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3831 orderByComparator);
3832
3833 if (!list.isEmpty()) {
3834 return list.get(0);
3835 }
3836
3837 return null;
3838 }
3839
3840
3849 @Override
3850 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3851 OrderByComparator<SocialRelation> orderByComparator)
3852 throws NoSuchRelationException {
3853 SocialRelation socialRelation = fetchByU1_U2_Last(userId1, userId2,
3854 orderByComparator);
3855
3856 if (socialRelation != null) {
3857 return socialRelation;
3858 }
3859
3860 StringBundler msg = new StringBundler(6);
3861
3862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3863
3864 msg.append("userId1=");
3865 msg.append(userId1);
3866
3867 msg.append(", userId2=");
3868 msg.append(userId2);
3869
3870 msg.append(StringPool.CLOSE_CURLY_BRACE);
3871
3872 throw new NoSuchRelationException(msg.toString());
3873 }
3874
3875
3883 @Override
3884 public SocialRelation fetchByU1_U2_Last(long userId1, long userId2,
3885 OrderByComparator<SocialRelation> orderByComparator) {
3886 int count = countByU1_U2(userId1, userId2);
3887
3888 if (count == 0) {
3889 return null;
3890 }
3891
3892 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3893 count, orderByComparator);
3894
3895 if (!list.isEmpty()) {
3896 return list.get(0);
3897 }
3898
3899 return null;
3900 }
3901
3902
3912 @Override
3913 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3914 long userId1, long userId2,
3915 OrderByComparator<SocialRelation> orderByComparator)
3916 throws NoSuchRelationException {
3917 SocialRelation socialRelation = findByPrimaryKey(relationId);
3918
3919 Session session = null;
3920
3921 try {
3922 session = openSession();
3923
3924 SocialRelation[] array = new SocialRelationImpl[3];
3925
3926 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3927 userId2, orderByComparator, true);
3928
3929 array[1] = socialRelation;
3930
3931 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3932 userId2, orderByComparator, false);
3933
3934 return array;
3935 }
3936 catch (Exception e) {
3937 throw processException(e);
3938 }
3939 finally {
3940 closeSession(session);
3941 }
3942 }
3943
3944 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3945 SocialRelation socialRelation, long userId1, long userId2,
3946 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
3947 StringBundler query = null;
3948
3949 if (orderByComparator != null) {
3950 query = new StringBundler(6 +
3951 (orderByComparator.getOrderByFields().length * 6));
3952 }
3953 else {
3954 query = new StringBundler(3);
3955 }
3956
3957 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3958
3959 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3960
3961 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3962
3963 if (orderByComparator != null) {
3964 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3965
3966 if (orderByConditionFields.length > 0) {
3967 query.append(WHERE_AND);
3968 }
3969
3970 for (int i = 0; i < orderByConditionFields.length; i++) {
3971 query.append(_ORDER_BY_ENTITY_ALIAS);
3972 query.append(orderByConditionFields[i]);
3973
3974 if ((i + 1) < orderByConditionFields.length) {
3975 if (orderByComparator.isAscending() ^ previous) {
3976 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3977 }
3978 else {
3979 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3980 }
3981 }
3982 else {
3983 if (orderByComparator.isAscending() ^ previous) {
3984 query.append(WHERE_GREATER_THAN);
3985 }
3986 else {
3987 query.append(WHERE_LESSER_THAN);
3988 }
3989 }
3990 }
3991
3992 query.append(ORDER_BY_CLAUSE);
3993
3994 String[] orderByFields = orderByComparator.getOrderByFields();
3995
3996 for (int i = 0; i < orderByFields.length; i++) {
3997 query.append(_ORDER_BY_ENTITY_ALIAS);
3998 query.append(orderByFields[i]);
3999
4000 if ((i + 1) < orderByFields.length) {
4001 if (orderByComparator.isAscending() ^ previous) {
4002 query.append(ORDER_BY_ASC_HAS_NEXT);
4003 }
4004 else {
4005 query.append(ORDER_BY_DESC_HAS_NEXT);
4006 }
4007 }
4008 else {
4009 if (orderByComparator.isAscending() ^ previous) {
4010 query.append(ORDER_BY_ASC);
4011 }
4012 else {
4013 query.append(ORDER_BY_DESC);
4014 }
4015 }
4016 }
4017 }
4018 else {
4019 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4020 }
4021
4022 String sql = query.toString();
4023
4024 Query q = session.createQuery(sql);
4025
4026 q.setFirstResult(0);
4027 q.setMaxResults(2);
4028
4029 QueryPos qPos = QueryPos.getInstance(q);
4030
4031 qPos.add(userId1);
4032
4033 qPos.add(userId2);
4034
4035 if (orderByComparator != null) {
4036 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4037
4038 for (Object value : values) {
4039 qPos.add(value);
4040 }
4041 }
4042
4043 List<SocialRelation> list = q.list();
4044
4045 if (list.size() == 2) {
4046 return list.get(1);
4047 }
4048 else {
4049 return null;
4050 }
4051 }
4052
4053
4059 @Override
4060 public void removeByU1_U2(long userId1, long userId2) {
4061 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2,
4062 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4063 remove(socialRelation);
4064 }
4065 }
4066
4067
4074 @Override
4075 public int countByU1_U2(long userId1, long userId2) {
4076 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_U2;
4077
4078 Object[] finderArgs = new Object[] { userId1, userId2 };
4079
4080 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4081 this);
4082
4083 if (count == null) {
4084 StringBundler query = new StringBundler(3);
4085
4086 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4087
4088 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
4089
4090 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
4091
4092 String sql = query.toString();
4093
4094 Session session = null;
4095
4096 try {
4097 session = openSession();
4098
4099 Query q = session.createQuery(sql);
4100
4101 QueryPos qPos = QueryPos.getInstance(q);
4102
4103 qPos.add(userId1);
4104
4105 qPos.add(userId2);
4106
4107 count = (Long)q.uniqueResult();
4108
4109 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4110 }
4111 catch (Exception e) {
4112 FinderCacheUtil.removeResult(finderPath, finderArgs);
4113
4114 throw processException(e);
4115 }
4116 finally {
4117 closeSession(session);
4118 }
4119 }
4120
4121 return count.intValue();
4122 }
4123
4124 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
4125 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
4126 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4127 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4128 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4129 "findByU1_T",
4130 new String[] {
4131 Long.class.getName(), Integer.class.getName(),
4132
4133 Integer.class.getName(), Integer.class.getName(),
4134 OrderByComparator.class.getName()
4135 });
4136 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4137 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4138 SocialRelationImpl.class,
4139 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_T",
4140 new String[] { Long.class.getName(), Integer.class.getName() },
4141 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
4142 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
4143 public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4144 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4145 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_T",
4146 new String[] { Long.class.getName(), Integer.class.getName() });
4147
4148
4155 @Override
4156 public List<SocialRelation> findByU1_T(long userId1, int type) {
4157 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4158 null);
4159 }
4160
4161
4174 @Override
4175 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
4176 int end) {
4177 return findByU1_T(userId1, type, start, end, null);
4178 }
4179
4180
4194 @Override
4195 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
4196 int end, OrderByComparator<SocialRelation> orderByComparator) {
4197 boolean pagination = true;
4198 FinderPath finderPath = null;
4199 Object[] finderArgs = null;
4200
4201 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4202 (orderByComparator == null)) {
4203 pagination = false;
4204 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
4205 finderArgs = new Object[] { userId1, type };
4206 }
4207 else {
4208 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
4209 finderArgs = new Object[] {
4210 userId1, type,
4211
4212 start, end, orderByComparator
4213 };
4214 }
4215
4216 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4217 finderArgs, this);
4218
4219 if ((list != null) && !list.isEmpty()) {
4220 for (SocialRelation socialRelation : list) {
4221 if ((userId1 != socialRelation.getUserId1()) ||
4222 (type != socialRelation.getType())) {
4223 list = null;
4224
4225 break;
4226 }
4227 }
4228 }
4229
4230 if (list == null) {
4231 StringBundler query = null;
4232
4233 if (orderByComparator != null) {
4234 query = new StringBundler(4 +
4235 (orderByComparator.getOrderByFields().length * 3));
4236 }
4237 else {
4238 query = new StringBundler(4);
4239 }
4240
4241 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4242
4243 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4244
4245 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4246
4247 if (orderByComparator != null) {
4248 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4249 orderByComparator);
4250 }
4251 else
4252 if (pagination) {
4253 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4254 }
4255
4256 String sql = query.toString();
4257
4258 Session session = null;
4259
4260 try {
4261 session = openSession();
4262
4263 Query q = session.createQuery(sql);
4264
4265 QueryPos qPos = QueryPos.getInstance(q);
4266
4267 qPos.add(userId1);
4268
4269 qPos.add(type);
4270
4271 if (!pagination) {
4272 list = (List<SocialRelation>)QueryUtil.list(q,
4273 getDialect(), start, end, false);
4274
4275 Collections.sort(list);
4276
4277 list = Collections.unmodifiableList(list);
4278 }
4279 else {
4280 list = (List<SocialRelation>)QueryUtil.list(q,
4281 getDialect(), start, end);
4282 }
4283
4284 cacheResult(list);
4285
4286 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4287 }
4288 catch (Exception e) {
4289 FinderCacheUtil.removeResult(finderPath, finderArgs);
4290
4291 throw processException(e);
4292 }
4293 finally {
4294 closeSession(session);
4295 }
4296 }
4297
4298 return list;
4299 }
4300
4301
4310 @Override
4311 public SocialRelation findByU1_T_First(long userId1, int type,
4312 OrderByComparator<SocialRelation> orderByComparator)
4313 throws NoSuchRelationException {
4314 SocialRelation socialRelation = fetchByU1_T_First(userId1, type,
4315 orderByComparator);
4316
4317 if (socialRelation != null) {
4318 return socialRelation;
4319 }
4320
4321 StringBundler msg = new StringBundler(6);
4322
4323 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4324
4325 msg.append("userId1=");
4326 msg.append(userId1);
4327
4328 msg.append(", type=");
4329 msg.append(type);
4330
4331 msg.append(StringPool.CLOSE_CURLY_BRACE);
4332
4333 throw new NoSuchRelationException(msg.toString());
4334 }
4335
4336
4344 @Override
4345 public SocialRelation fetchByU1_T_First(long userId1, int type,
4346 OrderByComparator<SocialRelation> orderByComparator) {
4347 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
4348 orderByComparator);
4349
4350 if (!list.isEmpty()) {
4351 return list.get(0);
4352 }
4353
4354 return null;
4355 }
4356
4357
4366 @Override
4367 public SocialRelation findByU1_T_Last(long userId1, int type,
4368 OrderByComparator<SocialRelation> orderByComparator)
4369 throws NoSuchRelationException {
4370 SocialRelation socialRelation = fetchByU1_T_Last(userId1, type,
4371 orderByComparator);
4372
4373 if (socialRelation != null) {
4374 return socialRelation;
4375 }
4376
4377 StringBundler msg = new StringBundler(6);
4378
4379 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4380
4381 msg.append("userId1=");
4382 msg.append(userId1);
4383
4384 msg.append(", type=");
4385 msg.append(type);
4386
4387 msg.append(StringPool.CLOSE_CURLY_BRACE);
4388
4389 throw new NoSuchRelationException(msg.toString());
4390 }
4391
4392
4400 @Override
4401 public SocialRelation fetchByU1_T_Last(long userId1, int type,
4402 OrderByComparator<SocialRelation> orderByComparator) {
4403 int count = countByU1_T(userId1, type);
4404
4405 if (count == 0) {
4406 return null;
4407 }
4408
4409 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
4410 orderByComparator);
4411
4412 if (!list.isEmpty()) {
4413 return list.get(0);
4414 }
4415
4416 return null;
4417 }
4418
4419
4429 @Override
4430 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
4431 long userId1, int type,
4432 OrderByComparator<SocialRelation> orderByComparator)
4433 throws NoSuchRelationException {
4434 SocialRelation socialRelation = findByPrimaryKey(relationId);
4435
4436 Session session = null;
4437
4438 try {
4439 session = openSession();
4440
4441 SocialRelation[] array = new SocialRelationImpl[3];
4442
4443 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
4444 type, orderByComparator, true);
4445
4446 array[1] = socialRelation;
4447
4448 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
4449 type, orderByComparator, false);
4450
4451 return array;
4452 }
4453 catch (Exception e) {
4454 throw processException(e);
4455 }
4456 finally {
4457 closeSession(session);
4458 }
4459 }
4460
4461 protected SocialRelation getByU1_T_PrevAndNext(Session session,
4462 SocialRelation socialRelation, long userId1, int type,
4463 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
4464 StringBundler query = null;
4465
4466 if (orderByComparator != null) {
4467 query = new StringBundler(6 +
4468 (orderByComparator.getOrderByFields().length * 6));
4469 }
4470 else {
4471 query = new StringBundler(3);
4472 }
4473
4474 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4475
4476 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4477
4478 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4479
4480 if (orderByComparator != null) {
4481 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4482
4483 if (orderByConditionFields.length > 0) {
4484 query.append(WHERE_AND);
4485 }
4486
4487 for (int i = 0; i < orderByConditionFields.length; i++) {
4488 query.append(_ORDER_BY_ENTITY_ALIAS);
4489 query.append(orderByConditionFields[i]);
4490
4491 if ((i + 1) < orderByConditionFields.length) {
4492 if (orderByComparator.isAscending() ^ previous) {
4493 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4494 }
4495 else {
4496 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4497 }
4498 }
4499 else {
4500 if (orderByComparator.isAscending() ^ previous) {
4501 query.append(WHERE_GREATER_THAN);
4502 }
4503 else {
4504 query.append(WHERE_LESSER_THAN);
4505 }
4506 }
4507 }
4508
4509 query.append(ORDER_BY_CLAUSE);
4510
4511 String[] orderByFields = orderByComparator.getOrderByFields();
4512
4513 for (int i = 0; i < orderByFields.length; i++) {
4514 query.append(_ORDER_BY_ENTITY_ALIAS);
4515 query.append(orderByFields[i]);
4516
4517 if ((i + 1) < orderByFields.length) {
4518 if (orderByComparator.isAscending() ^ previous) {
4519 query.append(ORDER_BY_ASC_HAS_NEXT);
4520 }
4521 else {
4522 query.append(ORDER_BY_DESC_HAS_NEXT);
4523 }
4524 }
4525 else {
4526 if (orderByComparator.isAscending() ^ previous) {
4527 query.append(ORDER_BY_ASC);
4528 }
4529 else {
4530 query.append(ORDER_BY_DESC);
4531 }
4532 }
4533 }
4534 }
4535 else {
4536 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4537 }
4538
4539 String sql = query.toString();
4540
4541 Query q = session.createQuery(sql);
4542
4543 q.setFirstResult(0);
4544 q.setMaxResults(2);
4545
4546 QueryPos qPos = QueryPos.getInstance(q);
4547
4548 qPos.add(userId1);
4549
4550 qPos.add(type);
4551
4552 if (orderByComparator != null) {
4553 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4554
4555 for (Object value : values) {
4556 qPos.add(value);
4557 }
4558 }
4559
4560 List<SocialRelation> list = q.list();
4561
4562 if (list.size() == 2) {
4563 return list.get(1);
4564 }
4565 else {
4566 return null;
4567 }
4568 }
4569
4570
4576 @Override
4577 public void removeByU1_T(long userId1, int type) {
4578 for (SocialRelation socialRelation : findByU1_T(userId1, type,
4579 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4580 remove(socialRelation);
4581 }
4582 }
4583
4584
4591 @Override
4592 public int countByU1_T(long userId1, int type) {
4593 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_T;
4594
4595 Object[] finderArgs = new Object[] { userId1, type };
4596
4597 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4598 this);
4599
4600 if (count == null) {
4601 StringBundler query = new StringBundler(3);
4602
4603 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4604
4605 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4606
4607 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4608
4609 String sql = query.toString();
4610
4611 Session session = null;
4612
4613 try {
4614 session = openSession();
4615
4616 Query q = session.createQuery(sql);
4617
4618 QueryPos qPos = QueryPos.getInstance(q);
4619
4620 qPos.add(userId1);
4621
4622 qPos.add(type);
4623
4624 count = (Long)q.uniqueResult();
4625
4626 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4627 }
4628 catch (Exception e) {
4629 FinderCacheUtil.removeResult(finderPath, finderArgs);
4630
4631 throw processException(e);
4632 }
4633 finally {
4634 closeSession(session);
4635 }
4636 }
4637
4638 return count.intValue();
4639 }
4640
4641 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4642 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
4643 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4644 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4645 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4646 "findByU2_T",
4647 new String[] {
4648 Long.class.getName(), Integer.class.getName(),
4649
4650 Integer.class.getName(), Integer.class.getName(),
4651 OrderByComparator.class.getName()
4652 });
4653 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4654 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
4655 SocialRelationImpl.class,
4656 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU2_T",
4657 new String[] { Long.class.getName(), Integer.class.getName() },
4658 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
4659 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
4660 public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
4661 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4662 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU2_T",
4663 new String[] { Long.class.getName(), Integer.class.getName() });
4664
4665
4672 @Override
4673 public List<SocialRelation> findByU2_T(long userId2, int type) {
4674 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4675 null);
4676 }
4677
4678
4691 @Override
4692 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4693 int end) {
4694 return findByU2_T(userId2, type, start, end, null);
4695 }
4696
4697
4711 @Override
4712 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4713 int end, OrderByComparator<SocialRelation> orderByComparator) {
4714 boolean pagination = true;
4715 FinderPath finderPath = null;
4716 Object[] finderArgs = null;
4717
4718 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4719 (orderByComparator == null)) {
4720 pagination = false;
4721 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
4722 finderArgs = new Object[] { userId2, type };
4723 }
4724 else {
4725 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
4726 finderArgs = new Object[] {
4727 userId2, type,
4728
4729 start, end, orderByComparator
4730 };
4731 }
4732
4733 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4734 finderArgs, this);
4735
4736 if ((list != null) && !list.isEmpty()) {
4737 for (SocialRelation socialRelation : list) {
4738 if ((userId2 != socialRelation.getUserId2()) ||
4739 (type != socialRelation.getType())) {
4740 list = null;
4741
4742 break;
4743 }
4744 }
4745 }
4746
4747 if (list == null) {
4748 StringBundler query = null;
4749
4750 if (orderByComparator != null) {
4751 query = new StringBundler(4 +
4752 (orderByComparator.getOrderByFields().length * 3));
4753 }
4754 else {
4755 query = new StringBundler(4);
4756 }
4757
4758 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4759
4760 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4761
4762 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4763
4764 if (orderByComparator != null) {
4765 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4766 orderByComparator);
4767 }
4768 else
4769 if (pagination) {
4770 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
4771 }
4772
4773 String sql = query.toString();
4774
4775 Session session = null;
4776
4777 try {
4778 session = openSession();
4779
4780 Query q = session.createQuery(sql);
4781
4782 QueryPos qPos = QueryPos.getInstance(q);
4783
4784 qPos.add(userId2);
4785
4786 qPos.add(type);
4787
4788 if (!pagination) {
4789 list = (List<SocialRelation>)QueryUtil.list(q,
4790 getDialect(), start, end, false);
4791
4792 Collections.sort(list);
4793
4794 list = Collections.unmodifiableList(list);
4795 }
4796 else {
4797 list = (List<SocialRelation>)QueryUtil.list(q,
4798 getDialect(), start, end);
4799 }
4800
4801 cacheResult(list);
4802
4803 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4804 }
4805 catch (Exception e) {
4806 FinderCacheUtil.removeResult(finderPath, finderArgs);
4807
4808 throw processException(e);
4809 }
4810 finally {
4811 closeSession(session);
4812 }
4813 }
4814
4815 return list;
4816 }
4817
4818
4827 @Override
4828 public SocialRelation findByU2_T_First(long userId2, int type,
4829 OrderByComparator<SocialRelation> orderByComparator)
4830 throws NoSuchRelationException {
4831 SocialRelation socialRelation = fetchByU2_T_First(userId2, type,
4832 orderByComparator);
4833
4834 if (socialRelation != null) {
4835 return socialRelation;
4836 }
4837
4838 StringBundler msg = new StringBundler(6);
4839
4840 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4841
4842 msg.append("userId2=");
4843 msg.append(userId2);
4844
4845 msg.append(", type=");
4846 msg.append(type);
4847
4848 msg.append(StringPool.CLOSE_CURLY_BRACE);
4849
4850 throw new NoSuchRelationException(msg.toString());
4851 }
4852
4853
4861 @Override
4862 public SocialRelation fetchByU2_T_First(long userId2, int type,
4863 OrderByComparator<SocialRelation> orderByComparator) {
4864 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
4865 orderByComparator);
4866
4867 if (!list.isEmpty()) {
4868 return list.get(0);
4869 }
4870
4871 return null;
4872 }
4873
4874
4883 @Override
4884 public SocialRelation findByU2_T_Last(long userId2, int type,
4885 OrderByComparator<SocialRelation> orderByComparator)
4886 throws NoSuchRelationException {
4887 SocialRelation socialRelation = fetchByU2_T_Last(userId2, type,
4888 orderByComparator);
4889
4890 if (socialRelation != null) {
4891 return socialRelation;
4892 }
4893
4894 StringBundler msg = new StringBundler(6);
4895
4896 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4897
4898 msg.append("userId2=");
4899 msg.append(userId2);
4900
4901 msg.append(", type=");
4902 msg.append(type);
4903
4904 msg.append(StringPool.CLOSE_CURLY_BRACE);
4905
4906 throw new NoSuchRelationException(msg.toString());
4907 }
4908
4909
4917 @Override
4918 public SocialRelation fetchByU2_T_Last(long userId2, int type,
4919 OrderByComparator<SocialRelation> orderByComparator) {
4920 int count = countByU2_T(userId2, type);
4921
4922 if (count == 0) {
4923 return null;
4924 }
4925
4926 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
4927 orderByComparator);
4928
4929 if (!list.isEmpty()) {
4930 return list.get(0);
4931 }
4932
4933 return null;
4934 }
4935
4936
4946 @Override
4947 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
4948 long userId2, int type,
4949 OrderByComparator<SocialRelation> orderByComparator)
4950 throws NoSuchRelationException {
4951 SocialRelation socialRelation = findByPrimaryKey(relationId);
4952
4953 Session session = null;
4954
4955 try {
4956 session = openSession();
4957
4958 SocialRelation[] array = new SocialRelationImpl[3];
4959
4960 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4961 type, orderByComparator, true);
4962
4963 array[1] = socialRelation;
4964
4965 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4966 type, orderByComparator, false);
4967
4968 return array;
4969 }
4970 catch (Exception e) {
4971 throw processException(e);
4972 }
4973 finally {
4974 closeSession(session);
4975 }
4976 }
4977
4978 protected SocialRelation getByU2_T_PrevAndNext(Session session,
4979 SocialRelation socialRelation, long userId2, int type,
4980 OrderByComparator<SocialRelation> orderByComparator, boolean previous) {
4981 StringBundler query = null;
4982
4983 if (orderByComparator != null) {
4984 query = new StringBundler(6 +
4985 (orderByComparator.getOrderByFields().length * 6));
4986 }
4987 else {
4988 query = new StringBundler(3);
4989 }
4990
4991 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4992
4993 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4994
4995 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4996
4997 if (orderByComparator != null) {
4998 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4999
5000 if (orderByConditionFields.length > 0) {
5001 query.append(WHERE_AND);
5002 }
5003
5004 for (int i = 0; i < orderByConditionFields.length; i++) {
5005 query.append(_ORDER_BY_ENTITY_ALIAS);
5006 query.append(orderByConditionFields[i]);
5007
5008 if ((i + 1) < orderByConditionFields.length) {
5009 if (orderByComparator.isAscending() ^ previous) {
5010 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5011 }
5012 else {
5013 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5014 }
5015 }
5016 else {
5017 if (orderByComparator.isAscending() ^ previous) {
5018 query.append(WHERE_GREATER_THAN);
5019 }
5020 else {
5021 query.append(WHERE_LESSER_THAN);
5022 }
5023 }
5024 }
5025
5026 query.append(ORDER_BY_CLAUSE);
5027
5028 String[] orderByFields = orderByComparator.getOrderByFields();
5029
5030 for (int i = 0; i < orderByFields.length; i++) {
5031 query.append(_ORDER_BY_ENTITY_ALIAS);
5032 query.append(orderByFields[i]);
5033
5034 if ((i + 1) < orderByFields.length) {
5035 if (orderByComparator.isAscending() ^ previous) {
5036 query.append(ORDER_BY_ASC_HAS_NEXT);
5037 }
5038 else {
5039 query.append(ORDER_BY_DESC_HAS_NEXT);
5040 }
5041 }
5042 else {
5043 if (orderByComparator.isAscending() ^ previous) {
5044 query.append(ORDER_BY_ASC);
5045 }
5046 else {
5047 query.append(ORDER_BY_DESC);
5048 }
5049 }
5050 }
5051 }
5052 else {
5053 query.append(SocialRelationModelImpl.ORDER_BY_JPQL);
5054 }
5055
5056 String sql = query.toString();
5057
5058 Query q = session.createQuery(sql);
5059
5060 q.setFirstResult(0);
5061 q.setMaxResults(2);
5062
5063 QueryPos qPos = QueryPos.getInstance(q);
5064
5065 qPos.add(userId2);
5066
5067 qPos.add(type);
5068
5069 if (orderByComparator != null) {
5070 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
5071
5072 for (Object value : values) {
5073 qPos.add(value);
5074 }
5075 }
5076
5077 List<SocialRelation> list = q.list();
5078
5079 if (list.size() == 2) {
5080 return list.get(1);
5081 }
5082 else {
5083 return null;
5084 }
5085 }
5086
5087
5093 @Override
5094 public void removeByU2_T(long userId2, int type) {
5095 for (SocialRelation socialRelation : findByU2_T(userId2, type,
5096 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5097 remove(socialRelation);
5098 }
5099 }
5100
5101
5108 @Override
5109 public int countByU2_T(long userId2, int type) {
5110 FinderPath finderPath = FINDER_PATH_COUNT_BY_U2_T;
5111
5112 Object[] finderArgs = new Object[] { userId2, type };
5113
5114 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5115 this);
5116
5117 if (count == null) {
5118 StringBundler query = new StringBundler(3);
5119
5120 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5121
5122 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
5123
5124 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
5125
5126 String sql = query.toString();
5127
5128 Session session = null;
5129
5130 try {
5131 session = openSession();
5132
5133 Query q = session.createQuery(sql);
5134
5135 QueryPos qPos = QueryPos.getInstance(q);
5136
5137 qPos.add(userId2);
5138
5139 qPos.add(type);
5140
5141 count = (Long)q.uniqueResult();
5142
5143 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5144 }
5145 catch (Exception e) {
5146 FinderCacheUtil.removeResult(finderPath, finderArgs);
5147
5148 throw processException(e);
5149 }
5150 finally {
5151 closeSession(session);
5152 }
5153 }
5154
5155 return count.intValue();
5156 }
5157
5158 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5159 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5160 public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5161 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
5162 SocialRelationImpl.class, FINDER_CLASS_NAME_ENTITY,
5163 "fetchByU1_U2_T",
5164 new String[] {
5165 Long.class.getName(), Long.class.getName(),
5166 Integer.class.getName()
5167 },
5168 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
5169 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
5170 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
5171 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5172 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5173 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2_T",
5174 new String[] {
5175 Long.class.getName(), Long.class.getName(),
5176 Integer.class.getName()
5177 });
5178
5179
5188 @Override
5189 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
5190 throws NoSuchRelationException {
5191 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
5192
5193 if (socialRelation == null) {
5194 StringBundler msg = new StringBundler(8);
5195
5196 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5197
5198 msg.append("userId1=");
5199 msg.append(userId1);
5200
5201 msg.append(", userId2=");
5202 msg.append(userId2);
5203
5204 msg.append(", type=");
5205 msg.append(type);
5206
5207 msg.append(StringPool.CLOSE_CURLY_BRACE);
5208
5209 if (_log.isWarnEnabled()) {
5210 _log.warn(msg.toString());
5211 }
5212
5213 throw new NoSuchRelationException(msg.toString());
5214 }
5215
5216 return socialRelation;
5217 }
5218
5219
5227 @Override
5228 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type) {
5229 return fetchByU1_U2_T(userId1, userId2, type, true);
5230 }
5231
5232
5241 @Override
5242 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
5243 boolean retrieveFromCache) {
5244 Object[] finderArgs = new Object[] { userId1, userId2, type };
5245
5246 Object result = null;
5247
5248 if (retrieveFromCache) {
5249 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5250 finderArgs, this);
5251 }
5252
5253 if (result instanceof SocialRelation) {
5254 SocialRelation socialRelation = (SocialRelation)result;
5255
5256 if ((userId1 != socialRelation.getUserId1()) ||
5257 (userId2 != socialRelation.getUserId2()) ||
5258 (type != socialRelation.getType())) {
5259 result = null;
5260 }
5261 }
5262
5263 if (result == null) {
5264 StringBundler query = new StringBundler(5);
5265
5266 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
5267
5268 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5269
5270 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5271
5272 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5273
5274 String sql = query.toString();
5275
5276 Session session = null;
5277
5278 try {
5279 session = openSession();
5280
5281 Query q = session.createQuery(sql);
5282
5283 QueryPos qPos = QueryPos.getInstance(q);
5284
5285 qPos.add(userId1);
5286
5287 qPos.add(userId2);
5288
5289 qPos.add(type);
5290
5291 List<SocialRelation> list = q.list();
5292
5293 if (list.isEmpty()) {
5294 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5295 finderArgs, list);
5296 }
5297 else {
5298 SocialRelation socialRelation = list.get(0);
5299
5300 result = socialRelation;
5301
5302 cacheResult(socialRelation);
5303
5304 if ((socialRelation.getUserId1() != userId1) ||
5305 (socialRelation.getUserId2() != userId2) ||
5306 (socialRelation.getType() != type)) {
5307 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5308 finderArgs, socialRelation);
5309 }
5310 }
5311 }
5312 catch (Exception e) {
5313 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5314 finderArgs);
5315
5316 throw processException(e);
5317 }
5318 finally {
5319 closeSession(session);
5320 }
5321 }
5322
5323 if (result instanceof List<?>) {
5324 return null;
5325 }
5326 else {
5327 return (SocialRelation)result;
5328 }
5329 }
5330
5331
5339 @Override
5340 public SocialRelation removeByU1_U2_T(long userId1, long userId2, int type)
5341 throws NoSuchRelationException {
5342 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
5343
5344 return remove(socialRelation);
5345 }
5346
5347
5355 @Override
5356 public int countByU1_U2_T(long userId1, long userId2, int type) {
5357 FinderPath finderPath = FINDER_PATH_COUNT_BY_U1_U2_T;
5358
5359 Object[] finderArgs = new Object[] { userId1, userId2, type };
5360
5361 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5362 this);
5363
5364 if (count == null) {
5365 StringBundler query = new StringBundler(4);
5366
5367 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5368
5369 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5370
5371 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5372
5373 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5374
5375 String sql = query.toString();
5376
5377 Session session = null;
5378
5379 try {
5380 session = openSession();
5381
5382 Query q = session.createQuery(sql);
5383
5384 QueryPos qPos = QueryPos.getInstance(q);
5385
5386 qPos.add(userId1);
5387
5388 qPos.add(userId2);
5389
5390 qPos.add(type);
5391
5392 count = (Long)q.uniqueResult();
5393
5394 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5395 }
5396 catch (Exception e) {
5397 FinderCacheUtil.removeResult(finderPath, finderArgs);
5398
5399 throw processException(e);
5400 }
5401 finally {
5402 closeSession(session);
5403 }
5404 }
5405
5406 return count.intValue();
5407 }
5408
5409 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5410 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5411 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5412
5413 public SocialRelationPersistenceImpl() {
5414 setModelClass(SocialRelation.class);
5415 }
5416
5417
5422 @Override
5423 public void cacheResult(SocialRelation socialRelation) {
5424 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5425 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
5426 socialRelation);
5427
5428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
5429 new Object[] {
5430 socialRelation.getUserId1(), socialRelation.getUserId2(),
5431 socialRelation.getType()
5432 }, socialRelation);
5433
5434 socialRelation.resetOriginalValues();
5435 }
5436
5437
5442 @Override
5443 public void cacheResult(List<SocialRelation> socialRelations) {
5444 for (SocialRelation socialRelation : socialRelations) {
5445 if (EntityCacheUtil.getResult(
5446 SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5447 SocialRelationImpl.class, socialRelation.getPrimaryKey()) == null) {
5448 cacheResult(socialRelation);
5449 }
5450 else {
5451 socialRelation.resetOriginalValues();
5452 }
5453 }
5454 }
5455
5456
5463 @Override
5464 public void clearCache() {
5465 EntityCacheUtil.clearCache(SocialRelationImpl.class);
5466
5467 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5468 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5469 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5470 }
5471
5472
5479 @Override
5480 public void clearCache(SocialRelation socialRelation) {
5481 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5482 SocialRelationImpl.class, socialRelation.getPrimaryKey());
5483
5484 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5485 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5486
5487 clearUniqueFindersCache(socialRelation);
5488 }
5489
5490 @Override
5491 public void clearCache(List<SocialRelation> socialRelations) {
5492 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5493 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5494
5495 for (SocialRelation socialRelation : socialRelations) {
5496 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5497 SocialRelationImpl.class, socialRelation.getPrimaryKey());
5498
5499 clearUniqueFindersCache(socialRelation);
5500 }
5501 }
5502
5503 protected void cacheUniqueFindersCache(SocialRelation socialRelation) {
5504 if (socialRelation.isNew()) {
5505 Object[] args = new Object[] {
5506 socialRelation.getUserId1(), socialRelation.getUserId2(),
5507 socialRelation.getType()
5508 };
5509
5510 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
5511 Long.valueOf(1));
5512 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
5513 socialRelation);
5514 }
5515 else {
5516 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5517
5518 if ((socialRelationModelImpl.getColumnBitmask() &
5519 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
5520 Object[] args = new Object[] {
5521 socialRelation.getUserId1(), socialRelation.getUserId2(),
5522 socialRelation.getType()
5523 };
5524
5525 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
5526 Long.valueOf(1));
5527 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
5528 socialRelation);
5529 }
5530 }
5531 }
5532
5533 protected void clearUniqueFindersCache(SocialRelation socialRelation) {
5534 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5535
5536 Object[] args = new Object[] {
5537 socialRelation.getUserId1(), socialRelation.getUserId2(),
5538 socialRelation.getType()
5539 };
5540
5541 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
5542 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
5543
5544 if ((socialRelationModelImpl.getColumnBitmask() &
5545 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
5546 args = new Object[] {
5547 socialRelationModelImpl.getOriginalUserId1(),
5548 socialRelationModelImpl.getOriginalUserId2(),
5549 socialRelationModelImpl.getOriginalType()
5550 };
5551
5552 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
5553 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
5554 }
5555 }
5556
5557
5563 @Override
5564 public SocialRelation create(long relationId) {
5565 SocialRelation socialRelation = new SocialRelationImpl();
5566
5567 socialRelation.setNew(true);
5568 socialRelation.setPrimaryKey(relationId);
5569
5570 String uuid = PortalUUIDUtil.generate();
5571
5572 socialRelation.setUuid(uuid);
5573
5574 return socialRelation;
5575 }
5576
5577
5584 @Override
5585 public SocialRelation remove(long relationId)
5586 throws NoSuchRelationException {
5587 return remove((Serializable)relationId);
5588 }
5589
5590
5597 @Override
5598 public SocialRelation remove(Serializable primaryKey)
5599 throws NoSuchRelationException {
5600 Session session = null;
5601
5602 try {
5603 session = openSession();
5604
5605 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5606 primaryKey);
5607
5608 if (socialRelation == null) {
5609 if (_log.isWarnEnabled()) {
5610 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5611 }
5612
5613 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5614 primaryKey);
5615 }
5616
5617 return remove(socialRelation);
5618 }
5619 catch (NoSuchRelationException nsee) {
5620 throw nsee;
5621 }
5622 catch (Exception e) {
5623 throw processException(e);
5624 }
5625 finally {
5626 closeSession(session);
5627 }
5628 }
5629
5630 @Override
5631 protected SocialRelation removeImpl(SocialRelation socialRelation) {
5632 socialRelation = toUnwrappedModel(socialRelation);
5633
5634 Session session = null;
5635
5636 try {
5637 session = openSession();
5638
5639 if (!session.contains(socialRelation)) {
5640 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5641 socialRelation.getPrimaryKeyObj());
5642 }
5643
5644 if (socialRelation != null) {
5645 session.delete(socialRelation);
5646 }
5647 }
5648 catch (Exception e) {
5649 throw processException(e);
5650 }
5651 finally {
5652 closeSession(session);
5653 }
5654
5655 if (socialRelation != null) {
5656 clearCache(socialRelation);
5657 }
5658
5659 return socialRelation;
5660 }
5661
5662 @Override
5663 public SocialRelation updateImpl(SocialRelation socialRelation) {
5664 socialRelation = toUnwrappedModel(socialRelation);
5665
5666 boolean isNew = socialRelation.isNew();
5667
5668 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
5669
5670 if (Validator.isNull(socialRelation.getUuid())) {
5671 String uuid = PortalUUIDUtil.generate();
5672
5673 socialRelation.setUuid(uuid);
5674 }
5675
5676 Session session = null;
5677
5678 try {
5679 session = openSession();
5680
5681 if (socialRelation.isNew()) {
5682 session.save(socialRelation);
5683
5684 socialRelation.setNew(false);
5685 }
5686 else {
5687 session.merge(socialRelation);
5688 }
5689 }
5690 catch (Exception e) {
5691 throw processException(e);
5692 }
5693 finally {
5694 closeSession(session);
5695 }
5696
5697 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5698
5699 if (isNew || !SocialRelationModelImpl.COLUMN_BITMASK_ENABLED) {
5700 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5701 }
5702
5703 else {
5704 if ((socialRelationModelImpl.getColumnBitmask() &
5705 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5706 Object[] args = new Object[] {
5707 socialRelationModelImpl.getOriginalUuid()
5708 };
5709
5710 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5711 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5712 args);
5713
5714 args = new Object[] { socialRelationModelImpl.getUuid() };
5715
5716 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5717 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5718 args);
5719 }
5720
5721 if ((socialRelationModelImpl.getColumnBitmask() &
5722 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5723 Object[] args = new Object[] {
5724 socialRelationModelImpl.getOriginalUuid(),
5725 socialRelationModelImpl.getOriginalCompanyId()
5726 };
5727
5728 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5729 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5730 args);
5731
5732 args = new Object[] {
5733 socialRelationModelImpl.getUuid(),
5734 socialRelationModelImpl.getCompanyId()
5735 };
5736
5737 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5738 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5739 args);
5740 }
5741
5742 if ((socialRelationModelImpl.getColumnBitmask() &
5743 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
5744 Object[] args = new Object[] {
5745 socialRelationModelImpl.getOriginalCompanyId()
5746 };
5747
5748 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5749 args);
5750 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5751 args);
5752
5753 args = new Object[] { socialRelationModelImpl.getCompanyId() };
5754
5755 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5756 args);
5757 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5758 args);
5759 }
5760
5761 if ((socialRelationModelImpl.getColumnBitmask() &
5762 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1.getColumnBitmask()) != 0) {
5763 Object[] args = new Object[] {
5764 socialRelationModelImpl.getOriginalUserId1()
5765 };
5766
5767 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
5768 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
5769 args);
5770
5771 args = new Object[] { socialRelationModelImpl.getUserId1() };
5772
5773 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
5774 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
5775 args);
5776 }
5777
5778 if ((socialRelationModelImpl.getColumnBitmask() &
5779 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2.getColumnBitmask()) != 0) {
5780 Object[] args = new Object[] {
5781 socialRelationModelImpl.getOriginalUserId2()
5782 };
5783
5784 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
5785 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
5786 args);
5787
5788 args = new Object[] { socialRelationModelImpl.getUserId2() };
5789
5790 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
5791 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
5792 args);
5793 }
5794
5795 if ((socialRelationModelImpl.getColumnBitmask() &
5796 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
5797 Object[] args = new Object[] {
5798 socialRelationModelImpl.getOriginalType()
5799 };
5800
5801 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
5802 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
5803 args);
5804
5805 args = new Object[] { socialRelationModelImpl.getType() };
5806
5807 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
5808 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
5809 args);
5810 }
5811
5812 if ((socialRelationModelImpl.getColumnBitmask() &
5813 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
5814 Object[] args = new Object[] {
5815 socialRelationModelImpl.getOriginalCompanyId(),
5816 socialRelationModelImpl.getOriginalType()
5817 };
5818
5819 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
5820 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
5821 args);
5822
5823 args = new Object[] {
5824 socialRelationModelImpl.getCompanyId(),
5825 socialRelationModelImpl.getType()
5826 };
5827
5828 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
5829 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
5830 args);
5831 }
5832
5833 if ((socialRelationModelImpl.getColumnBitmask() &
5834 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2.getColumnBitmask()) != 0) {
5835 Object[] args = new Object[] {
5836 socialRelationModelImpl.getOriginalUserId1(),
5837 socialRelationModelImpl.getOriginalUserId2()
5838 };
5839
5840 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
5841 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
5842 args);
5843
5844 args = new Object[] {
5845 socialRelationModelImpl.getUserId1(),
5846 socialRelationModelImpl.getUserId2()
5847 };
5848
5849 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
5850 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
5851 args);
5852 }
5853
5854 if ((socialRelationModelImpl.getColumnBitmask() &
5855 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T.getColumnBitmask()) != 0) {
5856 Object[] args = new Object[] {
5857 socialRelationModelImpl.getOriginalUserId1(),
5858 socialRelationModelImpl.getOriginalType()
5859 };
5860
5861 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
5862 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
5863 args);
5864
5865 args = new Object[] {
5866 socialRelationModelImpl.getUserId1(),
5867 socialRelationModelImpl.getType()
5868 };
5869
5870 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
5871 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
5872 args);
5873 }
5874
5875 if ((socialRelationModelImpl.getColumnBitmask() &
5876 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T.getColumnBitmask()) != 0) {
5877 Object[] args = new Object[] {
5878 socialRelationModelImpl.getOriginalUserId2(),
5879 socialRelationModelImpl.getOriginalType()
5880 };
5881
5882 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
5883 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
5884 args);
5885
5886 args = new Object[] {
5887 socialRelationModelImpl.getUserId2(),
5888 socialRelationModelImpl.getType()
5889 };
5890
5891 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
5892 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
5893 args);
5894 }
5895 }
5896
5897 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5898 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
5899 socialRelation, false);
5900
5901 clearUniqueFindersCache(socialRelation);
5902 cacheUniqueFindersCache(socialRelation);
5903
5904 socialRelation.resetOriginalValues();
5905
5906 return socialRelation;
5907 }
5908
5909 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
5910 if (socialRelation instanceof SocialRelationImpl) {
5911 return socialRelation;
5912 }
5913
5914 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
5915
5916 socialRelationImpl.setNew(socialRelation.isNew());
5917 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
5918
5919 socialRelationImpl.setUuid(socialRelation.getUuid());
5920 socialRelationImpl.setRelationId(socialRelation.getRelationId());
5921 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
5922 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
5923 socialRelationImpl.setUserId1(socialRelation.getUserId1());
5924 socialRelationImpl.setUserId2(socialRelation.getUserId2());
5925 socialRelationImpl.setType(socialRelation.getType());
5926
5927 return socialRelationImpl;
5928 }
5929
5930
5937 @Override
5938 public SocialRelation findByPrimaryKey(Serializable primaryKey)
5939 throws NoSuchRelationException {
5940 SocialRelation socialRelation = fetchByPrimaryKey(primaryKey);
5941
5942 if (socialRelation == null) {
5943 if (_log.isWarnEnabled()) {
5944 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5945 }
5946
5947 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5948 primaryKey);
5949 }
5950
5951 return socialRelation;
5952 }
5953
5954
5961 @Override
5962 public SocialRelation findByPrimaryKey(long relationId)
5963 throws NoSuchRelationException {
5964 return findByPrimaryKey((Serializable)relationId);
5965 }
5966
5967
5973 @Override
5974 public SocialRelation fetchByPrimaryKey(Serializable primaryKey) {
5975 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5976 SocialRelationImpl.class, primaryKey);
5977
5978 if (socialRelation == _nullSocialRelation) {
5979 return null;
5980 }
5981
5982 if (socialRelation == null) {
5983 Session session = null;
5984
5985 try {
5986 session = openSession();
5987
5988 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
5989 primaryKey);
5990
5991 if (socialRelation != null) {
5992 cacheResult(socialRelation);
5993 }
5994 else {
5995 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
5996 SocialRelationImpl.class, primaryKey,
5997 _nullSocialRelation);
5998 }
5999 }
6000 catch (Exception e) {
6001 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
6002 SocialRelationImpl.class, primaryKey);
6003
6004 throw processException(e);
6005 }
6006 finally {
6007 closeSession(session);
6008 }
6009 }
6010
6011 return socialRelation;
6012 }
6013
6014
6020 @Override
6021 public SocialRelation fetchByPrimaryKey(long relationId) {
6022 return fetchByPrimaryKey((Serializable)relationId);
6023 }
6024
6025 @Override
6026 public Map<Serializable, SocialRelation> fetchByPrimaryKeys(
6027 Set<Serializable> primaryKeys) {
6028 if (primaryKeys.isEmpty()) {
6029 return Collections.emptyMap();
6030 }
6031
6032 Map<Serializable, SocialRelation> map = new HashMap<Serializable, SocialRelation>();
6033
6034 if (primaryKeys.size() == 1) {
6035 Iterator<Serializable> iterator = primaryKeys.iterator();
6036
6037 Serializable primaryKey = iterator.next();
6038
6039 SocialRelation socialRelation = fetchByPrimaryKey(primaryKey);
6040
6041 if (socialRelation != null) {
6042 map.put(primaryKey, socialRelation);
6043 }
6044
6045 return map;
6046 }
6047
6048 Set<Serializable> uncachedPrimaryKeys = null;
6049
6050 for (Serializable primaryKey : primaryKeys) {
6051 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
6052 SocialRelationImpl.class, primaryKey);
6053
6054 if (socialRelation == null) {
6055 if (uncachedPrimaryKeys == null) {
6056 uncachedPrimaryKeys = new HashSet<Serializable>();
6057 }
6058
6059 uncachedPrimaryKeys.add(primaryKey);
6060 }
6061 else {
6062 map.put(primaryKey, socialRelation);
6063 }
6064 }
6065
6066 if (uncachedPrimaryKeys == null) {
6067 return map;
6068 }
6069
6070 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
6071 1);
6072
6073 query.append(_SQL_SELECT_SOCIALRELATION_WHERE_PKS_IN);
6074
6075 for (Serializable primaryKey : uncachedPrimaryKeys) {
6076 query.append(String.valueOf(primaryKey));
6077
6078 query.append(StringPool.COMMA);
6079 }
6080
6081 query.setIndex(query.index() - 1);
6082
6083 query.append(StringPool.CLOSE_PARENTHESIS);
6084
6085 String sql = query.toString();
6086
6087 Session session = null;
6088
6089 try {
6090 session = openSession();
6091
6092 Query q = session.createQuery(sql);
6093
6094 for (SocialRelation socialRelation : (List<SocialRelation>)q.list()) {
6095 map.put(socialRelation.getPrimaryKeyObj(), socialRelation);
6096
6097 cacheResult(socialRelation);
6098
6099 uncachedPrimaryKeys.remove(socialRelation.getPrimaryKeyObj());
6100 }
6101
6102 for (Serializable primaryKey : uncachedPrimaryKeys) {
6103 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
6104 SocialRelationImpl.class, primaryKey, _nullSocialRelation);
6105 }
6106 }
6107 catch (Exception e) {
6108 throw processException(e);
6109 }
6110 finally {
6111 closeSession(session);
6112 }
6113
6114 return map;
6115 }
6116
6117
6122 @Override
6123 public List<SocialRelation> findAll() {
6124 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6125 }
6126
6127
6138 @Override
6139 public List<SocialRelation> findAll(int start, int end) {
6140 return findAll(start, end, null);
6141 }
6142
6143
6155 @Override
6156 public List<SocialRelation> findAll(int start, int end,
6157 OrderByComparator<SocialRelation> orderByComparator) {
6158 boolean pagination = true;
6159 FinderPath finderPath = null;
6160 Object[] finderArgs = null;
6161
6162 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6163 (orderByComparator == null)) {
6164 pagination = false;
6165 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6166 finderArgs = FINDER_ARGS_EMPTY;
6167 }
6168 else {
6169 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6170 finderArgs = new Object[] { start, end, orderByComparator };
6171 }
6172
6173 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
6174 finderArgs, this);
6175
6176 if (list == null) {
6177 StringBundler query = null;
6178 String sql = null;
6179
6180 if (orderByComparator != null) {
6181 query = new StringBundler(2 +
6182 (orderByComparator.getOrderByFields().length * 3));
6183
6184 query.append(_SQL_SELECT_SOCIALRELATION);
6185
6186 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6187 orderByComparator);
6188
6189 sql = query.toString();
6190 }
6191 else {
6192 sql = _SQL_SELECT_SOCIALRELATION;
6193
6194 if (pagination) {
6195 sql = sql.concat(SocialRelationModelImpl.ORDER_BY_JPQL);
6196 }
6197 }
6198
6199 Session session = null;
6200
6201 try {
6202 session = openSession();
6203
6204 Query q = session.createQuery(sql);
6205
6206 if (!pagination) {
6207 list = (List<SocialRelation>)QueryUtil.list(q,
6208 getDialect(), start, end, false);
6209
6210 Collections.sort(list);
6211
6212 list = Collections.unmodifiableList(list);
6213 }
6214 else {
6215 list = (List<SocialRelation>)QueryUtil.list(q,
6216 getDialect(), start, end);
6217 }
6218
6219 cacheResult(list);
6220
6221 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6222 }
6223 catch (Exception e) {
6224 FinderCacheUtil.removeResult(finderPath, finderArgs);
6225
6226 throw processException(e);
6227 }
6228 finally {
6229 closeSession(session);
6230 }
6231 }
6232
6233 return list;
6234 }
6235
6236
6240 @Override
6241 public void removeAll() {
6242 for (SocialRelation socialRelation : findAll()) {
6243 remove(socialRelation);
6244 }
6245 }
6246
6247
6252 @Override
6253 public int countAll() {
6254 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6255 FINDER_ARGS_EMPTY, this);
6256
6257 if (count == null) {
6258 Session session = null;
6259
6260 try {
6261 session = openSession();
6262
6263 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
6264
6265 count = (Long)q.uniqueResult();
6266
6267 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6268 FINDER_ARGS_EMPTY, count);
6269 }
6270 catch (Exception e) {
6271 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
6272 FINDER_ARGS_EMPTY);
6273
6274 throw processException(e);
6275 }
6276 finally {
6277 closeSession(session);
6278 }
6279 }
6280
6281 return count.intValue();
6282 }
6283
6284 @Override
6285 protected Set<String> getBadColumnNames() {
6286 return _badColumnNames;
6287 }
6288
6289
6292 public void afterPropertiesSet() {
6293 }
6294
6295 public void destroy() {
6296 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
6297 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6298 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6299 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6300 }
6301
6302 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
6303 private static final String _SQL_SELECT_SOCIALRELATION_WHERE_PKS_IN = "SELECT socialRelation FROM SocialRelation socialRelation WHERE relationId IN (";
6304 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
6305 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
6306 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
6307 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
6308 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
6309 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
6310 private static final Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
6311 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6312 "uuid", "type"
6313 });
6314 private static final SocialRelation _nullSocialRelation = new SocialRelationImpl() {
6315 @Override
6316 public Object clone() {
6317 return this;
6318 }
6319
6320 @Override
6321 public CacheModel<SocialRelation> toCacheModel() {
6322 return _nullSocialRelationCacheModel;
6323 }
6324 };
6325
6326 private static final CacheModel<SocialRelation> _nullSocialRelationCacheModel =
6327 new CacheModel<SocialRelation>() {
6328 @Override
6329 public SocialRelation toEntityModel() {
6330 return _nullSocialRelation;
6331 }
6332 };
6333 }