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 @Override
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 @Override
133 public List<PortletItem> findByG_C(long groupId, long classNameId,
134 int start, int end) throws SystemException {
135 return findByG_C(groupId, classNameId, start, end, null);
136 }
137
138
153 @Override
154 public List<PortletItem> findByG_C(long groupId, long classNameId,
155 int start, int end, OrderByComparator orderByComparator)
156 throws SystemException {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
165 finderArgs = new Object[] { groupId, classNameId };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
169 finderArgs = new Object[] {
170 groupId, classNameId,
171
172 start, end, orderByComparator
173 };
174 }
175
176 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (PortletItem portletItem : list) {
181 if ((groupId != portletItem.getGroupId()) ||
182 (classNameId != portletItem.getClassNameId())) {
183 list = null;
184
185 break;
186 }
187 }
188 }
189
190 if (list == null) {
191 StringBundler query = null;
192
193 if (orderByComparator != null) {
194 query = new StringBundler(4 +
195 (orderByComparator.getOrderByFields().length * 3));
196 }
197 else {
198 query = new StringBundler(4);
199 }
200
201 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
202
203 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
204
205 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
206
207 if (orderByComparator != null) {
208 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209 orderByComparator);
210 }
211 else
212 if (pagination) {
213 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
214 }
215
216 String sql = query.toString();
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 Query q = session.createQuery(sql);
224
225 QueryPos qPos = QueryPos.getInstance(q);
226
227 qPos.add(groupId);
228
229 qPos.add(classNameId);
230
231 if (!pagination) {
232 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
233 start, end, false);
234
235 Collections.sort(list);
236
237 list = new UnmodifiableList<PortletItem>(list);
238 }
239 else {
240 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
241 start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
271 @Override
272 public PortletItem findByG_C_First(long groupId, long classNameId,
273 OrderByComparator orderByComparator)
274 throws NoSuchPortletItemException, SystemException {
275 PortletItem portletItem = fetchByG_C_First(groupId, classNameId,
276 orderByComparator);
277
278 if (portletItem != null) {
279 return portletItem;
280 }
281
282 StringBundler msg = new StringBundler(6);
283
284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285
286 msg.append("groupId=");
287 msg.append(groupId);
288
289 msg.append(", classNameId=");
290 msg.append(classNameId);
291
292 msg.append(StringPool.CLOSE_CURLY_BRACE);
293
294 throw new NoSuchPortletItemException(msg.toString());
295 }
296
297
306 @Override
307 public PortletItem fetchByG_C_First(long groupId, long classNameId,
308 OrderByComparator orderByComparator) throws SystemException {
309 List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
310 orderByComparator);
311
312 if (!list.isEmpty()) {
313 return list.get(0);
314 }
315
316 return null;
317 }
318
319
329 @Override
330 public PortletItem findByG_C_Last(long groupId, long classNameId,
331 OrderByComparator orderByComparator)
332 throws NoSuchPortletItemException, SystemException {
333 PortletItem portletItem = fetchByG_C_Last(groupId, classNameId,
334 orderByComparator);
335
336 if (portletItem != null) {
337 return portletItem;
338 }
339
340 StringBundler msg = new StringBundler(6);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("groupId=");
345 msg.append(groupId);
346
347 msg.append(", classNameId=");
348 msg.append(classNameId);
349
350 msg.append(StringPool.CLOSE_CURLY_BRACE);
351
352 throw new NoSuchPortletItemException(msg.toString());
353 }
354
355
364 @Override
365 public PortletItem fetchByG_C_Last(long groupId, long classNameId,
366 OrderByComparator orderByComparator) throws SystemException {
367 int count = countByG_C(groupId, classNameId);
368
369 if (count == 0) {
370 return null;
371 }
372
373 List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
374 count, orderByComparator);
375
376 if (!list.isEmpty()) {
377 return list.get(0);
378 }
379
380 return null;
381 }
382
383
394 @Override
395 public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
396 long groupId, long classNameId, OrderByComparator orderByComparator)
397 throws NoSuchPortletItemException, SystemException {
398 PortletItem portletItem = findByPrimaryKey(portletItemId);
399
400 Session session = null;
401
402 try {
403 session = openSession();
404
405 PortletItem[] array = new PortletItemImpl[3];
406
407 array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
408 classNameId, orderByComparator, true);
409
410 array[1] = portletItem;
411
412 array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
413 classNameId, orderByComparator, false);
414
415 return array;
416 }
417 catch (Exception e) {
418 throw processException(e);
419 }
420 finally {
421 closeSession(session);
422 }
423 }
424
425 protected PortletItem getByG_C_PrevAndNext(Session session,
426 PortletItem portletItem, long groupId, long classNameId,
427 OrderByComparator orderByComparator, boolean previous) {
428 StringBundler query = null;
429
430 if (orderByComparator != null) {
431 query = new StringBundler(6 +
432 (orderByComparator.getOrderByFields().length * 6));
433 }
434 else {
435 query = new StringBundler(3);
436 }
437
438 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
439
440 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
441
442 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
443
444 if (orderByComparator != null) {
445 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446
447 if (orderByConditionFields.length > 0) {
448 query.append(WHERE_AND);
449 }
450
451 for (int i = 0; i < orderByConditionFields.length; i++) {
452 query.append(_ORDER_BY_ENTITY_ALIAS);
453 query.append(orderByConditionFields[i]);
454
455 if ((i + 1) < orderByConditionFields.length) {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN_HAS_NEXT);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN_HAS_NEXT);
461 }
462 }
463 else {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN);
469 }
470 }
471 }
472
473 query.append(ORDER_BY_CLAUSE);
474
475 String[] orderByFields = orderByComparator.getOrderByFields();
476
477 for (int i = 0; i < orderByFields.length; i++) {
478 query.append(_ORDER_BY_ENTITY_ALIAS);
479 query.append(orderByFields[i]);
480
481 if ((i + 1) < orderByFields.length) {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC_HAS_NEXT);
484 }
485 else {
486 query.append(ORDER_BY_DESC_HAS_NEXT);
487 }
488 }
489 else {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC);
492 }
493 else {
494 query.append(ORDER_BY_DESC);
495 }
496 }
497 }
498 }
499 else {
500 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
501 }
502
503 String sql = query.toString();
504
505 Query q = session.createQuery(sql);
506
507 q.setFirstResult(0);
508 q.setMaxResults(2);
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 qPos.add(groupId);
513
514 qPos.add(classNameId);
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<PortletItem> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
541 @Override
542 public void removeByG_C(long groupId, long classNameId)
543 throws SystemException {
544 for (PortletItem portletItem : findByG_C(groupId, classNameId,
545 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
546 remove(portletItem);
547 }
548 }
549
550
558 @Override
559 public int countByG_C(long groupId, long classNameId)
560 throws SystemException {
561 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
562
563 Object[] finderArgs = new Object[] { groupId, classNameId };
564
565 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
566 this);
567
568 if (count == null) {
569 StringBundler query = new StringBundler(3);
570
571 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
572
573 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
574
575 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
576
577 String sql = query.toString();
578
579 Session session = null;
580
581 try {
582 session = openSession();
583
584 Query q = session.createQuery(sql);
585
586 QueryPos qPos = QueryPos.getInstance(q);
587
588 qPos.add(groupId);
589
590 qPos.add(classNameId);
591
592 count = (Long)q.uniqueResult();
593
594 FinderCacheUtil.putResult(finderPath, finderArgs, count);
595 }
596 catch (Exception e) {
597 FinderCacheUtil.removeResult(finderPath, finderArgs);
598
599 throw processException(e);
600 }
601 finally {
602 closeSession(session);
603 }
604 }
605
606 return count.intValue();
607 }
608
609 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
610 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
611 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
612 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
613 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_C",
614 new String[] {
615 Long.class.getName(), String.class.getName(),
616 Long.class.getName(),
617
618 Integer.class.getName(), Integer.class.getName(),
619 OrderByComparator.class.getName()
620 });
621 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
622 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_C",
624 new String[] {
625 Long.class.getName(), String.class.getName(),
626 Long.class.getName()
627 },
628 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
629 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
630 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
631 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
632 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
633 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_C",
634 new String[] {
635 Long.class.getName(), String.class.getName(),
636 Long.class.getName()
637 });
638
639
648 @Override
649 public List<PortletItem> findByG_P_C(long groupId, String portletId,
650 long classNameId) throws SystemException {
651 return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
652 QueryUtil.ALL_POS, null);
653 }
654
655
670 @Override
671 public List<PortletItem> findByG_P_C(long groupId, String portletId,
672 long classNameId, int start, int end) throws SystemException {
673 return findByG_P_C(groupId, portletId, classNameId, start, end, null);
674 }
675
676
692 @Override
693 public List<PortletItem> findByG_P_C(long groupId, String portletId,
694 long classNameId, int start, int end,
695 OrderByComparator orderByComparator) throws SystemException {
696 boolean pagination = true;
697 FinderPath finderPath = null;
698 Object[] finderArgs = null;
699
700 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
701 (orderByComparator == null)) {
702 pagination = false;
703 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C;
704 finderArgs = new Object[] { groupId, portletId, classNameId };
705 }
706 else {
707 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C;
708 finderArgs = new Object[] {
709 groupId, portletId, classNameId,
710
711 start, end, orderByComparator
712 };
713 }
714
715 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
716 finderArgs, this);
717
718 if ((list != null) && !list.isEmpty()) {
719 for (PortletItem portletItem : list) {
720 if ((groupId != portletItem.getGroupId()) ||
721 !Validator.equals(portletId, portletItem.getPortletId()) ||
722 (classNameId != portletItem.getClassNameId())) {
723 list = null;
724
725 break;
726 }
727 }
728 }
729
730 if (list == null) {
731 StringBundler query = null;
732
733 if (orderByComparator != null) {
734 query = new StringBundler(5 +
735 (orderByComparator.getOrderByFields().length * 3));
736 }
737 else {
738 query = new StringBundler(5);
739 }
740
741 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
742
743 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
744
745 boolean bindPortletId = false;
746
747 if (portletId == null) {
748 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
749 }
750 else if (portletId.equals(StringPool.BLANK)) {
751 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
752 }
753 else {
754 bindPortletId = true;
755
756 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
757 }
758
759 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
760
761 if (orderByComparator != null) {
762 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
763 orderByComparator);
764 }
765 else
766 if (pagination) {
767 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
768 }
769
770 String sql = query.toString();
771
772 Session session = null;
773
774 try {
775 session = openSession();
776
777 Query q = session.createQuery(sql);
778
779 QueryPos qPos = QueryPos.getInstance(q);
780
781 qPos.add(groupId);
782
783 if (bindPortletId) {
784 qPos.add(portletId);
785 }
786
787 qPos.add(classNameId);
788
789 if (!pagination) {
790 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
791 start, end, false);
792
793 Collections.sort(list);
794
795 list = new UnmodifiableList<PortletItem>(list);
796 }
797 else {
798 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
799 start, end);
800 }
801
802 cacheResult(list);
803
804 FinderCacheUtil.putResult(finderPath, finderArgs, list);
805 }
806 catch (Exception e) {
807 FinderCacheUtil.removeResult(finderPath, finderArgs);
808
809 throw processException(e);
810 }
811 finally {
812 closeSession(session);
813 }
814 }
815
816 return list;
817 }
818
819
830 @Override
831 public PortletItem findByG_P_C_First(long groupId, String portletId,
832 long classNameId, OrderByComparator orderByComparator)
833 throws NoSuchPortletItemException, SystemException {
834 PortletItem portletItem = fetchByG_P_C_First(groupId, portletId,
835 classNameId, orderByComparator);
836
837 if (portletItem != null) {
838 return portletItem;
839 }
840
841 StringBundler msg = new StringBundler(8);
842
843 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
844
845 msg.append("groupId=");
846 msg.append(groupId);
847
848 msg.append(", portletId=");
849 msg.append(portletId);
850
851 msg.append(", classNameId=");
852 msg.append(classNameId);
853
854 msg.append(StringPool.CLOSE_CURLY_BRACE);
855
856 throw new NoSuchPortletItemException(msg.toString());
857 }
858
859
869 @Override
870 public PortletItem fetchByG_P_C_First(long groupId, String portletId,
871 long classNameId, OrderByComparator orderByComparator)
872 throws SystemException {
873 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
874 0, 1, orderByComparator);
875
876 if (!list.isEmpty()) {
877 return list.get(0);
878 }
879
880 return null;
881 }
882
883
894 @Override
895 public PortletItem findByG_P_C_Last(long groupId, String portletId,
896 long classNameId, OrderByComparator orderByComparator)
897 throws NoSuchPortletItemException, SystemException {
898 PortletItem portletItem = fetchByG_P_C_Last(groupId, portletId,
899 classNameId, orderByComparator);
900
901 if (portletItem != null) {
902 return portletItem;
903 }
904
905 StringBundler msg = new StringBundler(8);
906
907 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
908
909 msg.append("groupId=");
910 msg.append(groupId);
911
912 msg.append(", portletId=");
913 msg.append(portletId);
914
915 msg.append(", classNameId=");
916 msg.append(classNameId);
917
918 msg.append(StringPool.CLOSE_CURLY_BRACE);
919
920 throw new NoSuchPortletItemException(msg.toString());
921 }
922
923
933 @Override
934 public PortletItem fetchByG_P_C_Last(long groupId, String portletId,
935 long classNameId, OrderByComparator orderByComparator)
936 throws SystemException {
937 int count = countByG_P_C(groupId, portletId, classNameId);
938
939 if (count == 0) {
940 return null;
941 }
942
943 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
944 count - 1, count, orderByComparator);
945
946 if (!list.isEmpty()) {
947 return list.get(0);
948 }
949
950 return null;
951 }
952
953
965 @Override
966 public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
967 long groupId, String portletId, long classNameId,
968 OrderByComparator orderByComparator)
969 throws NoSuchPortletItemException, SystemException {
970 PortletItem portletItem = findByPrimaryKey(portletItemId);
971
972 Session session = null;
973
974 try {
975 session = openSession();
976
977 PortletItem[] array = new PortletItemImpl[3];
978
979 array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
980 portletId, classNameId, orderByComparator, true);
981
982 array[1] = portletItem;
983
984 array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
985 portletId, classNameId, orderByComparator, false);
986
987 return array;
988 }
989 catch (Exception e) {
990 throw processException(e);
991 }
992 finally {
993 closeSession(session);
994 }
995 }
996
997 protected PortletItem getByG_P_C_PrevAndNext(Session session,
998 PortletItem portletItem, long groupId, String portletId,
999 long classNameId, OrderByComparator orderByComparator, boolean previous) {
1000 StringBundler query = null;
1001
1002 if (orderByComparator != null) {
1003 query = new StringBundler(6 +
1004 (orderByComparator.getOrderByFields().length * 6));
1005 }
1006 else {
1007 query = new StringBundler(3);
1008 }
1009
1010 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1011
1012 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1013
1014 boolean bindPortletId = false;
1015
1016 if (portletId == null) {
1017 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1018 }
1019 else if (portletId.equals(StringPool.BLANK)) {
1020 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1021 }
1022 else {
1023 bindPortletId = true;
1024
1025 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1026 }
1027
1028 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1029
1030 if (orderByComparator != null) {
1031 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1032
1033 if (orderByConditionFields.length > 0) {
1034 query.append(WHERE_AND);
1035 }
1036
1037 for (int i = 0; i < orderByConditionFields.length; i++) {
1038 query.append(_ORDER_BY_ENTITY_ALIAS);
1039 query.append(orderByConditionFields[i]);
1040
1041 if ((i + 1) < orderByConditionFields.length) {
1042 if (orderByComparator.isAscending() ^ previous) {
1043 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1044 }
1045 else {
1046 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1047 }
1048 }
1049 else {
1050 if (orderByComparator.isAscending() ^ previous) {
1051 query.append(WHERE_GREATER_THAN);
1052 }
1053 else {
1054 query.append(WHERE_LESSER_THAN);
1055 }
1056 }
1057 }
1058
1059 query.append(ORDER_BY_CLAUSE);
1060
1061 String[] orderByFields = orderByComparator.getOrderByFields();
1062
1063 for (int i = 0; i < orderByFields.length; i++) {
1064 query.append(_ORDER_BY_ENTITY_ALIAS);
1065 query.append(orderByFields[i]);
1066
1067 if ((i + 1) < orderByFields.length) {
1068 if (orderByComparator.isAscending() ^ previous) {
1069 query.append(ORDER_BY_ASC_HAS_NEXT);
1070 }
1071 else {
1072 query.append(ORDER_BY_DESC_HAS_NEXT);
1073 }
1074 }
1075 else {
1076 if (orderByComparator.isAscending() ^ previous) {
1077 query.append(ORDER_BY_ASC);
1078 }
1079 else {
1080 query.append(ORDER_BY_DESC);
1081 }
1082 }
1083 }
1084 }
1085 else {
1086 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
1087 }
1088
1089 String sql = query.toString();
1090
1091 Query q = session.createQuery(sql);
1092
1093 q.setFirstResult(0);
1094 q.setMaxResults(2);
1095
1096 QueryPos qPos = QueryPos.getInstance(q);
1097
1098 qPos.add(groupId);
1099
1100 if (bindPortletId) {
1101 qPos.add(portletId);
1102 }
1103
1104 qPos.add(classNameId);
1105
1106 if (orderByComparator != null) {
1107 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1108
1109 for (Object value : values) {
1110 qPos.add(value);
1111 }
1112 }
1113
1114 List<PortletItem> list = q.list();
1115
1116 if (list.size() == 2) {
1117 return list.get(1);
1118 }
1119 else {
1120 return null;
1121 }
1122 }
1123
1124
1132 @Override
1133 public void removeByG_P_C(long groupId, String portletId, long classNameId)
1134 throws SystemException {
1135 for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1136 classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1137 remove(portletItem);
1138 }
1139 }
1140
1141
1150 @Override
1151 public int countByG_P_C(long groupId, String portletId, long classNameId)
1152 throws SystemException {
1153 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_C;
1154
1155 Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1156
1157 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1158 this);
1159
1160 if (count == null) {
1161 StringBundler query = new StringBundler(4);
1162
1163 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1164
1165 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1166
1167 boolean bindPortletId = false;
1168
1169 if (portletId == null) {
1170 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1171 }
1172 else if (portletId.equals(StringPool.BLANK)) {
1173 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1174 }
1175 else {
1176 bindPortletId = true;
1177
1178 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1179 }
1180
1181 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1182
1183 String sql = query.toString();
1184
1185 Session session = null;
1186
1187 try {
1188 session = openSession();
1189
1190 Query q = session.createQuery(sql);
1191
1192 QueryPos qPos = QueryPos.getInstance(q);
1193
1194 qPos.add(groupId);
1195
1196 if (bindPortletId) {
1197 qPos.add(portletId);
1198 }
1199
1200 qPos.add(classNameId);
1201
1202 count = (Long)q.uniqueResult();
1203
1204 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1205 }
1206 catch (Exception e) {
1207 FinderCacheUtil.removeResult(finderPath, finderArgs);
1208
1209 throw processException(e);
1210 }
1211 finally {
1212 closeSession(session);
1213 }
1214 }
1215
1216 return count.intValue();
1217 }
1218
1219 private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1220 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1221 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1222 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = '') AND ";
1223 private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1224 public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1225 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
1226 FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
1227 new String[] {
1228 Long.class.getName(), String.class.getName(),
1229 String.class.getName(), Long.class.getName()
1230 },
1231 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
1232 PortletItemModelImpl.NAME_COLUMN_BITMASK |
1233 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
1234 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1235 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1236 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
1237 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_P_C",
1238 new String[] {
1239 Long.class.getName(), String.class.getName(),
1240 String.class.getName(), Long.class.getName()
1241 });
1242
1243
1254 @Override
1255 public PortletItem findByG_N_P_C(long groupId, String name,
1256 String portletId, long classNameId)
1257 throws NoSuchPortletItemException, SystemException {
1258 PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1259 classNameId);
1260
1261 if (portletItem == null) {
1262 StringBundler msg = new StringBundler(10);
1263
1264 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1265
1266 msg.append("groupId=");
1267 msg.append(groupId);
1268
1269 msg.append(", name=");
1270 msg.append(name);
1271
1272 msg.append(", portletId=");
1273 msg.append(portletId);
1274
1275 msg.append(", classNameId=");
1276 msg.append(classNameId);
1277
1278 msg.append(StringPool.CLOSE_CURLY_BRACE);
1279
1280 if (_log.isWarnEnabled()) {
1281 _log.warn(msg.toString());
1282 }
1283
1284 throw new NoSuchPortletItemException(msg.toString());
1285 }
1286
1287 return portletItem;
1288 }
1289
1290
1300 @Override
1301 public PortletItem fetchByG_N_P_C(long groupId, String name,
1302 String portletId, long classNameId) throws SystemException {
1303 return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1304 }
1305
1306
1317 @Override
1318 public PortletItem fetchByG_N_P_C(long groupId, String name,
1319 String portletId, long classNameId, boolean retrieveFromCache)
1320 throws SystemException {
1321 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1322
1323 Object result = null;
1324
1325 if (retrieveFromCache) {
1326 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1327 finderArgs, this);
1328 }
1329
1330 if (result instanceof PortletItem) {
1331 PortletItem portletItem = (PortletItem)result;
1332
1333 if ((groupId != portletItem.getGroupId()) ||
1334 !Validator.equals(name, portletItem.getName()) ||
1335 !Validator.equals(portletId, portletItem.getPortletId()) ||
1336 (classNameId != portletItem.getClassNameId())) {
1337 result = null;
1338 }
1339 }
1340
1341 if (result == null) {
1342 StringBundler query = new StringBundler(6);
1343
1344 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1345
1346 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1347
1348 boolean bindName = false;
1349
1350 if (name == null) {
1351 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1352 }
1353 else if (name.equals(StringPool.BLANK)) {
1354 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1355 }
1356 else {
1357 bindName = true;
1358
1359 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1360 }
1361
1362 boolean bindPortletId = false;
1363
1364 if (portletId == null) {
1365 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1366 }
1367 else if (portletId.equals(StringPool.BLANK)) {
1368 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1369 }
1370 else {
1371 bindPortletId = true;
1372
1373 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1374 }
1375
1376 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1377
1378 String sql = query.toString();
1379
1380 Session session = null;
1381
1382 try {
1383 session = openSession();
1384
1385 Query q = session.createQuery(sql);
1386
1387 QueryPos qPos = QueryPos.getInstance(q);
1388
1389 qPos.add(groupId);
1390
1391 if (bindName) {
1392 qPos.add(name.toLowerCase());
1393 }
1394
1395 if (bindPortletId) {
1396 qPos.add(portletId);
1397 }
1398
1399 qPos.add(classNameId);
1400
1401 List<PortletItem> list = q.list();
1402
1403 if (list.isEmpty()) {
1404 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1405 finderArgs, list);
1406 }
1407 else {
1408 if ((list.size() > 1) && _log.isWarnEnabled()) {
1409 _log.warn(
1410 "PortletItemPersistenceImpl.fetchByG_N_P_C(long, String, String, long, boolean) with parameters (" +
1411 StringUtil.merge(finderArgs) +
1412 ") 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.");
1413 }
1414
1415 PortletItem portletItem = list.get(0);
1416
1417 result = portletItem;
1418
1419 cacheResult(portletItem);
1420
1421 if ((portletItem.getGroupId() != groupId) ||
1422 (portletItem.getName() == null) ||
1423 !portletItem.getName().equals(name) ||
1424 (portletItem.getPortletId() == null) ||
1425 !portletItem.getPortletId().equals(portletId) ||
1426 (portletItem.getClassNameId() != classNameId)) {
1427 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1428 finderArgs, portletItem);
1429 }
1430 }
1431 }
1432 catch (Exception e) {
1433 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1434 finderArgs);
1435
1436 throw processException(e);
1437 }
1438 finally {
1439 closeSession(session);
1440 }
1441 }
1442
1443 if (result instanceof List<?>) {
1444 return null;
1445 }
1446 else {
1447 return (PortletItem)result;
1448 }
1449 }
1450
1451
1461 @Override
1462 public PortletItem removeByG_N_P_C(long groupId, String name,
1463 String portletId, long classNameId)
1464 throws NoSuchPortletItemException, SystemException {
1465 PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1466 classNameId);
1467
1468 return remove(portletItem);
1469 }
1470
1471
1481 @Override
1482 public int countByG_N_P_C(long groupId, String name, String portletId,
1483 long classNameId) throws SystemException {
1484 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_P_C;
1485
1486 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1487
1488 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1489 this);
1490
1491 if (count == null) {
1492 StringBundler query = new StringBundler(5);
1493
1494 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1495
1496 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1497
1498 boolean bindName = false;
1499
1500 if (name == null) {
1501 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1502 }
1503 else if (name.equals(StringPool.BLANK)) {
1504 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1505 }
1506 else {
1507 bindName = true;
1508
1509 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1510 }
1511
1512 boolean bindPortletId = false;
1513
1514 if (portletId == null) {
1515 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1516 }
1517 else if (portletId.equals(StringPool.BLANK)) {
1518 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1519 }
1520 else {
1521 bindPortletId = true;
1522
1523 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1524 }
1525
1526 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1527
1528 String sql = query.toString();
1529
1530 Session session = null;
1531
1532 try {
1533 session = openSession();
1534
1535 Query q = session.createQuery(sql);
1536
1537 QueryPos qPos = QueryPos.getInstance(q);
1538
1539 qPos.add(groupId);
1540
1541 if (bindName) {
1542 qPos.add(name.toLowerCase());
1543 }
1544
1545 if (bindPortletId) {
1546 qPos.add(portletId);
1547 }
1548
1549 qPos.add(classNameId);
1550
1551 count = (Long)q.uniqueResult();
1552
1553 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1554 }
1555 catch (Exception e) {
1556 FinderCacheUtil.removeResult(finderPath, finderArgs);
1557
1558 throw processException(e);
1559 }
1560 finally {
1561 closeSession(session);
1562 }
1563 }
1564
1565 return count.intValue();
1566 }
1567
1568 private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1569 private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
1570 private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = ? AND ";
1571 private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR portletItem.name = '') AND ";
1572 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1573 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1574 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = '') AND ";
1575 private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1576
1577
1582 @Override
1583 public void cacheResult(PortletItem portletItem) {
1584 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1585 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
1586
1587 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1588 new Object[] {
1589 portletItem.getGroupId(), portletItem.getName(),
1590 portletItem.getPortletId(), portletItem.getClassNameId()
1591 }, portletItem);
1592
1593 portletItem.resetOriginalValues();
1594 }
1595
1596
1601 @Override
1602 public void cacheResult(List<PortletItem> portletItems) {
1603 for (PortletItem portletItem : portletItems) {
1604 if (EntityCacheUtil.getResult(
1605 PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1606 PortletItemImpl.class, portletItem.getPrimaryKey()) == null) {
1607 cacheResult(portletItem);
1608 }
1609 else {
1610 portletItem.resetOriginalValues();
1611 }
1612 }
1613 }
1614
1615
1622 @Override
1623 public void clearCache() {
1624 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1625 CacheRegistryUtil.clear(PortletItemImpl.class.getName());
1626 }
1627
1628 EntityCacheUtil.clearCache(PortletItemImpl.class.getName());
1629
1630 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1631 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1632 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1633 }
1634
1635
1642 @Override
1643 public void clearCache(PortletItem portletItem) {
1644 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1645 PortletItemImpl.class, portletItem.getPrimaryKey());
1646
1647 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1648 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1649
1650 clearUniqueFindersCache(portletItem);
1651 }
1652
1653 @Override
1654 public void clearCache(List<PortletItem> portletItems) {
1655 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1656 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1657
1658 for (PortletItem portletItem : portletItems) {
1659 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1660 PortletItemImpl.class, portletItem.getPrimaryKey());
1661
1662 clearUniqueFindersCache(portletItem);
1663 }
1664 }
1665
1666 protected void cacheUniqueFindersCache(PortletItem portletItem) {
1667 if (portletItem.isNew()) {
1668 Object[] args = new Object[] {
1669 portletItem.getGroupId(), portletItem.getName(),
1670 portletItem.getPortletId(), portletItem.getClassNameId()
1671 };
1672
1673 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
1674 Long.valueOf(1));
1675 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
1676 portletItem);
1677 }
1678 else {
1679 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1680
1681 if ((portletItemModelImpl.getColumnBitmask() &
1682 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
1683 Object[] args = new Object[] {
1684 portletItem.getGroupId(), portletItem.getName(),
1685 portletItem.getPortletId(), portletItem.getClassNameId()
1686 };
1687
1688 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
1689 Long.valueOf(1));
1690 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
1691 portletItem);
1692 }
1693 }
1694 }
1695
1696 protected void clearUniqueFindersCache(PortletItem portletItem) {
1697 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1698
1699 Object[] args = new Object[] {
1700 portletItem.getGroupId(), portletItem.getName(),
1701 portletItem.getPortletId(), portletItem.getClassNameId()
1702 };
1703
1704 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
1705 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
1706
1707 if ((portletItemModelImpl.getColumnBitmask() &
1708 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
1709 args = new Object[] {
1710 portletItemModelImpl.getOriginalGroupId(),
1711 portletItemModelImpl.getOriginalName(),
1712 portletItemModelImpl.getOriginalPortletId(),
1713 portletItemModelImpl.getOriginalClassNameId()
1714 };
1715
1716 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
1717 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
1718 }
1719 }
1720
1721
1727 @Override
1728 public PortletItem create(long portletItemId) {
1729 PortletItem portletItem = new PortletItemImpl();
1730
1731 portletItem.setNew(true);
1732 portletItem.setPrimaryKey(portletItemId);
1733
1734 return portletItem;
1735 }
1736
1737
1745 @Override
1746 public PortletItem remove(long portletItemId)
1747 throws NoSuchPortletItemException, SystemException {
1748 return remove((Serializable)portletItemId);
1749 }
1750
1751
1759 @Override
1760 public PortletItem remove(Serializable primaryKey)
1761 throws NoSuchPortletItemException, SystemException {
1762 Session session = null;
1763
1764 try {
1765 session = openSession();
1766
1767 PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
1768 primaryKey);
1769
1770 if (portletItem == null) {
1771 if (_log.isWarnEnabled()) {
1772 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1773 }
1774
1775 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1776 primaryKey);
1777 }
1778
1779 return remove(portletItem);
1780 }
1781 catch (NoSuchPortletItemException nsee) {
1782 throw nsee;
1783 }
1784 catch (Exception e) {
1785 throw processException(e);
1786 }
1787 finally {
1788 closeSession(session);
1789 }
1790 }
1791
1792 @Override
1793 protected PortletItem removeImpl(PortletItem portletItem)
1794 throws SystemException {
1795 portletItem = toUnwrappedModel(portletItem);
1796
1797 Session session = null;
1798
1799 try {
1800 session = openSession();
1801
1802 if (!session.contains(portletItem)) {
1803 portletItem = (PortletItem)session.get(PortletItemImpl.class,
1804 portletItem.getPrimaryKeyObj());
1805 }
1806
1807 if (portletItem != null) {
1808 session.delete(portletItem);
1809 }
1810 }
1811 catch (Exception e) {
1812 throw processException(e);
1813 }
1814 finally {
1815 closeSession(session);
1816 }
1817
1818 if (portletItem != null) {
1819 clearCache(portletItem);
1820 }
1821
1822 return portletItem;
1823 }
1824
1825 @Override
1826 public PortletItem updateImpl(
1827 com.liferay.portal.model.PortletItem portletItem)
1828 throws SystemException {
1829 portletItem = toUnwrappedModel(portletItem);
1830
1831 boolean isNew = portletItem.isNew();
1832
1833 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1834
1835 Session session = null;
1836
1837 try {
1838 session = openSession();
1839
1840 if (portletItem.isNew()) {
1841 session.save(portletItem);
1842
1843 portletItem.setNew(false);
1844 }
1845 else {
1846 session.merge(portletItem);
1847 }
1848 }
1849 catch (Exception e) {
1850 throw processException(e);
1851 }
1852 finally {
1853 closeSession(session);
1854 }
1855
1856 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1857
1858 if (isNew || !PortletItemModelImpl.COLUMN_BITMASK_ENABLED) {
1859 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1860 }
1861
1862 else {
1863 if ((portletItemModelImpl.getColumnBitmask() &
1864 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1865 Object[] args = new Object[] {
1866 portletItemModelImpl.getOriginalGroupId(),
1867 portletItemModelImpl.getOriginalClassNameId()
1868 };
1869
1870 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1871 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1872 args);
1873
1874 args = new Object[] {
1875 portletItemModelImpl.getGroupId(),
1876 portletItemModelImpl.getClassNameId()
1877 };
1878
1879 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1880 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1881 args);
1882 }
1883
1884 if ((portletItemModelImpl.getColumnBitmask() &
1885 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C.getColumnBitmask()) != 0) {
1886 Object[] args = new Object[] {
1887 portletItemModelImpl.getOriginalGroupId(),
1888 portletItemModelImpl.getOriginalPortletId(),
1889 portletItemModelImpl.getOriginalClassNameId()
1890 };
1891
1892 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
1893 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
1894 args);
1895
1896 args = new Object[] {
1897 portletItemModelImpl.getGroupId(),
1898 portletItemModelImpl.getPortletId(),
1899 portletItemModelImpl.getClassNameId()
1900 };
1901
1902 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
1903 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
1904 args);
1905 }
1906 }
1907
1908 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1909 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
1910
1911 clearUniqueFindersCache(portletItem);
1912 cacheUniqueFindersCache(portletItem);
1913
1914 return portletItem;
1915 }
1916
1917 protected PortletItem toUnwrappedModel(PortletItem portletItem) {
1918 if (portletItem instanceof PortletItemImpl) {
1919 return portletItem;
1920 }
1921
1922 PortletItemImpl portletItemImpl = new PortletItemImpl();
1923
1924 portletItemImpl.setNew(portletItem.isNew());
1925 portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
1926
1927 portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
1928 portletItemImpl.setGroupId(portletItem.getGroupId());
1929 portletItemImpl.setCompanyId(portletItem.getCompanyId());
1930 portletItemImpl.setUserId(portletItem.getUserId());
1931 portletItemImpl.setUserName(portletItem.getUserName());
1932 portletItemImpl.setCreateDate(portletItem.getCreateDate());
1933 portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
1934 portletItemImpl.setName(portletItem.getName());
1935 portletItemImpl.setPortletId(portletItem.getPortletId());
1936 portletItemImpl.setClassNameId(portletItem.getClassNameId());
1937
1938 return portletItemImpl;
1939 }
1940
1941
1949 @Override
1950 public PortletItem findByPrimaryKey(Serializable primaryKey)
1951 throws NoSuchPortletItemException, SystemException {
1952 PortletItem portletItem = fetchByPrimaryKey(primaryKey);
1953
1954 if (portletItem == null) {
1955 if (_log.isWarnEnabled()) {
1956 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1957 }
1958
1959 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1960 primaryKey);
1961 }
1962
1963 return portletItem;
1964 }
1965
1966
1974 @Override
1975 public PortletItem findByPrimaryKey(long portletItemId)
1976 throws NoSuchPortletItemException, SystemException {
1977 return findByPrimaryKey((Serializable)portletItemId);
1978 }
1979
1980
1987 @Override
1988 public PortletItem fetchByPrimaryKey(Serializable primaryKey)
1989 throws SystemException {
1990 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1991 PortletItemImpl.class, primaryKey);
1992
1993 if (portletItem == _nullPortletItem) {
1994 return null;
1995 }
1996
1997 if (portletItem == null) {
1998 Session session = null;
1999
2000 try {
2001 session = openSession();
2002
2003 portletItem = (PortletItem)session.get(PortletItemImpl.class,
2004 primaryKey);
2005
2006 if (portletItem != null) {
2007 cacheResult(portletItem);
2008 }
2009 else {
2010 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
2011 PortletItemImpl.class, primaryKey, _nullPortletItem);
2012 }
2013 }
2014 catch (Exception e) {
2015 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
2016 PortletItemImpl.class, primaryKey);
2017
2018 throw processException(e);
2019 }
2020 finally {
2021 closeSession(session);
2022 }
2023 }
2024
2025 return portletItem;
2026 }
2027
2028
2035 @Override
2036 public PortletItem fetchByPrimaryKey(long portletItemId)
2037 throws SystemException {
2038 return fetchByPrimaryKey((Serializable)portletItemId);
2039 }
2040
2041
2047 @Override
2048 public List<PortletItem> findAll() throws SystemException {
2049 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2050 }
2051
2052
2064 @Override
2065 public List<PortletItem> findAll(int start, int end)
2066 throws SystemException {
2067 return findAll(start, end, null);
2068 }
2069
2070
2083 @Override
2084 public List<PortletItem> findAll(int start, int end,
2085 OrderByComparator orderByComparator) throws SystemException {
2086 boolean pagination = true;
2087 FinderPath finderPath = null;
2088 Object[] finderArgs = null;
2089
2090 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2091 (orderByComparator == null)) {
2092 pagination = false;
2093 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2094 finderArgs = FINDER_ARGS_EMPTY;
2095 }
2096 else {
2097 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2098 finderArgs = new Object[] { start, end, orderByComparator };
2099 }
2100
2101 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
2102 finderArgs, this);
2103
2104 if (list == null) {
2105 StringBundler query = null;
2106 String sql = null;
2107
2108 if (orderByComparator != null) {
2109 query = new StringBundler(2 +
2110 (orderByComparator.getOrderByFields().length * 3));
2111
2112 query.append(_SQL_SELECT_PORTLETITEM);
2113
2114 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2115 orderByComparator);
2116
2117 sql = query.toString();
2118 }
2119 else {
2120 sql = _SQL_SELECT_PORTLETITEM;
2121
2122 if (pagination) {
2123 sql = sql.concat(PortletItemModelImpl.ORDER_BY_JPQL);
2124 }
2125 }
2126
2127 Session session = null;
2128
2129 try {
2130 session = openSession();
2131
2132 Query q = session.createQuery(sql);
2133
2134 if (!pagination) {
2135 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
2136 start, end, false);
2137
2138 Collections.sort(list);
2139
2140 list = new UnmodifiableList<PortletItem>(list);
2141 }
2142 else {
2143 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
2144 start, end);
2145 }
2146
2147 cacheResult(list);
2148
2149 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2150 }
2151 catch (Exception e) {
2152 FinderCacheUtil.removeResult(finderPath, finderArgs);
2153
2154 throw processException(e);
2155 }
2156 finally {
2157 closeSession(session);
2158 }
2159 }
2160
2161 return list;
2162 }
2163
2164
2169 @Override
2170 public void removeAll() throws SystemException {
2171 for (PortletItem portletItem : findAll()) {
2172 remove(portletItem);
2173 }
2174 }
2175
2176
2182 @Override
2183 public int countAll() throws SystemException {
2184 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2185 FINDER_ARGS_EMPTY, this);
2186
2187 if (count == null) {
2188 Session session = null;
2189
2190 try {
2191 session = openSession();
2192
2193 Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
2194
2195 count = (Long)q.uniqueResult();
2196
2197 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2198 FINDER_ARGS_EMPTY, count);
2199 }
2200 catch (Exception e) {
2201 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2202 FINDER_ARGS_EMPTY);
2203
2204 throw processException(e);
2205 }
2206 finally {
2207 closeSession(session);
2208 }
2209 }
2210
2211 return count.intValue();
2212 }
2213
2214
2217 public void afterPropertiesSet() {
2218 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2219 com.liferay.portal.util.PropsUtil.get(
2220 "value.object.listener.com.liferay.portal.model.PortletItem")));
2221
2222 if (listenerClassNames.length > 0) {
2223 try {
2224 List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
2225
2226 for (String listenerClassName : listenerClassNames) {
2227 listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
2228 getClassLoader(), listenerClassName));
2229 }
2230
2231 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2232 }
2233 catch (Exception e) {
2234 _log.error(e);
2235 }
2236 }
2237 }
2238
2239 public void destroy() {
2240 EntityCacheUtil.removeCache(PortletItemImpl.class.getName());
2241 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2242 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2243 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2244 }
2245
2246 private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
2247 private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
2248 private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
2249 private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
2250 private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
2251 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
2252 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
2253 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2254 private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
2255 private static PortletItem _nullPortletItem = new PortletItemImpl() {
2256 @Override
2257 public Object clone() {
2258 return this;
2259 }
2260
2261 @Override
2262 public CacheModel<PortletItem> toCacheModel() {
2263 return _nullPortletItemCacheModel;
2264 }
2265 };
2266
2267 private static CacheModel<PortletItem> _nullPortletItemCacheModel = new CacheModel<PortletItem>() {
2268 @Override
2269 public PortletItem toEntityModel() {
2270 return _nullPortletItem;
2271 }
2272 };
2273 }