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