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.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.PortletItem;
040 import com.liferay.portal.model.impl.PortletItemImpl;
041 import com.liferay.portal.model.impl.PortletItemModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class PortletItemPersistenceImpl extends BasePersistenceImpl<PortletItem>
063 implements PortletItemPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = PortletItemImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
075 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
077 new String[] {
078 Long.class.getName(), Long.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
084 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
086 new String[] { Long.class.getName(), Long.class.getName() },
087 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
088 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
089 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
090 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
092 new String[] { Long.class.getName(), Long.class.getName() });
093 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
094 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
095 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_C",
096 new String[] {
097 Long.class.getName(), String.class.getName(),
098 Long.class.getName(),
099
100 "java.lang.Integer", "java.lang.Integer",
101 "com.liferay.portal.kernel.util.OrderByComparator"
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
104 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_C",
106 new String[] {
107 Long.class.getName(), String.class.getName(),
108 Long.class.getName()
109 },
110 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
111 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
112 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
113 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
114 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_C",
116 new String[] {
117 Long.class.getName(), String.class.getName(),
118 Long.class.getName()
119 });
120 public static final FinderPath FINDER_PATH_FETCH_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
121 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
122 FINDER_CLASS_NAME_ENTITY, "fetchByG_N_P_C",
123 new String[] {
124 Long.class.getName(), String.class.getName(),
125 String.class.getName(), Long.class.getName()
126 },
127 PortletItemModelImpl.GROUPID_COLUMN_BITMASK |
128 PortletItemModelImpl.NAME_COLUMN_BITMASK |
129 PortletItemModelImpl.PORTLETID_COLUMN_BITMASK |
130 PortletItemModelImpl.CLASSNAMEID_COLUMN_BITMASK);
131 public static final FinderPath FINDER_PATH_COUNT_BY_G_N_P_C = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
132 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
133 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_P_C",
134 new String[] {
135 Long.class.getName(), String.class.getName(),
136 String.class.getName(), Long.class.getName()
137 });
138 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
139 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
140 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
141 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
142 PortletItemModelImpl.FINDER_CACHE_ENABLED, PortletItemImpl.class,
143 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
144 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
145 PortletItemModelImpl.FINDER_CACHE_ENABLED, Long.class,
146 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
147
148
153 public void cacheResult(PortletItem portletItem) {
154 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
155 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
156
157 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
158 new Object[] {
159 Long.valueOf(portletItem.getGroupId()),
160
161 portletItem.getName(),
162
163 portletItem.getPortletId(),
164 Long.valueOf(portletItem.getClassNameId())
165 }, portletItem);
166
167 portletItem.resetOriginalValues();
168 }
169
170
175 public void cacheResult(List<PortletItem> portletItems) {
176 for (PortletItem portletItem : portletItems) {
177 if (EntityCacheUtil.getResult(
178 PortletItemModelImpl.ENTITY_CACHE_ENABLED,
179 PortletItemImpl.class, portletItem.getPrimaryKey()) == null) {
180 cacheResult(portletItem);
181 }
182 else {
183 portletItem.resetOriginalValues();
184 }
185 }
186 }
187
188
195 @Override
196 public void clearCache() {
197 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
198 CacheRegistryUtil.clear(PortletItemImpl.class.getName());
199 }
200
201 EntityCacheUtil.clearCache(PortletItemImpl.class.getName());
202
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206 }
207
208
215 @Override
216 public void clearCache(PortletItem portletItem) {
217 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
218 PortletItemImpl.class, portletItem.getPrimaryKey());
219
220 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
222
223 clearUniqueFindersCache(portletItem);
224 }
225
226 @Override
227 public void clearCache(List<PortletItem> portletItems) {
228 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
230
231 for (PortletItem portletItem : portletItems) {
232 EntityCacheUtil.removeResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
233 PortletItemImpl.class, portletItem.getPrimaryKey());
234
235 clearUniqueFindersCache(portletItem);
236 }
237 }
238
239 protected void clearUniqueFindersCache(PortletItem portletItem) {
240 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
241 new Object[] {
242 Long.valueOf(portletItem.getGroupId()),
243
244 portletItem.getName(),
245
246 portletItem.getPortletId(),
247 Long.valueOf(portletItem.getClassNameId())
248 });
249 }
250
251
257 public PortletItem create(long portletItemId) {
258 PortletItem portletItem = new PortletItemImpl();
259
260 portletItem.setNew(true);
261 portletItem.setPrimaryKey(portletItemId);
262
263 return portletItem;
264 }
265
266
274 public PortletItem remove(long portletItemId)
275 throws NoSuchPortletItemException, SystemException {
276 return remove(Long.valueOf(portletItemId));
277 }
278
279
287 @Override
288 public PortletItem remove(Serializable primaryKey)
289 throws NoSuchPortletItemException, SystemException {
290 Session session = null;
291
292 try {
293 session = openSession();
294
295 PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
296 primaryKey);
297
298 if (portletItem == null) {
299 if (_log.isWarnEnabled()) {
300 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
301 }
302
303 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
304 primaryKey);
305 }
306
307 return remove(portletItem);
308 }
309 catch (NoSuchPortletItemException nsee) {
310 throw nsee;
311 }
312 catch (Exception e) {
313 throw processException(e);
314 }
315 finally {
316 closeSession(session);
317 }
318 }
319
320 @Override
321 protected PortletItem removeImpl(PortletItem portletItem)
322 throws SystemException {
323 portletItem = toUnwrappedModel(portletItem);
324
325 Session session = null;
326
327 try {
328 session = openSession();
329
330 BatchSessionUtil.delete(session, portletItem);
331 }
332 catch (Exception e) {
333 throw processException(e);
334 }
335 finally {
336 closeSession(session);
337 }
338
339 clearCache(portletItem);
340
341 return portletItem;
342 }
343
344 @Override
345 public PortletItem updateImpl(
346 com.liferay.portal.model.PortletItem portletItem, boolean merge)
347 throws SystemException {
348 portletItem = toUnwrappedModel(portletItem);
349
350 boolean isNew = portletItem.isNew();
351
352 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
353
354 Session session = null;
355
356 try {
357 session = openSession();
358
359 BatchSessionUtil.update(session, portletItem, merge);
360
361 portletItem.setNew(false);
362 }
363 catch (Exception e) {
364 throw processException(e);
365 }
366 finally {
367 closeSession(session);
368 }
369
370 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
371
372 if (isNew || !PortletItemModelImpl.COLUMN_BITMASK_ENABLED) {
373 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
374 }
375
376 else {
377 if ((portletItemModelImpl.getColumnBitmask() &
378 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
379 Object[] args = new Object[] {
380 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
381 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
382 };
383
384 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
385 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
386 args);
387
388 args = new Object[] {
389 Long.valueOf(portletItemModelImpl.getGroupId()),
390 Long.valueOf(portletItemModelImpl.getClassNameId())
391 };
392
393 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
394 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
395 args);
396 }
397
398 if ((portletItemModelImpl.getColumnBitmask() &
399 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C.getColumnBitmask()) != 0) {
400 Object[] args = new Object[] {
401 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
402
403 portletItemModelImpl.getOriginalPortletId(),
404 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
405 };
406
407 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
408 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
409 args);
410
411 args = new Object[] {
412 Long.valueOf(portletItemModelImpl.getGroupId()),
413
414 portletItemModelImpl.getPortletId(),
415 Long.valueOf(portletItemModelImpl.getClassNameId())
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 }
423
424 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
425 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
426
427 if (isNew) {
428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
429 new Object[] {
430 Long.valueOf(portletItem.getGroupId()),
431
432 portletItem.getName(),
433
434 portletItem.getPortletId(),
435 Long.valueOf(portletItem.getClassNameId())
436 }, portletItem);
437 }
438 else {
439 if ((portletItemModelImpl.getColumnBitmask() &
440 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
441 Object[] args = new Object[] {
442 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
443
444 portletItemModelImpl.getOriginalName(),
445
446 portletItemModelImpl.getOriginalPortletId(),
447 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
448 };
449
450 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
451 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
452
453 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
454 new Object[] {
455 Long.valueOf(portletItem.getGroupId()),
456
457 portletItem.getName(),
458
459 portletItem.getPortletId(),
460 Long.valueOf(portletItem.getClassNameId())
461 }, portletItem);
462 }
463 }
464
465 return portletItem;
466 }
467
468 protected PortletItem toUnwrappedModel(PortletItem portletItem) {
469 if (portletItem instanceof PortletItemImpl) {
470 return portletItem;
471 }
472
473 PortletItemImpl portletItemImpl = new PortletItemImpl();
474
475 portletItemImpl.setNew(portletItem.isNew());
476 portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
477
478 portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
479 portletItemImpl.setGroupId(portletItem.getGroupId());
480 portletItemImpl.setCompanyId(portletItem.getCompanyId());
481 portletItemImpl.setUserId(portletItem.getUserId());
482 portletItemImpl.setUserName(portletItem.getUserName());
483 portletItemImpl.setCreateDate(portletItem.getCreateDate());
484 portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
485 portletItemImpl.setName(portletItem.getName());
486 portletItemImpl.setPortletId(portletItem.getPortletId());
487 portletItemImpl.setClassNameId(portletItem.getClassNameId());
488
489 return portletItemImpl;
490 }
491
492
500 @Override
501 public PortletItem findByPrimaryKey(Serializable primaryKey)
502 throws NoSuchModelException, SystemException {
503 return findByPrimaryKey(((Long)primaryKey).longValue());
504 }
505
506
514 public PortletItem findByPrimaryKey(long portletItemId)
515 throws NoSuchPortletItemException, SystemException {
516 PortletItem portletItem = fetchByPrimaryKey(portletItemId);
517
518 if (portletItem == null) {
519 if (_log.isWarnEnabled()) {
520 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
521 }
522
523 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
524 portletItemId);
525 }
526
527 return portletItem;
528 }
529
530
537 @Override
538 public PortletItem fetchByPrimaryKey(Serializable primaryKey)
539 throws SystemException {
540 return fetchByPrimaryKey(((Long)primaryKey).longValue());
541 }
542
543
550 public PortletItem fetchByPrimaryKey(long portletItemId)
551 throws SystemException {
552 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
553 PortletItemImpl.class, portletItemId);
554
555 if (portletItem == _nullPortletItem) {
556 return null;
557 }
558
559 if (portletItem == null) {
560 Session session = null;
561
562 boolean hasException = false;
563
564 try {
565 session = openSession();
566
567 portletItem = (PortletItem)session.get(PortletItemImpl.class,
568 Long.valueOf(portletItemId));
569 }
570 catch (Exception e) {
571 hasException = true;
572
573 throw processException(e);
574 }
575 finally {
576 if (portletItem != null) {
577 cacheResult(portletItem);
578 }
579 else if (!hasException) {
580 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
581 PortletItemImpl.class, portletItemId, _nullPortletItem);
582 }
583
584 closeSession(session);
585 }
586 }
587
588 return portletItem;
589 }
590
591
599 public List<PortletItem> findByG_C(long groupId, long classNameId)
600 throws SystemException {
601 return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
602 QueryUtil.ALL_POS, null);
603 }
604
605
619 public List<PortletItem> findByG_C(long groupId, long classNameId,
620 int start, int end) throws SystemException {
621 return findByG_C(groupId, classNameId, start, end, null);
622 }
623
624
639 public List<PortletItem> findByG_C(long groupId, long classNameId,
640 int start, int end, OrderByComparator orderByComparator)
641 throws SystemException {
642 FinderPath finderPath = null;
643 Object[] finderArgs = null;
644
645 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
646 (orderByComparator == null)) {
647 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
648 finderArgs = new Object[] { groupId, classNameId };
649 }
650 else {
651 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
652 finderArgs = new Object[] {
653 groupId, classNameId,
654
655 start, end, orderByComparator
656 };
657 }
658
659 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
660 finderArgs, this);
661
662 if (list == null) {
663 StringBundler query = null;
664
665 if (orderByComparator != null) {
666 query = new StringBundler(4 +
667 (orderByComparator.getOrderByFields().length * 3));
668 }
669 else {
670 query = new StringBundler(3);
671 }
672
673 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
674
675 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
676
677 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
678
679 if (orderByComparator != null) {
680 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
681 orderByComparator);
682 }
683
684 String sql = query.toString();
685
686 Session session = null;
687
688 try {
689 session = openSession();
690
691 Query q = session.createQuery(sql);
692
693 QueryPos qPos = QueryPos.getInstance(q);
694
695 qPos.add(groupId);
696
697 qPos.add(classNameId);
698
699 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
700 start, end);
701 }
702 catch (Exception e) {
703 throw processException(e);
704 }
705 finally {
706 if (list == null) {
707 FinderCacheUtil.removeResult(finderPath, finderArgs);
708 }
709 else {
710 cacheResult(list);
711
712 FinderCacheUtil.putResult(finderPath, finderArgs, list);
713 }
714
715 closeSession(session);
716 }
717 }
718
719 return list;
720 }
721
722
736 public PortletItem findByG_C_First(long groupId, long classNameId,
737 OrderByComparator orderByComparator)
738 throws NoSuchPortletItemException, SystemException {
739 List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
740 orderByComparator);
741
742 if (list.isEmpty()) {
743 StringBundler msg = new StringBundler(6);
744
745 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
746
747 msg.append("groupId=");
748 msg.append(groupId);
749
750 msg.append(", classNameId=");
751 msg.append(classNameId);
752
753 msg.append(StringPool.CLOSE_CURLY_BRACE);
754
755 throw new NoSuchPortletItemException(msg.toString());
756 }
757 else {
758 return list.get(0);
759 }
760 }
761
762
776 public PortletItem findByG_C_Last(long groupId, long classNameId,
777 OrderByComparator orderByComparator)
778 throws NoSuchPortletItemException, SystemException {
779 int count = countByG_C(groupId, classNameId);
780
781 List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
782 count, orderByComparator);
783
784 if (list.isEmpty()) {
785 StringBundler msg = new StringBundler(6);
786
787 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
788
789 msg.append("groupId=");
790 msg.append(groupId);
791
792 msg.append(", classNameId=");
793 msg.append(classNameId);
794
795 msg.append(StringPool.CLOSE_CURLY_BRACE);
796
797 throw new NoSuchPortletItemException(msg.toString());
798 }
799 else {
800 return list.get(0);
801 }
802 }
803
804
819 public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
820 long groupId, long classNameId, OrderByComparator orderByComparator)
821 throws NoSuchPortletItemException, SystemException {
822 PortletItem portletItem = findByPrimaryKey(portletItemId);
823
824 Session session = null;
825
826 try {
827 session = openSession();
828
829 PortletItem[] array = new PortletItemImpl[3];
830
831 array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
832 classNameId, orderByComparator, true);
833
834 array[1] = portletItem;
835
836 array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
837 classNameId, orderByComparator, false);
838
839 return array;
840 }
841 catch (Exception e) {
842 throw processException(e);
843 }
844 finally {
845 closeSession(session);
846 }
847 }
848
849 protected PortletItem getByG_C_PrevAndNext(Session session,
850 PortletItem portletItem, long groupId, long classNameId,
851 OrderByComparator orderByComparator, boolean previous) {
852 StringBundler query = null;
853
854 if (orderByComparator != null) {
855 query = new StringBundler(6 +
856 (orderByComparator.getOrderByFields().length * 6));
857 }
858 else {
859 query = new StringBundler(3);
860 }
861
862 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
863
864 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
865
866 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
867
868 if (orderByComparator != null) {
869 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
870
871 if (orderByConditionFields.length > 0) {
872 query.append(WHERE_AND);
873 }
874
875 for (int i = 0; i < orderByConditionFields.length; i++) {
876 query.append(_ORDER_BY_ENTITY_ALIAS);
877 query.append(orderByConditionFields[i]);
878
879 if ((i + 1) < orderByConditionFields.length) {
880 if (orderByComparator.isAscending() ^ previous) {
881 query.append(WHERE_GREATER_THAN_HAS_NEXT);
882 }
883 else {
884 query.append(WHERE_LESSER_THAN_HAS_NEXT);
885 }
886 }
887 else {
888 if (orderByComparator.isAscending() ^ previous) {
889 query.append(WHERE_GREATER_THAN);
890 }
891 else {
892 query.append(WHERE_LESSER_THAN);
893 }
894 }
895 }
896
897 query.append(ORDER_BY_CLAUSE);
898
899 String[] orderByFields = orderByComparator.getOrderByFields();
900
901 for (int i = 0; i < orderByFields.length; i++) {
902 query.append(_ORDER_BY_ENTITY_ALIAS);
903 query.append(orderByFields[i]);
904
905 if ((i + 1) < orderByFields.length) {
906 if (orderByComparator.isAscending() ^ previous) {
907 query.append(ORDER_BY_ASC_HAS_NEXT);
908 }
909 else {
910 query.append(ORDER_BY_DESC_HAS_NEXT);
911 }
912 }
913 else {
914 if (orderByComparator.isAscending() ^ previous) {
915 query.append(ORDER_BY_ASC);
916 }
917 else {
918 query.append(ORDER_BY_DESC);
919 }
920 }
921 }
922 }
923
924 String sql = query.toString();
925
926 Query q = session.createQuery(sql);
927
928 q.setFirstResult(0);
929 q.setMaxResults(2);
930
931 QueryPos qPos = QueryPos.getInstance(q);
932
933 qPos.add(groupId);
934
935 qPos.add(classNameId);
936
937 if (orderByComparator != null) {
938 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
939
940 for (Object value : values) {
941 qPos.add(value);
942 }
943 }
944
945 List<PortletItem> list = q.list();
946
947 if (list.size() == 2) {
948 return list.get(1);
949 }
950 else {
951 return null;
952 }
953 }
954
955
964 public List<PortletItem> findByG_P_C(long groupId, String portletId,
965 long classNameId) throws SystemException {
966 return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
967 QueryUtil.ALL_POS, null);
968 }
969
970
985 public List<PortletItem> findByG_P_C(long groupId, String portletId,
986 long classNameId, int start, int end) throws SystemException {
987 return findByG_P_C(groupId, portletId, classNameId, start, end, null);
988 }
989
990
1006 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1007 long classNameId, int start, int end,
1008 OrderByComparator orderByComparator) throws SystemException {
1009 FinderPath finderPath = null;
1010 Object[] finderArgs = null;
1011
1012 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1013 (orderByComparator == null)) {
1014 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C;
1015 finderArgs = new Object[] { groupId, portletId, classNameId };
1016 }
1017 else {
1018 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C;
1019 finderArgs = new Object[] {
1020 groupId, portletId, classNameId,
1021
1022 start, end, orderByComparator
1023 };
1024 }
1025
1026 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
1027 finderArgs, this);
1028
1029 if (list == null) {
1030 StringBundler query = null;
1031
1032 if (orderByComparator != null) {
1033 query = new StringBundler(5 +
1034 (orderByComparator.getOrderByFields().length * 3));
1035 }
1036 else {
1037 query = new StringBundler(4);
1038 }
1039
1040 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1041
1042 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1043
1044 if (portletId == null) {
1045 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1046 }
1047 else {
1048 if (portletId.equals(StringPool.BLANK)) {
1049 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1050 }
1051 else {
1052 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1053 }
1054 }
1055
1056 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1057
1058 if (orderByComparator != null) {
1059 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1060 orderByComparator);
1061 }
1062
1063 String sql = query.toString();
1064
1065 Session session = null;
1066
1067 try {
1068 session = openSession();
1069
1070 Query q = session.createQuery(sql);
1071
1072 QueryPos qPos = QueryPos.getInstance(q);
1073
1074 qPos.add(groupId);
1075
1076 if (portletId != null) {
1077 qPos.add(portletId);
1078 }
1079
1080 qPos.add(classNameId);
1081
1082 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1083 start, end);
1084 }
1085 catch (Exception e) {
1086 throw processException(e);
1087 }
1088 finally {
1089 if (list == null) {
1090 FinderCacheUtil.removeResult(finderPath, finderArgs);
1091 }
1092 else {
1093 cacheResult(list);
1094
1095 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1096 }
1097
1098 closeSession(session);
1099 }
1100 }
1101
1102 return list;
1103 }
1104
1105
1120 public PortletItem findByG_P_C_First(long groupId, String portletId,
1121 long classNameId, OrderByComparator orderByComparator)
1122 throws NoSuchPortletItemException, SystemException {
1123 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
1124 0, 1, orderByComparator);
1125
1126 if (list.isEmpty()) {
1127 StringBundler msg = new StringBundler(8);
1128
1129 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1130
1131 msg.append("groupId=");
1132 msg.append(groupId);
1133
1134 msg.append(", portletId=");
1135 msg.append(portletId);
1136
1137 msg.append(", classNameId=");
1138 msg.append(classNameId);
1139
1140 msg.append(StringPool.CLOSE_CURLY_BRACE);
1141
1142 throw new NoSuchPortletItemException(msg.toString());
1143 }
1144 else {
1145 return list.get(0);
1146 }
1147 }
1148
1149
1164 public PortletItem findByG_P_C_Last(long groupId, String portletId,
1165 long classNameId, OrderByComparator orderByComparator)
1166 throws NoSuchPortletItemException, SystemException {
1167 int count = countByG_P_C(groupId, portletId, classNameId);
1168
1169 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
1170 count - 1, count, orderByComparator);
1171
1172 if (list.isEmpty()) {
1173 StringBundler msg = new StringBundler(8);
1174
1175 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1176
1177 msg.append("groupId=");
1178 msg.append(groupId);
1179
1180 msg.append(", portletId=");
1181 msg.append(portletId);
1182
1183 msg.append(", classNameId=");
1184 msg.append(classNameId);
1185
1186 msg.append(StringPool.CLOSE_CURLY_BRACE);
1187
1188 throw new NoSuchPortletItemException(msg.toString());
1189 }
1190 else {
1191 return list.get(0);
1192 }
1193 }
1194
1195
1211 public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
1212 long groupId, String portletId, long classNameId,
1213 OrderByComparator orderByComparator)
1214 throws NoSuchPortletItemException, SystemException {
1215 PortletItem portletItem = findByPrimaryKey(portletItemId);
1216
1217 Session session = null;
1218
1219 try {
1220 session = openSession();
1221
1222 PortletItem[] array = new PortletItemImpl[3];
1223
1224 array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
1225 portletId, classNameId, orderByComparator, true);
1226
1227 array[1] = portletItem;
1228
1229 array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
1230 portletId, classNameId, orderByComparator, false);
1231
1232 return array;
1233 }
1234 catch (Exception e) {
1235 throw processException(e);
1236 }
1237 finally {
1238 closeSession(session);
1239 }
1240 }
1241
1242 protected PortletItem getByG_P_C_PrevAndNext(Session session,
1243 PortletItem portletItem, long groupId, String portletId,
1244 long classNameId, OrderByComparator orderByComparator, boolean previous) {
1245 StringBundler query = null;
1246
1247 if (orderByComparator != null) {
1248 query = new StringBundler(6 +
1249 (orderByComparator.getOrderByFields().length * 6));
1250 }
1251 else {
1252 query = new StringBundler(3);
1253 }
1254
1255 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1256
1257 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1258
1259 if (portletId == null) {
1260 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1261 }
1262 else {
1263 if (portletId.equals(StringPool.BLANK)) {
1264 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1265 }
1266 else {
1267 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1268 }
1269 }
1270
1271 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1272
1273 if (orderByComparator != null) {
1274 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1275
1276 if (orderByConditionFields.length > 0) {
1277 query.append(WHERE_AND);
1278 }
1279
1280 for (int i = 0; i < orderByConditionFields.length; i++) {
1281 query.append(_ORDER_BY_ENTITY_ALIAS);
1282 query.append(orderByConditionFields[i]);
1283
1284 if ((i + 1) < orderByConditionFields.length) {
1285 if (orderByComparator.isAscending() ^ previous) {
1286 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1287 }
1288 else {
1289 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1290 }
1291 }
1292 else {
1293 if (orderByComparator.isAscending() ^ previous) {
1294 query.append(WHERE_GREATER_THAN);
1295 }
1296 else {
1297 query.append(WHERE_LESSER_THAN);
1298 }
1299 }
1300 }
1301
1302 query.append(ORDER_BY_CLAUSE);
1303
1304 String[] orderByFields = orderByComparator.getOrderByFields();
1305
1306 for (int i = 0; i < orderByFields.length; i++) {
1307 query.append(_ORDER_BY_ENTITY_ALIAS);
1308 query.append(orderByFields[i]);
1309
1310 if ((i + 1) < orderByFields.length) {
1311 if (orderByComparator.isAscending() ^ previous) {
1312 query.append(ORDER_BY_ASC_HAS_NEXT);
1313 }
1314 else {
1315 query.append(ORDER_BY_DESC_HAS_NEXT);
1316 }
1317 }
1318 else {
1319 if (orderByComparator.isAscending() ^ previous) {
1320 query.append(ORDER_BY_ASC);
1321 }
1322 else {
1323 query.append(ORDER_BY_DESC);
1324 }
1325 }
1326 }
1327 }
1328
1329 String sql = query.toString();
1330
1331 Query q = session.createQuery(sql);
1332
1333 q.setFirstResult(0);
1334 q.setMaxResults(2);
1335
1336 QueryPos qPos = QueryPos.getInstance(q);
1337
1338 qPos.add(groupId);
1339
1340 if (portletId != null) {
1341 qPos.add(portletId);
1342 }
1343
1344 qPos.add(classNameId);
1345
1346 if (orderByComparator != null) {
1347 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1348
1349 for (Object value : values) {
1350 qPos.add(value);
1351 }
1352 }
1353
1354 List<PortletItem> list = q.list();
1355
1356 if (list.size() == 2) {
1357 return list.get(1);
1358 }
1359 else {
1360 return null;
1361 }
1362 }
1363
1364
1375 public PortletItem findByG_N_P_C(long groupId, String name,
1376 String portletId, long classNameId)
1377 throws NoSuchPortletItemException, SystemException {
1378 PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1379 classNameId);
1380
1381 if (portletItem == null) {
1382 StringBundler msg = new StringBundler(10);
1383
1384 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1385
1386 msg.append("groupId=");
1387 msg.append(groupId);
1388
1389 msg.append(", name=");
1390 msg.append(name);
1391
1392 msg.append(", portletId=");
1393 msg.append(portletId);
1394
1395 msg.append(", classNameId=");
1396 msg.append(classNameId);
1397
1398 msg.append(StringPool.CLOSE_CURLY_BRACE);
1399
1400 if (_log.isWarnEnabled()) {
1401 _log.warn(msg.toString());
1402 }
1403
1404 throw new NoSuchPortletItemException(msg.toString());
1405 }
1406
1407 return portletItem;
1408 }
1409
1410
1420 public PortletItem fetchByG_N_P_C(long groupId, String name,
1421 String portletId, long classNameId) throws SystemException {
1422 return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1423 }
1424
1425
1436 public PortletItem fetchByG_N_P_C(long groupId, String name,
1437 String portletId, long classNameId, boolean retrieveFromCache)
1438 throws SystemException {
1439 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1440
1441 Object result = null;
1442
1443 if (retrieveFromCache) {
1444 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1445 finderArgs, this);
1446 }
1447
1448 if (result == null) {
1449 StringBundler query = new StringBundler(5);
1450
1451 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1452
1453 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1454
1455 if (name == null) {
1456 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1457 }
1458 else {
1459 if (name.equals(StringPool.BLANK)) {
1460 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1461 }
1462 else {
1463 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1464 }
1465 }
1466
1467 if (portletId == null) {
1468 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1469 }
1470 else {
1471 if (portletId.equals(StringPool.BLANK)) {
1472 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1473 }
1474 else {
1475 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1476 }
1477 }
1478
1479 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1480
1481 String sql = query.toString();
1482
1483 Session session = null;
1484
1485 try {
1486 session = openSession();
1487
1488 Query q = session.createQuery(sql);
1489
1490 QueryPos qPos = QueryPos.getInstance(q);
1491
1492 qPos.add(groupId);
1493
1494 if (name != null) {
1495 qPos.add(name);
1496 }
1497
1498 if (portletId != null) {
1499 qPos.add(portletId);
1500 }
1501
1502 qPos.add(classNameId);
1503
1504 List<PortletItem> list = q.list();
1505
1506 result = list;
1507
1508 PortletItem portletItem = null;
1509
1510 if (list.isEmpty()) {
1511 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1512 finderArgs, list);
1513 }
1514 else {
1515 portletItem = list.get(0);
1516
1517 cacheResult(portletItem);
1518
1519 if ((portletItem.getGroupId() != groupId) ||
1520 (portletItem.getName() == null) ||
1521 !portletItem.getName().equals(name) ||
1522 (portletItem.getPortletId() == null) ||
1523 !portletItem.getPortletId().equals(portletId) ||
1524 (portletItem.getClassNameId() != classNameId)) {
1525 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1526 finderArgs, portletItem);
1527 }
1528 }
1529
1530 return portletItem;
1531 }
1532 catch (Exception e) {
1533 throw processException(e);
1534 }
1535 finally {
1536 if (result == null) {
1537 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1538 finderArgs);
1539 }
1540
1541 closeSession(session);
1542 }
1543 }
1544 else {
1545 if (result instanceof List<?>) {
1546 return null;
1547 }
1548 else {
1549 return (PortletItem)result;
1550 }
1551 }
1552 }
1553
1554
1560 public List<PortletItem> findAll() throws SystemException {
1561 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1562 }
1563
1564
1576 public List<PortletItem> findAll(int start, int end)
1577 throws SystemException {
1578 return findAll(start, end, null);
1579 }
1580
1581
1594 public List<PortletItem> findAll(int start, int end,
1595 OrderByComparator orderByComparator) throws SystemException {
1596 FinderPath finderPath = null;
1597 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1598
1599 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1600 (orderByComparator == null)) {
1601 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1602 finderArgs = FINDER_ARGS_EMPTY;
1603 }
1604 else {
1605 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1606 finderArgs = new Object[] { start, end, orderByComparator };
1607 }
1608
1609 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
1610 finderArgs, this);
1611
1612 if (list == null) {
1613 StringBundler query = null;
1614 String sql = null;
1615
1616 if (orderByComparator != null) {
1617 query = new StringBundler(2 +
1618 (orderByComparator.getOrderByFields().length * 3));
1619
1620 query.append(_SQL_SELECT_PORTLETITEM);
1621
1622 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1623 orderByComparator);
1624
1625 sql = query.toString();
1626 }
1627 else {
1628 sql = _SQL_SELECT_PORTLETITEM;
1629 }
1630
1631 Session session = null;
1632
1633 try {
1634 session = openSession();
1635
1636 Query q = session.createQuery(sql);
1637
1638 if (orderByComparator == null) {
1639 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1640 start, end, false);
1641
1642 Collections.sort(list);
1643 }
1644 else {
1645 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1646 start, end);
1647 }
1648 }
1649 catch (Exception e) {
1650 throw processException(e);
1651 }
1652 finally {
1653 if (list == null) {
1654 FinderCacheUtil.removeResult(finderPath, finderArgs);
1655 }
1656 else {
1657 cacheResult(list);
1658
1659 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1660 }
1661
1662 closeSession(session);
1663 }
1664 }
1665
1666 return list;
1667 }
1668
1669
1676 public void removeByG_C(long groupId, long classNameId)
1677 throws SystemException {
1678 for (PortletItem portletItem : findByG_C(groupId, classNameId)) {
1679 remove(portletItem);
1680 }
1681 }
1682
1683
1691 public void removeByG_P_C(long groupId, String portletId, long classNameId)
1692 throws SystemException {
1693 for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1694 classNameId)) {
1695 remove(portletItem);
1696 }
1697 }
1698
1699
1708 public void removeByG_N_P_C(long groupId, String name, String portletId,
1709 long classNameId) throws NoSuchPortletItemException, SystemException {
1710 PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1711 classNameId);
1712
1713 remove(portletItem);
1714 }
1715
1716
1721 public void removeAll() throws SystemException {
1722 for (PortletItem portletItem : findAll()) {
1723 remove(portletItem);
1724 }
1725 }
1726
1727
1735 public int countByG_C(long groupId, long classNameId)
1736 throws SystemException {
1737 Object[] finderArgs = new Object[] { groupId, classNameId };
1738
1739 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1740 finderArgs, this);
1741
1742 if (count == null) {
1743 StringBundler query = new StringBundler(3);
1744
1745 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1746
1747 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1748
1749 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1750
1751 String sql = query.toString();
1752
1753 Session session = null;
1754
1755 try {
1756 session = openSession();
1757
1758 Query q = session.createQuery(sql);
1759
1760 QueryPos qPos = QueryPos.getInstance(q);
1761
1762 qPos.add(groupId);
1763
1764 qPos.add(classNameId);
1765
1766 count = (Long)q.uniqueResult();
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 if (count == null) {
1773 count = Long.valueOf(0);
1774 }
1775
1776 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1777 count);
1778
1779 closeSession(session);
1780 }
1781 }
1782
1783 return count.intValue();
1784 }
1785
1786
1795 public int countByG_P_C(long groupId, String portletId, long classNameId)
1796 throws SystemException {
1797 Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1798
1799 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_C,
1800 finderArgs, this);
1801
1802 if (count == null) {
1803 StringBundler query = new StringBundler(4);
1804
1805 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1806
1807 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1808
1809 if (portletId == null) {
1810 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1811 }
1812 else {
1813 if (portletId.equals(StringPool.BLANK)) {
1814 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1815 }
1816 else {
1817 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1818 }
1819 }
1820
1821 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1822
1823 String sql = query.toString();
1824
1825 Session session = null;
1826
1827 try {
1828 session = openSession();
1829
1830 Query q = session.createQuery(sql);
1831
1832 QueryPos qPos = QueryPos.getInstance(q);
1833
1834 qPos.add(groupId);
1835
1836 if (portletId != null) {
1837 qPos.add(portletId);
1838 }
1839
1840 qPos.add(classNameId);
1841
1842 count = (Long)q.uniqueResult();
1843 }
1844 catch (Exception e) {
1845 throw processException(e);
1846 }
1847 finally {
1848 if (count == null) {
1849 count = Long.valueOf(0);
1850 }
1851
1852 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_C,
1853 finderArgs, count);
1854
1855 closeSession(session);
1856 }
1857 }
1858
1859 return count.intValue();
1860 }
1861
1862
1872 public int countByG_N_P_C(long groupId, String name, String portletId,
1873 long classNameId) throws SystemException {
1874 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1875
1876 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1877 finderArgs, this);
1878
1879 if (count == null) {
1880 StringBundler query = new StringBundler(5);
1881
1882 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1883
1884 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1885
1886 if (name == null) {
1887 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1888 }
1889 else {
1890 if (name.equals(StringPool.BLANK)) {
1891 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1892 }
1893 else {
1894 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1895 }
1896 }
1897
1898 if (portletId == null) {
1899 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1900 }
1901 else {
1902 if (portletId.equals(StringPool.BLANK)) {
1903 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1904 }
1905 else {
1906 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1907 }
1908 }
1909
1910 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1911
1912 String sql = query.toString();
1913
1914 Session session = null;
1915
1916 try {
1917 session = openSession();
1918
1919 Query q = session.createQuery(sql);
1920
1921 QueryPos qPos = QueryPos.getInstance(q);
1922
1923 qPos.add(groupId);
1924
1925 if (name != null) {
1926 qPos.add(name);
1927 }
1928
1929 if (portletId != null) {
1930 qPos.add(portletId);
1931 }
1932
1933 qPos.add(classNameId);
1934
1935 count = (Long)q.uniqueResult();
1936 }
1937 catch (Exception e) {
1938 throw processException(e);
1939 }
1940 finally {
1941 if (count == null) {
1942 count = Long.valueOf(0);
1943 }
1944
1945 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1946 finderArgs, count);
1947
1948 closeSession(session);
1949 }
1950 }
1951
1952 return count.intValue();
1953 }
1954
1955
1961 public int countAll() throws SystemException {
1962 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1963 FINDER_ARGS_EMPTY, this);
1964
1965 if (count == null) {
1966 Session session = null;
1967
1968 try {
1969 session = openSession();
1970
1971 Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
1972
1973 count = (Long)q.uniqueResult();
1974 }
1975 catch (Exception e) {
1976 throw processException(e);
1977 }
1978 finally {
1979 if (count == null) {
1980 count = Long.valueOf(0);
1981 }
1982
1983 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1984 FINDER_ARGS_EMPTY, count);
1985
1986 closeSession(session);
1987 }
1988 }
1989
1990 return count.intValue();
1991 }
1992
1993
1996 public void afterPropertiesSet() {
1997 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1998 com.liferay.portal.util.PropsUtil.get(
1999 "value.object.listener.com.liferay.portal.model.PortletItem")));
2000
2001 if (listenerClassNames.length > 0) {
2002 try {
2003 List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
2004
2005 for (String listenerClassName : listenerClassNames) {
2006 listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
2007 listenerClassName));
2008 }
2009
2010 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2011 }
2012 catch (Exception e) {
2013 _log.error(e);
2014 }
2015 }
2016 }
2017
2018 public void destroy() {
2019 EntityCacheUtil.removeCache(PortletItemImpl.class.getName());
2020 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2021 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2022 }
2023
2024 @BeanReference(type = AccountPersistence.class)
2025 protected AccountPersistence accountPersistence;
2026 @BeanReference(type = AddressPersistence.class)
2027 protected AddressPersistence addressPersistence;
2028 @BeanReference(type = BrowserTrackerPersistence.class)
2029 protected BrowserTrackerPersistence browserTrackerPersistence;
2030 @BeanReference(type = ClassNamePersistence.class)
2031 protected ClassNamePersistence classNamePersistence;
2032 @BeanReference(type = ClusterGroupPersistence.class)
2033 protected ClusterGroupPersistence clusterGroupPersistence;
2034 @BeanReference(type = CompanyPersistence.class)
2035 protected CompanyPersistence companyPersistence;
2036 @BeanReference(type = ContactPersistence.class)
2037 protected ContactPersistence contactPersistence;
2038 @BeanReference(type = CountryPersistence.class)
2039 protected CountryPersistence countryPersistence;
2040 @BeanReference(type = EmailAddressPersistence.class)
2041 protected EmailAddressPersistence emailAddressPersistence;
2042 @BeanReference(type = GroupPersistence.class)
2043 protected GroupPersistence groupPersistence;
2044 @BeanReference(type = ImagePersistence.class)
2045 protected ImagePersistence imagePersistence;
2046 @BeanReference(type = LayoutPersistence.class)
2047 protected LayoutPersistence layoutPersistence;
2048 @BeanReference(type = LayoutBranchPersistence.class)
2049 protected LayoutBranchPersistence layoutBranchPersistence;
2050 @BeanReference(type = LayoutPrototypePersistence.class)
2051 protected LayoutPrototypePersistence layoutPrototypePersistence;
2052 @BeanReference(type = LayoutRevisionPersistence.class)
2053 protected LayoutRevisionPersistence layoutRevisionPersistence;
2054 @BeanReference(type = LayoutSetPersistence.class)
2055 protected LayoutSetPersistence layoutSetPersistence;
2056 @BeanReference(type = LayoutSetBranchPersistence.class)
2057 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2058 @BeanReference(type = LayoutSetPrototypePersistence.class)
2059 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2060 @BeanReference(type = ListTypePersistence.class)
2061 protected ListTypePersistence listTypePersistence;
2062 @BeanReference(type = LockPersistence.class)
2063 protected LockPersistence lockPersistence;
2064 @BeanReference(type = MembershipRequestPersistence.class)
2065 protected MembershipRequestPersistence membershipRequestPersistence;
2066 @BeanReference(type = OrganizationPersistence.class)
2067 protected OrganizationPersistence organizationPersistence;
2068 @BeanReference(type = OrgGroupPermissionPersistence.class)
2069 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2070 @BeanReference(type = OrgGroupRolePersistence.class)
2071 protected OrgGroupRolePersistence orgGroupRolePersistence;
2072 @BeanReference(type = OrgLaborPersistence.class)
2073 protected OrgLaborPersistence orgLaborPersistence;
2074 @BeanReference(type = PasswordPolicyPersistence.class)
2075 protected PasswordPolicyPersistence passwordPolicyPersistence;
2076 @BeanReference(type = PasswordPolicyRelPersistence.class)
2077 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2078 @BeanReference(type = PasswordTrackerPersistence.class)
2079 protected PasswordTrackerPersistence passwordTrackerPersistence;
2080 @BeanReference(type = PermissionPersistence.class)
2081 protected PermissionPersistence permissionPersistence;
2082 @BeanReference(type = PhonePersistence.class)
2083 protected PhonePersistence phonePersistence;
2084 @BeanReference(type = PluginSettingPersistence.class)
2085 protected PluginSettingPersistence pluginSettingPersistence;
2086 @BeanReference(type = PortalPreferencesPersistence.class)
2087 protected PortalPreferencesPersistence portalPreferencesPersistence;
2088 @BeanReference(type = PortletPersistence.class)
2089 protected PortletPersistence portletPersistence;
2090 @BeanReference(type = PortletItemPersistence.class)
2091 protected PortletItemPersistence portletItemPersistence;
2092 @BeanReference(type = PortletPreferencesPersistence.class)
2093 protected PortletPreferencesPersistence portletPreferencesPersistence;
2094 @BeanReference(type = RegionPersistence.class)
2095 protected RegionPersistence regionPersistence;
2096 @BeanReference(type = ReleasePersistence.class)
2097 protected ReleasePersistence releasePersistence;
2098 @BeanReference(type = RepositoryPersistence.class)
2099 protected RepositoryPersistence repositoryPersistence;
2100 @BeanReference(type = RepositoryEntryPersistence.class)
2101 protected RepositoryEntryPersistence repositoryEntryPersistence;
2102 @BeanReference(type = ResourcePersistence.class)
2103 protected ResourcePersistence resourcePersistence;
2104 @BeanReference(type = ResourceActionPersistence.class)
2105 protected ResourceActionPersistence resourceActionPersistence;
2106 @BeanReference(type = ResourceBlockPersistence.class)
2107 protected ResourceBlockPersistence resourceBlockPersistence;
2108 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2109 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2110 @BeanReference(type = ResourceCodePersistence.class)
2111 protected ResourceCodePersistence resourceCodePersistence;
2112 @BeanReference(type = ResourcePermissionPersistence.class)
2113 protected ResourcePermissionPersistence resourcePermissionPersistence;
2114 @BeanReference(type = ResourceTypePermissionPersistence.class)
2115 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2116 @BeanReference(type = RolePersistence.class)
2117 protected RolePersistence rolePersistence;
2118 @BeanReference(type = ServiceComponentPersistence.class)
2119 protected ServiceComponentPersistence serviceComponentPersistence;
2120 @BeanReference(type = ShardPersistence.class)
2121 protected ShardPersistence shardPersistence;
2122 @BeanReference(type = SubscriptionPersistence.class)
2123 protected SubscriptionPersistence subscriptionPersistence;
2124 @BeanReference(type = TeamPersistence.class)
2125 protected TeamPersistence teamPersistence;
2126 @BeanReference(type = TicketPersistence.class)
2127 protected TicketPersistence ticketPersistence;
2128 @BeanReference(type = UserPersistence.class)
2129 protected UserPersistence userPersistence;
2130 @BeanReference(type = UserGroupPersistence.class)
2131 protected UserGroupPersistence userGroupPersistence;
2132 @BeanReference(type = UserGroupGroupRolePersistence.class)
2133 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2134 @BeanReference(type = UserGroupRolePersistence.class)
2135 protected UserGroupRolePersistence userGroupRolePersistence;
2136 @BeanReference(type = UserIdMapperPersistence.class)
2137 protected UserIdMapperPersistence userIdMapperPersistence;
2138 @BeanReference(type = UserNotificationEventPersistence.class)
2139 protected UserNotificationEventPersistence userNotificationEventPersistence;
2140 @BeanReference(type = UserTrackerPersistence.class)
2141 protected UserTrackerPersistence userTrackerPersistence;
2142 @BeanReference(type = UserTrackerPathPersistence.class)
2143 protected UserTrackerPathPersistence userTrackerPathPersistence;
2144 @BeanReference(type = VirtualHostPersistence.class)
2145 protected VirtualHostPersistence virtualHostPersistence;
2146 @BeanReference(type = WebDAVPropsPersistence.class)
2147 protected WebDAVPropsPersistence webDAVPropsPersistence;
2148 @BeanReference(type = WebsitePersistence.class)
2149 protected WebsitePersistence websitePersistence;
2150 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2151 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2152 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2153 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2154 private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
2155 private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
2156 private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
2157 private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
2158 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2159 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2160 private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2161 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
2162 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
2163 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
2164 private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2165 private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2166 private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
2167 private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = lower(CAST_TEXT(?)) AND ";
2168 private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR lower(portletItem.name) = lower(CAST_TEXT(?))) AND ";
2169 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
2170 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
2171 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
2172 private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2173 private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
2174 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
2175 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
2176 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2177 private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
2178 private static PortletItem _nullPortletItem = new PortletItemImpl() {
2179 @Override
2180 public Object clone() {
2181 return this;
2182 }
2183
2184 @Override
2185 public CacheModel<PortletItem> toCacheModel() {
2186 return _nullPortletItemCacheModel;
2187 }
2188 };
2189
2190 private static CacheModel<PortletItem> _nullPortletItemCacheModel = new CacheModel<PortletItem>() {
2191 public PortletItem toEntityModel() {
2192 return _nullPortletItem;
2193 }
2194 };
2195 }