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