001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchPortletItemException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.PortletItem;
040 import com.liferay.portal.model.impl.PortletItemImpl;
041 import com.liferay.portal.model.impl.PortletItemModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class PortletItemPersistenceImpl extends BasePersistenceImpl<PortletItem>
063 implements PortletItemPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = PortletItemImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
075 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
078 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
081 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
084 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
086 new String[] {
087 Long.class.getName(), Long.class.getName(),
088
089 Integer.class.getName(), Integer.class.getName(),
090 OrderByComparator.class.getName()
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
093 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
095 new String[] { Long.class.getName(), Long.class.getName() },
096 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
097 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
098 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
099 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
101 new String[] { Long.class.getName(), Long.class.getName() });
102
103
111 public List<PortletItem> findByG_C(long groupId, long classNameId)
112 throws SystemException {
113 return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
114 QueryUtil.ALL_POS, null);
115 }
116
117
131 public List<PortletItem> findByG_C(long groupId, long classNameId,
132 int start, int end) throws SystemException {
133 return findByG_C(groupId, classNameId, start, end, null);
134 }
135
136
151 public List<PortletItem> findByG_C(long groupId, long classNameId,
152 int start, int end, OrderByComparator orderByComparator)
153 throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
162 finderArgs = new Object[] { groupId, classNameId };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
166 finderArgs = new Object[] {
167 groupId, classNameId,
168
169 start, end, orderByComparator
170 };
171 }
172
173 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
174 finderArgs, this);
175
176 if ((list != null) && !list.isEmpty()) {
177 for (PortletItem portletItem : list) {
178 if ((groupId != portletItem.getGroupId()) ||
179 (classNameId != portletItem.getClassNameId())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(4 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(4);
196 }
197
198 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
199
200 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
201
202 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
203
204 if (orderByComparator != null) {
205 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
206 orderByComparator);
207 }
208 else
209 if (pagination) {
210 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
211 }
212
213 String sql = query.toString();
214
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 Query q = session.createQuery(sql);
221
222 QueryPos qPos = QueryPos.getInstance(q);
223
224 qPos.add(groupId);
225
226 qPos.add(classNameId);
227
228 if (!pagination) {
229 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
230 start, end, false);
231
232 Collections.sort(list);
233
234 list = new UnmodifiableList<PortletItem>(list);
235 }
236 else {
237 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
238 start, end);
239 }
240
241 cacheResult(list);
242
243 FinderCacheUtil.putResult(finderPath, finderArgs, list);
244 }
245 catch (Exception e) {
246 FinderCacheUtil.removeResult(finderPath, finderArgs);
247
248 throw processException(e);
249 }
250 finally {
251 closeSession(session);
252 }
253 }
254
255 return list;
256 }
257
258
268 public PortletItem findByG_C_First(long groupId, long classNameId,
269 OrderByComparator orderByComparator)
270 throws NoSuchPortletItemException, SystemException {
271 PortletItem portletItem = fetchByG_C_First(groupId, classNameId,
272 orderByComparator);
273
274 if (portletItem != null) {
275 return portletItem;
276 }
277
278 StringBundler msg = new StringBundler(6);
279
280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
281
282 msg.append("groupId=");
283 msg.append(groupId);
284
285 msg.append(", classNameId=");
286 msg.append(classNameId);
287
288 msg.append(StringPool.CLOSE_CURLY_BRACE);
289
290 throw new NoSuchPortletItemException(msg.toString());
291 }
292
293
302 public PortletItem fetchByG_C_First(long groupId, long classNameId,
303 OrderByComparator orderByComparator) throws SystemException {
304 List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
305 orderByComparator);
306
307 if (!list.isEmpty()) {
308 return list.get(0);
309 }
310
311 return null;
312 }
313
314
324 public PortletItem findByG_C_Last(long groupId, long classNameId,
325 OrderByComparator orderByComparator)
326 throws NoSuchPortletItemException, SystemException {
327 PortletItem portletItem = fetchByG_C_Last(groupId, classNameId,
328 orderByComparator);
329
330 if (portletItem != null) {
331 return portletItem;
332 }
333
334 StringBundler msg = new StringBundler(6);
335
336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337
338 msg.append("groupId=");
339 msg.append(groupId);
340
341 msg.append(", classNameId=");
342 msg.append(classNameId);
343
344 msg.append(StringPool.CLOSE_CURLY_BRACE);
345
346 throw new NoSuchPortletItemException(msg.toString());
347 }
348
349
358 public PortletItem fetchByG_C_Last(long groupId, long classNameId,
359 OrderByComparator orderByComparator) throws SystemException {
360 int count = countByG_C(groupId, classNameId);
361
362 List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
363 count, orderByComparator);
364
365 if (!list.isEmpty()) {
366 return list.get(0);
367 }
368
369 return null;
370 }
371
372
383 public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
384 long groupId, long classNameId, OrderByComparator orderByComparator)
385 throws NoSuchPortletItemException, SystemException {
386 PortletItem portletItem = findByPrimaryKey(portletItemId);
387
388 Session session = null;
389
390 try {
391 session = openSession();
392
393 PortletItem[] array = new PortletItemImpl[3];
394
395 array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
396 classNameId, orderByComparator, true);
397
398 array[1] = portletItem;
399
400 array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
401 classNameId, orderByComparator, false);
402
403 return array;
404 }
405 catch (Exception e) {
406 throw processException(e);
407 }
408 finally {
409 closeSession(session);
410 }
411 }
412
413 protected PortletItem getByG_C_PrevAndNext(Session session,
414 PortletItem portletItem, long groupId, long classNameId,
415 OrderByComparator orderByComparator, boolean previous) {
416 StringBundler query = null;
417
418 if (orderByComparator != null) {
419 query = new StringBundler(6 +
420 (orderByComparator.getOrderByFields().length * 6));
421 }
422 else {
423 query = new StringBundler(3);
424 }
425
426 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
427
428 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
429
430 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
431
432 if (orderByComparator != null) {
433 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
434
435 if (orderByConditionFields.length > 0) {
436 query.append(WHERE_AND);
437 }
438
439 for (int i = 0; i < orderByConditionFields.length; i++) {
440 query.append(_ORDER_BY_ENTITY_ALIAS);
441 query.append(orderByConditionFields[i]);
442
443 if ((i + 1) < orderByConditionFields.length) {
444 if (orderByComparator.isAscending() ^ previous) {
445 query.append(WHERE_GREATER_THAN_HAS_NEXT);
446 }
447 else {
448 query.append(WHERE_LESSER_THAN_HAS_NEXT);
449 }
450 }
451 else {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN);
457 }
458 }
459 }
460
461 query.append(ORDER_BY_CLAUSE);
462
463 String[] orderByFields = orderByComparator.getOrderByFields();
464
465 for (int i = 0; i < orderByFields.length; i++) {
466 query.append(_ORDER_BY_ENTITY_ALIAS);
467 query.append(orderByFields[i]);
468
469 if ((i + 1) < orderByFields.length) {
470 if (orderByComparator.isAscending() ^ previous) {
471 query.append(ORDER_BY_ASC_HAS_NEXT);
472 }
473 else {
474 query.append(ORDER_BY_DESC_HAS_NEXT);
475 }
476 }
477 else {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC);
480 }
481 else {
482 query.append(ORDER_BY_DESC);
483 }
484 }
485 }
486 }
487 else {
488 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
489 }
490
491 String sql = query.toString();
492
493 Query q = session.createQuery(sql);
494
495 q.setFirstResult(0);
496 q.setMaxResults(2);
497
498 QueryPos qPos = QueryPos.getInstance(q);
499
500 qPos.add(groupId);
501
502 qPos.add(classNameId);
503
504 if (orderByComparator != null) {
505 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
506
507 for (Object value : values) {
508 qPos.add(value);
509 }
510 }
511
512 List<PortletItem> list = q.list();
513
514 if (list.size() == 2) {
515 return list.get(1);
516 }
517 else {
518 return null;
519 }
520 }
521
522
529 public void removeByG_C(long groupId, long classNameId)
530 throws SystemException {
531 for (PortletItem portletItem : findByG_C(groupId, classNameId,
532 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
533 remove(portletItem);
534 }
535 }
536
537
545 public int countByG_C(long groupId, long classNameId)
546 throws SystemException {
547 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
548
549 Object[] finderArgs = new Object[] { groupId, classNameId };
550
551 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552 this);
553
554 if (count == null) {
555 StringBundler query = new StringBundler(3);
556
557 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
558
559 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
560
561 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
562
563 String sql = query.toString();
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 Query q = session.createQuery(sql);
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 qPos.add(groupId);
575
576 qPos.add(classNameId);
577
578 count = (Long)q.uniqueResult();
579
580 FinderCacheUtil.putResult(finderPath, finderArgs, count);
581 }
582 catch (Exception e) {
583 FinderCacheUtil.removeResult(finderPath, finderArgs);
584
585 throw processException(e);
586 }
587 finally {
588 closeSession(session);
589 }
590 }
591
592 return count.intValue();
593 }
594
595 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
596 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
597 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
598 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
599 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_C",
600 new String[] {
601 Long.class.getName(), String.class.getName(),
602 Long.class.getName(),
603
604 Integer.class.getName(), Integer.class.getName(),
605 OrderByComparator.class.getName()
606 });
607 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
608 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
609 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_C",
610 new String[] {
611 Long.class.getName(), String.class.getName(),
612 Long.class.getName()
613 },
614 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
615 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
616 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
617 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
618 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
619 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_C",
620 new String[] {
621 Long.class.getName(), String.class.getName(),
622 Long.class.getName()
623 });
624
625
634 public List<PortletItem> findByG_P_C(long groupId, String portletId,
635 long classNameId) throws SystemException {
636 return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
637 QueryUtil.ALL_POS, null);
638 }
639
640
655 public List<PortletItem> findByG_P_C(long groupId, String portletId,
656 long classNameId, int start, int end) throws SystemException {
657 return findByG_P_C(groupId, portletId, classNameId, start, end, null);
658 }
659
660
676 public List<PortletItem> findByG_P_C(long groupId, String portletId,
677 long classNameId, int start, int end,
678 OrderByComparator orderByComparator) throws SystemException {
679 boolean pagination = true;
680 FinderPath finderPath = null;
681 Object[] finderArgs = null;
682
683 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
684 (orderByComparator == null)) {
685 pagination = false;
686 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C;
687 finderArgs = new Object[] { groupId, portletId, classNameId };
688 }
689 else {
690 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C;
691 finderArgs = new Object[] {
692 groupId, portletId, classNameId,
693
694 start, end, orderByComparator
695 };
696 }
697
698 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
699 finderArgs, this);
700
701 if ((list != null) && !list.isEmpty()) {
702 for (PortletItem portletItem : list) {
703 if ((groupId != portletItem.getGroupId()) ||
704 !Validator.equals(portletId, portletItem.getPortletId()) ||
705 (classNameId != portletItem.getClassNameId())) {
706 list = null;
707
708 break;
709 }
710 }
711 }
712
713 if (list == null) {
714 StringBundler query = null;
715
716 if (orderByComparator != null) {
717 query = new StringBundler(5 +
718 (orderByComparator.getOrderByFields().length * 3));
719 }
720 else {
721 query = new StringBundler(5);
722 }
723
724 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
725
726 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
727
728 boolean bindPortletId = false;
729
730 if (portletId == null) {
731 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
732 }
733 else if (portletId.equals(StringPool.BLANK)) {
734 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
735 }
736 else {
737 bindPortletId = true;
738
739 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
740 }
741
742 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
743
744 if (orderByComparator != null) {
745 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
746 orderByComparator);
747 }
748 else
749 if (pagination) {
750 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
751 }
752
753 String sql = query.toString();
754
755 Session session = null;
756
757 try {
758 session = openSession();
759
760 Query q = session.createQuery(sql);
761
762 QueryPos qPos = QueryPos.getInstance(q);
763
764 qPos.add(groupId);
765
766 if (bindPortletId) {
767 qPos.add(portletId);
768 }
769
770 qPos.add(classNameId);
771
772 if (!pagination) {
773 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
774 start, end, false);
775
776 Collections.sort(list);
777
778 list = new UnmodifiableList<PortletItem>(list);
779 }
780 else {
781 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
782 start, end);
783 }
784
785 cacheResult(list);
786
787 FinderCacheUtil.putResult(finderPath, finderArgs, list);
788 }
789 catch (Exception e) {
790 FinderCacheUtil.removeResult(finderPath, finderArgs);
791
792 throw processException(e);
793 }
794 finally {
795 closeSession(session);
796 }
797 }
798
799 return list;
800 }
801
802
813 public PortletItem findByG_P_C_First(long groupId, String portletId,
814 long classNameId, OrderByComparator orderByComparator)
815 throws NoSuchPortletItemException, SystemException {
816 PortletItem portletItem = fetchByG_P_C_First(groupId, portletId,
817 classNameId, orderByComparator);
818
819 if (portletItem != null) {
820 return portletItem;
821 }
822
823 StringBundler msg = new StringBundler(8);
824
825 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826
827 msg.append("groupId=");
828 msg.append(groupId);
829
830 msg.append(", portletId=");
831 msg.append(portletId);
832
833 msg.append(", classNameId=");
834 msg.append(classNameId);
835
836 msg.append(StringPool.CLOSE_CURLY_BRACE);
837
838 throw new NoSuchPortletItemException(msg.toString());
839 }
840
841
851 public PortletItem fetchByG_P_C_First(long groupId, String portletId,
852 long classNameId, OrderByComparator orderByComparator)
853 throws SystemException {
854 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
855 0, 1, orderByComparator);
856
857 if (!list.isEmpty()) {
858 return list.get(0);
859 }
860
861 return null;
862 }
863
864
875 public PortletItem findByG_P_C_Last(long groupId, String portletId,
876 long classNameId, OrderByComparator orderByComparator)
877 throws NoSuchPortletItemException, SystemException {
878 PortletItem portletItem = fetchByG_P_C_Last(groupId, portletId,
879 classNameId, orderByComparator);
880
881 if (portletItem != null) {
882 return portletItem;
883 }
884
885 StringBundler msg = new StringBundler(8);
886
887 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
888
889 msg.append("groupId=");
890 msg.append(groupId);
891
892 msg.append(", portletId=");
893 msg.append(portletId);
894
895 msg.append(", classNameId=");
896 msg.append(classNameId);
897
898 msg.append(StringPool.CLOSE_CURLY_BRACE);
899
900 throw new NoSuchPortletItemException(msg.toString());
901 }
902
903
913 public PortletItem fetchByG_P_C_Last(long groupId, String portletId,
914 long classNameId, OrderByComparator orderByComparator)
915 throws SystemException {
916 int count = countByG_P_C(groupId, portletId, classNameId);
917
918 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
919 count - 1, count, orderByComparator);
920
921 if (!list.isEmpty()) {
922 return list.get(0);
923 }
924
925 return null;
926 }
927
928
940 public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
941 long groupId, String portletId, long classNameId,
942 OrderByComparator orderByComparator)
943 throws NoSuchPortletItemException, SystemException {
944 PortletItem portletItem = findByPrimaryKey(portletItemId);
945
946 Session session = null;
947
948 try {
949 session = openSession();
950
951 PortletItem[] array = new PortletItemImpl[3];
952
953 array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
954 portletId, classNameId, orderByComparator, true);
955
956 array[1] = portletItem;
957
958 array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
959 portletId, classNameId, orderByComparator, false);
960
961 return array;
962 }
963 catch (Exception e) {
964 throw processException(e);
965 }
966 finally {
967 closeSession(session);
968 }
969 }
970
971 protected PortletItem getByG_P_C_PrevAndNext(Session session,
972 PortletItem portletItem, long groupId, String portletId,
973 long classNameId, OrderByComparator orderByComparator, boolean previous) {
974 StringBundler query = null;
975
976 if (orderByComparator != null) {
977 query = new StringBundler(6 +
978 (orderByComparator.getOrderByFields().length * 6));
979 }
980 else {
981 query = new StringBundler(3);
982 }
983
984 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
985
986 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
987
988 boolean bindPortletId = false;
989
990 if (portletId == null) {
991 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
992 }
993 else if (portletId.equals(StringPool.BLANK)) {
994 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
995 }
996 else {
997 bindPortletId = true;
998
999 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1000 }
1001
1002 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1003
1004 if (orderByComparator != null) {
1005 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1006
1007 if (orderByConditionFields.length > 0) {
1008 query.append(WHERE_AND);
1009 }
1010
1011 for (int i = 0; i < orderByConditionFields.length; i++) {
1012 query.append(_ORDER_BY_ENTITY_ALIAS);
1013 query.append(orderByConditionFields[i]);
1014
1015 if ((i + 1) < orderByConditionFields.length) {
1016 if (orderByComparator.isAscending() ^ previous) {
1017 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1018 }
1019 else {
1020 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1021 }
1022 }
1023 else {
1024 if (orderByComparator.isAscending() ^ previous) {
1025 query.append(WHERE_GREATER_THAN);
1026 }
1027 else {
1028 query.append(WHERE_LESSER_THAN);
1029 }
1030 }
1031 }
1032
1033 query.append(ORDER_BY_CLAUSE);
1034
1035 String[] orderByFields = orderByComparator.getOrderByFields();
1036
1037 for (int i = 0; i < orderByFields.length; i++) {
1038 query.append(_ORDER_BY_ENTITY_ALIAS);
1039 query.append(orderByFields[i]);
1040
1041 if ((i + 1) < orderByFields.length) {
1042 if (orderByComparator.isAscending() ^ previous) {
1043 query.append(ORDER_BY_ASC_HAS_NEXT);
1044 }
1045 else {
1046 query.append(ORDER_BY_DESC_HAS_NEXT);
1047 }
1048 }
1049 else {
1050 if (orderByComparator.isAscending() ^ previous) {
1051 query.append(ORDER_BY_ASC);
1052 }
1053 else {
1054 query.append(ORDER_BY_DESC);
1055 }
1056 }
1057 }
1058 }
1059 else {
1060 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
1061 }
1062
1063 String sql = query.toString();
1064
1065 Query q = session.createQuery(sql);
1066
1067 q.setFirstResult(0);
1068 q.setMaxResults(2);
1069
1070 QueryPos qPos = QueryPos.getInstance(q);
1071
1072 qPos.add(groupId);
1073
1074 if (bindPortletId) {
1075 qPos.add(portletId);
1076 }
1077
1078 qPos.add(classNameId);
1079
1080 if (orderByComparator != null) {
1081 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1082
1083 for (Object value : values) {
1084 qPos.add(value);
1085 }
1086 }
1087
1088 List<PortletItem> list = q.list();
1089
1090 if (list.size() == 2) {
1091 return list.get(1);
1092 }
1093 else {
1094 return null;
1095 }
1096 }
1097
1098
1106 public void removeByG_P_C(long groupId, String portletId, long classNameId)
1107 throws SystemException {
1108 for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1109 classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1110 remove(portletItem);
1111 }
1112 }
1113
1114
1123 public int countByG_P_C(long groupId, String portletId, long classNameId)
1124 throws SystemException {
1125 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_C;
1126
1127 Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1128
1129 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1130 this);
1131
1132 if (count == null) {
1133 StringBundler query = new StringBundler(4);
1134
1135 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1136
1137 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1138
1139 boolean bindPortletId = false;
1140
1141 if (portletId == null) {
1142 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1143 }
1144 else if (portletId.equals(StringPool.BLANK)) {
1145 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1146 }
1147 else {
1148 bindPortletId = true;
1149
1150 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1151 }
1152
1153 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1154
1155 String sql = query.toString();
1156
1157 Session session = null;
1158
1159 try {
1160 session = openSession();
1161
1162 Query q = session.createQuery(sql);
1163
1164 QueryPos qPos = QueryPos.getInstance(q);
1165
1166 qPos.add(groupId);
1167
1168 if (bindPortletId) {
1169 qPos.add(portletId);
1170 }
1171
1172 qPos.add(classNameId);
1173
1174 count = (Long)q.uniqueResult();
1175
1176 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1177 }
1178 catch (Exception e) {
1179 FinderCacheUtil.removeResult(finderPath, finderArgs);
1180
1181 throw processException(e);
1182 }
1183 finally {
1184 closeSession(session);
1185 }
1186 }
1187
1188 return count.intValue();
1189 }
1190
1191 private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1192 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1193 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1194 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = '') AND ";
1195 private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1196 public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1197 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
1198 FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
1199 new String[] {
1200 Long.class.getName(), String.class.getName(),
1201 String.class.getName(), Long.class.getName()
1202 },
1203 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
1204 PortletItemModelImpl.NAME_COLUMN_BITMASK |
1205 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
1206 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1207 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1208 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
1209 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_P_C",
1210 new String[] {
1211 Long.class.getName(), String.class.getName(),
1212 String.class.getName(), Long.class.getName()
1213 });
1214
1215
1226 public PortletItem findByG_N_P_C(long groupId, String name,
1227 String portletId, long classNameId)
1228 throws NoSuchPortletItemException, SystemException {
1229 PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1230 classNameId);
1231
1232 if (portletItem == null) {
1233 StringBundler msg = new StringBundler(10);
1234
1235 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1236
1237 msg.append("groupId=");
1238 msg.append(groupId);
1239
1240 msg.append(", name=");
1241 msg.append(name);
1242
1243 msg.append(", portletId=");
1244 msg.append(portletId);
1245
1246 msg.append(", classNameId=");
1247 msg.append(classNameId);
1248
1249 msg.append(StringPool.CLOSE_CURLY_BRACE);
1250
1251 if (_log.isWarnEnabled()) {
1252 _log.warn(msg.toString());
1253 }
1254
1255 throw new NoSuchPortletItemException(msg.toString());
1256 }
1257
1258 return portletItem;
1259 }
1260
1261
1271 public PortletItem fetchByG_N_P_C(long groupId, String name,
1272 String portletId, long classNameId) throws SystemException {
1273 return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1274 }
1275
1276
1287 public PortletItem fetchByG_N_P_C(long groupId, String name,
1288 String portletId, long classNameId, boolean retrieveFromCache)
1289 throws SystemException {
1290 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1291
1292 Object result = null;
1293
1294 if (retrieveFromCache) {
1295 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1296 finderArgs, this);
1297 }
1298
1299 if (result instanceof PortletItem) {
1300 PortletItem portletItem = (PortletItem)result;
1301
1302 if ((groupId != portletItem.getGroupId()) ||
1303 !Validator.equals(name, portletItem.getName()) ||
1304 !Validator.equals(portletId, portletItem.getPortletId()) ||
1305 (classNameId != portletItem.getClassNameId())) {
1306 result = null;
1307 }
1308 }
1309
1310 if (result == null) {
1311 StringBundler query = new StringBundler(6);
1312
1313 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1314
1315 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1316
1317 boolean bindName = false;
1318
1319 if (name == null) {
1320 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1321 }
1322 else if (name.equals(StringPool.BLANK)) {
1323 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1324 }
1325 else {
1326 bindName = true;
1327
1328 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1329 }
1330
1331 boolean bindPortletId = false;
1332
1333 if (portletId == null) {
1334 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1335 }
1336 else if (portletId.equals(StringPool.BLANK)) {
1337 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1338 }
1339 else {
1340 bindPortletId = true;
1341
1342 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1343 }
1344
1345 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1346
1347 String sql = query.toString();
1348
1349 Session session = null;
1350
1351 try {
1352 session = openSession();
1353
1354 Query q = session.createQuery(sql);
1355
1356 QueryPos qPos = QueryPos.getInstance(q);
1357
1358 qPos.add(groupId);
1359
1360 if (bindName) {
1361 qPos.add(name.toLowerCase());
1362 }
1363
1364 if (bindPortletId) {
1365 qPos.add(portletId);
1366 }
1367
1368 qPos.add(classNameId);
1369
1370 List<PortletItem> list = q.list();
1371
1372 if (list.isEmpty()) {
1373 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1374 finderArgs, list);
1375 }
1376 else {
1377 if ((list.size() > 1) && _log.isWarnEnabled()) {
1378 _log.warn(
1379 "PortletItemPersistenceImpl.fetchByG_N_P_C(long, String, String, long, boolean) with parameters (" +
1380 StringUtil.merge(finderArgs) +
1381 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1382 }
1383
1384 PortletItem portletItem = list.get(0);
1385
1386 result = portletItem;
1387
1388 cacheResult(portletItem);
1389
1390 if ((portletItem.getGroupId() != groupId) ||
1391 (portletItem.getName() == null) ||
1392 !portletItem.getName().equals(name) ||
1393 (portletItem.getPortletId() == null) ||
1394 !portletItem.getPortletId().equals(portletId) ||
1395 (portletItem.getClassNameId() != classNameId)) {
1396 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1397 finderArgs, portletItem);
1398 }
1399 }
1400 }
1401 catch (Exception e) {
1402 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1403 finderArgs);
1404
1405 throw processException(e);
1406 }
1407 finally {
1408 closeSession(session);
1409 }
1410 }
1411
1412 if (result instanceof List<?>) {
1413 return null;
1414 }
1415 else {
1416 return (PortletItem)result;
1417 }
1418 }
1419
1420
1430 public PortletItem removeByG_N_P_C(long groupId, String name,
1431 String portletId, long classNameId)
1432 throws NoSuchPortletItemException, SystemException {
1433 PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1434 classNameId);
1435
1436 return remove(portletItem);
1437 }
1438
1439
1449 public int countByG_N_P_C(long groupId, String name, String portletId,
1450 long classNameId) throws SystemException {
1451 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_P_C;
1452
1453 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1454
1455 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1456 this);
1457
1458 if (count == null) {
1459 StringBundler query = new StringBundler(5);
1460
1461 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1462
1463 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1464
1465 boolean bindName = false;
1466
1467 if (name == null) {
1468 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1469 }
1470 else if (name.equals(StringPool.BLANK)) {
1471 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1472 }
1473 else {
1474 bindName = true;
1475
1476 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1477 }
1478
1479 boolean bindPortletId = false;
1480
1481 if (portletId == null) {
1482 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1483 }
1484 else if (portletId.equals(StringPool.BLANK)) {
1485 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1486 }
1487 else {
1488 bindPortletId = true;
1489
1490 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1491 }
1492
1493 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1494
1495 String sql = query.toString();
1496
1497 Session session = null;
1498
1499 try {
1500 session = openSession();
1501
1502 Query q = session.createQuery(sql);
1503
1504 QueryPos qPos = QueryPos.getInstance(q);
1505
1506 qPos.add(groupId);
1507
1508 if (bindName) {
1509 qPos.add(name.toLowerCase());
1510 }
1511
1512 if (bindPortletId) {
1513 qPos.add(portletId);
1514 }
1515
1516 qPos.add(classNameId);
1517
1518 count = (Long)q.uniqueResult();
1519
1520 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1521 }
1522 catch (Exception e) {
1523 FinderCacheUtil.removeResult(finderPath, finderArgs);
1524
1525 throw processException(e);
1526 }
1527 finally {
1528 closeSession(session);
1529 }
1530 }
1531
1532 return count.intValue();
1533 }
1534
1535 private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1536 private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
1537 private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = ? AND ";
1538 private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR portletItem.name = '') AND ";
1539 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1540 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1541 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = '') AND ";
1542 private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1543
1544
1549 public void cacheResult(PortletItem portletItem) {
1550 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1551 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
1552
1553 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1554 new Object[] {
1555 portletItem.getGroupId(), portletItem.getName(),
1556 portletItem.getPortletId(), portletItem.getClassNameId()
1557 }, portletItem);
1558
1559 portletItem.resetOriginalValues();
1560 }
1561
1562
1567 public void cacheResult(List<PortletItem> portletItems) {
1568 for (PortletItem portletItem : portletItems) {
1569 if (EntityCacheUtil.getResult(
1570 PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1571 PortletItemImpl.class, portletItem.getPrimaryKey()) == null) {
1572 cacheResult(portletItem);
1573 }
1574 else {
1575 portletItem.resetOriginalValues();
1576 }
1577 }
1578 }
1579
1580
1587 @Override
1588 public void clearCache() {
1589 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1590 CacheRegistryUtil.clear(PortletItemImpl.class.getName());
1591 }
1592
1593 EntityCacheUtil.clearCache(PortletItemImpl.class.getName());
1594
1595 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1596 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1597 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1598 }
1599
1600
1607 @Override
1608 public void clearCache(PortletItem portletItem) {
1609 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1610 PortletItemImpl.class, portletItem.getPrimaryKey());
1611
1612 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1613 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1614
1615 clearUniqueFindersCache(portletItem);
1616 }
1617
1618 @Override
1619 public void clearCache(List<PortletItem> portletItems) {
1620 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1621 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1622
1623 for (PortletItem portletItem : portletItems) {
1624 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1625 PortletItemImpl.class, portletItem.getPrimaryKey());
1626
1627 clearUniqueFindersCache(portletItem);
1628 }
1629 }
1630
1631 protected void cacheUniqueFindersCache(PortletItem portletItem) {
1632 if (portletItem.isNew()) {
1633 Object[] args = new Object[] {
1634 portletItem.getGroupId(), portletItem.getName(),
1635 portletItem.getPortletId(), portletItem.getClassNameId()
1636 };
1637
1638 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
1639 Long.valueOf(1));
1640 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
1641 portletItem);
1642 }
1643 else {
1644 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1645
1646 if ((portletItemModelImpl.getColumnBitmask() &
1647 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
1648 Object[] args = new Object[] {
1649 portletItem.getGroupId(), portletItem.getName(),
1650 portletItem.getPortletId(), portletItem.getClassNameId()
1651 };
1652
1653 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
1654 Long.valueOf(1));
1655 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
1656 portletItem);
1657 }
1658 }
1659 }
1660
1661 protected void clearUniqueFindersCache(PortletItem portletItem) {
1662 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1663
1664 Object[] args = new Object[] {
1665 portletItem.getGroupId(), portletItem.getName(),
1666 portletItem.getPortletId(), portletItem.getClassNameId()
1667 };
1668
1669 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
1670 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
1671
1672 if ((portletItemModelImpl.getColumnBitmask() &
1673 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
1674 args = new Object[] {
1675 portletItemModelImpl.getOriginalGroupId(),
1676 portletItemModelImpl.getOriginalName(),
1677 portletItemModelImpl.getOriginalPortletId(),
1678 portletItemModelImpl.getOriginalClassNameId()
1679 };
1680
1681 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
1682 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
1683 }
1684 }
1685
1686
1692 public PortletItem create(long portletItemId) {
1693 PortletItem portletItem = new PortletItemImpl();
1694
1695 portletItem.setNew(true);
1696 portletItem.setPrimaryKey(portletItemId);
1697
1698 return portletItem;
1699 }
1700
1701
1709 public PortletItem remove(long portletItemId)
1710 throws NoSuchPortletItemException, SystemException {
1711 return remove((Serializable)portletItemId);
1712 }
1713
1714
1722 @Override
1723 public PortletItem remove(Serializable primaryKey)
1724 throws NoSuchPortletItemException, SystemException {
1725 Session session = null;
1726
1727 try {
1728 session = openSession();
1729
1730 PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
1731 primaryKey);
1732
1733 if (portletItem == null) {
1734 if (_log.isWarnEnabled()) {
1735 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1736 }
1737
1738 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1739 primaryKey);
1740 }
1741
1742 return remove(portletItem);
1743 }
1744 catch (NoSuchPortletItemException nsee) {
1745 throw nsee;
1746 }
1747 catch (Exception e) {
1748 throw processException(e);
1749 }
1750 finally {
1751 closeSession(session);
1752 }
1753 }
1754
1755 @Override
1756 protected PortletItem removeImpl(PortletItem portletItem)
1757 throws SystemException {
1758 portletItem = toUnwrappedModel(portletItem);
1759
1760 Session session = null;
1761
1762 try {
1763 session = openSession();
1764
1765 if (!session.contains(portletItem)) {
1766 portletItem = (PortletItem)session.get(PortletItemImpl.class,
1767 portletItem.getPrimaryKeyObj());
1768 }
1769
1770 if (portletItem != null) {
1771 session.delete(portletItem);
1772 }
1773 }
1774 catch (Exception e) {
1775 throw processException(e);
1776 }
1777 finally {
1778 closeSession(session);
1779 }
1780
1781 if (portletItem != null) {
1782 clearCache(portletItem);
1783 }
1784
1785 return portletItem;
1786 }
1787
1788 @Override
1789 public PortletItem updateImpl(
1790 com.liferay.portal.model.PortletItem portletItem)
1791 throws SystemException {
1792 portletItem = toUnwrappedModel(portletItem);
1793
1794 boolean isNew = portletItem.isNew();
1795
1796 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1797
1798 Session session = null;
1799
1800 try {
1801 session = openSession();
1802
1803 if (portletItem.isNew()) {
1804 session.save(portletItem);
1805
1806 portletItem.setNew(false);
1807 }
1808 else {
1809 session.merge(portletItem);
1810 }
1811 }
1812 catch (Exception e) {
1813 throw processException(e);
1814 }
1815 finally {
1816 closeSession(session);
1817 }
1818
1819 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1820
1821 if (isNew || !PortletItemModelImpl.COLUMN_BITMASK_ENABLED) {
1822 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1823 }
1824
1825 else {
1826 if ((portletItemModelImpl.getColumnBitmask() &
1827 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1828 Object[] args = new Object[] {
1829 portletItemModelImpl.getOriginalGroupId(),
1830 portletItemModelImpl.getOriginalClassNameId()
1831 };
1832
1833 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1834 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1835 args);
1836
1837 args = new Object[] {
1838 portletItemModelImpl.getGroupId(),
1839 portletItemModelImpl.getClassNameId()
1840 };
1841
1842 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1843 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1844 args);
1845 }
1846
1847 if ((portletItemModelImpl.getColumnBitmask() &
1848 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C.getColumnBitmask()) != 0) {
1849 Object[] args = new Object[] {
1850 portletItemModelImpl.getOriginalGroupId(),
1851 portletItemModelImpl.getOriginalPortletId(),
1852 portletItemModelImpl.getOriginalClassNameId()
1853 };
1854
1855 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
1856 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
1857 args);
1858
1859 args = new Object[] {
1860 portletItemModelImpl.getGroupId(),
1861 portletItemModelImpl.getPortletId(),
1862 portletItemModelImpl.getClassNameId()
1863 };
1864
1865 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
1866 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
1867 args);
1868 }
1869 }
1870
1871 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1872 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
1873
1874 clearUniqueFindersCache(portletItem);
1875 cacheUniqueFindersCache(portletItem);
1876
1877 return portletItem;
1878 }
1879
1880 protected PortletItem toUnwrappedModel(PortletItem portletItem) {
1881 if (portletItem instanceof PortletItemImpl) {
1882 return portletItem;
1883 }
1884
1885 PortletItemImpl portletItemImpl = new PortletItemImpl();
1886
1887 portletItemImpl.setNew(portletItem.isNew());
1888 portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
1889
1890 portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
1891 portletItemImpl.setGroupId(portletItem.getGroupId());
1892 portletItemImpl.setCompanyId(portletItem.getCompanyId());
1893 portletItemImpl.setUserId(portletItem.getUserId());
1894 portletItemImpl.setUserName(portletItem.getUserName());
1895 portletItemImpl.setCreateDate(portletItem.getCreateDate());
1896 portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
1897 portletItemImpl.setName(portletItem.getName());
1898 portletItemImpl.setPortletId(portletItem.getPortletId());
1899 portletItemImpl.setClassNameId(portletItem.getClassNameId());
1900
1901 return portletItemImpl;
1902 }
1903
1904
1912 @Override
1913 public PortletItem findByPrimaryKey(Serializable primaryKey)
1914 throws NoSuchPortletItemException, SystemException {
1915 PortletItem portletItem = fetchByPrimaryKey(primaryKey);
1916
1917 if (portletItem == null) {
1918 if (_log.isWarnEnabled()) {
1919 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1920 }
1921
1922 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1923 primaryKey);
1924 }
1925
1926 return portletItem;
1927 }
1928
1929
1937 public PortletItem findByPrimaryKey(long portletItemId)
1938 throws NoSuchPortletItemException, SystemException {
1939 return findByPrimaryKey((Serializable)portletItemId);
1940 }
1941
1942
1949 @Override
1950 public PortletItem fetchByPrimaryKey(Serializable primaryKey)
1951 throws SystemException {
1952 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1953 PortletItemImpl.class, primaryKey);
1954
1955 if (portletItem == _nullPortletItem) {
1956 return null;
1957 }
1958
1959 if (portletItem == null) {
1960 Session session = null;
1961
1962 try {
1963 session = openSession();
1964
1965 portletItem = (PortletItem)session.get(PortletItemImpl.class,
1966 primaryKey);
1967
1968 if (portletItem != null) {
1969 cacheResult(portletItem);
1970 }
1971 else {
1972 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1973 PortletItemImpl.class, primaryKey, _nullPortletItem);
1974 }
1975 }
1976 catch (Exception e) {
1977 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1978 PortletItemImpl.class, primaryKey);
1979
1980 throw processException(e);
1981 }
1982 finally {
1983 closeSession(session);
1984 }
1985 }
1986
1987 return portletItem;
1988 }
1989
1990
1997 public PortletItem fetchByPrimaryKey(long portletItemId)
1998 throws SystemException {
1999 return fetchByPrimaryKey((Serializable)portletItemId);
2000 }
2001
2002
2008 public List<PortletItem> findAll() throws SystemException {
2009 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2010 }
2011
2012
2024 public List<PortletItem> findAll(int start, int end)
2025 throws SystemException {
2026 return findAll(start, end, null);
2027 }
2028
2029
2042 public List<PortletItem> findAll(int start, int end,
2043 OrderByComparator orderByComparator) throws SystemException {
2044 boolean pagination = true;
2045 FinderPath finderPath = null;
2046 Object[] finderArgs = null;
2047
2048 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2049 (orderByComparator == null)) {
2050 pagination = false;
2051 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2052 finderArgs = FINDER_ARGS_EMPTY;
2053 }
2054 else {
2055 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2056 finderArgs = new Object[] { start, end, orderByComparator };
2057 }
2058
2059 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
2060 finderArgs, this);
2061
2062 if (list == null) {
2063 StringBundler query = null;
2064 String sql = null;
2065
2066 if (orderByComparator != null) {
2067 query = new StringBundler(2 +
2068 (orderByComparator.getOrderByFields().length * 3));
2069
2070 query.append(_SQL_SELECT_PORTLETITEM);
2071
2072 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2073 orderByComparator);
2074
2075 sql = query.toString();
2076 }
2077 else {
2078 sql = _SQL_SELECT_PORTLETITEM;
2079
2080 if (pagination) {
2081 sql = sql.concat(PortletItemModelImpl.ORDER_BY_JPQL);
2082 }
2083 }
2084
2085 Session session = null;
2086
2087 try {
2088 session = openSession();
2089
2090 Query q = session.createQuery(sql);
2091
2092 if (!pagination) {
2093 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
2094 start, end, false);
2095
2096 Collections.sort(list);
2097
2098 list = new UnmodifiableList<PortletItem>(list);
2099 }
2100 else {
2101 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
2102 start, end);
2103 }
2104
2105 cacheResult(list);
2106
2107 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2108 }
2109 catch (Exception e) {
2110 FinderCacheUtil.removeResult(finderPath, finderArgs);
2111
2112 throw processException(e);
2113 }
2114 finally {
2115 closeSession(session);
2116 }
2117 }
2118
2119 return list;
2120 }
2121
2122
2127 public void removeAll() throws SystemException {
2128 for (PortletItem portletItem : findAll()) {
2129 remove(portletItem);
2130 }
2131 }
2132
2133
2139 public int countAll() throws SystemException {
2140 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2141 FINDER_ARGS_EMPTY, this);
2142
2143 if (count == null) {
2144 Session session = null;
2145
2146 try {
2147 session = openSession();
2148
2149 Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
2150
2151 count = (Long)q.uniqueResult();
2152
2153 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2154 FINDER_ARGS_EMPTY, count);
2155 }
2156 catch (Exception e) {
2157 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2158 FINDER_ARGS_EMPTY);
2159
2160 throw processException(e);
2161 }
2162 finally {
2163 closeSession(session);
2164 }
2165 }
2166
2167 return count.intValue();
2168 }
2169
2170
2173 public void afterPropertiesSet() {
2174 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2175 com.liferay.portal.util.PropsUtil.get(
2176 "value.object.listener.com.liferay.portal.model.PortletItem")));
2177
2178 if (listenerClassNames.length > 0) {
2179 try {
2180 List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
2181
2182 for (String listenerClassName : listenerClassNames) {
2183 listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
2184 listenerClassName));
2185 }
2186
2187 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2188 }
2189 catch (Exception e) {
2190 _log.error(e);
2191 }
2192 }
2193 }
2194
2195 public void destroy() {
2196 EntityCacheUtil.removeCache(PortletItemImpl.class.getName());
2197 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2198 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2199 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2200 }
2201
2202 private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
2203 private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
2204 private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
2205 private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
2206 private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
2207 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
2208 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
2209 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2210 private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
2211 private static PortletItem _nullPortletItem = new PortletItemImpl() {
2212 @Override
2213 public Object clone() {
2214 return this;
2215 }
2216
2217 @Override
2218 public CacheModel<PortletItem> toCacheModel() {
2219 return _nullPortletItemCacheModel;
2220 }
2221 };
2222
2223 private static CacheModel<PortletItem> _nullPortletItemCacheModel = new CacheModel<PortletItem>() {
2224 public PortletItem toEntityModel() {
2225 return _nullPortletItem;
2226 }
2227 };
2228 }