1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchPortletPreferencesException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.kernel.util.ListUtil;
35 import com.liferay.portal.kernel.util.OrderByComparator;
36 import com.liferay.portal.kernel.util.StringPool;
37 import com.liferay.portal.kernel.util.StringUtil;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.model.PortletPreferences;
40 import com.liferay.portal.model.impl.PortletPreferencesImpl;
41 import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
42 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43
44 import org.apache.commons.logging.Log;
45 import org.apache.commons.logging.LogFactory;
46
47 import java.util.ArrayList;
48 import java.util.Collections;
49 import java.util.Iterator;
50 import java.util.List;
51
52
58 public class PortletPreferencesPersistenceImpl extends BasePersistenceImpl
59 implements PortletPreferencesPersistence {
60 public PortletPreferences create(long portletPreferencesId) {
61 PortletPreferences portletPreferences = new PortletPreferencesImpl();
62
63 portletPreferences.setNew(true);
64 portletPreferences.setPrimaryKey(portletPreferencesId);
65
66 return portletPreferences;
67 }
68
69 public PortletPreferences remove(long portletPreferencesId)
70 throws NoSuchPortletPreferencesException, SystemException {
71 Session session = null;
72
73 try {
74 session = openSession();
75
76 PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
77 new Long(portletPreferencesId));
78
79 if (portletPreferences == null) {
80 if (_log.isWarnEnabled()) {
81 _log.warn(
82 "No PortletPreferences exists with the primary key " +
83 portletPreferencesId);
84 }
85
86 throw new NoSuchPortletPreferencesException(
87 "No PortletPreferences exists with the primary key " +
88 portletPreferencesId);
89 }
90
91 return remove(portletPreferences);
92 }
93 catch (NoSuchPortletPreferencesException nsee) {
94 throw nsee;
95 }
96 catch (Exception e) {
97 throw processException(e);
98 }
99 finally {
100 closeSession(session);
101 }
102 }
103
104 public PortletPreferences remove(PortletPreferences portletPreferences)
105 throws SystemException {
106 if (_listeners.length > 0) {
107 for (ModelListener listener : _listeners) {
108 listener.onBeforeRemove(portletPreferences);
109 }
110 }
111
112 portletPreferences = removeImpl(portletPreferences);
113
114 if (_listeners.length > 0) {
115 for (ModelListener listener : _listeners) {
116 listener.onAfterRemove(portletPreferences);
117 }
118 }
119
120 return portletPreferences;
121 }
122
123 protected PortletPreferences removeImpl(
124 PortletPreferences portletPreferences) throws SystemException {
125 Session session = null;
126
127 try {
128 session = openSession();
129
130 if (BatchSessionUtil.isEnabled()) {
131 Object staleObject = session.get(PortletPreferencesImpl.class,
132 portletPreferences.getPrimaryKeyObj());
133
134 if (staleObject != null) {
135 session.evict(staleObject);
136 }
137 }
138
139 session.delete(portletPreferences);
140
141 session.flush();
142
143 return portletPreferences;
144 }
145 catch (Exception e) {
146 throw processException(e);
147 }
148 finally {
149 closeSession(session);
150
151 FinderCacheUtil.clearCache(PortletPreferences.class.getName());
152 }
153 }
154
155
158 public PortletPreferences update(PortletPreferences portletPreferences)
159 throws SystemException {
160 if (_log.isWarnEnabled()) {
161 _log.warn(
162 "Using the deprecated update(PortletPreferences portletPreferences) method. Use update(PortletPreferences portletPreferences, boolean merge) instead.");
163 }
164
165 return update(portletPreferences, false);
166 }
167
168
181 public PortletPreferences update(PortletPreferences portletPreferences,
182 boolean merge) throws SystemException {
183 boolean isNew = portletPreferences.isNew();
184
185 if (_listeners.length > 0) {
186 for (ModelListener listener : _listeners) {
187 if (isNew) {
188 listener.onBeforeCreate(portletPreferences);
189 }
190 else {
191 listener.onBeforeUpdate(portletPreferences);
192 }
193 }
194 }
195
196 portletPreferences = updateImpl(portletPreferences, merge);
197
198 if (_listeners.length > 0) {
199 for (ModelListener listener : _listeners) {
200 if (isNew) {
201 listener.onAfterCreate(portletPreferences);
202 }
203 else {
204 listener.onAfterUpdate(portletPreferences);
205 }
206 }
207 }
208
209 return portletPreferences;
210 }
211
212 public PortletPreferences updateImpl(
213 com.liferay.portal.model.PortletPreferences portletPreferences,
214 boolean merge) throws SystemException {
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 BatchSessionUtil.update(session, portletPreferences, merge);
221
222 portletPreferences.setNew(false);
223
224 return portletPreferences;
225 }
226 catch (Exception e) {
227 throw processException(e);
228 }
229 finally {
230 closeSession(session);
231
232 FinderCacheUtil.clearCache(PortletPreferences.class.getName());
233 }
234 }
235
236 public PortletPreferences findByPrimaryKey(long portletPreferencesId)
237 throws NoSuchPortletPreferencesException, SystemException {
238 PortletPreferences portletPreferences = fetchByPrimaryKey(portletPreferencesId);
239
240 if (portletPreferences == null) {
241 if (_log.isWarnEnabled()) {
242 _log.warn("No PortletPreferences exists with the primary key " +
243 portletPreferencesId);
244 }
245
246 throw new NoSuchPortletPreferencesException(
247 "No PortletPreferences exists with the primary key " +
248 portletPreferencesId);
249 }
250
251 return portletPreferences;
252 }
253
254 public PortletPreferences fetchByPrimaryKey(long portletPreferencesId)
255 throws SystemException {
256 Session session = null;
257
258 try {
259 session = openSession();
260
261 return (PortletPreferences)session.get(PortletPreferencesImpl.class,
262 new Long(portletPreferencesId));
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270 }
271
272 public List<PortletPreferences> findByPlid(long plid)
273 throws SystemException {
274 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
275 String finderClassName = PortletPreferences.class.getName();
276 String finderMethodName = "findByPlid";
277 String[] finderParams = new String[] { Long.class.getName() };
278 Object[] finderArgs = new Object[] { new Long(plid) };
279
280 Object result = null;
281
282 if (finderClassNameCacheEnabled) {
283 result = FinderCacheUtil.getResult(finderClassName,
284 finderMethodName, finderParams, finderArgs, this);
285 }
286
287 if (result == null) {
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 StringBuilder query = new StringBuilder();
294
295 query.append(
296 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
297
298 query.append("plid = ?");
299
300 query.append(" ");
301
302 Query q = session.createQuery(query.toString());
303
304 QueryPos qPos = QueryPos.getInstance(q);
305
306 qPos.add(plid);
307
308 List<PortletPreferences> list = q.list();
309
310 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
311 finderClassName, finderMethodName, finderParams,
312 finderArgs, list);
313
314 return list;
315 }
316 catch (Exception e) {
317 throw processException(e);
318 }
319 finally {
320 closeSession(session);
321 }
322 }
323 else {
324 return (List<PortletPreferences>)result;
325 }
326 }
327
328 public List<PortletPreferences> findByPlid(long plid, int start, int end)
329 throws SystemException {
330 return findByPlid(plid, start, end, null);
331 }
332
333 public List<PortletPreferences> findByPlid(long plid, int start, int end,
334 OrderByComparator obc) throws SystemException {
335 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
336 String finderClassName = PortletPreferences.class.getName();
337 String finderMethodName = "findByPlid";
338 String[] finderParams = new String[] {
339 Long.class.getName(),
340
341 "java.lang.Integer", "java.lang.Integer",
342 "com.liferay.portal.kernel.util.OrderByComparator"
343 };
344 Object[] finderArgs = new Object[] {
345 new Long(plid),
346
347 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
348 };
349
350 Object result = null;
351
352 if (finderClassNameCacheEnabled) {
353 result = FinderCacheUtil.getResult(finderClassName,
354 finderMethodName, finderParams, finderArgs, this);
355 }
356
357 if (result == null) {
358 Session session = null;
359
360 try {
361 session = openSession();
362
363 StringBuilder query = new StringBuilder();
364
365 query.append(
366 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
367
368 query.append("plid = ?");
369
370 query.append(" ");
371
372 if (obc != null) {
373 query.append("ORDER BY ");
374 query.append(obc.getOrderBy());
375 }
376
377 Query q = session.createQuery(query.toString());
378
379 QueryPos qPos = QueryPos.getInstance(q);
380
381 qPos.add(plid);
382
383 List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
384 getDialect(), start, end);
385
386 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
387 finderClassName, finderMethodName, finderParams,
388 finderArgs, list);
389
390 return list;
391 }
392 catch (Exception e) {
393 throw processException(e);
394 }
395 finally {
396 closeSession(session);
397 }
398 }
399 else {
400 return (List<PortletPreferences>)result;
401 }
402 }
403
404 public PortletPreferences findByPlid_First(long plid, OrderByComparator obc)
405 throws NoSuchPortletPreferencesException, SystemException {
406 List<PortletPreferences> list = findByPlid(plid, 0, 1, obc);
407
408 if (list.size() == 0) {
409 StringBuilder msg = new StringBuilder();
410
411 msg.append("No PortletPreferences exists with the key {");
412
413 msg.append("plid=" + plid);
414
415 msg.append(StringPool.CLOSE_CURLY_BRACE);
416
417 throw new NoSuchPortletPreferencesException(msg.toString());
418 }
419 else {
420 return list.get(0);
421 }
422 }
423
424 public PortletPreferences findByPlid_Last(long plid, OrderByComparator obc)
425 throws NoSuchPortletPreferencesException, SystemException {
426 int count = countByPlid(plid);
427
428 List<PortletPreferences> list = findByPlid(plid, count - 1, count, obc);
429
430 if (list.size() == 0) {
431 StringBuilder msg = new StringBuilder();
432
433 msg.append("No PortletPreferences exists with the key {");
434
435 msg.append("plid=" + plid);
436
437 msg.append(StringPool.CLOSE_CURLY_BRACE);
438
439 throw new NoSuchPortletPreferencesException(msg.toString());
440 }
441 else {
442 return list.get(0);
443 }
444 }
445
446 public PortletPreferences[] findByPlid_PrevAndNext(
447 long portletPreferencesId, long plid, OrderByComparator obc)
448 throws NoSuchPortletPreferencesException, SystemException {
449 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
450
451 int count = countByPlid(plid);
452
453 Session session = null;
454
455 try {
456 session = openSession();
457
458 StringBuilder query = new StringBuilder();
459
460 query.append(
461 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
462
463 query.append("plid = ?");
464
465 query.append(" ");
466
467 if (obc != null) {
468 query.append("ORDER BY ");
469 query.append(obc.getOrderBy());
470 }
471
472 Query q = session.createQuery(query.toString());
473
474 QueryPos qPos = QueryPos.getInstance(q);
475
476 qPos.add(plid);
477
478 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
479 portletPreferences);
480
481 PortletPreferences[] array = new PortletPreferencesImpl[3];
482
483 array[0] = (PortletPreferences)objArray[0];
484 array[1] = (PortletPreferences)objArray[1];
485 array[2] = (PortletPreferences)objArray[2];
486
487 return array;
488 }
489 catch (Exception e) {
490 throw processException(e);
491 }
492 finally {
493 closeSession(session);
494 }
495 }
496
497 public List<PortletPreferences> findByP_P(long plid, String portletId)
498 throws SystemException {
499 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
500 String finderClassName = PortletPreferences.class.getName();
501 String finderMethodName = "findByP_P";
502 String[] finderParams = new String[] {
503 Long.class.getName(), String.class.getName()
504 };
505 Object[] finderArgs = new Object[] { new Long(plid), portletId };
506
507 Object result = null;
508
509 if (finderClassNameCacheEnabled) {
510 result = FinderCacheUtil.getResult(finderClassName,
511 finderMethodName, finderParams, finderArgs, this);
512 }
513
514 if (result == null) {
515 Session session = null;
516
517 try {
518 session = openSession();
519
520 StringBuilder query = new StringBuilder();
521
522 query.append(
523 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
524
525 query.append("plid = ?");
526
527 query.append(" AND ");
528
529 if (portletId == null) {
530 query.append("portletId IS NULL");
531 }
532 else {
533 query.append("portletId = ?");
534 }
535
536 query.append(" ");
537
538 Query q = session.createQuery(query.toString());
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(plid);
543
544 if (portletId != null) {
545 qPos.add(portletId);
546 }
547
548 List<PortletPreferences> list = q.list();
549
550 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
551 finderClassName, finderMethodName, finderParams,
552 finderArgs, list);
553
554 return list;
555 }
556 catch (Exception e) {
557 throw processException(e);
558 }
559 finally {
560 closeSession(session);
561 }
562 }
563 else {
564 return (List<PortletPreferences>)result;
565 }
566 }
567
568 public List<PortletPreferences> findByP_P(long plid, String portletId,
569 int start, int end) throws SystemException {
570 return findByP_P(plid, portletId, start, end, null);
571 }
572
573 public List<PortletPreferences> findByP_P(long plid, String portletId,
574 int start, int end, OrderByComparator obc) throws SystemException {
575 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
576 String finderClassName = PortletPreferences.class.getName();
577 String finderMethodName = "findByP_P";
578 String[] finderParams = new String[] {
579 Long.class.getName(), String.class.getName(),
580
581 "java.lang.Integer", "java.lang.Integer",
582 "com.liferay.portal.kernel.util.OrderByComparator"
583 };
584 Object[] finderArgs = new Object[] {
585 new Long(plid),
586
587 portletId,
588
589 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
590 };
591
592 Object result = null;
593
594 if (finderClassNameCacheEnabled) {
595 result = FinderCacheUtil.getResult(finderClassName,
596 finderMethodName, finderParams, finderArgs, this);
597 }
598
599 if (result == null) {
600 Session session = null;
601
602 try {
603 session = openSession();
604
605 StringBuilder query = new StringBuilder();
606
607 query.append(
608 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
609
610 query.append("plid = ?");
611
612 query.append(" AND ");
613
614 if (portletId == null) {
615 query.append("portletId IS NULL");
616 }
617 else {
618 query.append("portletId = ?");
619 }
620
621 query.append(" ");
622
623 if (obc != null) {
624 query.append("ORDER BY ");
625 query.append(obc.getOrderBy());
626 }
627
628 Query q = session.createQuery(query.toString());
629
630 QueryPos qPos = QueryPos.getInstance(q);
631
632 qPos.add(plid);
633
634 if (portletId != null) {
635 qPos.add(portletId);
636 }
637
638 List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
639 getDialect(), start, end);
640
641 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
642 finderClassName, finderMethodName, finderParams,
643 finderArgs, list);
644
645 return list;
646 }
647 catch (Exception e) {
648 throw processException(e);
649 }
650 finally {
651 closeSession(session);
652 }
653 }
654 else {
655 return (List<PortletPreferences>)result;
656 }
657 }
658
659 public PortletPreferences findByP_P_First(long plid, String portletId,
660 OrderByComparator obc)
661 throws NoSuchPortletPreferencesException, SystemException {
662 List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1, obc);
663
664 if (list.size() == 0) {
665 StringBuilder msg = new StringBuilder();
666
667 msg.append("No PortletPreferences exists with the key {");
668
669 msg.append("plid=" + plid);
670
671 msg.append(", ");
672 msg.append("portletId=" + portletId);
673
674 msg.append(StringPool.CLOSE_CURLY_BRACE);
675
676 throw new NoSuchPortletPreferencesException(msg.toString());
677 }
678 else {
679 return list.get(0);
680 }
681 }
682
683 public PortletPreferences findByP_P_Last(long plid, String portletId,
684 OrderByComparator obc)
685 throws NoSuchPortletPreferencesException, SystemException {
686 int count = countByP_P(plid, portletId);
687
688 List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
689 count, obc);
690
691 if (list.size() == 0) {
692 StringBuilder msg = new StringBuilder();
693
694 msg.append("No PortletPreferences exists with the key {");
695
696 msg.append("plid=" + plid);
697
698 msg.append(", ");
699 msg.append("portletId=" + portletId);
700
701 msg.append(StringPool.CLOSE_CURLY_BRACE);
702
703 throw new NoSuchPortletPreferencesException(msg.toString());
704 }
705 else {
706 return list.get(0);
707 }
708 }
709
710 public PortletPreferences[] findByP_P_PrevAndNext(
711 long portletPreferencesId, long plid, String portletId,
712 OrderByComparator obc)
713 throws NoSuchPortletPreferencesException, SystemException {
714 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
715
716 int count = countByP_P(plid, portletId);
717
718 Session session = null;
719
720 try {
721 session = openSession();
722
723 StringBuilder query = new StringBuilder();
724
725 query.append(
726 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
727
728 query.append("plid = ?");
729
730 query.append(" AND ");
731
732 if (portletId == null) {
733 query.append("portletId IS NULL");
734 }
735 else {
736 query.append("portletId = ?");
737 }
738
739 query.append(" ");
740
741 if (obc != null) {
742 query.append("ORDER BY ");
743 query.append(obc.getOrderBy());
744 }
745
746 Query q = session.createQuery(query.toString());
747
748 QueryPos qPos = QueryPos.getInstance(q);
749
750 qPos.add(plid);
751
752 if (portletId != null) {
753 qPos.add(portletId);
754 }
755
756 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
757 portletPreferences);
758
759 PortletPreferences[] array = new PortletPreferencesImpl[3];
760
761 array[0] = (PortletPreferences)objArray[0];
762 array[1] = (PortletPreferences)objArray[1];
763 array[2] = (PortletPreferences)objArray[2];
764
765 return array;
766 }
767 catch (Exception e) {
768 throw processException(e);
769 }
770 finally {
771 closeSession(session);
772 }
773 }
774
775 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
776 long plid) throws SystemException {
777 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
778 String finderClassName = PortletPreferences.class.getName();
779 String finderMethodName = "findByO_O_P";
780 String[] finderParams = new String[] {
781 Long.class.getName(), Integer.class.getName(),
782 Long.class.getName()
783 };
784 Object[] finderArgs = new Object[] {
785 new Long(ownerId), new Integer(ownerType), new Long(plid)
786 };
787
788 Object result = null;
789
790 if (finderClassNameCacheEnabled) {
791 result = FinderCacheUtil.getResult(finderClassName,
792 finderMethodName, finderParams, finderArgs, this);
793 }
794
795 if (result == null) {
796 Session session = null;
797
798 try {
799 session = openSession();
800
801 StringBuilder query = new StringBuilder();
802
803 query.append(
804 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
805
806 query.append("ownerId = ?");
807
808 query.append(" AND ");
809
810 query.append("ownerType = ?");
811
812 query.append(" AND ");
813
814 query.append("plid = ?");
815
816 query.append(" ");
817
818 Query q = session.createQuery(query.toString());
819
820 QueryPos qPos = QueryPos.getInstance(q);
821
822 qPos.add(ownerId);
823
824 qPos.add(ownerType);
825
826 qPos.add(plid);
827
828 List<PortletPreferences> list = q.list();
829
830 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
831 finderClassName, finderMethodName, finderParams,
832 finderArgs, list);
833
834 return list;
835 }
836 catch (Exception e) {
837 throw processException(e);
838 }
839 finally {
840 closeSession(session);
841 }
842 }
843 else {
844 return (List<PortletPreferences>)result;
845 }
846 }
847
848 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
849 long plid, int start, int end) throws SystemException {
850 return findByO_O_P(ownerId, ownerType, plid, start, end, null);
851 }
852
853 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
854 long plid, int start, int end, OrderByComparator obc)
855 throws SystemException {
856 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
857 String finderClassName = PortletPreferences.class.getName();
858 String finderMethodName = "findByO_O_P";
859 String[] finderParams = new String[] {
860 Long.class.getName(), Integer.class.getName(),
861 Long.class.getName(),
862
863 "java.lang.Integer", "java.lang.Integer",
864 "com.liferay.portal.kernel.util.OrderByComparator"
865 };
866 Object[] finderArgs = new Object[] {
867 new Long(ownerId), new Integer(ownerType), new Long(plid),
868
869 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
870 };
871
872 Object result = null;
873
874 if (finderClassNameCacheEnabled) {
875 result = FinderCacheUtil.getResult(finderClassName,
876 finderMethodName, finderParams, finderArgs, this);
877 }
878
879 if (result == null) {
880 Session session = null;
881
882 try {
883 session = openSession();
884
885 StringBuilder query = new StringBuilder();
886
887 query.append(
888 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
889
890 query.append("ownerId = ?");
891
892 query.append(" AND ");
893
894 query.append("ownerType = ?");
895
896 query.append(" AND ");
897
898 query.append("plid = ?");
899
900 query.append(" ");
901
902 if (obc != null) {
903 query.append("ORDER BY ");
904 query.append(obc.getOrderBy());
905 }
906
907 Query q = session.createQuery(query.toString());
908
909 QueryPos qPos = QueryPos.getInstance(q);
910
911 qPos.add(ownerId);
912
913 qPos.add(ownerType);
914
915 qPos.add(plid);
916
917 List<PortletPreferences> list = (List<PortletPreferences>)QueryUtil.list(q,
918 getDialect(), start, end);
919
920 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
921 finderClassName, finderMethodName, finderParams,
922 finderArgs, list);
923
924 return list;
925 }
926 catch (Exception e) {
927 throw processException(e);
928 }
929 finally {
930 closeSession(session);
931 }
932 }
933 else {
934 return (List<PortletPreferences>)result;
935 }
936 }
937
938 public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
939 long plid, OrderByComparator obc)
940 throws NoSuchPortletPreferencesException, SystemException {
941 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
942 0, 1, obc);
943
944 if (list.size() == 0) {
945 StringBuilder msg = new StringBuilder();
946
947 msg.append("No PortletPreferences exists with the key {");
948
949 msg.append("ownerId=" + ownerId);
950
951 msg.append(", ");
952 msg.append("ownerType=" + ownerType);
953
954 msg.append(", ");
955 msg.append("plid=" + plid);
956
957 msg.append(StringPool.CLOSE_CURLY_BRACE);
958
959 throw new NoSuchPortletPreferencesException(msg.toString());
960 }
961 else {
962 return list.get(0);
963 }
964 }
965
966 public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
967 long plid, OrderByComparator obc)
968 throws NoSuchPortletPreferencesException, SystemException {
969 int count = countByO_O_P(ownerId, ownerType, plid);
970
971 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
972 count - 1, count, obc);
973
974 if (list.size() == 0) {
975 StringBuilder msg = new StringBuilder();
976
977 msg.append("No PortletPreferences exists with the key {");
978
979 msg.append("ownerId=" + ownerId);
980
981 msg.append(", ");
982 msg.append("ownerType=" + ownerType);
983
984 msg.append(", ");
985 msg.append("plid=" + plid);
986
987 msg.append(StringPool.CLOSE_CURLY_BRACE);
988
989 throw new NoSuchPortletPreferencesException(msg.toString());
990 }
991 else {
992 return list.get(0);
993 }
994 }
995
996 public PortletPreferences[] findByO_O_P_PrevAndNext(
997 long portletPreferencesId, long ownerId, int ownerType, long plid,
998 OrderByComparator obc)
999 throws NoSuchPortletPreferencesException, SystemException {
1000 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1001
1002 int count = countByO_O_P(ownerId, ownerType, plid);
1003
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 StringBuilder query = new StringBuilder();
1010
1011 query.append(
1012 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1013
1014 query.append("ownerId = ?");
1015
1016 query.append(" AND ");
1017
1018 query.append("ownerType = ?");
1019
1020 query.append(" AND ");
1021
1022 query.append("plid = ?");
1023
1024 query.append(" ");
1025
1026 if (obc != null) {
1027 query.append("ORDER BY ");
1028 query.append(obc.getOrderBy());
1029 }
1030
1031 Query q = session.createQuery(query.toString());
1032
1033 QueryPos qPos = QueryPos.getInstance(q);
1034
1035 qPos.add(ownerId);
1036
1037 qPos.add(ownerType);
1038
1039 qPos.add(plid);
1040
1041 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1042 portletPreferences);
1043
1044 PortletPreferences[] array = new PortletPreferencesImpl[3];
1045
1046 array[0] = (PortletPreferences)objArray[0];
1047 array[1] = (PortletPreferences)objArray[1];
1048 array[2] = (PortletPreferences)objArray[2];
1049
1050 return array;
1051 }
1052 catch (Exception e) {
1053 throw processException(e);
1054 }
1055 finally {
1056 closeSession(session);
1057 }
1058 }
1059
1060 public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
1061 long plid, String portletId)
1062 throws NoSuchPortletPreferencesException, SystemException {
1063 PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
1064 ownerType, plid, portletId);
1065
1066 if (portletPreferences == null) {
1067 StringBuilder msg = new StringBuilder();
1068
1069 msg.append("No PortletPreferences exists with the key {");
1070
1071 msg.append("ownerId=" + ownerId);
1072
1073 msg.append(", ");
1074 msg.append("ownerType=" + ownerType);
1075
1076 msg.append(", ");
1077 msg.append("plid=" + plid);
1078
1079 msg.append(", ");
1080 msg.append("portletId=" + portletId);
1081
1082 msg.append(StringPool.CLOSE_CURLY_BRACE);
1083
1084 if (_log.isWarnEnabled()) {
1085 _log.warn(msg.toString());
1086 }
1087
1088 throw new NoSuchPortletPreferencesException(msg.toString());
1089 }
1090
1091 return portletPreferences;
1092 }
1093
1094 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1095 long plid, String portletId) throws SystemException {
1096 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1097 String finderClassName = PortletPreferences.class.getName();
1098 String finderMethodName = "fetchByO_O_P_P";
1099 String[] finderParams = new String[] {
1100 Long.class.getName(), Integer.class.getName(),
1101 Long.class.getName(), String.class.getName()
1102 };
1103 Object[] finderArgs = new Object[] {
1104 new Long(ownerId), new Integer(ownerType), new Long(plid),
1105
1106 portletId
1107 };
1108
1109 Object result = null;
1110
1111 if (finderClassNameCacheEnabled) {
1112 result = FinderCacheUtil.getResult(finderClassName,
1113 finderMethodName, finderParams, finderArgs, this);
1114 }
1115
1116 if (result == null) {
1117 Session session = null;
1118
1119 try {
1120 session = openSession();
1121
1122 StringBuilder query = new StringBuilder();
1123
1124 query.append(
1125 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1126
1127 query.append("ownerId = ?");
1128
1129 query.append(" AND ");
1130
1131 query.append("ownerType = ?");
1132
1133 query.append(" AND ");
1134
1135 query.append("plid = ?");
1136
1137 query.append(" AND ");
1138
1139 if (portletId == null) {
1140 query.append("portletId IS NULL");
1141 }
1142 else {
1143 query.append("portletId = ?");
1144 }
1145
1146 query.append(" ");
1147
1148 Query q = session.createQuery(query.toString());
1149
1150 QueryPos qPos = QueryPos.getInstance(q);
1151
1152 qPos.add(ownerId);
1153
1154 qPos.add(ownerType);
1155
1156 qPos.add(plid);
1157
1158 if (portletId != null) {
1159 qPos.add(portletId);
1160 }
1161
1162 List<PortletPreferences> list = q.list();
1163
1164 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1165 finderClassName, finderMethodName, finderParams,
1166 finderArgs, list);
1167
1168 if (list.size() == 0) {
1169 return null;
1170 }
1171 else {
1172 return list.get(0);
1173 }
1174 }
1175 catch (Exception e) {
1176 throw processException(e);
1177 }
1178 finally {
1179 closeSession(session);
1180 }
1181 }
1182 else {
1183 List<PortletPreferences> list = (List<PortletPreferences>)result;
1184
1185 if (list.size() == 0) {
1186 return null;
1187 }
1188 else {
1189 return list.get(0);
1190 }
1191 }
1192 }
1193
1194 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1195 throws SystemException {
1196 Session session = null;
1197
1198 try {
1199 session = openSession();
1200
1201 dynamicQuery.compile(session);
1202
1203 return dynamicQuery.list();
1204 }
1205 catch (Exception e) {
1206 throw processException(e);
1207 }
1208 finally {
1209 closeSession(session);
1210 }
1211 }
1212
1213 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1214 int start, int end) throws SystemException {
1215 Session session = null;
1216
1217 try {
1218 session = openSession();
1219
1220 dynamicQuery.setLimit(start, end);
1221
1222 dynamicQuery.compile(session);
1223
1224 return dynamicQuery.list();
1225 }
1226 catch (Exception e) {
1227 throw processException(e);
1228 }
1229 finally {
1230 closeSession(session);
1231 }
1232 }
1233
1234 public List<PortletPreferences> findAll() throws SystemException {
1235 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1236 }
1237
1238 public List<PortletPreferences> findAll(int start, int end)
1239 throws SystemException {
1240 return findAll(start, end, null);
1241 }
1242
1243 public List<PortletPreferences> findAll(int start, int end,
1244 OrderByComparator obc) throws SystemException {
1245 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1246 String finderClassName = PortletPreferences.class.getName();
1247 String finderMethodName = "findAll";
1248 String[] finderParams = new String[] {
1249 "java.lang.Integer", "java.lang.Integer",
1250 "com.liferay.portal.kernel.util.OrderByComparator"
1251 };
1252 Object[] finderArgs = new Object[] {
1253 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1254 };
1255
1256 Object result = null;
1257
1258 if (finderClassNameCacheEnabled) {
1259 result = FinderCacheUtil.getResult(finderClassName,
1260 finderMethodName, finderParams, finderArgs, this);
1261 }
1262
1263 if (result == null) {
1264 Session session = null;
1265
1266 try {
1267 session = openSession();
1268
1269 StringBuilder query = new StringBuilder();
1270
1271 query.append(
1272 "FROM com.liferay.portal.model.PortletPreferences ");
1273
1274 if (obc != null) {
1275 query.append("ORDER BY ");
1276 query.append(obc.getOrderBy());
1277 }
1278
1279 Query q = session.createQuery(query.toString());
1280
1281 List<PortletPreferences> list = null;
1282
1283 if (obc == null) {
1284 list = (List<PortletPreferences>)QueryUtil.list(q,
1285 getDialect(), start, end, false);
1286
1287 Collections.sort(list);
1288 }
1289 else {
1290 list = (List<PortletPreferences>)QueryUtil.list(q,
1291 getDialect(), start, end);
1292 }
1293
1294 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1295 finderClassName, finderMethodName, finderParams,
1296 finderArgs, list);
1297
1298 return list;
1299 }
1300 catch (Exception e) {
1301 throw processException(e);
1302 }
1303 finally {
1304 closeSession(session);
1305 }
1306 }
1307 else {
1308 return (List<PortletPreferences>)result;
1309 }
1310 }
1311
1312 public void removeByPlid(long plid) throws SystemException {
1313 for (PortletPreferences portletPreferences : findByPlid(plid)) {
1314 remove(portletPreferences);
1315 }
1316 }
1317
1318 public void removeByP_P(long plid, String portletId)
1319 throws SystemException {
1320 for (PortletPreferences portletPreferences : findByP_P(plid, portletId)) {
1321 remove(portletPreferences);
1322 }
1323 }
1324
1325 public void removeByO_O_P(long ownerId, int ownerType, long plid)
1326 throws SystemException {
1327 for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
1328 ownerType, plid)) {
1329 remove(portletPreferences);
1330 }
1331 }
1332
1333 public void removeByO_O_P_P(long ownerId, int ownerType, long plid,
1334 String portletId)
1335 throws NoSuchPortletPreferencesException, SystemException {
1336 PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
1337 ownerType, plid, portletId);
1338
1339 remove(portletPreferences);
1340 }
1341
1342 public void removeAll() throws SystemException {
1343 for (PortletPreferences portletPreferences : findAll()) {
1344 remove(portletPreferences);
1345 }
1346 }
1347
1348 public int countByPlid(long plid) throws SystemException {
1349 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1350 String finderClassName = PortletPreferences.class.getName();
1351 String finderMethodName = "countByPlid";
1352 String[] finderParams = new String[] { Long.class.getName() };
1353 Object[] finderArgs = new Object[] { new Long(plid) };
1354
1355 Object result = null;
1356
1357 if (finderClassNameCacheEnabled) {
1358 result = FinderCacheUtil.getResult(finderClassName,
1359 finderMethodName, finderParams, finderArgs, this);
1360 }
1361
1362 if (result == null) {
1363 Session session = null;
1364
1365 try {
1366 session = openSession();
1367
1368 StringBuilder query = new StringBuilder();
1369
1370 query.append("SELECT COUNT(*) ");
1371 query.append(
1372 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1373
1374 query.append("plid = ?");
1375
1376 query.append(" ");
1377
1378 Query q = session.createQuery(query.toString());
1379
1380 QueryPos qPos = QueryPos.getInstance(q);
1381
1382 qPos.add(plid);
1383
1384 Long count = null;
1385
1386 Iterator<Long> itr = q.list().iterator();
1387
1388 if (itr.hasNext()) {
1389 count = itr.next();
1390 }
1391
1392 if (count == null) {
1393 count = new Long(0);
1394 }
1395
1396 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1397 finderClassName, finderMethodName, finderParams,
1398 finderArgs, count);
1399
1400 return count.intValue();
1401 }
1402 catch (Exception e) {
1403 throw processException(e);
1404 }
1405 finally {
1406 closeSession(session);
1407 }
1408 }
1409 else {
1410 return ((Long)result).intValue();
1411 }
1412 }
1413
1414 public int countByP_P(long plid, String portletId)
1415 throws SystemException {
1416 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1417 String finderClassName = PortletPreferences.class.getName();
1418 String finderMethodName = "countByP_P";
1419 String[] finderParams = new String[] {
1420 Long.class.getName(), String.class.getName()
1421 };
1422 Object[] finderArgs = new Object[] { new Long(plid), portletId };
1423
1424 Object result = null;
1425
1426 if (finderClassNameCacheEnabled) {
1427 result = FinderCacheUtil.getResult(finderClassName,
1428 finderMethodName, finderParams, finderArgs, this);
1429 }
1430
1431 if (result == null) {
1432 Session session = null;
1433
1434 try {
1435 session = openSession();
1436
1437 StringBuilder query = new StringBuilder();
1438
1439 query.append("SELECT COUNT(*) ");
1440 query.append(
1441 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1442
1443 query.append("plid = ?");
1444
1445 query.append(" AND ");
1446
1447 if (portletId == null) {
1448 query.append("portletId IS NULL");
1449 }
1450 else {
1451 query.append("portletId = ?");
1452 }
1453
1454 query.append(" ");
1455
1456 Query q = session.createQuery(query.toString());
1457
1458 QueryPos qPos = QueryPos.getInstance(q);
1459
1460 qPos.add(plid);
1461
1462 if (portletId != null) {
1463 qPos.add(portletId);
1464 }
1465
1466 Long count = null;
1467
1468 Iterator<Long> itr = q.list().iterator();
1469
1470 if (itr.hasNext()) {
1471 count = itr.next();
1472 }
1473
1474 if (count == null) {
1475 count = new Long(0);
1476 }
1477
1478 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1479 finderClassName, finderMethodName, finderParams,
1480 finderArgs, count);
1481
1482 return count.intValue();
1483 }
1484 catch (Exception e) {
1485 throw processException(e);
1486 }
1487 finally {
1488 closeSession(session);
1489 }
1490 }
1491 else {
1492 return ((Long)result).intValue();
1493 }
1494 }
1495
1496 public int countByO_O_P(long ownerId, int ownerType, long plid)
1497 throws SystemException {
1498 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1499 String finderClassName = PortletPreferences.class.getName();
1500 String finderMethodName = "countByO_O_P";
1501 String[] finderParams = new String[] {
1502 Long.class.getName(), Integer.class.getName(),
1503 Long.class.getName()
1504 };
1505 Object[] finderArgs = new Object[] {
1506 new Long(ownerId), new Integer(ownerType), new Long(plid)
1507 };
1508
1509 Object result = null;
1510
1511 if (finderClassNameCacheEnabled) {
1512 result = FinderCacheUtil.getResult(finderClassName,
1513 finderMethodName, finderParams, finderArgs, this);
1514 }
1515
1516 if (result == null) {
1517 Session session = null;
1518
1519 try {
1520 session = openSession();
1521
1522 StringBuilder query = new StringBuilder();
1523
1524 query.append("SELECT COUNT(*) ");
1525 query.append(
1526 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1527
1528 query.append("ownerId = ?");
1529
1530 query.append(" AND ");
1531
1532 query.append("ownerType = ?");
1533
1534 query.append(" AND ");
1535
1536 query.append("plid = ?");
1537
1538 query.append(" ");
1539
1540 Query q = session.createQuery(query.toString());
1541
1542 QueryPos qPos = QueryPos.getInstance(q);
1543
1544 qPos.add(ownerId);
1545
1546 qPos.add(ownerType);
1547
1548 qPos.add(plid);
1549
1550 Long count = null;
1551
1552 Iterator<Long> itr = q.list().iterator();
1553
1554 if (itr.hasNext()) {
1555 count = itr.next();
1556 }
1557
1558 if (count == null) {
1559 count = new Long(0);
1560 }
1561
1562 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1563 finderClassName, finderMethodName, finderParams,
1564 finderArgs, count);
1565
1566 return count.intValue();
1567 }
1568 catch (Exception e) {
1569 throw processException(e);
1570 }
1571 finally {
1572 closeSession(session);
1573 }
1574 }
1575 else {
1576 return ((Long)result).intValue();
1577 }
1578 }
1579
1580 public int countByO_O_P_P(long ownerId, int ownerType, long plid,
1581 String portletId) throws SystemException {
1582 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1583 String finderClassName = PortletPreferences.class.getName();
1584 String finderMethodName = "countByO_O_P_P";
1585 String[] finderParams = new String[] {
1586 Long.class.getName(), Integer.class.getName(),
1587 Long.class.getName(), String.class.getName()
1588 };
1589 Object[] finderArgs = new Object[] {
1590 new Long(ownerId), new Integer(ownerType), new Long(plid),
1591
1592 portletId
1593 };
1594
1595 Object result = null;
1596
1597 if (finderClassNameCacheEnabled) {
1598 result = FinderCacheUtil.getResult(finderClassName,
1599 finderMethodName, finderParams, finderArgs, this);
1600 }
1601
1602 if (result == null) {
1603 Session session = null;
1604
1605 try {
1606 session = openSession();
1607
1608 StringBuilder query = new StringBuilder();
1609
1610 query.append("SELECT COUNT(*) ");
1611 query.append(
1612 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
1613
1614 query.append("ownerId = ?");
1615
1616 query.append(" AND ");
1617
1618 query.append("ownerType = ?");
1619
1620 query.append(" AND ");
1621
1622 query.append("plid = ?");
1623
1624 query.append(" AND ");
1625
1626 if (portletId == null) {
1627 query.append("portletId IS NULL");
1628 }
1629 else {
1630 query.append("portletId = ?");
1631 }
1632
1633 query.append(" ");
1634
1635 Query q = session.createQuery(query.toString());
1636
1637 QueryPos qPos = QueryPos.getInstance(q);
1638
1639 qPos.add(ownerId);
1640
1641 qPos.add(ownerType);
1642
1643 qPos.add(plid);
1644
1645 if (portletId != null) {
1646 qPos.add(portletId);
1647 }
1648
1649 Long count = null;
1650
1651 Iterator<Long> itr = q.list().iterator();
1652
1653 if (itr.hasNext()) {
1654 count = itr.next();
1655 }
1656
1657 if (count == null) {
1658 count = new Long(0);
1659 }
1660
1661 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1662 finderClassName, finderMethodName, finderParams,
1663 finderArgs, count);
1664
1665 return count.intValue();
1666 }
1667 catch (Exception e) {
1668 throw processException(e);
1669 }
1670 finally {
1671 closeSession(session);
1672 }
1673 }
1674 else {
1675 return ((Long)result).intValue();
1676 }
1677 }
1678
1679 public int countAll() throws SystemException {
1680 boolean finderClassNameCacheEnabled = PortletPreferencesModelImpl.CACHE_ENABLED;
1681 String finderClassName = PortletPreferences.class.getName();
1682 String finderMethodName = "countAll";
1683 String[] finderParams = new String[] { };
1684 Object[] finderArgs = new Object[] { };
1685
1686 Object result = null;
1687
1688 if (finderClassNameCacheEnabled) {
1689 result = FinderCacheUtil.getResult(finderClassName,
1690 finderMethodName, finderParams, finderArgs, this);
1691 }
1692
1693 if (result == null) {
1694 Session session = null;
1695
1696 try {
1697 session = openSession();
1698
1699 Query q = session.createQuery(
1700 "SELECT COUNT(*) FROM com.liferay.portal.model.PortletPreferences");
1701
1702 Long count = null;
1703
1704 Iterator<Long> itr = q.list().iterator();
1705
1706 if (itr.hasNext()) {
1707 count = itr.next();
1708 }
1709
1710 if (count == null) {
1711 count = new Long(0);
1712 }
1713
1714 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1715 finderClassName, finderMethodName, finderParams,
1716 finderArgs, count);
1717
1718 return count.intValue();
1719 }
1720 catch (Exception e) {
1721 throw processException(e);
1722 }
1723 finally {
1724 closeSession(session);
1725 }
1726 }
1727 else {
1728 return ((Long)result).intValue();
1729 }
1730 }
1731
1732 public void registerListener(ModelListener listener) {
1733 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1734
1735 listeners.add(listener);
1736
1737 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1738 }
1739
1740 public void unregisterListener(ModelListener listener) {
1741 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1742
1743 listeners.remove(listener);
1744
1745 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1746 }
1747
1748 public void afterPropertiesSet() {
1749 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1750 com.liferay.portal.util.PropsUtil.get(
1751 "value.object.listener.com.liferay.portal.model.PortletPreferences")));
1752
1753 if (listenerClassNames.length > 0) {
1754 try {
1755 List<ModelListener> listeners = new ArrayList<ModelListener>();
1756
1757 for (String listenerClassName : listenerClassNames) {
1758 listeners.add((ModelListener)Class.forName(
1759 listenerClassName).newInstance());
1760 }
1761
1762 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1763 }
1764 catch (Exception e) {
1765 _log.error(e);
1766 }
1767 }
1768 }
1769
1770 private static Log _log = LogFactory.getLog(PortletPreferencesPersistenceImpl.class);
1771 private ModelListener[] _listeners = new ModelListener[0];
1772}