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