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