001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPortletException;
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.Portlet;
040 import com.liferay.portal.model.impl.PortletImpl;
041 import com.liferay.portal.model.impl.PortletModelImpl;
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 PortletPersistenceImpl extends BasePersistenceImpl<Portlet>
063 implements PortletPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = PortletImpl.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_COMPANYID =
075 new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
076 PortletModelImpl.FINDER_CACHE_ENABLED, PortletImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
078 new String[] {
079 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_COMPANYID =
085 new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
086 PortletModelImpl.FINDER_CACHE_ENABLED, PortletImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
088 new String[] { Long.class.getName() },
089 PortletModelImpl.COMPANYID_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
091 PortletModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
093 new String[] { Long.class.getName() });
094 public static final FinderPath FINDER_PATH_FETCH_BY_C_P = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
095 PortletModelImpl.FINDER_CACHE_ENABLED, PortletImpl.class,
096 FINDER_CLASS_NAME_ENTITY, "fetchByC_P",
097 new String[] { Long.class.getName(), String.class.getName() },
098 PortletModelImpl.COMPANYID_COLUMN_BITMASK |
099 PortletModelImpl.PORTLETID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
101 PortletModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
103 new String[] { Long.class.getName(), String.class.getName() });
104 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
105 PortletModelImpl.FINDER_CACHE_ENABLED, PortletImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
108 PortletModelImpl.FINDER_CACHE_ENABLED, PortletImpl.class,
109 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
110 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
111 PortletModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
113
114
119 public void cacheResult(Portlet portlet) {
120 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
121 PortletImpl.class, portlet.getPrimaryKey(), portlet);
122
123 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
124 new Object[] {
125 Long.valueOf(portlet.getCompanyId()),
126
127 portlet.getPortletId()
128 }, portlet);
129
130 portlet.resetOriginalValues();
131 }
132
133
138 public void cacheResult(List<Portlet> portlets) {
139 for (Portlet portlet : portlets) {
140 if (EntityCacheUtil.getResult(
141 PortletModelImpl.ENTITY_CACHE_ENABLED,
142 PortletImpl.class, portlet.getPrimaryKey()) == null) {
143 cacheResult(portlet);
144 }
145 else {
146 portlet.resetOriginalValues();
147 }
148 }
149 }
150
151
158 @Override
159 public void clearCache() {
160 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
161 CacheRegistryUtil.clear(PortletImpl.class.getName());
162 }
163
164 EntityCacheUtil.clearCache(PortletImpl.class.getName());
165
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
168 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
169 }
170
171
178 @Override
179 public void clearCache(Portlet portlet) {
180 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
181 PortletImpl.class, portlet.getPrimaryKey());
182
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
185
186 clearUniqueFindersCache(portlet);
187 }
188
189 @Override
190 public void clearCache(List<Portlet> portlets) {
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193
194 for (Portlet portlet : portlets) {
195 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
196 PortletImpl.class, portlet.getPrimaryKey());
197
198 clearUniqueFindersCache(portlet);
199 }
200 }
201
202 protected void clearUniqueFindersCache(Portlet portlet) {
203 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
204 new Object[] {
205 Long.valueOf(portlet.getCompanyId()),
206
207 portlet.getPortletId()
208 });
209 }
210
211
217 public Portlet create(long id) {
218 Portlet portlet = new PortletImpl();
219
220 portlet.setNew(true);
221 portlet.setPrimaryKey(id);
222
223 return portlet;
224 }
225
226
234 public Portlet remove(long id)
235 throws NoSuchPortletException, SystemException {
236 return remove(Long.valueOf(id));
237 }
238
239
247 @Override
248 public Portlet remove(Serializable primaryKey)
249 throws NoSuchPortletException, SystemException {
250 Session session = null;
251
252 try {
253 session = openSession();
254
255 Portlet portlet = (Portlet)session.get(PortletImpl.class, primaryKey);
256
257 if (portlet == null) {
258 if (_log.isWarnEnabled()) {
259 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
260 }
261
262 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
263 primaryKey);
264 }
265
266 return remove(portlet);
267 }
268 catch (NoSuchPortletException nsee) {
269 throw nsee;
270 }
271 catch (Exception e) {
272 throw processException(e);
273 }
274 finally {
275 closeSession(session);
276 }
277 }
278
279 @Override
280 protected Portlet removeImpl(Portlet portlet) throws SystemException {
281 portlet = toUnwrappedModel(portlet);
282
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 BatchSessionUtil.delete(session, portlet);
289 }
290 catch (Exception e) {
291 throw processException(e);
292 }
293 finally {
294 closeSession(session);
295 }
296
297 clearCache(portlet);
298
299 return portlet;
300 }
301
302 @Override
303 public Portlet updateImpl(com.liferay.portal.model.Portlet portlet,
304 boolean merge) throws SystemException {
305 portlet = toUnwrappedModel(portlet);
306
307 boolean isNew = portlet.isNew();
308
309 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
310
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 BatchSessionUtil.update(session, portlet, merge);
317
318 portlet.setNew(false);
319 }
320 catch (Exception e) {
321 throw processException(e);
322 }
323 finally {
324 closeSession(session);
325 }
326
327 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
328
329 if (isNew || !PortletModelImpl.COLUMN_BITMASK_ENABLED) {
330 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
331 }
332
333 else {
334 if ((portletModelImpl.getColumnBitmask() &
335 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
336 Object[] args = new Object[] {
337 Long.valueOf(portletModelImpl.getOriginalCompanyId())
338 };
339
340 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
341 args);
342 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
343 args);
344
345 args = new Object[] {
346 Long.valueOf(portletModelImpl.getCompanyId())
347 };
348
349 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
350 args);
351 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
352 args);
353 }
354 }
355
356 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
357 PortletImpl.class, portlet.getPrimaryKey(), portlet);
358
359 if (isNew) {
360 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
361 new Object[] {
362 Long.valueOf(portlet.getCompanyId()),
363
364 portlet.getPortletId()
365 }, portlet);
366 }
367 else {
368 if ((portletModelImpl.getColumnBitmask() &
369 FINDER_PATH_FETCH_BY_C_P.getColumnBitmask()) != 0) {
370 Object[] args = new Object[] {
371 Long.valueOf(portletModelImpl.getOriginalCompanyId()),
372
373 portletModelImpl.getOriginalPortletId()
374 };
375
376 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
377 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P, args);
378
379 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
380 new Object[] {
381 Long.valueOf(portlet.getCompanyId()),
382
383 portlet.getPortletId()
384 }, portlet);
385 }
386 }
387
388 return portlet;
389 }
390
391 protected Portlet toUnwrappedModel(Portlet portlet) {
392 if (portlet instanceof PortletImpl) {
393 return portlet;
394 }
395
396 PortletImpl portletImpl = new PortletImpl();
397
398 portletImpl.setNew(portlet.isNew());
399 portletImpl.setPrimaryKey(portlet.getPrimaryKey());
400
401 portletImpl.setId(portlet.getId());
402 portletImpl.setCompanyId(portlet.getCompanyId());
403 portletImpl.setPortletId(portlet.getPortletId());
404 portletImpl.setRoles(portlet.getRoles());
405 portletImpl.setActive(portlet.isActive());
406
407 return portletImpl;
408 }
409
410
418 @Override
419 public Portlet findByPrimaryKey(Serializable primaryKey)
420 throws NoSuchModelException, SystemException {
421 return findByPrimaryKey(((Long)primaryKey).longValue());
422 }
423
424
432 public Portlet findByPrimaryKey(long id)
433 throws NoSuchPortletException, SystemException {
434 Portlet portlet = fetchByPrimaryKey(id);
435
436 if (portlet == null) {
437 if (_log.isWarnEnabled()) {
438 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
439 }
440
441 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
442 id);
443 }
444
445 return portlet;
446 }
447
448
455 @Override
456 public Portlet fetchByPrimaryKey(Serializable primaryKey)
457 throws SystemException {
458 return fetchByPrimaryKey(((Long)primaryKey).longValue());
459 }
460
461
468 public Portlet fetchByPrimaryKey(long id) throws SystemException {
469 Portlet portlet = (Portlet)EntityCacheUtil.getResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
470 PortletImpl.class, id);
471
472 if (portlet == _nullPortlet) {
473 return null;
474 }
475
476 if (portlet == null) {
477 Session session = null;
478
479 boolean hasException = false;
480
481 try {
482 session = openSession();
483
484 portlet = (Portlet)session.get(PortletImpl.class,
485 Long.valueOf(id));
486 }
487 catch (Exception e) {
488 hasException = true;
489
490 throw processException(e);
491 }
492 finally {
493 if (portlet != null) {
494 cacheResult(portlet);
495 }
496 else if (!hasException) {
497 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
498 PortletImpl.class, id, _nullPortlet);
499 }
500
501 closeSession(session);
502 }
503 }
504
505 return portlet;
506 }
507
508
515 public List<Portlet> findByCompanyId(long companyId)
516 throws SystemException {
517 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
518 null);
519 }
520
521
534 public List<Portlet> findByCompanyId(long companyId, int start, int end)
535 throws SystemException {
536 return findByCompanyId(companyId, start, end, null);
537 }
538
539
553 public List<Portlet> findByCompanyId(long companyId, int start, int end,
554 OrderByComparator orderByComparator) throws SystemException {
555 FinderPath finderPath = null;
556 Object[] finderArgs = null;
557
558 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
559 (orderByComparator == null)) {
560 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
561 finderArgs = new Object[] { companyId };
562 }
563 else {
564 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
565 finderArgs = new Object[] { companyId, start, end, orderByComparator };
566 }
567
568 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(finderPath,
569 finderArgs, this);
570
571 if (list == null) {
572 StringBundler query = null;
573
574 if (orderByComparator != null) {
575 query = new StringBundler(3 +
576 (orderByComparator.getOrderByFields().length * 3));
577 }
578 else {
579 query = new StringBundler(2);
580 }
581
582 query.append(_SQL_SELECT_PORTLET_WHERE);
583
584 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
585
586 if (orderByComparator != null) {
587 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
588 orderByComparator);
589 }
590
591 String sql = query.toString();
592
593 Session session = null;
594
595 try {
596 session = openSession();
597
598 Query q = session.createQuery(sql);
599
600 QueryPos qPos = QueryPos.getInstance(q);
601
602 qPos.add(companyId);
603
604 list = (List<Portlet>)QueryUtil.list(q, getDialect(), start, end);
605 }
606 catch (Exception e) {
607 throw processException(e);
608 }
609 finally {
610 if (list == null) {
611 FinderCacheUtil.removeResult(finderPath, finderArgs);
612 }
613 else {
614 cacheResult(list);
615
616 FinderCacheUtil.putResult(finderPath, finderArgs, list);
617 }
618
619 closeSession(session);
620 }
621 }
622
623 return list;
624 }
625
626
639 public Portlet findByCompanyId_First(long companyId,
640 OrderByComparator orderByComparator)
641 throws NoSuchPortletException, SystemException {
642 List<Portlet> list = findByCompanyId(companyId, 0, 1, orderByComparator);
643
644 if (list.isEmpty()) {
645 StringBundler msg = new StringBundler(4);
646
647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648
649 msg.append("companyId=");
650 msg.append(companyId);
651
652 msg.append(StringPool.CLOSE_CURLY_BRACE);
653
654 throw new NoSuchPortletException(msg.toString());
655 }
656 else {
657 return list.get(0);
658 }
659 }
660
661
674 public Portlet findByCompanyId_Last(long companyId,
675 OrderByComparator orderByComparator)
676 throws NoSuchPortletException, SystemException {
677 int count = countByCompanyId(companyId);
678
679 List<Portlet> list = findByCompanyId(companyId, count - 1, count,
680 orderByComparator);
681
682 if (list.isEmpty()) {
683 StringBundler msg = new StringBundler(4);
684
685 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
686
687 msg.append("companyId=");
688 msg.append(companyId);
689
690 msg.append(StringPool.CLOSE_CURLY_BRACE);
691
692 throw new NoSuchPortletException(msg.toString());
693 }
694 else {
695 return list.get(0);
696 }
697 }
698
699
713 public Portlet[] findByCompanyId_PrevAndNext(long id, long companyId,
714 OrderByComparator orderByComparator)
715 throws NoSuchPortletException, SystemException {
716 Portlet portlet = findByPrimaryKey(id);
717
718 Session session = null;
719
720 try {
721 session = openSession();
722
723 Portlet[] array = new PortletImpl[3];
724
725 array[0] = getByCompanyId_PrevAndNext(session, portlet, companyId,
726 orderByComparator, true);
727
728 array[1] = portlet;
729
730 array[2] = getByCompanyId_PrevAndNext(session, portlet, companyId,
731 orderByComparator, false);
732
733 return array;
734 }
735 catch (Exception e) {
736 throw processException(e);
737 }
738 finally {
739 closeSession(session);
740 }
741 }
742
743 protected Portlet getByCompanyId_PrevAndNext(Session session,
744 Portlet portlet, long companyId, OrderByComparator orderByComparator,
745 boolean previous) {
746 StringBundler query = null;
747
748 if (orderByComparator != null) {
749 query = new StringBundler(6 +
750 (orderByComparator.getOrderByFields().length * 6));
751 }
752 else {
753 query = new StringBundler(3);
754 }
755
756 query.append(_SQL_SELECT_PORTLET_WHERE);
757
758 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
759
760 if (orderByComparator != null) {
761 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
762
763 if (orderByConditionFields.length > 0) {
764 query.append(WHERE_AND);
765 }
766
767 for (int i = 0; i < orderByConditionFields.length; i++) {
768 query.append(_ORDER_BY_ENTITY_ALIAS);
769 query.append(orderByConditionFields[i]);
770
771 if ((i + 1) < orderByConditionFields.length) {
772 if (orderByComparator.isAscending() ^ previous) {
773 query.append(WHERE_GREATER_THAN_HAS_NEXT);
774 }
775 else {
776 query.append(WHERE_LESSER_THAN_HAS_NEXT);
777 }
778 }
779 else {
780 if (orderByComparator.isAscending() ^ previous) {
781 query.append(WHERE_GREATER_THAN);
782 }
783 else {
784 query.append(WHERE_LESSER_THAN);
785 }
786 }
787 }
788
789 query.append(ORDER_BY_CLAUSE);
790
791 String[] orderByFields = orderByComparator.getOrderByFields();
792
793 for (int i = 0; i < orderByFields.length; i++) {
794 query.append(_ORDER_BY_ENTITY_ALIAS);
795 query.append(orderByFields[i]);
796
797 if ((i + 1) < orderByFields.length) {
798 if (orderByComparator.isAscending() ^ previous) {
799 query.append(ORDER_BY_ASC_HAS_NEXT);
800 }
801 else {
802 query.append(ORDER_BY_DESC_HAS_NEXT);
803 }
804 }
805 else {
806 if (orderByComparator.isAscending() ^ previous) {
807 query.append(ORDER_BY_ASC);
808 }
809 else {
810 query.append(ORDER_BY_DESC);
811 }
812 }
813 }
814 }
815
816 String sql = query.toString();
817
818 Query q = session.createQuery(sql);
819
820 q.setFirstResult(0);
821 q.setMaxResults(2);
822
823 QueryPos qPos = QueryPos.getInstance(q);
824
825 qPos.add(companyId);
826
827 if (orderByComparator != null) {
828 Object[] values = orderByComparator.getOrderByConditionValues(portlet);
829
830 for (Object value : values) {
831 qPos.add(value);
832 }
833 }
834
835 List<Portlet> list = q.list();
836
837 if (list.size() == 2) {
838 return list.get(1);
839 }
840 else {
841 return null;
842 }
843 }
844
845
854 public Portlet findByC_P(long companyId, String portletId)
855 throws NoSuchPortletException, SystemException {
856 Portlet portlet = fetchByC_P(companyId, portletId);
857
858 if (portlet == null) {
859 StringBundler msg = new StringBundler(6);
860
861 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
862
863 msg.append("companyId=");
864 msg.append(companyId);
865
866 msg.append(", portletId=");
867 msg.append(portletId);
868
869 msg.append(StringPool.CLOSE_CURLY_BRACE);
870
871 if (_log.isWarnEnabled()) {
872 _log.warn(msg.toString());
873 }
874
875 throw new NoSuchPortletException(msg.toString());
876 }
877
878 return portlet;
879 }
880
881
889 public Portlet fetchByC_P(long companyId, String portletId)
890 throws SystemException {
891 return fetchByC_P(companyId, portletId, true);
892 }
893
894
903 public Portlet fetchByC_P(long companyId, String portletId,
904 boolean retrieveFromCache) throws SystemException {
905 Object[] finderArgs = new Object[] { companyId, portletId };
906
907 Object result = null;
908
909 if (retrieveFromCache) {
910 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
911 finderArgs, this);
912 }
913
914 if (result == null) {
915 StringBundler query = new StringBundler(3);
916
917 query.append(_SQL_SELECT_PORTLET_WHERE);
918
919 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
920
921 if (portletId == null) {
922 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
923 }
924 else {
925 if (portletId.equals(StringPool.BLANK)) {
926 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
927 }
928 else {
929 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
930 }
931 }
932
933 String sql = query.toString();
934
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 Query q = session.createQuery(sql);
941
942 QueryPos qPos = QueryPos.getInstance(q);
943
944 qPos.add(companyId);
945
946 if (portletId != null) {
947 qPos.add(portletId);
948 }
949
950 List<Portlet> list = q.list();
951
952 result = list;
953
954 Portlet portlet = null;
955
956 if (list.isEmpty()) {
957 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
958 finderArgs, list);
959 }
960 else {
961 portlet = list.get(0);
962
963 cacheResult(portlet);
964
965 if ((portlet.getCompanyId() != companyId) ||
966 (portlet.getPortletId() == null) ||
967 !portlet.getPortletId().equals(portletId)) {
968 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
969 finderArgs, portlet);
970 }
971 }
972
973 return portlet;
974 }
975 catch (Exception e) {
976 throw processException(e);
977 }
978 finally {
979 if (result == null) {
980 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
981 finderArgs);
982 }
983
984 closeSession(session);
985 }
986 }
987 else {
988 if (result instanceof List<?>) {
989 return null;
990 }
991 else {
992 return (Portlet)result;
993 }
994 }
995 }
996
997
1003 public List<Portlet> findAll() throws SystemException {
1004 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1005 }
1006
1007
1019 public List<Portlet> findAll(int start, int end) throws SystemException {
1020 return findAll(start, end, null);
1021 }
1022
1023
1036 public List<Portlet> findAll(int start, int end,
1037 OrderByComparator orderByComparator) throws SystemException {
1038 FinderPath finderPath = null;
1039 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1040
1041 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1042 (orderByComparator == null)) {
1043 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1044 finderArgs = FINDER_ARGS_EMPTY;
1045 }
1046 else {
1047 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1048 finderArgs = new Object[] { start, end, orderByComparator };
1049 }
1050
1051 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(finderPath,
1052 finderArgs, this);
1053
1054 if (list == null) {
1055 StringBundler query = null;
1056 String sql = null;
1057
1058 if (orderByComparator != null) {
1059 query = new StringBundler(2 +
1060 (orderByComparator.getOrderByFields().length * 3));
1061
1062 query.append(_SQL_SELECT_PORTLET);
1063
1064 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1065 orderByComparator);
1066
1067 sql = query.toString();
1068 }
1069 else {
1070 sql = _SQL_SELECT_PORTLET;
1071 }
1072
1073 Session session = null;
1074
1075 try {
1076 session = openSession();
1077
1078 Query q = session.createQuery(sql);
1079
1080 if (orderByComparator == null) {
1081 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
1082 start, end, false);
1083
1084 Collections.sort(list);
1085 }
1086 else {
1087 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
1088 start, end);
1089 }
1090 }
1091 catch (Exception e) {
1092 throw processException(e);
1093 }
1094 finally {
1095 if (list == null) {
1096 FinderCacheUtil.removeResult(finderPath, finderArgs);
1097 }
1098 else {
1099 cacheResult(list);
1100
1101 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1102 }
1103
1104 closeSession(session);
1105 }
1106 }
1107
1108 return list;
1109 }
1110
1111
1117 public void removeByCompanyId(long companyId) throws SystemException {
1118 for (Portlet portlet : findByCompanyId(companyId)) {
1119 remove(portlet);
1120 }
1121 }
1122
1123
1130 public void removeByC_P(long companyId, String portletId)
1131 throws NoSuchPortletException, SystemException {
1132 Portlet portlet = findByC_P(companyId, portletId);
1133
1134 remove(portlet);
1135 }
1136
1137
1142 public void removeAll() throws SystemException {
1143 for (Portlet portlet : findAll()) {
1144 remove(portlet);
1145 }
1146 }
1147
1148
1155 public int countByCompanyId(long companyId) throws SystemException {
1156 Object[] finderArgs = new Object[] { companyId };
1157
1158 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1159 finderArgs, this);
1160
1161 if (count == null) {
1162 StringBundler query = new StringBundler(2);
1163
1164 query.append(_SQL_COUNT_PORTLET_WHERE);
1165
1166 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1167
1168 String sql = query.toString();
1169
1170 Session session = null;
1171
1172 try {
1173 session = openSession();
1174
1175 Query q = session.createQuery(sql);
1176
1177 QueryPos qPos = QueryPos.getInstance(q);
1178
1179 qPos.add(companyId);
1180
1181 count = (Long)q.uniqueResult();
1182 }
1183 catch (Exception e) {
1184 throw processException(e);
1185 }
1186 finally {
1187 if (count == null) {
1188 count = Long.valueOf(0);
1189 }
1190
1191 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1192 finderArgs, count);
1193
1194 closeSession(session);
1195 }
1196 }
1197
1198 return count.intValue();
1199 }
1200
1201
1209 public int countByC_P(long companyId, String portletId)
1210 throws SystemException {
1211 Object[] finderArgs = new Object[] { companyId, portletId };
1212
1213 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1214 finderArgs, this);
1215
1216 if (count == null) {
1217 StringBundler query = new StringBundler(3);
1218
1219 query.append(_SQL_COUNT_PORTLET_WHERE);
1220
1221 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1222
1223 if (portletId == null) {
1224 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
1225 }
1226 else {
1227 if (portletId.equals(StringPool.BLANK)) {
1228 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
1229 }
1230 else {
1231 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
1232 }
1233 }
1234
1235 String sql = query.toString();
1236
1237 Session session = null;
1238
1239 try {
1240 session = openSession();
1241
1242 Query q = session.createQuery(sql);
1243
1244 QueryPos qPos = QueryPos.getInstance(q);
1245
1246 qPos.add(companyId);
1247
1248 if (portletId != null) {
1249 qPos.add(portletId);
1250 }
1251
1252 count = (Long)q.uniqueResult();
1253 }
1254 catch (Exception e) {
1255 throw processException(e);
1256 }
1257 finally {
1258 if (count == null) {
1259 count = Long.valueOf(0);
1260 }
1261
1262 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1263 count);
1264
1265 closeSession(session);
1266 }
1267 }
1268
1269 return count.intValue();
1270 }
1271
1272
1278 public int countAll() throws SystemException {
1279 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1280 FINDER_ARGS_EMPTY, this);
1281
1282 if (count == null) {
1283 Session session = null;
1284
1285 try {
1286 session = openSession();
1287
1288 Query q = session.createQuery(_SQL_COUNT_PORTLET);
1289
1290 count = (Long)q.uniqueResult();
1291 }
1292 catch (Exception e) {
1293 throw processException(e);
1294 }
1295 finally {
1296 if (count == null) {
1297 count = Long.valueOf(0);
1298 }
1299
1300 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1301 FINDER_ARGS_EMPTY, count);
1302
1303 closeSession(session);
1304 }
1305 }
1306
1307 return count.intValue();
1308 }
1309
1310
1313 public void afterPropertiesSet() {
1314 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1315 com.liferay.portal.util.PropsUtil.get(
1316 "value.object.listener.com.liferay.portal.model.Portlet")));
1317
1318 if (listenerClassNames.length > 0) {
1319 try {
1320 List<ModelListener<Portlet>> listenersList = new ArrayList<ModelListener<Portlet>>();
1321
1322 for (String listenerClassName : listenerClassNames) {
1323 listenersList.add((ModelListener<Portlet>)InstanceFactory.newInstance(
1324 listenerClassName));
1325 }
1326
1327 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1328 }
1329 catch (Exception e) {
1330 _log.error(e);
1331 }
1332 }
1333 }
1334
1335 public void destroy() {
1336 EntityCacheUtil.removeCache(PortletImpl.class.getName());
1337 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1338 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1339 }
1340
1341 @BeanReference(type = AccountPersistence.class)
1342 protected AccountPersistence accountPersistence;
1343 @BeanReference(type = AddressPersistence.class)
1344 protected AddressPersistence addressPersistence;
1345 @BeanReference(type = BrowserTrackerPersistence.class)
1346 protected BrowserTrackerPersistence browserTrackerPersistence;
1347 @BeanReference(type = ClassNamePersistence.class)
1348 protected ClassNamePersistence classNamePersistence;
1349 @BeanReference(type = ClusterGroupPersistence.class)
1350 protected ClusterGroupPersistence clusterGroupPersistence;
1351 @BeanReference(type = CompanyPersistence.class)
1352 protected CompanyPersistence companyPersistence;
1353 @BeanReference(type = ContactPersistence.class)
1354 protected ContactPersistence contactPersistence;
1355 @BeanReference(type = CountryPersistence.class)
1356 protected CountryPersistence countryPersistence;
1357 @BeanReference(type = EmailAddressPersistence.class)
1358 protected EmailAddressPersistence emailAddressPersistence;
1359 @BeanReference(type = GroupPersistence.class)
1360 protected GroupPersistence groupPersistence;
1361 @BeanReference(type = ImagePersistence.class)
1362 protected ImagePersistence imagePersistence;
1363 @BeanReference(type = LayoutPersistence.class)
1364 protected LayoutPersistence layoutPersistence;
1365 @BeanReference(type = LayoutBranchPersistence.class)
1366 protected LayoutBranchPersistence layoutBranchPersistence;
1367 @BeanReference(type = LayoutPrototypePersistence.class)
1368 protected LayoutPrototypePersistence layoutPrototypePersistence;
1369 @BeanReference(type = LayoutRevisionPersistence.class)
1370 protected LayoutRevisionPersistence layoutRevisionPersistence;
1371 @BeanReference(type = LayoutSetPersistence.class)
1372 protected LayoutSetPersistence layoutSetPersistence;
1373 @BeanReference(type = LayoutSetBranchPersistence.class)
1374 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1375 @BeanReference(type = LayoutSetPrototypePersistence.class)
1376 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1377 @BeanReference(type = ListTypePersistence.class)
1378 protected ListTypePersistence listTypePersistence;
1379 @BeanReference(type = LockPersistence.class)
1380 protected LockPersistence lockPersistence;
1381 @BeanReference(type = MembershipRequestPersistence.class)
1382 protected MembershipRequestPersistence membershipRequestPersistence;
1383 @BeanReference(type = OrganizationPersistence.class)
1384 protected OrganizationPersistence organizationPersistence;
1385 @BeanReference(type = OrgGroupPermissionPersistence.class)
1386 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1387 @BeanReference(type = OrgGroupRolePersistence.class)
1388 protected OrgGroupRolePersistence orgGroupRolePersistence;
1389 @BeanReference(type = OrgLaborPersistence.class)
1390 protected OrgLaborPersistence orgLaborPersistence;
1391 @BeanReference(type = PasswordPolicyPersistence.class)
1392 protected PasswordPolicyPersistence passwordPolicyPersistence;
1393 @BeanReference(type = PasswordPolicyRelPersistence.class)
1394 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1395 @BeanReference(type = PasswordTrackerPersistence.class)
1396 protected PasswordTrackerPersistence passwordTrackerPersistence;
1397 @BeanReference(type = PermissionPersistence.class)
1398 protected PermissionPersistence permissionPersistence;
1399 @BeanReference(type = PhonePersistence.class)
1400 protected PhonePersistence phonePersistence;
1401 @BeanReference(type = PluginSettingPersistence.class)
1402 protected PluginSettingPersistence pluginSettingPersistence;
1403 @BeanReference(type = PortalPreferencesPersistence.class)
1404 protected PortalPreferencesPersistence portalPreferencesPersistence;
1405 @BeanReference(type = PortletPersistence.class)
1406 protected PortletPersistence portletPersistence;
1407 @BeanReference(type = PortletItemPersistence.class)
1408 protected PortletItemPersistence portletItemPersistence;
1409 @BeanReference(type = PortletPreferencesPersistence.class)
1410 protected PortletPreferencesPersistence portletPreferencesPersistence;
1411 @BeanReference(type = RegionPersistence.class)
1412 protected RegionPersistence regionPersistence;
1413 @BeanReference(type = ReleasePersistence.class)
1414 protected ReleasePersistence releasePersistence;
1415 @BeanReference(type = RepositoryPersistence.class)
1416 protected RepositoryPersistence repositoryPersistence;
1417 @BeanReference(type = RepositoryEntryPersistence.class)
1418 protected RepositoryEntryPersistence repositoryEntryPersistence;
1419 @BeanReference(type = ResourcePersistence.class)
1420 protected ResourcePersistence resourcePersistence;
1421 @BeanReference(type = ResourceActionPersistence.class)
1422 protected ResourceActionPersistence resourceActionPersistence;
1423 @BeanReference(type = ResourceBlockPersistence.class)
1424 protected ResourceBlockPersistence resourceBlockPersistence;
1425 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1426 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1427 @BeanReference(type = ResourceCodePersistence.class)
1428 protected ResourceCodePersistence resourceCodePersistence;
1429 @BeanReference(type = ResourcePermissionPersistence.class)
1430 protected ResourcePermissionPersistence resourcePermissionPersistence;
1431 @BeanReference(type = ResourceTypePermissionPersistence.class)
1432 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1433 @BeanReference(type = RolePersistence.class)
1434 protected RolePersistence rolePersistence;
1435 @BeanReference(type = ServiceComponentPersistence.class)
1436 protected ServiceComponentPersistence serviceComponentPersistence;
1437 @BeanReference(type = ShardPersistence.class)
1438 protected ShardPersistence shardPersistence;
1439 @BeanReference(type = SubscriptionPersistence.class)
1440 protected SubscriptionPersistence subscriptionPersistence;
1441 @BeanReference(type = TeamPersistence.class)
1442 protected TeamPersistence teamPersistence;
1443 @BeanReference(type = TicketPersistence.class)
1444 protected TicketPersistence ticketPersistence;
1445 @BeanReference(type = UserPersistence.class)
1446 protected UserPersistence userPersistence;
1447 @BeanReference(type = UserGroupPersistence.class)
1448 protected UserGroupPersistence userGroupPersistence;
1449 @BeanReference(type = UserGroupGroupRolePersistence.class)
1450 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1451 @BeanReference(type = UserGroupRolePersistence.class)
1452 protected UserGroupRolePersistence userGroupRolePersistence;
1453 @BeanReference(type = UserIdMapperPersistence.class)
1454 protected UserIdMapperPersistence userIdMapperPersistence;
1455 @BeanReference(type = UserNotificationEventPersistence.class)
1456 protected UserNotificationEventPersistence userNotificationEventPersistence;
1457 @BeanReference(type = UserTrackerPersistence.class)
1458 protected UserTrackerPersistence userTrackerPersistence;
1459 @BeanReference(type = UserTrackerPathPersistence.class)
1460 protected UserTrackerPathPersistence userTrackerPathPersistence;
1461 @BeanReference(type = VirtualHostPersistence.class)
1462 protected VirtualHostPersistence virtualHostPersistence;
1463 @BeanReference(type = WebDAVPropsPersistence.class)
1464 protected WebDAVPropsPersistence webDAVPropsPersistence;
1465 @BeanReference(type = WebsitePersistence.class)
1466 protected WebsitePersistence websitePersistence;
1467 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1468 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1469 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1470 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1471 private static final String _SQL_SELECT_PORTLET = "SELECT portlet FROM Portlet portlet";
1472 private static final String _SQL_SELECT_PORTLET_WHERE = "SELECT portlet FROM Portlet portlet WHERE ";
1473 private static final String _SQL_COUNT_PORTLET = "SELECT COUNT(portlet) FROM Portlet portlet";
1474 private static final String _SQL_COUNT_PORTLET_WHERE = "SELECT COUNT(portlet) FROM Portlet portlet WHERE ";
1475 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "portlet.companyId = ?";
1476 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "portlet.companyId = ? AND ";
1477 private static final String _FINDER_COLUMN_C_P_PORTLETID_1 = "portlet.portletId IS NULL";
1478 private static final String _FINDER_COLUMN_C_P_PORTLETID_2 = "portlet.portletId = ?";
1479 private static final String _FINDER_COLUMN_C_P_PORTLETID_3 = "(portlet.portletId IS NULL OR portlet.portletId = ?)";
1480 private static final String _ORDER_BY_ENTITY_ALIAS = "portlet.";
1481 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Portlet exists with the primary key ";
1482 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Portlet exists with the key {";
1483 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1484 private static Log _log = LogFactoryUtil.getLog(PortletPersistenceImpl.class);
1485 private static Portlet _nullPortlet = new PortletImpl() {
1486 @Override
1487 public Object clone() {
1488 return this;
1489 }
1490
1491 @Override
1492 public CacheModel<Portlet> toCacheModel() {
1493 return _nullPortletCacheModel;
1494 }
1495 };
1496
1497 private static CacheModel<Portlet> _nullPortletCacheModel = new CacheModel<Portlet>() {
1498 public Portlet toEntityModel() {
1499 return _nullPortlet;
1500 }
1501 };
1502 }