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 cacheUniqueFindersCache(PortletItem portletItem) {
241 if (portletItem.isNew()) {
242 Object[] args = new Object[] {
243 Long.valueOf(portletItem.getGroupId()),
244
245 portletItem.getName(),
246
247 portletItem.getPortletId(),
248 Long.valueOf(portletItem.getClassNameId())
249 };
250
251 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
252 Long.valueOf(1));
253 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
254 portletItem);
255 }
256 else {
257 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
258
259 if ((portletItemModelImpl.getColumnBitmask() &
260 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
261 Object[] args = new Object[] {
262 Long.valueOf(portletItem.getGroupId()),
263
264 portletItem.getName(),
265
266 portletItem.getPortletId(),
267 Long.valueOf(portletItem.getClassNameId())
268 };
269
270 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C, args,
271 Long.valueOf(1));
272 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C, args,
273 portletItem);
274 }
275 }
276 }
277
278 protected void clearUniqueFindersCache(PortletItem portletItem) {
279 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
280
281 Object[] args = new Object[] {
282 Long.valueOf(portletItem.getGroupId()),
283
284 portletItem.getName(),
285
286 portletItem.getPortletId(),
287 Long.valueOf(portletItem.getClassNameId())
288 };
289
290 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
291 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
292
293 if ((portletItemModelImpl.getColumnBitmask() &
294 FINDER_PATH_FETCH_BY_G_N_P_C.getColumnBitmask()) != 0) {
295 args = new Object[] {
296 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
297
298 portletItemModelImpl.getOriginalName(),
299
300 portletItemModelImpl.getOriginalPortletId(),
301 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
302 };
303
304 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_P_C, args);
305 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C, args);
306 }
307 }
308
309
315 public PortletItem create(long portletItemId) {
316 PortletItem portletItem = new PortletItemImpl();
317
318 portletItem.setNew(true);
319 portletItem.setPrimaryKey(portletItemId);
320
321 return portletItem;
322 }
323
324
332 public PortletItem remove(long portletItemId)
333 throws NoSuchPortletItemException, SystemException {
334 return remove(Long.valueOf(portletItemId));
335 }
336
337
345 @Override
346 public PortletItem remove(Serializable primaryKey)
347 throws NoSuchPortletItemException, SystemException {
348 Session session = null;
349
350 try {
351 session = openSession();
352
353 PortletItem portletItem = (PortletItem)session.get(PortletItemImpl.class,
354 primaryKey);
355
356 if (portletItem == null) {
357 if (_log.isWarnEnabled()) {
358 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
359 }
360
361 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
362 primaryKey);
363 }
364
365 return remove(portletItem);
366 }
367 catch (NoSuchPortletItemException nsee) {
368 throw nsee;
369 }
370 catch (Exception e) {
371 throw processException(e);
372 }
373 finally {
374 closeSession(session);
375 }
376 }
377
378 @Override
379 protected PortletItem removeImpl(PortletItem portletItem)
380 throws SystemException {
381 portletItem = toUnwrappedModel(portletItem);
382
383 Session session = null;
384
385 try {
386 session = openSession();
387
388 BatchSessionUtil.delete(session, portletItem);
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396
397 clearCache(portletItem);
398
399 return portletItem;
400 }
401
402 @Override
403 public PortletItem updateImpl(
404 com.liferay.portal.model.PortletItem portletItem, boolean merge)
405 throws SystemException {
406 portletItem = toUnwrappedModel(portletItem);
407
408 boolean isNew = portletItem.isNew();
409
410 PortletItemModelImpl portletItemModelImpl = (PortletItemModelImpl)portletItem;
411
412 Session session = null;
413
414 try {
415 session = openSession();
416
417 BatchSessionUtil.update(session, portletItem, merge);
418
419 portletItem.setNew(false);
420 }
421 catch (Exception e) {
422 throw processException(e);
423 }
424 finally {
425 closeSession(session);
426 }
427
428 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
429
430 if (isNew || !PortletItemModelImpl.COLUMN_BITMASK_ENABLED) {
431 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
432 }
433
434 else {
435 if ((portletItemModelImpl.getColumnBitmask() &
436 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
437 Object[] args = new Object[] {
438 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
439 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
440 };
441
442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
443 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
444 args);
445
446 args = new Object[] {
447 Long.valueOf(portletItemModelImpl.getGroupId()),
448 Long.valueOf(portletItemModelImpl.getClassNameId())
449 };
450
451 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
452 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
453 args);
454 }
455
456 if ((portletItemModelImpl.getColumnBitmask() &
457 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C.getColumnBitmask()) != 0) {
458 Object[] args = new Object[] {
459 Long.valueOf(portletItemModelImpl.getOriginalGroupId()),
460
461 portletItemModelImpl.getOriginalPortletId(),
462 Long.valueOf(portletItemModelImpl.getOriginalClassNameId())
463 };
464
465 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
466 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
467 args);
468
469 args = new Object[] {
470 Long.valueOf(portletItemModelImpl.getGroupId()),
471
472 portletItemModelImpl.getPortletId(),
473 Long.valueOf(portletItemModelImpl.getClassNameId())
474 };
475
476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_C, args);
477 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C,
478 args);
479 }
480 }
481
482 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
483 PortletItemImpl.class, portletItem.getPrimaryKey(), portletItem);
484
485 clearUniqueFindersCache(portletItem);
486 cacheUniqueFindersCache(portletItem);
487
488 return portletItem;
489 }
490
491 protected PortletItem toUnwrappedModel(PortletItem portletItem) {
492 if (portletItem instanceof PortletItemImpl) {
493 return portletItem;
494 }
495
496 PortletItemImpl portletItemImpl = new PortletItemImpl();
497
498 portletItemImpl.setNew(portletItem.isNew());
499 portletItemImpl.setPrimaryKey(portletItem.getPrimaryKey());
500
501 portletItemImpl.setPortletItemId(portletItem.getPortletItemId());
502 portletItemImpl.setGroupId(portletItem.getGroupId());
503 portletItemImpl.setCompanyId(portletItem.getCompanyId());
504 portletItemImpl.setUserId(portletItem.getUserId());
505 portletItemImpl.setUserName(portletItem.getUserName());
506 portletItemImpl.setCreateDate(portletItem.getCreateDate());
507 portletItemImpl.setModifiedDate(portletItem.getModifiedDate());
508 portletItemImpl.setName(portletItem.getName());
509 portletItemImpl.setPortletId(portletItem.getPortletId());
510 portletItemImpl.setClassNameId(portletItem.getClassNameId());
511
512 return portletItemImpl;
513 }
514
515
523 @Override
524 public PortletItem findByPrimaryKey(Serializable primaryKey)
525 throws NoSuchModelException, SystemException {
526 return findByPrimaryKey(((Long)primaryKey).longValue());
527 }
528
529
537 public PortletItem findByPrimaryKey(long portletItemId)
538 throws NoSuchPortletItemException, SystemException {
539 PortletItem portletItem = fetchByPrimaryKey(portletItemId);
540
541 if (portletItem == null) {
542 if (_log.isWarnEnabled()) {
543 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + portletItemId);
544 }
545
546 throw new NoSuchPortletItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
547 portletItemId);
548 }
549
550 return portletItem;
551 }
552
553
560 @Override
561 public PortletItem fetchByPrimaryKey(Serializable primaryKey)
562 throws SystemException {
563 return fetchByPrimaryKey(((Long)primaryKey).longValue());
564 }
565
566
573 public PortletItem fetchByPrimaryKey(long portletItemId)
574 throws SystemException {
575 PortletItem portletItem = (PortletItem)EntityCacheUtil.getResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
576 PortletItemImpl.class, portletItemId);
577
578 if (portletItem == _nullPortletItem) {
579 return null;
580 }
581
582 if (portletItem == null) {
583 Session session = null;
584
585 boolean hasException = false;
586
587 try {
588 session = openSession();
589
590 portletItem = (PortletItem)session.get(PortletItemImpl.class,
591 Long.valueOf(portletItemId));
592 }
593 catch (Exception e) {
594 hasException = true;
595
596 throw processException(e);
597 }
598 finally {
599 if (portletItem != null) {
600 cacheResult(portletItem);
601 }
602 else if (!hasException) {
603 EntityCacheUtil.putResult(PortletItemModelImpl.ENTITY_CACHE_ENABLED,
604 PortletItemImpl.class, portletItemId, _nullPortletItem);
605 }
606
607 closeSession(session);
608 }
609 }
610
611 return portletItem;
612 }
613
614
622 public List<PortletItem> findByG_C(long groupId, long classNameId)
623 throws SystemException {
624 return findByG_C(groupId, classNameId, QueryUtil.ALL_POS,
625 QueryUtil.ALL_POS, null);
626 }
627
628
642 public List<PortletItem> findByG_C(long groupId, long classNameId,
643 int start, int end) throws SystemException {
644 return findByG_C(groupId, classNameId, start, end, null);
645 }
646
647
662 public List<PortletItem> findByG_C(long groupId, long classNameId,
663 int start, int end, OrderByComparator orderByComparator)
664 throws SystemException {
665 FinderPath finderPath = null;
666 Object[] finderArgs = null;
667
668 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
669 (orderByComparator == null)) {
670 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
671 finderArgs = new Object[] { groupId, classNameId };
672 }
673 else {
674 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
675 finderArgs = new Object[] {
676 groupId, classNameId,
677
678 start, end, orderByComparator
679 };
680 }
681
682 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
683 finderArgs, this);
684
685 if ((list != null) && !list.isEmpty()) {
686 for (PortletItem portletItem : list) {
687 if ((groupId != portletItem.getGroupId()) ||
688 (classNameId != portletItem.getClassNameId())) {
689 list = null;
690
691 break;
692 }
693 }
694 }
695
696 if (list == null) {
697 StringBundler query = null;
698
699 if (orderByComparator != null) {
700 query = new StringBundler(4 +
701 (orderByComparator.getOrderByFields().length * 3));
702 }
703 else {
704 query = new StringBundler(3);
705 }
706
707 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
708
709 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
710
711 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
712
713 if (orderByComparator != null) {
714 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
715 orderByComparator);
716 }
717
718 String sql = query.toString();
719
720 Session session = null;
721
722 try {
723 session = openSession();
724
725 Query q = session.createQuery(sql);
726
727 QueryPos qPos = QueryPos.getInstance(q);
728
729 qPos.add(groupId);
730
731 qPos.add(classNameId);
732
733 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
734 start, end);
735 }
736 catch (Exception e) {
737 throw processException(e);
738 }
739 finally {
740 if (list == null) {
741 FinderCacheUtil.removeResult(finderPath, finderArgs);
742 }
743 else {
744 cacheResult(list);
745
746 FinderCacheUtil.putResult(finderPath, finderArgs, list);
747 }
748
749 closeSession(session);
750 }
751 }
752
753 return list;
754 }
755
756
766 public PortletItem findByG_C_First(long groupId, long classNameId,
767 OrderByComparator orderByComparator)
768 throws NoSuchPortletItemException, SystemException {
769 PortletItem portletItem = fetchByG_C_First(groupId, classNameId,
770 orderByComparator);
771
772 if (portletItem != null) {
773 return portletItem;
774 }
775
776 StringBundler msg = new StringBundler(6);
777
778 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
779
780 msg.append("groupId=");
781 msg.append(groupId);
782
783 msg.append(", classNameId=");
784 msg.append(classNameId);
785
786 msg.append(StringPool.CLOSE_CURLY_BRACE);
787
788 throw new NoSuchPortletItemException(msg.toString());
789 }
790
791
800 public PortletItem fetchByG_C_First(long groupId, long classNameId,
801 OrderByComparator orderByComparator) throws SystemException {
802 List<PortletItem> list = findByG_C(groupId, classNameId, 0, 1,
803 orderByComparator);
804
805 if (!list.isEmpty()) {
806 return list.get(0);
807 }
808
809 return null;
810 }
811
812
822 public PortletItem findByG_C_Last(long groupId, long classNameId,
823 OrderByComparator orderByComparator)
824 throws NoSuchPortletItemException, SystemException {
825 PortletItem portletItem = fetchByG_C_Last(groupId, classNameId,
826 orderByComparator);
827
828 if (portletItem != null) {
829 return portletItem;
830 }
831
832 StringBundler msg = new StringBundler(6);
833
834 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
835
836 msg.append("groupId=");
837 msg.append(groupId);
838
839 msg.append(", classNameId=");
840 msg.append(classNameId);
841
842 msg.append(StringPool.CLOSE_CURLY_BRACE);
843
844 throw new NoSuchPortletItemException(msg.toString());
845 }
846
847
856 public PortletItem fetchByG_C_Last(long groupId, long classNameId,
857 OrderByComparator orderByComparator) throws SystemException {
858 int count = countByG_C(groupId, classNameId);
859
860 List<PortletItem> list = findByG_C(groupId, classNameId, count - 1,
861 count, orderByComparator);
862
863 if (!list.isEmpty()) {
864 return list.get(0);
865 }
866
867 return null;
868 }
869
870
881 public PortletItem[] findByG_C_PrevAndNext(long portletItemId,
882 long groupId, long classNameId, OrderByComparator orderByComparator)
883 throws NoSuchPortletItemException, SystemException {
884 PortletItem portletItem = findByPrimaryKey(portletItemId);
885
886 Session session = null;
887
888 try {
889 session = openSession();
890
891 PortletItem[] array = new PortletItemImpl[3];
892
893 array[0] = getByG_C_PrevAndNext(session, portletItem, groupId,
894 classNameId, orderByComparator, true);
895
896 array[1] = portletItem;
897
898 array[2] = getByG_C_PrevAndNext(session, portletItem, groupId,
899 classNameId, orderByComparator, false);
900
901 return array;
902 }
903 catch (Exception e) {
904 throw processException(e);
905 }
906 finally {
907 closeSession(session);
908 }
909 }
910
911 protected PortletItem getByG_C_PrevAndNext(Session session,
912 PortletItem portletItem, long groupId, long classNameId,
913 OrderByComparator orderByComparator, boolean previous) {
914 StringBundler query = null;
915
916 if (orderByComparator != null) {
917 query = new StringBundler(6 +
918 (orderByComparator.getOrderByFields().length * 6));
919 }
920 else {
921 query = new StringBundler(3);
922 }
923
924 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
925
926 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
927
928 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
929
930 if (orderByComparator != null) {
931 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
932
933 if (orderByConditionFields.length > 0) {
934 query.append(WHERE_AND);
935 }
936
937 for (int i = 0; i < orderByConditionFields.length; i++) {
938 query.append(_ORDER_BY_ENTITY_ALIAS);
939 query.append(orderByConditionFields[i]);
940
941 if ((i + 1) < orderByConditionFields.length) {
942 if (orderByComparator.isAscending() ^ previous) {
943 query.append(WHERE_GREATER_THAN_HAS_NEXT);
944 }
945 else {
946 query.append(WHERE_LESSER_THAN_HAS_NEXT);
947 }
948 }
949 else {
950 if (orderByComparator.isAscending() ^ previous) {
951 query.append(WHERE_GREATER_THAN);
952 }
953 else {
954 query.append(WHERE_LESSER_THAN);
955 }
956 }
957 }
958
959 query.append(ORDER_BY_CLAUSE);
960
961 String[] orderByFields = orderByComparator.getOrderByFields();
962
963 for (int i = 0; i < orderByFields.length; i++) {
964 query.append(_ORDER_BY_ENTITY_ALIAS);
965 query.append(orderByFields[i]);
966
967 if ((i + 1) < orderByFields.length) {
968 if (orderByComparator.isAscending() ^ previous) {
969 query.append(ORDER_BY_ASC_HAS_NEXT);
970 }
971 else {
972 query.append(ORDER_BY_DESC_HAS_NEXT);
973 }
974 }
975 else {
976 if (orderByComparator.isAscending() ^ previous) {
977 query.append(ORDER_BY_ASC);
978 }
979 else {
980 query.append(ORDER_BY_DESC);
981 }
982 }
983 }
984 }
985
986 String sql = query.toString();
987
988 Query q = session.createQuery(sql);
989
990 q.setFirstResult(0);
991 q.setMaxResults(2);
992
993 QueryPos qPos = QueryPos.getInstance(q);
994
995 qPos.add(groupId);
996
997 qPos.add(classNameId);
998
999 if (orderByComparator != null) {
1000 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1001
1002 for (Object value : values) {
1003 qPos.add(value);
1004 }
1005 }
1006
1007 List<PortletItem> list = q.list();
1008
1009 if (list.size() == 2) {
1010 return list.get(1);
1011 }
1012 else {
1013 return null;
1014 }
1015 }
1016
1017
1026 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1027 long classNameId) throws SystemException {
1028 return findByG_P_C(groupId, portletId, classNameId, QueryUtil.ALL_POS,
1029 QueryUtil.ALL_POS, null);
1030 }
1031
1032
1047 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1048 long classNameId, int start, int end) throws SystemException {
1049 return findByG_P_C(groupId, portletId, classNameId, start, end, null);
1050 }
1051
1052
1068 public List<PortletItem> findByG_P_C(long groupId, String portletId,
1069 long classNameId, int start, int end,
1070 OrderByComparator orderByComparator) throws SystemException {
1071 FinderPath finderPath = null;
1072 Object[] finderArgs = null;
1073
1074 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1075 (orderByComparator == null)) {
1076 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_C;
1077 finderArgs = new Object[] { groupId, portletId, classNameId };
1078 }
1079 else {
1080 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_C;
1081 finderArgs = new Object[] {
1082 groupId, portletId, classNameId,
1083
1084 start, end, orderByComparator
1085 };
1086 }
1087
1088 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
1089 finderArgs, this);
1090
1091 if ((list != null) && !list.isEmpty()) {
1092 for (PortletItem portletItem : list) {
1093 if ((groupId != portletItem.getGroupId()) ||
1094 !Validator.equals(portletId, portletItem.getPortletId()) ||
1095 (classNameId != portletItem.getClassNameId())) {
1096 list = null;
1097
1098 break;
1099 }
1100 }
1101 }
1102
1103 if (list == null) {
1104 StringBundler query = null;
1105
1106 if (orderByComparator != null) {
1107 query = new StringBundler(5 +
1108 (orderByComparator.getOrderByFields().length * 3));
1109 }
1110 else {
1111 query = new StringBundler(4);
1112 }
1113
1114 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1115
1116 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1117
1118 if (portletId == null) {
1119 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1120 }
1121 else {
1122 if (portletId.equals(StringPool.BLANK)) {
1123 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1124 }
1125 else {
1126 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1127 }
1128 }
1129
1130 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1131
1132 if (orderByComparator != null) {
1133 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1134 orderByComparator);
1135 }
1136
1137 String sql = query.toString();
1138
1139 Session session = null;
1140
1141 try {
1142 session = openSession();
1143
1144 Query q = session.createQuery(sql);
1145
1146 QueryPos qPos = QueryPos.getInstance(q);
1147
1148 qPos.add(groupId);
1149
1150 if (portletId != null) {
1151 qPos.add(portletId);
1152 }
1153
1154 qPos.add(classNameId);
1155
1156 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1157 start, end);
1158 }
1159 catch (Exception e) {
1160 throw processException(e);
1161 }
1162 finally {
1163 if (list == null) {
1164 FinderCacheUtil.removeResult(finderPath, finderArgs);
1165 }
1166 else {
1167 cacheResult(list);
1168
1169 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1170 }
1171
1172 closeSession(session);
1173 }
1174 }
1175
1176 return list;
1177 }
1178
1179
1190 public PortletItem findByG_P_C_First(long groupId, String portletId,
1191 long classNameId, OrderByComparator orderByComparator)
1192 throws NoSuchPortletItemException, SystemException {
1193 PortletItem portletItem = fetchByG_P_C_First(groupId, portletId,
1194 classNameId, orderByComparator);
1195
1196 if (portletItem != null) {
1197 return portletItem;
1198 }
1199
1200 StringBundler msg = new StringBundler(8);
1201
1202 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1203
1204 msg.append("groupId=");
1205 msg.append(groupId);
1206
1207 msg.append(", portletId=");
1208 msg.append(portletId);
1209
1210 msg.append(", classNameId=");
1211 msg.append(classNameId);
1212
1213 msg.append(StringPool.CLOSE_CURLY_BRACE);
1214
1215 throw new NoSuchPortletItemException(msg.toString());
1216 }
1217
1218
1228 public PortletItem fetchByG_P_C_First(long groupId, String portletId,
1229 long classNameId, OrderByComparator orderByComparator)
1230 throws SystemException {
1231 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
1232 0, 1, orderByComparator);
1233
1234 if (!list.isEmpty()) {
1235 return list.get(0);
1236 }
1237
1238 return null;
1239 }
1240
1241
1252 public PortletItem findByG_P_C_Last(long groupId, String portletId,
1253 long classNameId, OrderByComparator orderByComparator)
1254 throws NoSuchPortletItemException, SystemException {
1255 PortletItem portletItem = fetchByG_P_C_Last(groupId, portletId,
1256 classNameId, orderByComparator);
1257
1258 if (portletItem != null) {
1259 return portletItem;
1260 }
1261
1262 StringBundler msg = new StringBundler(8);
1263
1264 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1265
1266 msg.append("groupId=");
1267 msg.append(groupId);
1268
1269 msg.append(", portletId=");
1270 msg.append(portletId);
1271
1272 msg.append(", classNameId=");
1273 msg.append(classNameId);
1274
1275 msg.append(StringPool.CLOSE_CURLY_BRACE);
1276
1277 throw new NoSuchPortletItemException(msg.toString());
1278 }
1279
1280
1290 public PortletItem fetchByG_P_C_Last(long groupId, String portletId,
1291 long classNameId, OrderByComparator orderByComparator)
1292 throws SystemException {
1293 int count = countByG_P_C(groupId, portletId, classNameId);
1294
1295 List<PortletItem> list = findByG_P_C(groupId, portletId, classNameId,
1296 count - 1, count, orderByComparator);
1297
1298 if (!list.isEmpty()) {
1299 return list.get(0);
1300 }
1301
1302 return null;
1303 }
1304
1305
1317 public PortletItem[] findByG_P_C_PrevAndNext(long portletItemId,
1318 long groupId, String portletId, long classNameId,
1319 OrderByComparator orderByComparator)
1320 throws NoSuchPortletItemException, SystemException {
1321 PortletItem portletItem = findByPrimaryKey(portletItemId);
1322
1323 Session session = null;
1324
1325 try {
1326 session = openSession();
1327
1328 PortletItem[] array = new PortletItemImpl[3];
1329
1330 array[0] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
1331 portletId, classNameId, orderByComparator, true);
1332
1333 array[1] = portletItem;
1334
1335 array[2] = getByG_P_C_PrevAndNext(session, portletItem, groupId,
1336 portletId, classNameId, orderByComparator, false);
1337
1338 return array;
1339 }
1340 catch (Exception e) {
1341 throw processException(e);
1342 }
1343 finally {
1344 closeSession(session);
1345 }
1346 }
1347
1348 protected PortletItem getByG_P_C_PrevAndNext(Session session,
1349 PortletItem portletItem, long groupId, String portletId,
1350 long classNameId, OrderByComparator orderByComparator, boolean previous) {
1351 StringBundler query = null;
1352
1353 if (orderByComparator != null) {
1354 query = new StringBundler(6 +
1355 (orderByComparator.getOrderByFields().length * 6));
1356 }
1357 else {
1358 query = new StringBundler(3);
1359 }
1360
1361 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1362
1363 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1364
1365 if (portletId == null) {
1366 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1367 }
1368 else {
1369 if (portletId.equals(StringPool.BLANK)) {
1370 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1371 }
1372 else {
1373 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1374 }
1375 }
1376
1377 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1378
1379 if (orderByComparator != null) {
1380 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1381
1382 if (orderByConditionFields.length > 0) {
1383 query.append(WHERE_AND);
1384 }
1385
1386 for (int i = 0; i < orderByConditionFields.length; i++) {
1387 query.append(_ORDER_BY_ENTITY_ALIAS);
1388 query.append(orderByConditionFields[i]);
1389
1390 if ((i + 1) < orderByConditionFields.length) {
1391 if (orderByComparator.isAscending() ^ previous) {
1392 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1393 }
1394 else {
1395 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1396 }
1397 }
1398 else {
1399 if (orderByComparator.isAscending() ^ previous) {
1400 query.append(WHERE_GREATER_THAN);
1401 }
1402 else {
1403 query.append(WHERE_LESSER_THAN);
1404 }
1405 }
1406 }
1407
1408 query.append(ORDER_BY_CLAUSE);
1409
1410 String[] orderByFields = orderByComparator.getOrderByFields();
1411
1412 for (int i = 0; i < orderByFields.length; i++) {
1413 query.append(_ORDER_BY_ENTITY_ALIAS);
1414 query.append(orderByFields[i]);
1415
1416 if ((i + 1) < orderByFields.length) {
1417 if (orderByComparator.isAscending() ^ previous) {
1418 query.append(ORDER_BY_ASC_HAS_NEXT);
1419 }
1420 else {
1421 query.append(ORDER_BY_DESC_HAS_NEXT);
1422 }
1423 }
1424 else {
1425 if (orderByComparator.isAscending() ^ previous) {
1426 query.append(ORDER_BY_ASC);
1427 }
1428 else {
1429 query.append(ORDER_BY_DESC);
1430 }
1431 }
1432 }
1433 }
1434
1435 String sql = query.toString();
1436
1437 Query q = session.createQuery(sql);
1438
1439 q.setFirstResult(0);
1440 q.setMaxResults(2);
1441
1442 QueryPos qPos = QueryPos.getInstance(q);
1443
1444 qPos.add(groupId);
1445
1446 if (portletId != null) {
1447 qPos.add(portletId);
1448 }
1449
1450 qPos.add(classNameId);
1451
1452 if (orderByComparator != null) {
1453 Object[] values = orderByComparator.getOrderByConditionValues(portletItem);
1454
1455 for (Object value : values) {
1456 qPos.add(value);
1457 }
1458 }
1459
1460 List<PortletItem> list = q.list();
1461
1462 if (list.size() == 2) {
1463 return list.get(1);
1464 }
1465 else {
1466 return null;
1467 }
1468 }
1469
1470
1481 public PortletItem findByG_N_P_C(long groupId, String name,
1482 String portletId, long classNameId)
1483 throws NoSuchPortletItemException, SystemException {
1484 PortletItem portletItem = fetchByG_N_P_C(groupId, name, portletId,
1485 classNameId);
1486
1487 if (portletItem == null) {
1488 StringBundler msg = new StringBundler(10);
1489
1490 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1491
1492 msg.append("groupId=");
1493 msg.append(groupId);
1494
1495 msg.append(", name=");
1496 msg.append(name);
1497
1498 msg.append(", portletId=");
1499 msg.append(portletId);
1500
1501 msg.append(", classNameId=");
1502 msg.append(classNameId);
1503
1504 msg.append(StringPool.CLOSE_CURLY_BRACE);
1505
1506 if (_log.isWarnEnabled()) {
1507 _log.warn(msg.toString());
1508 }
1509
1510 throw new NoSuchPortletItemException(msg.toString());
1511 }
1512
1513 return portletItem;
1514 }
1515
1516
1526 public PortletItem fetchByG_N_P_C(long groupId, String name,
1527 String portletId, long classNameId) throws SystemException {
1528 return fetchByG_N_P_C(groupId, name, portletId, classNameId, true);
1529 }
1530
1531
1542 public PortletItem fetchByG_N_P_C(long groupId, String name,
1543 String portletId, long classNameId, boolean retrieveFromCache)
1544 throws SystemException {
1545 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1546
1547 Object result = null;
1548
1549 if (retrieveFromCache) {
1550 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1551 finderArgs, this);
1552 }
1553
1554 if (result instanceof PortletItem) {
1555 PortletItem portletItem = (PortletItem)result;
1556
1557 if ((groupId != portletItem.getGroupId()) ||
1558 !Validator.equals(name, portletItem.getName()) ||
1559 !Validator.equals(portletId, portletItem.getPortletId()) ||
1560 (classNameId != portletItem.getClassNameId())) {
1561 result = null;
1562 }
1563 }
1564
1565 if (result == null) {
1566 StringBundler query = new StringBundler(5);
1567
1568 query.append(_SQL_SELECT_PORTLETITEM_WHERE);
1569
1570 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
1571
1572 if (name == null) {
1573 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
1574 }
1575 else {
1576 if (name.equals(StringPool.BLANK)) {
1577 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
1578 }
1579 else {
1580 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
1581 }
1582 }
1583
1584 if (portletId == null) {
1585 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
1586 }
1587 else {
1588 if (portletId.equals(StringPool.BLANK)) {
1589 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
1590 }
1591 else {
1592 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
1593 }
1594 }
1595
1596 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
1597
1598 String sql = query.toString();
1599
1600 Session session = null;
1601
1602 try {
1603 session = openSession();
1604
1605 Query q = session.createQuery(sql);
1606
1607 QueryPos qPos = QueryPos.getInstance(q);
1608
1609 qPos.add(groupId);
1610
1611 if (name != null) {
1612 qPos.add(name);
1613 }
1614
1615 if (portletId != null) {
1616 qPos.add(portletId);
1617 }
1618
1619 qPos.add(classNameId);
1620
1621 List<PortletItem> list = q.list();
1622
1623 result = list;
1624
1625 PortletItem portletItem = null;
1626
1627 if (list.isEmpty()) {
1628 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1629 finderArgs, list);
1630 }
1631 else {
1632 portletItem = list.get(0);
1633
1634 cacheResult(portletItem);
1635
1636 if ((portletItem.getGroupId() != groupId) ||
1637 (portletItem.getName() == null) ||
1638 !portletItem.getName().equals(name) ||
1639 (portletItem.getPortletId() == null) ||
1640 !portletItem.getPortletId().equals(portletId) ||
1641 (portletItem.getClassNameId() != classNameId)) {
1642 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1643 finderArgs, portletItem);
1644 }
1645 }
1646
1647 return portletItem;
1648 }
1649 catch (Exception e) {
1650 throw processException(e);
1651 }
1652 finally {
1653 if (result == null) {
1654 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N_P_C,
1655 finderArgs);
1656 }
1657
1658 closeSession(session);
1659 }
1660 }
1661 else {
1662 if (result instanceof List<?>) {
1663 return null;
1664 }
1665 else {
1666 return (PortletItem)result;
1667 }
1668 }
1669 }
1670
1671
1677 public List<PortletItem> findAll() throws SystemException {
1678 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1679 }
1680
1681
1693 public List<PortletItem> findAll(int start, int end)
1694 throws SystemException {
1695 return findAll(start, end, null);
1696 }
1697
1698
1711 public List<PortletItem> findAll(int start, int end,
1712 OrderByComparator orderByComparator) throws SystemException {
1713 FinderPath finderPath = null;
1714 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1715
1716 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1717 (orderByComparator == null)) {
1718 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1719 finderArgs = FINDER_ARGS_EMPTY;
1720 }
1721 else {
1722 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1723 finderArgs = new Object[] { start, end, orderByComparator };
1724 }
1725
1726 List<PortletItem> list = (List<PortletItem>)FinderCacheUtil.getResult(finderPath,
1727 finderArgs, this);
1728
1729 if (list == null) {
1730 StringBundler query = null;
1731 String sql = null;
1732
1733 if (orderByComparator != null) {
1734 query = new StringBundler(2 +
1735 (orderByComparator.getOrderByFields().length * 3));
1736
1737 query.append(_SQL_SELECT_PORTLETITEM);
1738
1739 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1740 orderByComparator);
1741
1742 sql = query.toString();
1743 }
1744 else {
1745 sql = _SQL_SELECT_PORTLETITEM;
1746 }
1747
1748 Session session = null;
1749
1750 try {
1751 session = openSession();
1752
1753 Query q = session.createQuery(sql);
1754
1755 if (orderByComparator == null) {
1756 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1757 start, end, false);
1758
1759 Collections.sort(list);
1760 }
1761 else {
1762 list = (List<PortletItem>)QueryUtil.list(q, getDialect(),
1763 start, end);
1764 }
1765 }
1766 catch (Exception e) {
1767 throw processException(e);
1768 }
1769 finally {
1770 if (list == null) {
1771 FinderCacheUtil.removeResult(finderPath, finderArgs);
1772 }
1773 else {
1774 cacheResult(list);
1775
1776 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1777 }
1778
1779 closeSession(session);
1780 }
1781 }
1782
1783 return list;
1784 }
1785
1786
1793 public void removeByG_C(long groupId, long classNameId)
1794 throws SystemException {
1795 for (PortletItem portletItem : findByG_C(groupId, classNameId)) {
1796 remove(portletItem);
1797 }
1798 }
1799
1800
1808 public void removeByG_P_C(long groupId, String portletId, long classNameId)
1809 throws SystemException {
1810 for (PortletItem portletItem : findByG_P_C(groupId, portletId,
1811 classNameId)) {
1812 remove(portletItem);
1813 }
1814 }
1815
1816
1826 public PortletItem removeByG_N_P_C(long groupId, String name,
1827 String portletId, long classNameId)
1828 throws NoSuchPortletItemException, SystemException {
1829 PortletItem portletItem = findByG_N_P_C(groupId, name, portletId,
1830 classNameId);
1831
1832 return remove(portletItem);
1833 }
1834
1835
1840 public void removeAll() throws SystemException {
1841 for (PortletItem portletItem : findAll()) {
1842 remove(portletItem);
1843 }
1844 }
1845
1846
1854 public int countByG_C(long groupId, long classNameId)
1855 throws SystemException {
1856 Object[] finderArgs = new Object[] { groupId, classNameId };
1857
1858 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
1859 finderArgs, this);
1860
1861 if (count == null) {
1862 StringBundler query = new StringBundler(3);
1863
1864 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1865
1866 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1867
1868 query.append(_FINDER_COLUMN_G_C_CLASSNAMEID_2);
1869
1870 String sql = query.toString();
1871
1872 Session session = null;
1873
1874 try {
1875 session = openSession();
1876
1877 Query q = session.createQuery(sql);
1878
1879 QueryPos qPos = QueryPos.getInstance(q);
1880
1881 qPos.add(groupId);
1882
1883 qPos.add(classNameId);
1884
1885 count = (Long)q.uniqueResult();
1886 }
1887 catch (Exception e) {
1888 throw processException(e);
1889 }
1890 finally {
1891 if (count == null) {
1892 count = Long.valueOf(0);
1893 }
1894
1895 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
1896 count);
1897
1898 closeSession(session);
1899 }
1900 }
1901
1902 return count.intValue();
1903 }
1904
1905
1914 public int countByG_P_C(long groupId, String portletId, long classNameId)
1915 throws SystemException {
1916 Object[] finderArgs = new Object[] { groupId, portletId, classNameId };
1917
1918 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P_C,
1919 finderArgs, this);
1920
1921 if (count == null) {
1922 StringBundler query = new StringBundler(4);
1923
1924 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
1925
1926 query.append(_FINDER_COLUMN_G_P_C_GROUPID_2);
1927
1928 if (portletId == null) {
1929 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_1);
1930 }
1931 else {
1932 if (portletId.equals(StringPool.BLANK)) {
1933 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_3);
1934 }
1935 else {
1936 query.append(_FINDER_COLUMN_G_P_C_PORTLETID_2);
1937 }
1938 }
1939
1940 query.append(_FINDER_COLUMN_G_P_C_CLASSNAMEID_2);
1941
1942 String sql = query.toString();
1943
1944 Session session = null;
1945
1946 try {
1947 session = openSession();
1948
1949 Query q = session.createQuery(sql);
1950
1951 QueryPos qPos = QueryPos.getInstance(q);
1952
1953 qPos.add(groupId);
1954
1955 if (portletId != null) {
1956 qPos.add(portletId);
1957 }
1958
1959 qPos.add(classNameId);
1960
1961 count = (Long)q.uniqueResult();
1962 }
1963 catch (Exception e) {
1964 throw processException(e);
1965 }
1966 finally {
1967 if (count == null) {
1968 count = Long.valueOf(0);
1969 }
1970
1971 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P_C,
1972 finderArgs, count);
1973
1974 closeSession(session);
1975 }
1976 }
1977
1978 return count.intValue();
1979 }
1980
1981
1991 public int countByG_N_P_C(long groupId, String name, String portletId,
1992 long classNameId) throws SystemException {
1993 Object[] finderArgs = new Object[] { groupId, name, portletId, classNameId };
1994
1995 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N_P_C,
1996 finderArgs, this);
1997
1998 if (count == null) {
1999 StringBundler query = new StringBundler(5);
2000
2001 query.append(_SQL_COUNT_PORTLETITEM_WHERE);
2002
2003 query.append(_FINDER_COLUMN_G_N_P_C_GROUPID_2);
2004
2005 if (name == null) {
2006 query.append(_FINDER_COLUMN_G_N_P_C_NAME_1);
2007 }
2008 else {
2009 if (name.equals(StringPool.BLANK)) {
2010 query.append(_FINDER_COLUMN_G_N_P_C_NAME_3);
2011 }
2012 else {
2013 query.append(_FINDER_COLUMN_G_N_P_C_NAME_2);
2014 }
2015 }
2016
2017 if (portletId == null) {
2018 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_1);
2019 }
2020 else {
2021 if (portletId.equals(StringPool.BLANK)) {
2022 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_3);
2023 }
2024 else {
2025 query.append(_FINDER_COLUMN_G_N_P_C_PORTLETID_2);
2026 }
2027 }
2028
2029 query.append(_FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2);
2030
2031 String sql = query.toString();
2032
2033 Session session = null;
2034
2035 try {
2036 session = openSession();
2037
2038 Query q = session.createQuery(sql);
2039
2040 QueryPos qPos = QueryPos.getInstance(q);
2041
2042 qPos.add(groupId);
2043
2044 if (name != null) {
2045 qPos.add(name);
2046 }
2047
2048 if (portletId != null) {
2049 qPos.add(portletId);
2050 }
2051
2052 qPos.add(classNameId);
2053
2054 count = (Long)q.uniqueResult();
2055 }
2056 catch (Exception e) {
2057 throw processException(e);
2058 }
2059 finally {
2060 if (count == null) {
2061 count = Long.valueOf(0);
2062 }
2063
2064 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N_P_C,
2065 finderArgs, count);
2066
2067 closeSession(session);
2068 }
2069 }
2070
2071 return count.intValue();
2072 }
2073
2074
2080 public int countAll() throws SystemException {
2081 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2082 FINDER_ARGS_EMPTY, this);
2083
2084 if (count == null) {
2085 Session session = null;
2086
2087 try {
2088 session = openSession();
2089
2090 Query q = session.createQuery(_SQL_COUNT_PORTLETITEM);
2091
2092 count = (Long)q.uniqueResult();
2093 }
2094 catch (Exception e) {
2095 throw processException(e);
2096 }
2097 finally {
2098 if (count == null) {
2099 count = Long.valueOf(0);
2100 }
2101
2102 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2103 FINDER_ARGS_EMPTY, count);
2104
2105 closeSession(session);
2106 }
2107 }
2108
2109 return count.intValue();
2110 }
2111
2112
2115 public void afterPropertiesSet() {
2116 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2117 com.liferay.portal.util.PropsUtil.get(
2118 "value.object.listener.com.liferay.portal.model.PortletItem")));
2119
2120 if (listenerClassNames.length > 0) {
2121 try {
2122 List<ModelListener<PortletItem>> listenersList = new ArrayList<ModelListener<PortletItem>>();
2123
2124 for (String listenerClassName : listenerClassNames) {
2125 Class<?> clazz = getClass();
2126
2127 listenersList.add((ModelListener<PortletItem>)InstanceFactory.newInstance(
2128 clazz.getClassLoader(), listenerClassName));
2129 }
2130
2131 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2132 }
2133 catch (Exception e) {
2134 _log.error(e);
2135 }
2136 }
2137 }
2138
2139 public void destroy() {
2140 EntityCacheUtil.removeCache(PortletItemImpl.class.getName());
2141 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2142 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2143 }
2144
2145 @BeanReference(type = AccountPersistence.class)
2146 protected AccountPersistence accountPersistence;
2147 @BeanReference(type = AddressPersistence.class)
2148 protected AddressPersistence addressPersistence;
2149 @BeanReference(type = BrowserTrackerPersistence.class)
2150 protected BrowserTrackerPersistence browserTrackerPersistence;
2151 @BeanReference(type = ClassNamePersistence.class)
2152 protected ClassNamePersistence classNamePersistence;
2153 @BeanReference(type = ClusterGroupPersistence.class)
2154 protected ClusterGroupPersistence clusterGroupPersistence;
2155 @BeanReference(type = CompanyPersistence.class)
2156 protected CompanyPersistence companyPersistence;
2157 @BeanReference(type = ContactPersistence.class)
2158 protected ContactPersistence contactPersistence;
2159 @BeanReference(type = CountryPersistence.class)
2160 protected CountryPersistence countryPersistence;
2161 @BeanReference(type = EmailAddressPersistence.class)
2162 protected EmailAddressPersistence emailAddressPersistence;
2163 @BeanReference(type = GroupPersistence.class)
2164 protected GroupPersistence groupPersistence;
2165 @BeanReference(type = ImagePersistence.class)
2166 protected ImagePersistence imagePersistence;
2167 @BeanReference(type = LayoutPersistence.class)
2168 protected LayoutPersistence layoutPersistence;
2169 @BeanReference(type = LayoutBranchPersistence.class)
2170 protected LayoutBranchPersistence layoutBranchPersistence;
2171 @BeanReference(type = LayoutPrototypePersistence.class)
2172 protected LayoutPrototypePersistence layoutPrototypePersistence;
2173 @BeanReference(type = LayoutRevisionPersistence.class)
2174 protected LayoutRevisionPersistence layoutRevisionPersistence;
2175 @BeanReference(type = LayoutSetPersistence.class)
2176 protected LayoutSetPersistence layoutSetPersistence;
2177 @BeanReference(type = LayoutSetBranchPersistence.class)
2178 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2179 @BeanReference(type = LayoutSetPrototypePersistence.class)
2180 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2181 @BeanReference(type = ListTypePersistence.class)
2182 protected ListTypePersistence listTypePersistence;
2183 @BeanReference(type = LockPersistence.class)
2184 protected LockPersistence lockPersistence;
2185 @BeanReference(type = MembershipRequestPersistence.class)
2186 protected MembershipRequestPersistence membershipRequestPersistence;
2187 @BeanReference(type = OrganizationPersistence.class)
2188 protected OrganizationPersistence organizationPersistence;
2189 @BeanReference(type = OrgGroupPermissionPersistence.class)
2190 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2191 @BeanReference(type = OrgGroupRolePersistence.class)
2192 protected OrgGroupRolePersistence orgGroupRolePersistence;
2193 @BeanReference(type = OrgLaborPersistence.class)
2194 protected OrgLaborPersistence orgLaborPersistence;
2195 @BeanReference(type = PasswordPolicyPersistence.class)
2196 protected PasswordPolicyPersistence passwordPolicyPersistence;
2197 @BeanReference(type = PasswordPolicyRelPersistence.class)
2198 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2199 @BeanReference(type = PasswordTrackerPersistence.class)
2200 protected PasswordTrackerPersistence passwordTrackerPersistence;
2201 @BeanReference(type = PermissionPersistence.class)
2202 protected PermissionPersistence permissionPersistence;
2203 @BeanReference(type = PhonePersistence.class)
2204 protected PhonePersistence phonePersistence;
2205 @BeanReference(type = PluginSettingPersistence.class)
2206 protected PluginSettingPersistence pluginSettingPersistence;
2207 @BeanReference(type = PortalPreferencesPersistence.class)
2208 protected PortalPreferencesPersistence portalPreferencesPersistence;
2209 @BeanReference(type = PortletPersistence.class)
2210 protected PortletPersistence portletPersistence;
2211 @BeanReference(type = PortletItemPersistence.class)
2212 protected PortletItemPersistence portletItemPersistence;
2213 @BeanReference(type = PortletPreferencesPersistence.class)
2214 protected PortletPreferencesPersistence portletPreferencesPersistence;
2215 @BeanReference(type = RegionPersistence.class)
2216 protected RegionPersistence regionPersistence;
2217 @BeanReference(type = ReleasePersistence.class)
2218 protected ReleasePersistence releasePersistence;
2219 @BeanReference(type = RepositoryPersistence.class)
2220 protected RepositoryPersistence repositoryPersistence;
2221 @BeanReference(type = RepositoryEntryPersistence.class)
2222 protected RepositoryEntryPersistence repositoryEntryPersistence;
2223 @BeanReference(type = ResourcePersistence.class)
2224 protected ResourcePersistence resourcePersistence;
2225 @BeanReference(type = ResourceActionPersistence.class)
2226 protected ResourceActionPersistence resourceActionPersistence;
2227 @BeanReference(type = ResourceBlockPersistence.class)
2228 protected ResourceBlockPersistence resourceBlockPersistence;
2229 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2230 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2231 @BeanReference(type = ResourceCodePersistence.class)
2232 protected ResourceCodePersistence resourceCodePersistence;
2233 @BeanReference(type = ResourcePermissionPersistence.class)
2234 protected ResourcePermissionPersistence resourcePermissionPersistence;
2235 @BeanReference(type = ResourceTypePermissionPersistence.class)
2236 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2237 @BeanReference(type = RolePersistence.class)
2238 protected RolePersistence rolePersistence;
2239 @BeanReference(type = ServiceComponentPersistence.class)
2240 protected ServiceComponentPersistence serviceComponentPersistence;
2241 @BeanReference(type = ShardPersistence.class)
2242 protected ShardPersistence shardPersistence;
2243 @BeanReference(type = SubscriptionPersistence.class)
2244 protected SubscriptionPersistence subscriptionPersistence;
2245 @BeanReference(type = TeamPersistence.class)
2246 protected TeamPersistence teamPersistence;
2247 @BeanReference(type = TicketPersistence.class)
2248 protected TicketPersistence ticketPersistence;
2249 @BeanReference(type = UserPersistence.class)
2250 protected UserPersistence userPersistence;
2251 @BeanReference(type = UserGroupPersistence.class)
2252 protected UserGroupPersistence userGroupPersistence;
2253 @BeanReference(type = UserGroupGroupRolePersistence.class)
2254 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2255 @BeanReference(type = UserGroupRolePersistence.class)
2256 protected UserGroupRolePersistence userGroupRolePersistence;
2257 @BeanReference(type = UserIdMapperPersistence.class)
2258 protected UserIdMapperPersistence userIdMapperPersistence;
2259 @BeanReference(type = UserNotificationEventPersistence.class)
2260 protected UserNotificationEventPersistence userNotificationEventPersistence;
2261 @BeanReference(type = UserTrackerPersistence.class)
2262 protected UserTrackerPersistence userTrackerPersistence;
2263 @BeanReference(type = UserTrackerPathPersistence.class)
2264 protected UserTrackerPathPersistence userTrackerPathPersistence;
2265 @BeanReference(type = VirtualHostPersistence.class)
2266 protected VirtualHostPersistence virtualHostPersistence;
2267 @BeanReference(type = WebDAVPropsPersistence.class)
2268 protected WebDAVPropsPersistence webDAVPropsPersistence;
2269 @BeanReference(type = WebsitePersistence.class)
2270 protected WebsitePersistence websitePersistence;
2271 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2272 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2273 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2274 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2275 private static final String _SQL_SELECT_PORTLETITEM = "SELECT portletItem FROM PortletItem portletItem";
2276 private static final String _SQL_SELECT_PORTLETITEM_WHERE = "SELECT portletItem FROM PortletItem portletItem WHERE ";
2277 private static final String _SQL_COUNT_PORTLETITEM = "SELECT COUNT(portletItem) FROM PortletItem portletItem";
2278 private static final String _SQL_COUNT_PORTLETITEM_WHERE = "SELECT COUNT(portletItem) FROM PortletItem portletItem WHERE ";
2279 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2280 private static final String _FINDER_COLUMN_G_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2281 private static final String _FINDER_COLUMN_G_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2282 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
2283 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
2284 private static final String _FINDER_COLUMN_G_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
2285 private static final String _FINDER_COLUMN_G_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2286 private static final String _FINDER_COLUMN_G_N_P_C_GROUPID_2 = "portletItem.groupId = ? AND ";
2287 private static final String _FINDER_COLUMN_G_N_P_C_NAME_1 = "portletItem.name IS NULL AND ";
2288 private static final String _FINDER_COLUMN_G_N_P_C_NAME_2 = "lower(portletItem.name) = lower(CAST_TEXT(?)) AND ";
2289 private static final String _FINDER_COLUMN_G_N_P_C_NAME_3 = "(portletItem.name IS NULL OR lower(portletItem.name) = lower(CAST_TEXT(?))) AND ";
2290 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_1 = "portletItem.portletId IS NULL AND ";
2291 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_2 = "portletItem.portletId = ? AND ";
2292 private static final String _FINDER_COLUMN_G_N_P_C_PORTLETID_3 = "(portletItem.portletId IS NULL OR portletItem.portletId = ?) AND ";
2293 private static final String _FINDER_COLUMN_G_N_P_C_CLASSNAMEID_2 = "portletItem.classNameId = ?";
2294 private static final String _ORDER_BY_ENTITY_ALIAS = "portletItem.";
2295 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletItem exists with the primary key ";
2296 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletItem exists with the key {";
2297 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2298 private static Log _log = LogFactoryUtil.getLog(PortletItemPersistenceImpl.class);
2299 private static PortletItem _nullPortletItem = new PortletItemImpl() {
2300 @Override
2301 public Object clone() {
2302 return this;
2303 }
2304
2305 @Override
2306 public CacheModel<PortletItem> toCacheModel() {
2307 return _nullPortletItemCacheModel;
2308 }
2309 };
2310
2311 private static CacheModel<PortletItem> _nullPortletItemCacheModel = new CacheModel<PortletItem>() {
2312 public PortletItem toEntityModel() {
2313 return _nullPortletItem;
2314 }
2315 };
2316 }