001
014
015 package com.liferay.portlet.social.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.social.NoSuchRequestException;
043 import com.liferay.portlet.social.model.SocialRequest;
044 import com.liferay.portlet.social.model.impl.SocialRequestImpl;
045 import com.liferay.portlet.social.model.impl.SocialRequestModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052 import java.util.Set;
053
054
066 public class SocialRequestPersistenceImpl extends BasePersistenceImpl<SocialRequest>
067 implements SocialRequestPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = SocialRequestImpl.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(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
079 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
080 SocialRequestImpl.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(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
083 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
084 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
085 "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
087 SocialRequestModelImpl.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(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
090 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
091 SocialRequestImpl.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(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
100 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
101 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
102 "findByUuid", new String[] { String.class.getName() },
103 SocialRequestModelImpl.UUID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
105 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107 new String[] { String.class.getName() });
108
109
116 public List<SocialRequest> findByUuid(String uuid)
117 throws SystemException {
118 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<SocialRequest> findByUuid(String uuid, int start, int end)
135 throws SystemException {
136 return findByUuid(uuid, start, end, null);
137 }
138
139
153 public List<SocialRequest> findByUuid(String uuid, int start, int end,
154 OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid, start, end, orderByComparator };
168 }
169
170 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (SocialRequest socialRequest : list) {
175 if (!Validator.equals(uuid, socialRequest.getUuid())) {
176 list = null;
177
178 break;
179 }
180 }
181 }
182
183 if (list == null) {
184 StringBundler query = null;
185
186 if (orderByComparator != null) {
187 query = new StringBundler(3 +
188 (orderByComparator.getOrderByFields().length * 3));
189 }
190 else {
191 query = new StringBundler(3);
192 }
193
194 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
195
196 boolean bindUuid = false;
197
198 if (uuid == null) {
199 query.append(_FINDER_COLUMN_UUID_UUID_1);
200 }
201 else if (uuid.equals(StringPool.BLANK)) {
202 query.append(_FINDER_COLUMN_UUID_UUID_3);
203 }
204 else {
205 bindUuid = true;
206
207 query.append(_FINDER_COLUMN_UUID_UUID_2);
208 }
209
210 if (orderByComparator != null) {
211 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
212 orderByComparator);
213 }
214 else
215 if (pagination) {
216 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
217 }
218
219 String sql = query.toString();
220
221 Session session = null;
222
223 try {
224 session = openSession();
225
226 Query q = session.createQuery(sql);
227
228 QueryPos qPos = QueryPos.getInstance(q);
229
230 if (bindUuid) {
231 qPos.add(uuid);
232 }
233
234 if (!pagination) {
235 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
236 start, end, false);
237
238 Collections.sort(list);
239
240 list = new UnmodifiableList<SocialRequest>(list);
241 }
242 else {
243 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
244 start, end);
245 }
246
247 cacheResult(list);
248
249 FinderCacheUtil.putResult(finderPath, finderArgs, list);
250 }
251 catch (Exception e) {
252 FinderCacheUtil.removeResult(finderPath, finderArgs);
253
254 throw processException(e);
255 }
256 finally {
257 closeSession(session);
258 }
259 }
260
261 return list;
262 }
263
264
273 public SocialRequest findByUuid_First(String uuid,
274 OrderByComparator orderByComparator)
275 throws NoSuchRequestException, SystemException {
276 SocialRequest socialRequest = fetchByUuid_First(uuid, orderByComparator);
277
278 if (socialRequest != null) {
279 return socialRequest;
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 NoSuchRequestException(msg.toString());
292 }
293
294
302 public SocialRequest fetchByUuid_First(String uuid,
303 OrderByComparator orderByComparator) throws SystemException {
304 List<SocialRequest> list = findByUuid(uuid, 0, 1, orderByComparator);
305
306 if (!list.isEmpty()) {
307 return list.get(0);
308 }
309
310 return null;
311 }
312
313
322 public SocialRequest findByUuid_Last(String uuid,
323 OrderByComparator orderByComparator)
324 throws NoSuchRequestException, SystemException {
325 SocialRequest socialRequest = fetchByUuid_Last(uuid, orderByComparator);
326
327 if (socialRequest != null) {
328 return socialRequest;
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 NoSuchRequestException(msg.toString());
341 }
342
343
351 public SocialRequest fetchByUuid_Last(String uuid,
352 OrderByComparator orderByComparator) throws SystemException {
353 int count = countByUuid(uuid);
354
355 List<SocialRequest> list = findByUuid(uuid, count - 1, count,
356 orderByComparator);
357
358 if (!list.isEmpty()) {
359 return list.get(0);
360 }
361
362 return null;
363 }
364
365
375 public SocialRequest[] findByUuid_PrevAndNext(long requestId, String uuid,
376 OrderByComparator orderByComparator)
377 throws NoSuchRequestException, SystemException {
378 SocialRequest socialRequest = findByPrimaryKey(requestId);
379
380 Session session = null;
381
382 try {
383 session = openSession();
384
385 SocialRequest[] array = new SocialRequestImpl[3];
386
387 array[0] = getByUuid_PrevAndNext(session, socialRequest, uuid,
388 orderByComparator, true);
389
390 array[1] = socialRequest;
391
392 array[2] = getByUuid_PrevAndNext(session, socialRequest, uuid,
393 orderByComparator, false);
394
395 return array;
396 }
397 catch (Exception e) {
398 throw processException(e);
399 }
400 finally {
401 closeSession(session);
402 }
403 }
404
405 protected SocialRequest getByUuid_PrevAndNext(Session session,
406 SocialRequest socialRequest, String uuid,
407 OrderByComparator orderByComparator, boolean previous) {
408 StringBundler query = null;
409
410 if (orderByComparator != null) {
411 query = new StringBundler(6 +
412 (orderByComparator.getOrderByFields().length * 6));
413 }
414 else {
415 query = new StringBundler(3);
416 }
417
418 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
419
420 boolean bindUuid = false;
421
422 if (uuid == null) {
423 query.append(_FINDER_COLUMN_UUID_UUID_1);
424 }
425 else if (uuid.equals(StringPool.BLANK)) {
426 query.append(_FINDER_COLUMN_UUID_UUID_3);
427 }
428 else {
429 bindUuid = true;
430
431 query.append(_FINDER_COLUMN_UUID_UUID_2);
432 }
433
434 if (orderByComparator != null) {
435 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436
437 if (orderByConditionFields.length > 0) {
438 query.append(WHERE_AND);
439 }
440
441 for (int i = 0; i < orderByConditionFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByConditionFields[i]);
444
445 if ((i + 1) < orderByConditionFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN_HAS_NEXT);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN);
459 }
460 }
461 }
462
463 query.append(ORDER_BY_CLAUSE);
464
465 String[] orderByFields = orderByComparator.getOrderByFields();
466
467 for (int i = 0; i < orderByFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByFields[i]);
470
471 if ((i + 1) < orderByFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC_HAS_NEXT);
474 }
475 else {
476 query.append(ORDER_BY_DESC_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC);
482 }
483 else {
484 query.append(ORDER_BY_DESC);
485 }
486 }
487 }
488 }
489 else {
490 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 q.setFirstResult(0);
498 q.setMaxResults(2);
499
500 QueryPos qPos = QueryPos.getInstance(q);
501
502 if (bindUuid) {
503 qPos.add(uuid);
504 }
505
506 if (orderByComparator != null) {
507 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
508
509 for (Object value : values) {
510 qPos.add(value);
511 }
512 }
513
514 List<SocialRequest> list = q.list();
515
516 if (list.size() == 2) {
517 return list.get(1);
518 }
519 else {
520 return null;
521 }
522 }
523
524
530 public void removeByUuid(String uuid) throws SystemException {
531 for (SocialRequest socialRequest : findByUuid(uuid, QueryUtil.ALL_POS,
532 QueryUtil.ALL_POS, null)) {
533 remove(socialRequest);
534 }
535 }
536
537
544 public int countByUuid(String uuid) throws SystemException {
545 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
546
547 Object[] finderArgs = new Object[] { uuid };
548
549 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
550 this);
551
552 if (count == null) {
553 StringBundler query = new StringBundler(2);
554
555 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
556
557 boolean bindUuid = false;
558
559 if (uuid == null) {
560 query.append(_FINDER_COLUMN_UUID_UUID_1);
561 }
562 else if (uuid.equals(StringPool.BLANK)) {
563 query.append(_FINDER_COLUMN_UUID_UUID_3);
564 }
565 else {
566 bindUuid = true;
567
568 query.append(_FINDER_COLUMN_UUID_UUID_2);
569 }
570
571 String sql = query.toString();
572
573 Session session = null;
574
575 try {
576 session = openSession();
577
578 Query q = session.createQuery(sql);
579
580 QueryPos qPos = QueryPos.getInstance(q);
581
582 if (bindUuid) {
583 qPos.add(uuid);
584 }
585
586 count = (Long)q.uniqueResult();
587
588 FinderCacheUtil.putResult(finderPath, finderArgs, count);
589 }
590 catch (Exception e) {
591 FinderCacheUtil.removeResult(finderPath, finderArgs);
592
593 throw processException(e);
594 }
595 finally {
596 closeSession(session);
597 }
598 }
599
600 return count.intValue();
601 }
602
603 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRequest.uuid IS NULL";
604 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRequest.uuid = ?";
605 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = '')";
606 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
607 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
608 SocialRequestImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
609 new String[] { String.class.getName(), Long.class.getName() },
610 SocialRequestModelImpl.UUID_COLUMN_BITMASK |
611 SocialRequestModelImpl.GROUPID_COLUMN_BITMASK);
612 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
613 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
614 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
615 new String[] { String.class.getName(), Long.class.getName() });
616
617
626 public SocialRequest findByUUID_G(String uuid, long groupId)
627 throws NoSuchRequestException, SystemException {
628 SocialRequest socialRequest = fetchByUUID_G(uuid, groupId);
629
630 if (socialRequest == null) {
631 StringBundler msg = new StringBundler(6);
632
633 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
634
635 msg.append("uuid=");
636 msg.append(uuid);
637
638 msg.append(", groupId=");
639 msg.append(groupId);
640
641 msg.append(StringPool.CLOSE_CURLY_BRACE);
642
643 if (_log.isWarnEnabled()) {
644 _log.warn(msg.toString());
645 }
646
647 throw new NoSuchRequestException(msg.toString());
648 }
649
650 return socialRequest;
651 }
652
653
661 public SocialRequest fetchByUUID_G(String uuid, long groupId)
662 throws SystemException {
663 return fetchByUUID_G(uuid, groupId, true);
664 }
665
666
675 public SocialRequest fetchByUUID_G(String uuid, long groupId,
676 boolean retrieveFromCache) throws SystemException {
677 Object[] finderArgs = new Object[] { uuid, groupId };
678
679 Object result = null;
680
681 if (retrieveFromCache) {
682 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
683 finderArgs, this);
684 }
685
686 if (result instanceof SocialRequest) {
687 SocialRequest socialRequest = (SocialRequest)result;
688
689 if (!Validator.equals(uuid, socialRequest.getUuid()) ||
690 (groupId != socialRequest.getGroupId())) {
691 result = null;
692 }
693 }
694
695 if (result == null) {
696 StringBundler query = new StringBundler(4);
697
698 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
699
700 boolean bindUuid = false;
701
702 if (uuid == null) {
703 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
704 }
705 else if (uuid.equals(StringPool.BLANK)) {
706 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
707 }
708 else {
709 bindUuid = true;
710
711 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
712 }
713
714 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
715
716 String sql = query.toString();
717
718 Session session = null;
719
720 try {
721 session = openSession();
722
723 Query q = session.createQuery(sql);
724
725 QueryPos qPos = QueryPos.getInstance(q);
726
727 if (bindUuid) {
728 qPos.add(uuid);
729 }
730
731 qPos.add(groupId);
732
733 List<SocialRequest> list = q.list();
734
735 if (list.isEmpty()) {
736 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
737 finderArgs, list);
738 }
739 else {
740 SocialRequest socialRequest = list.get(0);
741
742 result = socialRequest;
743
744 cacheResult(socialRequest);
745
746 if ((socialRequest.getUuid() == null) ||
747 !socialRequest.getUuid().equals(uuid) ||
748 (socialRequest.getGroupId() != groupId)) {
749 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
750 finderArgs, socialRequest);
751 }
752 }
753 }
754 catch (Exception e) {
755 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
756 finderArgs);
757
758 throw processException(e);
759 }
760 finally {
761 closeSession(session);
762 }
763 }
764
765 if (result instanceof List<?>) {
766 return null;
767 }
768 else {
769 return (SocialRequest)result;
770 }
771 }
772
773
781 public SocialRequest removeByUUID_G(String uuid, long groupId)
782 throws NoSuchRequestException, SystemException {
783 SocialRequest socialRequest = findByUUID_G(uuid, groupId);
784
785 return remove(socialRequest);
786 }
787
788
796 public int countByUUID_G(String uuid, long groupId)
797 throws SystemException {
798 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
799
800 Object[] finderArgs = new Object[] { uuid, groupId };
801
802 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
803 this);
804
805 if (count == null) {
806 StringBundler query = new StringBundler(3);
807
808 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
809
810 boolean bindUuid = false;
811
812 if (uuid == null) {
813 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
814 }
815 else if (uuid.equals(StringPool.BLANK)) {
816 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
817 }
818 else {
819 bindUuid = true;
820
821 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
822 }
823
824 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
825
826 String sql = query.toString();
827
828 Session session = null;
829
830 try {
831 session = openSession();
832
833 Query q = session.createQuery(sql);
834
835 QueryPos qPos = QueryPos.getInstance(q);
836
837 if (bindUuid) {
838 qPos.add(uuid);
839 }
840
841 qPos.add(groupId);
842
843 count = (Long)q.uniqueResult();
844
845 FinderCacheUtil.putResult(finderPath, finderArgs, count);
846 }
847 catch (Exception e) {
848 FinderCacheUtil.removeResult(finderPath, finderArgs);
849
850 throw processException(e);
851 }
852 finally {
853 closeSession(session);
854 }
855 }
856
857 return count.intValue();
858 }
859
860 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "socialRequest.uuid IS NULL AND ";
861 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "socialRequest.uuid = ? AND ";
862 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = '') AND ";
863 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "socialRequest.groupId = ?";
864 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
865 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
866 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
867 "findByUuid_C",
868 new String[] {
869 String.class.getName(), Long.class.getName(),
870
871 Integer.class.getName(), Integer.class.getName(),
872 OrderByComparator.class.getName()
873 });
874 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
875 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
876 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
877 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
878 "findByUuid_C",
879 new String[] { String.class.getName(), Long.class.getName() },
880 SocialRequestModelImpl.UUID_COLUMN_BITMASK |
881 SocialRequestModelImpl.COMPANYID_COLUMN_BITMASK);
882 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
883 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
884 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
885 new String[] { String.class.getName(), Long.class.getName() });
886
887
895 public List<SocialRequest> findByUuid_C(String uuid, long companyId)
896 throws SystemException {
897 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
898 QueryUtil.ALL_POS, null);
899 }
900
901
915 public List<SocialRequest> findByUuid_C(String uuid, long companyId,
916 int start, int end) throws SystemException {
917 return findByUuid_C(uuid, companyId, start, end, null);
918 }
919
920
935 public List<SocialRequest> findByUuid_C(String uuid, long companyId,
936 int start, int end, OrderByComparator orderByComparator)
937 throws SystemException {
938 boolean pagination = true;
939 FinderPath finderPath = null;
940 Object[] finderArgs = null;
941
942 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
943 (orderByComparator == null)) {
944 pagination = false;
945 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
946 finderArgs = new Object[] { uuid, companyId };
947 }
948 else {
949 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
950 finderArgs = new Object[] {
951 uuid, companyId,
952
953 start, end, orderByComparator
954 };
955 }
956
957 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
958 finderArgs, this);
959
960 if ((list != null) && !list.isEmpty()) {
961 for (SocialRequest socialRequest : list) {
962 if (!Validator.equals(uuid, socialRequest.getUuid()) ||
963 (companyId != socialRequest.getCompanyId())) {
964 list = null;
965
966 break;
967 }
968 }
969 }
970
971 if (list == null) {
972 StringBundler query = null;
973
974 if (orderByComparator != null) {
975 query = new StringBundler(4 +
976 (orderByComparator.getOrderByFields().length * 3));
977 }
978 else {
979 query = new StringBundler(4);
980 }
981
982 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
983
984 boolean bindUuid = false;
985
986 if (uuid == null) {
987 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
988 }
989 else if (uuid.equals(StringPool.BLANK)) {
990 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
991 }
992 else {
993 bindUuid = true;
994
995 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
996 }
997
998 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
999
1000 if (orderByComparator != null) {
1001 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1002 orderByComparator);
1003 }
1004 else
1005 if (pagination) {
1006 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1007 }
1008
1009 String sql = query.toString();
1010
1011 Session session = null;
1012
1013 try {
1014 session = openSession();
1015
1016 Query q = session.createQuery(sql);
1017
1018 QueryPos qPos = QueryPos.getInstance(q);
1019
1020 if (bindUuid) {
1021 qPos.add(uuid);
1022 }
1023
1024 qPos.add(companyId);
1025
1026 if (!pagination) {
1027 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1028 start, end, false);
1029
1030 Collections.sort(list);
1031
1032 list = new UnmodifiableList<SocialRequest>(list);
1033 }
1034 else {
1035 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1036 start, end);
1037 }
1038
1039 cacheResult(list);
1040
1041 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1042 }
1043 catch (Exception e) {
1044 FinderCacheUtil.removeResult(finderPath, finderArgs);
1045
1046 throw processException(e);
1047 }
1048 finally {
1049 closeSession(session);
1050 }
1051 }
1052
1053 return list;
1054 }
1055
1056
1066 public SocialRequest findByUuid_C_First(String uuid, long companyId,
1067 OrderByComparator orderByComparator)
1068 throws NoSuchRequestException, SystemException {
1069 SocialRequest socialRequest = fetchByUuid_C_First(uuid, companyId,
1070 orderByComparator);
1071
1072 if (socialRequest != null) {
1073 return socialRequest;
1074 }
1075
1076 StringBundler msg = new StringBundler(6);
1077
1078 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1079
1080 msg.append("uuid=");
1081 msg.append(uuid);
1082
1083 msg.append(", companyId=");
1084 msg.append(companyId);
1085
1086 msg.append(StringPool.CLOSE_CURLY_BRACE);
1087
1088 throw new NoSuchRequestException(msg.toString());
1089 }
1090
1091
1100 public SocialRequest fetchByUuid_C_First(String uuid, long companyId,
1101 OrderByComparator orderByComparator) throws SystemException {
1102 List<SocialRequest> list = findByUuid_C(uuid, companyId, 0, 1,
1103 orderByComparator);
1104
1105 if (!list.isEmpty()) {
1106 return list.get(0);
1107 }
1108
1109 return null;
1110 }
1111
1112
1122 public SocialRequest findByUuid_C_Last(String uuid, long companyId,
1123 OrderByComparator orderByComparator)
1124 throws NoSuchRequestException, SystemException {
1125 SocialRequest socialRequest = fetchByUuid_C_Last(uuid, companyId,
1126 orderByComparator);
1127
1128 if (socialRequest != null) {
1129 return socialRequest;
1130 }
1131
1132 StringBundler msg = new StringBundler(6);
1133
1134 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1135
1136 msg.append("uuid=");
1137 msg.append(uuid);
1138
1139 msg.append(", companyId=");
1140 msg.append(companyId);
1141
1142 msg.append(StringPool.CLOSE_CURLY_BRACE);
1143
1144 throw new NoSuchRequestException(msg.toString());
1145 }
1146
1147
1156 public SocialRequest fetchByUuid_C_Last(String uuid, long companyId,
1157 OrderByComparator orderByComparator) throws SystemException {
1158 int count = countByUuid_C(uuid, companyId);
1159
1160 List<SocialRequest> list = findByUuid_C(uuid, companyId, count - 1,
1161 count, orderByComparator);
1162
1163 if (!list.isEmpty()) {
1164 return list.get(0);
1165 }
1166
1167 return null;
1168 }
1169
1170
1181 public SocialRequest[] findByUuid_C_PrevAndNext(long requestId,
1182 String uuid, long companyId, OrderByComparator orderByComparator)
1183 throws NoSuchRequestException, SystemException {
1184 SocialRequest socialRequest = findByPrimaryKey(requestId);
1185
1186 Session session = null;
1187
1188 try {
1189 session = openSession();
1190
1191 SocialRequest[] array = new SocialRequestImpl[3];
1192
1193 array[0] = getByUuid_C_PrevAndNext(session, socialRequest, uuid,
1194 companyId, orderByComparator, true);
1195
1196 array[1] = socialRequest;
1197
1198 array[2] = getByUuid_C_PrevAndNext(session, socialRequest, uuid,
1199 companyId, orderByComparator, false);
1200
1201 return array;
1202 }
1203 catch (Exception e) {
1204 throw processException(e);
1205 }
1206 finally {
1207 closeSession(session);
1208 }
1209 }
1210
1211 protected SocialRequest getByUuid_C_PrevAndNext(Session session,
1212 SocialRequest socialRequest, String uuid, long companyId,
1213 OrderByComparator orderByComparator, boolean previous) {
1214 StringBundler query = null;
1215
1216 if (orderByComparator != null) {
1217 query = new StringBundler(6 +
1218 (orderByComparator.getOrderByFields().length * 6));
1219 }
1220 else {
1221 query = new StringBundler(3);
1222 }
1223
1224 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1225
1226 boolean bindUuid = false;
1227
1228 if (uuid == null) {
1229 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1230 }
1231 else if (uuid.equals(StringPool.BLANK)) {
1232 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1233 }
1234 else {
1235 bindUuid = true;
1236
1237 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1238 }
1239
1240 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1241
1242 if (orderByComparator != null) {
1243 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1244
1245 if (orderByConditionFields.length > 0) {
1246 query.append(WHERE_AND);
1247 }
1248
1249 for (int i = 0; i < orderByConditionFields.length; i++) {
1250 query.append(_ORDER_BY_ENTITY_ALIAS);
1251 query.append(orderByConditionFields[i]);
1252
1253 if ((i + 1) < orderByConditionFields.length) {
1254 if (orderByComparator.isAscending() ^ previous) {
1255 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1256 }
1257 else {
1258 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1259 }
1260 }
1261 else {
1262 if (orderByComparator.isAscending() ^ previous) {
1263 query.append(WHERE_GREATER_THAN);
1264 }
1265 else {
1266 query.append(WHERE_LESSER_THAN);
1267 }
1268 }
1269 }
1270
1271 query.append(ORDER_BY_CLAUSE);
1272
1273 String[] orderByFields = orderByComparator.getOrderByFields();
1274
1275 for (int i = 0; i < orderByFields.length; i++) {
1276 query.append(_ORDER_BY_ENTITY_ALIAS);
1277 query.append(orderByFields[i]);
1278
1279 if ((i + 1) < orderByFields.length) {
1280 if (orderByComparator.isAscending() ^ previous) {
1281 query.append(ORDER_BY_ASC_HAS_NEXT);
1282 }
1283 else {
1284 query.append(ORDER_BY_DESC_HAS_NEXT);
1285 }
1286 }
1287 else {
1288 if (orderByComparator.isAscending() ^ previous) {
1289 query.append(ORDER_BY_ASC);
1290 }
1291 else {
1292 query.append(ORDER_BY_DESC);
1293 }
1294 }
1295 }
1296 }
1297 else {
1298 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1299 }
1300
1301 String sql = query.toString();
1302
1303 Query q = session.createQuery(sql);
1304
1305 q.setFirstResult(0);
1306 q.setMaxResults(2);
1307
1308 QueryPos qPos = QueryPos.getInstance(q);
1309
1310 if (bindUuid) {
1311 qPos.add(uuid);
1312 }
1313
1314 qPos.add(companyId);
1315
1316 if (orderByComparator != null) {
1317 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
1318
1319 for (Object value : values) {
1320 qPos.add(value);
1321 }
1322 }
1323
1324 List<SocialRequest> list = q.list();
1325
1326 if (list.size() == 2) {
1327 return list.get(1);
1328 }
1329 else {
1330 return null;
1331 }
1332 }
1333
1334
1341 public void removeByUuid_C(String uuid, long companyId)
1342 throws SystemException {
1343 for (SocialRequest socialRequest : findByUuid_C(uuid, companyId,
1344 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1345 remove(socialRequest);
1346 }
1347 }
1348
1349
1357 public int countByUuid_C(String uuid, long companyId)
1358 throws SystemException {
1359 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1360
1361 Object[] finderArgs = new Object[] { uuid, companyId };
1362
1363 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1364 this);
1365
1366 if (count == null) {
1367 StringBundler query = new StringBundler(3);
1368
1369 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
1370
1371 boolean bindUuid = false;
1372
1373 if (uuid == null) {
1374 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1375 }
1376 else if (uuid.equals(StringPool.BLANK)) {
1377 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1378 }
1379 else {
1380 bindUuid = true;
1381
1382 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1383 }
1384
1385 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1386
1387 String sql = query.toString();
1388
1389 Session session = null;
1390
1391 try {
1392 session = openSession();
1393
1394 Query q = session.createQuery(sql);
1395
1396 QueryPos qPos = QueryPos.getInstance(q);
1397
1398 if (bindUuid) {
1399 qPos.add(uuid);
1400 }
1401
1402 qPos.add(companyId);
1403
1404 count = (Long)q.uniqueResult();
1405
1406 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1407 }
1408 catch (Exception e) {
1409 FinderCacheUtil.removeResult(finderPath, finderArgs);
1410
1411 throw processException(e);
1412 }
1413 finally {
1414 closeSession(session);
1415 }
1416 }
1417
1418 return count.intValue();
1419 }
1420
1421 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "socialRequest.uuid IS NULL AND ";
1422 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "socialRequest.uuid = ? AND ";
1423 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = '') AND ";
1424 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "socialRequest.companyId = ?";
1425 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1426 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1427 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1428 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1429 "findByCompanyId",
1430 new String[] {
1431 Long.class.getName(),
1432
1433 Integer.class.getName(), Integer.class.getName(),
1434 OrderByComparator.class.getName()
1435 });
1436 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1437 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1438 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1439 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1440 "findByCompanyId", new String[] { Long.class.getName() },
1441 SocialRequestModelImpl.COMPANYID_COLUMN_BITMASK);
1442 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1443 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
1444 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1445 new String[] { Long.class.getName() });
1446
1447
1454 public List<SocialRequest> findByCompanyId(long companyId)
1455 throws SystemException {
1456 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1457 null);
1458 }
1459
1460
1473 public List<SocialRequest> findByCompanyId(long companyId, int start,
1474 int end) throws SystemException {
1475 return findByCompanyId(companyId, start, end, null);
1476 }
1477
1478
1492 public List<SocialRequest> findByCompanyId(long companyId, int start,
1493 int end, OrderByComparator orderByComparator) throws SystemException {
1494 boolean pagination = true;
1495 FinderPath finderPath = null;
1496 Object[] finderArgs = null;
1497
1498 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1499 (orderByComparator == null)) {
1500 pagination = false;
1501 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1502 finderArgs = new Object[] { companyId };
1503 }
1504 else {
1505 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1506 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1507 }
1508
1509 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
1510 finderArgs, this);
1511
1512 if ((list != null) && !list.isEmpty()) {
1513 for (SocialRequest socialRequest : list) {
1514 if ((companyId != socialRequest.getCompanyId())) {
1515 list = null;
1516
1517 break;
1518 }
1519 }
1520 }
1521
1522 if (list == null) {
1523 StringBundler query = null;
1524
1525 if (orderByComparator != null) {
1526 query = new StringBundler(3 +
1527 (orderByComparator.getOrderByFields().length * 3));
1528 }
1529 else {
1530 query = new StringBundler(3);
1531 }
1532
1533 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1534
1535 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1536
1537 if (orderByComparator != null) {
1538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1539 orderByComparator);
1540 }
1541 else
1542 if (pagination) {
1543 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1544 }
1545
1546 String sql = query.toString();
1547
1548 Session session = null;
1549
1550 try {
1551 session = openSession();
1552
1553 Query q = session.createQuery(sql);
1554
1555 QueryPos qPos = QueryPos.getInstance(q);
1556
1557 qPos.add(companyId);
1558
1559 if (!pagination) {
1560 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1561 start, end, false);
1562
1563 Collections.sort(list);
1564
1565 list = new UnmodifiableList<SocialRequest>(list);
1566 }
1567 else {
1568 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1569 start, end);
1570 }
1571
1572 cacheResult(list);
1573
1574 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1575 }
1576 catch (Exception e) {
1577 FinderCacheUtil.removeResult(finderPath, finderArgs);
1578
1579 throw processException(e);
1580 }
1581 finally {
1582 closeSession(session);
1583 }
1584 }
1585
1586 return list;
1587 }
1588
1589
1598 public SocialRequest findByCompanyId_First(long companyId,
1599 OrderByComparator orderByComparator)
1600 throws NoSuchRequestException, SystemException {
1601 SocialRequest socialRequest = fetchByCompanyId_First(companyId,
1602 orderByComparator);
1603
1604 if (socialRequest != null) {
1605 return socialRequest;
1606 }
1607
1608 StringBundler msg = new StringBundler(4);
1609
1610 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1611
1612 msg.append("companyId=");
1613 msg.append(companyId);
1614
1615 msg.append(StringPool.CLOSE_CURLY_BRACE);
1616
1617 throw new NoSuchRequestException(msg.toString());
1618 }
1619
1620
1628 public SocialRequest fetchByCompanyId_First(long companyId,
1629 OrderByComparator orderByComparator) throws SystemException {
1630 List<SocialRequest> list = findByCompanyId(companyId, 0, 1,
1631 orderByComparator);
1632
1633 if (!list.isEmpty()) {
1634 return list.get(0);
1635 }
1636
1637 return null;
1638 }
1639
1640
1649 public SocialRequest findByCompanyId_Last(long companyId,
1650 OrderByComparator orderByComparator)
1651 throws NoSuchRequestException, SystemException {
1652 SocialRequest socialRequest = fetchByCompanyId_Last(companyId,
1653 orderByComparator);
1654
1655 if (socialRequest != null) {
1656 return socialRequest;
1657 }
1658
1659 StringBundler msg = new StringBundler(4);
1660
1661 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1662
1663 msg.append("companyId=");
1664 msg.append(companyId);
1665
1666 msg.append(StringPool.CLOSE_CURLY_BRACE);
1667
1668 throw new NoSuchRequestException(msg.toString());
1669 }
1670
1671
1679 public SocialRequest fetchByCompanyId_Last(long companyId,
1680 OrderByComparator orderByComparator) throws SystemException {
1681 int count = countByCompanyId(companyId);
1682
1683 List<SocialRequest> list = findByCompanyId(companyId, count - 1, count,
1684 orderByComparator);
1685
1686 if (!list.isEmpty()) {
1687 return list.get(0);
1688 }
1689
1690 return null;
1691 }
1692
1693
1703 public SocialRequest[] findByCompanyId_PrevAndNext(long requestId,
1704 long companyId, OrderByComparator orderByComparator)
1705 throws NoSuchRequestException, SystemException {
1706 SocialRequest socialRequest = findByPrimaryKey(requestId);
1707
1708 Session session = null;
1709
1710 try {
1711 session = openSession();
1712
1713 SocialRequest[] array = new SocialRequestImpl[3];
1714
1715 array[0] = getByCompanyId_PrevAndNext(session, socialRequest,
1716 companyId, orderByComparator, true);
1717
1718 array[1] = socialRequest;
1719
1720 array[2] = getByCompanyId_PrevAndNext(session, socialRequest,
1721 companyId, orderByComparator, false);
1722
1723 return array;
1724 }
1725 catch (Exception e) {
1726 throw processException(e);
1727 }
1728 finally {
1729 closeSession(session);
1730 }
1731 }
1732
1733 protected SocialRequest getByCompanyId_PrevAndNext(Session session,
1734 SocialRequest socialRequest, long companyId,
1735 OrderByComparator orderByComparator, boolean previous) {
1736 StringBundler query = null;
1737
1738 if (orderByComparator != null) {
1739 query = new StringBundler(6 +
1740 (orderByComparator.getOrderByFields().length * 6));
1741 }
1742 else {
1743 query = new StringBundler(3);
1744 }
1745
1746 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1747
1748 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1749
1750 if (orderByComparator != null) {
1751 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1752
1753 if (orderByConditionFields.length > 0) {
1754 query.append(WHERE_AND);
1755 }
1756
1757 for (int i = 0; i < orderByConditionFields.length; i++) {
1758 query.append(_ORDER_BY_ENTITY_ALIAS);
1759 query.append(orderByConditionFields[i]);
1760
1761 if ((i + 1) < orderByConditionFields.length) {
1762 if (orderByComparator.isAscending() ^ previous) {
1763 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1764 }
1765 else {
1766 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1767 }
1768 }
1769 else {
1770 if (orderByComparator.isAscending() ^ previous) {
1771 query.append(WHERE_GREATER_THAN);
1772 }
1773 else {
1774 query.append(WHERE_LESSER_THAN);
1775 }
1776 }
1777 }
1778
1779 query.append(ORDER_BY_CLAUSE);
1780
1781 String[] orderByFields = orderByComparator.getOrderByFields();
1782
1783 for (int i = 0; i < orderByFields.length; i++) {
1784 query.append(_ORDER_BY_ENTITY_ALIAS);
1785 query.append(orderByFields[i]);
1786
1787 if ((i + 1) < orderByFields.length) {
1788 if (orderByComparator.isAscending() ^ previous) {
1789 query.append(ORDER_BY_ASC_HAS_NEXT);
1790 }
1791 else {
1792 query.append(ORDER_BY_DESC_HAS_NEXT);
1793 }
1794 }
1795 else {
1796 if (orderByComparator.isAscending() ^ previous) {
1797 query.append(ORDER_BY_ASC);
1798 }
1799 else {
1800 query.append(ORDER_BY_DESC);
1801 }
1802 }
1803 }
1804 }
1805 else {
1806 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1807 }
1808
1809 String sql = query.toString();
1810
1811 Query q = session.createQuery(sql);
1812
1813 q.setFirstResult(0);
1814 q.setMaxResults(2);
1815
1816 QueryPos qPos = QueryPos.getInstance(q);
1817
1818 qPos.add(companyId);
1819
1820 if (orderByComparator != null) {
1821 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
1822
1823 for (Object value : values) {
1824 qPos.add(value);
1825 }
1826 }
1827
1828 List<SocialRequest> list = q.list();
1829
1830 if (list.size() == 2) {
1831 return list.get(1);
1832 }
1833 else {
1834 return null;
1835 }
1836 }
1837
1838
1844 public void removeByCompanyId(long companyId) throws SystemException {
1845 for (SocialRequest socialRequest : findByCompanyId(companyId,
1846 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1847 remove(socialRequest);
1848 }
1849 }
1850
1851
1858 public int countByCompanyId(long companyId) throws SystemException {
1859 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1860
1861 Object[] finderArgs = new Object[] { companyId };
1862
1863 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1864 this);
1865
1866 if (count == null) {
1867 StringBundler query = new StringBundler(2);
1868
1869 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
1870
1871 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1872
1873 String sql = query.toString();
1874
1875 Session session = null;
1876
1877 try {
1878 session = openSession();
1879
1880 Query q = session.createQuery(sql);
1881
1882 QueryPos qPos = QueryPos.getInstance(q);
1883
1884 qPos.add(companyId);
1885
1886 count = (Long)q.uniqueResult();
1887
1888 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1889 }
1890 catch (Exception e) {
1891 FinderCacheUtil.removeResult(finderPath, finderArgs);
1892
1893 throw processException(e);
1894 }
1895 finally {
1896 closeSession(session);
1897 }
1898 }
1899
1900 return count.intValue();
1901 }
1902
1903 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRequest.companyId = ?";
1904 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1905 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1906 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1907 "findByUserId",
1908 new String[] {
1909 Long.class.getName(),
1910
1911 Integer.class.getName(), Integer.class.getName(),
1912 OrderByComparator.class.getName()
1913 });
1914 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1915 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1916 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1917 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1918 "findByUserId", new String[] { Long.class.getName() },
1919 SocialRequestModelImpl.USERID_COLUMN_BITMASK);
1920 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1921 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
1922 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1923 new String[] { Long.class.getName() });
1924
1925
1932 public List<SocialRequest> findByUserId(long userId)
1933 throws SystemException {
1934 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1935 }
1936
1937
1950 public List<SocialRequest> findByUserId(long userId, int start, int end)
1951 throws SystemException {
1952 return findByUserId(userId, start, end, null);
1953 }
1954
1955
1969 public List<SocialRequest> findByUserId(long userId, int start, int end,
1970 OrderByComparator orderByComparator) throws SystemException {
1971 boolean pagination = true;
1972 FinderPath finderPath = null;
1973 Object[] finderArgs = null;
1974
1975 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1976 (orderByComparator == null)) {
1977 pagination = false;
1978 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1979 finderArgs = new Object[] { userId };
1980 }
1981 else {
1982 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1983 finderArgs = new Object[] { userId, start, end, orderByComparator };
1984 }
1985
1986 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
1987 finderArgs, this);
1988
1989 if ((list != null) && !list.isEmpty()) {
1990 for (SocialRequest socialRequest : list) {
1991 if ((userId != socialRequest.getUserId())) {
1992 list = null;
1993
1994 break;
1995 }
1996 }
1997 }
1998
1999 if (list == null) {
2000 StringBundler query = null;
2001
2002 if (orderByComparator != null) {
2003 query = new StringBundler(3 +
2004 (orderByComparator.getOrderByFields().length * 3));
2005 }
2006 else {
2007 query = new StringBundler(3);
2008 }
2009
2010 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2011
2012 query.append(_FINDER_COLUMN_USERID_USERID_2);
2013
2014 if (orderByComparator != null) {
2015 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2016 orderByComparator);
2017 }
2018 else
2019 if (pagination) {
2020 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2021 }
2022
2023 String sql = query.toString();
2024
2025 Session session = null;
2026
2027 try {
2028 session = openSession();
2029
2030 Query q = session.createQuery(sql);
2031
2032 QueryPos qPos = QueryPos.getInstance(q);
2033
2034 qPos.add(userId);
2035
2036 if (!pagination) {
2037 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2038 start, end, false);
2039
2040 Collections.sort(list);
2041
2042 list = new UnmodifiableList<SocialRequest>(list);
2043 }
2044 else {
2045 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2046 start, end);
2047 }
2048
2049 cacheResult(list);
2050
2051 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2052 }
2053 catch (Exception e) {
2054 FinderCacheUtil.removeResult(finderPath, finderArgs);
2055
2056 throw processException(e);
2057 }
2058 finally {
2059 closeSession(session);
2060 }
2061 }
2062
2063 return list;
2064 }
2065
2066
2075 public SocialRequest findByUserId_First(long userId,
2076 OrderByComparator orderByComparator)
2077 throws NoSuchRequestException, SystemException {
2078 SocialRequest socialRequest = fetchByUserId_First(userId,
2079 orderByComparator);
2080
2081 if (socialRequest != null) {
2082 return socialRequest;
2083 }
2084
2085 StringBundler msg = new StringBundler(4);
2086
2087 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2088
2089 msg.append("userId=");
2090 msg.append(userId);
2091
2092 msg.append(StringPool.CLOSE_CURLY_BRACE);
2093
2094 throw new NoSuchRequestException(msg.toString());
2095 }
2096
2097
2105 public SocialRequest fetchByUserId_First(long userId,
2106 OrderByComparator orderByComparator) throws SystemException {
2107 List<SocialRequest> list = findByUserId(userId, 0, 1, orderByComparator);
2108
2109 if (!list.isEmpty()) {
2110 return list.get(0);
2111 }
2112
2113 return null;
2114 }
2115
2116
2125 public SocialRequest findByUserId_Last(long userId,
2126 OrderByComparator orderByComparator)
2127 throws NoSuchRequestException, SystemException {
2128 SocialRequest socialRequest = fetchByUserId_Last(userId,
2129 orderByComparator);
2130
2131 if (socialRequest != null) {
2132 return socialRequest;
2133 }
2134
2135 StringBundler msg = new StringBundler(4);
2136
2137 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2138
2139 msg.append("userId=");
2140 msg.append(userId);
2141
2142 msg.append(StringPool.CLOSE_CURLY_BRACE);
2143
2144 throw new NoSuchRequestException(msg.toString());
2145 }
2146
2147
2155 public SocialRequest fetchByUserId_Last(long userId,
2156 OrderByComparator orderByComparator) throws SystemException {
2157 int count = countByUserId(userId);
2158
2159 List<SocialRequest> list = findByUserId(userId, count - 1, count,
2160 orderByComparator);
2161
2162 if (!list.isEmpty()) {
2163 return list.get(0);
2164 }
2165
2166 return null;
2167 }
2168
2169
2179 public SocialRequest[] findByUserId_PrevAndNext(long requestId,
2180 long userId, OrderByComparator orderByComparator)
2181 throws NoSuchRequestException, SystemException {
2182 SocialRequest socialRequest = findByPrimaryKey(requestId);
2183
2184 Session session = null;
2185
2186 try {
2187 session = openSession();
2188
2189 SocialRequest[] array = new SocialRequestImpl[3];
2190
2191 array[0] = getByUserId_PrevAndNext(session, socialRequest, userId,
2192 orderByComparator, true);
2193
2194 array[1] = socialRequest;
2195
2196 array[2] = getByUserId_PrevAndNext(session, socialRequest, userId,
2197 orderByComparator, false);
2198
2199 return array;
2200 }
2201 catch (Exception e) {
2202 throw processException(e);
2203 }
2204 finally {
2205 closeSession(session);
2206 }
2207 }
2208
2209 protected SocialRequest getByUserId_PrevAndNext(Session session,
2210 SocialRequest socialRequest, long userId,
2211 OrderByComparator orderByComparator, boolean previous) {
2212 StringBundler query = null;
2213
2214 if (orderByComparator != null) {
2215 query = new StringBundler(6 +
2216 (orderByComparator.getOrderByFields().length * 6));
2217 }
2218 else {
2219 query = new StringBundler(3);
2220 }
2221
2222 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2223
2224 query.append(_FINDER_COLUMN_USERID_USERID_2);
2225
2226 if (orderByComparator != null) {
2227 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2228
2229 if (orderByConditionFields.length > 0) {
2230 query.append(WHERE_AND);
2231 }
2232
2233 for (int i = 0; i < orderByConditionFields.length; i++) {
2234 query.append(_ORDER_BY_ENTITY_ALIAS);
2235 query.append(orderByConditionFields[i]);
2236
2237 if ((i + 1) < orderByConditionFields.length) {
2238 if (orderByComparator.isAscending() ^ previous) {
2239 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2240 }
2241 else {
2242 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2243 }
2244 }
2245 else {
2246 if (orderByComparator.isAscending() ^ previous) {
2247 query.append(WHERE_GREATER_THAN);
2248 }
2249 else {
2250 query.append(WHERE_LESSER_THAN);
2251 }
2252 }
2253 }
2254
2255 query.append(ORDER_BY_CLAUSE);
2256
2257 String[] orderByFields = orderByComparator.getOrderByFields();
2258
2259 for (int i = 0; i < orderByFields.length; i++) {
2260 query.append(_ORDER_BY_ENTITY_ALIAS);
2261 query.append(orderByFields[i]);
2262
2263 if ((i + 1) < orderByFields.length) {
2264 if (orderByComparator.isAscending() ^ previous) {
2265 query.append(ORDER_BY_ASC_HAS_NEXT);
2266 }
2267 else {
2268 query.append(ORDER_BY_DESC_HAS_NEXT);
2269 }
2270 }
2271 else {
2272 if (orderByComparator.isAscending() ^ previous) {
2273 query.append(ORDER_BY_ASC);
2274 }
2275 else {
2276 query.append(ORDER_BY_DESC);
2277 }
2278 }
2279 }
2280 }
2281 else {
2282 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2283 }
2284
2285 String sql = query.toString();
2286
2287 Query q = session.createQuery(sql);
2288
2289 q.setFirstResult(0);
2290 q.setMaxResults(2);
2291
2292 QueryPos qPos = QueryPos.getInstance(q);
2293
2294 qPos.add(userId);
2295
2296 if (orderByComparator != null) {
2297 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
2298
2299 for (Object value : values) {
2300 qPos.add(value);
2301 }
2302 }
2303
2304 List<SocialRequest> list = q.list();
2305
2306 if (list.size() == 2) {
2307 return list.get(1);
2308 }
2309 else {
2310 return null;
2311 }
2312 }
2313
2314
2320 public void removeByUserId(long userId) throws SystemException {
2321 for (SocialRequest socialRequest : findByUserId(userId,
2322 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2323 remove(socialRequest);
2324 }
2325 }
2326
2327
2334 public int countByUserId(long userId) throws SystemException {
2335 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2336
2337 Object[] finderArgs = new Object[] { userId };
2338
2339 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2340 this);
2341
2342 if (count == null) {
2343 StringBundler query = new StringBundler(2);
2344
2345 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
2346
2347 query.append(_FINDER_COLUMN_USERID_USERID_2);
2348
2349 String sql = query.toString();
2350
2351 Session session = null;
2352
2353 try {
2354 session = openSession();
2355
2356 Query q = session.createQuery(sql);
2357
2358 QueryPos qPos = QueryPos.getInstance(q);
2359
2360 qPos.add(userId);
2361
2362 count = (Long)q.uniqueResult();
2363
2364 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2365 }
2366 catch (Exception e) {
2367 FinderCacheUtil.removeResult(finderPath, finderArgs);
2368
2369 throw processException(e);
2370 }
2371 finally {
2372 closeSession(session);
2373 }
2374 }
2375
2376 return count.intValue();
2377 }
2378
2379 private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialRequest.userId = ?";
2380 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID =
2381 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2382 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2383 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2384 "findByReceiverUserId",
2385 new String[] {
2386 Long.class.getName(),
2387
2388 Integer.class.getName(), Integer.class.getName(),
2389 OrderByComparator.class.getName()
2390 });
2391 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID =
2392 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2393 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2394 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2395 "findByReceiverUserId", new String[] { Long.class.getName() },
2396 SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
2397 public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2398 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
2399 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByReceiverUserId",
2400 new String[] { Long.class.getName() });
2401
2402
2409 public List<SocialRequest> findByReceiverUserId(long receiverUserId)
2410 throws SystemException {
2411 return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
2412 QueryUtil.ALL_POS, null);
2413 }
2414
2415
2428 public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2429 int start, int end) throws SystemException {
2430 return findByReceiverUserId(receiverUserId, start, end, null);
2431 }
2432
2433
2447 public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2448 int start, int end, OrderByComparator orderByComparator)
2449 throws SystemException {
2450 boolean pagination = true;
2451 FinderPath finderPath = null;
2452 Object[] finderArgs = null;
2453
2454 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2455 (orderByComparator == null)) {
2456 pagination = false;
2457 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID;
2458 finderArgs = new Object[] { receiverUserId };
2459 }
2460 else {
2461 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID;
2462 finderArgs = new Object[] {
2463 receiverUserId,
2464
2465 start, end, orderByComparator
2466 };
2467 }
2468
2469 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
2470 finderArgs, this);
2471
2472 if ((list != null) && !list.isEmpty()) {
2473 for (SocialRequest socialRequest : list) {
2474 if ((receiverUserId != socialRequest.getReceiverUserId())) {
2475 list = null;
2476
2477 break;
2478 }
2479 }
2480 }
2481
2482 if (list == null) {
2483 StringBundler query = null;
2484
2485 if (orderByComparator != null) {
2486 query = new StringBundler(3 +
2487 (orderByComparator.getOrderByFields().length * 3));
2488 }
2489 else {
2490 query = new StringBundler(3);
2491 }
2492
2493 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2494
2495 query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2496
2497 if (orderByComparator != null) {
2498 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2499 orderByComparator);
2500 }
2501 else
2502 if (pagination) {
2503 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2504 }
2505
2506 String sql = query.toString();
2507
2508 Session session = null;
2509
2510 try {
2511 session = openSession();
2512
2513 Query q = session.createQuery(sql);
2514
2515 QueryPos qPos = QueryPos.getInstance(q);
2516
2517 qPos.add(receiverUserId);
2518
2519 if (!pagination) {
2520 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2521 start, end, false);
2522
2523 Collections.sort(list);
2524
2525 list = new UnmodifiableList<SocialRequest>(list);
2526 }
2527 else {
2528 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2529 start, end);
2530 }
2531
2532 cacheResult(list);
2533
2534 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2535 }
2536 catch (Exception e) {
2537 FinderCacheUtil.removeResult(finderPath, finderArgs);
2538
2539 throw processException(e);
2540 }
2541 finally {
2542 closeSession(session);
2543 }
2544 }
2545
2546 return list;
2547 }
2548
2549
2558 public SocialRequest findByReceiverUserId_First(long receiverUserId,
2559 OrderByComparator orderByComparator)
2560 throws NoSuchRequestException, SystemException {
2561 SocialRequest socialRequest = fetchByReceiverUserId_First(receiverUserId,
2562 orderByComparator);
2563
2564 if (socialRequest != null) {
2565 return socialRequest;
2566 }
2567
2568 StringBundler msg = new StringBundler(4);
2569
2570 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2571
2572 msg.append("receiverUserId=");
2573 msg.append(receiverUserId);
2574
2575 msg.append(StringPool.CLOSE_CURLY_BRACE);
2576
2577 throw new NoSuchRequestException(msg.toString());
2578 }
2579
2580
2588 public SocialRequest fetchByReceiverUserId_First(long receiverUserId,
2589 OrderByComparator orderByComparator) throws SystemException {
2590 List<SocialRequest> list = findByReceiverUserId(receiverUserId, 0, 1,
2591 orderByComparator);
2592
2593 if (!list.isEmpty()) {
2594 return list.get(0);
2595 }
2596
2597 return null;
2598 }
2599
2600
2609 public SocialRequest findByReceiverUserId_Last(long receiverUserId,
2610 OrderByComparator orderByComparator)
2611 throws NoSuchRequestException, SystemException {
2612 SocialRequest socialRequest = fetchByReceiverUserId_Last(receiverUserId,
2613 orderByComparator);
2614
2615 if (socialRequest != null) {
2616 return socialRequest;
2617 }
2618
2619 StringBundler msg = new StringBundler(4);
2620
2621 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2622
2623 msg.append("receiverUserId=");
2624 msg.append(receiverUserId);
2625
2626 msg.append(StringPool.CLOSE_CURLY_BRACE);
2627
2628 throw new NoSuchRequestException(msg.toString());
2629 }
2630
2631
2639 public SocialRequest fetchByReceiverUserId_Last(long receiverUserId,
2640 OrderByComparator orderByComparator) throws SystemException {
2641 int count = countByReceiverUserId(receiverUserId);
2642
2643 List<SocialRequest> list = findByReceiverUserId(receiverUserId,
2644 count - 1, count, orderByComparator);
2645
2646 if (!list.isEmpty()) {
2647 return list.get(0);
2648 }
2649
2650 return null;
2651 }
2652
2653
2663 public SocialRequest[] findByReceiverUserId_PrevAndNext(long requestId,
2664 long receiverUserId, OrderByComparator orderByComparator)
2665 throws NoSuchRequestException, SystemException {
2666 SocialRequest socialRequest = findByPrimaryKey(requestId);
2667
2668 Session session = null;
2669
2670 try {
2671 session = openSession();
2672
2673 SocialRequest[] array = new SocialRequestImpl[3];
2674
2675 array[0] = getByReceiverUserId_PrevAndNext(session, socialRequest,
2676 receiverUserId, orderByComparator, true);
2677
2678 array[1] = socialRequest;
2679
2680 array[2] = getByReceiverUserId_PrevAndNext(session, socialRequest,
2681 receiverUserId, orderByComparator, false);
2682
2683 return array;
2684 }
2685 catch (Exception e) {
2686 throw processException(e);
2687 }
2688 finally {
2689 closeSession(session);
2690 }
2691 }
2692
2693 protected SocialRequest getByReceiverUserId_PrevAndNext(Session session,
2694 SocialRequest socialRequest, long receiverUserId,
2695 OrderByComparator orderByComparator, boolean previous) {
2696 StringBundler query = null;
2697
2698 if (orderByComparator != null) {
2699 query = new StringBundler(6 +
2700 (orderByComparator.getOrderByFields().length * 6));
2701 }
2702 else {
2703 query = new StringBundler(3);
2704 }
2705
2706 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2707
2708 query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2709
2710 if (orderByComparator != null) {
2711 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2712
2713 if (orderByConditionFields.length > 0) {
2714 query.append(WHERE_AND);
2715 }
2716
2717 for (int i = 0; i < orderByConditionFields.length; i++) {
2718 query.append(_ORDER_BY_ENTITY_ALIAS);
2719 query.append(orderByConditionFields[i]);
2720
2721 if ((i + 1) < orderByConditionFields.length) {
2722 if (orderByComparator.isAscending() ^ previous) {
2723 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2724 }
2725 else {
2726 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2727 }
2728 }
2729 else {
2730 if (orderByComparator.isAscending() ^ previous) {
2731 query.append(WHERE_GREATER_THAN);
2732 }
2733 else {
2734 query.append(WHERE_LESSER_THAN);
2735 }
2736 }
2737 }
2738
2739 query.append(ORDER_BY_CLAUSE);
2740
2741 String[] orderByFields = orderByComparator.getOrderByFields();
2742
2743 for (int i = 0; i < orderByFields.length; i++) {
2744 query.append(_ORDER_BY_ENTITY_ALIAS);
2745 query.append(orderByFields[i]);
2746
2747 if ((i + 1) < orderByFields.length) {
2748 if (orderByComparator.isAscending() ^ previous) {
2749 query.append(ORDER_BY_ASC_HAS_NEXT);
2750 }
2751 else {
2752 query.append(ORDER_BY_DESC_HAS_NEXT);
2753 }
2754 }
2755 else {
2756 if (orderByComparator.isAscending() ^ previous) {
2757 query.append(ORDER_BY_ASC);
2758 }
2759 else {
2760 query.append(ORDER_BY_DESC);
2761 }
2762 }
2763 }
2764 }
2765 else {
2766 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2767 }
2768
2769 String sql = query.toString();
2770
2771 Query q = session.createQuery(sql);
2772
2773 q.setFirstResult(0);
2774 q.setMaxResults(2);
2775
2776 QueryPos qPos = QueryPos.getInstance(q);
2777
2778 qPos.add(receiverUserId);
2779
2780 if (orderByComparator != null) {
2781 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
2782
2783 for (Object value : values) {
2784 qPos.add(value);
2785 }
2786 }
2787
2788 List<SocialRequest> list = q.list();
2789
2790 if (list.size() == 2) {
2791 return list.get(1);
2792 }
2793 else {
2794 return null;
2795 }
2796 }
2797
2798
2804 public void removeByReceiverUserId(long receiverUserId)
2805 throws SystemException {
2806 for (SocialRequest socialRequest : findByReceiverUserId(
2807 receiverUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2808 remove(socialRequest);
2809 }
2810 }
2811
2812
2819 public int countByReceiverUserId(long receiverUserId)
2820 throws SystemException {
2821 FinderPath finderPath = FINDER_PATH_COUNT_BY_RECEIVERUSERID;
2822
2823 Object[] finderArgs = new Object[] { receiverUserId };
2824
2825 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2826 this);
2827
2828 if (count == null) {
2829 StringBundler query = new StringBundler(2);
2830
2831 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
2832
2833 query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2834
2835 String sql = query.toString();
2836
2837 Session session = null;
2838
2839 try {
2840 session = openSession();
2841
2842 Query q = session.createQuery(sql);
2843
2844 QueryPos qPos = QueryPos.getInstance(q);
2845
2846 qPos.add(receiverUserId);
2847
2848 count = (Long)q.uniqueResult();
2849
2850 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2851 }
2852 catch (Exception e) {
2853 FinderCacheUtil.removeResult(finderPath, finderArgs);
2854
2855 throw processException(e);
2856 }
2857 finally {
2858 closeSession(session);
2859 }
2860 }
2861
2862 return count.intValue();
2863 }
2864
2865 private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
2866 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2867 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2868 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2869 "findByU_S",
2870 new String[] {
2871 Long.class.getName(), Integer.class.getName(),
2872
2873 Integer.class.getName(), Integer.class.getName(),
2874 OrderByComparator.class.getName()
2875 });
2876 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2877 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2878 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2879 "findByU_S",
2880 new String[] { Long.class.getName(), Integer.class.getName() },
2881 SocialRequestModelImpl.USERID_COLUMN_BITMASK |
2882 SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
2883 public static final FinderPath FINDER_PATH_COUNT_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2884 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
2885 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_S",
2886 new String[] { Long.class.getName(), Integer.class.getName() });
2887
2888
2896 public List<SocialRequest> findByU_S(long userId, int status)
2897 throws SystemException {
2898 return findByU_S(userId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2899 null);
2900 }
2901
2902
2916 public List<SocialRequest> findByU_S(long userId, int status, int start,
2917 int end) throws SystemException {
2918 return findByU_S(userId, status, start, end, null);
2919 }
2920
2921
2936 public List<SocialRequest> findByU_S(long userId, int status, int start,
2937 int end, OrderByComparator orderByComparator) throws SystemException {
2938 boolean pagination = true;
2939 FinderPath finderPath = null;
2940 Object[] finderArgs = null;
2941
2942 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2943 (orderByComparator == null)) {
2944 pagination = false;
2945 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S;
2946 finderArgs = new Object[] { userId, status };
2947 }
2948 else {
2949 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S;
2950 finderArgs = new Object[] {
2951 userId, status,
2952
2953 start, end, orderByComparator
2954 };
2955 }
2956
2957 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
2958 finderArgs, this);
2959
2960 if ((list != null) && !list.isEmpty()) {
2961 for (SocialRequest socialRequest : list) {
2962 if ((userId != socialRequest.getUserId()) ||
2963 (status != socialRequest.getStatus())) {
2964 list = null;
2965
2966 break;
2967 }
2968 }
2969 }
2970
2971 if (list == null) {
2972 StringBundler query = null;
2973
2974 if (orderByComparator != null) {
2975 query = new StringBundler(4 +
2976 (orderByComparator.getOrderByFields().length * 3));
2977 }
2978 else {
2979 query = new StringBundler(4);
2980 }
2981
2982 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2983
2984 query.append(_FINDER_COLUMN_U_S_USERID_2);
2985
2986 query.append(_FINDER_COLUMN_U_S_STATUS_2);
2987
2988 if (orderByComparator != null) {
2989 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2990 orderByComparator);
2991 }
2992 else
2993 if (pagination) {
2994 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2995 }
2996
2997 String sql = query.toString();
2998
2999 Session session = null;
3000
3001 try {
3002 session = openSession();
3003
3004 Query q = session.createQuery(sql);
3005
3006 QueryPos qPos = QueryPos.getInstance(q);
3007
3008 qPos.add(userId);
3009
3010 qPos.add(status);
3011
3012 if (!pagination) {
3013 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3014 start, end, false);
3015
3016 Collections.sort(list);
3017
3018 list = new UnmodifiableList<SocialRequest>(list);
3019 }
3020 else {
3021 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3022 start, end);
3023 }
3024
3025 cacheResult(list);
3026
3027 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3028 }
3029 catch (Exception e) {
3030 FinderCacheUtil.removeResult(finderPath, finderArgs);
3031
3032 throw processException(e);
3033 }
3034 finally {
3035 closeSession(session);
3036 }
3037 }
3038
3039 return list;
3040 }
3041
3042
3052 public SocialRequest findByU_S_First(long userId, int status,
3053 OrderByComparator orderByComparator)
3054 throws NoSuchRequestException, SystemException {
3055 SocialRequest socialRequest = fetchByU_S_First(userId, status,
3056 orderByComparator);
3057
3058 if (socialRequest != null) {
3059 return socialRequest;
3060 }
3061
3062 StringBundler msg = new StringBundler(6);
3063
3064 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3065
3066 msg.append("userId=");
3067 msg.append(userId);
3068
3069 msg.append(", status=");
3070 msg.append(status);
3071
3072 msg.append(StringPool.CLOSE_CURLY_BRACE);
3073
3074 throw new NoSuchRequestException(msg.toString());
3075 }
3076
3077
3086 public SocialRequest fetchByU_S_First(long userId, int status,
3087 OrderByComparator orderByComparator) throws SystemException {
3088 List<SocialRequest> list = findByU_S(userId, status, 0, 1,
3089 orderByComparator);
3090
3091 if (!list.isEmpty()) {
3092 return list.get(0);
3093 }
3094
3095 return null;
3096 }
3097
3098
3108 public SocialRequest findByU_S_Last(long userId, int status,
3109 OrderByComparator orderByComparator)
3110 throws NoSuchRequestException, SystemException {
3111 SocialRequest socialRequest = fetchByU_S_Last(userId, status,
3112 orderByComparator);
3113
3114 if (socialRequest != null) {
3115 return socialRequest;
3116 }
3117
3118 StringBundler msg = new StringBundler(6);
3119
3120 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3121
3122 msg.append("userId=");
3123 msg.append(userId);
3124
3125 msg.append(", status=");
3126 msg.append(status);
3127
3128 msg.append(StringPool.CLOSE_CURLY_BRACE);
3129
3130 throw new NoSuchRequestException(msg.toString());
3131 }
3132
3133
3142 public SocialRequest fetchByU_S_Last(long userId, int status,
3143 OrderByComparator orderByComparator) throws SystemException {
3144 int count = countByU_S(userId, status);
3145
3146 List<SocialRequest> list = findByU_S(userId, status, count - 1, count,
3147 orderByComparator);
3148
3149 if (!list.isEmpty()) {
3150 return list.get(0);
3151 }
3152
3153 return null;
3154 }
3155
3156
3167 public SocialRequest[] findByU_S_PrevAndNext(long requestId, long userId,
3168 int status, OrderByComparator orderByComparator)
3169 throws NoSuchRequestException, SystemException {
3170 SocialRequest socialRequest = findByPrimaryKey(requestId);
3171
3172 Session session = null;
3173
3174 try {
3175 session = openSession();
3176
3177 SocialRequest[] array = new SocialRequestImpl[3];
3178
3179 array[0] = getByU_S_PrevAndNext(session, socialRequest, userId,
3180 status, orderByComparator, true);
3181
3182 array[1] = socialRequest;
3183
3184 array[2] = getByU_S_PrevAndNext(session, socialRequest, userId,
3185 status, orderByComparator, false);
3186
3187 return array;
3188 }
3189 catch (Exception e) {
3190 throw processException(e);
3191 }
3192 finally {
3193 closeSession(session);
3194 }
3195 }
3196
3197 protected SocialRequest getByU_S_PrevAndNext(Session session,
3198 SocialRequest socialRequest, long userId, int status,
3199 OrderByComparator orderByComparator, boolean previous) {
3200 StringBundler query = null;
3201
3202 if (orderByComparator != null) {
3203 query = new StringBundler(6 +
3204 (orderByComparator.getOrderByFields().length * 6));
3205 }
3206 else {
3207 query = new StringBundler(3);
3208 }
3209
3210 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3211
3212 query.append(_FINDER_COLUMN_U_S_USERID_2);
3213
3214 query.append(_FINDER_COLUMN_U_S_STATUS_2);
3215
3216 if (orderByComparator != null) {
3217 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3218
3219 if (orderByConditionFields.length > 0) {
3220 query.append(WHERE_AND);
3221 }
3222
3223 for (int i = 0; i < orderByConditionFields.length; i++) {
3224 query.append(_ORDER_BY_ENTITY_ALIAS);
3225 query.append(orderByConditionFields[i]);
3226
3227 if ((i + 1) < orderByConditionFields.length) {
3228 if (orderByComparator.isAscending() ^ previous) {
3229 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3230 }
3231 else {
3232 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3233 }
3234 }
3235 else {
3236 if (orderByComparator.isAscending() ^ previous) {
3237 query.append(WHERE_GREATER_THAN);
3238 }
3239 else {
3240 query.append(WHERE_LESSER_THAN);
3241 }
3242 }
3243 }
3244
3245 query.append(ORDER_BY_CLAUSE);
3246
3247 String[] orderByFields = orderByComparator.getOrderByFields();
3248
3249 for (int i = 0; i < orderByFields.length; i++) {
3250 query.append(_ORDER_BY_ENTITY_ALIAS);
3251 query.append(orderByFields[i]);
3252
3253 if ((i + 1) < orderByFields.length) {
3254 if (orderByComparator.isAscending() ^ previous) {
3255 query.append(ORDER_BY_ASC_HAS_NEXT);
3256 }
3257 else {
3258 query.append(ORDER_BY_DESC_HAS_NEXT);
3259 }
3260 }
3261 else {
3262 if (orderByComparator.isAscending() ^ previous) {
3263 query.append(ORDER_BY_ASC);
3264 }
3265 else {
3266 query.append(ORDER_BY_DESC);
3267 }
3268 }
3269 }
3270 }
3271 else {
3272 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3273 }
3274
3275 String sql = query.toString();
3276
3277 Query q = session.createQuery(sql);
3278
3279 q.setFirstResult(0);
3280 q.setMaxResults(2);
3281
3282 QueryPos qPos = QueryPos.getInstance(q);
3283
3284 qPos.add(userId);
3285
3286 qPos.add(status);
3287
3288 if (orderByComparator != null) {
3289 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
3290
3291 for (Object value : values) {
3292 qPos.add(value);
3293 }
3294 }
3295
3296 List<SocialRequest> list = q.list();
3297
3298 if (list.size() == 2) {
3299 return list.get(1);
3300 }
3301 else {
3302 return null;
3303 }
3304 }
3305
3306
3313 public void removeByU_S(long userId, int status) throws SystemException {
3314 for (SocialRequest socialRequest : findByU_S(userId, status,
3315 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3316 remove(socialRequest);
3317 }
3318 }
3319
3320
3328 public int countByU_S(long userId, int status) throws SystemException {
3329 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_S;
3330
3331 Object[] finderArgs = new Object[] { userId, status };
3332
3333 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3334 this);
3335
3336 if (count == null) {
3337 StringBundler query = new StringBundler(3);
3338
3339 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3340
3341 query.append(_FINDER_COLUMN_U_S_USERID_2);
3342
3343 query.append(_FINDER_COLUMN_U_S_STATUS_2);
3344
3345 String sql = query.toString();
3346
3347 Session session = null;
3348
3349 try {
3350 session = openSession();
3351
3352 Query q = session.createQuery(sql);
3353
3354 QueryPos qPos = QueryPos.getInstance(q);
3355
3356 qPos.add(userId);
3357
3358 qPos.add(status);
3359
3360 count = (Long)q.uniqueResult();
3361
3362 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3363 }
3364 catch (Exception e) {
3365 FinderCacheUtil.removeResult(finderPath, finderArgs);
3366
3367 throw processException(e);
3368 }
3369 finally {
3370 closeSession(session);
3371 }
3372 }
3373
3374 return count.intValue();
3375 }
3376
3377 private static final String _FINDER_COLUMN_U_S_USERID_2 = "socialRequest.userId = ? AND ";
3378 private static final String _FINDER_COLUMN_U_S_STATUS_2 = "socialRequest.status = ?";
3379 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3380 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3381 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3382 "findByR_S",
3383 new String[] {
3384 Long.class.getName(), Integer.class.getName(),
3385
3386 Integer.class.getName(), Integer.class.getName(),
3387 OrderByComparator.class.getName()
3388 });
3389 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3390 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3391 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3392 "findByR_S",
3393 new String[] { Long.class.getName(), Integer.class.getName() },
3394 SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
3395 SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
3396 public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3397 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
3398 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_S",
3399 new String[] { Long.class.getName(), Integer.class.getName() });
3400
3401
3409 public List<SocialRequest> findByR_S(long receiverUserId, int status)
3410 throws SystemException {
3411 return findByR_S(receiverUserId, status, QueryUtil.ALL_POS,
3412 QueryUtil.ALL_POS, null);
3413 }
3414
3415
3429 public List<SocialRequest> findByR_S(long receiverUserId, int status,
3430 int start, int end) throws SystemException {
3431 return findByR_S(receiverUserId, status, start, end, null);
3432 }
3433
3434
3449 public List<SocialRequest> findByR_S(long receiverUserId, int status,
3450 int start, int end, OrderByComparator orderByComparator)
3451 throws SystemException {
3452 boolean pagination = true;
3453 FinderPath finderPath = null;
3454 Object[] finderArgs = null;
3455
3456 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3457 (orderByComparator == null)) {
3458 pagination = false;
3459 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S;
3460 finderArgs = new Object[] { receiverUserId, status };
3461 }
3462 else {
3463 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
3464 finderArgs = new Object[] {
3465 receiverUserId, status,
3466
3467 start, end, orderByComparator
3468 };
3469 }
3470
3471 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
3472 finderArgs, this);
3473
3474 if ((list != null) && !list.isEmpty()) {
3475 for (SocialRequest socialRequest : list) {
3476 if ((receiverUserId != socialRequest.getReceiverUserId()) ||
3477 (status != socialRequest.getStatus())) {
3478 list = null;
3479
3480 break;
3481 }
3482 }
3483 }
3484
3485 if (list == null) {
3486 StringBundler query = null;
3487
3488 if (orderByComparator != null) {
3489 query = new StringBundler(4 +
3490 (orderByComparator.getOrderByFields().length * 3));
3491 }
3492 else {
3493 query = new StringBundler(4);
3494 }
3495
3496 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3497
3498 query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
3499
3500 query.append(_FINDER_COLUMN_R_S_STATUS_2);
3501
3502 if (orderByComparator != null) {
3503 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3504 orderByComparator);
3505 }
3506 else
3507 if (pagination) {
3508 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3509 }
3510
3511 String sql = query.toString();
3512
3513 Session session = null;
3514
3515 try {
3516 session = openSession();
3517
3518 Query q = session.createQuery(sql);
3519
3520 QueryPos qPos = QueryPos.getInstance(q);
3521
3522 qPos.add(receiverUserId);
3523
3524 qPos.add(status);
3525
3526 if (!pagination) {
3527 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3528 start, end, false);
3529
3530 Collections.sort(list);
3531
3532 list = new UnmodifiableList<SocialRequest>(list);
3533 }
3534 else {
3535 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3536 start, end);
3537 }
3538
3539 cacheResult(list);
3540
3541 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3542 }
3543 catch (Exception e) {
3544 FinderCacheUtil.removeResult(finderPath, finderArgs);
3545
3546 throw processException(e);
3547 }
3548 finally {
3549 closeSession(session);
3550 }
3551 }
3552
3553 return list;
3554 }
3555
3556
3566 public SocialRequest findByR_S_First(long receiverUserId, int status,
3567 OrderByComparator orderByComparator)
3568 throws NoSuchRequestException, SystemException {
3569 SocialRequest socialRequest = fetchByR_S_First(receiverUserId, status,
3570 orderByComparator);
3571
3572 if (socialRequest != null) {
3573 return socialRequest;
3574 }
3575
3576 StringBundler msg = new StringBundler(6);
3577
3578 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3579
3580 msg.append("receiverUserId=");
3581 msg.append(receiverUserId);
3582
3583 msg.append(", status=");
3584 msg.append(status);
3585
3586 msg.append(StringPool.CLOSE_CURLY_BRACE);
3587
3588 throw new NoSuchRequestException(msg.toString());
3589 }
3590
3591
3600 public SocialRequest fetchByR_S_First(long receiverUserId, int status,
3601 OrderByComparator orderByComparator) throws SystemException {
3602 List<SocialRequest> list = findByR_S(receiverUserId, status, 0, 1,
3603 orderByComparator);
3604
3605 if (!list.isEmpty()) {
3606 return list.get(0);
3607 }
3608
3609 return null;
3610 }
3611
3612
3622 public SocialRequest findByR_S_Last(long receiverUserId, int status,
3623 OrderByComparator orderByComparator)
3624 throws NoSuchRequestException, SystemException {
3625 SocialRequest socialRequest = fetchByR_S_Last(receiverUserId, status,
3626 orderByComparator);
3627
3628 if (socialRequest != null) {
3629 return socialRequest;
3630 }
3631
3632 StringBundler msg = new StringBundler(6);
3633
3634 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3635
3636 msg.append("receiverUserId=");
3637 msg.append(receiverUserId);
3638
3639 msg.append(", status=");
3640 msg.append(status);
3641
3642 msg.append(StringPool.CLOSE_CURLY_BRACE);
3643
3644 throw new NoSuchRequestException(msg.toString());
3645 }
3646
3647
3656 public SocialRequest fetchByR_S_Last(long receiverUserId, int status,
3657 OrderByComparator orderByComparator) throws SystemException {
3658 int count = countByR_S(receiverUserId, status);
3659
3660 List<SocialRequest> list = findByR_S(receiverUserId, status, count - 1,
3661 count, orderByComparator);
3662
3663 if (!list.isEmpty()) {
3664 return list.get(0);
3665 }
3666
3667 return null;
3668 }
3669
3670
3681 public SocialRequest[] findByR_S_PrevAndNext(long requestId,
3682 long receiverUserId, int status, OrderByComparator orderByComparator)
3683 throws NoSuchRequestException, SystemException {
3684 SocialRequest socialRequest = findByPrimaryKey(requestId);
3685
3686 Session session = null;
3687
3688 try {
3689 session = openSession();
3690
3691 SocialRequest[] array = new SocialRequestImpl[3];
3692
3693 array[0] = getByR_S_PrevAndNext(session, socialRequest,
3694 receiverUserId, status, orderByComparator, true);
3695
3696 array[1] = socialRequest;
3697
3698 array[2] = getByR_S_PrevAndNext(session, socialRequest,
3699 receiverUserId, status, orderByComparator, false);
3700
3701 return array;
3702 }
3703 catch (Exception e) {
3704 throw processException(e);
3705 }
3706 finally {
3707 closeSession(session);
3708 }
3709 }
3710
3711 protected SocialRequest getByR_S_PrevAndNext(Session session,
3712 SocialRequest socialRequest, long receiverUserId, int status,
3713 OrderByComparator orderByComparator, boolean previous) {
3714 StringBundler query = null;
3715
3716 if (orderByComparator != null) {
3717 query = new StringBundler(6 +
3718 (orderByComparator.getOrderByFields().length * 6));
3719 }
3720 else {
3721 query = new StringBundler(3);
3722 }
3723
3724 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3725
3726 query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
3727
3728 query.append(_FINDER_COLUMN_R_S_STATUS_2);
3729
3730 if (orderByComparator != null) {
3731 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3732
3733 if (orderByConditionFields.length > 0) {
3734 query.append(WHERE_AND);
3735 }
3736
3737 for (int i = 0; i < orderByConditionFields.length; i++) {
3738 query.append(_ORDER_BY_ENTITY_ALIAS);
3739 query.append(orderByConditionFields[i]);
3740
3741 if ((i + 1) < orderByConditionFields.length) {
3742 if (orderByComparator.isAscending() ^ previous) {
3743 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3744 }
3745 else {
3746 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3747 }
3748 }
3749 else {
3750 if (orderByComparator.isAscending() ^ previous) {
3751 query.append(WHERE_GREATER_THAN);
3752 }
3753 else {
3754 query.append(WHERE_LESSER_THAN);
3755 }
3756 }
3757 }
3758
3759 query.append(ORDER_BY_CLAUSE);
3760
3761 String[] orderByFields = orderByComparator.getOrderByFields();
3762
3763 for (int i = 0; i < orderByFields.length; i++) {
3764 query.append(_ORDER_BY_ENTITY_ALIAS);
3765 query.append(orderByFields[i]);
3766
3767 if ((i + 1) < orderByFields.length) {
3768 if (orderByComparator.isAscending() ^ previous) {
3769 query.append(ORDER_BY_ASC_HAS_NEXT);
3770 }
3771 else {
3772 query.append(ORDER_BY_DESC_HAS_NEXT);
3773 }
3774 }
3775 else {
3776 if (orderByComparator.isAscending() ^ previous) {
3777 query.append(ORDER_BY_ASC);
3778 }
3779 else {
3780 query.append(ORDER_BY_DESC);
3781 }
3782 }
3783 }
3784 }
3785 else {
3786 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3787 }
3788
3789 String sql = query.toString();
3790
3791 Query q = session.createQuery(sql);
3792
3793 q.setFirstResult(0);
3794 q.setMaxResults(2);
3795
3796 QueryPos qPos = QueryPos.getInstance(q);
3797
3798 qPos.add(receiverUserId);
3799
3800 qPos.add(status);
3801
3802 if (orderByComparator != null) {
3803 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
3804
3805 for (Object value : values) {
3806 qPos.add(value);
3807 }
3808 }
3809
3810 List<SocialRequest> list = q.list();
3811
3812 if (list.size() == 2) {
3813 return list.get(1);
3814 }
3815 else {
3816 return null;
3817 }
3818 }
3819
3820
3827 public void removeByR_S(long receiverUserId, int status)
3828 throws SystemException {
3829 for (SocialRequest socialRequest : findByR_S(receiverUserId, status,
3830 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3831 remove(socialRequest);
3832 }
3833 }
3834
3835
3843 public int countByR_S(long receiverUserId, int status)
3844 throws SystemException {
3845 FinderPath finderPath = FINDER_PATH_COUNT_BY_R_S;
3846
3847 Object[] finderArgs = new Object[] { receiverUserId, status };
3848
3849 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3850 this);
3851
3852 if (count == null) {
3853 StringBundler query = new StringBundler(3);
3854
3855 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3856
3857 query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
3858
3859 query.append(_FINDER_COLUMN_R_S_STATUS_2);
3860
3861 String sql = query.toString();
3862
3863 Session session = null;
3864
3865 try {
3866 session = openSession();
3867
3868 Query q = session.createQuery(sql);
3869
3870 QueryPos qPos = QueryPos.getInstance(q);
3871
3872 qPos.add(receiverUserId);
3873
3874 qPos.add(status);
3875
3876 count = (Long)q.uniqueResult();
3877
3878 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3879 }
3880 catch (Exception e) {
3881 FinderCacheUtil.removeResult(finderPath, finderArgs);
3882
3883 throw processException(e);
3884 }
3885 finally {
3886 closeSession(session);
3887 }
3888 }
3889
3890 return count.intValue();
3891 }
3892
3893 private static final String _FINDER_COLUMN_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
3894 private static final String _FINDER_COLUMN_R_S_STATUS_2 = "socialRequest.status = ?";
3895 public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3896 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3897 SocialRequestImpl.class, FINDER_CLASS_NAME_ENTITY,
3898 "fetchByU_C_C_T_R",
3899 new String[] {
3900 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3901 Integer.class.getName(), Long.class.getName()
3902 },
3903 SocialRequestModelImpl.USERID_COLUMN_BITMASK |
3904 SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3905 SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
3906 SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
3907 SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
3908 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3909 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
3910 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T_R",
3911 new String[] {
3912 Long.class.getName(), Long.class.getName(), Long.class.getName(),
3913 Integer.class.getName(), Long.class.getName()
3914 });
3915
3916
3928 public SocialRequest findByU_C_C_T_R(long userId, long classNameId,
3929 long classPK, int type, long receiverUserId)
3930 throws NoSuchRequestException, SystemException {
3931 SocialRequest socialRequest = fetchByU_C_C_T_R(userId, classNameId,
3932 classPK, type, receiverUserId);
3933
3934 if (socialRequest == null) {
3935 StringBundler msg = new StringBundler(12);
3936
3937 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3938
3939 msg.append("userId=");
3940 msg.append(userId);
3941
3942 msg.append(", classNameId=");
3943 msg.append(classNameId);
3944
3945 msg.append(", classPK=");
3946 msg.append(classPK);
3947
3948 msg.append(", type=");
3949 msg.append(type);
3950
3951 msg.append(", receiverUserId=");
3952 msg.append(receiverUserId);
3953
3954 msg.append(StringPool.CLOSE_CURLY_BRACE);
3955
3956 if (_log.isWarnEnabled()) {
3957 _log.warn(msg.toString());
3958 }
3959
3960 throw new NoSuchRequestException(msg.toString());
3961 }
3962
3963 return socialRequest;
3964 }
3965
3966
3977 public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
3978 long classPK, int type, long receiverUserId) throws SystemException {
3979 return fetchByU_C_C_T_R(userId, classNameId, classPK, type,
3980 receiverUserId, true);
3981 }
3982
3983
3995 public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
3996 long classPK, int type, long receiverUserId, boolean retrieveFromCache)
3997 throws SystemException {
3998 Object[] finderArgs = new Object[] {
3999 userId, classNameId, classPK, type, receiverUserId
4000 };
4001
4002 Object result = null;
4003
4004 if (retrieveFromCache) {
4005 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4006 finderArgs, this);
4007 }
4008
4009 if (result instanceof SocialRequest) {
4010 SocialRequest socialRequest = (SocialRequest)result;
4011
4012 if ((userId != socialRequest.getUserId()) ||
4013 (classNameId != socialRequest.getClassNameId()) ||
4014 (classPK != socialRequest.getClassPK()) ||
4015 (type != socialRequest.getType()) ||
4016 (receiverUserId != socialRequest.getReceiverUserId())) {
4017 result = null;
4018 }
4019 }
4020
4021 if (result == null) {
4022 StringBundler query = new StringBundler(7);
4023
4024 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4025
4026 query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
4027
4028 query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
4029
4030 query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
4031
4032 query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
4033
4034 query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
4035
4036 String sql = query.toString();
4037
4038 Session session = null;
4039
4040 try {
4041 session = openSession();
4042
4043 Query q = session.createQuery(sql);
4044
4045 QueryPos qPos = QueryPos.getInstance(q);
4046
4047 qPos.add(userId);
4048
4049 qPos.add(classNameId);
4050
4051 qPos.add(classPK);
4052
4053 qPos.add(type);
4054
4055 qPos.add(receiverUserId);
4056
4057 List<SocialRequest> list = q.list();
4058
4059 if (list.isEmpty()) {
4060 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4061 finderArgs, list);
4062 }
4063 else {
4064 SocialRequest socialRequest = list.get(0);
4065
4066 result = socialRequest;
4067
4068 cacheResult(socialRequest);
4069
4070 if ((socialRequest.getUserId() != userId) ||
4071 (socialRequest.getClassNameId() != classNameId) ||
4072 (socialRequest.getClassPK() != classPK) ||
4073 (socialRequest.getType() != type) ||
4074 (socialRequest.getReceiverUserId() != receiverUserId)) {
4075 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4076 finderArgs, socialRequest);
4077 }
4078 }
4079 }
4080 catch (Exception e) {
4081 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4082 finderArgs);
4083
4084 throw processException(e);
4085 }
4086 finally {
4087 closeSession(session);
4088 }
4089 }
4090
4091 if (result instanceof List<?>) {
4092 return null;
4093 }
4094 else {
4095 return (SocialRequest)result;
4096 }
4097 }
4098
4099
4110 public SocialRequest removeByU_C_C_T_R(long userId, long classNameId,
4111 long classPK, int type, long receiverUserId)
4112 throws NoSuchRequestException, SystemException {
4113 SocialRequest socialRequest = findByU_C_C_T_R(userId, classNameId,
4114 classPK, type, receiverUserId);
4115
4116 return remove(socialRequest);
4117 }
4118
4119
4130 public int countByU_C_C_T_R(long userId, long classNameId, long classPK,
4131 int type, long receiverUserId) throws SystemException {
4132 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_T_R;
4133
4134 Object[] finderArgs = new Object[] {
4135 userId, classNameId, classPK, type, receiverUserId
4136 };
4137
4138 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4139 this);
4140
4141 if (count == null) {
4142 StringBundler query = new StringBundler(6);
4143
4144 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
4145
4146 query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
4147
4148 query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
4149
4150 query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
4151
4152 query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
4153
4154 query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
4155
4156 String sql = query.toString();
4157
4158 Session session = null;
4159
4160 try {
4161 session = openSession();
4162
4163 Query q = session.createQuery(sql);
4164
4165 QueryPos qPos = QueryPos.getInstance(q);
4166
4167 qPos.add(userId);
4168
4169 qPos.add(classNameId);
4170
4171 qPos.add(classPK);
4172
4173 qPos.add(type);
4174
4175 qPos.add(receiverUserId);
4176
4177 count = (Long)q.uniqueResult();
4178
4179 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4180 }
4181 catch (Exception e) {
4182 FinderCacheUtil.removeResult(finderPath, finderArgs);
4183
4184 throw processException(e);
4185 }
4186 finally {
4187 closeSession(session);
4188 }
4189 }
4190
4191 return count.intValue();
4192 }
4193
4194 private static final String _FINDER_COLUMN_U_C_C_T_R_USERID_2 = "socialRequest.userId = ? AND ";
4195 private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
4196 private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSPK_2 = "socialRequest.classPK = ? AND ";
4197 private static final String _FINDER_COLUMN_U_C_C_T_R_TYPE_2 = "socialRequest.type = ? AND ";
4198 private static final String _FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
4199 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T_S =
4200 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4201 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4202 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4203 "findByU_C_C_T_S",
4204 new String[] {
4205 Long.class.getName(), Long.class.getName(), Long.class.getName(),
4206 Integer.class.getName(), Integer.class.getName(),
4207
4208 Integer.class.getName(), Integer.class.getName(),
4209 OrderByComparator.class.getName()
4210 });
4211 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S =
4212 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4213 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4214 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4215 "findByU_C_C_T_S",
4216 new String[] {
4217 Long.class.getName(), Long.class.getName(), Long.class.getName(),
4218 Integer.class.getName(), Integer.class.getName()
4219 },
4220 SocialRequestModelImpl.USERID_COLUMN_BITMASK |
4221 SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4222 SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
4223 SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
4224 SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
4225 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4226 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
4227 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T_S",
4228 new String[] {
4229 Long.class.getName(), Long.class.getName(), Long.class.getName(),
4230 Integer.class.getName(), Integer.class.getName()
4231 });
4232
4233
4244 public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
4245 long classPK, int type, int status) throws SystemException {
4246 return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
4247 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4248 }
4249
4250
4267 public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
4268 long classPK, int type, int status, int start, int end)
4269 throws SystemException {
4270 return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
4271 start, end, null);
4272 }
4273
4274
4292 public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
4293 long classPK, int type, int status, int start, int end,
4294 OrderByComparator orderByComparator) throws SystemException {
4295 boolean pagination = true;
4296 FinderPath finderPath = null;
4297 Object[] finderArgs = null;
4298
4299 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4300 (orderByComparator == null)) {
4301 pagination = false;
4302 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S;
4303 finderArgs = new Object[] { userId, classNameId, classPK, type, status };
4304 }
4305 else {
4306 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T_S;
4307 finderArgs = new Object[] {
4308 userId, classNameId, classPK, type, status,
4309
4310 start, end, orderByComparator
4311 };
4312 }
4313
4314 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
4315 finderArgs, this);
4316
4317 if ((list != null) && !list.isEmpty()) {
4318 for (SocialRequest socialRequest : list) {
4319 if ((userId != socialRequest.getUserId()) ||
4320 (classNameId != socialRequest.getClassNameId()) ||
4321 (classPK != socialRequest.getClassPK()) ||
4322 (type != socialRequest.getType()) ||
4323 (status != socialRequest.getStatus())) {
4324 list = null;
4325
4326 break;
4327 }
4328 }
4329 }
4330
4331 if (list == null) {
4332 StringBundler query = null;
4333
4334 if (orderByComparator != null) {
4335 query = new StringBundler(7 +
4336 (orderByComparator.getOrderByFields().length * 3));
4337 }
4338 else {
4339 query = new StringBundler(7);
4340 }
4341
4342 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4343
4344 query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
4345
4346 query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
4347
4348 query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
4349
4350 query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
4351
4352 query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
4353
4354 if (orderByComparator != null) {
4355 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4356 orderByComparator);
4357 }
4358 else
4359 if (pagination) {
4360 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4361 }
4362
4363 String sql = query.toString();
4364
4365 Session session = null;
4366
4367 try {
4368 session = openSession();
4369
4370 Query q = session.createQuery(sql);
4371
4372 QueryPos qPos = QueryPos.getInstance(q);
4373
4374 qPos.add(userId);
4375
4376 qPos.add(classNameId);
4377
4378 qPos.add(classPK);
4379
4380 qPos.add(type);
4381
4382 qPos.add(status);
4383
4384 if (!pagination) {
4385 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4386 start, end, false);
4387
4388 Collections.sort(list);
4389
4390 list = new UnmodifiableList<SocialRequest>(list);
4391 }
4392 else {
4393 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4394 start, end);
4395 }
4396
4397 cacheResult(list);
4398
4399 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4400 }
4401 catch (Exception e) {
4402 FinderCacheUtil.removeResult(finderPath, finderArgs);
4403
4404 throw processException(e);
4405 }
4406 finally {
4407 closeSession(session);
4408 }
4409 }
4410
4411 return list;
4412 }
4413
4414
4427 public SocialRequest findByU_C_C_T_S_First(long userId, long classNameId,
4428 long classPK, int type, int status, OrderByComparator orderByComparator)
4429 throws NoSuchRequestException, SystemException {
4430 SocialRequest socialRequest = fetchByU_C_C_T_S_First(userId,
4431 classNameId, classPK, type, status, orderByComparator);
4432
4433 if (socialRequest != null) {
4434 return socialRequest;
4435 }
4436
4437 StringBundler msg = new StringBundler(12);
4438
4439 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4440
4441 msg.append("userId=");
4442 msg.append(userId);
4443
4444 msg.append(", classNameId=");
4445 msg.append(classNameId);
4446
4447 msg.append(", classPK=");
4448 msg.append(classPK);
4449
4450 msg.append(", type=");
4451 msg.append(type);
4452
4453 msg.append(", status=");
4454 msg.append(status);
4455
4456 msg.append(StringPool.CLOSE_CURLY_BRACE);
4457
4458 throw new NoSuchRequestException(msg.toString());
4459 }
4460
4461
4473 public SocialRequest fetchByU_C_C_T_S_First(long userId, long classNameId,
4474 long classPK, int type, int status, OrderByComparator orderByComparator)
4475 throws SystemException {
4476 List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
4477 classPK, type, status, 0, 1, orderByComparator);
4478
4479 if (!list.isEmpty()) {
4480 return list.get(0);
4481 }
4482
4483 return null;
4484 }
4485
4486
4499 public SocialRequest findByU_C_C_T_S_Last(long userId, long classNameId,
4500 long classPK, int type, int status, OrderByComparator orderByComparator)
4501 throws NoSuchRequestException, SystemException {
4502 SocialRequest socialRequest = fetchByU_C_C_T_S_Last(userId,
4503 classNameId, classPK, type, status, orderByComparator);
4504
4505 if (socialRequest != null) {
4506 return socialRequest;
4507 }
4508
4509 StringBundler msg = new StringBundler(12);
4510
4511 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4512
4513 msg.append("userId=");
4514 msg.append(userId);
4515
4516 msg.append(", classNameId=");
4517 msg.append(classNameId);
4518
4519 msg.append(", classPK=");
4520 msg.append(classPK);
4521
4522 msg.append(", type=");
4523 msg.append(type);
4524
4525 msg.append(", status=");
4526 msg.append(status);
4527
4528 msg.append(StringPool.CLOSE_CURLY_BRACE);
4529
4530 throw new NoSuchRequestException(msg.toString());
4531 }
4532
4533
4545 public SocialRequest fetchByU_C_C_T_S_Last(long userId, long classNameId,
4546 long classPK, int type, int status, OrderByComparator orderByComparator)
4547 throws SystemException {
4548 int count = countByU_C_C_T_S(userId, classNameId, classPK, type, status);
4549
4550 List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
4551 classPK, type, status, count - 1, count, orderByComparator);
4552
4553 if (!list.isEmpty()) {
4554 return list.get(0);
4555 }
4556
4557 return null;
4558 }
4559
4560
4574 public SocialRequest[] findByU_C_C_T_S_PrevAndNext(long requestId,
4575 long userId, long classNameId, long classPK, int type, int status,
4576 OrderByComparator orderByComparator)
4577 throws NoSuchRequestException, SystemException {
4578 SocialRequest socialRequest = findByPrimaryKey(requestId);
4579
4580 Session session = null;
4581
4582 try {
4583 session = openSession();
4584
4585 SocialRequest[] array = new SocialRequestImpl[3];
4586
4587 array[0] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
4588 userId, classNameId, classPK, type, status,
4589 orderByComparator, true);
4590
4591 array[1] = socialRequest;
4592
4593 array[2] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
4594 userId, classNameId, classPK, type, status,
4595 orderByComparator, false);
4596
4597 return array;
4598 }
4599 catch (Exception e) {
4600 throw processException(e);
4601 }
4602 finally {
4603 closeSession(session);
4604 }
4605 }
4606
4607 protected SocialRequest getByU_C_C_T_S_PrevAndNext(Session session,
4608 SocialRequest socialRequest, long userId, long classNameId,
4609 long classPK, int type, int status,
4610 OrderByComparator orderByComparator, boolean previous) {
4611 StringBundler query = null;
4612
4613 if (orderByComparator != null) {
4614 query = new StringBundler(6 +
4615 (orderByComparator.getOrderByFields().length * 6));
4616 }
4617 else {
4618 query = new StringBundler(3);
4619 }
4620
4621 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4622
4623 query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
4624
4625 query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
4626
4627 query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
4628
4629 query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
4630
4631 query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
4632
4633 if (orderByComparator != null) {
4634 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4635
4636 if (orderByConditionFields.length > 0) {
4637 query.append(WHERE_AND);
4638 }
4639
4640 for (int i = 0; i < orderByConditionFields.length; i++) {
4641 query.append(_ORDER_BY_ENTITY_ALIAS);
4642 query.append(orderByConditionFields[i]);
4643
4644 if ((i + 1) < orderByConditionFields.length) {
4645 if (orderByComparator.isAscending() ^ previous) {
4646 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4647 }
4648 else {
4649 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4650 }
4651 }
4652 else {
4653 if (orderByComparator.isAscending() ^ previous) {
4654 query.append(WHERE_GREATER_THAN);
4655 }
4656 else {
4657 query.append(WHERE_LESSER_THAN);
4658 }
4659 }
4660 }
4661
4662 query.append(ORDER_BY_CLAUSE);
4663
4664 String[] orderByFields = orderByComparator.getOrderByFields();
4665
4666 for (int i = 0; i < orderByFields.length; i++) {
4667 query.append(_ORDER_BY_ENTITY_ALIAS);
4668 query.append(orderByFields[i]);
4669
4670 if ((i + 1) < orderByFields.length) {
4671 if (orderByComparator.isAscending() ^ previous) {
4672 query.append(ORDER_BY_ASC_HAS_NEXT);
4673 }
4674 else {
4675 query.append(ORDER_BY_DESC_HAS_NEXT);
4676 }
4677 }
4678 else {
4679 if (orderByComparator.isAscending() ^ previous) {
4680 query.append(ORDER_BY_ASC);
4681 }
4682 else {
4683 query.append(ORDER_BY_DESC);
4684 }
4685 }
4686 }
4687 }
4688 else {
4689 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4690 }
4691
4692 String sql = query.toString();
4693
4694 Query q = session.createQuery(sql);
4695
4696 q.setFirstResult(0);
4697 q.setMaxResults(2);
4698
4699 QueryPos qPos = QueryPos.getInstance(q);
4700
4701 qPos.add(userId);
4702
4703 qPos.add(classNameId);
4704
4705 qPos.add(classPK);
4706
4707 qPos.add(type);
4708
4709 qPos.add(status);
4710
4711 if (orderByComparator != null) {
4712 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
4713
4714 for (Object value : values) {
4715 qPos.add(value);
4716 }
4717 }
4718
4719 List<SocialRequest> list = q.list();
4720
4721 if (list.size() == 2) {
4722 return list.get(1);
4723 }
4724 else {
4725 return null;
4726 }
4727 }
4728
4729
4739 public void removeByU_C_C_T_S(long userId, long classNameId, long classPK,
4740 int type, int status) throws SystemException {
4741 for (SocialRequest socialRequest : findByU_C_C_T_S(userId, classNameId,
4742 classPK, type, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4743 null)) {
4744 remove(socialRequest);
4745 }
4746 }
4747
4748
4759 public int countByU_C_C_T_S(long userId, long classNameId, long classPK,
4760 int type, int status) throws SystemException {
4761 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_T_S;
4762
4763 Object[] finderArgs = new Object[] {
4764 userId, classNameId, classPK, type, status
4765 };
4766
4767 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4768 this);
4769
4770 if (count == null) {
4771 StringBundler query = new StringBundler(6);
4772
4773 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
4774
4775 query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
4776
4777 query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
4778
4779 query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
4780
4781 query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
4782
4783 query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
4784
4785 String sql = query.toString();
4786
4787 Session session = null;
4788
4789 try {
4790 session = openSession();
4791
4792 Query q = session.createQuery(sql);
4793
4794 QueryPos qPos = QueryPos.getInstance(q);
4795
4796 qPos.add(userId);
4797
4798 qPos.add(classNameId);
4799
4800 qPos.add(classPK);
4801
4802 qPos.add(type);
4803
4804 qPos.add(status);
4805
4806 count = (Long)q.uniqueResult();
4807
4808 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4809 }
4810 catch (Exception e) {
4811 FinderCacheUtil.removeResult(finderPath, finderArgs);
4812
4813 throw processException(e);
4814 }
4815 finally {
4816 closeSession(session);
4817 }
4818 }
4819
4820 return count.intValue();
4821 }
4822
4823 private static final String _FINDER_COLUMN_U_C_C_T_S_USERID_2 = "socialRequest.userId = ? AND ";
4824 private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
4825 private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
4826 private static final String _FINDER_COLUMN_U_C_C_T_S_TYPE_2 = "socialRequest.type = ? AND ";
4827 private static final String _FINDER_COLUMN_U_C_C_T_S_STATUS_2 = "socialRequest.status = ?";
4828 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_R_S =
4829 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4830 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4831 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4832 "findByC_C_T_R_S",
4833 new String[] {
4834 Long.class.getName(), Long.class.getName(),
4835 Integer.class.getName(), Long.class.getName(),
4836 Integer.class.getName(),
4837
4838 Integer.class.getName(), Integer.class.getName(),
4839 OrderByComparator.class.getName()
4840 });
4841 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S =
4842 new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4843 SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4844 SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4845 "findByC_C_T_R_S",
4846 new String[] {
4847 Long.class.getName(), Long.class.getName(),
4848 Integer.class.getName(), Long.class.getName(),
4849 Integer.class.getName()
4850 },
4851 SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4852 SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
4853 SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
4854 SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
4855 SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
4856 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4857 SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
4858 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T_R_S",
4859 new String[] {
4860 Long.class.getName(), Long.class.getName(),
4861 Integer.class.getName(), Long.class.getName(),
4862 Integer.class.getName()
4863 });
4864
4865
4876 public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
4877 int type, long receiverUserId, int status) throws SystemException {
4878 return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
4879 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4880 }
4881
4882
4899 public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
4900 int type, long receiverUserId, int status, int start, int end)
4901 throws SystemException {
4902 return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
4903 status, start, end, null);
4904 }
4905
4906
4924 public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
4925 int type, long receiverUserId, int status, int start, int end,
4926 OrderByComparator orderByComparator) throws SystemException {
4927 boolean pagination = true;
4928 FinderPath finderPath = null;
4929 Object[] finderArgs = null;
4930
4931 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4932 (orderByComparator == null)) {
4933 pagination = false;
4934 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S;
4935 finderArgs = new Object[] {
4936 classNameId, classPK, type, receiverUserId, status
4937 };
4938 }
4939 else {
4940 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_R_S;
4941 finderArgs = new Object[] {
4942 classNameId, classPK, type, receiverUserId, status,
4943
4944 start, end, orderByComparator
4945 };
4946 }
4947
4948 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
4949 finderArgs, this);
4950
4951 if ((list != null) && !list.isEmpty()) {
4952 for (SocialRequest socialRequest : list) {
4953 if ((classNameId != socialRequest.getClassNameId()) ||
4954 (classPK != socialRequest.getClassPK()) ||
4955 (type != socialRequest.getType()) ||
4956 (receiverUserId != socialRequest.getReceiverUserId()) ||
4957 (status != socialRequest.getStatus())) {
4958 list = null;
4959
4960 break;
4961 }
4962 }
4963 }
4964
4965 if (list == null) {
4966 StringBundler query = null;
4967
4968 if (orderByComparator != null) {
4969 query = new StringBundler(7 +
4970 (orderByComparator.getOrderByFields().length * 3));
4971 }
4972 else {
4973 query = new StringBundler(7);
4974 }
4975
4976 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4977
4978 query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
4979
4980 query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
4981
4982 query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
4983
4984 query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
4985
4986 query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
4987
4988 if (orderByComparator != null) {
4989 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4990 orderByComparator);
4991 }
4992 else
4993 if (pagination) {
4994 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4995 }
4996
4997 String sql = query.toString();
4998
4999 Session session = null;
5000
5001 try {
5002 session = openSession();
5003
5004 Query q = session.createQuery(sql);
5005
5006 QueryPos qPos = QueryPos.getInstance(q);
5007
5008 qPos.add(classNameId);
5009
5010 qPos.add(classPK);
5011
5012 qPos.add(type);
5013
5014 qPos.add(receiverUserId);
5015
5016 qPos.add(status);
5017
5018 if (!pagination) {
5019 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
5020 start, end, false);
5021
5022 Collections.sort(list);
5023
5024 list = new UnmodifiableList<SocialRequest>(list);
5025 }
5026 else {
5027 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
5028 start, end);
5029 }
5030
5031 cacheResult(list);
5032
5033 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5034 }
5035 catch (Exception e) {
5036 FinderCacheUtil.removeResult(finderPath, finderArgs);
5037
5038 throw processException(e);
5039 }
5040 finally {
5041 closeSession(session);
5042 }
5043 }
5044
5045 return list;
5046 }
5047
5048
5061 public SocialRequest findByC_C_T_R_S_First(long classNameId, long classPK,
5062 int type, long receiverUserId, int status,
5063 OrderByComparator orderByComparator)
5064 throws NoSuchRequestException, SystemException {
5065 SocialRequest socialRequest = fetchByC_C_T_R_S_First(classNameId,
5066 classPK, type, receiverUserId, status, orderByComparator);
5067
5068 if (socialRequest != null) {
5069 return socialRequest;
5070 }
5071
5072 StringBundler msg = new StringBundler(12);
5073
5074 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5075
5076 msg.append("classNameId=");
5077 msg.append(classNameId);
5078
5079 msg.append(", classPK=");
5080 msg.append(classPK);
5081
5082 msg.append(", type=");
5083 msg.append(type);
5084
5085 msg.append(", receiverUserId=");
5086 msg.append(receiverUserId);
5087
5088 msg.append(", status=");
5089 msg.append(status);
5090
5091 msg.append(StringPool.CLOSE_CURLY_BRACE);
5092
5093 throw new NoSuchRequestException(msg.toString());
5094 }
5095
5096
5108 public SocialRequest fetchByC_C_T_R_S_First(long classNameId, long classPK,
5109 int type, long receiverUserId, int status,
5110 OrderByComparator orderByComparator) throws SystemException {
5111 List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
5112 receiverUserId, status, 0, 1, orderByComparator);
5113
5114 if (!list.isEmpty()) {
5115 return list.get(0);
5116 }
5117
5118 return null;
5119 }
5120
5121
5134 public SocialRequest findByC_C_T_R_S_Last(long classNameId, long classPK,
5135 int type, long receiverUserId, int status,
5136 OrderByComparator orderByComparator)
5137 throws NoSuchRequestException, SystemException {
5138 SocialRequest socialRequest = fetchByC_C_T_R_S_Last(classNameId,
5139 classPK, type, receiverUserId, status, orderByComparator);
5140
5141 if (socialRequest != null) {
5142 return socialRequest;
5143 }
5144
5145 StringBundler msg = new StringBundler(12);
5146
5147 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5148
5149 msg.append("classNameId=");
5150 msg.append(classNameId);
5151
5152 msg.append(", classPK=");
5153 msg.append(classPK);
5154
5155 msg.append(", type=");
5156 msg.append(type);
5157
5158 msg.append(", receiverUserId=");
5159 msg.append(receiverUserId);
5160
5161 msg.append(", status=");
5162 msg.append(status);
5163
5164 msg.append(StringPool.CLOSE_CURLY_BRACE);
5165
5166 throw new NoSuchRequestException(msg.toString());
5167 }
5168
5169
5181 public SocialRequest fetchByC_C_T_R_S_Last(long classNameId, long classPK,
5182 int type, long receiverUserId, int status,
5183 OrderByComparator orderByComparator) throws SystemException {
5184 int count = countByC_C_T_R_S(classNameId, classPK, type,
5185 receiverUserId, status);
5186
5187 List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
5188 receiverUserId, status, count - 1, count, orderByComparator);
5189
5190 if (!list.isEmpty()) {
5191 return list.get(0);
5192 }
5193
5194 return null;
5195 }
5196
5197
5211 public SocialRequest[] findByC_C_T_R_S_PrevAndNext(long requestId,
5212 long classNameId, long classPK, int type, long receiverUserId,
5213 int status, OrderByComparator orderByComparator)
5214 throws NoSuchRequestException, SystemException {
5215 SocialRequest socialRequest = findByPrimaryKey(requestId);
5216
5217 Session session = null;
5218
5219 try {
5220 session = openSession();
5221
5222 SocialRequest[] array = new SocialRequestImpl[3];
5223
5224 array[0] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
5225 classNameId, classPK, type, receiverUserId, status,
5226 orderByComparator, true);
5227
5228 array[1] = socialRequest;
5229
5230 array[2] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
5231 classNameId, classPK, type, receiverUserId, status,
5232 orderByComparator, false);
5233
5234 return array;
5235 }
5236 catch (Exception e) {
5237 throw processException(e);
5238 }
5239 finally {
5240 closeSession(session);
5241 }
5242 }
5243
5244 protected SocialRequest getByC_C_T_R_S_PrevAndNext(Session session,
5245 SocialRequest socialRequest, long classNameId, long classPK, int type,
5246 long receiverUserId, int status, OrderByComparator orderByComparator,
5247 boolean previous) {
5248 StringBundler query = null;
5249
5250 if (orderByComparator != null) {
5251 query = new StringBundler(6 +
5252 (orderByComparator.getOrderByFields().length * 6));
5253 }
5254 else {
5255 query = new StringBundler(3);
5256 }
5257
5258 query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
5259
5260 query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
5261
5262 query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
5263
5264 query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
5265
5266 query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
5267
5268 query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
5269
5270 if (orderByComparator != null) {
5271 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5272
5273 if (orderByConditionFields.length > 0) {
5274 query.append(WHERE_AND);
5275 }
5276
5277 for (int i = 0; i < orderByConditionFields.length; i++) {
5278 query.append(_ORDER_BY_ENTITY_ALIAS);
5279 query.append(orderByConditionFields[i]);
5280
5281 if ((i + 1) < orderByConditionFields.length) {
5282 if (orderByComparator.isAscending() ^ previous) {
5283 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5284 }
5285 else {
5286 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5287 }
5288 }
5289 else {
5290 if (orderByComparator.isAscending() ^ previous) {
5291 query.append(WHERE_GREATER_THAN);
5292 }
5293 else {
5294 query.append(WHERE_LESSER_THAN);
5295 }
5296 }
5297 }
5298
5299 query.append(ORDER_BY_CLAUSE);
5300
5301 String[] orderByFields = orderByComparator.getOrderByFields();
5302
5303 for (int i = 0; i < orderByFields.length; i++) {
5304 query.append(_ORDER_BY_ENTITY_ALIAS);
5305 query.append(orderByFields[i]);
5306
5307 if ((i + 1) < orderByFields.length) {
5308 if (orderByComparator.isAscending() ^ previous) {
5309 query.append(ORDER_BY_ASC_HAS_NEXT);
5310 }
5311 else {
5312 query.append(ORDER_BY_DESC_HAS_NEXT);
5313 }
5314 }
5315 else {
5316 if (orderByComparator.isAscending() ^ previous) {
5317 query.append(ORDER_BY_ASC);
5318 }
5319 else {
5320 query.append(ORDER_BY_DESC);
5321 }
5322 }
5323 }
5324 }
5325 else {
5326 query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
5327 }
5328
5329 String sql = query.toString();
5330
5331 Query q = session.createQuery(sql);
5332
5333 q.setFirstResult(0);
5334 q.setMaxResults(2);
5335
5336 QueryPos qPos = QueryPos.getInstance(q);
5337
5338 qPos.add(classNameId);
5339
5340 qPos.add(classPK);
5341
5342 qPos.add(type);
5343
5344 qPos.add(receiverUserId);
5345
5346 qPos.add(status);
5347
5348 if (orderByComparator != null) {
5349 Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
5350
5351 for (Object value : values) {
5352 qPos.add(value);
5353 }
5354 }
5355
5356 List<SocialRequest> list = q.list();
5357
5358 if (list.size() == 2) {
5359 return list.get(1);
5360 }
5361 else {
5362 return null;
5363 }
5364 }
5365
5366
5376 public void removeByC_C_T_R_S(long classNameId, long classPK, int type,
5377 long receiverUserId, int status) throws SystemException {
5378 for (SocialRequest socialRequest : findByC_C_T_R_S(classNameId,
5379 classPK, type, receiverUserId, status, QueryUtil.ALL_POS,
5380 QueryUtil.ALL_POS, null)) {
5381 remove(socialRequest);
5382 }
5383 }
5384
5385
5396 public int countByC_C_T_R_S(long classNameId, long classPK, int type,
5397 long receiverUserId, int status) throws SystemException {
5398 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_T_R_S;
5399
5400 Object[] finderArgs = new Object[] {
5401 classNameId, classPK, type, receiverUserId, status
5402 };
5403
5404 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5405 this);
5406
5407 if (count == null) {
5408 StringBundler query = new StringBundler(6);
5409
5410 query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5411
5412 query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
5413
5414 query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
5415
5416 query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
5417
5418 query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
5419
5420 query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
5421
5422 String sql = query.toString();
5423
5424 Session session = null;
5425
5426 try {
5427 session = openSession();
5428
5429 Query q = session.createQuery(sql);
5430
5431 QueryPos qPos = QueryPos.getInstance(q);
5432
5433 qPos.add(classNameId);
5434
5435 qPos.add(classPK);
5436
5437 qPos.add(type);
5438
5439 qPos.add(receiverUserId);
5440
5441 qPos.add(status);
5442
5443 count = (Long)q.uniqueResult();
5444
5445 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5446 }
5447 catch (Exception e) {
5448 FinderCacheUtil.removeResult(finderPath, finderArgs);
5449
5450 throw processException(e);
5451 }
5452 finally {
5453 closeSession(session);
5454 }
5455 }
5456
5457 return count.intValue();
5458 }
5459
5460 private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
5461 private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
5462 private static final String _FINDER_COLUMN_C_C_T_R_S_TYPE_2 = "socialRequest.type = ? AND ";
5463 private static final String _FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
5464 private static final String _FINDER_COLUMN_C_C_T_R_S_STATUS_2 = "socialRequest.status = ?";
5465
5466
5471 public void cacheResult(SocialRequest socialRequest) {
5472 EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5473 SocialRequestImpl.class, socialRequest.getPrimaryKey(),
5474 socialRequest);
5475
5476 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
5477 new Object[] { socialRequest.getUuid(), socialRequest.getGroupId() },
5478 socialRequest);
5479
5480 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
5481 new Object[] {
5482 socialRequest.getUserId(), socialRequest.getClassNameId(),
5483 socialRequest.getClassPK(), socialRequest.getType(),
5484 socialRequest.getReceiverUserId()
5485 }, socialRequest);
5486
5487 socialRequest.resetOriginalValues();
5488 }
5489
5490
5495 public void cacheResult(List<SocialRequest> socialRequests) {
5496 for (SocialRequest socialRequest : socialRequests) {
5497 if (EntityCacheUtil.getResult(
5498 SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5499 SocialRequestImpl.class, socialRequest.getPrimaryKey()) == null) {
5500 cacheResult(socialRequest);
5501 }
5502 else {
5503 socialRequest.resetOriginalValues();
5504 }
5505 }
5506 }
5507
5508
5515 @Override
5516 public void clearCache() {
5517 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
5518 CacheRegistryUtil.clear(SocialRequestImpl.class.getName());
5519 }
5520
5521 EntityCacheUtil.clearCache(SocialRequestImpl.class.getName());
5522
5523 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
5524 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5525 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5526 }
5527
5528
5535 @Override
5536 public void clearCache(SocialRequest socialRequest) {
5537 EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5538 SocialRequestImpl.class, socialRequest.getPrimaryKey());
5539
5540 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5541 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5542
5543 clearUniqueFindersCache(socialRequest);
5544 }
5545
5546 @Override
5547 public void clearCache(List<SocialRequest> socialRequests) {
5548 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5549 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5550
5551 for (SocialRequest socialRequest : socialRequests) {
5552 EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5553 SocialRequestImpl.class, socialRequest.getPrimaryKey());
5554
5555 clearUniqueFindersCache(socialRequest);
5556 }
5557 }
5558
5559 protected void cacheUniqueFindersCache(SocialRequest socialRequest) {
5560 if (socialRequest.isNew()) {
5561 Object[] args = new Object[] {
5562 socialRequest.getUuid(), socialRequest.getGroupId()
5563 };
5564
5565 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
5566 Long.valueOf(1));
5567 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
5568 socialRequest);
5569
5570 args = new Object[] {
5571 socialRequest.getUserId(), socialRequest.getClassNameId(),
5572 socialRequest.getClassPK(), socialRequest.getType(),
5573 socialRequest.getReceiverUserId()
5574 };
5575
5576 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args,
5577 Long.valueOf(1));
5578 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args,
5579 socialRequest);
5580 }
5581 else {
5582 SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
5583
5584 if ((socialRequestModelImpl.getColumnBitmask() &
5585 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5586 Object[] args = new Object[] {
5587 socialRequest.getUuid(), socialRequest.getGroupId()
5588 };
5589
5590 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
5591 Long.valueOf(1));
5592 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
5593 socialRequest);
5594 }
5595
5596 if ((socialRequestModelImpl.getColumnBitmask() &
5597 FINDER_PATH_FETCH_BY_U_C_C_T_R.getColumnBitmask()) != 0) {
5598 Object[] args = new Object[] {
5599 socialRequest.getUserId(),
5600 socialRequest.getClassNameId(),
5601 socialRequest.getClassPK(), socialRequest.getType(),
5602 socialRequest.getReceiverUserId()
5603 };
5604
5605 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args,
5606 Long.valueOf(1));
5607 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args,
5608 socialRequest);
5609 }
5610 }
5611 }
5612
5613 protected void clearUniqueFindersCache(SocialRequest socialRequest) {
5614 SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
5615
5616 Object[] args = new Object[] {
5617 socialRequest.getUuid(), socialRequest.getGroupId()
5618 };
5619
5620 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5621 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5622
5623 if ((socialRequestModelImpl.getColumnBitmask() &
5624 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5625 args = new Object[] {
5626 socialRequestModelImpl.getOriginalUuid(),
5627 socialRequestModelImpl.getOriginalGroupId()
5628 };
5629
5630 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5631 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5632 }
5633
5634 args = new Object[] {
5635 socialRequest.getUserId(), socialRequest.getClassNameId(),
5636 socialRequest.getClassPK(), socialRequest.getType(),
5637 socialRequest.getReceiverUserId()
5638 };
5639
5640 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args);
5641 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args);
5642
5643 if ((socialRequestModelImpl.getColumnBitmask() &
5644 FINDER_PATH_FETCH_BY_U_C_C_T_R.getColumnBitmask()) != 0) {
5645 args = new Object[] {
5646 socialRequestModelImpl.getOriginalUserId(),
5647 socialRequestModelImpl.getOriginalClassNameId(),
5648 socialRequestModelImpl.getOriginalClassPK(),
5649 socialRequestModelImpl.getOriginalType(),
5650 socialRequestModelImpl.getOriginalReceiverUserId()
5651 };
5652
5653 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args);
5654 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args);
5655 }
5656 }
5657
5658
5664 public SocialRequest create(long requestId) {
5665 SocialRequest socialRequest = new SocialRequestImpl();
5666
5667 socialRequest.setNew(true);
5668 socialRequest.setPrimaryKey(requestId);
5669
5670 String uuid = PortalUUIDUtil.generate();
5671
5672 socialRequest.setUuid(uuid);
5673
5674 return socialRequest;
5675 }
5676
5677
5685 public SocialRequest remove(long requestId)
5686 throws NoSuchRequestException, SystemException {
5687 return remove((Serializable)requestId);
5688 }
5689
5690
5698 @Override
5699 public SocialRequest remove(Serializable primaryKey)
5700 throws NoSuchRequestException, SystemException {
5701 Session session = null;
5702
5703 try {
5704 session = openSession();
5705
5706 SocialRequest socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
5707 primaryKey);
5708
5709 if (socialRequest == null) {
5710 if (_log.isWarnEnabled()) {
5711 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5712 }
5713
5714 throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5715 primaryKey);
5716 }
5717
5718 return remove(socialRequest);
5719 }
5720 catch (NoSuchRequestException nsee) {
5721 throw nsee;
5722 }
5723 catch (Exception e) {
5724 throw processException(e);
5725 }
5726 finally {
5727 closeSession(session);
5728 }
5729 }
5730
5731 @Override
5732 protected SocialRequest removeImpl(SocialRequest socialRequest)
5733 throws SystemException {
5734 socialRequest = toUnwrappedModel(socialRequest);
5735
5736 Session session = null;
5737
5738 try {
5739 session = openSession();
5740
5741 if (!session.contains(socialRequest)) {
5742 socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
5743 socialRequest.getPrimaryKeyObj());
5744 }
5745
5746 if (socialRequest != null) {
5747 session.delete(socialRequest);
5748 }
5749 }
5750 catch (Exception e) {
5751 throw processException(e);
5752 }
5753 finally {
5754 closeSession(session);
5755 }
5756
5757 if (socialRequest != null) {
5758 clearCache(socialRequest);
5759 }
5760
5761 return socialRequest;
5762 }
5763
5764 @Override
5765 public SocialRequest updateImpl(
5766 com.liferay.portlet.social.model.SocialRequest socialRequest)
5767 throws SystemException {
5768 socialRequest = toUnwrappedModel(socialRequest);
5769
5770 boolean isNew = socialRequest.isNew();
5771
5772 SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
5773
5774 if (Validator.isNull(socialRequest.getUuid())) {
5775 String uuid = PortalUUIDUtil.generate();
5776
5777 socialRequest.setUuid(uuid);
5778 }
5779
5780 Session session = null;
5781
5782 try {
5783 session = openSession();
5784
5785 if (socialRequest.isNew()) {
5786 session.save(socialRequest);
5787
5788 socialRequest.setNew(false);
5789 }
5790 else {
5791 session.merge(socialRequest);
5792 }
5793 }
5794 catch (Exception e) {
5795 throw processException(e);
5796 }
5797 finally {
5798 closeSession(session);
5799 }
5800
5801 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5802
5803 if (isNew || !SocialRequestModelImpl.COLUMN_BITMASK_ENABLED) {
5804 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5805 }
5806
5807 else {
5808 if ((socialRequestModelImpl.getColumnBitmask() &
5809 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
5810 Object[] args = new Object[] {
5811 socialRequestModelImpl.getOriginalUuid()
5812 };
5813
5814 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5815 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5816 args);
5817
5818 args = new Object[] { socialRequestModelImpl.getUuid() };
5819
5820 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
5821 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
5822 args);
5823 }
5824
5825 if ((socialRequestModelImpl.getColumnBitmask() &
5826 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
5827 Object[] args = new Object[] {
5828 socialRequestModelImpl.getOriginalUuid(),
5829 socialRequestModelImpl.getOriginalCompanyId()
5830 };
5831
5832 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5833 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5834 args);
5835
5836 args = new Object[] {
5837 socialRequestModelImpl.getUuid(),
5838 socialRequestModelImpl.getCompanyId()
5839 };
5840
5841 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
5842 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
5843 args);
5844 }
5845
5846 if ((socialRequestModelImpl.getColumnBitmask() &
5847 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
5848 Object[] args = new Object[] {
5849 socialRequestModelImpl.getOriginalCompanyId()
5850 };
5851
5852 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5853 args);
5854 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5855 args);
5856
5857 args = new Object[] { socialRequestModelImpl.getCompanyId() };
5858
5859 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
5860 args);
5861 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
5862 args);
5863 }
5864
5865 if ((socialRequestModelImpl.getColumnBitmask() &
5866 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
5867 Object[] args = new Object[] {
5868 socialRequestModelImpl.getOriginalUserId()
5869 };
5870
5871 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
5872 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
5873 args);
5874
5875 args = new Object[] { socialRequestModelImpl.getUserId() };
5876
5877 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
5878 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
5879 args);
5880 }
5881
5882 if ((socialRequestModelImpl.getColumnBitmask() &
5883 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID.getColumnBitmask()) != 0) {
5884 Object[] args = new Object[] {
5885 socialRequestModelImpl.getOriginalReceiverUserId()
5886 };
5887
5888 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
5889 args);
5890 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
5891 args);
5892
5893 args = new Object[] { socialRequestModelImpl.getReceiverUserId() };
5894
5895 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
5896 args);
5897 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
5898 args);
5899 }
5900
5901 if ((socialRequestModelImpl.getColumnBitmask() &
5902 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S.getColumnBitmask()) != 0) {
5903 Object[] args = new Object[] {
5904 socialRequestModelImpl.getOriginalUserId(),
5905 socialRequestModelImpl.getOriginalStatus()
5906 };
5907
5908 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_S, args);
5909 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S,
5910 args);
5911
5912 args = new Object[] {
5913 socialRequestModelImpl.getUserId(),
5914 socialRequestModelImpl.getStatus()
5915 };
5916
5917 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_S, args);
5918 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S,
5919 args);
5920 }
5921
5922 if ((socialRequestModelImpl.getColumnBitmask() &
5923 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
5924 Object[] args = new Object[] {
5925 socialRequestModelImpl.getOriginalReceiverUserId(),
5926 socialRequestModelImpl.getOriginalStatus()
5927 };
5928
5929 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
5930 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
5931 args);
5932
5933 args = new Object[] {
5934 socialRequestModelImpl.getReceiverUserId(),
5935 socialRequestModelImpl.getStatus()
5936 };
5937
5938 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
5939 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
5940 args);
5941 }
5942
5943 if ((socialRequestModelImpl.getColumnBitmask() &
5944 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S.getColumnBitmask()) != 0) {
5945 Object[] args = new Object[] {
5946 socialRequestModelImpl.getOriginalUserId(),
5947 socialRequestModelImpl.getOriginalClassNameId(),
5948 socialRequestModelImpl.getOriginalClassPK(),
5949 socialRequestModelImpl.getOriginalType(),
5950 socialRequestModelImpl.getOriginalStatus()
5951 };
5952
5953 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
5954 args);
5955 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S,
5956 args);
5957
5958 args = new Object[] {
5959 socialRequestModelImpl.getUserId(),
5960 socialRequestModelImpl.getClassNameId(),
5961 socialRequestModelImpl.getClassPK(),
5962 socialRequestModelImpl.getType(),
5963 socialRequestModelImpl.getStatus()
5964 };
5965
5966 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
5967 args);
5968 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S,
5969 args);
5970 }
5971
5972 if ((socialRequestModelImpl.getColumnBitmask() &
5973 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S.getColumnBitmask()) != 0) {
5974 Object[] args = new Object[] {
5975 socialRequestModelImpl.getOriginalClassNameId(),
5976 socialRequestModelImpl.getOriginalClassPK(),
5977 socialRequestModelImpl.getOriginalType(),
5978 socialRequestModelImpl.getOriginalReceiverUserId(),
5979 socialRequestModelImpl.getOriginalStatus()
5980 };
5981
5982 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
5983 args);
5984 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S,
5985 args);
5986
5987 args = new Object[] {
5988 socialRequestModelImpl.getClassNameId(),
5989 socialRequestModelImpl.getClassPK(),
5990 socialRequestModelImpl.getType(),
5991 socialRequestModelImpl.getReceiverUserId(),
5992 socialRequestModelImpl.getStatus()
5993 };
5994
5995 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
5996 args);
5997 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S,
5998 args);
5999 }
6000 }
6001
6002 EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6003 SocialRequestImpl.class, socialRequest.getPrimaryKey(),
6004 socialRequest);
6005
6006 clearUniqueFindersCache(socialRequest);
6007 cacheUniqueFindersCache(socialRequest);
6008
6009 return socialRequest;
6010 }
6011
6012 protected SocialRequest toUnwrappedModel(SocialRequest socialRequest) {
6013 if (socialRequest instanceof SocialRequestImpl) {
6014 return socialRequest;
6015 }
6016
6017 SocialRequestImpl socialRequestImpl = new SocialRequestImpl();
6018
6019 socialRequestImpl.setNew(socialRequest.isNew());
6020 socialRequestImpl.setPrimaryKey(socialRequest.getPrimaryKey());
6021
6022 socialRequestImpl.setUuid(socialRequest.getUuid());
6023 socialRequestImpl.setRequestId(socialRequest.getRequestId());
6024 socialRequestImpl.setGroupId(socialRequest.getGroupId());
6025 socialRequestImpl.setCompanyId(socialRequest.getCompanyId());
6026 socialRequestImpl.setUserId(socialRequest.getUserId());
6027 socialRequestImpl.setCreateDate(socialRequest.getCreateDate());
6028 socialRequestImpl.setModifiedDate(socialRequest.getModifiedDate());
6029 socialRequestImpl.setClassNameId(socialRequest.getClassNameId());
6030 socialRequestImpl.setClassPK(socialRequest.getClassPK());
6031 socialRequestImpl.setType(socialRequest.getType());
6032 socialRequestImpl.setExtraData(socialRequest.getExtraData());
6033 socialRequestImpl.setReceiverUserId(socialRequest.getReceiverUserId());
6034 socialRequestImpl.setStatus(socialRequest.getStatus());
6035
6036 return socialRequestImpl;
6037 }
6038
6039
6047 @Override
6048 public SocialRequest findByPrimaryKey(Serializable primaryKey)
6049 throws NoSuchRequestException, SystemException {
6050 SocialRequest socialRequest = fetchByPrimaryKey(primaryKey);
6051
6052 if (socialRequest == null) {
6053 if (_log.isWarnEnabled()) {
6054 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6055 }
6056
6057 throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6058 primaryKey);
6059 }
6060
6061 return socialRequest;
6062 }
6063
6064
6072 public SocialRequest findByPrimaryKey(long requestId)
6073 throws NoSuchRequestException, SystemException {
6074 return findByPrimaryKey((Serializable)requestId);
6075 }
6076
6077
6084 @Override
6085 public SocialRequest fetchByPrimaryKey(Serializable primaryKey)
6086 throws SystemException {
6087 SocialRequest socialRequest = (SocialRequest)EntityCacheUtil.getResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6088 SocialRequestImpl.class, primaryKey);
6089
6090 if (socialRequest == _nullSocialRequest) {
6091 return null;
6092 }
6093
6094 if (socialRequest == null) {
6095 Session session = null;
6096
6097 try {
6098 session = openSession();
6099
6100 socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
6101 primaryKey);
6102
6103 if (socialRequest != null) {
6104 cacheResult(socialRequest);
6105 }
6106 else {
6107 EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6108 SocialRequestImpl.class, primaryKey, _nullSocialRequest);
6109 }
6110 }
6111 catch (Exception e) {
6112 EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6113 SocialRequestImpl.class, primaryKey);
6114
6115 throw processException(e);
6116 }
6117 finally {
6118 closeSession(session);
6119 }
6120 }
6121
6122 return socialRequest;
6123 }
6124
6125
6132 public SocialRequest fetchByPrimaryKey(long requestId)
6133 throws SystemException {
6134 return fetchByPrimaryKey((Serializable)requestId);
6135 }
6136
6137
6143 public List<SocialRequest> findAll() throws SystemException {
6144 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6145 }
6146
6147
6159 public List<SocialRequest> findAll(int start, int end)
6160 throws SystemException {
6161 return findAll(start, end, null);
6162 }
6163
6164
6177 public List<SocialRequest> findAll(int start, int end,
6178 OrderByComparator orderByComparator) throws SystemException {
6179 boolean pagination = true;
6180 FinderPath finderPath = null;
6181 Object[] finderArgs = null;
6182
6183 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6184 (orderByComparator == null)) {
6185 pagination = false;
6186 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6187 finderArgs = FINDER_ARGS_EMPTY;
6188 }
6189 else {
6190 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6191 finderArgs = new Object[] { start, end, orderByComparator };
6192 }
6193
6194 List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
6195 finderArgs, this);
6196
6197 if (list == null) {
6198 StringBundler query = null;
6199 String sql = null;
6200
6201 if (orderByComparator != null) {
6202 query = new StringBundler(2 +
6203 (orderByComparator.getOrderByFields().length * 3));
6204
6205 query.append(_SQL_SELECT_SOCIALREQUEST);
6206
6207 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6208 orderByComparator);
6209
6210 sql = query.toString();
6211 }
6212 else {
6213 sql = _SQL_SELECT_SOCIALREQUEST;
6214
6215 if (pagination) {
6216 sql = sql.concat(SocialRequestModelImpl.ORDER_BY_JPQL);
6217 }
6218 }
6219
6220 Session session = null;
6221
6222 try {
6223 session = openSession();
6224
6225 Query q = session.createQuery(sql);
6226
6227 if (!pagination) {
6228 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
6229 start, end, false);
6230
6231 Collections.sort(list);
6232
6233 list = new UnmodifiableList<SocialRequest>(list);
6234 }
6235 else {
6236 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
6237 start, end);
6238 }
6239
6240 cacheResult(list);
6241
6242 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6243 }
6244 catch (Exception e) {
6245 FinderCacheUtil.removeResult(finderPath, finderArgs);
6246
6247 throw processException(e);
6248 }
6249 finally {
6250 closeSession(session);
6251 }
6252 }
6253
6254 return list;
6255 }
6256
6257
6262 public void removeAll() throws SystemException {
6263 for (SocialRequest socialRequest : findAll()) {
6264 remove(socialRequest);
6265 }
6266 }
6267
6268
6274 public int countAll() throws SystemException {
6275 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6276 FINDER_ARGS_EMPTY, this);
6277
6278 if (count == null) {
6279 Session session = null;
6280
6281 try {
6282 session = openSession();
6283
6284 Query q = session.createQuery(_SQL_COUNT_SOCIALREQUEST);
6285
6286 count = (Long)q.uniqueResult();
6287
6288 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6289 FINDER_ARGS_EMPTY, count);
6290 }
6291 catch (Exception e) {
6292 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
6293 FINDER_ARGS_EMPTY);
6294
6295 throw processException(e);
6296 }
6297 finally {
6298 closeSession(session);
6299 }
6300 }
6301
6302 return count.intValue();
6303 }
6304
6305 @Override
6306 protected Set<String> getBadColumnNames() {
6307 return _badColumnNames;
6308 }
6309
6310
6313 public void afterPropertiesSet() {
6314 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6315 com.liferay.portal.util.PropsUtil.get(
6316 "value.object.listener.com.liferay.portlet.social.model.SocialRequest")));
6317
6318 if (listenerClassNames.length > 0) {
6319 try {
6320 List<ModelListener<SocialRequest>> listenersList = new ArrayList<ModelListener<SocialRequest>>();
6321
6322 for (String listenerClassName : listenerClassNames) {
6323 listenersList.add((ModelListener<SocialRequest>)InstanceFactory.newInstance(
6324 getClassLoader(), listenerClassName));
6325 }
6326
6327 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6328 }
6329 catch (Exception e) {
6330 _log.error(e);
6331 }
6332 }
6333 }
6334
6335 public void destroy() {
6336 EntityCacheUtil.removeCache(SocialRequestImpl.class.getName());
6337 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6338 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6339 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6340 }
6341
6342 private static final String _SQL_SELECT_SOCIALREQUEST = "SELECT socialRequest FROM SocialRequest socialRequest";
6343 private static final String _SQL_SELECT_SOCIALREQUEST_WHERE = "SELECT socialRequest FROM SocialRequest socialRequest WHERE ";
6344 private static final String _SQL_COUNT_SOCIALREQUEST = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest";
6345 private static final String _SQL_COUNT_SOCIALREQUEST_WHERE = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest WHERE ";
6346 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRequest.";
6347 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRequest exists with the primary key ";
6348 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRequest exists with the key {";
6349 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6350 private static Log _log = LogFactoryUtil.getLog(SocialRequestPersistenceImpl.class);
6351 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6352 "uuid", "type"
6353 });
6354 private static SocialRequest _nullSocialRequest = new SocialRequestImpl() {
6355 @Override
6356 public Object clone() {
6357 return this;
6358 }
6359
6360 @Override
6361 public CacheModel<SocialRequest> toCacheModel() {
6362 return _nullSocialRequestCacheModel;
6363 }
6364 };
6365
6366 private static CacheModel<SocialRequest> _nullSocialRequestCacheModel = new CacheModel<SocialRequest>() {
6367 public SocialRequest toEntityModel() {
6368 return _nullSocialRequest;
6369 }
6370 };
6371 }