001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchPortletPreferencesException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCache;
022 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderCache;
024 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderPath;
026 import com.liferay.portal.kernel.dao.orm.Query;
027 import com.liferay.portal.kernel.dao.orm.QueryPos;
028 import com.liferay.portal.kernel.dao.orm.QueryUtil;
029 import com.liferay.portal.kernel.dao.orm.Session;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.PortletPreferences;
039 import com.liferay.portal.model.impl.PortletPreferencesImpl;
040 import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
041 import com.liferay.portal.service.persistence.CompanyProvider;
042 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
043 import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
044
045 import java.io.Serializable;
046
047 import java.util.Collections;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.Iterator;
051 import java.util.List;
052 import java.util.Map;
053 import java.util.Set;
054
055
067 @ProviderType
068 public class PortletPreferencesPersistenceImpl extends BasePersistenceImpl<PortletPreferences>
069 implements PortletPreferencesPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = PortletPreferencesImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
081 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
082 PortletPreferencesImpl.class,
083 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
085 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
086 PortletPreferencesImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
089 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
092 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
093 PortletPreferencesImpl.class,
094 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPlid",
095 new String[] {
096 Long.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
102 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
103 PortletPreferencesImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPlid",
105 new String[] { Long.class.getName() },
106 PortletPreferencesModelImpl.PLID_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
108 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPlid",
110 new String[] { Long.class.getName() });
111
112
118 @Override
119 public List<PortletPreferences> findByPlid(long plid) {
120 return findByPlid(plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
135 @Override
136 public List<PortletPreferences> findByPlid(long plid, int start, int end) {
137 return findByPlid(plid, start, end, null);
138 }
139
140
153 @Override
154 public List<PortletPreferences> findByPlid(long plid, int start, int end,
155 OrderByComparator<PortletPreferences> orderByComparator) {
156 return findByPlid(plid, start, end, orderByComparator, true);
157 }
158
159
173 @Override
174 public List<PortletPreferences> findByPlid(long plid, int start, int end,
175 OrderByComparator<PortletPreferences> orderByComparator,
176 boolean retrieveFromCache) {
177 boolean pagination = true;
178 FinderPath finderPath = null;
179 Object[] finderArgs = null;
180
181 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
182 (orderByComparator == null)) {
183 pagination = false;
184 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID;
185 finderArgs = new Object[] { plid };
186 }
187 else {
188 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PLID;
189 finderArgs = new Object[] { plid, start, end, orderByComparator };
190 }
191
192 List<PortletPreferences> list = null;
193
194 if (retrieveFromCache) {
195 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
196 finderArgs, this);
197
198 if ((list != null) && !list.isEmpty()) {
199 for (PortletPreferences portletPreferences : list) {
200 if ((plid != portletPreferences.getPlid())) {
201 list = null;
202
203 break;
204 }
205 }
206 }
207 }
208
209 if (list == null) {
210 StringBundler query = null;
211
212 if (orderByComparator != null) {
213 query = new StringBundler(3 +
214 (orderByComparator.getOrderByFields().length * 3));
215 }
216 else {
217 query = new StringBundler(3);
218 }
219
220 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
221
222 query.append(_FINDER_COLUMN_PLID_PLID_2);
223
224 if (orderByComparator != null) {
225 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
226 orderByComparator);
227 }
228 else
229 if (pagination) {
230 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
231 }
232
233 String sql = query.toString();
234
235 Session session = null;
236
237 try {
238 session = openSession();
239
240 Query q = session.createQuery(sql);
241
242 QueryPos qPos = QueryPos.getInstance(q);
243
244 qPos.add(plid);
245
246 if (!pagination) {
247 list = (List<PortletPreferences>)QueryUtil.list(q,
248 getDialect(), start, end, false);
249
250 Collections.sort(list);
251
252 list = Collections.unmodifiableList(list);
253 }
254 else {
255 list = (List<PortletPreferences>)QueryUtil.list(q,
256 getDialect(), start, end);
257 }
258
259 cacheResult(list);
260
261 finderCache.putResult(finderPath, finderArgs, list);
262 }
263 catch (Exception e) {
264 finderCache.removeResult(finderPath, finderArgs);
265
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271 }
272
273 return list;
274 }
275
276
284 @Override
285 public PortletPreferences findByPlid_First(long plid,
286 OrderByComparator<PortletPreferences> orderByComparator)
287 throws NoSuchPortletPreferencesException {
288 PortletPreferences portletPreferences = fetchByPlid_First(plid,
289 orderByComparator);
290
291 if (portletPreferences != null) {
292 return portletPreferences;
293 }
294
295 StringBundler msg = new StringBundler(4);
296
297 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
298
299 msg.append("plid=");
300 msg.append(plid);
301
302 msg.append(StringPool.CLOSE_CURLY_BRACE);
303
304 throw new NoSuchPortletPreferencesException(msg.toString());
305 }
306
307
314 @Override
315 public PortletPreferences fetchByPlid_First(long plid,
316 OrderByComparator<PortletPreferences> orderByComparator) {
317 List<PortletPreferences> list = findByPlid(plid, 0, 1, orderByComparator);
318
319 if (!list.isEmpty()) {
320 return list.get(0);
321 }
322
323 return null;
324 }
325
326
334 @Override
335 public PortletPreferences findByPlid_Last(long plid,
336 OrderByComparator<PortletPreferences> orderByComparator)
337 throws NoSuchPortletPreferencesException {
338 PortletPreferences portletPreferences = fetchByPlid_Last(plid,
339 orderByComparator);
340
341 if (portletPreferences != null) {
342 return portletPreferences;
343 }
344
345 StringBundler msg = new StringBundler(4);
346
347 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
348
349 msg.append("plid=");
350 msg.append(plid);
351
352 msg.append(StringPool.CLOSE_CURLY_BRACE);
353
354 throw new NoSuchPortletPreferencesException(msg.toString());
355 }
356
357
364 @Override
365 public PortletPreferences fetchByPlid_Last(long plid,
366 OrderByComparator<PortletPreferences> orderByComparator) {
367 int count = countByPlid(plid);
368
369 if (count == 0) {
370 return null;
371 }
372
373 List<PortletPreferences> list = findByPlid(plid, count - 1, count,
374 orderByComparator);
375
376 if (!list.isEmpty()) {
377 return list.get(0);
378 }
379
380 return null;
381 }
382
383
392 @Override
393 public PortletPreferences[] findByPlid_PrevAndNext(
394 long portletPreferencesId, long plid,
395 OrderByComparator<PortletPreferences> orderByComparator)
396 throws NoSuchPortletPreferencesException {
397 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
398
399 Session session = null;
400
401 try {
402 session = openSession();
403
404 PortletPreferences[] array = new PortletPreferencesImpl[3];
405
406 array[0] = getByPlid_PrevAndNext(session, portletPreferences, plid,
407 orderByComparator, true);
408
409 array[1] = portletPreferences;
410
411 array[2] = getByPlid_PrevAndNext(session, portletPreferences, plid,
412 orderByComparator, false);
413
414 return array;
415 }
416 catch (Exception e) {
417 throw processException(e);
418 }
419 finally {
420 closeSession(session);
421 }
422 }
423
424 protected PortletPreferences getByPlid_PrevAndNext(Session session,
425 PortletPreferences portletPreferences, long plid,
426 OrderByComparator<PortletPreferences> orderByComparator,
427 boolean previous) {
428 StringBundler query = null;
429
430 if (orderByComparator != null) {
431 query = new StringBundler(6 +
432 (orderByComparator.getOrderByFields().length * 6));
433 }
434 else {
435 query = new StringBundler(3);
436 }
437
438 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
439
440 query.append(_FINDER_COLUMN_PLID_PLID_2);
441
442 if (orderByComparator != null) {
443 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
444
445 if (orderByConditionFields.length > 0) {
446 query.append(WHERE_AND);
447 }
448
449 for (int i = 0; i < orderByConditionFields.length; i++) {
450 query.append(_ORDER_BY_ENTITY_ALIAS);
451 query.append(orderByConditionFields[i]);
452
453 if ((i + 1) < orderByConditionFields.length) {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN_HAS_NEXT);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN_HAS_NEXT);
459 }
460 }
461 else {
462 if (orderByComparator.isAscending() ^ previous) {
463 query.append(WHERE_GREATER_THAN);
464 }
465 else {
466 query.append(WHERE_LESSER_THAN);
467 }
468 }
469 }
470
471 query.append(ORDER_BY_CLAUSE);
472
473 String[] orderByFields = orderByComparator.getOrderByFields();
474
475 for (int i = 0; i < orderByFields.length; i++) {
476 query.append(_ORDER_BY_ENTITY_ALIAS);
477 query.append(orderByFields[i]);
478
479 if ((i + 1) < orderByFields.length) {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC_HAS_NEXT);
482 }
483 else {
484 query.append(ORDER_BY_DESC_HAS_NEXT);
485 }
486 }
487 else {
488 if (orderByComparator.isAscending() ^ previous) {
489 query.append(ORDER_BY_ASC);
490 }
491 else {
492 query.append(ORDER_BY_DESC);
493 }
494 }
495 }
496 }
497 else {
498 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
499 }
500
501 String sql = query.toString();
502
503 Query q = session.createQuery(sql);
504
505 q.setFirstResult(0);
506 q.setMaxResults(2);
507
508 QueryPos qPos = QueryPos.getInstance(q);
509
510 qPos.add(plid);
511
512 if (orderByComparator != null) {
513 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
514
515 for (Object value : values) {
516 qPos.add(value);
517 }
518 }
519
520 List<PortletPreferences> list = q.list();
521
522 if (list.size() == 2) {
523 return list.get(1);
524 }
525 else {
526 return null;
527 }
528 }
529
530
535 @Override
536 public void removeByPlid(long plid) {
537 for (PortletPreferences portletPreferences : findByPlid(plid,
538 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
539 remove(portletPreferences);
540 }
541 }
542
543
549 @Override
550 public int countByPlid(long plid) {
551 FinderPath finderPath = FINDER_PATH_COUNT_BY_PLID;
552
553 Object[] finderArgs = new Object[] { plid };
554
555 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
556
557 if (count == null) {
558 StringBundler query = new StringBundler(2);
559
560 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
561
562 query.append(_FINDER_COLUMN_PLID_PLID_2);
563
564 String sql = query.toString();
565
566 Session session = null;
567
568 try {
569 session = openSession();
570
571 Query q = session.createQuery(sql);
572
573 QueryPos qPos = QueryPos.getInstance(q);
574
575 qPos.add(plid);
576
577 count = (Long)q.uniqueResult();
578
579 finderCache.putResult(finderPath, finderArgs, count);
580 }
581 catch (Exception e) {
582 finderCache.removeResult(finderPath, finderArgs);
583
584 throw processException(e);
585 }
586 finally {
587 closeSession(session);
588 }
589 }
590
591 return count.intValue();
592 }
593
594 private static final String _FINDER_COLUMN_PLID_PLID_2 = "portletPreferences.plid = ?";
595 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PORTLETID =
596 new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
597 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
598 PortletPreferencesImpl.class,
599 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPortletId",
600 new String[] {
601 String.class.getName(),
602
603 Integer.class.getName(), Integer.class.getName(),
604 OrderByComparator.class.getName()
605 });
606 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID =
607 new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
608 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
609 PortletPreferencesImpl.class,
610 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPortletId",
611 new String[] { String.class.getName() },
612 PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
613 public static final FinderPath FINDER_PATH_COUNT_BY_PORTLETID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
614 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPortletId",
616 new String[] { String.class.getName() });
617
618
624 @Override
625 public List<PortletPreferences> findByPortletId(String portletId) {
626 return findByPortletId(portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
627 null);
628 }
629
630
642 @Override
643 public List<PortletPreferences> findByPortletId(String portletId,
644 int start, int end) {
645 return findByPortletId(portletId, start, end, null);
646 }
647
648
661 @Override
662 public List<PortletPreferences> findByPortletId(String portletId,
663 int start, int end,
664 OrderByComparator<PortletPreferences> orderByComparator) {
665 return findByPortletId(portletId, start, end, orderByComparator, true);
666 }
667
668
682 @Override
683 public List<PortletPreferences> findByPortletId(String portletId,
684 int start, int end,
685 OrderByComparator<PortletPreferences> orderByComparator,
686 boolean retrieveFromCache) {
687 boolean pagination = true;
688 FinderPath finderPath = null;
689 Object[] finderArgs = null;
690
691 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
692 (orderByComparator == null)) {
693 pagination = false;
694 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID;
695 finderArgs = new Object[] { portletId };
696 }
697 else {
698 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PORTLETID;
699 finderArgs = new Object[] { portletId, start, end, orderByComparator };
700 }
701
702 List<PortletPreferences> list = null;
703
704 if (retrieveFromCache) {
705 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
706 finderArgs, this);
707
708 if ((list != null) && !list.isEmpty()) {
709 for (PortletPreferences portletPreferences : list) {
710 if (!Validator.equals(portletId,
711 portletPreferences.getPortletId())) {
712 list = null;
713
714 break;
715 }
716 }
717 }
718 }
719
720 if (list == null) {
721 StringBundler query = null;
722
723 if (orderByComparator != null) {
724 query = new StringBundler(3 +
725 (orderByComparator.getOrderByFields().length * 3));
726 }
727 else {
728 query = new StringBundler(3);
729 }
730
731 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
732
733 boolean bindPortletId = false;
734
735 if (portletId == null) {
736 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
737 }
738 else if (portletId.equals(StringPool.BLANK)) {
739 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
740 }
741 else {
742 bindPortletId = true;
743
744 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
745 }
746
747 if (orderByComparator != null) {
748 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
749 orderByComparator);
750 }
751 else
752 if (pagination) {
753 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
754 }
755
756 String sql = query.toString();
757
758 Session session = null;
759
760 try {
761 session = openSession();
762
763 Query q = session.createQuery(sql);
764
765 QueryPos qPos = QueryPos.getInstance(q);
766
767 if (bindPortletId) {
768 qPos.add(portletId);
769 }
770
771 if (!pagination) {
772 list = (List<PortletPreferences>)QueryUtil.list(q,
773 getDialect(), start, end, false);
774
775 Collections.sort(list);
776
777 list = Collections.unmodifiableList(list);
778 }
779 else {
780 list = (List<PortletPreferences>)QueryUtil.list(q,
781 getDialect(), start, end);
782 }
783
784 cacheResult(list);
785
786 finderCache.putResult(finderPath, finderArgs, list);
787 }
788 catch (Exception e) {
789 finderCache.removeResult(finderPath, finderArgs);
790
791 throw processException(e);
792 }
793 finally {
794 closeSession(session);
795 }
796 }
797
798 return list;
799 }
800
801
809 @Override
810 public PortletPreferences findByPortletId_First(String portletId,
811 OrderByComparator<PortletPreferences> orderByComparator)
812 throws NoSuchPortletPreferencesException {
813 PortletPreferences portletPreferences = fetchByPortletId_First(portletId,
814 orderByComparator);
815
816 if (portletPreferences != null) {
817 return portletPreferences;
818 }
819
820 StringBundler msg = new StringBundler(4);
821
822 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
823
824 msg.append("portletId=");
825 msg.append(portletId);
826
827 msg.append(StringPool.CLOSE_CURLY_BRACE);
828
829 throw new NoSuchPortletPreferencesException(msg.toString());
830 }
831
832
839 @Override
840 public PortletPreferences fetchByPortletId_First(String portletId,
841 OrderByComparator<PortletPreferences> orderByComparator) {
842 List<PortletPreferences> list = findByPortletId(portletId, 0, 1,
843 orderByComparator);
844
845 if (!list.isEmpty()) {
846 return list.get(0);
847 }
848
849 return null;
850 }
851
852
860 @Override
861 public PortletPreferences findByPortletId_Last(String portletId,
862 OrderByComparator<PortletPreferences> orderByComparator)
863 throws NoSuchPortletPreferencesException {
864 PortletPreferences portletPreferences = fetchByPortletId_Last(portletId,
865 orderByComparator);
866
867 if (portletPreferences != null) {
868 return portletPreferences;
869 }
870
871 StringBundler msg = new StringBundler(4);
872
873 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
874
875 msg.append("portletId=");
876 msg.append(portletId);
877
878 msg.append(StringPool.CLOSE_CURLY_BRACE);
879
880 throw new NoSuchPortletPreferencesException(msg.toString());
881 }
882
883
890 @Override
891 public PortletPreferences fetchByPortletId_Last(String portletId,
892 OrderByComparator<PortletPreferences> orderByComparator) {
893 int count = countByPortletId(portletId);
894
895 if (count == 0) {
896 return null;
897 }
898
899 List<PortletPreferences> list = findByPortletId(portletId, count - 1,
900 count, orderByComparator);
901
902 if (!list.isEmpty()) {
903 return list.get(0);
904 }
905
906 return null;
907 }
908
909
918 @Override
919 public PortletPreferences[] findByPortletId_PrevAndNext(
920 long portletPreferencesId, String portletId,
921 OrderByComparator<PortletPreferences> orderByComparator)
922 throws NoSuchPortletPreferencesException {
923 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
924
925 Session session = null;
926
927 try {
928 session = openSession();
929
930 PortletPreferences[] array = new PortletPreferencesImpl[3];
931
932 array[0] = getByPortletId_PrevAndNext(session, portletPreferences,
933 portletId, orderByComparator, true);
934
935 array[1] = portletPreferences;
936
937 array[2] = getByPortletId_PrevAndNext(session, portletPreferences,
938 portletId, orderByComparator, false);
939
940 return array;
941 }
942 catch (Exception e) {
943 throw processException(e);
944 }
945 finally {
946 closeSession(session);
947 }
948 }
949
950 protected PortletPreferences getByPortletId_PrevAndNext(Session session,
951 PortletPreferences portletPreferences, String portletId,
952 OrderByComparator<PortletPreferences> orderByComparator,
953 boolean previous) {
954 StringBundler query = null;
955
956 if (orderByComparator != null) {
957 query = new StringBundler(6 +
958 (orderByComparator.getOrderByFields().length * 6));
959 }
960 else {
961 query = new StringBundler(3);
962 }
963
964 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
965
966 boolean bindPortletId = false;
967
968 if (portletId == null) {
969 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
970 }
971 else if (portletId.equals(StringPool.BLANK)) {
972 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
973 }
974 else {
975 bindPortletId = true;
976
977 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
978 }
979
980 if (orderByComparator != null) {
981 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
982
983 if (orderByConditionFields.length > 0) {
984 query.append(WHERE_AND);
985 }
986
987 for (int i = 0; i < orderByConditionFields.length; i++) {
988 query.append(_ORDER_BY_ENTITY_ALIAS);
989 query.append(orderByConditionFields[i]);
990
991 if ((i + 1) < orderByConditionFields.length) {
992 if (orderByComparator.isAscending() ^ previous) {
993 query.append(WHERE_GREATER_THAN_HAS_NEXT);
994 }
995 else {
996 query.append(WHERE_LESSER_THAN_HAS_NEXT);
997 }
998 }
999 else {
1000 if (orderByComparator.isAscending() ^ previous) {
1001 query.append(WHERE_GREATER_THAN);
1002 }
1003 else {
1004 query.append(WHERE_LESSER_THAN);
1005 }
1006 }
1007 }
1008
1009 query.append(ORDER_BY_CLAUSE);
1010
1011 String[] orderByFields = orderByComparator.getOrderByFields();
1012
1013 for (int i = 0; i < orderByFields.length; i++) {
1014 query.append(_ORDER_BY_ENTITY_ALIAS);
1015 query.append(orderByFields[i]);
1016
1017 if ((i + 1) < orderByFields.length) {
1018 if (orderByComparator.isAscending() ^ previous) {
1019 query.append(ORDER_BY_ASC_HAS_NEXT);
1020 }
1021 else {
1022 query.append(ORDER_BY_DESC_HAS_NEXT);
1023 }
1024 }
1025 else {
1026 if (orderByComparator.isAscending() ^ previous) {
1027 query.append(ORDER_BY_ASC);
1028 }
1029 else {
1030 query.append(ORDER_BY_DESC);
1031 }
1032 }
1033 }
1034 }
1035 else {
1036 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1037 }
1038
1039 String sql = query.toString();
1040
1041 Query q = session.createQuery(sql);
1042
1043 q.setFirstResult(0);
1044 q.setMaxResults(2);
1045
1046 QueryPos qPos = QueryPos.getInstance(q);
1047
1048 if (bindPortletId) {
1049 qPos.add(portletId);
1050 }
1051
1052 if (orderByComparator != null) {
1053 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
1054
1055 for (Object value : values) {
1056 qPos.add(value);
1057 }
1058 }
1059
1060 List<PortletPreferences> list = q.list();
1061
1062 if (list.size() == 2) {
1063 return list.get(1);
1064 }
1065 else {
1066 return null;
1067 }
1068 }
1069
1070
1075 @Override
1076 public void removeByPortletId(String portletId) {
1077 for (PortletPreferences portletPreferences : findByPortletId(
1078 portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1079 remove(portletPreferences);
1080 }
1081 }
1082
1083
1089 @Override
1090 public int countByPortletId(String portletId) {
1091 FinderPath finderPath = FINDER_PATH_COUNT_BY_PORTLETID;
1092
1093 Object[] finderArgs = new Object[] { portletId };
1094
1095 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1096
1097 if (count == null) {
1098 StringBundler query = new StringBundler(2);
1099
1100 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1101
1102 boolean bindPortletId = false;
1103
1104 if (portletId == null) {
1105 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_1);
1106 }
1107 else if (portletId.equals(StringPool.BLANK)) {
1108 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_3);
1109 }
1110 else {
1111 bindPortletId = true;
1112
1113 query.append(_FINDER_COLUMN_PORTLETID_PORTLETID_2);
1114 }
1115
1116 String sql = query.toString();
1117
1118 Session session = null;
1119
1120 try {
1121 session = openSession();
1122
1123 Query q = session.createQuery(sql);
1124
1125 QueryPos qPos = QueryPos.getInstance(q);
1126
1127 if (bindPortletId) {
1128 qPos.add(portletId);
1129 }
1130
1131 count = (Long)q.uniqueResult();
1132
1133 finderCache.putResult(finderPath, finderArgs, count);
1134 }
1135 catch (Exception e) {
1136 finderCache.removeResult(finderPath, finderArgs);
1137
1138 throw processException(e);
1139 }
1140 finally {
1141 closeSession(session);
1142 }
1143 }
1144
1145 return count.intValue();
1146 }
1147
1148 private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_1 = "portletPreferences.portletId IS NULL";
1149 private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_2 = "portletPreferences.portletId = ?";
1150 private static final String _FINDER_COLUMN_PORTLETID_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
1151 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1152 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1153 PortletPreferencesImpl.class,
1154 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_P",
1155 new String[] {
1156 Integer.class.getName(), String.class.getName(),
1157
1158 Integer.class.getName(), Integer.class.getName(),
1159 OrderByComparator.class.getName()
1160 });
1161 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1162 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1163 PortletPreferencesImpl.class,
1164 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_P",
1165 new String[] { Integer.class.getName(), String.class.getName() },
1166 PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
1167 PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
1168 public static final FinderPath FINDER_PATH_COUNT_BY_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1169 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
1170 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_P",
1171 new String[] { Integer.class.getName(), String.class.getName() });
1172
1173
1180 @Override
1181 public List<PortletPreferences> findByO_P(int ownerType, String portletId) {
1182 return findByO_P(ownerType, portletId, QueryUtil.ALL_POS,
1183 QueryUtil.ALL_POS, null);
1184 }
1185
1186
1199 @Override
1200 public List<PortletPreferences> findByO_P(int ownerType, String portletId,
1201 int start, int end) {
1202 return findByO_P(ownerType, portletId, start, end, null);
1203 }
1204
1205
1219 @Override
1220 public List<PortletPreferences> findByO_P(int ownerType, String portletId,
1221 int start, int end,
1222 OrderByComparator<PortletPreferences> orderByComparator) {
1223 return findByO_P(ownerType, portletId, start, end, orderByComparator,
1224 true);
1225 }
1226
1227
1242 @Override
1243 public List<PortletPreferences> findByO_P(int ownerType, String portletId,
1244 int start, int end,
1245 OrderByComparator<PortletPreferences> orderByComparator,
1246 boolean retrieveFromCache) {
1247 boolean pagination = true;
1248 FinderPath finderPath = null;
1249 Object[] finderArgs = null;
1250
1251 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1252 (orderByComparator == null)) {
1253 pagination = false;
1254 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P;
1255 finderArgs = new Object[] { ownerType, portletId };
1256 }
1257 else {
1258 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P;
1259 finderArgs = new Object[] {
1260 ownerType, portletId,
1261
1262 start, end, orderByComparator
1263 };
1264 }
1265
1266 List<PortletPreferences> list = null;
1267
1268 if (retrieveFromCache) {
1269 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
1270 finderArgs, this);
1271
1272 if ((list != null) && !list.isEmpty()) {
1273 for (PortletPreferences portletPreferences : list) {
1274 if ((ownerType != portletPreferences.getOwnerType()) ||
1275 !Validator.equals(portletId,
1276 portletPreferences.getPortletId())) {
1277 list = null;
1278
1279 break;
1280 }
1281 }
1282 }
1283 }
1284
1285 if (list == null) {
1286 StringBundler query = null;
1287
1288 if (orderByComparator != null) {
1289 query = new StringBundler(4 +
1290 (orderByComparator.getOrderByFields().length * 3));
1291 }
1292 else {
1293 query = new StringBundler(4);
1294 }
1295
1296 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1297
1298 query.append(_FINDER_COLUMN_O_P_OWNERTYPE_2);
1299
1300 boolean bindPortletId = false;
1301
1302 if (portletId == null) {
1303 query.append(_FINDER_COLUMN_O_P_PORTLETID_1);
1304 }
1305 else if (portletId.equals(StringPool.BLANK)) {
1306 query.append(_FINDER_COLUMN_O_P_PORTLETID_3);
1307 }
1308 else {
1309 bindPortletId = true;
1310
1311 query.append(_FINDER_COLUMN_O_P_PORTLETID_2);
1312 }
1313
1314 if (orderByComparator != null) {
1315 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1316 orderByComparator);
1317 }
1318 else
1319 if (pagination) {
1320 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1321 }
1322
1323 String sql = query.toString();
1324
1325 Session session = null;
1326
1327 try {
1328 session = openSession();
1329
1330 Query q = session.createQuery(sql);
1331
1332 QueryPos qPos = QueryPos.getInstance(q);
1333
1334 qPos.add(ownerType);
1335
1336 if (bindPortletId) {
1337 qPos.add(portletId);
1338 }
1339
1340 if (!pagination) {
1341 list = (List<PortletPreferences>)QueryUtil.list(q,
1342 getDialect(), start, end, false);
1343
1344 Collections.sort(list);
1345
1346 list = Collections.unmodifiableList(list);
1347 }
1348 else {
1349 list = (List<PortletPreferences>)QueryUtil.list(q,
1350 getDialect(), start, end);
1351 }
1352
1353 cacheResult(list);
1354
1355 finderCache.putResult(finderPath, finderArgs, list);
1356 }
1357 catch (Exception e) {
1358 finderCache.removeResult(finderPath, finderArgs);
1359
1360 throw processException(e);
1361 }
1362 finally {
1363 closeSession(session);
1364 }
1365 }
1366
1367 return list;
1368 }
1369
1370
1379 @Override
1380 public PortletPreferences findByO_P_First(int ownerType, String portletId,
1381 OrderByComparator<PortletPreferences> orderByComparator)
1382 throws NoSuchPortletPreferencesException {
1383 PortletPreferences portletPreferences = fetchByO_P_First(ownerType,
1384 portletId, orderByComparator);
1385
1386 if (portletPreferences != null) {
1387 return portletPreferences;
1388 }
1389
1390 StringBundler msg = new StringBundler(6);
1391
1392 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1393
1394 msg.append("ownerType=");
1395 msg.append(ownerType);
1396
1397 msg.append(", portletId=");
1398 msg.append(portletId);
1399
1400 msg.append(StringPool.CLOSE_CURLY_BRACE);
1401
1402 throw new NoSuchPortletPreferencesException(msg.toString());
1403 }
1404
1405
1413 @Override
1414 public PortletPreferences fetchByO_P_First(int ownerType, String portletId,
1415 OrderByComparator<PortletPreferences> orderByComparator) {
1416 List<PortletPreferences> list = findByO_P(ownerType, portletId, 0, 1,
1417 orderByComparator);
1418
1419 if (!list.isEmpty()) {
1420 return list.get(0);
1421 }
1422
1423 return null;
1424 }
1425
1426
1435 @Override
1436 public PortletPreferences findByO_P_Last(int ownerType, String portletId,
1437 OrderByComparator<PortletPreferences> orderByComparator)
1438 throws NoSuchPortletPreferencesException {
1439 PortletPreferences portletPreferences = fetchByO_P_Last(ownerType,
1440 portletId, orderByComparator);
1441
1442 if (portletPreferences != null) {
1443 return portletPreferences;
1444 }
1445
1446 StringBundler msg = new StringBundler(6);
1447
1448 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1449
1450 msg.append("ownerType=");
1451 msg.append(ownerType);
1452
1453 msg.append(", portletId=");
1454 msg.append(portletId);
1455
1456 msg.append(StringPool.CLOSE_CURLY_BRACE);
1457
1458 throw new NoSuchPortletPreferencesException(msg.toString());
1459 }
1460
1461
1469 @Override
1470 public PortletPreferences fetchByO_P_Last(int ownerType, String portletId,
1471 OrderByComparator<PortletPreferences> orderByComparator) {
1472 int count = countByO_P(ownerType, portletId);
1473
1474 if (count == 0) {
1475 return null;
1476 }
1477
1478 List<PortletPreferences> list = findByO_P(ownerType, portletId,
1479 count - 1, count, orderByComparator);
1480
1481 if (!list.isEmpty()) {
1482 return list.get(0);
1483 }
1484
1485 return null;
1486 }
1487
1488
1498 @Override
1499 public PortletPreferences[] findByO_P_PrevAndNext(
1500 long portletPreferencesId, int ownerType, String portletId,
1501 OrderByComparator<PortletPreferences> orderByComparator)
1502 throws NoSuchPortletPreferencesException {
1503 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1504
1505 Session session = null;
1506
1507 try {
1508 session = openSession();
1509
1510 PortletPreferences[] array = new PortletPreferencesImpl[3];
1511
1512 array[0] = getByO_P_PrevAndNext(session, portletPreferences,
1513 ownerType, portletId, orderByComparator, true);
1514
1515 array[1] = portletPreferences;
1516
1517 array[2] = getByO_P_PrevAndNext(session, portletPreferences,
1518 ownerType, portletId, orderByComparator, false);
1519
1520 return array;
1521 }
1522 catch (Exception e) {
1523 throw processException(e);
1524 }
1525 finally {
1526 closeSession(session);
1527 }
1528 }
1529
1530 protected PortletPreferences getByO_P_PrevAndNext(Session session,
1531 PortletPreferences portletPreferences, int ownerType, String portletId,
1532 OrderByComparator<PortletPreferences> orderByComparator,
1533 boolean previous) {
1534 StringBundler query = null;
1535
1536 if (orderByComparator != null) {
1537 query = new StringBundler(6 +
1538 (orderByComparator.getOrderByFields().length * 6));
1539 }
1540 else {
1541 query = new StringBundler(3);
1542 }
1543
1544 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1545
1546 query.append(_FINDER_COLUMN_O_P_OWNERTYPE_2);
1547
1548 boolean bindPortletId = false;
1549
1550 if (portletId == null) {
1551 query.append(_FINDER_COLUMN_O_P_PORTLETID_1);
1552 }
1553 else if (portletId.equals(StringPool.BLANK)) {
1554 query.append(_FINDER_COLUMN_O_P_PORTLETID_3);
1555 }
1556 else {
1557 bindPortletId = true;
1558
1559 query.append(_FINDER_COLUMN_O_P_PORTLETID_2);
1560 }
1561
1562 if (orderByComparator != null) {
1563 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1564
1565 if (orderByConditionFields.length > 0) {
1566 query.append(WHERE_AND);
1567 }
1568
1569 for (int i = 0; i < orderByConditionFields.length; i++) {
1570 query.append(_ORDER_BY_ENTITY_ALIAS);
1571 query.append(orderByConditionFields[i]);
1572
1573 if ((i + 1) < orderByConditionFields.length) {
1574 if (orderByComparator.isAscending() ^ previous) {
1575 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1576 }
1577 else {
1578 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1579 }
1580 }
1581 else {
1582 if (orderByComparator.isAscending() ^ previous) {
1583 query.append(WHERE_GREATER_THAN);
1584 }
1585 else {
1586 query.append(WHERE_LESSER_THAN);
1587 }
1588 }
1589 }
1590
1591 query.append(ORDER_BY_CLAUSE);
1592
1593 String[] orderByFields = orderByComparator.getOrderByFields();
1594
1595 for (int i = 0; i < orderByFields.length; i++) {
1596 query.append(_ORDER_BY_ENTITY_ALIAS);
1597 query.append(orderByFields[i]);
1598
1599 if ((i + 1) < orderByFields.length) {
1600 if (orderByComparator.isAscending() ^ previous) {
1601 query.append(ORDER_BY_ASC_HAS_NEXT);
1602 }
1603 else {
1604 query.append(ORDER_BY_DESC_HAS_NEXT);
1605 }
1606 }
1607 else {
1608 if (orderByComparator.isAscending() ^ previous) {
1609 query.append(ORDER_BY_ASC);
1610 }
1611 else {
1612 query.append(ORDER_BY_DESC);
1613 }
1614 }
1615 }
1616 }
1617 else {
1618 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1619 }
1620
1621 String sql = query.toString();
1622
1623 Query q = session.createQuery(sql);
1624
1625 q.setFirstResult(0);
1626 q.setMaxResults(2);
1627
1628 QueryPos qPos = QueryPos.getInstance(q);
1629
1630 qPos.add(ownerType);
1631
1632 if (bindPortletId) {
1633 qPos.add(portletId);
1634 }
1635
1636 if (orderByComparator != null) {
1637 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
1638
1639 for (Object value : values) {
1640 qPos.add(value);
1641 }
1642 }
1643
1644 List<PortletPreferences> list = q.list();
1645
1646 if (list.size() == 2) {
1647 return list.get(1);
1648 }
1649 else {
1650 return null;
1651 }
1652 }
1653
1654
1660 @Override
1661 public void removeByO_P(int ownerType, String portletId) {
1662 for (PortletPreferences portletPreferences : findByO_P(ownerType,
1663 portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1664 remove(portletPreferences);
1665 }
1666 }
1667
1668
1675 @Override
1676 public int countByO_P(int ownerType, String portletId) {
1677 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_P;
1678
1679 Object[] finderArgs = new Object[] { ownerType, portletId };
1680
1681 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1682
1683 if (count == null) {
1684 StringBundler query = new StringBundler(3);
1685
1686 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1687
1688 query.append(_FINDER_COLUMN_O_P_OWNERTYPE_2);
1689
1690 boolean bindPortletId = false;
1691
1692 if (portletId == null) {
1693 query.append(_FINDER_COLUMN_O_P_PORTLETID_1);
1694 }
1695 else if (portletId.equals(StringPool.BLANK)) {
1696 query.append(_FINDER_COLUMN_O_P_PORTLETID_3);
1697 }
1698 else {
1699 bindPortletId = true;
1700
1701 query.append(_FINDER_COLUMN_O_P_PORTLETID_2);
1702 }
1703
1704 String sql = query.toString();
1705
1706 Session session = null;
1707
1708 try {
1709 session = openSession();
1710
1711 Query q = session.createQuery(sql);
1712
1713 QueryPos qPos = QueryPos.getInstance(q);
1714
1715 qPos.add(ownerType);
1716
1717 if (bindPortletId) {
1718 qPos.add(portletId);
1719 }
1720
1721 count = (Long)q.uniqueResult();
1722
1723 finderCache.putResult(finderPath, finderArgs, count);
1724 }
1725 catch (Exception e) {
1726 finderCache.removeResult(finderPath, finderArgs);
1727
1728 throw processException(e);
1729 }
1730 finally {
1731 closeSession(session);
1732 }
1733 }
1734
1735 return count.intValue();
1736 }
1737
1738 private static final String _FINDER_COLUMN_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
1739 private static final String _FINDER_COLUMN_O_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
1740 private static final String _FINDER_COLUMN_O_P_PORTLETID_2 = "portletPreferences.portletId = ?";
1741 private static final String _FINDER_COLUMN_O_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
1742 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1743 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1744 PortletPreferencesImpl.class,
1745 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByP_P",
1746 new String[] {
1747 Long.class.getName(), String.class.getName(),
1748
1749 Integer.class.getName(), Integer.class.getName(),
1750 OrderByComparator.class.getName()
1751 });
1752 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1753 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
1754 PortletPreferencesImpl.class,
1755 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByP_P",
1756 new String[] { Long.class.getName(), String.class.getName() },
1757 PortletPreferencesModelImpl.PLID_COLUMN_BITMASK |
1758 PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
1759 public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
1760 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
1761 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_P",
1762 new String[] { Long.class.getName(), String.class.getName() });
1763
1764
1771 @Override
1772 public List<PortletPreferences> findByP_P(long plid, String portletId) {
1773 return findByP_P(plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1774 null);
1775 }
1776
1777
1790 @Override
1791 public List<PortletPreferences> findByP_P(long plid, String portletId,
1792 int start, int end) {
1793 return findByP_P(plid, portletId, start, end, null);
1794 }
1795
1796
1810 @Override
1811 public List<PortletPreferences> findByP_P(long plid, String portletId,
1812 int start, int end,
1813 OrderByComparator<PortletPreferences> orderByComparator) {
1814 return findByP_P(plid, portletId, start, end, orderByComparator, true);
1815 }
1816
1817
1832 @Override
1833 public List<PortletPreferences> findByP_P(long plid, String portletId,
1834 int start, int end,
1835 OrderByComparator<PortletPreferences> orderByComparator,
1836 boolean retrieveFromCache) {
1837 boolean pagination = true;
1838 FinderPath finderPath = null;
1839 Object[] finderArgs = null;
1840
1841 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1842 (orderByComparator == null)) {
1843 pagination = false;
1844 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P;
1845 finderArgs = new Object[] { plid, portletId };
1846 }
1847 else {
1848 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_P_P;
1849 finderArgs = new Object[] {
1850 plid, portletId,
1851
1852 start, end, orderByComparator
1853 };
1854 }
1855
1856 List<PortletPreferences> list = null;
1857
1858 if (retrieveFromCache) {
1859 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
1860 finderArgs, this);
1861
1862 if ((list != null) && !list.isEmpty()) {
1863 for (PortletPreferences portletPreferences : list) {
1864 if ((plid != portletPreferences.getPlid()) ||
1865 !Validator.equals(portletId,
1866 portletPreferences.getPortletId())) {
1867 list = null;
1868
1869 break;
1870 }
1871 }
1872 }
1873 }
1874
1875 if (list == null) {
1876 StringBundler query = null;
1877
1878 if (orderByComparator != null) {
1879 query = new StringBundler(4 +
1880 (orderByComparator.getOrderByFields().length * 3));
1881 }
1882 else {
1883 query = new StringBundler(4);
1884 }
1885
1886 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1887
1888 query.append(_FINDER_COLUMN_P_P_PLID_2);
1889
1890 boolean bindPortletId = false;
1891
1892 if (portletId == null) {
1893 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
1894 }
1895 else if (portletId.equals(StringPool.BLANK)) {
1896 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
1897 }
1898 else {
1899 bindPortletId = true;
1900
1901 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
1902 }
1903
1904 if (orderByComparator != null) {
1905 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1906 orderByComparator);
1907 }
1908 else
1909 if (pagination) {
1910 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
1911 }
1912
1913 String sql = query.toString();
1914
1915 Session session = null;
1916
1917 try {
1918 session = openSession();
1919
1920 Query q = session.createQuery(sql);
1921
1922 QueryPos qPos = QueryPos.getInstance(q);
1923
1924 qPos.add(plid);
1925
1926 if (bindPortletId) {
1927 qPos.add(portletId);
1928 }
1929
1930 if (!pagination) {
1931 list = (List<PortletPreferences>)QueryUtil.list(q,
1932 getDialect(), start, end, false);
1933
1934 Collections.sort(list);
1935
1936 list = Collections.unmodifiableList(list);
1937 }
1938 else {
1939 list = (List<PortletPreferences>)QueryUtil.list(q,
1940 getDialect(), start, end);
1941 }
1942
1943 cacheResult(list);
1944
1945 finderCache.putResult(finderPath, finderArgs, list);
1946 }
1947 catch (Exception e) {
1948 finderCache.removeResult(finderPath, finderArgs);
1949
1950 throw processException(e);
1951 }
1952 finally {
1953 closeSession(session);
1954 }
1955 }
1956
1957 return list;
1958 }
1959
1960
1969 @Override
1970 public PortletPreferences findByP_P_First(long plid, String portletId,
1971 OrderByComparator<PortletPreferences> orderByComparator)
1972 throws NoSuchPortletPreferencesException {
1973 PortletPreferences portletPreferences = fetchByP_P_First(plid,
1974 portletId, orderByComparator);
1975
1976 if (portletPreferences != null) {
1977 return portletPreferences;
1978 }
1979
1980 StringBundler msg = new StringBundler(6);
1981
1982 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1983
1984 msg.append("plid=");
1985 msg.append(plid);
1986
1987 msg.append(", portletId=");
1988 msg.append(portletId);
1989
1990 msg.append(StringPool.CLOSE_CURLY_BRACE);
1991
1992 throw new NoSuchPortletPreferencesException(msg.toString());
1993 }
1994
1995
2003 @Override
2004 public PortletPreferences fetchByP_P_First(long plid, String portletId,
2005 OrderByComparator<PortletPreferences> orderByComparator) {
2006 List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1,
2007 orderByComparator);
2008
2009 if (!list.isEmpty()) {
2010 return list.get(0);
2011 }
2012
2013 return null;
2014 }
2015
2016
2025 @Override
2026 public PortletPreferences findByP_P_Last(long plid, String portletId,
2027 OrderByComparator<PortletPreferences> orderByComparator)
2028 throws NoSuchPortletPreferencesException {
2029 PortletPreferences portletPreferences = fetchByP_P_Last(plid,
2030 portletId, orderByComparator);
2031
2032 if (portletPreferences != null) {
2033 return portletPreferences;
2034 }
2035
2036 StringBundler msg = new StringBundler(6);
2037
2038 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2039
2040 msg.append("plid=");
2041 msg.append(plid);
2042
2043 msg.append(", portletId=");
2044 msg.append(portletId);
2045
2046 msg.append(StringPool.CLOSE_CURLY_BRACE);
2047
2048 throw new NoSuchPortletPreferencesException(msg.toString());
2049 }
2050
2051
2059 @Override
2060 public PortletPreferences fetchByP_P_Last(long plid, String portletId,
2061 OrderByComparator<PortletPreferences> orderByComparator) {
2062 int count = countByP_P(plid, portletId);
2063
2064 if (count == 0) {
2065 return null;
2066 }
2067
2068 List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
2069 count, orderByComparator);
2070
2071 if (!list.isEmpty()) {
2072 return list.get(0);
2073 }
2074
2075 return null;
2076 }
2077
2078
2088 @Override
2089 public PortletPreferences[] findByP_P_PrevAndNext(
2090 long portletPreferencesId, long plid, String portletId,
2091 OrderByComparator<PortletPreferences> orderByComparator)
2092 throws NoSuchPortletPreferencesException {
2093 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
2094
2095 Session session = null;
2096
2097 try {
2098 session = openSession();
2099
2100 PortletPreferences[] array = new PortletPreferencesImpl[3];
2101
2102 array[0] = getByP_P_PrevAndNext(session, portletPreferences, plid,
2103 portletId, orderByComparator, true);
2104
2105 array[1] = portletPreferences;
2106
2107 array[2] = getByP_P_PrevAndNext(session, portletPreferences, plid,
2108 portletId, orderByComparator, false);
2109
2110 return array;
2111 }
2112 catch (Exception e) {
2113 throw processException(e);
2114 }
2115 finally {
2116 closeSession(session);
2117 }
2118 }
2119
2120 protected PortletPreferences getByP_P_PrevAndNext(Session session,
2121 PortletPreferences portletPreferences, long plid, String portletId,
2122 OrderByComparator<PortletPreferences> orderByComparator,
2123 boolean previous) {
2124 StringBundler query = null;
2125
2126 if (orderByComparator != null) {
2127 query = new StringBundler(6 +
2128 (orderByComparator.getOrderByFields().length * 6));
2129 }
2130 else {
2131 query = new StringBundler(3);
2132 }
2133
2134 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
2135
2136 query.append(_FINDER_COLUMN_P_P_PLID_2);
2137
2138 boolean bindPortletId = false;
2139
2140 if (portletId == null) {
2141 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
2142 }
2143 else if (portletId.equals(StringPool.BLANK)) {
2144 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
2145 }
2146 else {
2147 bindPortletId = true;
2148
2149 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
2150 }
2151
2152 if (orderByComparator != null) {
2153 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2154
2155 if (orderByConditionFields.length > 0) {
2156 query.append(WHERE_AND);
2157 }
2158
2159 for (int i = 0; i < orderByConditionFields.length; i++) {
2160 query.append(_ORDER_BY_ENTITY_ALIAS);
2161 query.append(orderByConditionFields[i]);
2162
2163 if ((i + 1) < orderByConditionFields.length) {
2164 if (orderByComparator.isAscending() ^ previous) {
2165 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2166 }
2167 else {
2168 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2169 }
2170 }
2171 else {
2172 if (orderByComparator.isAscending() ^ previous) {
2173 query.append(WHERE_GREATER_THAN);
2174 }
2175 else {
2176 query.append(WHERE_LESSER_THAN);
2177 }
2178 }
2179 }
2180
2181 query.append(ORDER_BY_CLAUSE);
2182
2183 String[] orderByFields = orderByComparator.getOrderByFields();
2184
2185 for (int i = 0; i < orderByFields.length; i++) {
2186 query.append(_ORDER_BY_ENTITY_ALIAS);
2187 query.append(orderByFields[i]);
2188
2189 if ((i + 1) < orderByFields.length) {
2190 if (orderByComparator.isAscending() ^ previous) {
2191 query.append(ORDER_BY_ASC_HAS_NEXT);
2192 }
2193 else {
2194 query.append(ORDER_BY_DESC_HAS_NEXT);
2195 }
2196 }
2197 else {
2198 if (orderByComparator.isAscending() ^ previous) {
2199 query.append(ORDER_BY_ASC);
2200 }
2201 else {
2202 query.append(ORDER_BY_DESC);
2203 }
2204 }
2205 }
2206 }
2207 else {
2208 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
2209 }
2210
2211 String sql = query.toString();
2212
2213 Query q = session.createQuery(sql);
2214
2215 q.setFirstResult(0);
2216 q.setMaxResults(2);
2217
2218 QueryPos qPos = QueryPos.getInstance(q);
2219
2220 qPos.add(plid);
2221
2222 if (bindPortletId) {
2223 qPos.add(portletId);
2224 }
2225
2226 if (orderByComparator != null) {
2227 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
2228
2229 for (Object value : values) {
2230 qPos.add(value);
2231 }
2232 }
2233
2234 List<PortletPreferences> list = q.list();
2235
2236 if (list.size() == 2) {
2237 return list.get(1);
2238 }
2239 else {
2240 return null;
2241 }
2242 }
2243
2244
2250 @Override
2251 public void removeByP_P(long plid, String portletId) {
2252 for (PortletPreferences portletPreferences : findByP_P(plid, portletId,
2253 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2254 remove(portletPreferences);
2255 }
2256 }
2257
2258
2265 @Override
2266 public int countByP_P(long plid, String portletId) {
2267 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_P;
2268
2269 Object[] finderArgs = new Object[] { plid, portletId };
2270
2271 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2272
2273 if (count == null) {
2274 StringBundler query = new StringBundler(3);
2275
2276 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2277
2278 query.append(_FINDER_COLUMN_P_P_PLID_2);
2279
2280 boolean bindPortletId = false;
2281
2282 if (portletId == null) {
2283 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
2284 }
2285 else if (portletId.equals(StringPool.BLANK)) {
2286 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
2287 }
2288 else {
2289 bindPortletId = true;
2290
2291 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
2292 }
2293
2294 String sql = query.toString();
2295
2296 Session session = null;
2297
2298 try {
2299 session = openSession();
2300
2301 Query q = session.createQuery(sql);
2302
2303 QueryPos qPos = QueryPos.getInstance(q);
2304
2305 qPos.add(plid);
2306
2307 if (bindPortletId) {
2308 qPos.add(portletId);
2309 }
2310
2311 count = (Long)q.uniqueResult();
2312
2313 finderCache.putResult(finderPath, finderArgs, count);
2314 }
2315 catch (Exception e) {
2316 finderCache.removeResult(finderPath, finderArgs);
2317
2318 throw processException(e);
2319 }
2320 finally {
2321 closeSession(session);
2322 }
2323 }
2324
2325 return count.intValue();
2326 }
2327
2328 private static final String _FINDER_COLUMN_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
2329 private static final String _FINDER_COLUMN_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
2330 private static final String _FINDER_COLUMN_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
2331 private static final String _FINDER_COLUMN_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
2332 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2333 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2334 PortletPreferencesImpl.class,
2335 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_O_P",
2336 new String[] {
2337 Long.class.getName(), Integer.class.getName(),
2338 Long.class.getName(),
2339
2340 Integer.class.getName(), Integer.class.getName(),
2341 OrderByComparator.class.getName()
2342 });
2343 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2344 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2345 PortletPreferencesImpl.class,
2346 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_O_P",
2347 new String[] {
2348 Long.class.getName(), Integer.class.getName(),
2349 Long.class.getName()
2350 },
2351 PortletPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
2352 PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
2353 PortletPreferencesModelImpl.PLID_COLUMN_BITMASK);
2354 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2355 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
2356 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O_P",
2357 new String[] {
2358 Long.class.getName(), Integer.class.getName(),
2359 Long.class.getName()
2360 });
2361
2362
2370 @Override
2371 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2372 long plid) {
2373 return findByO_O_P(ownerId, ownerType, plid, QueryUtil.ALL_POS,
2374 QueryUtil.ALL_POS, null);
2375 }
2376
2377
2391 @Override
2392 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2393 long plid, int start, int end) {
2394 return findByO_O_P(ownerId, ownerType, plid, start, end, null);
2395 }
2396
2397
2412 @Override
2413 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2414 long plid, int start, int end,
2415 OrderByComparator<PortletPreferences> orderByComparator) {
2416 return findByO_O_P(ownerId, ownerType, plid, start, end,
2417 orderByComparator, true);
2418 }
2419
2420
2436 @Override
2437 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
2438 long plid, int start, int end,
2439 OrderByComparator<PortletPreferences> orderByComparator,
2440 boolean retrieveFromCache) {
2441 boolean pagination = true;
2442 FinderPath finderPath = null;
2443 Object[] finderArgs = null;
2444
2445 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2446 (orderByComparator == null)) {
2447 pagination = false;
2448 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P;
2449 finderArgs = new Object[] { ownerId, ownerType, plid };
2450 }
2451 else {
2452 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_P;
2453 finderArgs = new Object[] {
2454 ownerId, ownerType, plid,
2455
2456 start, end, orderByComparator
2457 };
2458 }
2459
2460 List<PortletPreferences> list = null;
2461
2462 if (retrieveFromCache) {
2463 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
2464 finderArgs, this);
2465
2466 if ((list != null) && !list.isEmpty()) {
2467 for (PortletPreferences portletPreferences : list) {
2468 if ((ownerId != portletPreferences.getOwnerId()) ||
2469 (ownerType != portletPreferences.getOwnerType()) ||
2470 (plid != portletPreferences.getPlid())) {
2471 list = null;
2472
2473 break;
2474 }
2475 }
2476 }
2477 }
2478
2479 if (list == null) {
2480 StringBundler query = null;
2481
2482 if (orderByComparator != null) {
2483 query = new StringBundler(5 +
2484 (orderByComparator.getOrderByFields().length * 3));
2485 }
2486 else {
2487 query = new StringBundler(5);
2488 }
2489
2490 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
2491
2492 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2493
2494 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2495
2496 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2497
2498 if (orderByComparator != null) {
2499 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2500 orderByComparator);
2501 }
2502 else
2503 if (pagination) {
2504 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
2505 }
2506
2507 String sql = query.toString();
2508
2509 Session session = null;
2510
2511 try {
2512 session = openSession();
2513
2514 Query q = session.createQuery(sql);
2515
2516 QueryPos qPos = QueryPos.getInstance(q);
2517
2518 qPos.add(ownerId);
2519
2520 qPos.add(ownerType);
2521
2522 qPos.add(plid);
2523
2524 if (!pagination) {
2525 list = (List<PortletPreferences>)QueryUtil.list(q,
2526 getDialect(), start, end, false);
2527
2528 Collections.sort(list);
2529
2530 list = Collections.unmodifiableList(list);
2531 }
2532 else {
2533 list = (List<PortletPreferences>)QueryUtil.list(q,
2534 getDialect(), start, end);
2535 }
2536
2537 cacheResult(list);
2538
2539 finderCache.putResult(finderPath, finderArgs, list);
2540 }
2541 catch (Exception e) {
2542 finderCache.removeResult(finderPath, finderArgs);
2543
2544 throw processException(e);
2545 }
2546 finally {
2547 closeSession(session);
2548 }
2549 }
2550
2551 return list;
2552 }
2553
2554
2564 @Override
2565 public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
2566 long plid, OrderByComparator<PortletPreferences> orderByComparator)
2567 throws NoSuchPortletPreferencesException {
2568 PortletPreferences portletPreferences = fetchByO_O_P_First(ownerId,
2569 ownerType, plid, orderByComparator);
2570
2571 if (portletPreferences != null) {
2572 return portletPreferences;
2573 }
2574
2575 StringBundler msg = new StringBundler(8);
2576
2577 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2578
2579 msg.append("ownerId=");
2580 msg.append(ownerId);
2581
2582 msg.append(", ownerType=");
2583 msg.append(ownerType);
2584
2585 msg.append(", plid=");
2586 msg.append(plid);
2587
2588 msg.append(StringPool.CLOSE_CURLY_BRACE);
2589
2590 throw new NoSuchPortletPreferencesException(msg.toString());
2591 }
2592
2593
2602 @Override
2603 public PortletPreferences fetchByO_O_P_First(long ownerId, int ownerType,
2604 long plid, OrderByComparator<PortletPreferences> orderByComparator) {
2605 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
2606 0, 1, orderByComparator);
2607
2608 if (!list.isEmpty()) {
2609 return list.get(0);
2610 }
2611
2612 return null;
2613 }
2614
2615
2625 @Override
2626 public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
2627 long plid, OrderByComparator<PortletPreferences> orderByComparator)
2628 throws NoSuchPortletPreferencesException {
2629 PortletPreferences portletPreferences = fetchByO_O_P_Last(ownerId,
2630 ownerType, plid, orderByComparator);
2631
2632 if (portletPreferences != null) {
2633 return portletPreferences;
2634 }
2635
2636 StringBundler msg = new StringBundler(8);
2637
2638 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2639
2640 msg.append("ownerId=");
2641 msg.append(ownerId);
2642
2643 msg.append(", ownerType=");
2644 msg.append(ownerType);
2645
2646 msg.append(", plid=");
2647 msg.append(plid);
2648
2649 msg.append(StringPool.CLOSE_CURLY_BRACE);
2650
2651 throw new NoSuchPortletPreferencesException(msg.toString());
2652 }
2653
2654
2663 @Override
2664 public PortletPreferences fetchByO_O_P_Last(long ownerId, int ownerType,
2665 long plid, OrderByComparator<PortletPreferences> orderByComparator) {
2666 int count = countByO_O_P(ownerId, ownerType, plid);
2667
2668 if (count == 0) {
2669 return null;
2670 }
2671
2672 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
2673 count - 1, count, orderByComparator);
2674
2675 if (!list.isEmpty()) {
2676 return list.get(0);
2677 }
2678
2679 return null;
2680 }
2681
2682
2693 @Override
2694 public PortletPreferences[] findByO_O_P_PrevAndNext(
2695 long portletPreferencesId, long ownerId, int ownerType, long plid,
2696 OrderByComparator<PortletPreferences> orderByComparator)
2697 throws NoSuchPortletPreferencesException {
2698 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
2699
2700 Session session = null;
2701
2702 try {
2703 session = openSession();
2704
2705 PortletPreferences[] array = new PortletPreferencesImpl[3];
2706
2707 array[0] = getByO_O_P_PrevAndNext(session, portletPreferences,
2708 ownerId, ownerType, plid, orderByComparator, true);
2709
2710 array[1] = portletPreferences;
2711
2712 array[2] = getByO_O_P_PrevAndNext(session, portletPreferences,
2713 ownerId, ownerType, plid, orderByComparator, false);
2714
2715 return array;
2716 }
2717 catch (Exception e) {
2718 throw processException(e);
2719 }
2720 finally {
2721 closeSession(session);
2722 }
2723 }
2724
2725 protected PortletPreferences getByO_O_P_PrevAndNext(Session session,
2726 PortletPreferences portletPreferences, long ownerId, int ownerType,
2727 long plid, OrderByComparator<PortletPreferences> orderByComparator,
2728 boolean previous) {
2729 StringBundler query = null;
2730
2731 if (orderByComparator != null) {
2732 query = new StringBundler(6 +
2733 (orderByComparator.getOrderByFields().length * 6));
2734 }
2735 else {
2736 query = new StringBundler(3);
2737 }
2738
2739 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
2740
2741 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2742
2743 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2744
2745 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2746
2747 if (orderByComparator != null) {
2748 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2749
2750 if (orderByConditionFields.length > 0) {
2751 query.append(WHERE_AND);
2752 }
2753
2754 for (int i = 0; i < orderByConditionFields.length; i++) {
2755 query.append(_ORDER_BY_ENTITY_ALIAS);
2756 query.append(orderByConditionFields[i]);
2757
2758 if ((i + 1) < orderByConditionFields.length) {
2759 if (orderByComparator.isAscending() ^ previous) {
2760 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2761 }
2762 else {
2763 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2764 }
2765 }
2766 else {
2767 if (orderByComparator.isAscending() ^ previous) {
2768 query.append(WHERE_GREATER_THAN);
2769 }
2770 else {
2771 query.append(WHERE_LESSER_THAN);
2772 }
2773 }
2774 }
2775
2776 query.append(ORDER_BY_CLAUSE);
2777
2778 String[] orderByFields = orderByComparator.getOrderByFields();
2779
2780 for (int i = 0; i < orderByFields.length; i++) {
2781 query.append(_ORDER_BY_ENTITY_ALIAS);
2782 query.append(orderByFields[i]);
2783
2784 if ((i + 1) < orderByFields.length) {
2785 if (orderByComparator.isAscending() ^ previous) {
2786 query.append(ORDER_BY_ASC_HAS_NEXT);
2787 }
2788 else {
2789 query.append(ORDER_BY_DESC_HAS_NEXT);
2790 }
2791 }
2792 else {
2793 if (orderByComparator.isAscending() ^ previous) {
2794 query.append(ORDER_BY_ASC);
2795 }
2796 else {
2797 query.append(ORDER_BY_DESC);
2798 }
2799 }
2800 }
2801 }
2802 else {
2803 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
2804 }
2805
2806 String sql = query.toString();
2807
2808 Query q = session.createQuery(sql);
2809
2810 q.setFirstResult(0);
2811 q.setMaxResults(2);
2812
2813 QueryPos qPos = QueryPos.getInstance(q);
2814
2815 qPos.add(ownerId);
2816
2817 qPos.add(ownerType);
2818
2819 qPos.add(plid);
2820
2821 if (orderByComparator != null) {
2822 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
2823
2824 for (Object value : values) {
2825 qPos.add(value);
2826 }
2827 }
2828
2829 List<PortletPreferences> list = q.list();
2830
2831 if (list.size() == 2) {
2832 return list.get(1);
2833 }
2834 else {
2835 return null;
2836 }
2837 }
2838
2839
2846 @Override
2847 public void removeByO_O_P(long ownerId, int ownerType, long plid) {
2848 for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
2849 ownerType, plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2850 remove(portletPreferences);
2851 }
2852 }
2853
2854
2862 @Override
2863 public int countByO_O_P(long ownerId, int ownerType, long plid) {
2864 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O_P;
2865
2866 Object[] finderArgs = new Object[] { ownerId, ownerType, plid };
2867
2868 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2869
2870 if (count == null) {
2871 StringBundler query = new StringBundler(4);
2872
2873 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2874
2875 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2876
2877 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2878
2879 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2880
2881 String sql = query.toString();
2882
2883 Session session = null;
2884
2885 try {
2886 session = openSession();
2887
2888 Query q = session.createQuery(sql);
2889
2890 QueryPos qPos = QueryPos.getInstance(q);
2891
2892 qPos.add(ownerId);
2893
2894 qPos.add(ownerType);
2895
2896 qPos.add(plid);
2897
2898 count = (Long)q.uniqueResult();
2899
2900 finderCache.putResult(finderPath, finderArgs, count);
2901 }
2902 catch (Exception e) {
2903 finderCache.removeResult(finderPath, finderArgs);
2904
2905 throw processException(e);
2906 }
2907 finally {
2908 closeSession(session);
2909 }
2910 }
2911
2912 return count.intValue();
2913 }
2914
2915 private static final String _FINDER_COLUMN_O_O_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
2916 private static final String _FINDER_COLUMN_O_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
2917 private static final String _FINDER_COLUMN_O_O_P_PLID_2 = "portletPreferences.plid = ?";
2918 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_PI = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2919 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2920 PortletPreferencesImpl.class,
2921 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_O_PI",
2922 new String[] {
2923 Long.class.getName(), Integer.class.getName(),
2924 String.class.getName(),
2925
2926 Integer.class.getName(), Integer.class.getName(),
2927 OrderByComparator.class.getName()
2928 });
2929 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI =
2930 new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2931 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
2932 PortletPreferencesImpl.class,
2933 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_O_PI",
2934 new String[] {
2935 Long.class.getName(), Integer.class.getName(),
2936 String.class.getName()
2937 },
2938 PortletPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
2939 PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
2940 PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
2941 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_PI = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
2942 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
2943 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O_PI",
2944 new String[] {
2945 Long.class.getName(), Integer.class.getName(),
2946 String.class.getName()
2947 });
2948
2949
2957 @Override
2958 public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
2959 String portletId) {
2960 return findByO_O_PI(ownerId, ownerType, portletId, QueryUtil.ALL_POS,
2961 QueryUtil.ALL_POS, null);
2962 }
2963
2964
2978 @Override
2979 public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
2980 String portletId, int start, int end) {
2981 return findByO_O_PI(ownerId, ownerType, portletId, start, end, null);
2982 }
2983
2984
2999 @Override
3000 public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
3001 String portletId, int start, int end,
3002 OrderByComparator<PortletPreferences> orderByComparator) {
3003 return findByO_O_PI(ownerId, ownerType, portletId, start, end,
3004 orderByComparator, true);
3005 }
3006
3007
3023 @Override
3024 public List<PortletPreferences> findByO_O_PI(long ownerId, int ownerType,
3025 String portletId, int start, int end,
3026 OrderByComparator<PortletPreferences> orderByComparator,
3027 boolean retrieveFromCache) {
3028 boolean pagination = true;
3029 FinderPath finderPath = null;
3030 Object[] finderArgs = null;
3031
3032 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3033 (orderByComparator == null)) {
3034 pagination = false;
3035 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI;
3036 finderArgs = new Object[] { ownerId, ownerType, portletId };
3037 }
3038 else {
3039 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_O_PI;
3040 finderArgs = new Object[] {
3041 ownerId, ownerType, portletId,
3042
3043 start, end, orderByComparator
3044 };
3045 }
3046
3047 List<PortletPreferences> list = null;
3048
3049 if (retrieveFromCache) {
3050 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
3051 finderArgs, this);
3052
3053 if ((list != null) && !list.isEmpty()) {
3054 for (PortletPreferences portletPreferences : list) {
3055 if ((ownerId != portletPreferences.getOwnerId()) ||
3056 (ownerType != portletPreferences.getOwnerType()) ||
3057 !Validator.equals(portletId,
3058 portletPreferences.getPortletId())) {
3059 list = null;
3060
3061 break;
3062 }
3063 }
3064 }
3065 }
3066
3067 if (list == null) {
3068 StringBundler query = null;
3069
3070 if (orderByComparator != null) {
3071 query = new StringBundler(5 +
3072 (orderByComparator.getOrderByFields().length * 3));
3073 }
3074 else {
3075 query = new StringBundler(5);
3076 }
3077
3078 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3079
3080 query.append(_FINDER_COLUMN_O_O_PI_OWNERID_2);
3081
3082 query.append(_FINDER_COLUMN_O_O_PI_OWNERTYPE_2);
3083
3084 boolean bindPortletId = false;
3085
3086 if (portletId == null) {
3087 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_1);
3088 }
3089 else if (portletId.equals(StringPool.BLANK)) {
3090 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_3);
3091 }
3092 else {
3093 bindPortletId = true;
3094
3095 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_2);
3096 }
3097
3098 if (orderByComparator != null) {
3099 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3100 orderByComparator);
3101 }
3102 else
3103 if (pagination) {
3104 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
3105 }
3106
3107 String sql = query.toString();
3108
3109 Session session = null;
3110
3111 try {
3112 session = openSession();
3113
3114 Query q = session.createQuery(sql);
3115
3116 QueryPos qPos = QueryPos.getInstance(q);
3117
3118 qPos.add(ownerId);
3119
3120 qPos.add(ownerType);
3121
3122 if (bindPortletId) {
3123 qPos.add(portletId);
3124 }
3125
3126 if (!pagination) {
3127 list = (List<PortletPreferences>)QueryUtil.list(q,
3128 getDialect(), start, end, false);
3129
3130 Collections.sort(list);
3131
3132 list = Collections.unmodifiableList(list);
3133 }
3134 else {
3135 list = (List<PortletPreferences>)QueryUtil.list(q,
3136 getDialect(), start, end);
3137 }
3138
3139 cacheResult(list);
3140
3141 finderCache.putResult(finderPath, finderArgs, list);
3142 }
3143 catch (Exception e) {
3144 finderCache.removeResult(finderPath, finderArgs);
3145
3146 throw processException(e);
3147 }
3148 finally {
3149 closeSession(session);
3150 }
3151 }
3152
3153 return list;
3154 }
3155
3156
3166 @Override
3167 public PortletPreferences findByO_O_PI_First(long ownerId, int ownerType,
3168 String portletId,
3169 OrderByComparator<PortletPreferences> orderByComparator)
3170 throws NoSuchPortletPreferencesException {
3171 PortletPreferences portletPreferences = fetchByO_O_PI_First(ownerId,
3172 ownerType, portletId, orderByComparator);
3173
3174 if (portletPreferences != null) {
3175 return portletPreferences;
3176 }
3177
3178 StringBundler msg = new StringBundler(8);
3179
3180 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3181
3182 msg.append("ownerId=");
3183 msg.append(ownerId);
3184
3185 msg.append(", ownerType=");
3186 msg.append(ownerType);
3187
3188 msg.append(", portletId=");
3189 msg.append(portletId);
3190
3191 msg.append(StringPool.CLOSE_CURLY_BRACE);
3192
3193 throw new NoSuchPortletPreferencesException(msg.toString());
3194 }
3195
3196
3205 @Override
3206 public PortletPreferences fetchByO_O_PI_First(long ownerId, int ownerType,
3207 String portletId,
3208 OrderByComparator<PortletPreferences> orderByComparator) {
3209 List<PortletPreferences> list = findByO_O_PI(ownerId, ownerType,
3210 portletId, 0, 1, orderByComparator);
3211
3212 if (!list.isEmpty()) {
3213 return list.get(0);
3214 }
3215
3216 return null;
3217 }
3218
3219
3229 @Override
3230 public PortletPreferences findByO_O_PI_Last(long ownerId, int ownerType,
3231 String portletId,
3232 OrderByComparator<PortletPreferences> orderByComparator)
3233 throws NoSuchPortletPreferencesException {
3234 PortletPreferences portletPreferences = fetchByO_O_PI_Last(ownerId,
3235 ownerType, portletId, orderByComparator);
3236
3237 if (portletPreferences != null) {
3238 return portletPreferences;
3239 }
3240
3241 StringBundler msg = new StringBundler(8);
3242
3243 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3244
3245 msg.append("ownerId=");
3246 msg.append(ownerId);
3247
3248 msg.append(", ownerType=");
3249 msg.append(ownerType);
3250
3251 msg.append(", portletId=");
3252 msg.append(portletId);
3253
3254 msg.append(StringPool.CLOSE_CURLY_BRACE);
3255
3256 throw new NoSuchPortletPreferencesException(msg.toString());
3257 }
3258
3259
3268 @Override
3269 public PortletPreferences fetchByO_O_PI_Last(long ownerId, int ownerType,
3270 String portletId,
3271 OrderByComparator<PortletPreferences> orderByComparator) {
3272 int count = countByO_O_PI(ownerId, ownerType, portletId);
3273
3274 if (count == 0) {
3275 return null;
3276 }
3277
3278 List<PortletPreferences> list = findByO_O_PI(ownerId, ownerType,
3279 portletId, count - 1, count, orderByComparator);
3280
3281 if (!list.isEmpty()) {
3282 return list.get(0);
3283 }
3284
3285 return null;
3286 }
3287
3288
3299 @Override
3300 public PortletPreferences[] findByO_O_PI_PrevAndNext(
3301 long portletPreferencesId, long ownerId, int ownerType,
3302 String portletId,
3303 OrderByComparator<PortletPreferences> orderByComparator)
3304 throws NoSuchPortletPreferencesException {
3305 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
3306
3307 Session session = null;
3308
3309 try {
3310 session = openSession();
3311
3312 PortletPreferences[] array = new PortletPreferencesImpl[3];
3313
3314 array[0] = getByO_O_PI_PrevAndNext(session, portletPreferences,
3315 ownerId, ownerType, portletId, orderByComparator, true);
3316
3317 array[1] = portletPreferences;
3318
3319 array[2] = getByO_O_PI_PrevAndNext(session, portletPreferences,
3320 ownerId, ownerType, portletId, orderByComparator, false);
3321
3322 return array;
3323 }
3324 catch (Exception e) {
3325 throw processException(e);
3326 }
3327 finally {
3328 closeSession(session);
3329 }
3330 }
3331
3332 protected PortletPreferences getByO_O_PI_PrevAndNext(Session session,
3333 PortletPreferences portletPreferences, long ownerId, int ownerType,
3334 String portletId,
3335 OrderByComparator<PortletPreferences> orderByComparator,
3336 boolean previous) {
3337 StringBundler query = null;
3338
3339 if (orderByComparator != null) {
3340 query = new StringBundler(6 +
3341 (orderByComparator.getOrderByFields().length * 6));
3342 }
3343 else {
3344 query = new StringBundler(3);
3345 }
3346
3347 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3348
3349 query.append(_FINDER_COLUMN_O_O_PI_OWNERID_2);
3350
3351 query.append(_FINDER_COLUMN_O_O_PI_OWNERTYPE_2);
3352
3353 boolean bindPortletId = false;
3354
3355 if (portletId == null) {
3356 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_1);
3357 }
3358 else if (portletId.equals(StringPool.BLANK)) {
3359 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_3);
3360 }
3361 else {
3362 bindPortletId = true;
3363
3364 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_2);
3365 }
3366
3367 if (orderByComparator != null) {
3368 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3369
3370 if (orderByConditionFields.length > 0) {
3371 query.append(WHERE_AND);
3372 }
3373
3374 for (int i = 0; i < orderByConditionFields.length; i++) {
3375 query.append(_ORDER_BY_ENTITY_ALIAS);
3376 query.append(orderByConditionFields[i]);
3377
3378 if ((i + 1) < orderByConditionFields.length) {
3379 if (orderByComparator.isAscending() ^ previous) {
3380 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3381 }
3382 else {
3383 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3384 }
3385 }
3386 else {
3387 if (orderByComparator.isAscending() ^ previous) {
3388 query.append(WHERE_GREATER_THAN);
3389 }
3390 else {
3391 query.append(WHERE_LESSER_THAN);
3392 }
3393 }
3394 }
3395
3396 query.append(ORDER_BY_CLAUSE);
3397
3398 String[] orderByFields = orderByComparator.getOrderByFields();
3399
3400 for (int i = 0; i < orderByFields.length; i++) {
3401 query.append(_ORDER_BY_ENTITY_ALIAS);
3402 query.append(orderByFields[i]);
3403
3404 if ((i + 1) < orderByFields.length) {
3405 if (orderByComparator.isAscending() ^ previous) {
3406 query.append(ORDER_BY_ASC_HAS_NEXT);
3407 }
3408 else {
3409 query.append(ORDER_BY_DESC_HAS_NEXT);
3410 }
3411 }
3412 else {
3413 if (orderByComparator.isAscending() ^ previous) {
3414 query.append(ORDER_BY_ASC);
3415 }
3416 else {
3417 query.append(ORDER_BY_DESC);
3418 }
3419 }
3420 }
3421 }
3422 else {
3423 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
3424 }
3425
3426 String sql = query.toString();
3427
3428 Query q = session.createQuery(sql);
3429
3430 q.setFirstResult(0);
3431 q.setMaxResults(2);
3432
3433 QueryPos qPos = QueryPos.getInstance(q);
3434
3435 qPos.add(ownerId);
3436
3437 qPos.add(ownerType);
3438
3439 if (bindPortletId) {
3440 qPos.add(portletId);
3441 }
3442
3443 if (orderByComparator != null) {
3444 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
3445
3446 for (Object value : values) {
3447 qPos.add(value);
3448 }
3449 }
3450
3451 List<PortletPreferences> list = q.list();
3452
3453 if (list.size() == 2) {
3454 return list.get(1);
3455 }
3456 else {
3457 return null;
3458 }
3459 }
3460
3461
3468 @Override
3469 public void removeByO_O_PI(long ownerId, int ownerType, String portletId) {
3470 for (PortletPreferences portletPreferences : findByO_O_PI(ownerId,
3471 ownerType, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3472 remove(portletPreferences);
3473 }
3474 }
3475
3476
3484 @Override
3485 public int countByO_O_PI(long ownerId, int ownerType, String portletId) {
3486 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O_PI;
3487
3488 Object[] finderArgs = new Object[] { ownerId, ownerType, portletId };
3489
3490 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3491
3492 if (count == null) {
3493 StringBundler query = new StringBundler(4);
3494
3495 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
3496
3497 query.append(_FINDER_COLUMN_O_O_PI_OWNERID_2);
3498
3499 query.append(_FINDER_COLUMN_O_O_PI_OWNERTYPE_2);
3500
3501 boolean bindPortletId = false;
3502
3503 if (portletId == null) {
3504 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_1);
3505 }
3506 else if (portletId.equals(StringPool.BLANK)) {
3507 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_3);
3508 }
3509 else {
3510 bindPortletId = true;
3511
3512 query.append(_FINDER_COLUMN_O_O_PI_PORTLETID_2);
3513 }
3514
3515 String sql = query.toString();
3516
3517 Session session = null;
3518
3519 try {
3520 session = openSession();
3521
3522 Query q = session.createQuery(sql);
3523
3524 QueryPos qPos = QueryPos.getInstance(q);
3525
3526 qPos.add(ownerId);
3527
3528 qPos.add(ownerType);
3529
3530 if (bindPortletId) {
3531 qPos.add(portletId);
3532 }
3533
3534 count = (Long)q.uniqueResult();
3535
3536 finderCache.putResult(finderPath, finderArgs, count);
3537 }
3538 catch (Exception e) {
3539 finderCache.removeResult(finderPath, finderArgs);
3540
3541 throw processException(e);
3542 }
3543 finally {
3544 closeSession(session);
3545 }
3546 }
3547
3548 return count.intValue();
3549 }
3550
3551 private static final String _FINDER_COLUMN_O_O_PI_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
3552 private static final String _FINDER_COLUMN_O_O_PI_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
3553 private static final String _FINDER_COLUMN_O_O_PI_PORTLETID_1 = "portletPreferences.portletId IS NULL";
3554 private static final String _FINDER_COLUMN_O_O_PI_PORTLETID_2 = "portletPreferences.portletId = ?";
3555 private static final String _FINDER_COLUMN_O_O_PI_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
3556 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
3557 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
3558 PortletPreferencesImpl.class,
3559 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_P_P",
3560 new String[] {
3561 Integer.class.getName(), Long.class.getName(),
3562 String.class.getName(),
3563
3564 Integer.class.getName(), Integer.class.getName(),
3565 OrderByComparator.class.getName()
3566 });
3567 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
3568 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
3569 PortletPreferencesImpl.class,
3570 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByO_P_P",
3571 new String[] {
3572 Integer.class.getName(), Long.class.getName(),
3573 String.class.getName()
3574 },
3575 PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
3576 PortletPreferencesModelImpl.PLID_COLUMN_BITMASK |
3577 PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
3578 public static final FinderPath FINDER_PATH_COUNT_BY_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
3579 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
3580 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_P_P",
3581 new String[] {
3582 Integer.class.getName(), Long.class.getName(),
3583 String.class.getName()
3584 });
3585
3586
3594 @Override
3595 public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3596 String portletId) {
3597 return findByO_P_P(ownerType, plid, portletId, QueryUtil.ALL_POS,
3598 QueryUtil.ALL_POS, null);
3599 }
3600
3601
3615 @Override
3616 public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3617 String portletId, int start, int end) {
3618 return findByO_P_P(ownerType, plid, portletId, start, end, null);
3619 }
3620
3621
3636 @Override
3637 public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3638 String portletId, int start, int end,
3639 OrderByComparator<PortletPreferences> orderByComparator) {
3640 return findByO_P_P(ownerType, plid, portletId, start, end,
3641 orderByComparator, true);
3642 }
3643
3644
3660 @Override
3661 public List<PortletPreferences> findByO_P_P(int ownerType, long plid,
3662 String portletId, int start, int end,
3663 OrderByComparator<PortletPreferences> orderByComparator,
3664 boolean retrieveFromCache) {
3665 boolean pagination = true;
3666 FinderPath finderPath = null;
3667 Object[] finderArgs = null;
3668
3669 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3670 (orderByComparator == null)) {
3671 pagination = false;
3672 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P;
3673 finderArgs = new Object[] { ownerType, plid, portletId };
3674 }
3675 else {
3676 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_P_P;
3677 finderArgs = new Object[] {
3678 ownerType, plid, portletId,
3679
3680 start, end, orderByComparator
3681 };
3682 }
3683
3684 List<PortletPreferences> list = null;
3685
3686 if (retrieveFromCache) {
3687 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
3688 finderArgs, this);
3689
3690 if ((list != null) && !list.isEmpty()) {
3691 for (PortletPreferences portletPreferences : list) {
3692 if ((ownerType != portletPreferences.getOwnerType()) ||
3693 (plid != portletPreferences.getPlid()) ||
3694 !Validator.equals(portletId,
3695 portletPreferences.getPortletId())) {
3696 list = null;
3697
3698 break;
3699 }
3700 }
3701 }
3702 }
3703
3704 if (list == null) {
3705 StringBundler query = null;
3706
3707 if (orderByComparator != null) {
3708 query = new StringBundler(5 +
3709 (orderByComparator.getOrderByFields().length * 3));
3710 }
3711 else {
3712 query = new StringBundler(5);
3713 }
3714
3715 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3716
3717 query.append(_FINDER_COLUMN_O_P_P_OWNERTYPE_2);
3718
3719 query.append(_FINDER_COLUMN_O_P_P_PLID_2);
3720
3721 boolean bindPortletId = false;
3722
3723 if (portletId == null) {
3724 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_1);
3725 }
3726 else if (portletId.equals(StringPool.BLANK)) {
3727 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_3);
3728 }
3729 else {
3730 bindPortletId = true;
3731
3732 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_2);
3733 }
3734
3735 if (orderByComparator != null) {
3736 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3737 orderByComparator);
3738 }
3739 else
3740 if (pagination) {
3741 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
3742 }
3743
3744 String sql = query.toString();
3745
3746 Session session = null;
3747
3748 try {
3749 session = openSession();
3750
3751 Query q = session.createQuery(sql);
3752
3753 QueryPos qPos = QueryPos.getInstance(q);
3754
3755 qPos.add(ownerType);
3756
3757 qPos.add(plid);
3758
3759 if (bindPortletId) {
3760 qPos.add(portletId);
3761 }
3762
3763 if (!pagination) {
3764 list = (List<PortletPreferences>)QueryUtil.list(q,
3765 getDialect(), start, end, false);
3766
3767 Collections.sort(list);
3768
3769 list = Collections.unmodifiableList(list);
3770 }
3771 else {
3772 list = (List<PortletPreferences>)QueryUtil.list(q,
3773 getDialect(), start, end);
3774 }
3775
3776 cacheResult(list);
3777
3778 finderCache.putResult(finderPath, finderArgs, list);
3779 }
3780 catch (Exception e) {
3781 finderCache.removeResult(finderPath, finderArgs);
3782
3783 throw processException(e);
3784 }
3785 finally {
3786 closeSession(session);
3787 }
3788 }
3789
3790 return list;
3791 }
3792
3793
3803 @Override
3804 public PortletPreferences findByO_P_P_First(int ownerType, long plid,
3805 String portletId,
3806 OrderByComparator<PortletPreferences> orderByComparator)
3807 throws NoSuchPortletPreferencesException {
3808 PortletPreferences portletPreferences = fetchByO_P_P_First(ownerType,
3809 plid, portletId, orderByComparator);
3810
3811 if (portletPreferences != null) {
3812 return portletPreferences;
3813 }
3814
3815 StringBundler msg = new StringBundler(8);
3816
3817 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3818
3819 msg.append("ownerType=");
3820 msg.append(ownerType);
3821
3822 msg.append(", plid=");
3823 msg.append(plid);
3824
3825 msg.append(", portletId=");
3826 msg.append(portletId);
3827
3828 msg.append(StringPool.CLOSE_CURLY_BRACE);
3829
3830 throw new NoSuchPortletPreferencesException(msg.toString());
3831 }
3832
3833
3842 @Override
3843 public PortletPreferences fetchByO_P_P_First(int ownerType, long plid,
3844 String portletId,
3845 OrderByComparator<PortletPreferences> orderByComparator) {
3846 List<PortletPreferences> list = findByO_P_P(ownerType, plid, portletId,
3847 0, 1, orderByComparator);
3848
3849 if (!list.isEmpty()) {
3850 return list.get(0);
3851 }
3852
3853 return null;
3854 }
3855
3856
3866 @Override
3867 public PortletPreferences findByO_P_P_Last(int ownerType, long plid,
3868 String portletId,
3869 OrderByComparator<PortletPreferences> orderByComparator)
3870 throws NoSuchPortletPreferencesException {
3871 PortletPreferences portletPreferences = fetchByO_P_P_Last(ownerType,
3872 plid, portletId, orderByComparator);
3873
3874 if (portletPreferences != null) {
3875 return portletPreferences;
3876 }
3877
3878 StringBundler msg = new StringBundler(8);
3879
3880 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3881
3882 msg.append("ownerType=");
3883 msg.append(ownerType);
3884
3885 msg.append(", plid=");
3886 msg.append(plid);
3887
3888 msg.append(", portletId=");
3889 msg.append(portletId);
3890
3891 msg.append(StringPool.CLOSE_CURLY_BRACE);
3892
3893 throw new NoSuchPortletPreferencesException(msg.toString());
3894 }
3895
3896
3905 @Override
3906 public PortletPreferences fetchByO_P_P_Last(int ownerType, long plid,
3907 String portletId,
3908 OrderByComparator<PortletPreferences> orderByComparator) {
3909 int count = countByO_P_P(ownerType, plid, portletId);
3910
3911 if (count == 0) {
3912 return null;
3913 }
3914
3915 List<PortletPreferences> list = findByO_P_P(ownerType, plid, portletId,
3916 count - 1, count, orderByComparator);
3917
3918 if (!list.isEmpty()) {
3919 return list.get(0);
3920 }
3921
3922 return null;
3923 }
3924
3925
3936 @Override
3937 public PortletPreferences[] findByO_P_P_PrevAndNext(
3938 long portletPreferencesId, int ownerType, long plid, String portletId,
3939 OrderByComparator<PortletPreferences> orderByComparator)
3940 throws NoSuchPortletPreferencesException {
3941 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
3942
3943 Session session = null;
3944
3945 try {
3946 session = openSession();
3947
3948 PortletPreferences[] array = new PortletPreferencesImpl[3];
3949
3950 array[0] = getByO_P_P_PrevAndNext(session, portletPreferences,
3951 ownerType, plid, portletId, orderByComparator, true);
3952
3953 array[1] = portletPreferences;
3954
3955 array[2] = getByO_P_P_PrevAndNext(session, portletPreferences,
3956 ownerType, plid, portletId, orderByComparator, false);
3957
3958 return array;
3959 }
3960 catch (Exception e) {
3961 throw processException(e);
3962 }
3963 finally {
3964 closeSession(session);
3965 }
3966 }
3967
3968 protected PortletPreferences getByO_P_P_PrevAndNext(Session session,
3969 PortletPreferences portletPreferences, int ownerType, long plid,
3970 String portletId,
3971 OrderByComparator<PortletPreferences> orderByComparator,
3972 boolean previous) {
3973 StringBundler query = null;
3974
3975 if (orderByComparator != null) {
3976 query = new StringBundler(6 +
3977 (orderByComparator.getOrderByFields().length * 6));
3978 }
3979 else {
3980 query = new StringBundler(3);
3981 }
3982
3983 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
3984
3985 query.append(_FINDER_COLUMN_O_P_P_OWNERTYPE_2);
3986
3987 query.append(_FINDER_COLUMN_O_P_P_PLID_2);
3988
3989 boolean bindPortletId = false;
3990
3991 if (portletId == null) {
3992 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_1);
3993 }
3994 else if (portletId.equals(StringPool.BLANK)) {
3995 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_3);
3996 }
3997 else {
3998 bindPortletId = true;
3999
4000 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_2);
4001 }
4002
4003 if (orderByComparator != null) {
4004 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4005
4006 if (orderByConditionFields.length > 0) {
4007 query.append(WHERE_AND);
4008 }
4009
4010 for (int i = 0; i < orderByConditionFields.length; i++) {
4011 query.append(_ORDER_BY_ENTITY_ALIAS);
4012 query.append(orderByConditionFields[i]);
4013
4014 if ((i + 1) < orderByConditionFields.length) {
4015 if (orderByComparator.isAscending() ^ previous) {
4016 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4017 }
4018 else {
4019 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4020 }
4021 }
4022 else {
4023 if (orderByComparator.isAscending() ^ previous) {
4024 query.append(WHERE_GREATER_THAN);
4025 }
4026 else {
4027 query.append(WHERE_LESSER_THAN);
4028 }
4029 }
4030 }
4031
4032 query.append(ORDER_BY_CLAUSE);
4033
4034 String[] orderByFields = orderByComparator.getOrderByFields();
4035
4036 for (int i = 0; i < orderByFields.length; i++) {
4037 query.append(_ORDER_BY_ENTITY_ALIAS);
4038 query.append(orderByFields[i]);
4039
4040 if ((i + 1) < orderByFields.length) {
4041 if (orderByComparator.isAscending() ^ previous) {
4042 query.append(ORDER_BY_ASC_HAS_NEXT);
4043 }
4044 else {
4045 query.append(ORDER_BY_DESC_HAS_NEXT);
4046 }
4047 }
4048 else {
4049 if (orderByComparator.isAscending() ^ previous) {
4050 query.append(ORDER_BY_ASC);
4051 }
4052 else {
4053 query.append(ORDER_BY_DESC);
4054 }
4055 }
4056 }
4057 }
4058 else {
4059 query.append(PortletPreferencesModelImpl.ORDER_BY_JPQL);
4060 }
4061
4062 String sql = query.toString();
4063
4064 Query q = session.createQuery(sql);
4065
4066 q.setFirstResult(0);
4067 q.setMaxResults(2);
4068
4069 QueryPos qPos = QueryPos.getInstance(q);
4070
4071 qPos.add(ownerType);
4072
4073 qPos.add(plid);
4074
4075 if (bindPortletId) {
4076 qPos.add(portletId);
4077 }
4078
4079 if (orderByComparator != null) {
4080 Object[] values = orderByComparator.getOrderByConditionValues(portletPreferences);
4081
4082 for (Object value : values) {
4083 qPos.add(value);
4084 }
4085 }
4086
4087 List<PortletPreferences> list = q.list();
4088
4089 if (list.size() == 2) {
4090 return list.get(1);
4091 }
4092 else {
4093 return null;
4094 }
4095 }
4096
4097
4104 @Override
4105 public void removeByO_P_P(int ownerType, long plid, String portletId) {
4106 for (PortletPreferences portletPreferences : findByO_P_P(ownerType,
4107 plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4108 remove(portletPreferences);
4109 }
4110 }
4111
4112
4120 @Override
4121 public int countByO_P_P(int ownerType, long plid, String portletId) {
4122 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_P_P;
4123
4124 Object[] finderArgs = new Object[] { ownerType, plid, portletId };
4125
4126 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4127
4128 if (count == null) {
4129 StringBundler query = new StringBundler(4);
4130
4131 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
4132
4133 query.append(_FINDER_COLUMN_O_P_P_OWNERTYPE_2);
4134
4135 query.append(_FINDER_COLUMN_O_P_P_PLID_2);
4136
4137 boolean bindPortletId = false;
4138
4139 if (portletId == null) {
4140 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_1);
4141 }
4142 else if (portletId.equals(StringPool.BLANK)) {
4143 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_3);
4144 }
4145 else {
4146 bindPortletId = true;
4147
4148 query.append(_FINDER_COLUMN_O_P_P_PORTLETID_2);
4149 }
4150
4151 String sql = query.toString();
4152
4153 Session session = null;
4154
4155 try {
4156 session = openSession();
4157
4158 Query q = session.createQuery(sql);
4159
4160 QueryPos qPos = QueryPos.getInstance(q);
4161
4162 qPos.add(ownerType);
4163
4164 qPos.add(plid);
4165
4166 if (bindPortletId) {
4167 qPos.add(portletId);
4168 }
4169
4170 count = (Long)q.uniqueResult();
4171
4172 finderCache.putResult(finderPath, finderArgs, count);
4173 }
4174 catch (Exception e) {
4175 finderCache.removeResult(finderPath, finderArgs);
4176
4177 throw processException(e);
4178 }
4179 finally {
4180 closeSession(session);
4181 }
4182 }
4183
4184 return count.intValue();
4185 }
4186
4187 private static final String _FINDER_COLUMN_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
4188 private static final String _FINDER_COLUMN_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
4189 private static final String _FINDER_COLUMN_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
4190 private static final String _FINDER_COLUMN_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
4191 private static final String _FINDER_COLUMN_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
4192 public static final FinderPath FINDER_PATH_FETCH_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4193 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
4194 PortletPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
4195 "fetchByO_O_P_P",
4196 new String[] {
4197 Long.class.getName(), Integer.class.getName(),
4198 Long.class.getName(), String.class.getName()
4199 },
4200 PortletPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
4201 PortletPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK |
4202 PortletPreferencesModelImpl.PLID_COLUMN_BITMASK |
4203 PortletPreferencesModelImpl.PORTLETID_COLUMN_BITMASK);
4204 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4205 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
4206 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O_P_P",
4207 new String[] {
4208 Long.class.getName(), Integer.class.getName(),
4209 Long.class.getName(), String.class.getName()
4210 });
4211
4212
4222 @Override
4223 public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
4224 long plid, String portletId) throws NoSuchPortletPreferencesException {
4225 PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
4226 ownerType, plid, portletId);
4227
4228 if (portletPreferences == null) {
4229 StringBundler msg = new StringBundler(10);
4230
4231 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4232
4233 msg.append("ownerId=");
4234 msg.append(ownerId);
4235
4236 msg.append(", ownerType=");
4237 msg.append(ownerType);
4238
4239 msg.append(", plid=");
4240 msg.append(plid);
4241
4242 msg.append(", portletId=");
4243 msg.append(portletId);
4244
4245 msg.append(StringPool.CLOSE_CURLY_BRACE);
4246
4247 if (_log.isWarnEnabled()) {
4248 _log.warn(msg.toString());
4249 }
4250
4251 throw new NoSuchPortletPreferencesException(msg.toString());
4252 }
4253
4254 return portletPreferences;
4255 }
4256
4257
4266 @Override
4267 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
4268 long plid, String portletId) {
4269 return fetchByO_O_P_P(ownerId, ownerType, plid, portletId, true);
4270 }
4271
4272
4282 @Override
4283 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
4284 long plid, String portletId, boolean retrieveFromCache) {
4285 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
4286
4287 Object result = null;
4288
4289 if (retrieveFromCache) {
4290 result = finderCache.getResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4291 finderArgs, this);
4292 }
4293
4294 if (result instanceof PortletPreferences) {
4295 PortletPreferences portletPreferences = (PortletPreferences)result;
4296
4297 if ((ownerId != portletPreferences.getOwnerId()) ||
4298 (ownerType != portletPreferences.getOwnerType()) ||
4299 (plid != portletPreferences.getPlid()) ||
4300 !Validator.equals(portletId,
4301 portletPreferences.getPortletId())) {
4302 result = null;
4303 }
4304 }
4305
4306 if (result == null) {
4307 StringBundler query = new StringBundler(6);
4308
4309 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
4310
4311 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
4312
4313 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
4314
4315 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
4316
4317 boolean bindPortletId = false;
4318
4319 if (portletId == null) {
4320 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
4321 }
4322 else if (portletId.equals(StringPool.BLANK)) {
4323 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
4324 }
4325 else {
4326 bindPortletId = true;
4327
4328 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
4329 }
4330
4331 String sql = query.toString();
4332
4333 Session session = null;
4334
4335 try {
4336 session = openSession();
4337
4338 Query q = session.createQuery(sql);
4339
4340 QueryPos qPos = QueryPos.getInstance(q);
4341
4342 qPos.add(ownerId);
4343
4344 qPos.add(ownerType);
4345
4346 qPos.add(plid);
4347
4348 if (bindPortletId) {
4349 qPos.add(portletId);
4350 }
4351
4352 List<PortletPreferences> list = q.list();
4353
4354 if (list.isEmpty()) {
4355 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4356 finderArgs, list);
4357 }
4358 else {
4359 PortletPreferences portletPreferences = list.get(0);
4360
4361 result = portletPreferences;
4362
4363 cacheResult(portletPreferences);
4364
4365 if ((portletPreferences.getOwnerId() != ownerId) ||
4366 (portletPreferences.getOwnerType() != ownerType) ||
4367 (portletPreferences.getPlid() != plid) ||
4368 (portletPreferences.getPortletId() == null) ||
4369 !portletPreferences.getPortletId().equals(portletId)) {
4370 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4371 finderArgs, portletPreferences);
4372 }
4373 }
4374 }
4375 catch (Exception e) {
4376 finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4377 finderArgs);
4378
4379 throw processException(e);
4380 }
4381 finally {
4382 closeSession(session);
4383 }
4384 }
4385
4386 if (result instanceof List<?>) {
4387 return null;
4388 }
4389 else {
4390 return (PortletPreferences)result;
4391 }
4392 }
4393
4394
4403 @Override
4404 public PortletPreferences removeByO_O_P_P(long ownerId, int ownerType,
4405 long plid, String portletId) throws NoSuchPortletPreferencesException {
4406 PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
4407 ownerType, plid, portletId);
4408
4409 return remove(portletPreferences);
4410 }
4411
4412
4421 @Override
4422 public int countByO_O_P_P(long ownerId, int ownerType, long plid,
4423 String portletId) {
4424 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O_P_P;
4425
4426 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
4427
4428 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4429
4430 if (count == null) {
4431 StringBundler query = new StringBundler(5);
4432
4433 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
4434
4435 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
4436
4437 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
4438
4439 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
4440
4441 boolean bindPortletId = false;
4442
4443 if (portletId == null) {
4444 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
4445 }
4446 else if (portletId.equals(StringPool.BLANK)) {
4447 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
4448 }
4449 else {
4450 bindPortletId = true;
4451
4452 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
4453 }
4454
4455 String sql = query.toString();
4456
4457 Session session = null;
4458
4459 try {
4460 session = openSession();
4461
4462 Query q = session.createQuery(sql);
4463
4464 QueryPos qPos = QueryPos.getInstance(q);
4465
4466 qPos.add(ownerId);
4467
4468 qPos.add(ownerType);
4469
4470 qPos.add(plid);
4471
4472 if (bindPortletId) {
4473 qPos.add(portletId);
4474 }
4475
4476 count = (Long)q.uniqueResult();
4477
4478 finderCache.putResult(finderPath, finderArgs, count);
4479 }
4480 catch (Exception e) {
4481 finderCache.removeResult(finderPath, finderArgs);
4482
4483 throw processException(e);
4484 }
4485 finally {
4486 closeSession(session);
4487 }
4488 }
4489
4490 return count.intValue();
4491 }
4492
4493 private static final String _FINDER_COLUMN_O_O_P_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
4494 private static final String _FINDER_COLUMN_O_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
4495 private static final String _FINDER_COLUMN_O_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
4496 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
4497 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
4498 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = '')";
4499
4500 public PortletPreferencesPersistenceImpl() {
4501 setModelClass(PortletPreferences.class);
4502 }
4503
4504
4509 @Override
4510 public void cacheResult(PortletPreferences portletPreferences) {
4511 entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4512 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
4513 portletPreferences);
4514
4515 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
4516 new Object[] {
4517 portletPreferences.getOwnerId(),
4518 portletPreferences.getOwnerType(), portletPreferences.getPlid(),
4519 portletPreferences.getPortletId()
4520 }, portletPreferences);
4521
4522 portletPreferences.resetOriginalValues();
4523 }
4524
4525
4530 @Override
4531 public void cacheResult(List<PortletPreferences> portletPreferenceses) {
4532 for (PortletPreferences portletPreferences : portletPreferenceses) {
4533 if (entityCache.getResult(
4534 PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4535 PortletPreferencesImpl.class,
4536 portletPreferences.getPrimaryKey()) == null) {
4537 cacheResult(portletPreferences);
4538 }
4539 else {
4540 portletPreferences.resetOriginalValues();
4541 }
4542 }
4543 }
4544
4545
4552 @Override
4553 public void clearCache() {
4554 entityCache.clearCache(PortletPreferencesImpl.class);
4555
4556 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
4557 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4558 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4559 }
4560
4561
4568 @Override
4569 public void clearCache(PortletPreferences portletPreferences) {
4570 entityCache.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4571 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
4572
4573 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4574 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4575
4576 clearUniqueFindersCache((PortletPreferencesModelImpl)portletPreferences);
4577 }
4578
4579 @Override
4580 public void clearCache(List<PortletPreferences> portletPreferenceses) {
4581 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4582 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4583
4584 for (PortletPreferences portletPreferences : portletPreferenceses) {
4585 entityCache.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4586 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
4587
4588 clearUniqueFindersCache((PortletPreferencesModelImpl)portletPreferences);
4589 }
4590 }
4591
4592 protected void cacheUniqueFindersCache(
4593 PortletPreferencesModelImpl portletPreferencesModelImpl, boolean isNew) {
4594 if (isNew) {
4595 Object[] args = new Object[] {
4596 portletPreferencesModelImpl.getOwnerId(),
4597 portletPreferencesModelImpl.getOwnerType(),
4598 portletPreferencesModelImpl.getPlid(),
4599 portletPreferencesModelImpl.getPortletId()
4600 };
4601
4602 finderCache.putResult(FINDER_PATH_COUNT_BY_O_O_P_P, args,
4603 Long.valueOf(1));
4604 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P, args,
4605 portletPreferencesModelImpl);
4606 }
4607 else {
4608 if ((portletPreferencesModelImpl.getColumnBitmask() &
4609 FINDER_PATH_FETCH_BY_O_O_P_P.getColumnBitmask()) != 0) {
4610 Object[] args = new Object[] {
4611 portletPreferencesModelImpl.getOwnerId(),
4612 portletPreferencesModelImpl.getOwnerType(),
4613 portletPreferencesModelImpl.getPlid(),
4614 portletPreferencesModelImpl.getPortletId()
4615 };
4616
4617 finderCache.putResult(FINDER_PATH_COUNT_BY_O_O_P_P, args,
4618 Long.valueOf(1));
4619 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O_P_P, args,
4620 portletPreferencesModelImpl);
4621 }
4622 }
4623 }
4624
4625 protected void clearUniqueFindersCache(
4626 PortletPreferencesModelImpl portletPreferencesModelImpl) {
4627 Object[] args = new Object[] {
4628 portletPreferencesModelImpl.getOwnerId(),
4629 portletPreferencesModelImpl.getOwnerType(),
4630 portletPreferencesModelImpl.getPlid(),
4631 portletPreferencesModelImpl.getPortletId()
4632 };
4633
4634 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P_P, args);
4635 finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P, args);
4636
4637 if ((portletPreferencesModelImpl.getColumnBitmask() &
4638 FINDER_PATH_FETCH_BY_O_O_P_P.getColumnBitmask()) != 0) {
4639 args = new Object[] {
4640 portletPreferencesModelImpl.getOriginalOwnerId(),
4641 portletPreferencesModelImpl.getOriginalOwnerType(),
4642 portletPreferencesModelImpl.getOriginalPlid(),
4643 portletPreferencesModelImpl.getOriginalPortletId()
4644 };
4645
4646 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P_P, args);
4647 finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P, args);
4648 }
4649 }
4650
4651
4657 @Override
4658 public PortletPreferences create(long portletPreferencesId) {
4659 PortletPreferences portletPreferences = new PortletPreferencesImpl();
4660
4661 portletPreferences.setNew(true);
4662 portletPreferences.setPrimaryKey(portletPreferencesId);
4663
4664 portletPreferences.setCompanyId(companyProvider.getCompanyId());
4665
4666 return portletPreferences;
4667 }
4668
4669
4676 @Override
4677 public PortletPreferences remove(long portletPreferencesId)
4678 throws NoSuchPortletPreferencesException {
4679 return remove((Serializable)portletPreferencesId);
4680 }
4681
4682
4689 @Override
4690 public PortletPreferences remove(Serializable primaryKey)
4691 throws NoSuchPortletPreferencesException {
4692 Session session = null;
4693
4694 try {
4695 session = openSession();
4696
4697 PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
4698 primaryKey);
4699
4700 if (portletPreferences == null) {
4701 if (_log.isWarnEnabled()) {
4702 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4703 }
4704
4705 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4706 primaryKey);
4707 }
4708
4709 return remove(portletPreferences);
4710 }
4711 catch (NoSuchPortletPreferencesException nsee) {
4712 throw nsee;
4713 }
4714 catch (Exception e) {
4715 throw processException(e);
4716 }
4717 finally {
4718 closeSession(session);
4719 }
4720 }
4721
4722 @Override
4723 protected PortletPreferences removeImpl(
4724 PortletPreferences portletPreferences) {
4725 portletPreferences = toUnwrappedModel(portletPreferences);
4726
4727 Session session = null;
4728
4729 try {
4730 session = openSession();
4731
4732 if (!session.contains(portletPreferences)) {
4733 portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
4734 portletPreferences.getPrimaryKeyObj());
4735 }
4736
4737 if (portletPreferences != null) {
4738 session.delete(portletPreferences);
4739 }
4740 }
4741 catch (Exception e) {
4742 throw processException(e);
4743 }
4744 finally {
4745 closeSession(session);
4746 }
4747
4748 if (portletPreferences != null) {
4749 clearCache(portletPreferences);
4750 }
4751
4752 return portletPreferences;
4753 }
4754
4755 @Override
4756 public PortletPreferences updateImpl(PortletPreferences portletPreferences) {
4757 portletPreferences = toUnwrappedModel(portletPreferences);
4758
4759 boolean isNew = portletPreferences.isNew();
4760
4761 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
4762
4763 Session session = null;
4764
4765 try {
4766 session = openSession();
4767
4768 if (portletPreferences.isNew()) {
4769 session.save(portletPreferences);
4770
4771 portletPreferences.setNew(false);
4772 }
4773 else {
4774 portletPreferences = (PortletPreferences)session.merge(portletPreferences);
4775 }
4776 }
4777 catch (Exception e) {
4778 throw processException(e);
4779 }
4780 finally {
4781 closeSession(session);
4782 }
4783
4784 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4785
4786 if (isNew || !PortletPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
4787 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4788 }
4789
4790 else {
4791 if ((portletPreferencesModelImpl.getColumnBitmask() &
4792 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID.getColumnBitmask()) != 0) {
4793 Object[] args = new Object[] {
4794 portletPreferencesModelImpl.getOriginalPlid()
4795 };
4796
4797 finderCache.removeResult(FINDER_PATH_COUNT_BY_PLID, args);
4798 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID,
4799 args);
4800
4801 args = new Object[] { portletPreferencesModelImpl.getPlid() };
4802
4803 finderCache.removeResult(FINDER_PATH_COUNT_BY_PLID, args);
4804 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PLID,
4805 args);
4806 }
4807
4808 if ((portletPreferencesModelImpl.getColumnBitmask() &
4809 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID.getColumnBitmask()) != 0) {
4810 Object[] args = new Object[] {
4811 portletPreferencesModelImpl.getOriginalPortletId()
4812 };
4813
4814 finderCache.removeResult(FINDER_PATH_COUNT_BY_PORTLETID, args);
4815 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID,
4816 args);
4817
4818 args = new Object[] { portletPreferencesModelImpl.getPortletId() };
4819
4820 finderCache.removeResult(FINDER_PATH_COUNT_BY_PORTLETID, args);
4821 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PORTLETID,
4822 args);
4823 }
4824
4825 if ((portletPreferencesModelImpl.getColumnBitmask() &
4826 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P.getColumnBitmask()) != 0) {
4827 Object[] args = new Object[] {
4828 portletPreferencesModelImpl.getOriginalOwnerType(),
4829 portletPreferencesModelImpl.getOriginalPortletId()
4830 };
4831
4832 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P, args);
4833 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P,
4834 args);
4835
4836 args = new Object[] {
4837 portletPreferencesModelImpl.getOwnerType(),
4838 portletPreferencesModelImpl.getPortletId()
4839 };
4840
4841 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P, args);
4842 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P,
4843 args);
4844 }
4845
4846 if ((portletPreferencesModelImpl.getColumnBitmask() &
4847 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P.getColumnBitmask()) != 0) {
4848 Object[] args = new Object[] {
4849 portletPreferencesModelImpl.getOriginalPlid(),
4850 portletPreferencesModelImpl.getOriginalPortletId()
4851 };
4852
4853 finderCache.removeResult(FINDER_PATH_COUNT_BY_P_P, args);
4854 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P,
4855 args);
4856
4857 args = new Object[] {
4858 portletPreferencesModelImpl.getPlid(),
4859 portletPreferencesModelImpl.getPortletId()
4860 };
4861
4862 finderCache.removeResult(FINDER_PATH_COUNT_BY_P_P, args);
4863 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_P_P,
4864 args);
4865 }
4866
4867 if ((portletPreferencesModelImpl.getColumnBitmask() &
4868 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P.getColumnBitmask()) != 0) {
4869 Object[] args = new Object[] {
4870 portletPreferencesModelImpl.getOriginalOwnerId(),
4871 portletPreferencesModelImpl.getOriginalOwnerType(),
4872 portletPreferencesModelImpl.getOriginalPlid()
4873 };
4874
4875 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P, args);
4876 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P,
4877 args);
4878
4879 args = new Object[] {
4880 portletPreferencesModelImpl.getOwnerId(),
4881 portletPreferencesModelImpl.getOwnerType(),
4882 portletPreferencesModelImpl.getPlid()
4883 };
4884
4885 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_P, args);
4886 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_P,
4887 args);
4888 }
4889
4890 if ((portletPreferencesModelImpl.getColumnBitmask() &
4891 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI.getColumnBitmask()) != 0) {
4892 Object[] args = new Object[] {
4893 portletPreferencesModelImpl.getOriginalOwnerId(),
4894 portletPreferencesModelImpl.getOriginalOwnerType(),
4895 portletPreferencesModelImpl.getOriginalPortletId()
4896 };
4897
4898 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_PI, args);
4899 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI,
4900 args);
4901
4902 args = new Object[] {
4903 portletPreferencesModelImpl.getOwnerId(),
4904 portletPreferencesModelImpl.getOwnerType(),
4905 portletPreferencesModelImpl.getPortletId()
4906 };
4907
4908 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O_PI, args);
4909 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_O_PI,
4910 args);
4911 }
4912
4913 if ((portletPreferencesModelImpl.getColumnBitmask() &
4914 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P.getColumnBitmask()) != 0) {
4915 Object[] args = new Object[] {
4916 portletPreferencesModelImpl.getOriginalOwnerType(),
4917 portletPreferencesModelImpl.getOriginalPlid(),
4918 portletPreferencesModelImpl.getOriginalPortletId()
4919 };
4920
4921 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P_P, args);
4922 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P,
4923 args);
4924
4925 args = new Object[] {
4926 portletPreferencesModelImpl.getOwnerType(),
4927 portletPreferencesModelImpl.getPlid(),
4928 portletPreferencesModelImpl.getPortletId()
4929 };
4930
4931 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_P_P, args);
4932 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_O_P_P,
4933 args);
4934 }
4935 }
4936
4937 entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
4938 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
4939 portletPreferences, false);
4940
4941 clearUniqueFindersCache(portletPreferencesModelImpl);
4942 cacheUniqueFindersCache(portletPreferencesModelImpl, isNew);
4943
4944 portletPreferences.resetOriginalValues();
4945
4946 return portletPreferences;
4947 }
4948
4949 protected PortletPreferences toUnwrappedModel(
4950 PortletPreferences portletPreferences) {
4951 if (portletPreferences instanceof PortletPreferencesImpl) {
4952 return portletPreferences;
4953 }
4954
4955 PortletPreferencesImpl portletPreferencesImpl = new PortletPreferencesImpl();
4956
4957 portletPreferencesImpl.setNew(portletPreferences.isNew());
4958 portletPreferencesImpl.setPrimaryKey(portletPreferences.getPrimaryKey());
4959
4960 portletPreferencesImpl.setMvccVersion(portletPreferences.getMvccVersion());
4961 portletPreferencesImpl.setPortletPreferencesId(portletPreferences.getPortletPreferencesId());
4962 portletPreferencesImpl.setCompanyId(portletPreferences.getCompanyId());
4963 portletPreferencesImpl.setOwnerId(portletPreferences.getOwnerId());
4964 portletPreferencesImpl.setOwnerType(portletPreferences.getOwnerType());
4965 portletPreferencesImpl.setPlid(portletPreferences.getPlid());
4966 portletPreferencesImpl.setPortletId(portletPreferences.getPortletId());
4967 portletPreferencesImpl.setPreferences(portletPreferences.getPreferences());
4968
4969 return portletPreferencesImpl;
4970 }
4971
4972
4979 @Override
4980 public PortletPreferences findByPrimaryKey(Serializable primaryKey)
4981 throws NoSuchPortletPreferencesException {
4982 PortletPreferences portletPreferences = fetchByPrimaryKey(primaryKey);
4983
4984 if (portletPreferences == null) {
4985 if (_log.isWarnEnabled()) {
4986 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4987 }
4988
4989 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4990 primaryKey);
4991 }
4992
4993 return portletPreferences;
4994 }
4995
4996
5003 @Override
5004 public PortletPreferences findByPrimaryKey(long portletPreferencesId)
5005 throws NoSuchPortletPreferencesException {
5006 return findByPrimaryKey((Serializable)portletPreferencesId);
5007 }
5008
5009
5015 @Override
5016 public PortletPreferences fetchByPrimaryKey(Serializable primaryKey) {
5017 PortletPreferences portletPreferences = (PortletPreferences)entityCache.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5018 PortletPreferencesImpl.class, primaryKey);
5019
5020 if (portletPreferences == _nullPortletPreferences) {
5021 return null;
5022 }
5023
5024 if (portletPreferences == null) {
5025 Session session = null;
5026
5027 try {
5028 session = openSession();
5029
5030 portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
5031 primaryKey);
5032
5033 if (portletPreferences != null) {
5034 cacheResult(portletPreferences);
5035 }
5036 else {
5037 entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5038 PortletPreferencesImpl.class, primaryKey,
5039 _nullPortletPreferences);
5040 }
5041 }
5042 catch (Exception e) {
5043 entityCache.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5044 PortletPreferencesImpl.class, primaryKey);
5045
5046 throw processException(e);
5047 }
5048 finally {
5049 closeSession(session);
5050 }
5051 }
5052
5053 return portletPreferences;
5054 }
5055
5056
5062 @Override
5063 public PortletPreferences fetchByPrimaryKey(long portletPreferencesId) {
5064 return fetchByPrimaryKey((Serializable)portletPreferencesId);
5065 }
5066
5067 @Override
5068 public Map<Serializable, PortletPreferences> fetchByPrimaryKeys(
5069 Set<Serializable> primaryKeys) {
5070 if (primaryKeys.isEmpty()) {
5071 return Collections.emptyMap();
5072 }
5073
5074 Map<Serializable, PortletPreferences> map = new HashMap<Serializable, PortletPreferences>();
5075
5076 if (primaryKeys.size() == 1) {
5077 Iterator<Serializable> iterator = primaryKeys.iterator();
5078
5079 Serializable primaryKey = iterator.next();
5080
5081 PortletPreferences portletPreferences = fetchByPrimaryKey(primaryKey);
5082
5083 if (portletPreferences != null) {
5084 map.put(primaryKey, portletPreferences);
5085 }
5086
5087 return map;
5088 }
5089
5090 Set<Serializable> uncachedPrimaryKeys = null;
5091
5092 for (Serializable primaryKey : primaryKeys) {
5093 PortletPreferences portletPreferences = (PortletPreferences)entityCache.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5094 PortletPreferencesImpl.class, primaryKey);
5095
5096 if (portletPreferences == null) {
5097 if (uncachedPrimaryKeys == null) {
5098 uncachedPrimaryKeys = new HashSet<Serializable>();
5099 }
5100
5101 uncachedPrimaryKeys.add(primaryKey);
5102 }
5103 else {
5104 map.put(primaryKey, portletPreferences);
5105 }
5106 }
5107
5108 if (uncachedPrimaryKeys == null) {
5109 return map;
5110 }
5111
5112 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
5113 1);
5114
5115 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE_PKS_IN);
5116
5117 for (Serializable primaryKey : uncachedPrimaryKeys) {
5118 query.append(String.valueOf(primaryKey));
5119
5120 query.append(StringPool.COMMA);
5121 }
5122
5123 query.setIndex(query.index() - 1);
5124
5125 query.append(StringPool.CLOSE_PARENTHESIS);
5126
5127 String sql = query.toString();
5128
5129 Session session = null;
5130
5131 try {
5132 session = openSession();
5133
5134 Query q = session.createQuery(sql);
5135
5136 for (PortletPreferences portletPreferences : (List<PortletPreferences>)q.list()) {
5137 map.put(portletPreferences.getPrimaryKeyObj(),
5138 portletPreferences);
5139
5140 cacheResult(portletPreferences);
5141
5142 uncachedPrimaryKeys.remove(portletPreferences.getPrimaryKeyObj());
5143 }
5144
5145 for (Serializable primaryKey : uncachedPrimaryKeys) {
5146 entityCache.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
5147 PortletPreferencesImpl.class, primaryKey,
5148 _nullPortletPreferences);
5149 }
5150 }
5151 catch (Exception e) {
5152 throw processException(e);
5153 }
5154 finally {
5155 closeSession(session);
5156 }
5157
5158 return map;
5159 }
5160
5161
5166 @Override
5167 public List<PortletPreferences> findAll() {
5168 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5169 }
5170
5171
5182 @Override
5183 public List<PortletPreferences> findAll(int start, int end) {
5184 return findAll(start, end, null);
5185 }
5186
5187
5199 @Override
5200 public List<PortletPreferences> findAll(int start, int end,
5201 OrderByComparator<PortletPreferences> orderByComparator) {
5202 return findAll(start, end, orderByComparator, true);
5203 }
5204
5205
5218 @Override
5219 public List<PortletPreferences> findAll(int start, int end,
5220 OrderByComparator<PortletPreferences> orderByComparator,
5221 boolean retrieveFromCache) {
5222 boolean pagination = true;
5223 FinderPath finderPath = null;
5224 Object[] finderArgs = null;
5225
5226 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5227 (orderByComparator == null)) {
5228 pagination = false;
5229 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5230 finderArgs = FINDER_ARGS_EMPTY;
5231 }
5232 else {
5233 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5234 finderArgs = new Object[] { start, end, orderByComparator };
5235 }
5236
5237 List<PortletPreferences> list = null;
5238
5239 if (retrieveFromCache) {
5240 list = (List<PortletPreferences>)finderCache.getResult(finderPath,
5241 finderArgs, this);
5242 }
5243
5244 if (list == null) {
5245 StringBundler query = null;
5246 String sql = null;
5247
5248 if (orderByComparator != null) {
5249 query = new StringBundler(2 +
5250 (orderByComparator.getOrderByFields().length * 3));
5251
5252 query.append(_SQL_SELECT_PORTLETPREFERENCES);
5253
5254 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5255 orderByComparator);
5256
5257 sql = query.toString();
5258 }
5259 else {
5260 sql = _SQL_SELECT_PORTLETPREFERENCES;
5261
5262 if (pagination) {
5263 sql = sql.concat(PortletPreferencesModelImpl.ORDER_BY_JPQL);
5264 }
5265 }
5266
5267 Session session = null;
5268
5269 try {
5270 session = openSession();
5271
5272 Query q = session.createQuery(sql);
5273
5274 if (!pagination) {
5275 list = (List<PortletPreferences>)QueryUtil.list(q,
5276 getDialect(), start, end, false);
5277
5278 Collections.sort(list);
5279
5280 list = Collections.unmodifiableList(list);
5281 }
5282 else {
5283 list = (List<PortletPreferences>)QueryUtil.list(q,
5284 getDialect(), start, end);
5285 }
5286
5287 cacheResult(list);
5288
5289 finderCache.putResult(finderPath, finderArgs, list);
5290 }
5291 catch (Exception e) {
5292 finderCache.removeResult(finderPath, finderArgs);
5293
5294 throw processException(e);
5295 }
5296 finally {
5297 closeSession(session);
5298 }
5299 }
5300
5301 return list;
5302 }
5303
5304
5308 @Override
5309 public void removeAll() {
5310 for (PortletPreferences portletPreferences : findAll()) {
5311 remove(portletPreferences);
5312 }
5313 }
5314
5315
5320 @Override
5321 public int countAll() {
5322 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
5323 FINDER_ARGS_EMPTY, this);
5324
5325 if (count == null) {
5326 Session session = null;
5327
5328 try {
5329 session = openSession();
5330
5331 Query q = session.createQuery(_SQL_COUNT_PORTLETPREFERENCES);
5332
5333 count = (Long)q.uniqueResult();
5334
5335 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
5336 count);
5337 }
5338 catch (Exception e) {
5339 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
5340 FINDER_ARGS_EMPTY);
5341
5342 throw processException(e);
5343 }
5344 finally {
5345 closeSession(session);
5346 }
5347 }
5348
5349 return count.intValue();
5350 }
5351
5352 @Override
5353 protected Map<String, Integer> getTableColumnsMap() {
5354 return PortletPreferencesModelImpl.TABLE_COLUMNS_MAP;
5355 }
5356
5357
5360 public void afterPropertiesSet() {
5361 }
5362
5363 public void destroy() {
5364 entityCache.removeCache(PortletPreferencesImpl.class.getName());
5365 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
5366 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5367 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5368 }
5369
5370 @BeanReference(type = CompanyProviderWrapper.class)
5371 protected CompanyProvider companyProvider;
5372 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
5373 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
5374 private static final String _SQL_SELECT_PORTLETPREFERENCES = "SELECT portletPreferences FROM PortletPreferences portletPreferences";
5375 private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE_PKS_IN = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE portletPreferencesId IN (";
5376 private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE ";
5377 private static final String _SQL_COUNT_PORTLETPREFERENCES = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences";
5378 private static final String _SQL_COUNT_PORTLETPREFERENCES_WHERE = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences WHERE ";
5379 private static final String _ORDER_BY_ENTITY_ALIAS = "portletPreferences.";
5380 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletPreferences exists with the primary key ";
5381 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletPreferences exists with the key {";
5382 private static final Log _log = LogFactoryUtil.getLog(PortletPreferencesPersistenceImpl.class);
5383 private static final PortletPreferences _nullPortletPreferences = new PortletPreferencesImpl() {
5384 @Override
5385 public Object clone() {
5386 return this;
5387 }
5388
5389 @Override
5390 public CacheModel<PortletPreferences> toCacheModel() {
5391 return _nullPortletPreferencesCacheModel;
5392 }
5393 };
5394
5395 private static final CacheModel<PortletPreferences> _nullPortletPreferencesCacheModel =
5396 new NullCacheModel();
5397
5398 private static class NullCacheModel implements CacheModel<PortletPreferences>,
5399 MVCCModel {
5400 @Override
5401 public long getMvccVersion() {
5402 return -1;
5403 }
5404
5405 @Override
5406 public void setMvccVersion(long mvccVersion) {
5407 }
5408
5409 @Override
5410 public PortletPreferences toEntityModel() {
5411 return _nullPortletPreferences;
5412 }
5413 }
5414 }