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 if (portletPreferences.isCachedModel() ||
285 BatchSessionUtil.isEnabled()) {
286 Object staleObject = session.get(PortletPreferencesImpl.class,
287 portletPreferences.getPrimaryKeyObj());
288
289 if (staleObject != null) {
290 session.evict(staleObject);
291 }
292 }
293
294 session.delete(portletPreferences);
295
296 session.flush();
297 }
298 catch (Exception e) {
299 throw processException(e);
300 }
301 finally {
302 closeSession(session);
303 }
304
305 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
306
307 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
308
309 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
310 new Object[] {
311 new Long(portletPreferencesModelImpl.getOriginalOwnerId()),
312 new Integer(portletPreferencesModelImpl.getOriginalOwnerType()),
313 new Long(portletPreferencesModelImpl.getOriginalPlid()),
314
315 portletPreferencesModelImpl.getOriginalPortletId()
316 });
317
318 EntityCacheUtil.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
319 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
320
321 return portletPreferences;
322 }
323
324 public PortletPreferences updateImpl(
325 com.liferay.portal.model.PortletPreferences portletPreferences,
326 boolean merge) throws SystemException {
327 portletPreferences = toUnwrappedModel(portletPreferences);
328
329 boolean isNew = portletPreferences.isNew();
330
331 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
332
333 Session session = null;
334
335 try {
336 session = openSession();
337
338 BatchSessionUtil.update(session, portletPreferences, merge);
339
340 portletPreferences.setNew(false);
341 }
342 catch (Exception e) {
343 throw processException(e);
344 }
345 finally {
346 closeSession(session);
347 }
348
349 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
350
351 EntityCacheUtil.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
352 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
353 portletPreferences);
354
355 if (!isNew &&
356 ((portletPreferences.getOwnerId() != portletPreferencesModelImpl.getOriginalOwnerId()) ||
357 (portletPreferences.getOwnerType() != portletPreferencesModelImpl.getOriginalOwnerType()) ||
358 (portletPreferences.getPlid() != portletPreferencesModelImpl.getOriginalPlid()) ||
359 !Validator.equals(portletPreferences.getPortletId(),
360 portletPreferencesModelImpl.getOriginalPortletId()))) {
361 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
362 new Object[] {
363 new Long(portletPreferencesModelImpl.getOriginalOwnerId()),
364 new Integer(portletPreferencesModelImpl.getOriginalOwnerType()),
365 new Long(portletPreferencesModelImpl.getOriginalPlid()),
366
367 portletPreferencesModelImpl.getOriginalPortletId()
368 });
369 }
370
371 if (isNew ||
372 ((portletPreferences.getOwnerId() != portletPreferencesModelImpl.getOriginalOwnerId()) ||
373 (portletPreferences.getOwnerType() != portletPreferencesModelImpl.getOriginalOwnerType()) ||
374 (portletPreferences.getPlid() != portletPreferencesModelImpl.getOriginalPlid()) ||
375 !Validator.equals(portletPreferences.getPortletId(),
376 portletPreferencesModelImpl.getOriginalPortletId()))) {
377 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
378 new Object[] {
379 new Long(portletPreferences.getOwnerId()),
380 new Integer(portletPreferences.getOwnerType()),
381 new Long(portletPreferences.getPlid()),
382
383 portletPreferences.getPortletId()
384 }, portletPreferences);
385 }
386
387 return portletPreferences;
388 }
389
390 protected PortletPreferences toUnwrappedModel(
391 PortletPreferences portletPreferences) {
392 if (portletPreferences instanceof PortletPreferencesImpl) {
393 return portletPreferences;
394 }
395
396 PortletPreferencesImpl portletPreferencesImpl = new PortletPreferencesImpl();
397
398 portletPreferencesImpl.setNew(portletPreferences.isNew());
399 portletPreferencesImpl.setPrimaryKey(portletPreferences.getPrimaryKey());
400
401 portletPreferencesImpl.setPortletPreferencesId(portletPreferences.getPortletPreferencesId());
402 portletPreferencesImpl.setOwnerId(portletPreferences.getOwnerId());
403 portletPreferencesImpl.setOwnerType(portletPreferences.getOwnerType());
404 portletPreferencesImpl.setPlid(portletPreferences.getPlid());
405 portletPreferencesImpl.setPortletId(portletPreferences.getPortletId());
406 portletPreferencesImpl.setPreferences(portletPreferences.getPreferences());
407
408 return portletPreferencesImpl;
409 }
410
411
419 public PortletPreferences findByPrimaryKey(Serializable primaryKey)
420 throws NoSuchModelException, SystemException {
421 return findByPrimaryKey(((Long)primaryKey).longValue());
422 }
423
424
432 public PortletPreferences findByPrimaryKey(long portletPreferencesId)
433 throws NoSuchPortletPreferencesException, SystemException {
434 PortletPreferences portletPreferences = fetchByPrimaryKey(portletPreferencesId);
435
436 if (portletPreferences == null) {
437 if (_log.isWarnEnabled()) {
438 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
439 portletPreferencesId);
440 }
441
442 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
443 portletPreferencesId);
444 }
445
446 return portletPreferences;
447 }
448
449
456 public PortletPreferences fetchByPrimaryKey(Serializable primaryKey)
457 throws SystemException {
458 return fetchByPrimaryKey(((Long)primaryKey).longValue());
459 }
460
461
468 public PortletPreferences fetchByPrimaryKey(long portletPreferencesId)
469 throws SystemException {
470 PortletPreferences portletPreferences = (PortletPreferences)EntityCacheUtil.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
471 PortletPreferencesImpl.class, portletPreferencesId, this);
472
473 if (portletPreferences == null) {
474 Session session = null;
475
476 try {
477 session = openSession();
478
479 portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
480 new Long(portletPreferencesId));
481 }
482 catch (Exception e) {
483 throw processException(e);
484 }
485 finally {
486 if (portletPreferences != null) {
487 cacheResult(portletPreferences);
488 }
489
490 closeSession(session);
491 }
492 }
493
494 return portletPreferences;
495 }
496
497
504 public List<PortletPreferences> findByPlid(long plid)
505 throws SystemException {
506 return findByPlid(plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
507 }
508
509
522 public List<PortletPreferences> findByPlid(long plid, int start, int end)
523 throws SystemException {
524 return findByPlid(plid, start, end, null);
525 }
526
527
541 public List<PortletPreferences> findByPlid(long plid, int start, int end,
542 OrderByComparator orderByComparator) throws SystemException {
543 Object[] finderArgs = new Object[] {
544 plid,
545
546 String.valueOf(start), String.valueOf(end),
547 String.valueOf(orderByComparator)
548 };
549
550 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PLID,
551 finderArgs, this);
552
553 if (list == null) {
554 Session session = null;
555
556 try {
557 session = openSession();
558
559 StringBundler query = null;
560
561 if (orderByComparator != null) {
562 query = new StringBundler(3 +
563 (orderByComparator.getOrderByFields().length * 3));
564 }
565 else {
566 query = new StringBundler(2);
567 }
568
569 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
570
571 query.append(_FINDER_COLUMN_PLID_PLID_2);
572
573 if (orderByComparator != null) {
574 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
575 orderByComparator);
576 }
577
578 String sql = query.toString();
579
580 Query q = session.createQuery(sql);
581
582 QueryPos qPos = QueryPos.getInstance(q);
583
584 qPos.add(plid);
585
586 list = (List<PortletPreferences>)QueryUtil.list(q,
587 getDialect(), start, end);
588 }
589 catch (Exception e) {
590 throw processException(e);
591 }
592 finally {
593 if (list == null) {
594 list = new ArrayList<PortletPreferences>();
595 }
596
597 cacheResult(list);
598
599 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PLID, finderArgs,
600 list);
601
602 closeSession(session);
603 }
604 }
605
606 return list;
607 }
608
609
622 public PortletPreferences findByPlid_First(long plid,
623 OrderByComparator orderByComparator)
624 throws NoSuchPortletPreferencesException, SystemException {
625 List<PortletPreferences> list = findByPlid(plid, 0, 1, orderByComparator);
626
627 if (list.isEmpty()) {
628 StringBundler msg = new StringBundler(4);
629
630 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631
632 msg.append("plid=");
633 msg.append(plid);
634
635 msg.append(StringPool.CLOSE_CURLY_BRACE);
636
637 throw new NoSuchPortletPreferencesException(msg.toString());
638 }
639 else {
640 return list.get(0);
641 }
642 }
643
644
657 public PortletPreferences findByPlid_Last(long plid,
658 OrderByComparator orderByComparator)
659 throws NoSuchPortletPreferencesException, SystemException {
660 int count = countByPlid(plid);
661
662 List<PortletPreferences> list = findByPlid(plid, count - 1, count,
663 orderByComparator);
664
665 if (list.isEmpty()) {
666 StringBundler msg = new StringBundler(4);
667
668 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
669
670 msg.append("plid=");
671 msg.append(plid);
672
673 msg.append(StringPool.CLOSE_CURLY_BRACE);
674
675 throw new NoSuchPortletPreferencesException(msg.toString());
676 }
677 else {
678 return list.get(0);
679 }
680 }
681
682
696 public PortletPreferences[] findByPlid_PrevAndNext(
697 long portletPreferencesId, long plid,
698 OrderByComparator orderByComparator)
699 throws NoSuchPortletPreferencesException, SystemException {
700 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
701
702 Session session = null;
703
704 try {
705 session = openSession();
706
707 PortletPreferences[] array = new PortletPreferencesImpl[3];
708
709 array[0] = getByPlid_PrevAndNext(session, portletPreferences, plid,
710 orderByComparator, true);
711
712 array[1] = portletPreferences;
713
714 array[2] = getByPlid_PrevAndNext(session, portletPreferences, plid,
715 orderByComparator, false);
716
717 return array;
718 }
719 catch (Exception e) {
720 throw processException(e);
721 }
722 finally {
723 closeSession(session);
724 }
725 }
726
727 protected PortletPreferences getByPlid_PrevAndNext(Session session,
728 PortletPreferences portletPreferences, long plid,
729 OrderByComparator orderByComparator, boolean previous) {
730 StringBundler query = null;
731
732 if (orderByComparator != null) {
733 query = new StringBundler(6 +
734 (orderByComparator.getOrderByFields().length * 6));
735 }
736 else {
737 query = new StringBundler(3);
738 }
739
740 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
741
742 query.append(_FINDER_COLUMN_PLID_PLID_2);
743
744 if (orderByComparator != null) {
745 String[] orderByFields = orderByComparator.getOrderByFields();
746
747 if (orderByFields.length > 0) {
748 query.append(WHERE_AND);
749 }
750
751 for (int i = 0; i < orderByFields.length; i++) {
752 query.append(_ORDER_BY_ENTITY_ALIAS);
753 query.append(orderByFields[i]);
754
755 if ((i + 1) < orderByFields.length) {
756 if (orderByComparator.isAscending() ^ previous) {
757 query.append(WHERE_GREATER_THAN_HAS_NEXT);
758 }
759 else {
760 query.append(WHERE_LESSER_THAN_HAS_NEXT);
761 }
762 }
763 else {
764 if (orderByComparator.isAscending() ^ previous) {
765 query.append(WHERE_GREATER_THAN);
766 }
767 else {
768 query.append(WHERE_LESSER_THAN);
769 }
770 }
771 }
772
773 query.append(ORDER_BY_CLAUSE);
774
775 for (int i = 0; i < orderByFields.length; i++) {
776 query.append(_ORDER_BY_ENTITY_ALIAS);
777 query.append(orderByFields[i]);
778
779 if ((i + 1) < orderByFields.length) {
780 if (orderByComparator.isAscending() ^ previous) {
781 query.append(ORDER_BY_ASC_HAS_NEXT);
782 }
783 else {
784 query.append(ORDER_BY_DESC_HAS_NEXT);
785 }
786 }
787 else {
788 if (orderByComparator.isAscending() ^ previous) {
789 query.append(ORDER_BY_ASC);
790 }
791 else {
792 query.append(ORDER_BY_DESC);
793 }
794 }
795 }
796 }
797
798 String sql = query.toString();
799
800 Query q = session.createQuery(sql);
801
802 q.setFirstResult(0);
803 q.setMaxResults(2);
804
805 QueryPos qPos = QueryPos.getInstance(q);
806
807 qPos.add(plid);
808
809 if (orderByComparator != null) {
810 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
811
812 for (Object value : values) {
813 qPos.add(value);
814 }
815 }
816
817 List<PortletPreferences> list = q.list();
818
819 if (list.size() == 2) {
820 return list.get(1);
821 }
822 else {
823 return null;
824 }
825 }
826
827
835 public List<PortletPreferences> findByP_P(long plid, String portletId)
836 throws SystemException {
837 return findByP_P(plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
838 null);
839 }
840
841
855 public List<PortletPreferences> findByP_P(long plid, String portletId,
856 int start, int end) throws SystemException {
857 return findByP_P(plid, portletId, start, end, null);
858 }
859
860
875 public List<PortletPreferences> findByP_P(long plid, String portletId,
876 int start, int end, OrderByComparator orderByComparator)
877 throws SystemException {
878 Object[] finderArgs = new Object[] {
879 plid, portletId,
880
881 String.valueOf(start), String.valueOf(end),
882 String.valueOf(orderByComparator)
883 };
884
885 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_P_P,
886 finderArgs, this);
887
888 if (list == null) {
889 Session session = null;
890
891 try {
892 session = openSession();
893
894 StringBundler query = null;
895
896 if (orderByComparator != null) {
897 query = new StringBundler(4 +
898 (orderByComparator.getOrderByFields().length * 3));
899 }
900 else {
901 query = new StringBundler(3);
902 }
903
904 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
905
906 query.append(_FINDER_COLUMN_P_P_PLID_2);
907
908 if (portletId == null) {
909 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
910 }
911 else {
912 if (portletId.equals(StringPool.BLANK)) {
913 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
914 }
915 else {
916 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
917 }
918 }
919
920 if (orderByComparator != null) {
921 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
922 orderByComparator);
923 }
924
925 String sql = query.toString();
926
927 Query q = session.createQuery(sql);
928
929 QueryPos qPos = QueryPos.getInstance(q);
930
931 qPos.add(plid);
932
933 if (portletId != null) {
934 qPos.add(portletId);
935 }
936
937 list = (List<PortletPreferences>)QueryUtil.list(q,
938 getDialect(), start, end);
939 }
940 catch (Exception e) {
941 throw processException(e);
942 }
943 finally {
944 if (list == null) {
945 list = new ArrayList<PortletPreferences>();
946 }
947
948 cacheResult(list);
949
950 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_P_P, finderArgs,
951 list);
952
953 closeSession(session);
954 }
955 }
956
957 return list;
958 }
959
960
974 public PortletPreferences findByP_P_First(long plid, String portletId,
975 OrderByComparator orderByComparator)
976 throws NoSuchPortletPreferencesException, SystemException {
977 List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1,
978 orderByComparator);
979
980 if (list.isEmpty()) {
981 StringBundler msg = new StringBundler(6);
982
983 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
984
985 msg.append("plid=");
986 msg.append(plid);
987
988 msg.append(", portletId=");
989 msg.append(portletId);
990
991 msg.append(StringPool.CLOSE_CURLY_BRACE);
992
993 throw new NoSuchPortletPreferencesException(msg.toString());
994 }
995 else {
996 return list.get(0);
997 }
998 }
999
1000
1014 public PortletPreferences findByP_P_Last(long plid, String portletId,
1015 OrderByComparator orderByComparator)
1016 throws NoSuchPortletPreferencesException, SystemException {
1017 int count = countByP_P(plid, portletId);
1018
1019 List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
1020 count, orderByComparator);
1021
1022 if (list.isEmpty()) {
1023 StringBundler msg = new StringBundler(6);
1024
1025 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1026
1027 msg.append("plid=");
1028 msg.append(plid);
1029
1030 msg.append(", portletId=");
1031 msg.append(portletId);
1032
1033 msg.append(StringPool.CLOSE_CURLY_BRACE);
1034
1035 throw new NoSuchPortletPreferencesException(msg.toString());
1036 }
1037 else {
1038 return list.get(0);
1039 }
1040 }
1041
1042
1057 public PortletPreferences[] findByP_P_PrevAndNext(
1058 long portletPreferencesId, long plid, String portletId,
1059 OrderByComparator orderByComparator)
1060 throws NoSuchPortletPreferencesException, SystemException {
1061 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1062
1063 Session session = null;
1064
1065 try {
1066 session = openSession();
1067
1068 PortletPreferences[] array = new PortletPreferencesImpl[3];
1069
1070 array[0] = getByP_P_PrevAndNext(session, portletPreferences, plid,
1071 portletId, orderByComparator, true);
1072
1073 array[1] = portletPreferences;
1074
1075 array[2] = getByP_P_PrevAndNext(session, portletPreferences, plid,
1076 portletId, orderByComparator, false);
1077
1078 return array;
1079 }
1080 catch (Exception e) {
1081 throw processException(e);
1082 }
1083 finally {
1084 closeSession(session);
1085 }
1086 }
1087
1088 protected PortletPreferences getByP_P_PrevAndNext(Session session,
1089 PortletPreferences portletPreferences, long plid, String portletId,
1090 OrderByComparator orderByComparator, boolean previous) {
1091 StringBundler query = null;
1092
1093 if (orderByComparator != null) {
1094 query = new StringBundler(6 +
1095 (orderByComparator.getOrderByFields().length * 6));
1096 }
1097 else {
1098 query = new StringBundler(3);
1099 }
1100
1101 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1102
1103 query.append(_FINDER_COLUMN_P_P_PLID_2);
1104
1105 if (portletId == null) {
1106 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
1107 }
1108 else {
1109 if (portletId.equals(StringPool.BLANK)) {
1110 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
1111 }
1112 else {
1113 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
1114 }
1115 }
1116
1117 if (orderByComparator != null) {
1118 String[] orderByFields = orderByComparator.getOrderByFields();
1119
1120 if (orderByFields.length > 0) {
1121 query.append(WHERE_AND);
1122 }
1123
1124 for (int i = 0; i < orderByFields.length; i++) {
1125 query.append(_ORDER_BY_ENTITY_ALIAS);
1126 query.append(orderByFields[i]);
1127
1128 if ((i + 1) < orderByFields.length) {
1129 if (orderByComparator.isAscending() ^ previous) {
1130 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1131 }
1132 else {
1133 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1134 }
1135 }
1136 else {
1137 if (orderByComparator.isAscending() ^ previous) {
1138 query.append(WHERE_GREATER_THAN);
1139 }
1140 else {
1141 query.append(WHERE_LESSER_THAN);
1142 }
1143 }
1144 }
1145
1146 query.append(ORDER_BY_CLAUSE);
1147
1148 for (int i = 0; i < orderByFields.length; i++) {
1149 query.append(_ORDER_BY_ENTITY_ALIAS);
1150 query.append(orderByFields[i]);
1151
1152 if ((i + 1) < orderByFields.length) {
1153 if (orderByComparator.isAscending() ^ previous) {
1154 query.append(ORDER_BY_ASC_HAS_NEXT);
1155 }
1156 else {
1157 query.append(ORDER_BY_DESC_HAS_NEXT);
1158 }
1159 }
1160 else {
1161 if (orderByComparator.isAscending() ^ previous) {
1162 query.append(ORDER_BY_ASC);
1163 }
1164 else {
1165 query.append(ORDER_BY_DESC);
1166 }
1167 }
1168 }
1169 }
1170
1171 String sql = query.toString();
1172
1173 Query q = session.createQuery(sql);
1174
1175 q.setFirstResult(0);
1176 q.setMaxResults(2);
1177
1178 QueryPos qPos = QueryPos.getInstance(q);
1179
1180 qPos.add(plid);
1181
1182 if (portletId != null) {
1183 qPos.add(portletId);
1184 }
1185
1186 if (orderByComparator != null) {
1187 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
1188
1189 for (Object value : values) {
1190 qPos.add(value);
1191 }
1192 }
1193
1194 List<PortletPreferences> list = q.list();
1195
1196 if (list.size() == 2) {
1197 return list.get(1);
1198 }
1199 else {
1200 return null;
1201 }
1202 }
1203
1204
1213 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
1214 long plid) throws SystemException {
1215 return findByO_O_P(ownerId, ownerType, plid, QueryUtil.ALL_POS,
1216 QueryUtil.ALL_POS, null);
1217 }
1218
1219
1234 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
1235 long plid, int start, int end) throws SystemException {
1236 return findByO_O_P(ownerId, ownerType, plid, start, end, null);
1237 }
1238
1239
1255 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
1256 long plid, int start, int end, OrderByComparator orderByComparator)
1257 throws SystemException {
1258 Object[] finderArgs = new Object[] {
1259 ownerId, ownerType, plid,
1260
1261 String.valueOf(start), String.valueOf(end),
1262 String.valueOf(orderByComparator)
1263 };
1264
1265 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_O_O_P,
1266 finderArgs, this);
1267
1268 if (list == null) {
1269 Session session = null;
1270
1271 try {
1272 session = openSession();
1273
1274 StringBundler query = null;
1275
1276 if (orderByComparator != null) {
1277 query = new StringBundler(5 +
1278 (orderByComparator.getOrderByFields().length * 3));
1279 }
1280 else {
1281 query = new StringBundler(4);
1282 }
1283
1284 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1285
1286 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1287
1288 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1289
1290 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1291
1292 if (orderByComparator != null) {
1293 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1294 orderByComparator);
1295 }
1296
1297 String sql = query.toString();
1298
1299 Query q = session.createQuery(sql);
1300
1301 QueryPos qPos = QueryPos.getInstance(q);
1302
1303 qPos.add(ownerId);
1304
1305 qPos.add(ownerType);
1306
1307 qPos.add(plid);
1308
1309 list = (List<PortletPreferences>)QueryUtil.list(q,
1310 getDialect(), start, end);
1311 }
1312 catch (Exception e) {
1313 throw processException(e);
1314 }
1315 finally {
1316 if (list == null) {
1317 list = new ArrayList<PortletPreferences>();
1318 }
1319
1320 cacheResult(list);
1321
1322 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_O_O_P,
1323 finderArgs, list);
1324
1325 closeSession(session);
1326 }
1327 }
1328
1329 return list;
1330 }
1331
1332
1347 public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
1348 long plid, OrderByComparator orderByComparator)
1349 throws NoSuchPortletPreferencesException, SystemException {
1350 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
1351 0, 1, orderByComparator);
1352
1353 if (list.isEmpty()) {
1354 StringBundler msg = new StringBundler(8);
1355
1356 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1357
1358 msg.append("ownerId=");
1359 msg.append(ownerId);
1360
1361 msg.append(", ownerType=");
1362 msg.append(ownerType);
1363
1364 msg.append(", plid=");
1365 msg.append(plid);
1366
1367 msg.append(StringPool.CLOSE_CURLY_BRACE);
1368
1369 throw new NoSuchPortletPreferencesException(msg.toString());
1370 }
1371 else {
1372 return list.get(0);
1373 }
1374 }
1375
1376
1391 public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
1392 long plid, OrderByComparator orderByComparator)
1393 throws NoSuchPortletPreferencesException, SystemException {
1394 int count = countByO_O_P(ownerId, ownerType, plid);
1395
1396 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
1397 count - 1, count, orderByComparator);
1398
1399 if (list.isEmpty()) {
1400 StringBundler msg = new StringBundler(8);
1401
1402 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1403
1404 msg.append("ownerId=");
1405 msg.append(ownerId);
1406
1407 msg.append(", ownerType=");
1408 msg.append(ownerType);
1409
1410 msg.append(", plid=");
1411 msg.append(plid);
1412
1413 msg.append(StringPool.CLOSE_CURLY_BRACE);
1414
1415 throw new NoSuchPortletPreferencesException(msg.toString());
1416 }
1417 else {
1418 return list.get(0);
1419 }
1420 }
1421
1422
1438 public PortletPreferences[] findByO_O_P_PrevAndNext(
1439 long portletPreferencesId, long ownerId, int ownerType, long plid,
1440 OrderByComparator orderByComparator)
1441 throws NoSuchPortletPreferencesException, SystemException {
1442 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1443
1444 Session session = null;
1445
1446 try {
1447 session = openSession();
1448
1449 PortletPreferences[] array = new PortletPreferencesImpl[3];
1450
1451 array[0] = getByO_O_P_PrevAndNext(session, portletPreferences,
1452 ownerId, ownerType, plid, orderByComparator, true);
1453
1454 array[1] = portletPreferences;
1455
1456 array[2] = getByO_O_P_PrevAndNext(session, portletPreferences,
1457 ownerId, ownerType, plid, orderByComparator, false);
1458
1459 return array;
1460 }
1461 catch (Exception e) {
1462 throw processException(e);
1463 }
1464 finally {
1465 closeSession(session);
1466 }
1467 }
1468
1469 protected PortletPreferences getByO_O_P_PrevAndNext(Session session,
1470 PortletPreferences portletPreferences, long ownerId, int ownerType,
1471 long plid, OrderByComparator orderByComparator, boolean previous) {
1472 StringBundler query = null;
1473
1474 if (orderByComparator != null) {
1475 query = new StringBundler(6 +
1476 (orderByComparator.getOrderByFields().length * 6));
1477 }
1478 else {
1479 query = new StringBundler(3);
1480 }
1481
1482 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1483
1484 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1485
1486 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1487
1488 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1489
1490 if (orderByComparator != null) {
1491 String[] orderByFields = orderByComparator.getOrderByFields();
1492
1493 if (orderByFields.length > 0) {
1494 query.append(WHERE_AND);
1495 }
1496
1497 for (int i = 0; i < orderByFields.length; i++) {
1498 query.append(_ORDER_BY_ENTITY_ALIAS);
1499 query.append(orderByFields[i]);
1500
1501 if ((i + 1) < orderByFields.length) {
1502 if (orderByComparator.isAscending() ^ previous) {
1503 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1504 }
1505 else {
1506 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1507 }
1508 }
1509 else {
1510 if (orderByComparator.isAscending() ^ previous) {
1511 query.append(WHERE_GREATER_THAN);
1512 }
1513 else {
1514 query.append(WHERE_LESSER_THAN);
1515 }
1516 }
1517 }
1518
1519 query.append(ORDER_BY_CLAUSE);
1520
1521 for (int i = 0; i < orderByFields.length; i++) {
1522 query.append(_ORDER_BY_ENTITY_ALIAS);
1523 query.append(orderByFields[i]);
1524
1525 if ((i + 1) < orderByFields.length) {
1526 if (orderByComparator.isAscending() ^ previous) {
1527 query.append(ORDER_BY_ASC_HAS_NEXT);
1528 }
1529 else {
1530 query.append(ORDER_BY_DESC_HAS_NEXT);
1531 }
1532 }
1533 else {
1534 if (orderByComparator.isAscending() ^ previous) {
1535 query.append(ORDER_BY_ASC);
1536 }
1537 else {
1538 query.append(ORDER_BY_DESC);
1539 }
1540 }
1541 }
1542 }
1543
1544 String sql = query.toString();
1545
1546 Query q = session.createQuery(sql);
1547
1548 q.setFirstResult(0);
1549 q.setMaxResults(2);
1550
1551 QueryPos qPos = QueryPos.getInstance(q);
1552
1553 qPos.add(ownerId);
1554
1555 qPos.add(ownerType);
1556
1557 qPos.add(plid);
1558
1559 if (orderByComparator != null) {
1560 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
1561
1562 for (Object value : values) {
1563 qPos.add(value);
1564 }
1565 }
1566
1567 List<PortletPreferences> list = q.list();
1568
1569 if (list.size() == 2) {
1570 return list.get(1);
1571 }
1572 else {
1573 return null;
1574 }
1575 }
1576
1577
1588 public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
1589 long plid, String portletId)
1590 throws NoSuchPortletPreferencesException, SystemException {
1591 PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
1592 ownerType, plid, portletId);
1593
1594 if (portletPreferences == null) {
1595 StringBundler msg = new StringBundler(10);
1596
1597 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1598
1599 msg.append("ownerId=");
1600 msg.append(ownerId);
1601
1602 msg.append(", ownerType=");
1603 msg.append(ownerType);
1604
1605 msg.append(", plid=");
1606 msg.append(plid);
1607
1608 msg.append(", portletId=");
1609 msg.append(portletId);
1610
1611 msg.append(StringPool.CLOSE_CURLY_BRACE);
1612
1613 if (_log.isWarnEnabled()) {
1614 _log.warn(msg.toString());
1615 }
1616
1617 throw new NoSuchPortletPreferencesException(msg.toString());
1618 }
1619
1620 return portletPreferences;
1621 }
1622
1623
1633 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1634 long plid, String portletId) throws SystemException {
1635 return fetchByO_O_P_P(ownerId, ownerType, plid, portletId, true);
1636 }
1637
1638
1648 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1649 long plid, String portletId, boolean retrieveFromCache)
1650 throws SystemException {
1651 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
1652
1653 Object result = null;
1654
1655 if (retrieveFromCache) {
1656 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1657 finderArgs, this);
1658 }
1659
1660 if (result == null) {
1661 Session session = null;
1662
1663 try {
1664 session = openSession();
1665
1666 StringBundler query = new StringBundler(5);
1667
1668 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1669
1670 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
1671
1672 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
1673
1674 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
1675
1676 if (portletId == null) {
1677 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
1678 }
1679 else {
1680 if (portletId.equals(StringPool.BLANK)) {
1681 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
1682 }
1683 else {
1684 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
1685 }
1686 }
1687
1688 String sql = query.toString();
1689
1690 Query q = session.createQuery(sql);
1691
1692 QueryPos qPos = QueryPos.getInstance(q);
1693
1694 qPos.add(ownerId);
1695
1696 qPos.add(ownerType);
1697
1698 qPos.add(plid);
1699
1700 if (portletId != null) {
1701 qPos.add(portletId);
1702 }
1703
1704 List<PortletPreferences> list = q.list();
1705
1706 result = list;
1707
1708 PortletPreferences portletPreferences = null;
1709
1710 if (list.isEmpty()) {
1711 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1712 finderArgs, list);
1713 }
1714 else {
1715 portletPreferences = list.get(0);
1716
1717 cacheResult(portletPreferences);
1718
1719 if ((portletPreferences.getOwnerId() != ownerId) ||
1720 (portletPreferences.getOwnerType() != ownerType) ||
1721 (portletPreferences.getPlid() != plid) ||
1722 (portletPreferences.getPortletId() == null) ||
1723 !portletPreferences.getPortletId().equals(portletId)) {
1724 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1725 finderArgs, portletPreferences);
1726 }
1727 }
1728
1729 return portletPreferences;
1730 }
1731 catch (Exception e) {
1732 throw processException(e);
1733 }
1734 finally {
1735 if (result == null) {
1736 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1737 finderArgs, new ArrayList<PortletPreferences>());
1738 }
1739
1740 closeSession(session);
1741 }
1742 }
1743 else {
1744 if (result instanceof List<?>) {
1745 return null;
1746 }
1747 else {
1748 return (PortletPreferences)result;
1749 }
1750 }
1751 }
1752
1753
1759 public List<PortletPreferences> findAll() throws SystemException {
1760 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1761 }
1762
1763
1775 public List<PortletPreferences> findAll(int start, int end)
1776 throws SystemException {
1777 return findAll(start, end, null);
1778 }
1779
1780
1793 public List<PortletPreferences> findAll(int start, int end,
1794 OrderByComparator orderByComparator) throws SystemException {
1795 Object[] finderArgs = new Object[] {
1796 String.valueOf(start), String.valueOf(end),
1797 String.valueOf(orderByComparator)
1798 };
1799
1800 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1801 finderArgs, this);
1802
1803 if (list == null) {
1804 Session session = null;
1805
1806 try {
1807 session = openSession();
1808
1809 StringBundler query = null;
1810 String sql = null;
1811
1812 if (orderByComparator != null) {
1813 query = new StringBundler(2 +
1814 (orderByComparator.getOrderByFields().length * 3));
1815
1816 query.append(_SQL_SELECT_PORTLETPREFERENCES);
1817
1818 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1819 orderByComparator);
1820
1821 sql = query.toString();
1822 }
1823 else {
1824 sql = _SQL_SELECT_PORTLETPREFERENCES;
1825 }
1826
1827 Query q = session.createQuery(sql);
1828
1829 if (orderByComparator == null) {
1830 list = (List<PortletPreferences>)QueryUtil.list(q,
1831 getDialect(), start, end, false);
1832
1833 Collections.sort(list);
1834 }
1835 else {
1836 list = (List<PortletPreferences>)QueryUtil.list(q,
1837 getDialect(), start, end);
1838 }
1839 }
1840 catch (Exception e) {
1841 throw processException(e);
1842 }
1843 finally {
1844 if (list == null) {
1845 list = new ArrayList<PortletPreferences>();
1846 }
1847
1848 cacheResult(list);
1849
1850 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1851
1852 closeSession(session);
1853 }
1854 }
1855
1856 return list;
1857 }
1858
1859
1865 public void removeByPlid(long plid) throws SystemException {
1866 for (PortletPreferences portletPreferences : findByPlid(plid)) {
1867 remove(portletPreferences);
1868 }
1869 }
1870
1871
1878 public void removeByP_P(long plid, String portletId)
1879 throws SystemException {
1880 for (PortletPreferences portletPreferences : findByP_P(plid, portletId)) {
1881 remove(portletPreferences);
1882 }
1883 }
1884
1885
1893 public void removeByO_O_P(long ownerId, int ownerType, long plid)
1894 throws SystemException {
1895 for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
1896 ownerType, plid)) {
1897 remove(portletPreferences);
1898 }
1899 }
1900
1901
1910 public void removeByO_O_P_P(long ownerId, int ownerType, long plid,
1911 String portletId)
1912 throws NoSuchPortletPreferencesException, SystemException {
1913 PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
1914 ownerType, plid, portletId);
1915
1916 remove(portletPreferences);
1917 }
1918
1919
1924 public void removeAll() throws SystemException {
1925 for (PortletPreferences portletPreferences : findAll()) {
1926 remove(portletPreferences);
1927 }
1928 }
1929
1930
1937 public int countByPlid(long plid) throws SystemException {
1938 Object[] finderArgs = new Object[] { plid };
1939
1940 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PLID,
1941 finderArgs, this);
1942
1943 if (count == null) {
1944 Session session = null;
1945
1946 try {
1947 session = openSession();
1948
1949 StringBundler query = new StringBundler(2);
1950
1951 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1952
1953 query.append(_FINDER_COLUMN_PLID_PLID_2);
1954
1955 String sql = query.toString();
1956
1957 Query q = session.createQuery(sql);
1958
1959 QueryPos qPos = QueryPos.getInstance(q);
1960
1961 qPos.add(plid);
1962
1963 count = (Long)q.uniqueResult();
1964 }
1965 catch (Exception e) {
1966 throw processException(e);
1967 }
1968 finally {
1969 if (count == null) {
1970 count = Long.valueOf(0);
1971 }
1972
1973 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PLID,
1974 finderArgs, count);
1975
1976 closeSession(session);
1977 }
1978 }
1979
1980 return count.intValue();
1981 }
1982
1983
1991 public int countByP_P(long plid, String portletId)
1992 throws SystemException {
1993 Object[] finderArgs = new Object[] { plid, portletId };
1994
1995 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_P,
1996 finderArgs, this);
1997
1998 if (count == null) {
1999 Session session = null;
2000
2001 try {
2002 session = openSession();
2003
2004 StringBundler query = new StringBundler(3);
2005
2006 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2007
2008 query.append(_FINDER_COLUMN_P_P_PLID_2);
2009
2010 if (portletId == null) {
2011 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
2012 }
2013 else {
2014 if (portletId.equals(StringPool.BLANK)) {
2015 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
2016 }
2017 else {
2018 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
2019 }
2020 }
2021
2022 String sql = query.toString();
2023
2024 Query q = session.createQuery(sql);
2025
2026 QueryPos qPos = QueryPos.getInstance(q);
2027
2028 qPos.add(plid);
2029
2030 if (portletId != null) {
2031 qPos.add(portletId);
2032 }
2033
2034 count = (Long)q.uniqueResult();
2035 }
2036 catch (Exception e) {
2037 throw processException(e);
2038 }
2039 finally {
2040 if (count == null) {
2041 count = Long.valueOf(0);
2042 }
2043
2044 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, finderArgs,
2045 count);
2046
2047 closeSession(session);
2048 }
2049 }
2050
2051 return count.intValue();
2052 }
2053
2054
2063 public int countByO_O_P(long ownerId, int ownerType, long plid)
2064 throws SystemException {
2065 Object[] finderArgs = new Object[] { ownerId, ownerType, plid };
2066
2067 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O_P,
2068 finderArgs, this);
2069
2070 if (count == null) {
2071 Session session = null;
2072
2073 try {
2074 session = openSession();
2075
2076 StringBundler query = new StringBundler(4);
2077
2078 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2079
2080 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
2081
2082 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
2083
2084 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
2085
2086 String sql = query.toString();
2087
2088 Query q = session.createQuery(sql);
2089
2090 QueryPos qPos = QueryPos.getInstance(q);
2091
2092 qPos.add(ownerId);
2093
2094 qPos.add(ownerType);
2095
2096 qPos.add(plid);
2097
2098 count = (Long)q.uniqueResult();
2099 }
2100 catch (Exception e) {
2101 throw processException(e);
2102 }
2103 finally {
2104 if (count == null) {
2105 count = Long.valueOf(0);
2106 }
2107
2108 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O_P,
2109 finderArgs, count);
2110
2111 closeSession(session);
2112 }
2113 }
2114
2115 return count.intValue();
2116 }
2117
2118
2128 public int countByO_O_P_P(long ownerId, int ownerType, long plid,
2129 String portletId) throws SystemException {
2130 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
2131
2132 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O_P_P,
2133 finderArgs, this);
2134
2135 if (count == null) {
2136 Session session = null;
2137
2138 try {
2139 session = openSession();
2140
2141 StringBundler query = new StringBundler(5);
2142
2143 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
2144
2145 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
2146
2147 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
2148
2149 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
2150
2151 if (portletId == null) {
2152 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
2153 }
2154 else {
2155 if (portletId.equals(StringPool.BLANK)) {
2156 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
2157 }
2158 else {
2159 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
2160 }
2161 }
2162
2163 String sql = query.toString();
2164
2165 Query q = session.createQuery(sql);
2166
2167 QueryPos qPos = QueryPos.getInstance(q);
2168
2169 qPos.add(ownerId);
2170
2171 qPos.add(ownerType);
2172
2173 qPos.add(plid);
2174
2175 if (portletId != null) {
2176 qPos.add(portletId);
2177 }
2178
2179 count = (Long)q.uniqueResult();
2180 }
2181 catch (Exception e) {
2182 throw processException(e);
2183 }
2184 finally {
2185 if (count == null) {
2186 count = Long.valueOf(0);
2187 }
2188
2189 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O_P_P,
2190 finderArgs, count);
2191
2192 closeSession(session);
2193 }
2194 }
2195
2196 return count.intValue();
2197 }
2198
2199
2205 public int countAll() throws SystemException {
2206 Object[] finderArgs = new Object[0];
2207
2208 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2209 finderArgs, this);
2210
2211 if (count == null) {
2212 Session session = null;
2213
2214 try {
2215 session = openSession();
2216
2217 Query q = session.createQuery(_SQL_COUNT_PORTLETPREFERENCES);
2218
2219 count = (Long)q.uniqueResult();
2220 }
2221 catch (Exception e) {
2222 throw processException(e);
2223 }
2224 finally {
2225 if (count == null) {
2226 count = Long.valueOf(0);
2227 }
2228
2229 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2230 count);
2231
2232 closeSession(session);
2233 }
2234 }
2235
2236 return count.intValue();
2237 }
2238
2239
2242 public void afterPropertiesSet() {
2243 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2244 com.liferay.portal.util.PropsUtil.get(
2245 "value.object.listener.com.liferay.portal.model.PortletPreferences")));
2246
2247 if (listenerClassNames.length > 0) {
2248 try {
2249 List<ModelListener<PortletPreferences>> listenersList = new ArrayList<ModelListener<PortletPreferences>>();
2250
2251 for (String listenerClassName : listenerClassNames) {
2252 listenersList.add((ModelListener<PortletPreferences>)InstanceFactory.newInstance(
2253 listenerClassName));
2254 }
2255
2256 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2257 }
2258 catch (Exception e) {
2259 _log.error(e);
2260 }
2261 }
2262 }
2263
2264 @BeanReference(type = AccountPersistence.class)
2265 protected AccountPersistence accountPersistence;
2266 @BeanReference(type = AddressPersistence.class)
2267 protected AddressPersistence addressPersistence;
2268 @BeanReference(type = BrowserTrackerPersistence.class)
2269 protected BrowserTrackerPersistence browserTrackerPersistence;
2270 @BeanReference(type = ClassNamePersistence.class)
2271 protected ClassNamePersistence classNamePersistence;
2272 @BeanReference(type = ClusterGroupPersistence.class)
2273 protected ClusterGroupPersistence clusterGroupPersistence;
2274 @BeanReference(type = CompanyPersistence.class)
2275 protected CompanyPersistence companyPersistence;
2276 @BeanReference(type = ContactPersistence.class)
2277 protected ContactPersistence contactPersistence;
2278 @BeanReference(type = CountryPersistence.class)
2279 protected CountryPersistence countryPersistence;
2280 @BeanReference(type = EmailAddressPersistence.class)
2281 protected EmailAddressPersistence emailAddressPersistence;
2282 @BeanReference(type = GroupPersistence.class)
2283 protected GroupPersistence groupPersistence;
2284 @BeanReference(type = ImagePersistence.class)
2285 protected ImagePersistence imagePersistence;
2286 @BeanReference(type = LayoutPersistence.class)
2287 protected LayoutPersistence layoutPersistence;
2288 @BeanReference(type = LayoutPrototypePersistence.class)
2289 protected LayoutPrototypePersistence layoutPrototypePersistence;
2290 @BeanReference(type = LayoutSetPersistence.class)
2291 protected LayoutSetPersistence layoutSetPersistence;
2292 @BeanReference(type = LayoutSetPrototypePersistence.class)
2293 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2294 @BeanReference(type = ListTypePersistence.class)
2295 protected ListTypePersistence listTypePersistence;
2296 @BeanReference(type = LockPersistence.class)
2297 protected LockPersistence lockPersistence;
2298 @BeanReference(type = MembershipRequestPersistence.class)
2299 protected MembershipRequestPersistence membershipRequestPersistence;
2300 @BeanReference(type = OrganizationPersistence.class)
2301 protected OrganizationPersistence organizationPersistence;
2302 @BeanReference(type = OrgGroupPermissionPersistence.class)
2303 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2304 @BeanReference(type = OrgGroupRolePersistence.class)
2305 protected OrgGroupRolePersistence orgGroupRolePersistence;
2306 @BeanReference(type = OrgLaborPersistence.class)
2307 protected OrgLaborPersistence orgLaborPersistence;
2308 @BeanReference(type = PasswordPolicyPersistence.class)
2309 protected PasswordPolicyPersistence passwordPolicyPersistence;
2310 @BeanReference(type = PasswordPolicyRelPersistence.class)
2311 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2312 @BeanReference(type = PasswordTrackerPersistence.class)
2313 protected PasswordTrackerPersistence passwordTrackerPersistence;
2314 @BeanReference(type = PermissionPersistence.class)
2315 protected PermissionPersistence permissionPersistence;
2316 @BeanReference(type = PhonePersistence.class)
2317 protected PhonePersistence phonePersistence;
2318 @BeanReference(type = PluginSettingPersistence.class)
2319 protected PluginSettingPersistence pluginSettingPersistence;
2320 @BeanReference(type = PortletPersistence.class)
2321 protected PortletPersistence portletPersistence;
2322 @BeanReference(type = PortletItemPersistence.class)
2323 protected PortletItemPersistence portletItemPersistence;
2324 @BeanReference(type = PortletPreferencesPersistence.class)
2325 protected PortletPreferencesPersistence portletPreferencesPersistence;
2326 @BeanReference(type = RegionPersistence.class)
2327 protected RegionPersistence regionPersistence;
2328 @BeanReference(type = ReleasePersistence.class)
2329 protected ReleasePersistence releasePersistence;
2330 @BeanReference(type = ResourcePersistence.class)
2331 protected ResourcePersistence resourcePersistence;
2332 @BeanReference(type = ResourceActionPersistence.class)
2333 protected ResourceActionPersistence resourceActionPersistence;
2334 @BeanReference(type = ResourceCodePersistence.class)
2335 protected ResourceCodePersistence resourceCodePersistence;
2336 @BeanReference(type = ResourcePermissionPersistence.class)
2337 protected ResourcePermissionPersistence resourcePermissionPersistence;
2338 @BeanReference(type = RolePersistence.class)
2339 protected RolePersistence rolePersistence;
2340 @BeanReference(type = ServiceComponentPersistence.class)
2341 protected ServiceComponentPersistence serviceComponentPersistence;
2342 @BeanReference(type = ShardPersistence.class)
2343 protected ShardPersistence shardPersistence;
2344 @BeanReference(type = SubscriptionPersistence.class)
2345 protected SubscriptionPersistence subscriptionPersistence;
2346 @BeanReference(type = TicketPersistence.class)
2347 protected TicketPersistence ticketPersistence;
2348 @BeanReference(type = TeamPersistence.class)
2349 protected TeamPersistence teamPersistence;
2350 @BeanReference(type = UserPersistence.class)
2351 protected UserPersistence userPersistence;
2352 @BeanReference(type = UserGroupPersistence.class)
2353 protected UserGroupPersistence userGroupPersistence;
2354 @BeanReference(type = UserGroupGroupRolePersistence.class)
2355 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2356 @BeanReference(type = UserGroupRolePersistence.class)
2357 protected UserGroupRolePersistence userGroupRolePersistence;
2358 @BeanReference(type = UserIdMapperPersistence.class)
2359 protected UserIdMapperPersistence userIdMapperPersistence;
2360 @BeanReference(type = UserTrackerPersistence.class)
2361 protected UserTrackerPersistence userTrackerPersistence;
2362 @BeanReference(type = UserTrackerPathPersistence.class)
2363 protected UserTrackerPathPersistence userTrackerPathPersistence;
2364 @BeanReference(type = WebDAVPropsPersistence.class)
2365 protected WebDAVPropsPersistence webDAVPropsPersistence;
2366 @BeanReference(type = WebsitePersistence.class)
2367 protected WebsitePersistence websitePersistence;
2368 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2369 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2370 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2371 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2372 private static final String _SQL_SELECT_PORTLETPREFERENCES = "SELECT portletPreferences FROM PortletPreferences portletPreferences";
2373 private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE ";
2374 private static final String _SQL_COUNT_PORTLETPREFERENCES = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences";
2375 private static final String _SQL_COUNT_PORTLETPREFERENCES_WHERE = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences WHERE ";
2376 private static final String _FINDER_COLUMN_PLID_PLID_2 = "portletPreferences.plid = ?";
2377 private static final String _FINDER_COLUMN_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
2378 private static final String _FINDER_COLUMN_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
2379 private static final String _FINDER_COLUMN_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
2380 private static final String _FINDER_COLUMN_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = ?)";
2381 private static final String _FINDER_COLUMN_O_O_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
2382 private static final String _FINDER_COLUMN_O_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
2383 private static final String _FINDER_COLUMN_O_O_P_PLID_2 = "portletPreferences.plid = ?";
2384 private static final String _FINDER_COLUMN_O_O_P_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
2385 private static final String _FINDER_COLUMN_O_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
2386 private static final String _FINDER_COLUMN_O_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
2387 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
2388 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
2389 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = ?)";
2390 private static final String _ORDER_BY_ENTITY_ALIAS = "portletPreferences.";
2391 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletPreferences exists with the primary key ";
2392 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletPreferences exists with the key {";
2393 private static Log _log = LogFactoryUtil.getLog(PortletPreferencesPersistenceImpl.class);
2394 }