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