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