001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchPortletItemException;
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.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.StringUtil;
033 import com.liferay.portal.kernel.util.Validator;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.model.MVCCModel;
036 import com.liferay.portal.model.PortletItem;
037 import com.liferay.portal.model.impl.PortletItemImpl;
038 import com.liferay.portal.model.impl.PortletItemModelImpl;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portal.service.ServiceContextThreadLocal;
041 import com.liferay.portal.service.persistence.PortletItemPersistence;
042
043 import java.io.Serializable;
044
045 import java.util.Collections;
046 import java.util.Date;
047 import java.util.HashMap;
048 import java.util.HashSet;
049 import java.util.Iterator;
050 import java.util.List;
051 import java.util.Map;
052 import java.util.Set;
053
054
066 @ProviderType
067 public class PortletItemPersistenceImpl extends BasePersistenceImpl<PortletItem>
068 implements PortletItemPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = PortletItemImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
080 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
083 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
086 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
089 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
091 new String[] {
092 Long.class.getName(), Long.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
098 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
100 new String[] { Long.class.getName(), Long.class.getName() },
101 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
102 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
104 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
106 new String[] { Long.class.getName(), Long.class.getName() });
107
108
115 @Override
116 public List<PortletItem> findByG_C(long groupId, long classNameId) {
117 return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
118 QueryUtil.ALL_POS, null);
119 }
120
121
134 @Override
135 public List<PortletItem> findByG_C(long groupId, long classNameId,
136 int start, int end) {
137 return findByG_C(groupId, classNameId, start, end, null);
138 }
139
140
154 @Override
155 public List<PortletItem> findByG_C(long groupId, long classNameId,
156 int start, int end, OrderByComparator<PortletItem> orderByComparator) {
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 = Collections.unmodifiableList(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
270 @Override
271 public PortletItem findByG_C_First(long groupId, long classNameId,
272 OrderByComparator<PortletItem> orderByComparator)
273 throws NoSuchPortletItemException {
274 PortletItem portletItem = fetchByG_C_First(groupId, classNameId,
275 orderByComparator);
276
277 if (portletItem != null) {
278 return portletItem;
279 }
280
281 StringBundler msg = new StringBundler(6);
282
283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
284
285 msg.append("groupId=");
286 msg.append(groupId);
287
288 msg.append(", classNameId=");
289 msg.append(classNameId);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchPortletItemException(msg.toString());
294 }
295
296
304 @Override
305 public PortletItem fetchByG_C_First(long groupId, long classNameId,
306 OrderByComparator<PortletItem> orderByComparator) {
307 List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
308 orderByComparator);
309
310 if (!list.isEmpty()) {
311 return list.get(0);
312 }
313
314 return null;
315 }
316
317
326 @Override
327 public PortletItem findByG_C_Last(long groupId, long classNameId,
328 OrderByComparator<PortletItem> orderByComparator)
329 throws NoSuchPortletItemException {
330 PortletItem portletItem = fetchByG_C_Last(groupId, classNameId,
331 orderByComparator);
332
333 if (portletItem != null) {
334 return portletItem;
335 }
336
337 StringBundler msg = new StringBundler(6);
338
339 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340
341 msg.append("groupId=");
342 msg.append(groupId);
343
344 msg.append(", classNameId=");
345 msg.append(classNameId);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchPortletItemException(msg.toString());
350 }
351
352
360 @Override
361 public PortletItem fetchByG_C_Last(long groupId, long classNameId,
362 OrderByComparator<PortletItem> orderByComparator) {
363 int count = countByG_C(groupId, classNameId);
364
365 if (count == 0) {
366 return null;
367 }
368
369 List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
370 count, orderByComparator);
371
372 if (!list.isEmpty()) {
373 return list.get(0);
374 }
375
376 return null;
377 }
378
379
389 @Override
390 public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
391 long groupId, long classNameId,
392 OrderByComparator<PortletItem> orderByComparator)
393 throws NoSuchPortletItemException {
394 PortletItem portletItem = findByPrimaryKey(portletItemId);
395
396 Session session = null;
397
398 try {
399 session = openSession();
400
401 PortletItem[] array = new PortletItemImpl[3];
402
403 array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
404 classNameId, orderByComparator, true);
405
406 array[1] = portletItem;
407
408 array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
409 classNameId, orderByComparator, false);
410
411 return array;
412 }
413 catch (Exception e) {
414 throw processException(e);
415 }
416 finally {
417 closeSession(session);
418 }
419 }
420
421 protected PortletItem getByG_C_PrevAndNext(Session session,
422 PortletItem portletItem, long groupId, long classNameId,
423 OrderByComparator<PortletItem> orderByComparator, boolean previous) {
424 StringBundler query = null;
425
426 if (orderByComparator != null) {
427 query = new StringBundler(6 +
428 (orderByComparator.getOrderByFields().length * 6));
429 }
430 else {
431 query = new StringBundler(3);
432 }
433
434 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
435
436 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
437
438 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
439
440 if (orderByComparator != null) {
441 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442
443 if (orderByConditionFields.length > 0) {
444 query.append(WHERE_AND);
445 }
446
447 for (int i = 0; i < orderByConditionFields.length; i++) {
448 query.append(_ORDER_BY_ENTITY_ALIAS);
449 query.append(orderByConditionFields[i]);
450
451 if ((i + 1) < orderByConditionFields.length) {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN_HAS_NEXT);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN_HAS_NEXT);
457 }
458 }
459 else {
460 if (orderByComparator.isAscending() ^ previous) {
461 query.append(WHERE_GREATER_THAN);
462 }
463 else {
464 query.append(WHERE_LESSER_THAN);
465 }
466 }
467 }
468
469 query.append(ORDER_BY_CLAUSE);
470
471 String[] orderByFields = orderByComparator.getOrderByFields();
472
473 for (int i = 0; i < orderByFields.length; i++) {
474 query.append(_ORDER_BY_ENTITY_ALIAS);
475 query.append(orderByFields[i]);
476
477 if ((i + 1) < orderByFields.length) {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC_HAS_NEXT);
480 }
481 else {
482 query.append(ORDER_BY_DESC_HAS_NEXT);
483 }
484 }
485 else {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(ORDER_BY_ASC);
488 }
489 else {
490 query.append(ORDER_BY_DESC);
491 }
492 }
493 }
494 }
495 else {
496 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
497 }
498
499 String sql = query.toString();
500
501 Query q = session.createQuery(sql);
502
503 q.setFirstResult(0);
504 q.setMaxResults(2);
505
506 QueryPos qPos = QueryPos.getInstance(q);
507
508 qPos.add(groupId);
509
510 qPos.add(classNameId);
511
512 if (orderByComparator != null) {
513 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
514
515 for (Object value : values) {
516 qPos.add(value);
517 }
518 }
519
520 List<PortletItem> list = q.list();
521
522 if (list.size() == 2) {
523 return list.get(1);
524 }
525 else {
526 return null;
527 }
528 }
529
530
536 @Override
537 public void removeByG_C(long groupId, long classNameId) {
538 for (PortletItem portletItem : findByG_C(groupId, classNameId,
539 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
540 remove(portletItem);
541 }
542 }
543
544
551 @Override
552 public int countByG_C(long groupId, long classNameId) {
553 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
554
555 Object[] finderArgs = new Object[] { groupId, classNameId };
556
557 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
558 this);
559
560 if (count == null) {
561 StringBundler query = new StringBundler(3);
562
563 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
564
565 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
566
567 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
568
569 String sql = query.toString();
570
571 Session session = null;
572
573 try {
574 session = openSession();
575
576 Query q = session.createQuery(sql);
577
578 QueryPos qPos = QueryPos.getInstance(q);
579
580 qPos.add(groupId);
581
582 qPos.add(classNameId);
583
584 count = (Long)q.uniqueResult();
585
586 FinderCacheUtil.putResult(finderPath, finderArgs, count);
587 }
588 catch (Exception e) {
589 FinderCacheUtil.removeResult(finderPath, finderArgs);
590
591 throw processException(e);
592 }
593 finally {
594 closeSession(session);
595 }
596 }
597
598 return count.intValue();
599 }
600
601 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
602 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
603 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
604 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
605 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_C",
606 new String[] {
607 Long.class.getName(), String.class.getName(),
608 Long.class.getName(),
609
610 Integer.class.getName(), Integer.class.getName(),
611 OrderByComparator.class.getName()
612 });
613 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
614 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_C",
616 new String[] {
617 Long.class.getName(), String.class.getName(),
618 Long.class.getName()
619 },
620 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
621 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
622 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
623 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
624 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
625 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_C",
626 new String[] {
627 Long.class.getName(), String.class.getName(),
628 Long.class.getName()
629 });
630
631
639 @Override
640 public List<PortletItem> findByG_P_C(long groupId, String portletId,
641 long classNameId) {
642 return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
643 QueryUtil.ALL_POS, null);
644 }
645
646
660 @Override
661 public List<PortletItem> findByG_P_C(long groupId, String portletId,
662 long classNameId, int start, int end) {
663 return findByG_P_C(groupId, portletId, classNameId, start, end, null);
664 }
665
666
681 @Override
682 public List<PortletItem> findByG_P_C(long groupId, String portletId,
683 long classNameId, int start, int end,
684 OrderByComparator<PortletItem> orderByComparator) {
685 boolean pagination = true;
686 FinderPath finderPath = null;
687 Object[] finderArgs = null;
688
689 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
690 (orderByComparator == null)) {
691 pagination = false;
692 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C;
693 finderArgs = new Object[] { groupId, portletId, classNameId };
694 }
695 else {
696 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C;
697 finderArgs = new Object[] {
698 groupId, portletId, classNameId,
699
700 start, end, orderByComparator
701 };
702 }
703
704 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
705 finderArgs, this);
706
707 if ((list != null) && !list.isEmpty()) {
708 for (PortletItem portletItem : list) {
709 if ((groupId != portletItem.getGroupId()) ||
710 !Validator.equals(portletId, portletItem.getPortletId()) ||
711 (classNameId != portletItem.getClassNameId())) {
712 list = null;
713
714 break;
715 }
716 }
717 }
718
719 if (list == null) {
720 StringBundler query = null;
721
722 if (orderByComparator != null) {
723 query = new StringBundler(5 +
724 (orderByComparator.getOrderByFields().length * 3));
725 }
726 else {
727 query = new StringBundler(5);
728 }
729
730 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
731
732 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
733
734 boolean bindPortletId = false;
735
736 if (portletId == null) {
737 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
738 }
739 else if (portletId.equals(StringPool.BLANK)) {
740 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
741 }
742 else {
743 bindPortletId = true;
744
745 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
746 }
747
748 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
749
750 if (orderByComparator != null) {
751 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
752 orderByComparator);
753 }
754 else
755 if (pagination) {
756 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
757 }
758
759 String sql = query.toString();
760
761 Session session = null;
762
763 try {
764 session = openSession();
765
766 Query q = session.createQuery(sql);
767
768 QueryPos qPos = QueryPos.getInstance(q);
769
770 qPos.add(groupId);
771
772 if (bindPortletId) {
773 qPos.add(portletId);
774 }
775
776 qPos.add(classNameId);
777
778 if (!pagination) {
779 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
780 start, end, false);
781
782 Collections.sort(list);
783
784 list = Collections.unmodifiableList(list);
785 }
786 else {
787 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
788 start, end);
789 }
790
791 cacheResult(list);
792
793 FinderCacheUtil.putResult(finderPath, finderArgs, list);
794 }
795 catch (Exception e) {
796 FinderCacheUtil.removeResult(finderPath, finderArgs);
797
798 throw processException(e);
799 }
800 finally {
801 closeSession(session);
802 }
803 }
804
805 return list;
806 }
807
808
818 @Override
819 public PortletItem findByG_P_C_First(long groupId, String portletId,
820 long classNameId, OrderByComparator<PortletItem> orderByComparator)
821 throws NoSuchPortletItemException {
822 PortletItem portletItem = fetchByG_P_C_First(groupId, portletId,
823 classNameId, orderByComparator);
824
825 if (portletItem != null) {
826 return portletItem;
827 }
828
829 StringBundler msg = new StringBundler(8);
830
831 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
832
833 msg.append("groupId=");
834 msg.append(groupId);
835
836 msg.append(", portletId=");
837 msg.append(portletId);
838
839 msg.append(", classNameId=");
840 msg.append(classNameId);
841
842 msg.append(StringPool.CLOSE_CURLY_BRACE);
843
844 throw new NoSuchPortletItemException(msg.toString());
845 }
846
847
856 @Override
857 public PortletItem fetchByG_P_C_First(long groupId, String portletId,
858 long classNameId, OrderByComparator<PortletItem> orderByComparator) {
859 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
860 0, 1, orderByComparator);
861
862 if (!list.isEmpty()) {
863 return list.get(0);
864 }
865
866 return null;
867 }
868
869
879 @Override
880 public PortletItem findByG_P_C_Last(long groupId, String portletId,
881 long classNameId, OrderByComparator<PortletItem> orderByComparator)
882 throws NoSuchPortletItemException {
883 PortletItem portletItem = fetchByG_P_C_Last(groupId, portletId,
884 classNameId, orderByComparator);
885
886 if (portletItem != null) {
887 return portletItem;
888 }
889
890 StringBundler msg = new StringBundler(8);
891
892 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
893
894 msg.append("groupId=");
895 msg.append(groupId);
896
897 msg.append(", portletId=");
898 msg.append(portletId);
899
900 msg.append(", classNameId=");
901 msg.append(classNameId);
902
903 msg.append(StringPool.CLOSE_CURLY_BRACE);
904
905 throw new NoSuchPortletItemException(msg.toString());
906 }
907
908
917 @Override
918 public PortletItem fetchByG_P_C_Last(long groupId, String portletId,
919 long classNameId, OrderByComparator<PortletItem> orderByComparator) {
920 int count = countByG_P_C(groupId, portletId, classNameId);
921
922 if (count == 0) {
923 return null;
924 }
925
926 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
927 count - 1, count, orderByComparator);
928
929 if (!list.isEmpty()) {
930 return list.get(0);
931 }
932
933 return null;
934 }
935
936
947 @Override
948 public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
949 long groupId, String portletId, long classNameId,
950 OrderByComparator<PortletItem> orderByComparator)
951 throws NoSuchPortletItemException {
952 PortletItem portletItem = findByPrimaryKey(portletItemId);
953
954 Session session = null;
955
956 try {
957 session = openSession();
958
959 PortletItem[] array = new PortletItemImpl[3];
960
961 array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
962 portletId, classNameId, orderByComparator, true);
963
964 array[1] = portletItem;
965
966 array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
967 portletId, classNameId, orderByComparator, false);
968
969 return array;
970 }
971 catch (Exception e) {
972 throw processException(e);
973 }
974 finally {
975 closeSession(session);
976 }
977 }
978
979 protected PortletItem getByG_P_C_PrevAndNext(Session session,
980 PortletItem portletItem, long groupId, String portletId,
981 long classNameId, OrderByComparator<PortletItem> orderByComparator,
982 boolean previous) {
983 StringBundler query = null;
984
985 if (orderByComparator != null) {
986 query = new StringBundler(6 +
987 (orderByComparator.getOrderByFields().length * 6));
988 }
989 else {
990 query = new StringBundler(3);
991 }
992
993 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
994
995 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
996
997 boolean bindPortletId = false;
998
999 if (portletId == null) {
1000 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1001 }
1002 else if (portletId.equals(StringPool.BLANK)) {
1003 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1004 }
1005 else {
1006 bindPortletId = true;
1007
1008 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1009 }
1010
1011 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1012
1013 if (orderByComparator != null) {
1014 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1015
1016 if (orderByConditionFields.length > 0) {
1017 query.append(WHERE_AND);
1018 }
1019
1020 for (int i = 0; i < orderByConditionFields.length; i++) {
1021 query.append(_ORDER_BY_ENTITY_ALIAS);
1022 query.append(orderByConditionFields[i]);
1023
1024 if ((i + 1) < orderByConditionFields.length) {
1025 if (orderByComparator.isAscending() ^ previous) {
1026 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1027 }
1028 else {
1029 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1030 }
1031 }
1032 else {
1033 if (orderByComparator.isAscending() ^ previous) {
1034 query.append(WHERE_GREATER_THAN);
1035 }
1036 else {
1037 query.append(WHERE_LESSER_THAN);
1038 }
1039 }
1040 }
1041
1042 query.append(ORDER_BY_CLAUSE);
1043
1044 String[] orderByFields = orderByComparator.getOrderByFields();
1045
1046 for (int i = 0; i < orderByFields.length; i++) {
1047 query.append(_ORDER_BY_ENTITY_ALIAS);
1048 query.append(orderByFields[i]);
1049
1050 if ((i + 1) < orderByFields.length) {
1051 if (orderByComparator.isAscending() ^ previous) {
1052 query.append(ORDER_BY_ASC_HAS_NEXT);
1053 }
1054 else {
1055 query.append(ORDER_BY_DESC_HAS_NEXT);
1056 }
1057 }
1058 else {
1059 if (orderByComparator.isAscending() ^ previous) {
1060 query.append(ORDER_BY_ASC);
1061 }
1062 else {
1063 query.append(ORDER_BY_DESC);
1064 }
1065 }
1066 }
1067 }
1068 else {
1069 query.append(PortletItemModelImpl.ORDER_BY_JPQL);
1070 }
1071
1072 String sql = query.toString();
1073
1074 Query q = session.createQuery(sql);
1075
1076 q.setFirstResult(0);
1077 q.setMaxResults(2);
1078
1079 QueryPos qPos = QueryPos.getInstance(q);
1080
1081 qPos.add(groupId);
1082
1083 if (bindPortletId) {
1084 qPos.add(portletId);
1085 }
1086
1087 qPos.add(classNameId);
1088
1089 if (orderByComparator != null) {
1090 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1091
1092 for (Object value : values) {
1093 qPos.add(value);
1094 }
1095 }
1096
1097 List<PortletItem> list = q.list();
1098
1099 if (list.size() == 2) {
1100 return list.get(1);
1101 }
1102 else {
1103 return null;
1104 }
1105 }
1106
1107
1114 @Override
1115 public void removeByG_P_C(long groupId, String portletId, long classNameId) {
1116 for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1117 classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1118 remove(portletItem);
1119 }
1120 }
1121
1122
1130 @Override
1131 public int countByG_P_C(long groupId, String portletId, long classNameId) {
1132 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_C;
1133
1134 Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1135
1136 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1137 this);
1138
1139 if (count == null) {
1140 StringBundler query = new StringBundler(4);
1141
1142 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1143
1144 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1145
1146 boolean bindPortletId = false;
1147
1148 if (portletId == null) {
1149 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1150 }
1151 else if (portletId.equals(StringPool.BLANK)) {
1152 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1153 }
1154 else {
1155 bindPortletId = true;
1156
1157 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1158 }
1159
1160 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1161
1162 String sql = query.toString();
1163
1164 Session session = null;
1165
1166 try {
1167 session = openSession();
1168
1169 Query q = session.createQuery(sql);
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 qPos.add(groupId);
1174
1175 if (bindPortletId) {
1176 qPos.add(portletId);
1177 }
1178
1179 qPos.add(classNameId);
1180
1181 count = (Long)q.uniqueResult();
1182
1183 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1184 }
1185 catch (Exception e) {
1186 FinderCacheUtil.removeResult(finderPath, finderArgs);
1187
1188 throw processException(e);
1189 }
1190 finally {
1191 closeSession(session);
1192 }
1193 }
1194
1195 return count.intValue();
1196 }
1197
1198 private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1199 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1200 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1201 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = '') AND ";
1202 private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1203 public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1204 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
1205 FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
1206 new String[] {
1207 Long.class.getName(), String.class.getName(),
1208 String.class.getName(), Long.class.getName()
1209 },
1210 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
1211 PortletItemModelImpl.NAME_COLUMN_BITMASK |
1212 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
1213 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1214 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1215 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
1216 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_P_C",
1217 new String[] {
1218 Long.class.getName(), String.class.getName(),
1219 String.class.getName(), Long.class.getName()
1220 });
1221
1222
1232 @Override
1233 public PortletItem findByG_N_P_C(long groupId, String name,
1234 String portletId, long classNameId) throws NoSuchPortletItemException {
1235 PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1236 classNameId);
1237
1238 if (portletItem == null) {
1239 StringBundler msg = new StringBundler(10);
1240
1241 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1242
1243 msg.append("groupId=");
1244 msg.append(groupId);
1245
1246 msg.append(", name=");
1247 msg.append(name);
1248
1249 msg.append(", portletId=");
1250 msg.append(portletId);
1251
1252 msg.append(", classNameId=");
1253 msg.append(classNameId);
1254
1255 msg.append(StringPool.CLOSE_CURLY_BRACE);
1256
1257 if (_log.isWarnEnabled()) {
1258 _log.warn(msg.toString());
1259 }
1260
1261 throw new NoSuchPortletItemException(msg.toString());
1262 }
1263
1264 return portletItem;
1265 }
1266
1267
1276 @Override
1277 public PortletItem fetchByG_N_P_C(long groupId, String name,
1278 String portletId, long classNameId) {
1279 return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1280 }
1281
1282
1292 @Override
1293 public PortletItem fetchByG_N_P_C(long groupId, String name,
1294 String portletId, long classNameId, boolean retrieveFromCache) {
1295 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1296
1297 Object result = null;
1298
1299 if (retrieveFromCache) {
1300 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1301 finderArgs, this);
1302 }
1303
1304 if (result instanceof PortletItem) {
1305 PortletItem portletItem = (PortletItem)result;
1306
1307 if ((groupId != portletItem.getGroupId()) ||
1308 !Validator.equals(name, portletItem.getName()) ||
1309 !Validator.equals(portletId, portletItem.getPortletId()) ||
1310 (classNameId != portletItem.getClassNameId())) {
1311 result = null;
1312 }
1313 }
1314
1315 if (result == null) {
1316 StringBundler query = new StringBundler(6);
1317
1318 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1319
1320 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1321
1322 boolean bindName = false;
1323
1324 if (name == null) {
1325 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1326 }
1327 else if (name.equals(StringPool.BLANK)) {
1328 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1329 }
1330 else {
1331 bindName = true;
1332
1333 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1334 }
1335
1336 boolean bindPortletId = false;
1337
1338 if (portletId == null) {
1339 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1340 }
1341 else if (portletId.equals(StringPool.BLANK)) {
1342 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1343 }
1344 else {
1345 bindPortletId = true;
1346
1347 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1348 }
1349
1350 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1351
1352 String sql = query.toString();
1353
1354 Session session = null;
1355
1356 try {
1357 session = openSession();
1358
1359 Query q = session.createQuery(sql);
1360
1361 QueryPos qPos = QueryPos.getInstance(q);
1362
1363 qPos.add(groupId);
1364
1365 if (bindName) {
1366 qPos.add(StringUtil.toLowerCase(name));
1367 }
1368
1369 if (bindPortletId) {
1370 qPos.add(portletId);
1371 }
1372
1373 qPos.add(classNameId);
1374
1375 List<PortletItem> list = q.list();
1376
1377 if (list.isEmpty()) {
1378 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1379 finderArgs, list);
1380 }
1381 else {
1382 if ((list.size() > 1) && _log.isWarnEnabled()) {
1383 _log.warn(
1384 "PortletItemPersistenceImpl.fetchByG_N_P_C(long, String, String, long, boolean) with parameters (" +
1385 StringUtil.merge(finderArgs) +
1386 ") 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.");
1387 }
1388
1389 PortletItem portletItem = list.get(0);
1390
1391 result = portletItem;
1392
1393 cacheResult(portletItem);
1394
1395 if ((portletItem.getGroupId() != groupId) ||
1396 (portletItem.getName() == null) ||
1397 !portletItem.getName().equals(name) ||
1398 (portletItem.getPortletId() == null) ||
1399 !portletItem.getPortletId().equals(portletId) ||
1400 (portletItem.getClassNameId() != classNameId)) {
1401 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1402 finderArgs, portletItem);
1403 }
1404 }
1405 }
1406 catch (Exception e) {
1407 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1408 finderArgs);
1409
1410 throw processException(e);
1411 }
1412 finally {
1413 closeSession(session);
1414 }
1415 }
1416
1417 if (result instanceof List<?>) {
1418 return null;
1419 }
1420 else {
1421 return (PortletItem)result;
1422 }
1423 }
1424
1425
1434 @Override
1435 public PortletItem removeByG_N_P_C(long groupId, String name,
1436 String portletId, long classNameId) throws NoSuchPortletItemException {
1437 PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1438 classNameId);
1439
1440 return remove(portletItem);
1441 }
1442
1443
1452 @Override
1453 public int countByG_N_P_C(long groupId, String name, String portletId,
1454 long classNameId) {
1455 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_P_C;
1456
1457 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1458
1459 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1460 this);
1461
1462 if (count == null) {
1463 StringBundler query = new StringBundler(5);
1464
1465 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1466
1467 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1468
1469 boolean bindName = false;
1470
1471 if (name == null) {
1472 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1473 }
1474 else if (name.equals(StringPool.BLANK)) {
1475 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1476 }
1477 else {
1478 bindName = true;
1479
1480 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1481 }
1482
1483 boolean bindPortletId = false;
1484
1485 if (portletId == null) {
1486 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1487 }
1488 else if (portletId.equals(StringPool.BLANK)) {
1489 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1490 }
1491 else {
1492 bindPortletId = true;
1493
1494 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1495 }
1496
1497 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1498
1499 String sql = query.toString();
1500
1501 Session session = null;
1502
1503 try {
1504 session = openSession();
1505
1506 Query q = session.createQuery(sql);
1507
1508 QueryPos qPos = QueryPos.getInstance(q);
1509
1510 qPos.add(groupId);
1511
1512 if (bindName) {
1513 qPos.add(StringUtil.toLowerCase(name));
1514 }
1515
1516 if (bindPortletId) {
1517 qPos.add(portletId);
1518 }
1519
1520 qPos.add(classNameId);
1521
1522 count = (Long)q.uniqueResult();
1523
1524 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1525 }
1526 catch (Exception e) {
1527 FinderCacheUtil.removeResult(finderPath, finderArgs);
1528
1529 throw processException(e);
1530 }
1531 finally {
1532 closeSession(session);
1533 }
1534 }
1535
1536 return count.intValue();
1537 }
1538
1539 private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
1540 private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
1541 private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = ? AND ";
1542 private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR portletItem.name = '') AND ";
1543 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
1544 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
1545 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = '') AND ";
1546 private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
1547
1548 public PortletItemPersistenceImpl() {
1549 setModelClass(PortletItem.class);
1550 }
1551
1552
1557 @Override
1558 public void cacheResult(PortletItem portletItem) {
1559 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1560 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
1561
1562 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1563 new Object[] {
1564 portletItem.getGroupId(), portletItem.getName(),
1565 portletItem.getPortletId(), portletItem.getClassNameId()
1566 }, portletItem);
1567
1568 portletItem.resetOriginalValues();
1569 }
1570
1571
1576 @Override
1577 public void cacheResult(List<PortletItem> portletItems) {
1578 for (PortletItem portletItem : portletItems) {
1579 if (EntityCacheUtil.getResult(
1580 PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1581 PortletItemImpl.class, portletItem.getPrimaryKey()) == null) {
1582 cacheResult(portletItem);
1583 }
1584 else {
1585 portletItem.resetOriginalValues();
1586 }
1587 }
1588 }
1589
1590
1597 @Override
1598 public void clearCache() {
1599 EntityCacheUtil.clearCache(PortletItemImpl.class);
1600
1601 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1602 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1603 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1604 }
1605
1606
1613 @Override
1614 public void clearCache(PortletItem portletItem) {
1615 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1616 PortletItemImpl.class, portletItem.getPrimaryKey());
1617
1618 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1619 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1620
1621 clearUniqueFindersCache(portletItem);
1622 }
1623
1624 @Override
1625 public void clearCache(List<PortletItem> portletItems) {
1626 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1627 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1628
1629 for (PortletItem portletItem : portletItems) {
1630 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1631 PortletItemImpl.class, portletItem.getPrimaryKey());
1632
1633 clearUniqueFindersCache(portletItem);
1634 }
1635 }
1636
1637 protected void cacheUniqueFindersCache(PortletItem portletItem) {
1638 if (portletItem.isNew()) {
1639 Object[] args = new Object[] {
1640 portletItem.getGroupId(), portletItem.getName(),
1641 portletItem.getPortletId(), portletItem.getClassNameId()
1642 };
1643
1644 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
1645 Long.valueOf(1));
1646 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
1647 portletItem);
1648 }
1649 else {
1650 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1651
1652 if ((portletItemModelImpl.getColumnBitmask() &
1653 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
1654 Object[] args = new Object[] {
1655 portletItem.getGroupId(), portletItem.getName(),
1656 portletItem.getPortletId(), portletItem.getClassNameId()
1657 };
1658
1659 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
1660 Long.valueOf(1));
1661 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
1662 portletItem);
1663 }
1664 }
1665 }
1666
1667 protected void clearUniqueFindersCache(PortletItem portletItem) {
1668 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1669
1670 Object[] args = new Object[] {
1671 portletItem.getGroupId(), portletItem.getName(),
1672 portletItem.getPortletId(), portletItem.getClassNameId()
1673 };
1674
1675 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
1676 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
1677
1678 if ((portletItemModelImpl.getColumnBitmask() &
1679 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
1680 args = new Object[] {
1681 portletItemModelImpl.getOriginalGroupId(),
1682 portletItemModelImpl.getOriginalName(),
1683 portletItemModelImpl.getOriginalPortletId(),
1684 portletItemModelImpl.getOriginalClassNameId()
1685 };
1686
1687 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
1688 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
1689 }
1690 }
1691
1692
1698 @Override
1699 public PortletItem create(long portletItemId) {
1700 PortletItem portletItem = new PortletItemImpl();
1701
1702 portletItem.setNew(true);
1703 portletItem.setPrimaryKey(portletItemId);
1704
1705 return portletItem;
1706 }
1707
1708
1715 @Override
1716 public PortletItem remove(long portletItemId)
1717 throws NoSuchPortletItemException {
1718 return remove((Serializable)portletItemId);
1719 }
1720
1721
1728 @Override
1729 public PortletItem remove(Serializable primaryKey)
1730 throws NoSuchPortletItemException {
1731 Session session = null;
1732
1733 try {
1734 session = openSession();
1735
1736 PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
1737 primaryKey);
1738
1739 if (portletItem == null) {
1740 if (_log.isWarnEnabled()) {
1741 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1742 }
1743
1744 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1745 primaryKey);
1746 }
1747
1748 return remove(portletItem);
1749 }
1750 catch (NoSuchPortletItemException nsee) {
1751 throw nsee;
1752 }
1753 catch (Exception e) {
1754 throw processException(e);
1755 }
1756 finally {
1757 closeSession(session);
1758 }
1759 }
1760
1761 @Override
1762 protected PortletItem removeImpl(PortletItem portletItem) {
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(PortletItem portletItem) {
1795 portletItem = toUnwrappedModel(portletItem);
1796
1797 boolean isNew = portletItem.isNew();
1798
1799 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
1800
1801 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
1802
1803 Date now = new Date();
1804
1805 if (isNew && (portletItem.getCreateDate() == null)) {
1806 if (serviceContext == null) {
1807 portletItem.setCreateDate(now);
1808 }
1809 else {
1810 portletItem.setCreateDate(serviceContext.getCreateDate(now));
1811 }
1812 }
1813
1814 if (!portletItemModelImpl.hasSetModifiedDate()) {
1815 if (serviceContext == null) {
1816 portletItem.setModifiedDate(now);
1817 }
1818 else {
1819 portletItem.setModifiedDate(serviceContext.getModifiedDate(now));
1820 }
1821 }
1822
1823 Session session = null;
1824
1825 try {
1826 session = openSession();
1827
1828 if (portletItem.isNew()) {
1829 session.save(portletItem);
1830
1831 portletItem.setNew(false);
1832 }
1833 else {
1834 session.merge(portletItem);
1835 }
1836 }
1837 catch (Exception e) {
1838 throw processException(e);
1839 }
1840 finally {
1841 closeSession(session);
1842 }
1843
1844 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1845
1846 if (isNew || !PortletItemModelImpl.COLUMN_BITMASK_ENABLED) {
1847 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1848 }
1849
1850 else {
1851 if ((portletItemModelImpl.getColumnBitmask() &
1852 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
1853 Object[] args = new Object[] {
1854 portletItemModelImpl.getOriginalGroupId(),
1855 portletItemModelImpl.getOriginalClassNameId()
1856 };
1857
1858 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1859 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1860 args);
1861
1862 args = new Object[] {
1863 portletItemModelImpl.getGroupId(),
1864 portletItemModelImpl.getClassNameId()
1865 };
1866
1867 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
1868 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
1869 args);
1870 }
1871
1872 if ((portletItemModelImpl.getColumnBitmask() &
1873 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C.getColumnBitmask()) != 0) {
1874 Object[] args = new Object[] {
1875 portletItemModelImpl.getOriginalGroupId(),
1876 portletItemModelImpl.getOriginalPortletId(),
1877 portletItemModelImpl.getOriginalClassNameId()
1878 };
1879
1880 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
1881 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
1882 args);
1883
1884 args = new Object[] {
1885 portletItemModelImpl.getGroupId(),
1886 portletItemModelImpl.getPortletId(),
1887 portletItemModelImpl.getClassNameId()
1888 };
1889
1890 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
1891 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
1892 args);
1893 }
1894 }
1895
1896 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1897 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem,
1898 false);
1899
1900 clearUniqueFindersCache(portletItem);
1901 cacheUniqueFindersCache(portletItem);
1902
1903 portletItem.resetOriginalValues();
1904
1905 return portletItem;
1906 }
1907
1908 protected PortletItem toUnwrappedModel(PortletItem portletItem) {
1909 if (portletItem instanceof PortletItemImpl) {
1910 return portletItem;
1911 }
1912
1913 PortletItemImpl portletItemImpl = new PortletItemImpl();
1914
1915 portletItemImpl.setNew(portletItem.isNew());
1916 portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
1917
1918 portletItemImpl.setMvccVersion(portletItem.getMvccVersion());
1919 portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
1920 portletItemImpl.setGroupId(portletItem.getGroupId());
1921 portletItemImpl.setCompanyId(portletItem.getCompanyId());
1922 portletItemImpl.setUserId(portletItem.getUserId());
1923 portletItemImpl.setUserName(portletItem.getUserName());
1924 portletItemImpl.setCreateDate(portletItem.getCreateDate());
1925 portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
1926 portletItemImpl.setName(portletItem.getName());
1927 portletItemImpl.setPortletId(portletItem.getPortletId());
1928 portletItemImpl.setClassNameId(portletItem.getClassNameId());
1929
1930 return portletItemImpl;
1931 }
1932
1933
1940 @Override
1941 public PortletItem findByPrimaryKey(Serializable primaryKey)
1942 throws NoSuchPortletItemException {
1943 PortletItem portletItem = fetchByPrimaryKey(primaryKey);
1944
1945 if (portletItem == null) {
1946 if (_log.isWarnEnabled()) {
1947 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1948 }
1949
1950 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1951 primaryKey);
1952 }
1953
1954 return portletItem;
1955 }
1956
1957
1964 @Override
1965 public PortletItem findByPrimaryKey(long portletItemId)
1966 throws NoSuchPortletItemException {
1967 return findByPrimaryKey((Serializable)portletItemId);
1968 }
1969
1970
1976 @Override
1977 public PortletItem fetchByPrimaryKey(Serializable primaryKey) {
1978 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1979 PortletItemImpl.class, primaryKey);
1980
1981 if (portletItem == _nullPortletItem) {
1982 return null;
1983 }
1984
1985 if (portletItem == null) {
1986 Session session = null;
1987
1988 try {
1989 session = openSession();
1990
1991 portletItem = (PortletItem)session.get(PortletItemImpl.class,
1992 primaryKey);
1993
1994 if (portletItem != null) {
1995 cacheResult(portletItem);
1996 }
1997 else {
1998 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
1999 PortletItemImpl.class, primaryKey, _nullPortletItem);
2000 }
2001 }
2002 catch (Exception e) {
2003 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
2004 PortletItemImpl.class, primaryKey);
2005
2006 throw processException(e);
2007 }
2008 finally {
2009 closeSession(session);
2010 }
2011 }
2012
2013 return portletItem;
2014 }
2015
2016
2022 @Override
2023 public PortletItem fetchByPrimaryKey(long portletItemId) {
2024 return fetchByPrimaryKey((Serializable)portletItemId);
2025 }
2026
2027 @Override
2028 public Map<Serializable, PortletItem> fetchByPrimaryKeys(
2029 Set<Serializable> primaryKeys) {
2030 if (primaryKeys.isEmpty()) {
2031 return Collections.emptyMap();
2032 }
2033
2034 Map<Serializable, PortletItem> map = new HashMap<Serializable, PortletItem>();
2035
2036 if (primaryKeys.size() == 1) {
2037 Iterator<Serializable> iterator = primaryKeys.iterator();
2038
2039 Serializable primaryKey = iterator.next();
2040
2041 PortletItem portletItem = fetchByPrimaryKey(primaryKey);
2042
2043 if (portletItem != null) {
2044 map.put(primaryKey, portletItem);
2045 }
2046
2047 return map;
2048 }
2049
2050 Set<Serializable> uncachedPrimaryKeys = null;
2051
2052 for (Serializable primaryKey : primaryKeys) {
2053 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
2054 PortletItemImpl.class, primaryKey);
2055
2056 if (portletItem == null) {
2057 if (uncachedPrimaryKeys == null) {
2058 uncachedPrimaryKeys = new HashSet<Serializable>();
2059 }
2060
2061 uncachedPrimaryKeys.add(primaryKey);
2062 }
2063 else {
2064 map.put(primaryKey, portletItem);
2065 }
2066 }
2067
2068 if (uncachedPrimaryKeys == null) {
2069 return map;
2070 }
2071
2072 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2073 1);
2074
2075 query.append(_SQL_SELECT_PORTLETITEM_WHERE_PKS_IN);
2076
2077 for (Serializable primaryKey : uncachedPrimaryKeys) {
2078 query.append(String.valueOf(primaryKey));
2079
2080 query.append(StringPool.COMMA);
2081 }
2082
2083 query.setIndex(query.index() - 1);
2084
2085 query.append(StringPool.CLOSE_PARENTHESIS);
2086
2087 String sql = query.toString();
2088
2089 Session session = null;
2090
2091 try {
2092 session = openSession();
2093
2094 Query q = session.createQuery(sql);
2095
2096 for (PortletItem portletItem : (List<PortletItem>)q.list()) {
2097 map.put(portletItem.getPrimaryKeyObj(), portletItem);
2098
2099 cacheResult(portletItem);
2100
2101 uncachedPrimaryKeys.remove(portletItem.getPrimaryKeyObj());
2102 }
2103
2104 for (Serializable primaryKey : uncachedPrimaryKeys) {
2105 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
2106 PortletItemImpl.class, primaryKey, _nullPortletItem);
2107 }
2108 }
2109 catch (Exception e) {
2110 throw processException(e);
2111 }
2112 finally {
2113 closeSession(session);
2114 }
2115
2116 return map;
2117 }
2118
2119
2124 @Override
2125 public List<PortletItem> findAll() {
2126 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2127 }
2128
2129
2140 @Override
2141 public List<PortletItem> findAll(int start, int end) {
2142 return findAll(start, end, null);
2143 }
2144
2145
2157 @Override
2158 public List<PortletItem> findAll(int start, int end,
2159 OrderByComparator<PortletItem> orderByComparator) {
2160 boolean pagination = true;
2161 FinderPath finderPath = null;
2162 Object[] finderArgs = null;
2163
2164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2165 (orderByComparator == null)) {
2166 pagination = false;
2167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2168 finderArgs = FINDER_ARGS_EMPTY;
2169 }
2170 else {
2171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2172 finderArgs = new Object[] { start, end, orderByComparator };
2173 }
2174
2175 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
2176 finderArgs, this);
2177
2178 if (list == null) {
2179 StringBundler query = null;
2180 String sql = null;
2181
2182 if (orderByComparator != null) {
2183 query = new StringBundler(2 +
2184 (orderByComparator.getOrderByFields().length * 3));
2185
2186 query.append(_SQL_SELECT_PORTLETITEM);
2187
2188 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2189 orderByComparator);
2190
2191 sql = query.toString();
2192 }
2193 else {
2194 sql = _SQL_SELECT_PORTLETITEM;
2195
2196 if (pagination) {
2197 sql = sql.concat(PortletItemModelImpl.ORDER_BY_JPQL);
2198 }
2199 }
2200
2201 Session session = null;
2202
2203 try {
2204 session = openSession();
2205
2206 Query q = session.createQuery(sql);
2207
2208 if (!pagination) {
2209 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
2210 start, end, false);
2211
2212 Collections.sort(list);
2213
2214 list = Collections.unmodifiableList(list);
2215 }
2216 else {
2217 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
2218 start, end);
2219 }
2220
2221 cacheResult(list);
2222
2223 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2224 }
2225 catch (Exception e) {
2226 FinderCacheUtil.removeResult(finderPath, finderArgs);
2227
2228 throw processException(e);
2229 }
2230 finally {
2231 closeSession(session);
2232 }
2233 }
2234
2235 return list;
2236 }
2237
2238
2242 @Override
2243 public void removeAll() {
2244 for (PortletItem portletItem : findAll()) {
2245 remove(portletItem);
2246 }
2247 }
2248
2249
2254 @Override
2255 public int countAll() {
2256 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2257 FINDER_ARGS_EMPTY, this);
2258
2259 if (count == null) {
2260 Session session = null;
2261
2262 try {
2263 session = openSession();
2264
2265 Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
2266
2267 count = (Long)q.uniqueResult();
2268
2269 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2270 FINDER_ARGS_EMPTY, count);
2271 }
2272 catch (Exception e) {
2273 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2274 FINDER_ARGS_EMPTY);
2275
2276 throw processException(e);
2277 }
2278 finally {
2279 closeSession(session);
2280 }
2281 }
2282
2283 return count.intValue();
2284 }
2285
2286
2289 public void afterPropertiesSet() {
2290 }
2291
2292 public void destroy() {
2293 EntityCacheUtil.removeCache(PortletItemImpl.class.getName());
2294 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2295 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2296 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2297 }
2298
2299 private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
2300 private static final String _SQL_SELECT_PORTLETITEM_WHERE_PKS_IN = "SELECT portletItem FROM PortletItem portletItem WHERE portletItemId IN (";
2301 private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
2302 private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
2303 private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
2304 private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
2305 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
2306 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
2307 private static final Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
2308 private static final PortletItem _nullPortletItem = new PortletItemImpl() {
2309 @Override
2310 public Object clone() {
2311 return this;
2312 }
2313
2314 @Override
2315 public CacheModel<PortletItem> toCacheModel() {
2316 return _nullPortletItemCacheModel;
2317 }
2318 };
2319
2320 private static final CacheModel<PortletItem> _nullPortletItemCacheModel = new NullCacheModel();
2321
2322 private static class NullCacheModel implements CacheModel<PortletItem>,
2323 MVCCModel {
2324 @Override
2325 public long getMvccVersion() {
2326 return -1;
2327 }
2328
2329 @Override
2330 public void setMvccVersion(long mvccVersion) {
2331 }
2332
2333 @Override
2334 public PortletItem toEntityModel() {
2335 return _nullPortletItem;
2336 }
2337 }
2338 }