001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPortletPreferencesException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.PortletPreferences;
040 import com.liferay.portal.model.impl.PortletPreferencesImpl;
041 import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
066 public class PortletPreferencesPersistenceImpl extends BasePersistenceImpl<PortletPreferences>
067 implements PortletPreferencesPersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = PortletPreferencesImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FIND_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
072 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
073 FINDER_CLASS_NAME_LIST, "findByPlid",
074 new String[] {
075 Long.class.getName(),
076
077 "java.lang.Integer", "java.lang.Integer",
078 "com.liferay.portal.kernel.util.OrderByComparator"
079 });
080 public static final FinderPath FINDER_PATH_COUNT_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
081 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
082 FINDER_CLASS_NAME_LIST, "countByPlid",
083 new String[] { Long.class.getName() });
084 public static final FinderPath FINDER_PATH_FIND_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
085 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
086 FINDER_CLASS_NAME_LIST, "findByP_P",
087 new String[] {
088 Long.class.getName(), String.class.getName(),
089
090 "java.lang.Integer", "java.lang.Integer",
091 "com.liferay.portal.kernel.util.OrderByComparator"
092 });
093 public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
094 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
095 FINDER_CLASS_NAME_LIST, "countByP_P",
096 new String[] { Long.class.getName(), String.class.getName() });
097 public static final FinderPath FINDER_PATH_FIND_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
098 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
099 FINDER_CLASS_NAME_LIST, "findByO_O_P",
100 new String[] {
101 Long.class.getName(), Integer.class.getName(),
102 Long.class.getName(),
103
104 "java.lang.Integer", "java.lang.Integer",
105 "com.liferay.portal.kernel.util.OrderByComparator"
106 });
107 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
108 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
109 FINDER_CLASS_NAME_LIST, "countByO_O_P",
110 new String[] {
111 Long.class.getName(), Integer.class.getName(),
112 Long.class.getName()
113 });
114 public static final FinderPath FINDER_PATH_FETCH_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
115 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
116 FINDER_CLASS_NAME_ENTITY, "fetchByO_O_P_P",
117 new String[] {
118 Long.class.getName(), Integer.class.getName(),
119 Long.class.getName(), String.class.getName()
120 });
121 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
122 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
123 FINDER_CLASS_NAME_LIST, "countByO_O_P_P",
124 new String[] {
125 Long.class.getName(), Integer.class.getName(),
126 Long.class.getName(), String.class.getName()
127 });
128 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
129 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
130 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
131 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
132 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
133 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
134
135
140 public void cacheResult(PortletPreferences portletPreferences) {
141 EntityCacheUtil.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
142 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
143 portletPreferences);
144
145 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
146 new Object[] {
147 new Long(portletPreferences.getOwnerId()),
148 new Integer(portletPreferences.getOwnerType()),
149 new Long(portletPreferences.getPlid()),
150
151 portletPreferences.getPortletId()
152 }, portletPreferences);
153 }
154
155
160 public void cacheResult(List<PortletPreferences> portletPreferenceses) {
161 for (PortletPreferences portletPreferences : portletPreferenceses) {
162 if (EntityCacheUtil.getResult(
163 PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
164 PortletPreferencesImpl.class,
165 portletPreferences.getPrimaryKey(), this) == null) {
166 cacheResult(portletPreferences);
167 }
168 }
169 }
170
171
178 public void clearCache() {
179 CacheRegistryUtil.clear(PortletPreferencesImpl.class.getName());
180 EntityCacheUtil.clearCache(PortletPreferencesImpl.class.getName());
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
183 }
184
185
192 public void clearCache(PortletPreferences portletPreferences) {
193 EntityCacheUtil.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
194 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
195
196 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
197 new Object[] {
198 new Long(portletPreferences.getOwnerId()),
199 new Integer(portletPreferences.getOwnerType()),
200 new Long(portletPreferences.getPlid()),
201
202 portletPreferences.getPortletId()
203 });
204 }
205
206
212 public PortletPreferences create(long portletPreferencesId) {
213 PortletPreferences portletPreferences = new PortletPreferencesImpl();
214
215 portletPreferences.setNew(true);
216 portletPreferences.setPrimaryKey(portletPreferencesId);
217
218 return portletPreferences;
219 }
220
221
229 public PortletPreferences remove(Serializable primaryKey)
230 throws NoSuchModelException, SystemException {
231 return remove(((Long)primaryKey).longValue());
232 }
233
234
242 public PortletPreferences remove(long portletPreferencesId)
243 throws NoSuchPortletPreferencesException, SystemException {
244 Session session = null;
245
246 try {
247 session = openSession();
248
249 PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
250 new Long(portletPreferencesId));
251
252 if (portletPreferences == null) {
253 if (_log.isWarnEnabled()) {
254 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
255 portletPreferencesId);
256 }
257
258 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
259 portletPreferencesId);
260 }
261
262 return remove(portletPreferences);
263 }
264 catch (NoSuchPortletPreferencesException nsee) {
265 throw nsee;
266 }
267 catch (Exception e) {
268 throw processException(e);
269 }
270 finally {
271 closeSession(session);
272 }
273 }
274
275 protected PortletPreferences removeImpl(
276 PortletPreferences portletPreferences) throws SystemException {
277 portletPreferences = toUnwrappedModel(portletPreferences);
278
279 Session session = null;
280
281 try {
282 session = openSession();
283
284 BatchSessionUtil.delete(session, portletPreferences);
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292
293 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
294
295 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
296
297 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
298 new Object[] {
299 new Long(portletPreferencesModelImpl.getOwnerId()),
300 new Integer(portletPreferencesModelImpl.getOwnerType()),
301 new Long(portletPreferencesModelImpl.getPlid()),
302
303 portletPreferencesModelImpl.getPortletId()
304 });
305
306 EntityCacheUtil.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
307 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
308
309 return portletPreferences;
310 }
311
312 public PortletPreferences updateImpl(
313 com.liferay.portal.model.PortletPreferences portletPreferences,
314 boolean merge) throws SystemException {
315 portletPreferences = toUnwrappedModel(portletPreferences);
316
317 boolean isNew = portletPreferences.isNew();
318
319 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
320
321 Session session = null;
322
323 try {
324 session = openSession();
325
326 BatchSessionUtil.update(session, portletPreferences, merge);
327
328 portletPreferences.setNew(false);
329 }
330 catch (Exception e) {
331 throw processException(e);
332 }
333 finally {
334 closeSession(session);
335 }
336
337 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
338
339 EntityCacheUtil.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
340 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
341 portletPreferences);
342
343 if (!isNew &&
344 ((portletPreferences.getOwnerId() != portletPreferencesModelImpl.getOriginalOwnerId()) ||
345 (portletPreferences.getOwnerType() != portletPreferencesModelImpl.getOriginalOwnerType()) ||
346 (portletPreferences.getPlid() != portletPreferencesModelImpl.getOriginalPlid()) ||
347 !Validator.equals(portletPreferences.getPortletId(),
348 portletPreferencesModelImpl.getOriginalPortletId()))) {
349 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
350 new Object[] {
351 new Long(portletPreferencesModelImpl.getOriginalOwnerId()),
352 new Integer(portletPreferencesModelImpl.getOriginalOwnerType()),
353 new Long(portletPreferencesModelImpl.getOriginalPlid()),
354
355 portletPreferencesModelImpl.getOriginalPortletId()
356 });
357 }
358
359 if (isNew ||
360 ((portletPreferences.getOwnerId() != portletPreferencesModelImpl.getOriginalOwnerId()) ||
361 (portletPreferences.getOwnerType() != portletPreferencesModelImpl.getOriginalOwnerType()) ||
362 (portletPreferences.getPlid() != portletPreferencesModelImpl.getOriginalPlid()) ||
363 !Validator.equals(portletPreferences.getPortletId(),
364 portletPreferencesModelImpl.getOriginalPortletId()))) {
365 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
366 new Object[] {
367 new Long(portletPreferences.getOwnerId()),
368 new Integer(portletPreferences.getOwnerType()),
369 new Long(portletPreferences.getPlid()),
370
371 portletPreferences.getPortletId()
372 }, portletPreferences);
373 }
374
375 return portletPreferences;
376 }
377
378 protected PortletPreferences toUnwrappedModel(
379 PortletPreferences portletPreferences) {
380 if (portletPreferences instanceof PortletPreferencesImpl) {
381 return portletPreferences;
382 }
383
384 PortletPreferencesImpl portletPreferencesImpl = new PortletPreferencesImpl();
385
386 portletPreferencesImpl.setNew(portletPreferences.isNew());
387 portletPreferencesImpl.setPrimaryKey(portletPreferences.getPrimaryKey());
388
389 portletPreferencesImpl.setPortletPreferencesId(portletPreferences.getPortletPreferencesId());
390 portletPreferencesImpl.setOwnerId(portletPreferences.getOwnerId());
391 portletPreferencesImpl.setOwnerType(portletPreferences.getOwnerType());
392 portletPreferencesImpl.setPlid(portletPreferences.getPlid());
393 portletPreferencesImpl.setPortletId(portletPreferences.getPortletId());
394 portletPreferencesImpl.setPreferences(portletPreferences.getPreferences());
395
396 return portletPreferencesImpl;
397 }
398
399
407 public PortletPreferences findByPrimaryKey(Serializable primaryKey)
408 throws NoSuchModelException, SystemException {
409 return findByPrimaryKey(((Long)primaryKey).longValue());
410 }
411
412
420 public PortletPreferences findByPrimaryKey(long portletPreferencesId)
421 throws NoSuchPortletPreferencesException, SystemException {
422 PortletPreferences portletPreferences = fetchByPrimaryKey(portletPreferencesId);
423
424 if (portletPreferences == null) {
425 if (_log.isWarnEnabled()) {
426 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
427 portletPreferencesId);
428 }
429
430 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
431 portletPreferencesId);
432 }
433
434 return portletPreferences;
435 }
436
437
444 public PortletPreferences fetchByPrimaryKey(Serializable primaryKey)
445 throws SystemException {
446 return fetchByPrimaryKey(((Long)primaryKey).longValue());
447 }
448
449
456 public PortletPreferences fetchByPrimaryKey(long portletPreferencesId)
457 throws SystemException {
458 PortletPreferences portletPreferences = (PortletPreferences)EntityCacheUtil.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
459 PortletPreferencesImpl.class, portletPreferencesId, this);
460
461 if (portletPreferences == null) {
462 Session session = null;
463
464 try {
465 session = openSession();
466
467 portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
468 new Long(portletPreferencesId));
469 }
470 catch (Exception e) {
471 throw processException(e);
472 }
473 finally {
474 if (portletPreferences != null) {
475 cacheResult(portletPreferences);
476 }
477
478 closeSession(session);
479 }
480 }
481
482 return portletPreferences;
483 }
484
485
492 public List<PortletPreferences> findByPlid(long plid)
493 throws SystemException {
494 return findByPlid(plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
495 }
496
497
510 public List<PortletPreferences> findByPlid(long plid, int start, int end)
511 throws SystemException {
512 return findByPlid(plid, start, end, null);
513 }
514
515
529 public List<PortletPreferences> findByPlid(long plid, int start, int end,
530 OrderByComparator orderByComparator) throws SystemException {
531 Object[] finderArgs = new Object[] {
532 plid,
533
534 String.valueOf(start), String.valueOf(end),
535 String.valueOf(orderByComparator)
536 };
537
538 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PLID,
539 finderArgs, this);
540
541 if (list == null) {
542 StringBundler query = null;
543
544 if (orderByComparator != null) {
545 query = new StringBundler(3 +
546 (orderByComparator.getOrderByFields().length * 3));
547 }
548 else {
549 query = new StringBundler(2);
550 }
551
552 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
553
554 query.append(_FINDER_COLUMN_PLID_PLID_2);
555
556 if (orderByComparator != null) {
557 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
558 orderByComparator);
559 }
560
561 String sql = query.toString();
562
563 Session session = null;
564
565 try {
566 session = openSession();
567
568 Query q = session.createQuery(sql);
569
570 QueryPos qPos = QueryPos.getInstance(q);
571
572 qPos.add(plid);
573
574 list = (List<PortletPreferences>)QueryUtil.list(q,
575 getDialect(), start, end);
576 }
577 catch (Exception e) {
578 throw processException(e);
579 }
580 finally {
581 if (list == null) {
582 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_PLID,
583 finderArgs);
584 }
585 else {
586 cacheResult(list);
587
588 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PLID,
589 finderArgs, list);
590 }
591
592 closeSession(session);
593 }
594 }
595
596 return list;
597 }
598
599
612 public PortletPreferences findByPlid_First(long plid,
613 OrderByComparator orderByComparator)
614 throws NoSuchPortletPreferencesException, SystemException {
615 List<PortletPreferences> list = findByPlid(plid, 0, 1, orderByComparator);
616
617 if (list.isEmpty()) {
618 StringBundler msg = new StringBundler(4);
619
620 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
621
622 msg.append("plid=");
623 msg.append(plid);
624
625 msg.append(StringPool.CLOSE_CURLY_BRACE);
626
627 throw new NoSuchPortletPreferencesException(msg.toString());
628 }
629 else {
630 return list.get(0);
631 }
632 }
633
634
647 public PortletPreferences findByPlid_Last(long plid,
648 OrderByComparator orderByComparator)
649 throws NoSuchPortletPreferencesException, SystemException {
650 int count = countByPlid(plid);
651
652 List<PortletPreferences> list = findByPlid(plid, count - 1, count,
653 orderByComparator);
654
655 if (list.isEmpty()) {
656 StringBundler msg = new StringBundler(4);
657
658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
659
660 msg.append("plid=");
661 msg.append(plid);
662
663 msg.append(StringPool.CLOSE_CURLY_BRACE);
664
665 throw new NoSuchPortletPreferencesException(msg.toString());
666 }
667 else {
668 return list.get(0);
669 }
670 }
671
672
686 public PortletPreferences[] findByPlid_PrevAndNext(
687 long portletPreferencesId, long plid,
688 OrderByComparator orderByComparator)
689 throws NoSuchPortletPreferencesException, SystemException {
690 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
691
692 Session session = null;
693
694 try {
695 session = openSession();
696
697 PortletPreferences[] array = new PortletPreferencesImpl[3];
698
699 array[0] = getByPlid_PrevAndNext(session, portletPreferences, plid,
700 orderByComparator, true);
701
702 array[1] = portletPreferences;
703
704 array[2] = getByPlid_PrevAndNext(session, portletPreferences, plid,
705 orderByComparator, false);
706
707 return array;
708 }
709 catch (Exception e) {
710 throw processException(e);
711 }
712 finally {
713 closeSession(session);
714 }
715 }
716
717 protected PortletPreferences getByPlid_PrevAndNext(Session session,
718 PortletPreferences portletPreferences, long plid,
719 OrderByComparator orderByComparator, boolean previous) {
720 StringBundler query = null;
721
722 if (orderByComparator != null) {
723 query = new StringBundler(6 +
724 (orderByComparator.getOrderByFields().length * 6));
725 }
726 else {
727 query = new StringBundler(3);
728 }
729
730 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
731
732 query.append(_FINDER_COLUMN_PLID_PLID_2);
733
734 if (orderByComparator != null) {
735 String[] orderByFields = orderByComparator.getOrderByFields();
736
737 if (orderByFields.length > 0) {
738 query.append(WHERE_AND);
739 }
740
741 for (int i = 0; i < orderByFields.length; i++) {
742 query.append(_ORDER_BY_ENTITY_ALIAS);
743 query.append(orderByFields[i]);
744
745 if ((i + 1) < orderByFields.length) {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(WHERE_GREATER_THAN_HAS_NEXT);
748 }
749 else {
750 query.append(WHERE_LESSER_THAN_HAS_NEXT);
751 }
752 }
753 else {
754 if (orderByComparator.isAscending() ^ previous) {
755 query.append(WHERE_GREATER_THAN);
756 }
757 else {
758 query.append(WHERE_LESSER_THAN);
759 }
760 }
761 }
762
763 query.append(ORDER_BY_CLAUSE);
764
765 for (int i = 0; i < orderByFields.length; i++) {
766 query.append(_ORDER_BY_ENTITY_ALIAS);
767 query.append(orderByFields[i]);
768
769 if ((i + 1) < orderByFields.length) {
770 if (orderByComparator.isAscending() ^ previous) {
771 query.append(ORDER_BY_ASC_HAS_NEXT);
772 }
773 else {
774 query.append(ORDER_BY_DESC_HAS_NEXT);
775 }
776 }
777 else {
778 if (orderByComparator.isAscending() ^ previous) {
779 query.append(ORDER_BY_ASC);
780 }
781 else {
782 query.append(ORDER_BY_DESC);
783 }
784 }
785 }
786 }
787
788 String sql = query.toString();
789
790 Query q = session.createQuery(sql);
791
792 q.setFirstResult(0);
793 q.setMaxResults(2);
794
795 QueryPos qPos = QueryPos.getInstance(q);
796
797 qPos.add(plid);
798
799 if (orderByComparator != null) {
800 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
801
802 for (Object value : values) {
803 qPos.add(value);
804 }
805 }
806
807 List<PortletPreferences> list = q.list();
808
809 if (list.size() == 2) {
810 return list.get(1);
811 }
812 else {
813 return null;
814 }
815 }
816
817
825 public List<PortletPreferences> findByP_P(long plid, String portletId)
826 throws SystemException {
827 return findByP_P(plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
828 null);
829 }
830
831
845 public List<PortletPreferences> findByP_P(long plid, String portletId,
846 int start, int end) throws SystemException {
847 return findByP_P(plid, portletId, start, end, null);
848 }
849
850
865 public List<PortletPreferences> findByP_P(long plid, String portletId,
866 int start, int end, OrderByComparator orderByComparator)
867 throws SystemException {
868 Object[] finderArgs = new Object[] {
869 plid, portletId,
870
871 String.valueOf(start), String.valueOf(end),
872 String.valueOf(orderByComparator)
873 };
874
875 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_P_P,
876 finderArgs, this);
877
878 if (list == null) {
879 StringBundler query = null;
880
881 if (orderByComparator != null) {
882 query = new StringBundler(4 +
883 (orderByComparator.getOrderByFields().length * 3));
884 }
885 else {
886 query = new StringBundler(3);
887 }
888
889 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
890
891 query.append(_FINDER_COLUMN_P_P_PLID_2);
892
893 if (portletId == null) {
894 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
895 }
896 else {
897 if (portletId.equals(StringPool.BLANK)) {
898 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
899 }
900 else {
901 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
902 }
903 }
904
905 if (orderByComparator != null) {
906 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
907 orderByComparator);
908 }
909
910 String sql = query.toString();
911
912 Session session = null;
913
914 try {
915 session = openSession();
916
917 Query q = session.createQuery(sql);
918
919 QueryPos qPos = QueryPos.getInstance(q);
920
921 qPos.add(plid);
922
923 if (portletId != null) {
924 qPos.add(portletId);
925 }
926
927 list = (List<PortletPreferences>)QueryUtil.list(q,
928 getDialect(), start, end);
929 }
930 catch (Exception e) {
931 throw processException(e);
932 }
933 finally {
934 if (list == null) {
935 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_P_P,
936 finderArgs);
937 }
938 else {
939 cacheResult(list);
940
941 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_P_P,
942 finderArgs, list);
943 }
944
945 closeSession(session);
946 }
947 }
948
949 return list;
950 }
951
952
966 public PortletPreferences findByP_P_First(long plid, String portletId,
967 OrderByComparator orderByComparator)
968 throws NoSuchPortletPreferencesException, SystemException {
969 List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1,
970 orderByComparator);
971
972 if (list.isEmpty()) {
973 StringBundler msg = new StringBundler(6);
974
975 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
976
977 msg.append("plid=");
978 msg.append(plid);
979
980 msg.append(", portletId=");
981 msg.append(portletId);
982
983 msg.append(StringPool.CLOSE_CURLY_BRACE);
984
985 throw new NoSuchPortletPreferencesException(msg.toString());
986 }
987 else {
988 return list.get(0);
989 }
990 }
991
992
1006 public PortletPreferences findByP_P_Last(long plid, String portletId,
1007 OrderByComparator orderByComparator)
1008 throws NoSuchPortletPreferencesException, SystemException {
1009 int count = countByP_P(plid, portletId);
1010
1011 List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
1012 count, orderByComparator);
1013
1014 if (list.isEmpty()) {
1015 StringBundler msg = new StringBundler(6);
1016
1017 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1018
1019 msg.append("plid=");
1020 msg.append(plid);
1021
1022 msg.append(", portletId=");
1023 msg.append(portletId);
1024
1025 msg.append(StringPool.CLOSE_CURLY_BRACE);
1026
1027 throw new NoSuchPortletPreferencesException(msg.toString());
1028 }
1029 else {
1030 return list.get(0);
1031 }
1032 }
1033
1034
1049 public PortletPreferences[] findByP_P_PrevAndNext(
1050 long portletPreferencesId, long plid, String portletId,
1051 OrderByComparator orderByComparator)
1052 throws NoSuchPortletPreferencesException, SystemException {
1053 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1054
1055 Session session = null;
1056
1057 try {
1058 session = openSession();
1059
1060 PortletPreferences[] array = new PortletPreferencesImpl[3];
1061
1062 array[0] = getByP_P_PrevAndNext(session, portletPreferences, plid,
1063 portletId, orderByComparator, true);
1064
1065 array[1] = portletPreferences;
1066
1067 array[2] = getByP_P_PrevAndNext(session, portletPreferences, plid,
1068 portletId, orderByComparator, false);
1069
1070 return array;
1071 }
1072 catch (Exception e) {
1073 throw processException(e);
1074 }
1075 finally {
1076 closeSession(session);
1077 }
1078 }
1079
1080 protected PortletPreferences getByP_P_PrevAndNext(Session session,
1081 PortletPreferences portletPreferences, long plid, String portletId,
1082 OrderByComparator orderByComparator, boolean previous) {
1083 StringBundler query = null;
1084
1085 if (orderByComparator != null) {
1086 query = new StringBundler(6 +
1087 (orderByComparator.getOrderByFields().length * 6));
1088 }
1089 else {
1090 query = new StringBundler(3);
1091 }
1092
1093 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1094
1095 query.append(_FINDER_COLUMN_P_P_PLID_2);
1096
1097 if (portletId == null) {
1098 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
1099 }
1100 else {
1101 if (portletId.equals(StringPool.BLANK)) {
1102 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
1103 }
1104 else {
1105 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
1106 }
1107 }
1108
1109 if (orderByComparator != null) {
1110 String[] orderByFields = orderByComparator.getOrderByFields();
1111
1112 if (orderByFields.length > 0) {
1113 query.append(WHERE_AND);
1114 }
1115
1116 for (int i = 0; i < orderByFields.length; i++) {
1117 query.append(_ORDER_BY_ENTITY_ALIAS);
1118 query.append(orderByFields[i]);
1119
1120 if ((i + 1) < orderByFields.length) {
1121 if (orderByComparator.isAscending() ^ previous) {
1122 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1123 }
1124 else {
1125 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1126 }
1127 }
1128 else {
1129 if (orderByComparator.isAscending() ^ previous) {
1130 query.append(WHERE_GREATER_THAN);
1131 }
1132 else {
1133 query.append(WHERE_LESSER_THAN);
1134 }
1135 }
1136 }
1137
1138 query.append(ORDER_BY_CLAUSE);
1139
1140 for (int i = 0; i < orderByFields.length; i++) {
1141 query.append(_ORDER_BY_ENTITY_ALIAS);
1142 query.append(orderByFields[i]);
1143
1144 if ((i + 1) < orderByFields.length) {
1145 if (orderByComparator.isAscending() ^ previous) {
1146 query.append(ORDER_BY_ASC_HAS_NEXT);
1147 }
1148 else {
1149 query.append(ORDER_BY_DESC_HAS_NEXT);
1150 }
1151 }
1152 else {
1153 if (orderByComparator.isAscending() ^ previous) {
1154 query.append(ORDER_BY_ASC);
1155 }
1156 else {
1157 query.append(ORDER_BY_DESC);
1158 }
1159 }
1160 }
1161 }
1162
1163 String sql = query.toString();
1164
1165 Query q = session.createQuery(sql);
1166
1167 q.setFirstResult(0);
1168 q.setMaxResults(2);
1169
1170 QueryPos qPos = QueryPos.getInstance(q);
1171
1172 qPos.add(plid);
1173
1174 if (portletId != null) {
1175 qPos.add(portletId);
1176 }
1177
1178 if (orderByComparator != null) {
1179 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
1180
1181 for (Object value : values) {
1182 qPos.add(value);
1183 }
1184 }
1185
1186 List<PortletPreferences> list = q.list();
1187
1188 if (list.size() == 2) {
1189 return list.get(1);
1190 }
1191 else {
1192 return null;
1193 }
1194 }
1195
1196
1205 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
1206 long plid) throws SystemException {
1207 return findByO_O_P(ownerId, ownerType, plid, QueryUtil.ALL_POS,
1208 QueryUtil.ALL_POS, null);
1209 }
1210
1211
1226 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
1227 long plid, int start, int end) throws SystemException {
1228 return findByO_O_P(ownerId, ownerType, plid, start, end, null);
1229 }
1230
1231
1247 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
1248 long plid, int start, int end, OrderByComparator orderByComparator)
1249 throws SystemException {
1250 Object[] finderArgs = new Object[] {
1251 ownerId, ownerType, plid,
1252
1253 String.valueOf(start), String.valueOf(end),
1254 String.valueOf(orderByComparator)
1255 };
1256
1257 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_O_O_P,
1258 finderArgs, this);
1259
1260 if (list == null) {
1261 StringBundler query = null;
1262
1263 if (orderByComparator != null) {
1264 query = new StringBundler(5 +
1265 (orderByComparator.getOrderByFields().length * 3));
1266 }
1267 else {
1268 query = new StringBundler(4);
1269 }
1270
1271 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1272
1273 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1274
1275 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1276
1277 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1278
1279 if (orderByComparator != null) {
1280 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1281 orderByComparator);
1282 }
1283
1284 String sql = query.toString();
1285
1286 Session session = null;
1287
1288 try {
1289 session = openSession();
1290
1291 Query q = session.createQuery(sql);
1292
1293 QueryPos qPos = QueryPos.getInstance(q);
1294
1295 qPos.add(ownerId);
1296
1297 qPos.add(ownerType);
1298
1299 qPos.add(plid);
1300
1301 list = (List<PortletPreferences>)QueryUtil.list(q,
1302 getDialect(), start, end);
1303 }
1304 catch (Exception e) {
1305 throw processException(e);
1306 }
1307 finally {
1308 if (list == null) {
1309 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_O_O_P,
1310 finderArgs);
1311 }
1312 else {
1313 cacheResult(list);
1314
1315 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_O_O_P,
1316 finderArgs, list);
1317 }
1318
1319 closeSession(session);
1320 }
1321 }
1322
1323 return list;
1324 }
1325
1326
1341 public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
1342 long plid, OrderByComparator orderByComparator)
1343 throws NoSuchPortletPreferencesException, SystemException {
1344 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
1345 0, 1, orderByComparator);
1346
1347 if (list.isEmpty()) {
1348 StringBundler msg = new StringBundler(8);
1349
1350 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351
1352 msg.append("ownerId=");
1353 msg.append(ownerId);
1354
1355 msg.append(", ownerType=");
1356 msg.append(ownerType);
1357
1358 msg.append(", plid=");
1359 msg.append(plid);
1360
1361 msg.append(StringPool.CLOSE_CURLY_BRACE);
1362
1363 throw new NoSuchPortletPreferencesException(msg.toString());
1364 }
1365 else {
1366 return list.get(0);
1367 }
1368 }
1369
1370
1385 public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
1386 long plid, OrderByComparator orderByComparator)
1387 throws NoSuchPortletPreferencesException, SystemException {
1388 int count = countByO_O_P(ownerId, ownerType, plid);
1389
1390 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
1391 count - 1, count, orderByComparator);
1392
1393 if (list.isEmpty()) {
1394 StringBundler msg = new StringBundler(8);
1395
1396 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1397
1398 msg.append("ownerId=");
1399 msg.append(ownerId);
1400
1401 msg.append(", ownerType=");
1402 msg.append(ownerType);
1403
1404 msg.append(", plid=");
1405 msg.append(plid);
1406
1407 msg.append(StringPool.CLOSE_CURLY_BRACE);
1408
1409 throw new NoSuchPortletPreferencesException(msg.toString());
1410 }
1411 else {
1412 return list.get(0);
1413 }
1414 }
1415
1416
1432 public PortletPreferences[] findByO_O_P_PrevAndNext(
1433 long portletPreferencesId, long ownerId, int ownerType, long plid,
1434 OrderByComparator orderByComparator)
1435 throws NoSuchPortletPreferencesException, SystemException {
1436 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1437
1438 Session session = null;
1439
1440 try {
1441 session = openSession();
1442
1443 PortletPreferences[] array = new PortletPreferencesImpl[3];
1444
1445 array[0] = getByO_O_P_PrevAndNext(session, portletPreferences,
1446 ownerId, ownerType, plid, orderByComparator, true);
1447
1448 array[1] = portletPreferences;
1449
1450 array[2] = getByO_O_P_PrevAndNext(session, portletPreferences,
1451 ownerId, ownerType, plid, orderByComparator, false);
1452
1453 return array;
1454 }
1455 catch (Exception e) {
1456 throw processException(e);
1457 }
1458 finally {
1459 closeSession(session);
1460 }
1461 }
1462
1463 protected PortletPreferences getByO_O_P_PrevAndNext(Session session,
1464 PortletPreferences portletPreferences, long ownerId, int ownerType,
1465 long plid, OrderByComparator orderByComparator, boolean previous) {
1466 StringBundler query = null;
1467
1468 if (orderByComparator != null) {
1469 query = new StringBundler(6 +
1470 (orderByComparator.getOrderByFields().length * 6));
1471 }
1472 else {
1473 query = new StringBundler(3);
1474 }
1475
1476 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1477
1478 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1479
1480 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1481
1482 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1483
1484 if (orderByComparator != null) {
1485 String[] orderByFields = orderByComparator.getOrderByFields();
1486
1487 if (orderByFields.length > 0) {
1488 query.append(WHERE_AND);
1489 }
1490
1491 for (int i = 0; i < orderByFields.length; i++) {
1492 query.append(_ORDER_BY_ENTITY_ALIAS);
1493 query.append(orderByFields[i]);
1494
1495 if ((i + 1) < orderByFields.length) {
1496 if (orderByComparator.isAscending() ^ previous) {
1497 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1498 }
1499 else {
1500 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1501 }
1502 }
1503 else {
1504 if (orderByComparator.isAscending() ^ previous) {
1505 query.append(WHERE_GREATER_THAN);
1506 }
1507 else {
1508 query.append(WHERE_LESSER_THAN);
1509 }
1510 }
1511 }
1512
1513 query.append(ORDER_BY_CLAUSE);
1514
1515 for (int i = 0; i < orderByFields.length; i++) {
1516 query.append(_ORDER_BY_ENTITY_ALIAS);
1517 query.append(orderByFields[i]);
1518
1519 if ((i + 1) < orderByFields.length) {
1520 if (orderByComparator.isAscending() ^ previous) {
1521 query.append(ORDER_BY_ASC_HAS_NEXT);
1522 }
1523 else {
1524 query.append(ORDER_BY_DESC_HAS_NEXT);
1525 }
1526 }
1527 else {
1528 if (orderByComparator.isAscending() ^ previous) {
1529 query.append(ORDER_BY_ASC);
1530 }
1531 else {
1532 query.append(ORDER_BY_DESC);
1533 }
1534 }
1535 }
1536 }
1537
1538 String sql = query.toString();
1539
1540 Query q = session.createQuery(sql);
1541
1542 q.setFirstResult(0);
1543 q.setMaxResults(2);
1544
1545 QueryPos qPos = QueryPos.getInstance(q);
1546
1547 qPos.add(ownerId);
1548
1549 qPos.add(ownerType);
1550
1551 qPos.add(plid);
1552
1553 if (orderByComparator != null) {
1554 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
1555
1556 for (Object value : values) {
1557 qPos.add(value);
1558 }
1559 }
1560
1561 List<PortletPreferences> list = q.list();
1562
1563 if (list.size() == 2) {
1564 return list.get(1);
1565 }
1566 else {
1567 return null;
1568 }
1569 }
1570
1571
1582 public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
1583 long plid, String portletId)
1584 throws NoSuchPortletPreferencesException, SystemException {
1585 PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
1586 ownerType, plid, portletId);
1587
1588 if (portletPreferences == null) {
1589 StringBundler msg = new StringBundler(10);
1590
1591 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1592
1593 msg.append("ownerId=");
1594 msg.append(ownerId);
1595
1596 msg.append(", ownerType=");
1597 msg.append(ownerType);
1598
1599 msg.append(", plid=");
1600 msg.append(plid);
1601
1602 msg.append(", portletId=");
1603 msg.append(portletId);
1604
1605 msg.append(StringPool.CLOSE_CURLY_BRACE);
1606
1607 if (_log.isWarnEnabled()) {
1608 _log.warn(msg.toString());
1609 }
1610
1611 throw new NoSuchPortletPreferencesException(msg.toString());
1612 }
1613
1614 return portletPreferences;
1615 }
1616
1617
1627 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1628 long plid, String portletId) throws SystemException {
1629 return fetchByO_O_P_P(ownerId, ownerType, plid, portletId, true);
1630 }
1631
1632
1642 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1643 long plid, String portletId, boolean retrieveFromCache)
1644 throws SystemException {
1645 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
1646
1647 Object result = null;
1648
1649 if (retrieveFromCache) {
1650 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1651 finderArgs, this);
1652 }
1653
1654 if (result == null) {
1655 StringBundler query = new StringBundler(5);
1656
1657 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1658
1659 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
1660
1661 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
1662
1663 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
1664
1665 if (portletId == null) {
1666 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
1667 }
1668 else {
1669 if (portletId.equals(StringPool.BLANK)) {
1670 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
1671 }
1672 else {
1673 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
1674 }
1675 }
1676
1677 String sql = query.toString();
1678
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 Query q = session.createQuery(sql);
1685
1686 QueryPos qPos = QueryPos.getInstance(q);
1687
1688 qPos.add(ownerId);
1689
1690 qPos.add(ownerType);
1691
1692 qPos.add(plid);
1693
1694 if (portletId != null) {
1695 qPos.add(portletId);
1696 }
1697
1698 List<PortletPreferences> list = q.list();
1699
1700 result = list;
1701
1702 PortletPreferences portletPreferences = null;
1703
1704 if (list.isEmpty()) {
1705 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1706 finderArgs, list);
1707 }
1708 else {
1709 portletPreferences = list.get(0);
1710
1711 cacheResult(portletPreferences);
1712
1713 if ((portletPreferences.getOwnerId() != ownerId) ||
1714 (portletPreferences.getOwnerType() != ownerType) ||
1715 (portletPreferences.getPlid() != plid) ||
1716 (portletPreferences.getPortletId() == null) ||
1717 !portletPreferences.getPortletId().equals(portletId)) {
1718 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1719 finderArgs, portletPreferences);
1720 }
1721 }
1722
1723 return portletPreferences;
1724 }
1725 catch (Exception e) {
1726 throw processException(e);
1727 }
1728 finally {
1729 if (result == null) {
1730 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1731 finderArgs);
1732 }
1733
1734 closeSession(session);
1735 }
1736 }
1737 else {
1738 if (result instanceof List<?>) {
1739 return null;
1740 }
1741 else {
1742 return (PortletPreferences)result;
1743 }
1744 }
1745 }
1746
1747
1753 public List<PortletPreferences> findAll() throws SystemException {
1754 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1755 }
1756
1757
1769 public List<PortletPreferences> findAll(int start, int end)
1770 throws SystemException {
1771 return findAll(start, end, null);
1772 }
1773
1774
1787 public List<PortletPreferences> findAll(int start, int end,
1788 OrderByComparator orderByComparator) throws SystemException {
1789 Object[] finderArgs = new Object[] {
1790 String.valueOf(start), String.valueOf(end),
1791 String.valueOf(orderByComparator)
1792 };
1793
1794 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1795 finderArgs, this);
1796
1797 if (list == null) {
1798 StringBundler query = null;
1799 String sql = null;
1800
1801 if (orderByComparator != null) {
1802 query = new StringBundler(2 +
1803 (orderByComparator.getOrderByFields().length * 3));
1804
1805 query.append(_SQL_SELECT_PORTLETPREFERENCES);
1806
1807 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1808 orderByComparator);
1809
1810 sql = query.toString();
1811 }
1812 else {
1813 sql = _SQL_SELECT_PORTLETPREFERENCES;
1814 }
1815
1816 Session session = null;
1817
1818 try {
1819 session = openSession();
1820
1821 Query q = session.createQuery(sql);
1822
1823 if (orderByComparator == null) {
1824 list = (List<PortletPreferences>)QueryUtil.list(q,
1825 getDialect(), start, end, false);
1826
1827 Collections.sort(list);
1828 }
1829 else {
1830 list = (List<PortletPreferences>)QueryUtil.list(q,
1831 getDialect(), start, end);
1832 }
1833 }
1834 catch (Exception e) {
1835 throw processException(e);
1836 }
1837 finally {
1838 if (list == null) {
1839 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1840 finderArgs);
1841 }
1842 else {
1843 cacheResult(list);
1844
1845 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1846 list);
1847 }
1848
1849 closeSession(session);
1850 }
1851 }
1852
1853 return list;
1854 }
1855
1856
1862 public void removeByPlid(long plid) throws SystemException {
1863 for (PortletPreferences portletPreferences : findByPlid(plid)) {
1864 remove(portletPreferences);
1865 }
1866 }
1867
1868
1875 public void removeByP_P(long plid, String portletId)
1876 throws SystemException {
1877 for (PortletPreferences portletPreferences : findByP_P(plid, portletId)) {
1878 remove(portletPreferences);
1879 }
1880 }
1881
1882
1890 public void removeByO_O_P(long ownerId, int ownerType, long plid)
1891 throws SystemException {
1892 for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
1893 ownerType, plid)) {
1894 remove(portletPreferences);
1895 }
1896 }
1897
1898
1907 public void removeByO_O_P_P(long ownerId, int ownerType, long plid,
1908 String portletId)
1909 throws NoSuchPortletPreferencesException, SystemException {
1910 PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
1911 ownerType, plid, portletId);
1912
1913 remove(portletPreferences);
1914 }
1915
1916
1921 public void removeAll() throws SystemException {
1922 for (PortletPreferences portletPreferences : findAll()) {
1923 remove(portletPreferences);
1924 }
1925 }
1926
1927
1934 public int countByPlid(long plid) throws SystemException {
1935 Object[] finderArgs = new Object[] { plid };
1936
1937 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PLID,
1938 finderArgs, this);
1939
1940 if (count == null) {
1941 StringBundler query = new StringBundler(2);
1942
1943 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1944
1945 query.append(_FINDER_COLUMN_PLID_PLID_2);
1946
1947 String sql = query.toString();
1948
1949 Session session = null;
1950
1951 try {
1952 session = openSession();
1953
1954 Query q = session.createQuery(sql);
1955
1956 QueryPos qPos = QueryPos.getInstance(q);
1957
1958 qPos.add(plid);
1959
1960 count = (Long)q.uniqueResult();
1961 }
1962 catch (Exception e) {
1963 throw processException(e);
1964 }
1965 finally {
1966 if (count == null) {
1967 count = Long.valueOf(0);
1968 }
1969
1970 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PLID,
1971 finderArgs, count);
1972
1973 closeSession(session);
1974 }
1975 }
1976
1977 return count.intValue();
1978 }
1979
1980
1988 public int countByP_P(long plid, String portletId)
1989 throws SystemException {
1990 Object[] finderArgs = new Object[] { plid, portletId };
1991
1992 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_P,
1993 finderArgs, this);
1994
1995 if (count == null) {
1996 StringBundler query = new StringBundler(3);
1997
1998 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1999
2000 query.append(_FINDER_COLUMN_P_P_PLID_2);
2001
2002 if (portletId == null) {
2003 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
2004 }
2005 else {
2006 if (portletId.equals(StringPool.BLANK)) {
2007 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
2008 }
2009 else {
2010 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
2011 }
2012 }
2013
2014 String sql = query.toString();
2015
2016 Session session = null;
2017
2018 try {
2019 session = openSession();
2020
2021 Query q = session.createQuery(sql);
2022
2023 QueryPos qPos = QueryPos.getInstance(q);
2024
2025 qPos.add(plid);
2026
2027 if (portletId != null) {
2028 qPos.add(portletId);
2029 }
2030
2031 count = (Long)q.uniqueResult();
2032 }
2033 catch (Exception e) {
2034 throw processException(e);
2035 }
2036 finally {
2037 if (count == null) {
2038 count = Long.valueOf(0);
2039 }
2040
2041 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, finderArgs,
2042 count);
2043
2044 closeSession(session);
2045 }
2046 }
2047
2048 return count.intValue();
2049 }
2050
2051
2060 public int countByO_O_P(long ownerId, int ownerType, long plid)
2061 throws SystemException {
2062 Object[] finderArgs = new Object[] { ownerId, ownerType, plid };
2063
2064 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O_P,
2065 finderArgs, this);
2066
2067 if (count == null) {
2068 StringBundler query = new StringBundler(4);
2069
2070 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2071
2072 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2073
2074 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2075
2076 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2077
2078 String sql = query.toString();
2079
2080 Session session = null;
2081
2082 try {
2083 session = openSession();
2084
2085 Query q = session.createQuery(sql);
2086
2087 QueryPos qPos = QueryPos.getInstance(q);
2088
2089 qPos.add(ownerId);
2090
2091 qPos.add(ownerType);
2092
2093 qPos.add(plid);
2094
2095 count = (Long)q.uniqueResult();
2096 }
2097 catch (Exception e) {
2098 throw processException(e);
2099 }
2100 finally {
2101 if (count == null) {
2102 count = Long.valueOf(0);
2103 }
2104
2105 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O_P,
2106 finderArgs, count);
2107
2108 closeSession(session);
2109 }
2110 }
2111
2112 return count.intValue();
2113 }
2114
2115
2125 public int countByO_O_P_P(long ownerId, int ownerType, long plid,
2126 String portletId) throws SystemException {
2127 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
2128
2129 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O_P_P,
2130 finderArgs, this);
2131
2132 if (count == null) {
2133 StringBundler query = new StringBundler(5);
2134
2135 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2136
2137 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
2138
2139 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
2140
2141 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
2142
2143 if (portletId == null) {
2144 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
2145 }
2146 else {
2147 if (portletId.equals(StringPool.BLANK)) {
2148 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
2149 }
2150 else {
2151 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
2152 }
2153 }
2154
2155 String sql = query.toString();
2156
2157 Session session = null;
2158
2159 try {
2160 session = openSession();
2161
2162 Query q = session.createQuery(sql);
2163
2164 QueryPos qPos = QueryPos.getInstance(q);
2165
2166 qPos.add(ownerId);
2167
2168 qPos.add(ownerType);
2169
2170 qPos.add(plid);
2171
2172 if (portletId != null) {
2173 qPos.add(portletId);
2174 }
2175
2176 count = (Long)q.uniqueResult();
2177 }
2178 catch (Exception e) {
2179 throw processException(e);
2180 }
2181 finally {
2182 if (count == null) {
2183 count = Long.valueOf(0);
2184 }
2185
2186 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O_P_P,
2187 finderArgs, count);
2188
2189 closeSession(session);
2190 }
2191 }
2192
2193 return count.intValue();
2194 }
2195
2196
2202 public int countAll() throws SystemException {
2203 Object[] finderArgs = new Object[0];
2204
2205 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2206 finderArgs, this);
2207
2208 if (count == null) {
2209 Session session = null;
2210
2211 try {
2212 session = openSession();
2213
2214 Query q = session.createQuery(_SQL_COUNT_PORTLETPREFERENCES);
2215
2216 count = (Long)q.uniqueResult();
2217 }
2218 catch (Exception e) {
2219 throw processException(e);
2220 }
2221 finally {
2222 if (count == null) {
2223 count = Long.valueOf(0);
2224 }
2225
2226 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2227 count);
2228
2229 closeSession(session);
2230 }
2231 }
2232
2233 return count.intValue();
2234 }
2235
2236
2239 public void afterPropertiesSet() {
2240 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2241 com.liferay.portal.util.PropsUtil.get(
2242 "value.object.listener.com.liferay.portal.model.PortletPreferences")));
2243
2244 if (listenerClassNames.length > 0) {
2245 try {
2246 List<ModelListener<PortletPreferences>> listenersList = new ArrayList<ModelListener<PortletPreferences>>();
2247
2248 for (String listenerClassName : listenerClassNames) {
2249 listenersList.add((ModelListener<PortletPreferences>)InstanceFactory.newInstance(
2250 listenerClassName));
2251 }
2252
2253 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2254 }
2255 catch (Exception e) {
2256 _log.error(e);
2257 }
2258 }
2259 }
2260
2261 public void destroy() {
2262 EntityCacheUtil.removeCache(PortletPreferencesImpl.class.getName());
2263 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2264 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2265 }
2266
2267 @BeanReference(type = AccountPersistence.class)
2268 protected AccountPersistence accountPersistence;
2269 @BeanReference(type = AddressPersistence.class)
2270 protected AddressPersistence addressPersistence;
2271 @BeanReference(type = BrowserTrackerPersistence.class)
2272 protected BrowserTrackerPersistence browserTrackerPersistence;
2273 @BeanReference(type = ClassNamePersistence.class)
2274 protected ClassNamePersistence classNamePersistence;
2275 @BeanReference(type = ClusterGroupPersistence.class)
2276 protected ClusterGroupPersistence clusterGroupPersistence;
2277 @BeanReference(type = CompanyPersistence.class)
2278 protected CompanyPersistence companyPersistence;
2279 @BeanReference(type = ContactPersistence.class)
2280 protected ContactPersistence contactPersistence;
2281 @BeanReference(type = CountryPersistence.class)
2282 protected CountryPersistence countryPersistence;
2283 @BeanReference(type = EmailAddressPersistence.class)
2284 protected EmailAddressPersistence emailAddressPersistence;
2285 @BeanReference(type = GroupPersistence.class)
2286 protected GroupPersistence groupPersistence;
2287 @BeanReference(type = ImagePersistence.class)
2288 protected ImagePersistence imagePersistence;
2289 @BeanReference(type = LayoutPersistence.class)
2290 protected LayoutPersistence layoutPersistence;
2291 @BeanReference(type = LayoutPrototypePersistence.class)
2292 protected LayoutPrototypePersistence layoutPrototypePersistence;
2293 @BeanReference(type = LayoutSetPersistence.class)
2294 protected LayoutSetPersistence layoutSetPersistence;
2295 @BeanReference(type = LayoutSetPrototypePersistence.class)
2296 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2297 @BeanReference(type = ListTypePersistence.class)
2298 protected ListTypePersistence listTypePersistence;
2299 @BeanReference(type = LockPersistence.class)
2300 protected LockPersistence lockPersistence;
2301 @BeanReference(type = MembershipRequestPersistence.class)
2302 protected MembershipRequestPersistence membershipRequestPersistence;
2303 @BeanReference(type = OrganizationPersistence.class)
2304 protected OrganizationPersistence organizationPersistence;
2305 @BeanReference(type = OrgGroupPermissionPersistence.class)
2306 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2307 @BeanReference(type = OrgGroupRolePersistence.class)
2308 protected OrgGroupRolePersistence orgGroupRolePersistence;
2309 @BeanReference(type = OrgLaborPersistence.class)
2310 protected OrgLaborPersistence orgLaborPersistence;
2311 @BeanReference(type = PasswordPolicyPersistence.class)
2312 protected PasswordPolicyPersistence passwordPolicyPersistence;
2313 @BeanReference(type = PasswordPolicyRelPersistence.class)
2314 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2315 @BeanReference(type = PasswordTrackerPersistence.class)
2316 protected PasswordTrackerPersistence passwordTrackerPersistence;
2317 @BeanReference(type = PermissionPersistence.class)
2318 protected PermissionPersistence permissionPersistence;
2319 @BeanReference(type = PhonePersistence.class)
2320 protected PhonePersistence phonePersistence;
2321 @BeanReference(type = PluginSettingPersistence.class)
2322 protected PluginSettingPersistence pluginSettingPersistence;
2323 @BeanReference(type = PortletPersistence.class)
2324 protected PortletPersistence portletPersistence;
2325 @BeanReference(type = PortletItemPersistence.class)
2326 protected PortletItemPersistence portletItemPersistence;
2327 @BeanReference(type = PortletPreferencesPersistence.class)
2328 protected PortletPreferencesPersistence portletPreferencesPersistence;
2329 @BeanReference(type = RegionPersistence.class)
2330 protected RegionPersistence regionPersistence;
2331 @BeanReference(type = ReleasePersistence.class)
2332 protected ReleasePersistence releasePersistence;
2333 @BeanReference(type = ResourcePersistence.class)
2334 protected ResourcePersistence resourcePersistence;
2335 @BeanReference(type = ResourceActionPersistence.class)
2336 protected ResourceActionPersistence resourceActionPersistence;
2337 @BeanReference(type = ResourceCodePersistence.class)
2338 protected ResourceCodePersistence resourceCodePersistence;
2339 @BeanReference(type = ResourcePermissionPersistence.class)
2340 protected ResourcePermissionPersistence resourcePermissionPersistence;
2341 @BeanReference(type = RolePersistence.class)
2342 protected RolePersistence rolePersistence;
2343 @BeanReference(type = ServiceComponentPersistence.class)
2344 protected ServiceComponentPersistence serviceComponentPersistence;
2345 @BeanReference(type = ShardPersistence.class)
2346 protected ShardPersistence shardPersistence;
2347 @BeanReference(type = SubscriptionPersistence.class)
2348 protected SubscriptionPersistence subscriptionPersistence;
2349 @BeanReference(type = TicketPersistence.class)
2350 protected TicketPersistence ticketPersistence;
2351 @BeanReference(type = TeamPersistence.class)
2352 protected TeamPersistence teamPersistence;
2353 @BeanReference(type = UserPersistence.class)
2354 protected UserPersistence userPersistence;
2355 @BeanReference(type = UserGroupPersistence.class)
2356 protected UserGroupPersistence userGroupPersistence;
2357 @BeanReference(type = UserGroupGroupRolePersistence.class)
2358 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2359 @BeanReference(type = UserGroupRolePersistence.class)
2360 protected UserGroupRolePersistence userGroupRolePersistence;
2361 @BeanReference(type = UserIdMapperPersistence.class)
2362 protected UserIdMapperPersistence userIdMapperPersistence;
2363 @BeanReference(type = UserTrackerPersistence.class)
2364 protected UserTrackerPersistence userTrackerPersistence;
2365 @BeanReference(type = UserTrackerPathPersistence.class)
2366 protected UserTrackerPathPersistence userTrackerPathPersistence;
2367 @BeanReference(type = WebDAVPropsPersistence.class)
2368 protected WebDAVPropsPersistence webDAVPropsPersistence;
2369 @BeanReference(type = WebsitePersistence.class)
2370 protected WebsitePersistence websitePersistence;
2371 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2372 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2373 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2374 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2375 private static final String _SQL_SELECT_PORTLETPREFERENCES = "SELECT portletPreferences FROM PortletPreferences portletPreferences";
2376 private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE ";
2377 private static final String _SQL_COUNT_PORTLETPREFERENCES = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences";
2378 private static final String _SQL_COUNT_PORTLETPREFERENCES_WHERE = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences WHERE ";
2379 private static final String _FINDER_COLUMN_PLID_PLID_2 = "portletPreferences.plid = ?";
2380 private static final String _FINDER_COLUMN_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
2381 private static final String _FINDER_COLUMN_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
2382 private static final String _FINDER_COLUMN_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
2383 private static final String _FINDER_COLUMN_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = ?)";
2384 private static final String _FINDER_COLUMN_O_O_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
2385 private static final String _FINDER_COLUMN_O_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
2386 private static final String _FINDER_COLUMN_O_O_P_PLID_2 = "portletPreferences.plid = ?";
2387 private static final String _FINDER_COLUMN_O_O_P_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
2388 private static final String _FINDER_COLUMN_O_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
2389 private static final String _FINDER_COLUMN_O_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
2390 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
2391 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
2392 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = ?)";
2393 private static final String _ORDER_BY_ENTITY_ALIAS = "portletPreferences.";
2394 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletPreferences exists with the primary key ";
2395 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletPreferences exists with the key {";
2396 private static Log _log = LogFactoryUtil.getLog(PortletPreferencesPersistenceImpl.class);
2397 }