001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPortletItemException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.PortletItem;
041 import com.liferay.portal.model.impl.PortletItemImpl;
042 import com.liferay.portal.model.impl.PortletItemModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class PortletItemPersistenceImpl extends BasePersistenceImpl<PortletItem>
064 implements PortletItemPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = PortletItemImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
076 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
078 new String[] {
079 Long.class.getName(), Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
085 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
087 new String[] { Long.class.getName(), Long.class.getName() },
088 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
089 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
091 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
093 new String[] { Long.class.getName(), Long.class.getName() });
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
095 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_C",
097 new String[] {
098 Long.class.getName(), String.class.getName(),
099 Long.class.getName(),
100
101 "java.lang.Integer", "java.lang.Integer",
102 "com.liferay.portal.kernel.util.OrderByComparator"
103 });
104 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
105 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_C",
107 new String[] {
108 Long.class.getName(), String.class.getName(),
109 Long.class.getName()
110 },
111 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
112 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
113 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
114 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
115 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_C",
117 new String[] {
118 Long.class.getName(), String.class.getName(),
119 Long.class.getName()
120 });
121 public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
122 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
123 FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
124 new String[] {
125 Long.class.getName(), String.class.getName(),
126 String.class.getName(), Long.class.getName()
127 },
128 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
129 PortletItemModelImpl.NAME_COLUMN_BITMASK |
130 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
131 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
132 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
133 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
134 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_P_C",
135 new String[] {
136 Long.class.getName(), String.class.getName(),
137 String.class.getName(), Long.class.getName()
138 });
139 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
140 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
141 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
142 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
143 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
144 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
145 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
146 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
147 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
148
149
154 public void cacheResult(PortletItem portletItem) {
155 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
156 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
157
158 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
159 new Object[] {
160 Long.valueOf(portletItem.getGroupId()),
161
162 portletItem.getName(),
163
164 portletItem.getPortletId(),
165 Long.valueOf(portletItem.getClassNameId())
166 }, portletItem);
167
168 portletItem.resetOriginalValues();
169 }
170
171
176 public void cacheResult(List<PortletItem> portletItems) {
177 for (PortletItem portletItem : portletItems) {
178 if (EntityCacheUtil.getResult(
179 PortletItemModelImpl.ENTITY_CACHE_ENABLED,
180 PortletItemImpl.class, portletItem.getPrimaryKey()) == null) {
181 cacheResult(portletItem);
182 }
183 else {
184 portletItem.resetOriginalValues();
185 }
186 }
187 }
188
189
196 @Override
197 public void clearCache() {
198 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
199 CacheRegistryUtil.clear(PortletItemImpl.class.getName());
200 }
201
202 EntityCacheUtil.clearCache(PortletItemImpl.class.getName());
203
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
207 }
208
209
216 @Override
217 public void clearCache(PortletItem portletItem) {
218 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
219 PortletItemImpl.class, portletItem.getPrimaryKey());
220
221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
223
224 clearUniqueFindersCache(portletItem);
225 }
226
227 @Override
228 public void clearCache(List<PortletItem> portletItems) {
229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
231
232 for (PortletItem portletItem : portletItems) {
233 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
234 PortletItemImpl.class, portletItem.getPrimaryKey());
235
236 clearUniqueFindersCache(portletItem);
237 }
238 }
239
240 protected void clearUniqueFindersCache(PortletItem portletItem) {
241 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
242 new Object[] {
243 Long.valueOf(portletItem.getGroupId()),
244
245 portletItem.getName(),
246
247 portletItem.getPortletId(),
248 Long.valueOf(portletItem.getClassNameId())
249 });
250 }
251
252
258 public PortletItem create(long portletItemId) {
259 PortletItem portletItem = new PortletItemImpl();
260
261 portletItem.setNew(true);
262 portletItem.setPrimaryKey(portletItemId);
263
264 return portletItem;
265 }
266
267
275 public PortletItem remove(long portletItemId)
276 throws NoSuchPortletItemException, SystemException {
277 return remove(Long.valueOf(portletItemId));
278 }
279
280
288 @Override
289 public PortletItem remove(Serializable primaryKey)
290 throws NoSuchPortletItemException, SystemException {
291 Session session = null;
292
293 try {
294 session = openSession();
295
296 PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
297 primaryKey);
298
299 if (portletItem == null) {
300 if (_log.isWarnEnabled()) {
301 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
302 }
303
304 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
305 primaryKey);
306 }
307
308 return remove(portletItem);
309 }
310 catch (NoSuchPortletItemException nsee) {
311 throw nsee;
312 }
313 catch (Exception e) {
314 throw processException(e);
315 }
316 finally {
317 closeSession(session);
318 }
319 }
320
321 @Override
322 protected PortletItem removeImpl(PortletItem portletItem)
323 throws SystemException {
324 portletItem = toUnwrappedModel(portletItem);
325
326 Session session = null;
327
328 try {
329 session = openSession();
330
331 if (portletItem.isCachedModel()) {
332 portletItem = (PortletItem)session.get(PortletItemImpl.class,
333 portletItem.getPrimaryKeyObj());
334 }
335
336 session.delete(portletItem);
337 }
338 catch (Exception e) {
339 throw processException(e);
340 }
341 finally {
342 closeSession(session);
343 }
344
345 clearCache(portletItem);
346
347 return portletItem;
348 }
349
350 @Override
351 public PortletItem updateImpl(
352 com.liferay.portal.model.PortletItem portletItem)
353 throws SystemException {
354 portletItem = toUnwrappedModel(portletItem);
355
356 boolean isNew = portletItem.isNew();
357
358 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
359
360 Session session = null;
361
362 try {
363 session = openSession();
364
365 if (portletItem.isNew()) {
366 session.save(portletItem);
367
368 portletItem.setNew(false);
369 }
370 else {
371 session.merge(portletItem);
372 }
373 }
374 catch (Exception e) {
375 throw processException(e);
376 }
377 finally {
378 closeSession(session);
379 }
380
381 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
382
383 if (isNew || !PortletItemModelImpl.COLUMN_BITMASK_ENABLED) {
384 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
385 }
386
387 else {
388 if ((portletItemModelImpl.getColumnBitmask() &
389 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
390 Object[] args = new Object[] {
391 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
392 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
393 };
394
395 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
396 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
397 args);
398
399 args = new Object[] {
400 Long.valueOf(portletItemModelImpl.getGroupId()),
401 Long.valueOf(portletItemModelImpl.getClassNameId())
402 };
403
404 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
405 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
406 args);
407 }
408
409 if ((portletItemModelImpl.getColumnBitmask() &
410 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C.getColumnBitmask()) != 0) {
411 Object[] args = new Object[] {
412 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
413
414 portletItemModelImpl.getOriginalPortletId(),
415 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
416 };
417
418 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
419 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
420 args);
421
422 args = new Object[] {
423 Long.valueOf(portletItemModelImpl.getGroupId()),
424
425 portletItemModelImpl.getPortletId(),
426 Long.valueOf(portletItemModelImpl.getClassNameId())
427 };
428
429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
430 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
431 args);
432 }
433 }
434
435 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
436 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
437
438 if (isNew) {
439 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
440 new Object[] {
441 Long.valueOf(portletItem.getGroupId()),
442
443 portletItem.getName(),
444
445 portletItem.getPortletId(),
446 Long.valueOf(portletItem.getClassNameId())
447 }, portletItem);
448 }
449 else {
450 if ((portletItemModelImpl.getColumnBitmask() &
451 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
452 Object[] args = new Object[] {
453 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
454
455 portletItemModelImpl.getOriginalName(),
456
457 portletItemModelImpl.getOriginalPortletId(),
458 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
459 };
460
461 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
462
463 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
464
465 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
466 new Object[] {
467 Long.valueOf(portletItem.getGroupId()),
468
469 portletItem.getName(),
470
471 portletItem.getPortletId(),
472 Long.valueOf(portletItem.getClassNameId())
473 }, portletItem);
474 }
475 }
476
477 return portletItem;
478 }
479
480 protected PortletItem toUnwrappedModel(PortletItem portletItem) {
481 if (portletItem instanceof PortletItemImpl) {
482 return portletItem;
483 }
484
485 PortletItemImpl portletItemImpl = new PortletItemImpl();
486
487 portletItemImpl.setNew(portletItem.isNew());
488 portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
489
490 portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
491 portletItemImpl.setGroupId(portletItem.getGroupId());
492 portletItemImpl.setCompanyId(portletItem.getCompanyId());
493 portletItemImpl.setUserId(portletItem.getUserId());
494 portletItemImpl.setUserName(portletItem.getUserName());
495 portletItemImpl.setCreateDate(portletItem.getCreateDate());
496 portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
497 portletItemImpl.setName(portletItem.getName());
498 portletItemImpl.setPortletId(portletItem.getPortletId());
499 portletItemImpl.setClassNameId(portletItem.getClassNameId());
500
501 return portletItemImpl;
502 }
503
504
512 @Override
513 public PortletItem findByPrimaryKey(Serializable primaryKey)
514 throws NoSuchModelException, SystemException {
515 return findByPrimaryKey(((Long)primaryKey).longValue());
516 }
517
518
526 public PortletItem findByPrimaryKey(long portletItemId)
527 throws NoSuchPortletItemException, SystemException {
528 PortletItem portletItem = fetchByPrimaryKey(portletItemId);
529
530 if (portletItem == null) {
531 if (_log.isWarnEnabled()) {
532 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
533 }
534
535 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
536 portletItemId);
537 }
538
539 return portletItem;
540 }
541
542
549 @Override
550 public PortletItem fetchByPrimaryKey(Serializable primaryKey)
551 throws SystemException {
552 return fetchByPrimaryKey(((Long)primaryKey).longValue());
553 }
554
555
562 public PortletItem fetchByPrimaryKey(long portletItemId)
563 throws SystemException {
564 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
565 PortletItemImpl.class, portletItemId);
566
567 if (portletItem == _nullPortletItem) {
568 return null;
569 }
570
571 if (portletItem == null) {
572 Session session = null;
573
574 boolean hasException = false;
575
576 try {
577 session = openSession();
578
579 portletItem = (PortletItem)session.get(PortletItemImpl.class,
580 Long.valueOf(portletItemId));
581 }
582 catch (Exception e) {
583 hasException = true;
584
585 throw processException(e);
586 }
587 finally {
588 if (portletItem != null) {
589 cacheResult(portletItem);
590 }
591 else if (!hasException) {
592 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
593 PortletItemImpl.class, portletItemId, _nullPortletItem);
594 }
595
596 closeSession(session);
597 }
598 }
599
600 return portletItem;
601 }
602
603
611 public List<PortletItem> findByG_C(long groupId, long classNameId)
612 throws SystemException {
613 return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
614 QueryUtil.ALL_POS, null);
615 }
616
617
631 public List<PortletItem> findByG_C(long groupId, long classNameId,
632 int start, int end) throws SystemException {
633 return findByG_C(groupId, classNameId, start, end, null);
634 }
635
636
651 public List<PortletItem> findByG_C(long groupId, long classNameId,
652 int start, int end, OrderByComparator orderByComparator)
653 throws SystemException {
654 FinderPath finderPath = null;
655 Object[] finderArgs = null;
656
657 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
658 (orderByComparator == null)) {
659 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
660 finderArgs = new Object[] { groupId, classNameId };
661 }
662 else {
663 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
664 finderArgs = new Object[] {
665 groupId, classNameId,
666
667 start, end, orderByComparator
668 };
669 }
670
671 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
672 finderArgs, this);
673
674 if ((list != null) && !list.isEmpty()) {
675 for (PortletItem portletItem : list) {
676 if ((groupId != portletItem.getGroupId()) ||
677 (classNameId != portletItem.getClassNameId())) {
678 list = null;
679
680 break;
681 }
682 }
683 }
684
685 if (list == null) {
686 StringBundler query = null;
687
688 if (orderByComparator != null) {
689 query = new StringBundler(4 +
690 (orderByComparator.getOrderByFields().length * 3));
691 }
692 else {
693 query = new StringBundler(3);
694 }
695
696 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
697
698 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
699
700 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
701
702 if (orderByComparator != null) {
703 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
704 orderByComparator);
705 }
706
707 String sql = query.toString();
708
709 Session session = null;
710
711 try {
712 session = openSession();
713
714 Query q = session.createQuery(sql);
715
716 QueryPos qPos = QueryPos.getInstance(q);
717
718 qPos.add(groupId);
719
720 qPos.add(classNameId);
721
722 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
723 start, end);
724 }
725 catch (Exception e) {
726 throw processException(e);
727 }
728 finally {
729 if (list == null) {
730 FinderCacheUtil.removeResult(finderPath, finderArgs);
731 }
732 else {
733 cacheResult(list);
734
735 FinderCacheUtil.putResult(finderPath, finderArgs, list);
736 }
737
738 closeSession(session);
739 }
740 }
741
742 return list;
743 }
744
745
755 public PortletItem findByG_C_First(long groupId, long classNameId,
756 OrderByComparator orderByComparator)
757 throws NoSuchPortletItemException, SystemException {
758 PortletItem portletItem = fetchByG_C_First(groupId, classNameId,
759 orderByComparator);
760
761 if (portletItem != null) {
762 return portletItem;
763 }
764
765 StringBundler msg = new StringBundler(6);
766
767 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
768
769 msg.append("groupId=");
770 msg.append(groupId);
771
772 msg.append(", classNameId=");
773 msg.append(classNameId);
774
775 msg.append(StringPool.CLOSE_CURLY_BRACE);
776
777 throw new NoSuchPortletItemException(msg.toString());
778 }
779
780
789 public PortletItem fetchByG_C_First(long groupId, long classNameId,
790 OrderByComparator orderByComparator) throws SystemException {
791 List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
792 orderByComparator);
793
794 if (!list.isEmpty()) {
795 return list.get(0);
796 }
797
798 return null;
799 }
800
801
811 public PortletItem findByG_C_Last(long groupId, long classNameId,
812 OrderByComparator orderByComparator)
813 throws NoSuchPortletItemException, SystemException {
814 PortletItem portletItem = fetchByG_C_Last(groupId, classNameId,
815 orderByComparator);
816
817 if (portletItem != null) {
818 return portletItem;
819 }
820
821 StringBundler msg = new StringBundler(6);
822
823 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824
825 msg.append("groupId=");
826 msg.append(groupId);
827
828 msg.append(", classNameId=");
829 msg.append(classNameId);
830
831 msg.append(StringPool.CLOSE_CURLY_BRACE);
832
833 throw new NoSuchPortletItemException(msg.toString());
834 }
835
836
845 public PortletItem fetchByG_C_Last(long groupId, long classNameId,
846 OrderByComparator orderByComparator) throws SystemException {
847 int count = countByG_C(groupId, classNameId);
848
849 List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
850 count, orderByComparator);
851
852 if (!list.isEmpty()) {
853 return list.get(0);
854 }
855
856 return null;
857 }
858
859
870 public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
871 long groupId, long classNameId, OrderByComparator orderByComparator)
872 throws NoSuchPortletItemException, SystemException {
873 PortletItem portletItem = findByPrimaryKey(portletItemId);
874
875 Session session = null;
876
877 try {
878 session = openSession();
879
880 PortletItem[] array = new PortletItemImpl[3];
881
882 array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
883 classNameId, orderByComparator, true);
884
885 array[1] = portletItem;
886
887 array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
888 classNameId, orderByComparator, false);
889
890 return array;
891 }
892 catch (Exception e) {
893 throw processException(e);
894 }
895 finally {
896 closeSession(session);
897 }
898 }
899
900 protected PortletItem getByG_C_PrevAndNext(Session session,
901 PortletItem portletItem, long groupId, long classNameId,
902 OrderByComparator orderByComparator, boolean previous) {
903 StringBundler query = null;
904
905 if (orderByComparator != null) {
906 query = new StringBundler(6 +
907 (orderByComparator.getOrderByFields().length * 6));
908 }
909 else {
910 query = new StringBundler(3);
911 }
912
913 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
914
915 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
916
917 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
918
919 if (orderByComparator != null) {
920 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
921
922 if (orderByConditionFields.length > 0) {
923 query.append(WHERE_AND);
924 }
925
926 for (int i = 0; i < orderByConditionFields.length; i++) {
927 query.append(_ORDER_BY_ENTITY_ALIAS);
928 query.append(orderByConditionFields[i]);
929
930 if ((i + 1) < orderByConditionFields.length) {
931 if (orderByComparator.isAscending() ^ previous) {
932 query.append(WHERE_GREATER_THAN_HAS_NEXT);
933 }
934 else {
935 query.append(WHERE_LESSER_THAN_HAS_NEXT);
936 }
937 }
938 else {
939 if (orderByComparator.isAscending() ^ previous) {
940 query.append(WHERE_GREATER_THAN);
941 }
942 else {
943 query.append(WHERE_LESSER_THAN);
944 }
945 }
946 }
947
948 query.append(ORDER_BY_CLAUSE);
949
950 String[] orderByFields = orderByComparator.getOrderByFields();
951
952 for (int i = 0; i < orderByFields.length; i++) {
953 query.append(_ORDER_BY_ENTITY_ALIAS);
954 query.append(orderByFields[i]);
955
956 if ((i + 1) < orderByFields.length) {
957 if (orderByComparator.isAscending() ^ previous) {
958 query.append(ORDER_BY_ASC_HAS_NEXT);
959 }
960 else {
961 query.append(ORDER_BY_DESC_HAS_NEXT);
962 }
963 }
964 else {
965 if (orderByComparator.isAscending() ^ previous) {
966 query.append(ORDER_BY_ASC);
967 }
968 else {
969 query.append(ORDER_BY_DESC);
970 }
971 }
972 }
973 }
974
975 String sql = query.toString();
976
977 Query q = session.createQuery(sql);
978
979 q.setFirstResult(0);
980 q.setMaxResults(2);
981
982 QueryPos qPos = QueryPos.getInstance(q);
983
984 qPos.add(groupId);
985
986 qPos.add(classNameId);
987
988 if (orderByComparator != null) {
989 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
990
991 for (Object value : values) {
992 qPos.add(value);
993 }
994 }
995
996 List<PortletItem> list = q.list();
997
998 if (list.size() == 2) {
999 return list.get(1);
1000 }
1001 else {
1002 return null;
1003 }
1004 }
1005
1006
1015 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1016 long classNameId) throws SystemException {
1017 return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
1018 QueryUtil.ALL_POS, null);
1019 }
1020
1021
1036 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1037 long classNameId, int start, int end) throws SystemException {
1038 return findByG_P_C(groupId, portletId, classNameId, start, end, null);
1039 }
1040
1041
1057 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1058 long classNameId, int start, int end,
1059 OrderByComparator orderByComparator) throws SystemException {
1060 FinderPath finderPath = null;
1061 Object[] finderArgs = null;
1062
1063 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1064 (orderByComparator == null)) {
1065 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C;
1066 finderArgs = new Object[] { groupId, portletId, classNameId };
1067 }
1068 else {
1069 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C;
1070 finderArgs = new Object[] {
1071 groupId, portletId, classNameId,
1072
1073 start, end, orderByComparator
1074 };
1075 }
1076
1077 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
1078 finderArgs, this);
1079
1080 if ((list != null) && !list.isEmpty()) {
1081 for (PortletItem portletItem : list) {
1082 if ((groupId != portletItem.getGroupId()) ||
1083 !Validator.equals(portletId, portletItem.getPortletId()) ||
1084 (classNameId != portletItem.getClassNameId())) {
1085 list = null;
1086
1087 break;
1088 }
1089 }
1090 }
1091
1092 if (list == null) {
1093 StringBundler query = null;
1094
1095 if (orderByComparator != null) {
1096 query = new StringBundler(5 +
1097 (orderByComparator.getOrderByFields().length * 3));
1098 }
1099 else {
1100 query = new StringBundler(4);
1101 }
1102
1103 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1104
1105 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1106
1107 if (portletId == null) {
1108 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1109 }
1110 else {
1111 if (portletId.equals(StringPool.BLANK)) {
1112 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1113 }
1114 else {
1115 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1116 }
1117 }
1118
1119 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1120
1121 if (orderByComparator != null) {
1122 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1123 orderByComparator);
1124 }
1125
1126 String sql = query.toString();
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 Query q = session.createQuery(sql);
1134
1135 QueryPos qPos = QueryPos.getInstance(q);
1136
1137 qPos.add(groupId);
1138
1139 if (portletId != null) {
1140 qPos.add(portletId);
1141 }
1142
1143 qPos.add(classNameId);
1144
1145 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1146 start, end);
1147 }
1148 catch (Exception e) {
1149 throw processException(e);
1150 }
1151 finally {
1152 if (list == null) {
1153 FinderCacheUtil.removeResult(finderPath, finderArgs);
1154 }
1155 else {
1156 cacheResult(list);
1157
1158 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1159 }
1160
1161 closeSession(session);
1162 }
1163 }
1164
1165 return list;
1166 }
1167
1168
1179 public PortletItem findByG_P_C_First(long groupId, String portletId,
1180 long classNameId, OrderByComparator orderByComparator)
1181 throws NoSuchPortletItemException, SystemException {
1182 PortletItem portletItem = fetchByG_P_C_First(groupId, portletId,
1183 classNameId, orderByComparator);
1184
1185 if (portletItem != null) {
1186 return portletItem;
1187 }
1188
1189 StringBundler msg = new StringBundler(8);
1190
1191 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1192
1193 msg.append("groupId=");
1194 msg.append(groupId);
1195
1196 msg.append(", portletId=");
1197 msg.append(portletId);
1198
1199 msg.append(", classNameId=");
1200 msg.append(classNameId);
1201
1202 msg.append(StringPool.CLOSE_CURLY_BRACE);
1203
1204 throw new NoSuchPortletItemException(msg.toString());
1205 }
1206
1207
1217 public PortletItem fetchByG_P_C_First(long groupId, String portletId,
1218 long classNameId, OrderByComparator orderByComparator)
1219 throws SystemException {
1220 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
1221 0, 1, orderByComparator);
1222
1223 if (!list.isEmpty()) {
1224 return list.get(0);
1225 }
1226
1227 return null;
1228 }
1229
1230
1241 public PortletItem findByG_P_C_Last(long groupId, String portletId,
1242 long classNameId, OrderByComparator orderByComparator)
1243 throws NoSuchPortletItemException, SystemException {
1244 PortletItem portletItem = fetchByG_P_C_Last(groupId, portletId,
1245 classNameId, orderByComparator);
1246
1247 if (portletItem != null) {
1248 return portletItem;
1249 }
1250
1251 StringBundler msg = new StringBundler(8);
1252
1253 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1254
1255 msg.append("groupId=");
1256 msg.append(groupId);
1257
1258 msg.append(", portletId=");
1259 msg.append(portletId);
1260
1261 msg.append(", classNameId=");
1262 msg.append(classNameId);
1263
1264 msg.append(StringPool.CLOSE_CURLY_BRACE);
1265
1266 throw new NoSuchPortletItemException(msg.toString());
1267 }
1268
1269
1279 public PortletItem fetchByG_P_C_Last(long groupId, String portletId,
1280 long classNameId, OrderByComparator orderByComparator)
1281 throws SystemException {
1282 int count = countByG_P_C(groupId, portletId, classNameId);
1283
1284 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
1285 count - 1, count, orderByComparator);
1286
1287 if (!list.isEmpty()) {
1288 return list.get(0);
1289 }
1290
1291 return null;
1292 }
1293
1294
1306 public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
1307 long groupId, String portletId, long classNameId,
1308 OrderByComparator orderByComparator)
1309 throws NoSuchPortletItemException, SystemException {
1310 PortletItem portletItem = findByPrimaryKey(portletItemId);
1311
1312 Session session = null;
1313
1314 try {
1315 session = openSession();
1316
1317 PortletItem[] array = new PortletItemImpl[3];
1318
1319 array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
1320 portletId, classNameId, orderByComparator, true);
1321
1322 array[1] = portletItem;
1323
1324 array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
1325 portletId, classNameId, orderByComparator, false);
1326
1327 return array;
1328 }
1329 catch (Exception e) {
1330 throw processException(e);
1331 }
1332 finally {
1333 closeSession(session);
1334 }
1335 }
1336
1337 protected PortletItem getByG_P_C_PrevAndNext(Session session,
1338 PortletItem portletItem, long groupId, String portletId,
1339 long classNameId, OrderByComparator orderByComparator, boolean previous) {
1340 StringBundler query = null;
1341
1342 if (orderByComparator != null) {
1343 query = new StringBundler(6 +
1344 (orderByComparator.getOrderByFields().length * 6));
1345 }
1346 else {
1347 query = new StringBundler(3);
1348 }
1349
1350 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1351
1352 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1353
1354 if (portletId == null) {
1355 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1356 }
1357 else {
1358 if (portletId.equals(StringPool.BLANK)) {
1359 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1360 }
1361 else {
1362 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1363 }
1364 }
1365
1366 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1367
1368 if (orderByComparator != null) {
1369 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1370
1371 if (orderByConditionFields.length > 0) {
1372 query.append(WHERE_AND);
1373 }
1374
1375 for (int i = 0; i < orderByConditionFields.length; i++) {
1376 query.append(_ORDER_BY_ENTITY_ALIAS);
1377 query.append(orderByConditionFields[i]);
1378
1379 if ((i + 1) < orderByConditionFields.length) {
1380 if (orderByComparator.isAscending() ^ previous) {
1381 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1382 }
1383 else {
1384 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1385 }
1386 }
1387 else {
1388 if (orderByComparator.isAscending() ^ previous) {
1389 query.append(WHERE_GREATER_THAN);
1390 }
1391 else {
1392 query.append(WHERE_LESSER_THAN);
1393 }
1394 }
1395 }
1396
1397 query.append(ORDER_BY_CLAUSE);
1398
1399 String[] orderByFields = orderByComparator.getOrderByFields();
1400
1401 for (int i = 0; i < orderByFields.length; i++) {
1402 query.append(_ORDER_BY_ENTITY_ALIAS);
1403 query.append(orderByFields[i]);
1404
1405 if ((i + 1) < orderByFields.length) {
1406 if (orderByComparator.isAscending() ^ previous) {
1407 query.append(ORDER_BY_ASC_HAS_NEXT);
1408 }
1409 else {
1410 query.append(ORDER_BY_DESC_HAS_NEXT);
1411 }
1412 }
1413 else {
1414 if (orderByComparator.isAscending() ^ previous) {
1415 query.append(ORDER_BY_ASC);
1416 }
1417 else {
1418 query.append(ORDER_BY_DESC);
1419 }
1420 }
1421 }
1422 }
1423
1424 String sql = query.toString();
1425
1426 Query q = session.createQuery(sql);
1427
1428 q.setFirstResult(0);
1429 q.setMaxResults(2);
1430
1431 QueryPos qPos = QueryPos.getInstance(q);
1432
1433 qPos.add(groupId);
1434
1435 if (portletId != null) {
1436 qPos.add(portletId);
1437 }
1438
1439 qPos.add(classNameId);
1440
1441 if (orderByComparator != null) {
1442 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1443
1444 for (Object value : values) {
1445 qPos.add(value);
1446 }
1447 }
1448
1449 List<PortletItem> list = q.list();
1450
1451 if (list.size() == 2) {
1452 return list.get(1);
1453 }
1454 else {
1455 return null;
1456 }
1457 }
1458
1459
1470 public PortletItem findByG_N_P_C(long groupId, String name,
1471 String portletId, long classNameId)
1472 throws NoSuchPortletItemException, SystemException {
1473 PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1474 classNameId);
1475
1476 if (portletItem == null) {
1477 StringBundler msg = new StringBundler(10);
1478
1479 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1480
1481 msg.append("groupId=");
1482 msg.append(groupId);
1483
1484 msg.append(", name=");
1485 msg.append(name);
1486
1487 msg.append(", portletId=");
1488 msg.append(portletId);
1489
1490 msg.append(", classNameId=");
1491 msg.append(classNameId);
1492
1493 msg.append(StringPool.CLOSE_CURLY_BRACE);
1494
1495 if (_log.isWarnEnabled()) {
1496 _log.warn(msg.toString());
1497 }
1498
1499 throw new NoSuchPortletItemException(msg.toString());
1500 }
1501
1502 return portletItem;
1503 }
1504
1505
1515 public PortletItem fetchByG_N_P_C(long groupId, String name,
1516 String portletId, long classNameId) throws SystemException {
1517 return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1518 }
1519
1520
1531 public PortletItem fetchByG_N_P_C(long groupId, String name,
1532 String portletId, long classNameId, boolean retrieveFromCache)
1533 throws SystemException {
1534 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1535
1536 Object result = null;
1537
1538 if (retrieveFromCache) {
1539 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1540 finderArgs, this);
1541 }
1542
1543 if (result instanceof PortletItem) {
1544 PortletItem portletItem = (PortletItem)result;
1545
1546 if ((groupId != portletItem.getGroupId()) ||
1547 !Validator.equals(name, portletItem.getName()) ||
1548 !Validator.equals(portletId, portletItem.getPortletId()) ||
1549 (classNameId != portletItem.getClassNameId())) {
1550 result = null;
1551 }
1552 }
1553
1554 if (result == null) {
1555 StringBundler query = new StringBundler(5);
1556
1557 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1558
1559 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1560
1561 if (name == null) {
1562 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1563 }
1564 else {
1565 if (name.equals(StringPool.BLANK)) {
1566 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1567 }
1568 else {
1569 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1570 }
1571 }
1572
1573 if (portletId == null) {
1574 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1575 }
1576 else {
1577 if (portletId.equals(StringPool.BLANK)) {
1578 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1579 }
1580 else {
1581 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1582 }
1583 }
1584
1585 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1586
1587 String sql = query.toString();
1588
1589 Session session = null;
1590
1591 try {
1592 session = openSession();
1593
1594 Query q = session.createQuery(sql);
1595
1596 QueryPos qPos = QueryPos.getInstance(q);
1597
1598 qPos.add(groupId);
1599
1600 if (name != null) {
1601 qPos.add(name);
1602 }
1603
1604 if (portletId != null) {
1605 qPos.add(portletId);
1606 }
1607
1608 qPos.add(classNameId);
1609
1610 List<PortletItem> list = q.list();
1611
1612 result = list;
1613
1614 PortletItem portletItem = null;
1615
1616 if (list.isEmpty()) {
1617 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1618 finderArgs, list);
1619 }
1620 else {
1621 portletItem = list.get(0);
1622
1623 cacheResult(portletItem);
1624
1625 if ((portletItem.getGroupId() != groupId) ||
1626 (portletItem.getName() == null) ||
1627 !portletItem.getName().equals(name) ||
1628 (portletItem.getPortletId() == null) ||
1629 !portletItem.getPortletId().equals(portletId) ||
1630 (portletItem.getClassNameId() != classNameId)) {
1631 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1632 finderArgs, portletItem);
1633 }
1634 }
1635
1636 return portletItem;
1637 }
1638 catch (Exception e) {
1639 throw processException(e);
1640 }
1641 finally {
1642 if (result == null) {
1643 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1644 finderArgs);
1645 }
1646
1647 closeSession(session);
1648 }
1649 }
1650 else {
1651 if (result instanceof List<?>) {
1652 return null;
1653 }
1654 else {
1655 return (PortletItem)result;
1656 }
1657 }
1658 }
1659
1660
1666 public List<PortletItem> findAll() throws SystemException {
1667 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1668 }
1669
1670
1682 public List<PortletItem> findAll(int start, int end)
1683 throws SystemException {
1684 return findAll(start, end, null);
1685 }
1686
1687
1700 public List<PortletItem> findAll(int start, int end,
1701 OrderByComparator orderByComparator) throws SystemException {
1702 FinderPath finderPath = null;
1703 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1704
1705 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1706 (orderByComparator == null)) {
1707 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1708 finderArgs = FINDER_ARGS_EMPTY;
1709 }
1710 else {
1711 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1712 finderArgs = new Object[] { start, end, orderByComparator };
1713 }
1714
1715 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
1716 finderArgs, this);
1717
1718 if (list == null) {
1719 StringBundler query = null;
1720 String sql = null;
1721
1722 if (orderByComparator != null) {
1723 query = new StringBundler(2 +
1724 (orderByComparator.getOrderByFields().length * 3));
1725
1726 query.append(_SQL_SELECT_PORTLETITEM);
1727
1728 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1729 orderByComparator);
1730
1731 sql = query.toString();
1732 }
1733 else {
1734 sql = _SQL_SELECT_PORTLETITEM;
1735 }
1736
1737 Session session = null;
1738
1739 try {
1740 session = openSession();
1741
1742 Query q = session.createQuery(sql);
1743
1744 if (orderByComparator == null) {
1745 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1746 start, end, false);
1747
1748 Collections.sort(list);
1749 }
1750 else {
1751 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1752 start, end);
1753 }
1754 }
1755 catch (Exception e) {
1756 throw processException(e);
1757 }
1758 finally {
1759 if (list == null) {
1760 FinderCacheUtil.removeResult(finderPath, finderArgs);
1761 }
1762 else {
1763 cacheResult(list);
1764
1765 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1766 }
1767
1768 closeSession(session);
1769 }
1770 }
1771
1772 return list;
1773 }
1774
1775
1782 public void removeByG_C(long groupId, long classNameId)
1783 throws SystemException {
1784 for (PortletItem portletItem : findByG_C(groupId, classNameId)) {
1785 remove(portletItem);
1786 }
1787 }
1788
1789
1797 public void removeByG_P_C(long groupId, String portletId, long classNameId)
1798 throws SystemException {
1799 for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1800 classNameId)) {
1801 remove(portletItem);
1802 }
1803 }
1804
1805
1815 public PortletItem removeByG_N_P_C(long groupId, String name,
1816 String portletId, long classNameId)
1817 throws NoSuchPortletItemException, SystemException {
1818 PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1819 classNameId);
1820
1821 return remove(portletItem);
1822 }
1823
1824
1829 public void removeAll() throws SystemException {
1830 for (PortletItem portletItem : findAll()) {
1831 remove(portletItem);
1832 }
1833 }
1834
1835
1843 public int countByG_C(long groupId, long classNameId)
1844 throws SystemException {
1845 Object[] finderArgs = new Object[] { groupId, classNameId };
1846
1847 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1848 finderArgs, this);
1849
1850 if (count == null) {
1851 StringBundler query = new StringBundler(3);
1852
1853 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1854
1855 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1856
1857 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1858
1859 String sql = query.toString();
1860
1861 Session session = null;
1862
1863 try {
1864 session = openSession();
1865
1866 Query q = session.createQuery(sql);
1867
1868 QueryPos qPos = QueryPos.getInstance(q);
1869
1870 qPos.add(groupId);
1871
1872 qPos.add(classNameId);
1873
1874 count = (Long)q.uniqueResult();
1875 }
1876 catch (Exception e) {
1877 throw processException(e);
1878 }
1879 finally {
1880 if (count == null) {
1881 count = Long.valueOf(0);
1882 }
1883
1884 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1885 count);
1886
1887 closeSession(session);
1888 }
1889 }
1890
1891 return count.intValue();
1892 }
1893
1894
1903 public int countByG_P_C(long groupId, String portletId, long classNameId)
1904 throws SystemException {
1905 Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1906
1907 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_C,
1908 finderArgs, this);
1909
1910 if (count == null) {
1911 StringBundler query = new StringBundler(4);
1912
1913 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1914
1915 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1916
1917 if (portletId == null) {
1918 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1919 }
1920 else {
1921 if (portletId.equals(StringPool.BLANK)) {
1922 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1923 }
1924 else {
1925 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1926 }
1927 }
1928
1929 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1930
1931 String sql = query.toString();
1932
1933 Session session = null;
1934
1935 try {
1936 session = openSession();
1937
1938 Query q = session.createQuery(sql);
1939
1940 QueryPos qPos = QueryPos.getInstance(q);
1941
1942 qPos.add(groupId);
1943
1944 if (portletId != null) {
1945 qPos.add(portletId);
1946 }
1947
1948 qPos.add(classNameId);
1949
1950 count = (Long)q.uniqueResult();
1951 }
1952 catch (Exception e) {
1953 throw processException(e);
1954 }
1955 finally {
1956 if (count == null) {
1957 count = Long.valueOf(0);
1958 }
1959
1960 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_C,
1961 finderArgs, count);
1962
1963 closeSession(session);
1964 }
1965 }
1966
1967 return count.intValue();
1968 }
1969
1970
1980 public int countByG_N_P_C(long groupId, String name, String portletId,
1981 long classNameId) throws SystemException {
1982 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1983
1984 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1985 finderArgs, this);
1986
1987 if (count == null) {
1988 StringBundler query = new StringBundler(5);
1989
1990 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1991
1992 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1993
1994 if (name == null) {
1995 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1996 }
1997 else {
1998 if (name.equals(StringPool.BLANK)) {
1999 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
2000 }
2001 else {
2002 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
2003 }
2004 }
2005
2006 if (portletId == null) {
2007 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
2008 }
2009 else {
2010 if (portletId.equals(StringPool.BLANK)) {
2011 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
2012 }
2013 else {
2014 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
2015 }
2016 }
2017
2018 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
2019
2020 String sql = query.toString();
2021
2022 Session session = null;
2023
2024 try {
2025 session = openSession();
2026
2027 Query q = session.createQuery(sql);
2028
2029 QueryPos qPos = QueryPos.getInstance(q);
2030
2031 qPos.add(groupId);
2032
2033 if (name != null) {
2034 qPos.add(name);
2035 }
2036
2037 if (portletId != null) {
2038 qPos.add(portletId);
2039 }
2040
2041 qPos.add(classNameId);
2042
2043 count = (Long)q.uniqueResult();
2044 }
2045 catch (Exception e) {
2046 throw processException(e);
2047 }
2048 finally {
2049 if (count == null) {
2050 count = Long.valueOf(0);
2051 }
2052
2053 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C,
2054 finderArgs, count);
2055
2056 closeSession(session);
2057 }
2058 }
2059
2060 return count.intValue();
2061 }
2062
2063
2069 public int countAll() throws SystemException {
2070 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2071 FINDER_ARGS_EMPTY, this);
2072
2073 if (count == null) {
2074 Session session = null;
2075
2076 try {
2077 session = openSession();
2078
2079 Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
2080
2081 count = (Long)q.uniqueResult();
2082 }
2083 catch (Exception e) {
2084 throw processException(e);
2085 }
2086 finally {
2087 if (count == null) {
2088 count = Long.valueOf(0);
2089 }
2090
2091 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2092 FINDER_ARGS_EMPTY, count);
2093
2094 closeSession(session);
2095 }
2096 }
2097
2098 return count.intValue();
2099 }
2100
2101
2104 public void afterPropertiesSet() {
2105 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2106 com.liferay.portal.util.PropsUtil.get(
2107 "value.object.listener.com.liferay.portal.model.PortletItem")));
2108
2109 if (listenerClassNames.length > 0) {
2110 try {
2111 List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
2112
2113 for (String listenerClassName : listenerClassNames) {
2114 listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
2115 listenerClassName));
2116 }
2117
2118 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2119 }
2120 catch (Exception e) {
2121 _log.error(e);
2122 }
2123 }
2124 }
2125
2126 public void destroy() {
2127 EntityCacheUtil.removeCache(PortletItemImpl.class.getName());
2128 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2129 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2130 }
2131
2132 @BeanReference(type = AccountPersistence.class)
2133 protected AccountPersistence accountPersistence;
2134 @BeanReference(type = AddressPersistence.class)
2135 protected AddressPersistence addressPersistence;
2136 @BeanReference(type = BrowserTrackerPersistence.class)
2137 protected BrowserTrackerPersistence browserTrackerPersistence;
2138 @BeanReference(type = ClassNamePersistence.class)
2139 protected ClassNamePersistence classNamePersistence;
2140 @BeanReference(type = ClusterGroupPersistence.class)
2141 protected ClusterGroupPersistence clusterGroupPersistence;
2142 @BeanReference(type = CompanyPersistence.class)
2143 protected CompanyPersistence companyPersistence;
2144 @BeanReference(type = ContactPersistence.class)
2145 protected ContactPersistence contactPersistence;
2146 @BeanReference(type = CountryPersistence.class)
2147 protected CountryPersistence countryPersistence;
2148 @BeanReference(type = EmailAddressPersistence.class)
2149 protected EmailAddressPersistence emailAddressPersistence;
2150 @BeanReference(type = GroupPersistence.class)
2151 protected GroupPersistence groupPersistence;
2152 @BeanReference(type = ImagePersistence.class)
2153 protected ImagePersistence imagePersistence;
2154 @BeanReference(type = LayoutPersistence.class)
2155 protected LayoutPersistence layoutPersistence;
2156 @BeanReference(type = LayoutBranchPersistence.class)
2157 protected LayoutBranchPersistence layoutBranchPersistence;
2158 @BeanReference(type = LayoutPrototypePersistence.class)
2159 protected LayoutPrototypePersistence layoutPrototypePersistence;
2160 @BeanReference(type = LayoutRevisionPersistence.class)
2161 protected LayoutRevisionPersistence layoutRevisionPersistence;
2162 @BeanReference(type = LayoutSetPersistence.class)
2163 protected LayoutSetPersistence layoutSetPersistence;
2164 @BeanReference(type = LayoutSetBranchPersistence.class)
2165 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2166 @BeanReference(type = LayoutSetPrototypePersistence.class)
2167 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2168 @BeanReference(type = ListTypePersistence.class)
2169 protected ListTypePersistence listTypePersistence;
2170 @BeanReference(type = LockPersistence.class)
2171 protected LockPersistence lockPersistence;
2172 @BeanReference(type = MembershipRequestPersistence.class)
2173 protected MembershipRequestPersistence membershipRequestPersistence;
2174 @BeanReference(type = OrganizationPersistence.class)
2175 protected OrganizationPersistence organizationPersistence;
2176 @BeanReference(type = OrgGroupRolePersistence.class)
2177 protected OrgGroupRolePersistence orgGroupRolePersistence;
2178 @BeanReference(type = OrgLaborPersistence.class)
2179 protected OrgLaborPersistence orgLaborPersistence;
2180 @BeanReference(type = PasswordPolicyPersistence.class)
2181 protected PasswordPolicyPersistence passwordPolicyPersistence;
2182 @BeanReference(type = PasswordPolicyRelPersistence.class)
2183 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2184 @BeanReference(type = PasswordTrackerPersistence.class)
2185 protected PasswordTrackerPersistence passwordTrackerPersistence;
2186 @BeanReference(type = PhonePersistence.class)
2187 protected PhonePersistence phonePersistence;
2188 @BeanReference(type = PluginSettingPersistence.class)
2189 protected PluginSettingPersistence pluginSettingPersistence;
2190 @BeanReference(type = PortalPreferencesPersistence.class)
2191 protected PortalPreferencesPersistence portalPreferencesPersistence;
2192 @BeanReference(type = PortletPersistence.class)
2193 protected PortletPersistence portletPersistence;
2194 @BeanReference(type = PortletItemPersistence.class)
2195 protected PortletItemPersistence portletItemPersistence;
2196 @BeanReference(type = PortletPreferencesPersistence.class)
2197 protected PortletPreferencesPersistence portletPreferencesPersistence;
2198 @BeanReference(type = RegionPersistence.class)
2199 protected RegionPersistence regionPersistence;
2200 @BeanReference(type = ReleasePersistence.class)
2201 protected ReleasePersistence releasePersistence;
2202 @BeanReference(type = RepositoryPersistence.class)
2203 protected RepositoryPersistence repositoryPersistence;
2204 @BeanReference(type = RepositoryEntryPersistence.class)
2205 protected RepositoryEntryPersistence repositoryEntryPersistence;
2206 @BeanReference(type = ResourceActionPersistence.class)
2207 protected ResourceActionPersistence resourceActionPersistence;
2208 @BeanReference(type = ResourceBlockPersistence.class)
2209 protected ResourceBlockPersistence resourceBlockPersistence;
2210 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2211 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2212 @BeanReference(type = ResourcePermissionPersistence.class)
2213 protected ResourcePermissionPersistence resourcePermissionPersistence;
2214 @BeanReference(type = ResourceTypePermissionPersistence.class)
2215 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2216 @BeanReference(type = RolePersistence.class)
2217 protected RolePersistence rolePersistence;
2218 @BeanReference(type = ServiceComponentPersistence.class)
2219 protected ServiceComponentPersistence serviceComponentPersistence;
2220 @BeanReference(type = ShardPersistence.class)
2221 protected ShardPersistence shardPersistence;
2222 @BeanReference(type = SubscriptionPersistence.class)
2223 protected SubscriptionPersistence subscriptionPersistence;
2224 @BeanReference(type = TeamPersistence.class)
2225 protected TeamPersistence teamPersistence;
2226 @BeanReference(type = TicketPersistence.class)
2227 protected TicketPersistence ticketPersistence;
2228 @BeanReference(type = UserPersistence.class)
2229 protected UserPersistence userPersistence;
2230 @BeanReference(type = UserGroupPersistence.class)
2231 protected UserGroupPersistence userGroupPersistence;
2232 @BeanReference(type = UserGroupGroupRolePersistence.class)
2233 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2234 @BeanReference(type = UserGroupRolePersistence.class)
2235 protected UserGroupRolePersistence userGroupRolePersistence;
2236 @BeanReference(type = UserIdMapperPersistence.class)
2237 protected UserIdMapperPersistence userIdMapperPersistence;
2238 @BeanReference(type = UserNotificationEventPersistence.class)
2239 protected UserNotificationEventPersistence userNotificationEventPersistence;
2240 @BeanReference(type = UserTrackerPersistence.class)
2241 protected UserTrackerPersistence userTrackerPersistence;
2242 @BeanReference(type = UserTrackerPathPersistence.class)
2243 protected UserTrackerPathPersistence userTrackerPathPersistence;
2244 @BeanReference(type = VirtualHostPersistence.class)
2245 protected VirtualHostPersistence virtualHostPersistence;
2246 @BeanReference(type = WebDAVPropsPersistence.class)
2247 protected WebDAVPropsPersistence webDAVPropsPersistence;
2248 @BeanReference(type = WebsitePersistence.class)
2249 protected WebsitePersistence websitePersistence;
2250 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2251 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2252 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2253 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2254 private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
2255 private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
2256 private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
2257 private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
2258 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2259 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2260 private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2261 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
2262 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
2263 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
2264 private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2265 private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2266 private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
2267 private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = lower(CAST_TEXT(?)) AND ";
2268 private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR lower(portletItem.name) = lower(CAST_TEXT(?))) AND ";
2269 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
2270 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
2271 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
2272 private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2273 private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
2274 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
2275 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
2276 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2277 private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
2278 private static PortletItem _nullPortletItem = new PortletItemImpl() {
2279 @Override
2280 public Object clone() {
2281 return this;
2282 }
2283
2284 @Override
2285 public CacheModel<PortletItem> toCacheModel() {
2286 return _nullPortletItemCacheModel;
2287 }
2288 };
2289
2290 private static CacheModel<PortletItem> _nullPortletItemCacheModel = new CacheModel<PortletItem>() {
2291 public PortletItem toEntityModel() {
2292 return _nullPortletItem;
2293 }
2294 };
2295 }