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.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.model.PortletPreferences;
33 import com.liferay.portal.model.impl.PortletPreferencesImpl;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37
38 import com.liferay.util.dao.hibernate.QueryUtil;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 import org.hibernate.Query;
44 import org.hibernate.Session;
45
46 import java.util.Collections;
47 import java.util.Iterator;
48 import java.util.List;
49
50
56 public class PortletPreferencesPersistenceImpl extends BasePersistence
57 implements PortletPreferencesPersistence {
58 public PortletPreferences create(long portletPreferencesId) {
59 PortletPreferences portletPreferences = new PortletPreferencesImpl();
60 portletPreferences.setNew(true);
61 portletPreferences.setPrimaryKey(portletPreferencesId);
62
63 return portletPreferences;
64 }
65
66 public PortletPreferences remove(long portletPreferencesId)
67 throws NoSuchPortletPreferencesException, SystemException {
68 Session session = null;
69
70 try {
71 session = openSession();
72
73 PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
74 new Long(portletPreferencesId));
75
76 if (portletPreferences == null) {
77 if (_log.isWarnEnabled()) {
78 _log.warn(
79 "No PortletPreferences exists with the primary key " +
80 portletPreferencesId);
81 }
82
83 throw new NoSuchPortletPreferencesException(
84 "No PortletPreferences exists with the primary key " +
85 portletPreferencesId);
86 }
87
88 return remove(portletPreferences);
89 }
90 catch (NoSuchPortletPreferencesException nsee) {
91 throw nsee;
92 }
93 catch (Exception e) {
94 throw HibernateUtil.processException(e);
95 }
96 finally {
97 closeSession(session);
98 }
99 }
100
101 public PortletPreferences remove(PortletPreferences portletPreferences)
102 throws SystemException {
103 Session session = null;
104
105 try {
106 session = openSession();
107 session.delete(portletPreferences);
108 session.flush();
109
110 return portletPreferences;
111 }
112 catch (Exception e) {
113 throw HibernateUtil.processException(e);
114 }
115 finally {
116 closeSession(session);
117 FinderCache.clearCache(PortletPreferences.class.getName());
118 }
119 }
120
121 public PortletPreferences update(
122 com.liferay.portal.model.PortletPreferences portletPreferences)
123 throws SystemException {
124 return update(portletPreferences, false);
125 }
126
127 public PortletPreferences update(
128 com.liferay.portal.model.PortletPreferences portletPreferences,
129 boolean merge) throws SystemException {
130 Session session = null;
131
132 try {
133 session = openSession();
134
135 if (merge) {
136 session.merge(portletPreferences);
137 }
138 else {
139 if (portletPreferences.isNew()) {
140 session.save(portletPreferences);
141 }
142 }
143
144 session.flush();
145 portletPreferences.setNew(false);
146
147 return portletPreferences;
148 }
149 catch (Exception e) {
150 throw HibernateUtil.processException(e);
151 }
152 finally {
153 closeSession(session);
154 FinderCache.clearCache(PortletPreferences.class.getName());
155 }
156 }
157
158 public PortletPreferences findByPrimaryKey(long portletPreferencesId)
159 throws NoSuchPortletPreferencesException, SystemException {
160 PortletPreferences portletPreferences = fetchByPrimaryKey(portletPreferencesId);
161
162 if (portletPreferences == null) {
163 if (_log.isWarnEnabled()) {
164 _log.warn("No PortletPreferences exists with the primary key " +
165 portletPreferencesId);
166 }
167
168 throw new NoSuchPortletPreferencesException(
169 "No PortletPreferences exists with the primary key " +
170 portletPreferencesId);
171 }
172
173 return portletPreferences;
174 }
175
176 public PortletPreferences fetchByPrimaryKey(long portletPreferencesId)
177 throws SystemException {
178 Session session = null;
179
180 try {
181 session = openSession();
182
183 return (PortletPreferences)session.get(PortletPreferencesImpl.class,
184 new Long(portletPreferencesId));
185 }
186 catch (Exception e) {
187 throw HibernateUtil.processException(e);
188 }
189 finally {
190 closeSession(session);
191 }
192 }
193
194 public List findByPlid(long plid) throws SystemException {
195 String finderClassName = PortletPreferences.class.getName();
196 String finderMethodName = "findByPlid";
197 String[] finderParams = new String[] { Long.class.getName() };
198 Object[] finderArgs = new Object[] { new Long(plid) };
199 Object result = FinderCache.getResult(finderClassName,
200 finderMethodName, finderParams, finderArgs, getSessionFactory());
201
202 if (result == null) {
203 Session session = null;
204
205 try {
206 session = openSession();
207
208 StringMaker query = new StringMaker();
209 query.append(
210 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
211 query.append("plid = ?");
212 query.append(" ");
213
214 Query q = session.createQuery(query.toString());
215 int queryPos = 0;
216 q.setLong(queryPos++, plid);
217
218 List list = q.list();
219 FinderCache.putResult(finderClassName, finderMethodName,
220 finderParams, finderArgs, list);
221
222 return list;
223 }
224 catch (Exception e) {
225 throw HibernateUtil.processException(e);
226 }
227 finally {
228 closeSession(session);
229 }
230 }
231 else {
232 return (List)result;
233 }
234 }
235
236 public List findByPlid(long plid, int begin, int end)
237 throws SystemException {
238 return findByPlid(plid, begin, end, null);
239 }
240
241 public List findByPlid(long plid, int begin, int end, OrderByComparator obc)
242 throws SystemException {
243 String finderClassName = PortletPreferences.class.getName();
244 String finderMethodName = "findByPlid";
245 String[] finderParams = new String[] {
246 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
247 "com.liferay.portal.kernel.util.OrderByComparator"
248 };
249 Object[] finderArgs = new Object[] {
250 new Long(plid), String.valueOf(begin), String.valueOf(end),
251 String.valueOf(obc)
252 };
253 Object result = FinderCache.getResult(finderClassName,
254 finderMethodName, finderParams, finderArgs, getSessionFactory());
255
256 if (result == null) {
257 Session session = null;
258
259 try {
260 session = openSession();
261
262 StringMaker query = new StringMaker();
263 query.append(
264 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
265 query.append("plid = ?");
266 query.append(" ");
267
268 if (obc != null) {
269 query.append("ORDER BY ");
270 query.append(obc.getOrderBy());
271 }
272
273 Query q = session.createQuery(query.toString());
274 int queryPos = 0;
275 q.setLong(queryPos++, plid);
276
277 List list = QueryUtil.list(q, getDialect(), begin, end);
278 FinderCache.putResult(finderClassName, finderMethodName,
279 finderParams, finderArgs, list);
280
281 return list;
282 }
283 catch (Exception e) {
284 throw HibernateUtil.processException(e);
285 }
286 finally {
287 closeSession(session);
288 }
289 }
290 else {
291 return (List)result;
292 }
293 }
294
295 public PortletPreferences findByPlid_First(long plid, OrderByComparator obc)
296 throws NoSuchPortletPreferencesException, SystemException {
297 List list = findByPlid(plid, 0, 1, obc);
298
299 if (list.size() == 0) {
300 StringMaker msg = new StringMaker();
301 msg.append("No PortletPreferences exists with the key ");
302 msg.append(StringPool.OPEN_CURLY_BRACE);
303 msg.append("plid=");
304 msg.append(plid);
305 msg.append(StringPool.CLOSE_CURLY_BRACE);
306 throw new NoSuchPortletPreferencesException(msg.toString());
307 }
308 else {
309 return (PortletPreferences)list.get(0);
310 }
311 }
312
313 public PortletPreferences findByPlid_Last(long plid, OrderByComparator obc)
314 throws NoSuchPortletPreferencesException, SystemException {
315 int count = countByPlid(plid);
316 List list = findByPlid(plid, count - 1, count, obc);
317
318 if (list.size() == 0) {
319 StringMaker msg = new StringMaker();
320 msg.append("No PortletPreferences exists with the key ");
321 msg.append(StringPool.OPEN_CURLY_BRACE);
322 msg.append("plid=");
323 msg.append(plid);
324 msg.append(StringPool.CLOSE_CURLY_BRACE);
325 throw new NoSuchPortletPreferencesException(msg.toString());
326 }
327 else {
328 return (PortletPreferences)list.get(0);
329 }
330 }
331
332 public PortletPreferences[] findByPlid_PrevAndNext(
333 long portletPreferencesId, long plid, OrderByComparator obc)
334 throws NoSuchPortletPreferencesException, SystemException {
335 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
336 int count = countByPlid(plid);
337 Session session = null;
338
339 try {
340 session = openSession();
341
342 StringMaker query = new StringMaker();
343 query.append(
344 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
345 query.append("plid = ?");
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 int queryPos = 0;
355 q.setLong(queryPos++, plid);
356
357 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
358 portletPreferences);
359 PortletPreferences[] array = new PortletPreferencesImpl[3];
360 array[0] = (PortletPreferences)objArray[0];
361 array[1] = (PortletPreferences)objArray[1];
362 array[2] = (PortletPreferences)objArray[2];
363
364 return array;
365 }
366 catch (Exception e) {
367 throw HibernateUtil.processException(e);
368 }
369 finally {
370 closeSession(session);
371 }
372 }
373
374 public List findByO_O_P(long ownerId, int ownerType, long plid)
375 throws SystemException {
376 String finderClassName = PortletPreferences.class.getName();
377 String finderMethodName = "findByO_O_P";
378 String[] finderParams = new String[] {
379 Long.class.getName(), Integer.class.getName(),
380 Long.class.getName()
381 };
382 Object[] finderArgs = new Object[] {
383 new Long(ownerId), new Integer(ownerType), new Long(plid)
384 };
385 Object result = FinderCache.getResult(finderClassName,
386 finderMethodName, finderParams, finderArgs, getSessionFactory());
387
388 if (result == null) {
389 Session session = null;
390
391 try {
392 session = openSession();
393
394 StringMaker query = new StringMaker();
395 query.append(
396 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
397 query.append("ownerId = ?");
398 query.append(" AND ");
399 query.append("ownerType = ?");
400 query.append(" AND ");
401 query.append("plid = ?");
402 query.append(" ");
403
404 Query q = session.createQuery(query.toString());
405 int queryPos = 0;
406 q.setLong(queryPos++, ownerId);
407 q.setInteger(queryPos++, ownerType);
408 q.setLong(queryPos++, plid);
409
410 List list = q.list();
411 FinderCache.putResult(finderClassName, finderMethodName,
412 finderParams, finderArgs, list);
413
414 return list;
415 }
416 catch (Exception e) {
417 throw HibernateUtil.processException(e);
418 }
419 finally {
420 closeSession(session);
421 }
422 }
423 else {
424 return (List)result;
425 }
426 }
427
428 public List findByO_O_P(long ownerId, int ownerType, long plid, int begin,
429 int end) throws SystemException {
430 return findByO_O_P(ownerId, ownerType, plid, begin, end, null);
431 }
432
433 public List findByO_O_P(long ownerId, int ownerType, long plid, int begin,
434 int end, OrderByComparator obc) throws SystemException {
435 String finderClassName = PortletPreferences.class.getName();
436 String finderMethodName = "findByO_O_P";
437 String[] finderParams = new String[] {
438 Long.class.getName(), Integer.class.getName(),
439 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
440 "com.liferay.portal.kernel.util.OrderByComparator"
441 };
442 Object[] finderArgs = new Object[] {
443 new Long(ownerId), new Integer(ownerType), new Long(plid),
444 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
445 };
446 Object result = FinderCache.getResult(finderClassName,
447 finderMethodName, finderParams, finderArgs, getSessionFactory());
448
449 if (result == null) {
450 Session session = null;
451
452 try {
453 session = openSession();
454
455 StringMaker query = new StringMaker();
456 query.append(
457 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
458 query.append("ownerId = ?");
459 query.append(" AND ");
460 query.append("ownerType = ?");
461 query.append(" AND ");
462 query.append("plid = ?");
463 query.append(" ");
464
465 if (obc != null) {
466 query.append("ORDER BY ");
467 query.append(obc.getOrderBy());
468 }
469
470 Query q = session.createQuery(query.toString());
471 int queryPos = 0;
472 q.setLong(queryPos++, ownerId);
473 q.setInteger(queryPos++, ownerType);
474 q.setLong(queryPos++, plid);
475
476 List list = QueryUtil.list(q, getDialect(), begin, end);
477 FinderCache.putResult(finderClassName, finderMethodName,
478 finderParams, finderArgs, list);
479
480 return list;
481 }
482 catch (Exception e) {
483 throw HibernateUtil.processException(e);
484 }
485 finally {
486 closeSession(session);
487 }
488 }
489 else {
490 return (List)result;
491 }
492 }
493
494 public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
495 long plid, OrderByComparator obc)
496 throws NoSuchPortletPreferencesException, SystemException {
497 List list = findByO_O_P(ownerId, ownerType, plid, 0, 1, obc);
498
499 if (list.size() == 0) {
500 StringMaker msg = new StringMaker();
501 msg.append("No PortletPreferences exists with the key ");
502 msg.append(StringPool.OPEN_CURLY_BRACE);
503 msg.append("ownerId=");
504 msg.append(ownerId);
505 msg.append(", ");
506 msg.append("ownerType=");
507 msg.append(ownerType);
508 msg.append(", ");
509 msg.append("plid=");
510 msg.append(plid);
511 msg.append(StringPool.CLOSE_CURLY_BRACE);
512 throw new NoSuchPortletPreferencesException(msg.toString());
513 }
514 else {
515 return (PortletPreferences)list.get(0);
516 }
517 }
518
519 public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
520 long plid, OrderByComparator obc)
521 throws NoSuchPortletPreferencesException, SystemException {
522 int count = countByO_O_P(ownerId, ownerType, plid);
523 List list = findByO_O_P(ownerId, ownerType, plid, count - 1, count, obc);
524
525 if (list.size() == 0) {
526 StringMaker msg = new StringMaker();
527 msg.append("No PortletPreferences exists with the key ");
528 msg.append(StringPool.OPEN_CURLY_BRACE);
529 msg.append("ownerId=");
530 msg.append(ownerId);
531 msg.append(", ");
532 msg.append("ownerType=");
533 msg.append(ownerType);
534 msg.append(", ");
535 msg.append("plid=");
536 msg.append(plid);
537 msg.append(StringPool.CLOSE_CURLY_BRACE);
538 throw new NoSuchPortletPreferencesException(msg.toString());
539 }
540 else {
541 return (PortletPreferences)list.get(0);
542 }
543 }
544
545 public PortletPreferences[] findByO_O_P_PrevAndNext(
546 long portletPreferencesId, long ownerId, int ownerType, long plid,
547 OrderByComparator obc)
548 throws NoSuchPortletPreferencesException, SystemException {
549 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
550 int count = countByO_O_P(ownerId, ownerType, plid);
551 Session session = null;
552
553 try {
554 session = openSession();
555
556 StringMaker query = new StringMaker();
557 query.append(
558 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
559 query.append("ownerId = ?");
560 query.append(" AND ");
561 query.append("ownerType = ?");
562 query.append(" AND ");
563 query.append("plid = ?");
564 query.append(" ");
565
566 if (obc != null) {
567 query.append("ORDER BY ");
568 query.append(obc.getOrderBy());
569 }
570
571 Query q = session.createQuery(query.toString());
572 int queryPos = 0;
573 q.setLong(queryPos++, ownerId);
574 q.setInteger(queryPos++, ownerType);
575 q.setLong(queryPos++, plid);
576
577 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
578 portletPreferences);
579 PortletPreferences[] array = new PortletPreferencesImpl[3];
580 array[0] = (PortletPreferences)objArray[0];
581 array[1] = (PortletPreferences)objArray[1];
582 array[2] = (PortletPreferences)objArray[2];
583
584 return array;
585 }
586 catch (Exception e) {
587 throw HibernateUtil.processException(e);
588 }
589 finally {
590 closeSession(session);
591 }
592 }
593
594 public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
595 long plid, String portletId)
596 throws NoSuchPortletPreferencesException, SystemException {
597 PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
598 ownerType, plid, portletId);
599
600 if (portletPreferences == null) {
601 StringMaker msg = new StringMaker();
602 msg.append("No PortletPreferences exists with the key ");
603 msg.append(StringPool.OPEN_CURLY_BRACE);
604 msg.append("ownerId=");
605 msg.append(ownerId);
606 msg.append(", ");
607 msg.append("ownerType=");
608 msg.append(ownerType);
609 msg.append(", ");
610 msg.append("plid=");
611 msg.append(plid);
612 msg.append(", ");
613 msg.append("portletId=");
614 msg.append(portletId);
615 msg.append(StringPool.CLOSE_CURLY_BRACE);
616
617 if (_log.isWarnEnabled()) {
618 _log.warn(msg.toString());
619 }
620
621 throw new NoSuchPortletPreferencesException(msg.toString());
622 }
623
624 return portletPreferences;
625 }
626
627 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
628 long plid, String portletId) throws SystemException {
629 String finderClassName = PortletPreferences.class.getName();
630 String finderMethodName = "fetchByO_O_P_P";
631 String[] finderParams = new String[] {
632 Long.class.getName(), Integer.class.getName(),
633 Long.class.getName(), String.class.getName()
634 };
635 Object[] finderArgs = new Object[] {
636 new Long(ownerId), new Integer(ownerType), new Long(plid),
637 portletId
638 };
639 Object result = FinderCache.getResult(finderClassName,
640 finderMethodName, finderParams, finderArgs, getSessionFactory());
641
642 if (result == null) {
643 Session session = null;
644
645 try {
646 session = openSession();
647
648 StringMaker query = new StringMaker();
649 query.append(
650 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
651 query.append("ownerId = ?");
652 query.append(" AND ");
653 query.append("ownerType = ?");
654 query.append(" AND ");
655 query.append("plid = ?");
656 query.append(" AND ");
657
658 if (portletId == null) {
659 query.append("portletId IS NULL");
660 }
661 else {
662 query.append("portletId = ?");
663 }
664
665 query.append(" ");
666
667 Query q = session.createQuery(query.toString());
668 int queryPos = 0;
669 q.setLong(queryPos++, ownerId);
670 q.setInteger(queryPos++, ownerType);
671 q.setLong(queryPos++, plid);
672
673 if (portletId != null) {
674 q.setString(queryPos++, portletId);
675 }
676
677 List list = q.list();
678 FinderCache.putResult(finderClassName, finderMethodName,
679 finderParams, finderArgs, list);
680
681 if (list.size() == 0) {
682 return null;
683 }
684 else {
685 return (PortletPreferences)list.get(0);
686 }
687 }
688 catch (Exception e) {
689 throw HibernateUtil.processException(e);
690 }
691 finally {
692 closeSession(session);
693 }
694 }
695 else {
696 List list = (List)result;
697
698 if (list.size() == 0) {
699 return null;
700 }
701 else {
702 return (PortletPreferences)list.get(0);
703 }
704 }
705 }
706
707 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
708 throws SystemException {
709 Session session = null;
710
711 try {
712 session = openSession();
713
714 DynamicQuery query = queryInitializer.initialize(session);
715
716 return query.list();
717 }
718 catch (Exception e) {
719 throw HibernateUtil.processException(e);
720 }
721 finally {
722 closeSession(session);
723 }
724 }
725
726 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
727 int begin, int end) throws SystemException {
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 DynamicQuery query = queryInitializer.initialize(session);
734 query.setLimit(begin, end);
735
736 return query.list();
737 }
738 catch (Exception e) {
739 throw HibernateUtil.processException(e);
740 }
741 finally {
742 closeSession(session);
743 }
744 }
745
746 public List findAll() throws SystemException {
747 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
748 }
749
750 public List findAll(int begin, int end) throws SystemException {
751 return findAll(begin, end, null);
752 }
753
754 public List findAll(int begin, int end, OrderByComparator obc)
755 throws SystemException {
756 String finderClassName = PortletPreferences.class.getName();
757 String finderMethodName = "findAll";
758 String[] finderParams = new String[] {
759 "java.lang.Integer", "java.lang.Integer",
760 "com.liferay.portal.kernel.util.OrderByComparator"
761 };
762 Object[] finderArgs = new Object[] {
763 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
764 };
765 Object result = FinderCache.getResult(finderClassName,
766 finderMethodName, finderParams, finderArgs, getSessionFactory());
767
768 if (result == null) {
769 Session session = null;
770
771 try {
772 session = openSession();
773
774 StringMaker query = new StringMaker();
775 query.append(
776 "FROM com.liferay.portal.model.PortletPreferences ");
777
778 if (obc != null) {
779 query.append("ORDER BY ");
780 query.append(obc.getOrderBy());
781 }
782
783 Query q = session.createQuery(query.toString());
784 List list = QueryUtil.list(q, getDialect(), begin, end);
785
786 if (obc == null) {
787 Collections.sort(list);
788 }
789
790 FinderCache.putResult(finderClassName, finderMethodName,
791 finderParams, finderArgs, list);
792
793 return list;
794 }
795 catch (Exception e) {
796 throw HibernateUtil.processException(e);
797 }
798 finally {
799 closeSession(session);
800 }
801 }
802 else {
803 return (List)result;
804 }
805 }
806
807 public void removeByPlid(long plid) throws SystemException {
808 Iterator itr = findByPlid(plid).iterator();
809
810 while (itr.hasNext()) {
811 PortletPreferences portletPreferences = (PortletPreferences)itr.next();
812 remove(portletPreferences);
813 }
814 }
815
816 public void removeByO_O_P(long ownerId, int ownerType, long plid)
817 throws SystemException {
818 Iterator itr = findByO_O_P(ownerId, ownerType, plid).iterator();
819
820 while (itr.hasNext()) {
821 PortletPreferences portletPreferences = (PortletPreferences)itr.next();
822 remove(portletPreferences);
823 }
824 }
825
826 public void removeByO_O_P_P(long ownerId, int ownerType, long plid,
827 String portletId)
828 throws NoSuchPortletPreferencesException, SystemException {
829 PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
830 ownerType, plid, portletId);
831 remove(portletPreferences);
832 }
833
834 public void removeAll() throws SystemException {
835 Iterator itr = findAll().iterator();
836
837 while (itr.hasNext()) {
838 remove((PortletPreferences)itr.next());
839 }
840 }
841
842 public int countByPlid(long plid) throws SystemException {
843 String finderClassName = PortletPreferences.class.getName();
844 String finderMethodName = "countByPlid";
845 String[] finderParams = new String[] { Long.class.getName() };
846 Object[] finderArgs = new Object[] { new Long(plid) };
847 Object result = FinderCache.getResult(finderClassName,
848 finderMethodName, finderParams, finderArgs, getSessionFactory());
849
850 if (result == null) {
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 StringMaker query = new StringMaker();
857 query.append("SELECT COUNT(*) ");
858 query.append(
859 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
860 query.append("plid = ?");
861 query.append(" ");
862
863 Query q = session.createQuery(query.toString());
864 int queryPos = 0;
865 q.setLong(queryPos++, plid);
866
867 Long count = null;
868 Iterator itr = q.list().iterator();
869
870 if (itr.hasNext()) {
871 count = (Long)itr.next();
872 }
873
874 if (count == null) {
875 count = new Long(0);
876 }
877
878 FinderCache.putResult(finderClassName, finderMethodName,
879 finderParams, finderArgs, count);
880
881 return count.intValue();
882 }
883 catch (Exception e) {
884 throw HibernateUtil.processException(e);
885 }
886 finally {
887 closeSession(session);
888 }
889 }
890 else {
891 return ((Long)result).intValue();
892 }
893 }
894
895 public int countByO_O_P(long ownerId, int ownerType, long plid)
896 throws SystemException {
897 String finderClassName = PortletPreferences.class.getName();
898 String finderMethodName = "countByO_O_P";
899 String[] finderParams = new String[] {
900 Long.class.getName(), Integer.class.getName(),
901 Long.class.getName()
902 };
903 Object[] finderArgs = new Object[] {
904 new Long(ownerId), new Integer(ownerType), new Long(plid)
905 };
906 Object result = FinderCache.getResult(finderClassName,
907 finderMethodName, finderParams, finderArgs, getSessionFactory());
908
909 if (result == null) {
910 Session session = null;
911
912 try {
913 session = openSession();
914
915 StringMaker query = new StringMaker();
916 query.append("SELECT COUNT(*) ");
917 query.append(
918 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
919 query.append("ownerId = ?");
920 query.append(" AND ");
921 query.append("ownerType = ?");
922 query.append(" AND ");
923 query.append("plid = ?");
924 query.append(" ");
925
926 Query q = session.createQuery(query.toString());
927 int queryPos = 0;
928 q.setLong(queryPos++, ownerId);
929 q.setInteger(queryPos++, ownerType);
930 q.setLong(queryPos++, plid);
931
932 Long count = null;
933 Iterator itr = q.list().iterator();
934
935 if (itr.hasNext()) {
936 count = (Long)itr.next();
937 }
938
939 if (count == null) {
940 count = new Long(0);
941 }
942
943 FinderCache.putResult(finderClassName, finderMethodName,
944 finderParams, finderArgs, count);
945
946 return count.intValue();
947 }
948 catch (Exception e) {
949 throw HibernateUtil.processException(e);
950 }
951 finally {
952 closeSession(session);
953 }
954 }
955 else {
956 return ((Long)result).intValue();
957 }
958 }
959
960 public int countByO_O_P_P(long ownerId, int ownerType, long plid,
961 String portletId) throws SystemException {
962 String finderClassName = PortletPreferences.class.getName();
963 String finderMethodName = "countByO_O_P_P";
964 String[] finderParams = new String[] {
965 Long.class.getName(), Integer.class.getName(),
966 Long.class.getName(), String.class.getName()
967 };
968 Object[] finderArgs = new Object[] {
969 new Long(ownerId), new Integer(ownerType), new Long(plid),
970 portletId
971 };
972 Object result = FinderCache.getResult(finderClassName,
973 finderMethodName, finderParams, finderArgs, getSessionFactory());
974
975 if (result == null) {
976 Session session = null;
977
978 try {
979 session = openSession();
980
981 StringMaker query = new StringMaker();
982 query.append("SELECT COUNT(*) ");
983 query.append(
984 "FROM com.liferay.portal.model.PortletPreferences WHERE ");
985 query.append("ownerId = ?");
986 query.append(" AND ");
987 query.append("ownerType = ?");
988 query.append(" AND ");
989 query.append("plid = ?");
990 query.append(" AND ");
991
992 if (portletId == null) {
993 query.append("portletId IS NULL");
994 }
995 else {
996 query.append("portletId = ?");
997 }
998
999 query.append(" ");
1000
1001 Query q = session.createQuery(query.toString());
1002 int queryPos = 0;
1003 q.setLong(queryPos++, ownerId);
1004 q.setInteger(queryPos++, ownerType);
1005 q.setLong(queryPos++, plid);
1006
1007 if (portletId != null) {
1008 q.setString(queryPos++, portletId);
1009 }
1010
1011 Long count = null;
1012 Iterator itr = q.list().iterator();
1013
1014 if (itr.hasNext()) {
1015 count = (Long)itr.next();
1016 }
1017
1018 if (count == null) {
1019 count = new Long(0);
1020 }
1021
1022 FinderCache.putResult(finderClassName, finderMethodName,
1023 finderParams, finderArgs, count);
1024
1025 return count.intValue();
1026 }
1027 catch (Exception e) {
1028 throw HibernateUtil.processException(e);
1029 }
1030 finally {
1031 closeSession(session);
1032 }
1033 }
1034 else {
1035 return ((Long)result).intValue();
1036 }
1037 }
1038
1039 public int countAll() throws SystemException {
1040 String finderClassName = PortletPreferences.class.getName();
1041 String finderMethodName = "countAll";
1042 String[] finderParams = new String[] { };
1043 Object[] finderArgs = new Object[] { };
1044 Object result = FinderCache.getResult(finderClassName,
1045 finderMethodName, finderParams, finderArgs, getSessionFactory());
1046
1047 if (result == null) {
1048 Session session = null;
1049
1050 try {
1051 session = openSession();
1052
1053 StringMaker query = new StringMaker();
1054 query.append("SELECT COUNT(*) ");
1055 query.append("FROM com.liferay.portal.model.PortletPreferences");
1056
1057 Query q = session.createQuery(query.toString());
1058 Long count = null;
1059 Iterator itr = q.list().iterator();
1060
1061 if (itr.hasNext()) {
1062 count = (Long)itr.next();
1063 }
1064
1065 if (count == null) {
1066 count = new Long(0);
1067 }
1068
1069 FinderCache.putResult(finderClassName, finderMethodName,
1070 finderParams, finderArgs, count);
1071
1072 return count.intValue();
1073 }
1074 catch (Exception e) {
1075 throw HibernateUtil.processException(e);
1076 }
1077 finally {
1078 closeSession(session);
1079 }
1080 }
1081 else {
1082 return ((Long)result).intValue();
1083 }
1084 }
1085
1086 protected void initDao() {
1087 }
1088
1089 private static Log _log = LogFactory.getLog(PortletPreferencesPersistenceImpl.class);
1090}